9

Some devices have extra security features and check if an app is drawing on top of others, when showing a permission dialog.

I have a sidebar app, and my app has to be disabled, before users can accept a system dialog.

Questions

  • How am I supposed to handle this case?
  • Is there a way to listen for an "System dialog shown" event, so that I can remove my sidebar and a "System dialog finished" so that I know, i can continue with my sidebar overlay? I know, that it's enough to stop the service (you don't have to remove the permission), so this would be a solution as well

EDIT

One solution I can think of is following:

Using the AccessibilityService to check current foreground apps/views. There I will be able to check events that show me current foreground activities and even views...

My problems:

  • I don't know how to identify a permission dialog there.
  • Secondly, this forces me to ask the user to get this permission (which I want to avoid, but having a solution with this service, would already be an improvement for me, because some users give this permission to my app already - I would have to ask all then and explain the reason, which is something I can live with).
prom85
  • 16,896
  • 17
  • 122
  • 242

1 Answers1

0

As far as I know, what you want isn't possible. In a similar question, there is a solution to detect system dialogs, but I don't think it will work for your overlay (only for the currently active activity).

Another question suggests that it may be possible to monitor system dialogs via the ActivityManager class, but that API has been deprecated since LOLIPOP.

For these reasons, I suggest you to add a pause button to your overlay. Or even better, use a sticky notification with stop/start buttons so users can manually pause your overlay.


To identify system apps, you need the package name as explained in this answer:
public boolean isSystemApp(String packageName) {
    try {
        // Get packageinfo for target application
        PackageInfo targetPkgInfo = mPackageManager.getPackageInfo(
                packageName, PackageManager.GET_SIGNATURES);
        // Get packageinfo for system package
        PackageInfo sys = mPackageManager.getPackageInfo(
                "android", PackageManager.GET_SIGNATURES);
        // Match both packageinfo for there signatures
        return (targetPkgInfo != null && targetPkgInfo.signatures != null && sys.signatures[0]
                .equals(targetPkgInfo.signatures[0]));
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}
Community
  • 1
  • 1
Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76
  • I'll check the links... My app pauses itself sometimes already, when some user selected blacklisted apps are in the foreground, so I monitor this via `ActivityManager` (or the newer `AccessibilityService`) anyways already... I thought there may be a solution with the `AccessibilityService`at least... – prom85 Aug 11 '16 at 08:46
  • @prom85 Yes, it might also be possible with [AccessibilityService#getWindows()](https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html#getWindows()), which accordings to the documentation returns all windows shown. – Manuel Allenspach Aug 11 '16 at 08:53
  • I already have a pause/resume button in the notification... And getting the current foreground app/view is no problem, still, I don't know how to identify system windows... I've add some extra infos to my question related to the `AccessibilityService` solution... – prom85 Aug 11 '16 at 09:31
  • I updated my answer with more info. Use the package name or the ApplicationInfo of the app to find out whether the app is a system app. – Manuel Allenspach Aug 11 '16 at 09:47
  • This would mean, my app gets disabled whenever a system app is in front (when you show your device settings, run a preinstalled system app like maybe facebook/google/gmail, as those are installed as system apps sometimes and many more)... that does not work... I need to identify the SYSTEM DIALOG WINDOW only, no matter which app is starting it... – prom85 Aug 11 '16 at 12:09