Skip to content
Commit 9a34b6ae authored by Hui Yu's avatar Hui Yu
Browse files

BG-FGS-start while-in-use permission restriction improvement.

Foreground service started from background shall not have while-in-use
access like location/camera/microphone.

Previously we set mAllowWhileInUsePermissionInFgs only at service start
by startService() or bindService() command. But after
service start, the Service.startForeground() call may be some time later
and at that time the caller may not be in the foreground any more. This
CL will add further restriction on that.

1. If the first Service.startForeground() call is more than 10 seconds (can be
configured by DeviceConfig key "fgs_start_foreground_timeout") after the
Context.startService() call, check the service's app proc state and set
mAllowWhileInUsePermissionInFgs again.
2. At Service.stopForeground() call, mAllowWhileInUsePermissionInFgs
should be reset to false so FGS while-in-use permission is not allowed.
3. After Context.startForegroundService()(or Context.startService()) ->
Service.startForeground() -> Service.stopForeground(), the second or
more times Service.startForeground() is called, check the service's
app proc state and set mAllowWhileInUsePermissionInFgs again.

This CL is the backport of ag/Idc88f274c7a323d175d65bb47eca041772ae9bb7 from
S branch.

Bug: 183147114
Bug: 183204439
Test: atest cts/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java#testStartForegroundTimeout
Test: atest cts/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java#testSecondStartForeground
Change-Id: I0aca484e5a0dd051bbeac379d30b0fb4ecfa2da0
Merged-In: Idc88f274c7a323d175d65bb47eca041772ae9bb7
parent dd894ae8
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment