Android R One-Time Permission Expiration Sometimes Kills Alarms, Jobs, More

UPDATE 2020-09-13: It turns out that the problem listed here is really an Android Studio problem.

Android R adds one-time permissions to the user experience. The idea is that the user can grant a runtime permission for a while. I thought that it was for the current process invocation, but it appears as though you lose the permission if your app moves to the background for a while as well, where “a while” is less than a minute.

Worse, as I found out first from this Stack Overflow question, we lose a lot more in less than a minute… at least sometimes.

That question, and the associated entry in the issue tracker, point out that alarms and jobs get canceled when the one-time permissions get revoked. I did more testing, based on their sample app, and IMHO the effect feels a lot like a “Force Stop”. Specifically, we can no longer respond to broadcasts registered in the manifest, even for those that are on the implicit broadcast exception whitelist, such as ACTION_LOCALE_CHANGED. The only thing that I know of that would explain all those behaviors is a “Force Stop”, though it is certainly possible that there is something else that happens to look similar.

In my light testing, the overall effect was inconsistent. I could get it to happen reliably the first time I tried a one-time permission for an app installation; after that it was “hit or miss”.

Android developers have been dealing with rogue “Force Stop” operations for years. Originally, users could only cause this via an app’s screen in the Settings app. Then, a few device manufacturers decided to have their own task manager apps do a “Force Stop”. Eventually, that led them to have “Force Stop” take effect when swiping the task off the overview screen. But, this is the first time that I can think of that Google is doing this sort of unexpected “Force Stop”.

If you have done your own analysis of this problem and can add further evidence (more than “me too!”), please contribute to the issue. Frankly, I suspect that we are doomed, given that it is very late in the Android R beta cycle. But, maybe we will get lucky, and our contributions can get this cleared up, or at least documented, by the time Android 11 ships in stable form.

Find out about new posts on the CommonsBlog via the Atom feed, or follow @CommonsWare on Twitter!