From fc0df84eddd97ee1f23226632d6470f6e7096d86 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 8 Apr 2019 15:36:44 -0400 Subject: [PATCH] Keep track of foreground activity --- .../main/java/com/topjohnwu/magisk/App.java | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/App.java b/app/src/main/java/com/topjohnwu/magisk/App.java index da3535832..293975b30 100644 --- a/app/src/main/java/com/topjohnwu/magisk/App.java +++ b/app/src/main/java/com/topjohnwu/magisk/App.java @@ -1,13 +1,19 @@ package com.topjohnwu.magisk; +import android.app.Activity; import android.app.Application; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.AsyncTask; import android.os.Build; +import android.os.Bundle; import android.preference.PreferenceManager; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.topjohnwu.magisk.components.BaseActivity; import com.topjohnwu.magisk.database.MagiskDB; import com.topjohnwu.magisk.database.RepoDatabaseHelper; import com.topjohnwu.magisk.utils.LocaleManager; @@ -17,7 +23,7 @@ import com.topjohnwu.superuser.Shell; import java.util.concurrent.ThreadPoolExecutor; -public class App extends Application { +public class App extends Application implements Application.ActivityLifecycleCallbacks { public static App self; public static Context deContext; @@ -27,6 +33,7 @@ public class App extends Application { public SharedPreferences prefs; public MagiskDB mDB; public RepoDatabaseHelper repoDB; + public BaseActivity foreground; static { Shell.Config.setFlags(Shell.FLAG_MOUNT_MASTER | Shell.FLAG_USE_MAGISK_BUSYBOX); @@ -41,6 +48,7 @@ public class App extends Application { super.attachBaseContext(base); self = this; deContext = base; + registerActivityLifecycleCallbacks(this); if (Build.VERSION.SDK_INT >= 24) { deContext = base.createDeviceProtectedStorageContext(); @@ -55,8 +63,33 @@ public class App extends Application { } @Override - public void onConfigurationChanged(Configuration newConfig) { + public void onConfigurationChanged(@NonNull Configuration newConfig) { super.onConfigurationChanged(newConfig); LocaleManager.setLocale(this); } + + @Override + public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {} + + @Override + public void onActivityStarted(@NonNull Activity activity) {} + + @Override + public void onActivityResumed(@NonNull Activity activity) { + foreground = (BaseActivity) activity; + } + + @Override + public void onActivityPaused(@NonNull Activity activity) { + foreground = null; + } + + @Override + public void onActivityStopped(@NonNull Activity activity) {} + + @Override + public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {} + + @Override + public void onActivityDestroyed(@NonNull Activity activity) {} }