- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
204 lines
8.0 KiB
Java
204 lines
8.0 KiB
Java
package com.google.firebase.sessions;
|
|
|
|
import android.content.ComponentName;
|
|
import android.content.ServiceConnection;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.IBinder;
|
|
import android.os.Looper;
|
|
import android.os.Message;
|
|
import android.os.Messenger;
|
|
import android.os.RemoteException;
|
|
import android.util.Log;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.concurrent.LinkedBlockingDeque;
|
|
import kotlin.coroutines.CoroutineContext;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
import kotlinx.coroutines.BuildersKt__Builders_commonKt;
|
|
import kotlinx.coroutines.CoroutineScopeKt;
|
|
import kotlinx.coroutines.Job;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public final class SessionLifecycleClient {
|
|
public static final Companion Companion = new Companion(null);
|
|
public final CoroutineContext backgroundDispatcher;
|
|
public final LinkedBlockingDeque queuedMessages;
|
|
public Messenger service;
|
|
public boolean serviceBound;
|
|
public final SessionLifecycleClient$serviceConnection$1 serviceConnection;
|
|
|
|
/* JADX WARN: Type inference failed for: r2v2, types: [com.google.firebase.sessions.SessionLifecycleClient$serviceConnection$1] */
|
|
public SessionLifecycleClient(CoroutineContext backgroundDispatcher) {
|
|
Intrinsics.checkNotNullParameter(backgroundDispatcher, "backgroundDispatcher");
|
|
this.backgroundDispatcher = backgroundDispatcher;
|
|
this.queuedMessages = new LinkedBlockingDeque(20);
|
|
this.serviceConnection = new ServiceConnection() { // from class: com.google.firebase.sessions.SessionLifecycleClient$serviceConnection$1
|
|
@Override // android.content.ServiceConnection
|
|
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
|
LinkedBlockingDeque linkedBlockingDeque;
|
|
List drainQueue;
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Connected to SessionLifecycleService. Queue size ");
|
|
linkedBlockingDeque = SessionLifecycleClient.this.queuedMessages;
|
|
sb.append(linkedBlockingDeque.size());
|
|
SessionLifecycleClient.this.service = new Messenger(iBinder);
|
|
SessionLifecycleClient.this.serviceBound = true;
|
|
SessionLifecycleClient sessionLifecycleClient = SessionLifecycleClient.this;
|
|
drainQueue = sessionLifecycleClient.drainQueue();
|
|
sessionLifecycleClient.sendLifecycleEvents(drainQueue);
|
|
}
|
|
|
|
@Override // android.content.ServiceConnection
|
|
public void onServiceDisconnected(ComponentName componentName) {
|
|
SessionLifecycleClient.this.service = null;
|
|
SessionLifecycleClient.this.serviceBound = false;
|
|
}
|
|
};
|
|
}
|
|
|
|
public static final class ClientUpdateHandler extends Handler {
|
|
public final CoroutineContext backgroundDispatcher;
|
|
|
|
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
|
|
public ClientUpdateHandler(CoroutineContext backgroundDispatcher) {
|
|
super(Looper.getMainLooper());
|
|
Intrinsics.checkNotNullParameter(backgroundDispatcher, "backgroundDispatcher");
|
|
this.backgroundDispatcher = backgroundDispatcher;
|
|
}
|
|
|
|
@Override // android.os.Handler
|
|
public void handleMessage(Message msg) {
|
|
String str;
|
|
Intrinsics.checkNotNullParameter(msg, "msg");
|
|
if (msg.what == 3) {
|
|
Bundle data = msg.getData();
|
|
if (data == null || (str = data.getString("SessionUpdateExtra")) == null) {
|
|
str = "";
|
|
}
|
|
handleSessionUpdate(str);
|
|
return;
|
|
}
|
|
Log.w("SessionLifecycleClient", "Received unexpected event from the SessionLifecycleService: " + msg);
|
|
super.handleMessage(msg);
|
|
}
|
|
|
|
public final void handleSessionUpdate(String str) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Session update received: ");
|
|
sb.append(str);
|
|
BuildersKt__Builders_commonKt.launch$default(CoroutineScopeKt.CoroutineScope(this.backgroundDispatcher), null, null, new SessionLifecycleClient$ClientUpdateHandler$handleSessionUpdate$1(str, null), 3, null);
|
|
}
|
|
}
|
|
|
|
public final void bindToService(SessionLifecycleServiceBinder sessionLifecycleServiceBinder) {
|
|
Intrinsics.checkNotNullParameter(sessionLifecycleServiceBinder, "sessionLifecycleServiceBinder");
|
|
sessionLifecycleServiceBinder.bindToService(new Messenger(new ClientUpdateHandler(this.backgroundDispatcher)), this.serviceConnection);
|
|
}
|
|
|
|
public final void foregrounded() {
|
|
sendLifecycleEvent(1);
|
|
}
|
|
|
|
public final void backgrounded() {
|
|
sendLifecycleEvent(2);
|
|
}
|
|
|
|
public final void sendLifecycleEvent(int i) {
|
|
List drainQueue = drainQueue();
|
|
Message obtain = Message.obtain(null, i, 0, 0);
|
|
Intrinsics.checkNotNullExpressionValue(obtain, "obtain(null, messageCode, 0, 0)");
|
|
drainQueue.add(obtain);
|
|
sendLifecycleEvents(drainQueue);
|
|
}
|
|
|
|
public final Job sendLifecycleEvents(List list) {
|
|
Job launch$default;
|
|
launch$default = BuildersKt__Builders_commonKt.launch$default(CoroutineScopeKt.CoroutineScope(this.backgroundDispatcher), null, null, new SessionLifecycleClient$sendLifecycleEvents$1(this, list, null), 3, null);
|
|
return launch$default;
|
|
}
|
|
|
|
public final void sendMessageToServer(Message message) {
|
|
if (this.service != null) {
|
|
try {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Sending lifecycle ");
|
|
sb.append(message.what);
|
|
sb.append(" to service");
|
|
Messenger messenger = this.service;
|
|
if (messenger != null) {
|
|
messenger.send(message);
|
|
return;
|
|
}
|
|
return;
|
|
} catch (RemoteException e) {
|
|
Log.w("SessionLifecycleClient", "Unable to deliver message: " + message.what, e);
|
|
queueMessage(message);
|
|
return;
|
|
}
|
|
}
|
|
queueMessage(message);
|
|
}
|
|
|
|
public final void queueMessage(Message message) {
|
|
if (this.queuedMessages.offer(message)) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Queued message ");
|
|
sb.append(message.what);
|
|
sb.append(". Queue size ");
|
|
sb.append(this.queuedMessages.size());
|
|
return;
|
|
}
|
|
StringBuilder sb2 = new StringBuilder();
|
|
sb2.append("Failed to enqueue message ");
|
|
sb2.append(message.what);
|
|
sb2.append(". Dropping.");
|
|
}
|
|
|
|
public final List drainQueue() {
|
|
ArrayList arrayList = new ArrayList();
|
|
this.queuedMessages.drainTo(arrayList);
|
|
return arrayList;
|
|
}
|
|
|
|
public final Message getLatestByCode(List list, int i) {
|
|
Object obj;
|
|
ArrayList arrayList = new ArrayList();
|
|
for (Object obj2 : list) {
|
|
if (((Message) obj2).what == i) {
|
|
arrayList.add(obj2);
|
|
}
|
|
}
|
|
Iterator it = arrayList.iterator();
|
|
if (it.hasNext()) {
|
|
Object next = it.next();
|
|
if (it.hasNext()) {
|
|
long when = ((Message) next).getWhen();
|
|
do {
|
|
Object next2 = it.next();
|
|
long when2 = ((Message) next2).getWhen();
|
|
if (when < when2) {
|
|
next = next2;
|
|
when = when2;
|
|
}
|
|
} while (it.hasNext());
|
|
}
|
|
obj = next;
|
|
} else {
|
|
obj = null;
|
|
}
|
|
return (Message) obj;
|
|
}
|
|
|
|
public static final class Companion {
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public Companion() {
|
|
}
|
|
}
|
|
}
|