- Added realracing3-community.apk (71.57 MB) - Removed 32-bit support (armeabi-v7a) - Only includes arm64-v8a libraries - Decompiled source code included - Added README-community.md with analysis
221 lines
8.5 KiB
Java
221 lines
8.5 KiB
Java
package com.google.firebase.sessions;
|
|
|
|
import android.app.Service;
|
|
import android.content.Intent;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.DeadObjectException;
|
|
import android.os.Handler;
|
|
import android.os.HandlerThread;
|
|
import android.os.IBinder;
|
|
import android.os.Looper;
|
|
import android.os.Message;
|
|
import android.os.Messenger;
|
|
import android.util.Log;
|
|
import com.google.firebase.sessions.SessionGenerator;
|
|
import com.google.firebase.sessions.settings.SessionsSettings;
|
|
import java.util.ArrayList;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
import kotlin.time.Duration;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public final class SessionLifecycleService extends Service {
|
|
public static final Companion Companion = new Companion(null);
|
|
public final HandlerThread handlerThread = new HandlerThread("FirebaseSessions_HandlerThread");
|
|
public MessageHandler messageHandler;
|
|
public Messenger messenger;
|
|
|
|
public static final class MessageHandler extends Handler {
|
|
public final ArrayList boundClients;
|
|
public boolean hasForegrounded;
|
|
public long lastMsgTimeMs;
|
|
|
|
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
|
|
public MessageHandler(Looper looper) {
|
|
super(looper);
|
|
Intrinsics.checkNotNullParameter(looper, "looper");
|
|
this.boundClients = new ArrayList();
|
|
}
|
|
|
|
@Override // android.os.Handler
|
|
public void handleMessage(Message msg) {
|
|
Intrinsics.checkNotNullParameter(msg, "msg");
|
|
if (this.lastMsgTimeMs > msg.getWhen()) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Ignoring old message from ");
|
|
sb.append(msg.getWhen());
|
|
sb.append(" which is older than ");
|
|
sb.append(this.lastMsgTimeMs);
|
|
sb.append('.');
|
|
return;
|
|
}
|
|
int i = msg.what;
|
|
if (i == 1) {
|
|
handleForegrounding(msg);
|
|
return;
|
|
}
|
|
if (i == 2) {
|
|
handleBackgrounding(msg);
|
|
return;
|
|
}
|
|
if (i == 4) {
|
|
handleClientBound(msg);
|
|
return;
|
|
}
|
|
Log.w("SessionLifecycleService", "Received unexpected event from the SessionLifecycleClient: " + msg);
|
|
super.handleMessage(msg);
|
|
}
|
|
|
|
public final void handleForegrounding(Message message) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Activity foregrounding at ");
|
|
sb.append(message.getWhen());
|
|
sb.append('.');
|
|
if (!this.hasForegrounded) {
|
|
this.hasForegrounded = true;
|
|
newSession();
|
|
} else if (isSessionRestart(message.getWhen())) {
|
|
newSession();
|
|
}
|
|
this.lastMsgTimeMs = message.getWhen();
|
|
}
|
|
|
|
public final void handleBackgrounding(Message message) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Activity backgrounding at ");
|
|
sb.append(message.getWhen());
|
|
this.lastMsgTimeMs = message.getWhen();
|
|
}
|
|
|
|
public final void handleClientBound(Message message) {
|
|
this.boundClients.add(message.replyTo);
|
|
Messenger messenger = message.replyTo;
|
|
Intrinsics.checkNotNullExpressionValue(messenger, "msg.replyTo");
|
|
maybeSendSessionToClient(messenger);
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Client ");
|
|
sb.append(message.replyTo);
|
|
sb.append(" bound at ");
|
|
sb.append(message.getWhen());
|
|
sb.append(". Clients: ");
|
|
sb.append(this.boundClients.size());
|
|
}
|
|
|
|
public final void newSession() {
|
|
SessionGenerator.Companion companion = SessionGenerator.Companion;
|
|
companion.getInstance().generateNewSession();
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Generated new session ");
|
|
sb.append(companion.getInstance().getCurrentSession().getSessionId());
|
|
broadcastSession();
|
|
SessionDatastore.Companion.getInstance().updateSessionId(companion.getInstance().getCurrentSession().getSessionId());
|
|
}
|
|
|
|
public final void broadcastSession() {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Broadcasting new session: ");
|
|
SessionGenerator.Companion companion = SessionGenerator.Companion;
|
|
sb.append(companion.getInstance().getCurrentSession());
|
|
SessionFirelogPublisher.Companion.getInstance().logSession(companion.getInstance().getCurrentSession());
|
|
for (Messenger it : new ArrayList(this.boundClients)) {
|
|
Intrinsics.checkNotNullExpressionValue(it, "it");
|
|
maybeSendSessionToClient(it);
|
|
}
|
|
}
|
|
|
|
public final void maybeSendSessionToClient(Messenger messenger) {
|
|
if (this.hasForegrounded) {
|
|
sendSessionToClient(messenger, SessionGenerator.Companion.getInstance().getCurrentSession().getSessionId());
|
|
return;
|
|
}
|
|
String currentSessionId = SessionDatastore.Companion.getInstance().getCurrentSessionId();
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("App has not yet foregrounded. Using previously stored session: ");
|
|
sb.append(currentSessionId);
|
|
if (currentSessionId != null) {
|
|
sendSessionToClient(messenger, currentSessionId);
|
|
}
|
|
}
|
|
|
|
public final void sendSessionToClient(Messenger messenger, String str) {
|
|
try {
|
|
Bundle bundle = new Bundle();
|
|
bundle.putString("SessionUpdateExtra", str);
|
|
Message obtain = Message.obtain(null, 3, 0, 0);
|
|
obtain.setData(bundle);
|
|
messenger.send(obtain);
|
|
} catch (DeadObjectException unused) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Removing dead client from list: ");
|
|
sb.append(messenger);
|
|
this.boundClients.remove(messenger);
|
|
} catch (Exception e) {
|
|
Log.w("SessionLifecycleService", "Unable to push new session to " + messenger + '.', e);
|
|
}
|
|
}
|
|
|
|
public final boolean isSessionRestart(long j) {
|
|
return j - this.lastMsgTimeMs > Duration.m4081getInWholeMillisecondsimpl(SessionsSettings.Companion.getInstance().m853getSessionRestartTimeoutUwyO8pc());
|
|
}
|
|
}
|
|
|
|
@Override // android.app.Service
|
|
public void onCreate() {
|
|
super.onCreate();
|
|
this.handlerThread.start();
|
|
Looper looper = this.handlerThread.getLooper();
|
|
Intrinsics.checkNotNullExpressionValue(looper, "handlerThread.looper");
|
|
this.messageHandler = new MessageHandler(looper);
|
|
this.messenger = new Messenger(this.messageHandler);
|
|
}
|
|
|
|
@Override // android.app.Service
|
|
public IBinder onBind(Intent intent) {
|
|
if (intent == null) {
|
|
return null;
|
|
}
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Service bound to new client on process ");
|
|
sb.append(intent.getAction());
|
|
Messenger clientCallback = getClientCallback(intent);
|
|
if (clientCallback != null) {
|
|
Message obtain = Message.obtain(null, 4, 0, 0);
|
|
obtain.replyTo = clientCallback;
|
|
MessageHandler messageHandler = this.messageHandler;
|
|
if (messageHandler != null) {
|
|
messageHandler.sendMessage(obtain);
|
|
}
|
|
}
|
|
Messenger messenger = this.messenger;
|
|
if (messenger != null) {
|
|
return messenger.getBinder();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override // android.app.Service
|
|
public void onDestroy() {
|
|
super.onDestroy();
|
|
this.handlerThread.quit();
|
|
}
|
|
|
|
public final Messenger getClientCallback(Intent intent) {
|
|
Object parcelableExtra;
|
|
if (Build.VERSION.SDK_INT >= 33) {
|
|
parcelableExtra = intent.getParcelableExtra("ClientCallbackMessenger", Messenger.class);
|
|
return (Messenger) parcelableExtra;
|
|
}
|
|
return (Messenger) intent.getParcelableExtra("ClientCallbackMessenger");
|
|
}
|
|
|
|
public static final class Companion {
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public Companion() {
|
|
}
|
|
}
|
|
}
|