- 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
166 lines
5.7 KiB
Java
166 lines
5.7 KiB
Java
package com.singular.sdk.internal;
|
|
|
|
import android.app.Application;
|
|
import android.content.IntentFilter;
|
|
import android.content.SharedPreferences;
|
|
import com.singular.sdk.internal.BroadcastReceivers;
|
|
|
|
/* loaded from: classes4.dex */
|
|
public class SessionManager {
|
|
public static final SingularLog logger = SingularLog.getLogger("Session");
|
|
public final BroadcastReceivers.NetworkChange networkChangeReceiver;
|
|
public final SingularInstance singular;
|
|
public boolean usingForegroundTracking = false;
|
|
public long sessionId = -1;
|
|
public long lastSessionPauseTime = -1;
|
|
public long sequence = 0;
|
|
public boolean inForeground = true;
|
|
|
|
public long getNextSequenceNumber() {
|
|
long j = this.sequence + 1;
|
|
this.sequence = j;
|
|
return j;
|
|
}
|
|
|
|
public long getSessionId() {
|
|
return this.sessionId;
|
|
}
|
|
|
|
public final boolean inSession() {
|
|
return this.sessionId > 0;
|
|
}
|
|
|
|
public final void resetSequence() {
|
|
this.sequence = 0L;
|
|
}
|
|
|
|
public final void setSessionId(long j) {
|
|
this.sessionId = j;
|
|
}
|
|
|
|
public void useForegroundTracking() {
|
|
this.usingForegroundTracking = true;
|
|
}
|
|
|
|
public SessionManager(SingularInstance singularInstance) {
|
|
this.singular = singularInstance;
|
|
this.networkChangeReceiver = new BroadcastReceivers.NetworkChange(singularInstance);
|
|
load();
|
|
startNewSessionIfNeeded(Utils.getCurrentTimeMillis());
|
|
enableForegroundTracking((Application) singularInstance.getContext());
|
|
registerNetworkChangeReceiver();
|
|
}
|
|
|
|
public final void enableForegroundTracking(Application application) {
|
|
if (this.usingForegroundTracking) {
|
|
return;
|
|
}
|
|
new SingularLifecycleCallbacks(this).registerSelf(application);
|
|
}
|
|
|
|
public final void load() {
|
|
SharedPreferences sharedPreferences = this.singular.getContext().getSharedPreferences("singular-pref-session", 0);
|
|
this.sessionId = sharedPreferences.getLong("id", -1L);
|
|
long j = sharedPreferences.getLong("lastSessionPauseTime", -1L);
|
|
this.lastSessionPauseTime = j;
|
|
if (j < 0) {
|
|
this.lastSessionPauseTime = sharedPreferences.getLong("lastEvent", -1L);
|
|
}
|
|
this.sequence = sharedPreferences.getLong("seq", 0L);
|
|
logger.debug("load() <= %s", toString());
|
|
}
|
|
|
|
public final void persist() {
|
|
SharedPreferences.Editor edit = this.singular.getContext().getSharedPreferences("singular-pref-session", 0).edit();
|
|
edit.putLong("id", this.sessionId);
|
|
edit.putLong("lastSessionPauseTime", this.lastSessionPauseTime);
|
|
edit.putLong("seq", this.sequence);
|
|
edit.commit();
|
|
}
|
|
|
|
public final void setLastSessionPauseTime(long j) {
|
|
this.lastSessionPauseTime = j;
|
|
persist();
|
|
}
|
|
|
|
public final boolean startNewSessionIfNeeded(long j) {
|
|
if (SingularInstance.getInstance().getSingularConfig().singularLink != null) {
|
|
startNewSession(j);
|
|
return true;
|
|
}
|
|
if (inSession() && isWithinMinTimeBetweenSessions(j)) {
|
|
return false;
|
|
}
|
|
startNewSession(j);
|
|
return true;
|
|
}
|
|
|
|
public void startNewSession(long j) {
|
|
logger.debug("startNewSession() At %d", Long.valueOf(j));
|
|
setSessionId(j);
|
|
resetSequence();
|
|
sendSessionStartEvent();
|
|
}
|
|
|
|
public final boolean isWithinMinTimeBetweenSessions(long j) {
|
|
return j - this.lastSessionPauseTime < this.singular.getSingularConfig().sessionTimeoutSec * 1000;
|
|
}
|
|
|
|
public final void sendSessionStartEvent() {
|
|
if (inSession()) {
|
|
this.singular.logSessionStart(this.sessionId);
|
|
}
|
|
}
|
|
|
|
public void onExitForeground(final long j) {
|
|
logger.debug("onExitForeground() At %d", Long.valueOf(j));
|
|
this.singular.runOnWorker(new Runnable() { // from class: com.singular.sdk.internal.SessionManager.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
SessionManager.this.setLastSessionPauseTime(j);
|
|
SessionManager.this.inForeground = false;
|
|
SessionManager.this.unregisterNetworkChangeReceiver();
|
|
Utils.appMovedToBackground();
|
|
}
|
|
});
|
|
}
|
|
|
|
public void onEnterForeground(final long j) {
|
|
if (Utils.isOpenedWithDeeplink()) {
|
|
return;
|
|
}
|
|
logger.debug("onEnterForeground() At %d", Long.valueOf(j));
|
|
this.singular.runOnWorker(new Runnable() { // from class: com.singular.sdk.internal.SessionManager.2
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
SessionManager.this.inForeground = true;
|
|
SessionManager.this.startNewSessionIfNeeded(j);
|
|
SessionManager.this.registerNetworkChangeReceiver();
|
|
}
|
|
});
|
|
}
|
|
|
|
public void registerNetworkChangeReceiver() {
|
|
if (this.inForeground || !this.usingForegroundTracking) {
|
|
IntentFilter intentFilter = new IntentFilter();
|
|
intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
|
|
this.singular.getContext().registerReceiver(this.networkChangeReceiver, intentFilter);
|
|
logger.debug("registerNetworkChangeReceiver()");
|
|
}
|
|
}
|
|
|
|
public void unregisterNetworkChangeReceiver() {
|
|
if (this.networkChangeReceiver != null) {
|
|
try {
|
|
this.singular.getContext().unregisterReceiver(this.networkChangeReceiver);
|
|
logger.debug("unregisterNetworkChangeReceiver()");
|
|
} catch (Exception unused) {
|
|
}
|
|
}
|
|
}
|
|
|
|
public String toString() {
|
|
return "{id=" + this.sessionId + ", lastSessionPauseTime=" + this.lastSessionPauseTime + ", seq=" + this.sequence + '}';
|
|
}
|
|
}
|