From c553312fd5ec77c68423e26757d9375f37339d4b Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Mon, 26 Sep 2016 12:51:57 -0500 Subject: [PATCH] Re-add activity check Causes false disables otherwise. --- .../magisk/services/MonitorService.java | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/services/MonitorService.java b/app/src/main/java/com/topjohnwu/magisk/services/MonitorService.java index f56e8cf4f..e8a61e293 100644 --- a/app/src/main/java/com/topjohnwu/magisk/services/MonitorService.java +++ b/app/src/main/java/com/topjohnwu/magisk/services/MonitorService.java @@ -7,6 +7,7 @@ import android.app.PendingIntent; import android.content.ComponentName; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Build; @@ -61,23 +62,35 @@ public class MonitorService extends AccessibilityService { event.getPackageName().toString(), event.getClassName().toString() ); - Logger.dh("MonitorService: CurrentActivity: " + event.getPackageName()); + ActivityInfo activityInfo = tryGetActivity(componentName); + boolean isActivity = activityInfo != null; + if (isActivity) { + Logger.dh("MonitorService: CurrentActivity: " + event.getPackageName()); - String mPackage = componentName.getPackageName(); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - if (Utils.autoToggleEnabled(getApplicationContext())) { - Set setBlackList = prefs.getStringSet("auto_blacklist", null); + String mPackage = componentName.getPackageName(); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + if (Utils.autoToggleEnabled(getApplicationContext())) { + Set setBlackList = prefs.getStringSet("auto_blacklist", null); - if (setBlackList != null) { - disableroot = setBlackList.contains(mPackage); - ForceRoot(!disableroot); - String appFriendly = getAppName(mPackage); - ShowNotification(disableroot, appFriendly); + if (setBlackList != null) { + disableroot = setBlackList.contains(mPackage); + ForceRoot(!disableroot); + String appFriendly = getAppName(mPackage); + ShowNotification(disableroot, appFriendly); + } } } } } + private ActivityInfo tryGetActivity(ComponentName componentName) { + try { + return getPackageManager().getActivityInfo(componentName, 0); + } catch (PackageManager.NameNotFoundException e) { + return null; + } + } + private String getAppName(String packageName) { PackageManager pkManager = getPackageManager(); ApplicationInfo appInfo;