- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
497 lines
20 KiB
Java
497 lines
20 KiB
Java
package com.vungle.ads.internal.util;
|
|
|
|
import android.app.Activity;
|
|
import android.app.Application;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import com.vungle.ads.AnalyticsClient;
|
|
import com.vungle.ads.internal.ui.PresenterAdOpenCallback;
|
|
import com.vungle.ads.internal.util.ActivityManager;
|
|
import com.vungle.ads.internal.util.Logger;
|
|
import java.lang.ref.WeakReference;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.CopyOnWriteArraySet;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
import kotlin.collections.CollectionsKt__CollectionsJVMKt;
|
|
import kotlin.collections.CollectionsKt__CollectionsKt;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
|
|
/* loaded from: classes4.dex */
|
|
public final class ActivityManager implements Application.ActivityLifecycleCallbacks {
|
|
private Handler handler;
|
|
private String lastStoppedActivityName;
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final String TAG = ActivityManager.class.getSimpleName();
|
|
private static final ActivityManager instance = new ActivityManager();
|
|
private static final long TIMEOUT = 3000;
|
|
private static final long CONFIG_CHANGE_DELAY = 700;
|
|
private State state = State.UNKNOWN;
|
|
private AtomicBoolean isInitialized = new AtomicBoolean(false);
|
|
private final CopyOnWriteArraySet<String> startedActivities = new CopyOnWriteArraySet<>();
|
|
private final CopyOnWriteArraySet<String> resumedActivities = new CopyOnWriteArraySet<>();
|
|
private final CopyOnWriteArraySet<LifeCycleCallback> callbacks = new CopyOnWriteArraySet<>();
|
|
private final ConcurrentHashMap<LeftApplicationCallback, LifeCycleCallback> adLeftCallbacks = new ConcurrentHashMap<>();
|
|
private final Runnable configChangeRunnable = new Runnable() { // from class: com.vungle.ads.internal.util.ActivityManager$$ExternalSyntheticLambda0
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
ActivityManager.m3987configChangeRunnable$lambda0(ActivityManager.this);
|
|
}
|
|
};
|
|
|
|
public interface LeftApplicationCallback {
|
|
void onLeftApplication();
|
|
}
|
|
|
|
public static class LifeCycleCallback {
|
|
public void onPause() {
|
|
}
|
|
|
|
public void onResume() {
|
|
}
|
|
|
|
public void onStart() {
|
|
}
|
|
|
|
public void onStop() {
|
|
}
|
|
}
|
|
|
|
public enum State {
|
|
STARTED,
|
|
RESUMED,
|
|
PAUSED,
|
|
STOPPED,
|
|
UNKNOWN
|
|
}
|
|
|
|
@Override // android.app.Application.ActivityLifecycleCallbacks
|
|
public void onActivityCreated(Activity activity, Bundle bundle) {
|
|
Intrinsics.checkNotNullParameter(activity, "activity");
|
|
}
|
|
|
|
@Override // android.app.Application.ActivityLifecycleCallbacks
|
|
public void onActivityDestroyed(Activity activity) {
|
|
Intrinsics.checkNotNullParameter(activity, "activity");
|
|
}
|
|
|
|
@Override // android.app.Application.ActivityLifecycleCallbacks
|
|
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
|
|
Intrinsics.checkNotNullParameter(activity, "activity");
|
|
Intrinsics.checkNotNullParameter(outState, "outState");
|
|
}
|
|
|
|
private ActivityManager() {
|
|
}
|
|
|
|
private final int getStartedActivitiesCount() {
|
|
return this.startedActivities.size();
|
|
}
|
|
|
|
private final int getResumedActivitiesCount() {
|
|
return this.resumedActivities.size();
|
|
}
|
|
|
|
private final boolean isAppForeground() {
|
|
return !this.resumedActivities.isEmpty();
|
|
}
|
|
|
|
private final boolean getNoResumedActivities() {
|
|
return this.resumedActivities.isEmpty();
|
|
}
|
|
|
|
private final boolean getNoStartedActivities() {
|
|
return this.startedActivities.isEmpty();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
/* renamed from: configChangeRunnable$lambda-0, reason: not valid java name */
|
|
public static final void m3987configChangeRunnable$lambda0(ActivityManager this$0) {
|
|
Intrinsics.checkNotNullParameter(this$0, "this$0");
|
|
if (this$0.getNoResumedActivities()) {
|
|
State state = this$0.state;
|
|
State state2 = State.PAUSED;
|
|
if (state != state2) {
|
|
this$0.state = state2;
|
|
Iterator<LifeCycleCallback> it = this$0.callbacks.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().onPause();
|
|
}
|
|
}
|
|
}
|
|
if (this$0.getNoStartedActivities() && this$0.state == State.PAUSED) {
|
|
this$0.state = State.STOPPED;
|
|
Iterator<LifeCycleCallback> it2 = this$0.callbacks.iterator();
|
|
while (it2.hasNext()) {
|
|
it2.next().onStop();
|
|
}
|
|
}
|
|
}
|
|
|
|
public final void init(final Context context) {
|
|
Intrinsics.checkNotNullParameter(context, "context");
|
|
if (this.isInitialized.getAndSet(true)) {
|
|
return;
|
|
}
|
|
try {
|
|
Handler handler = new Handler(Looper.getMainLooper());
|
|
this.handler = handler;
|
|
handler.post(new Runnable() { // from class: com.vungle.ads.internal.util.ActivityManager$$ExternalSyntheticLambda1
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
ActivityManager.m3988init$lambda1(context, this);
|
|
}
|
|
});
|
|
} catch (Exception e) {
|
|
Logger.Companion companion = Logger.Companion;
|
|
String TAG2 = TAG;
|
|
Intrinsics.checkNotNullExpressionValue(TAG2, "TAG");
|
|
companion.e(TAG2, "Error initializing ActivityManager", e);
|
|
this.isInitialized.set(false);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
/* renamed from: init$lambda-1, reason: not valid java name */
|
|
public static final void m3988init$lambda1(Context context, ActivityManager this$0) {
|
|
Intrinsics.checkNotNullParameter(context, "$context");
|
|
Intrinsics.checkNotNullParameter(this$0, "this$0");
|
|
Context applicationContext = context.getApplicationContext();
|
|
Intrinsics.checkNotNull(applicationContext, "null cannot be cast to non-null type android.app.Application");
|
|
((Application) applicationContext).registerActivityLifecycleCallbacks(this$0);
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public final void deInit(Context context) {
|
|
Intrinsics.checkNotNullParameter(context, "context");
|
|
Context applicationContext = context.getApplicationContext();
|
|
Intrinsics.checkNotNull(applicationContext, "null cannot be cast to non-null type android.app.Application");
|
|
((Application) applicationContext).unregisterActivityLifecycleCallbacks(this);
|
|
this.startedActivities.clear();
|
|
this.resumedActivities.clear();
|
|
this.isInitialized.set(false);
|
|
this.callbacks.clear();
|
|
this.adLeftCallbacks.clear();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public final boolean inForeground() {
|
|
return !this.isInitialized.get() || this.lastStoppedActivityName == null || isAppForeground();
|
|
}
|
|
|
|
public final void addListener(LifeCycleCallback callback) {
|
|
Intrinsics.checkNotNullParameter(callback, "callback");
|
|
this.callbacks.add(callback);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public final void removeListener(LifeCycleCallback lifeCycleCallback) {
|
|
this.callbacks.remove(lifeCycleCallback);
|
|
}
|
|
|
|
@Override // android.app.Application.ActivityLifecycleCallbacks
|
|
public void onActivityStarted(Activity activity) {
|
|
List listOf;
|
|
Intrinsics.checkNotNullParameter(activity, "activity");
|
|
this.startedActivities.add(activity.toString());
|
|
if (getStartedActivitiesCount() == 1) {
|
|
State state = State.STARTED;
|
|
listOf = CollectionsKt__CollectionsKt.listOf((Object[]) new State[]{state, State.RESUMED});
|
|
if (listOf.contains(this.state)) {
|
|
return;
|
|
}
|
|
this.state = state;
|
|
Iterator<LifeCycleCallback> it = this.callbacks.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().onStart();
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // android.app.Application.ActivityLifecycleCallbacks
|
|
public void onActivityStopped(Activity activity) {
|
|
Handler handler;
|
|
Intrinsics.checkNotNullParameter(activity, "activity");
|
|
this.lastStoppedActivityName = activity.toString();
|
|
this.startedActivities.remove(activity.toString());
|
|
if (!getNoStartedActivities() || (handler = this.handler) == null) {
|
|
return;
|
|
}
|
|
handler.removeCallbacks(this.configChangeRunnable);
|
|
handler.postDelayed(this.configChangeRunnable, CONFIG_CHANGE_DELAY);
|
|
}
|
|
|
|
@Override // android.app.Application.ActivityLifecycleCallbacks
|
|
public void onActivityResumed(Activity activity) {
|
|
Intrinsics.checkNotNullParameter(activity, "activity");
|
|
boolean noResumedActivities = getNoResumedActivities();
|
|
this.resumedActivities.add(activity.toString());
|
|
if (getResumedActivitiesCount() == 1) {
|
|
if (noResumedActivities) {
|
|
State state = State.RESUMED;
|
|
if (!CollectionsKt__CollectionsJVMKt.listOf(state).contains(this.state)) {
|
|
this.state = state;
|
|
Iterator<LifeCycleCallback> it = this.callbacks.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().onResume();
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
Handler handler = this.handler;
|
|
if (handler != null) {
|
|
handler.removeCallbacks(this.configChangeRunnable);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // android.app.Application.ActivityLifecycleCallbacks
|
|
public void onActivityPaused(Activity activity) {
|
|
Intrinsics.checkNotNullParameter(activity, "activity");
|
|
this.resumedActivities.remove(activity.toString());
|
|
if (getNoResumedActivities()) {
|
|
Handler handler = this.handler;
|
|
if (handler != null) {
|
|
handler.removeCallbacks(this.configChangeRunnable);
|
|
}
|
|
Handler handler2 = this.handler;
|
|
if (handler2 != null) {
|
|
handler2.postDelayed(this.configChangeRunnable, CONFIG_CHANGE_DELAY);
|
|
}
|
|
}
|
|
}
|
|
|
|
public final void addOnNextAppLeftCallback(LeftApplicationCallback leftApplicationCallback) {
|
|
if (leftApplicationCallback == null) {
|
|
return;
|
|
}
|
|
if (!this.isInitialized.get()) {
|
|
leftApplicationCallback.onLeftApplication();
|
|
return;
|
|
}
|
|
final WeakReference weakReference = new WeakReference(leftApplicationCallback);
|
|
final Runnable runnable = new Runnable() { // from class: com.vungle.ads.internal.util.ActivityManager$addOnNextAppLeftCallback$cancelRunnable$1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
Handler handler;
|
|
handler = ActivityManager.this.handler;
|
|
if (handler != null) {
|
|
handler.removeCallbacks(this);
|
|
}
|
|
ActivityManager.this.removeOnNextAppLeftCallback(weakReference.get());
|
|
}
|
|
};
|
|
LifeCycleCallback lifeCycleCallback = new LifeCycleCallback() { // from class: com.vungle.ads.internal.util.ActivityManager$addOnNextAppLeftCallback$callback$1
|
|
private boolean wasPaused;
|
|
|
|
public final boolean getWasPaused() {
|
|
return this.wasPaused;
|
|
}
|
|
|
|
public final void setWasPaused(boolean z) {
|
|
this.wasPaused = z;
|
|
}
|
|
|
|
@Override // com.vungle.ads.internal.util.ActivityManager.LifeCycleCallback
|
|
public void onStop() {
|
|
Handler handler;
|
|
ConcurrentHashMap concurrentHashMap;
|
|
super.onStop();
|
|
ActivityManager.LeftApplicationCallback leftApplicationCallback2 = weakReference.get();
|
|
if (this.wasPaused && leftApplicationCallback2 != null) {
|
|
concurrentHashMap = this.adLeftCallbacks;
|
|
if (concurrentHashMap.containsKey(leftApplicationCallback2)) {
|
|
leftApplicationCallback2.onLeftApplication();
|
|
}
|
|
}
|
|
this.removeOnNextAppLeftCallback(leftApplicationCallback2);
|
|
handler = this.handler;
|
|
if (handler != null) {
|
|
handler.removeCallbacks(runnable);
|
|
}
|
|
}
|
|
|
|
@Override // com.vungle.ads.internal.util.ActivityManager.LifeCycleCallback
|
|
public void onResume() {
|
|
Handler handler;
|
|
super.onResume();
|
|
handler = this.handler;
|
|
if (handler != null) {
|
|
handler.postDelayed(runnable, ActivityManager.Companion.getCONFIG_CHANGE_DELAY() * 2);
|
|
}
|
|
}
|
|
|
|
@Override // com.vungle.ads.internal.util.ActivityManager.LifeCycleCallback
|
|
public void onPause() {
|
|
Handler handler;
|
|
super.onPause();
|
|
this.wasPaused = true;
|
|
handler = this.handler;
|
|
if (handler != null) {
|
|
handler.removeCallbacks(runnable);
|
|
}
|
|
}
|
|
};
|
|
this.adLeftCallbacks.put(leftApplicationCallback, lifeCycleCallback);
|
|
if (inForeground()) {
|
|
Handler handler = this.handler;
|
|
if (handler != null) {
|
|
handler.postDelayed(runnable, TIMEOUT);
|
|
}
|
|
addListener(lifeCycleCallback);
|
|
return;
|
|
}
|
|
instance.addListener(new LifeCycleCallback() { // from class: com.vungle.ads.internal.util.ActivityManager$addOnNextAppLeftCallback$1
|
|
@Override // com.vungle.ads.internal.util.ActivityManager.LifeCycleCallback
|
|
public void onStart() {
|
|
ConcurrentHashMap concurrentHashMap;
|
|
Handler handler2;
|
|
ActivityManager.Companion companion = ActivityManager.Companion;
|
|
companion.getInstance$vungle_ads_release().removeListener(this);
|
|
concurrentHashMap = ActivityManager.this.adLeftCallbacks;
|
|
ActivityManager.LifeCycleCallback lifeCycleCallback2 = (ActivityManager.LifeCycleCallback) concurrentHashMap.get(weakReference.get());
|
|
if (lifeCycleCallback2 != null) {
|
|
handler2 = ActivityManager.this.handler;
|
|
if (handler2 != null) {
|
|
handler2.postDelayed(runnable, companion.getTIMEOUT());
|
|
}
|
|
ActivityManager.this.addListener(lifeCycleCallback2);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public final void removeOnNextAppLeftCallback(LeftApplicationCallback leftApplicationCallback) {
|
|
LifeCycleCallback remove;
|
|
if (leftApplicationCallback == null || (remove = this.adLeftCallbacks.remove(leftApplicationCallback)) == null) {
|
|
return;
|
|
}
|
|
removeListener(remove);
|
|
}
|
|
|
|
public static final class Companion {
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public static /* synthetic */ void getCONFIG_CHANGE_DELAY$annotations() {
|
|
}
|
|
|
|
@VisibleForTesting(otherwise = 2)
|
|
public static /* synthetic */ void getInstance$vungle_ads_release$annotations() {
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public static /* synthetic */ void getTIMEOUT$annotations() {
|
|
}
|
|
|
|
private Companion() {
|
|
}
|
|
|
|
public final String getTAG() {
|
|
return ActivityManager.TAG;
|
|
}
|
|
|
|
public final ActivityManager getInstance$vungle_ads_release() {
|
|
return ActivityManager.instance;
|
|
}
|
|
|
|
public final long getTIMEOUT() {
|
|
return ActivityManager.TIMEOUT;
|
|
}
|
|
|
|
public final long getCONFIG_CHANGE_DELAY() {
|
|
return ActivityManager.CONFIG_CHANGE_DELAY;
|
|
}
|
|
|
|
public final void startWhenForeground(Context context, final Intent intent, final Intent intent2, final LeftApplicationCallback leftApplicationCallback, final PresenterAdOpenCallback presenterAdOpenCallback) {
|
|
Intrinsics.checkNotNullParameter(context, "context");
|
|
final WeakReference weakReference = new WeakReference(context);
|
|
if (getInstance$vungle_ads_release().inForeground()) {
|
|
if (startActivityHandleException(context, intent, intent2, presenterAdOpenCallback)) {
|
|
getInstance$vungle_ads_release().addOnNextAppLeftCallback(leftApplicationCallback);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
getInstance$vungle_ads_release().addListener(new LifeCycleCallback() { // from class: com.vungle.ads.internal.util.ActivityManager$Companion$startWhenForeground$1
|
|
@Override // com.vungle.ads.internal.util.ActivityManager.LifeCycleCallback
|
|
public void onStart() {
|
|
boolean startActivityHandleException;
|
|
super.onStart();
|
|
ActivityManager.Companion companion = ActivityManager.Companion;
|
|
companion.getInstance$vungle_ads_release().removeListener(this);
|
|
Context context2 = weakReference.get();
|
|
if (context2 != null) {
|
|
startActivityHandleException = companion.startActivityHandleException(context2, intent, intent2, presenterAdOpenCallback);
|
|
if (startActivityHandleException) {
|
|
companion.getInstance$vungle_ads_release().addOnNextAppLeftCallback(leftApplicationCallback);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public final void startWhenForeground(Context context, Intent intent, Intent intent2, LeftApplicationCallback leftApplicationCallback) {
|
|
Intrinsics.checkNotNullParameter(context, "context");
|
|
startWhenForeground(context, intent, intent2, leftApplicationCallback, null);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public final boolean startActivityHandleException(Context context, Intent intent, Intent intent2, PresenterAdOpenCallback presenterAdOpenCallback) {
|
|
if (intent == null && intent2 == null) {
|
|
return false;
|
|
}
|
|
try {
|
|
if (intent != null) {
|
|
context.startActivity(intent);
|
|
if (presenterAdOpenCallback != null) {
|
|
presenterAdOpenCallback.onDeeplinkClick(true);
|
|
}
|
|
} else {
|
|
context.startActivity(intent2);
|
|
}
|
|
return true;
|
|
} catch (Exception e) {
|
|
Logger.Companion companion = Logger.Companion;
|
|
String TAG = getTAG();
|
|
Intrinsics.checkNotNullExpressionValue(TAG, "TAG");
|
|
companion.e(TAG, "Cannot launch/find activity to handle the Implicit intent: " + e);
|
|
if (intent != null) {
|
|
try {
|
|
AnalyticsClient.INSTANCE.logError$vungle_ads_release(312, "Fail to open " + intent.getDataString(), (r13 & 4) != 0 ? null : "", (r13 & 8) != 0 ? null : null, (r13 & 16) != 0 ? null : null);
|
|
if (presenterAdOpenCallback != null) {
|
|
presenterAdOpenCallback.onDeeplinkClick(false);
|
|
}
|
|
} catch (Exception unused) {
|
|
return false;
|
|
}
|
|
}
|
|
if (intent != null && intent2 != null) {
|
|
context.startActivity(intent2);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public final void init(Context context) {
|
|
Intrinsics.checkNotNullParameter(context, "context");
|
|
getInstance$vungle_ads_release().init(context);
|
|
}
|
|
|
|
public final void addLifecycleListener(LifeCycleCallback listener) {
|
|
Intrinsics.checkNotNullParameter(listener, "listener");
|
|
getInstance$vungle_ads_release().addListener(listener);
|
|
}
|
|
}
|
|
}
|