Re-add activity check

Causes false disables otherwise.
This commit is contained in:
d8ahazard 2016-09-26 12:51:57 -05:00 committed by topjohnwu
parent 3adc7ca22a
commit c553312fd5

View File

@ -7,6 +7,7 @@ import android.app.PendingIntent;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
@ -61,6 +62,9 @@ public class MonitorService extends AccessibilityService {
event.getPackageName().toString(), event.getPackageName().toString(),
event.getClassName().toString() event.getClassName().toString()
); );
ActivityInfo activityInfo = tryGetActivity(componentName);
boolean isActivity = activityInfo != null;
if (isActivity) {
Logger.dh("MonitorService: CurrentActivity: " + event.getPackageName()); Logger.dh("MonitorService: CurrentActivity: " + event.getPackageName());
String mPackage = componentName.getPackageName(); String mPackage = componentName.getPackageName();
@ -77,6 +81,15 @@ public class MonitorService extends AccessibilityService {
} }
} }
} }
}
private ActivityInfo tryGetActivity(ComponentName componentName) {
try {
return getPackageManager().getActivityInfo(componentName, 0);
} catch (PackageManager.NameNotFoundException e) {
return null;
}
}
private String getAppName(String packageName) { private String getAppName(String packageName) {
PackageManager pkManager = getPackageManager(); PackageManager pkManager = getPackageManager();