This sample provides an Android sample application for reproducing a bug found on Android 11.
In Android 11, new one-time permissions have been introduced for Location, Microphone and Camera permissions. With this option, as soon as the user leaves the application, the permission is revoked (more details can be found here). The problem is that after a short amount of time when the app is no longer in the foreground (it is not necessary to kill the app, just minimizing is enough), all future scheduled alarms or jobs are removed, as if the app was force killed. This only happens with this level of permission. Denying or providing other levels keep the previously scheduled alarms or jobs, as expected.
This single activity app schedules an alarm to ring in the next five minutes, as well as a job to trigger in between 5-6 minutes. The screen has three buttons, each triggering the corresponding permission request. The JobService and BroadcastReceiver classes only log that they have been triggered.
We have reproduced this in the Beta 3 build, in a Pixel 2 emulator with the RPB3.200720.005 build number. It can be reproduced after the following steps:
- Whenever the app is started, it is possible to run both
adb shell dumpsys alarm | grep com.example.permissions.app
andadb shell dumpsys jobscheduler | grep com.example.permissions.app
to see that both the alarm and the job are scheduled; - Click in any of the buttons and grant the one-time permission level;
- Minimize the app (you can go to the home screen or open other app);
- After around a minute, run both
adb shell dumpsys alarm | grep com.example.permissions.app
andadb shell dumpsys jobscheduler | grep com.example.permissions.app
. The alarm and job will no longer appear; - Waiting the original scheduled times for both job and alarm (with lenience for system delays) will show that they won't be triggered.