Skip to content
Commit 6706c1ac authored by Hui Yu's avatar Hui Yu
Browse files

Background startForeground() improvement.

Previously Service.startForeground() can be called from a background
service and startForeground()/stopForeground() can be called repeatly
from background. The BG-FGS-launch will add more restriction on this.

1. If the first 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 and mAllowStartForeground flags again.
2. At Service.stopForeground() call, mAllowWhileInUsePermissionInFgs and
mAllowStartForeground flags should be reset to false so FGS while-in-use
 permission and FGS BG start 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 and mAllowStartForeground
flags again.

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: Idc88f274c7a323d175d65bb47eca041772ae9bb7
parent e3e4c1f9
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