Fix the while-in-use and BFSL bug
Bug: 276963716 Test: atest android.app.cts.ActivityManagerFgsBgStartTest Test: Manual tests - Test 1: Using the JobScheduler PoC app from b/243510362, make sure the FGS can't start. Here's the log from it: 04-13 22:36:30.575 1000 1809 1864 E ActivityManager: FGS while-in-use changed (b/276963716): old=PROC_STATE_PERSISTENT new=DENIED com.example.aospoc/.TestForegroundService 04-13 22:36:30.576 1000 1809 1864 W ActivityManager: Foreground service started from background can not have location/camera/microphone access: service com.example.aospoc/.TestForegroundService 04-13 22:36:30.576 1000 1809 2132 I am_wtf : [0,1809,system_server,-1,ActivityManager,FGS while-in-use changed (b/276963716): old=PROC_STATE_PERSISTENT new=DENIED com.example.aospoc/.TestForegroundService] 04-13 22:36:30.576 1000 1809 1864 W ActivityManager: Background started FGS: Disallowed [callingPackage: com.example.aospoc; callingUid: 10268; uidState: TRNB; uidBFSL: n/a; intent: Intent { cmp=com.example.aospoc/.TestForegroundService }; code:DENIED; tempAllowListReason:<null>; targetSdkVersion:33; callerTargetSdkVersion:33; startForegroundCount:0; bindFromPackage:null: isBindService:false]; startForegroundDelayMs:0; started: false; num_bindings: 1; wasForeground: false; resetNeeded:false 04-13 22:36:30.576 1000 1809 1864 W ActivityManager: Service.startForeground() not allowed due to mAllowStartForeground false: service com.example.aospoc/.TestForegroundService - Test 2:Add BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS to JobServiceContext and make sure the FGS can start, and it has allowWhileInUsePermissionInFgs=true. 04-13 22:37:47.180 1000 1809 4010 E ActivityManager: FGS while-in-use changed (b/276963716): old=PROC_STATE_PERSISTENT new=ACTIVITY_STARTER com.example.aospoc/.TestForegroundService 04-13 22:37:47.181 1000 1809 2132 I am_wtf : [0,1809,system_server,-1,ActivityManager,FGS while-in-use changed (b/276963716): old=PROC_STATE_PERSISTENT new=ACTIVITY_STARTER com.example.aospoc/.TestForegroundService] 04-13 22:37:47.181 1000 1809 4010 I ActivityManager: Background started FGS: Allowed [callingPackage: com.example.aospoc; callingUid: 10268; uidState: TRNB; uidBFSL: n/a; intent: Intent { cmp=com.example.aospoc/.TestForegroundService }; code:ACTIVITY_STARTER; tempAllowListReason:<null>; targetSdkVersion:33; callerTargetSdkVersion:33; startForegroundCount:0; bindFromPackage:null: isBindService:false]; startForegroundDelayMs:0; started: false; num_bindings: 2; wasForeground: false; resetNeeded:false 04-13 22:37:47.181 1000 1809 2132 I am_wtf : [0,1809,system_server,-1,ActivityManager,Background started FGS: Allowed [callingPackage: com.example.aospoc; callingUid: 10268; uidState: TRNB; uidBFSL: n/a; intent: Intent { cmp=com.example.aospoc/.TestForegroundService }; code:ACTIVITY_STARTER; tempAllowListReason:<null>; targetSdkVersion:33; callerTargetSdkVersion:33; startForegroundCount:0; bindFromPackage:null: isBindService:false]; startForegroundDelayMs:0; started: false; num_bindings: 2; wasForeground: false; resetNeeded:false] 04-13 22:37:47.182 1000 1809 4010 W ActivityManager: Starting FGS with type microphone code=4 callerApp=ProcessRecord{64baff6 19352:com.example.aospoc/u0a268} targetSDK=33 requiredPermissions=all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MICROPHONE] any of the permissions allOf=false [android.permission.CAPTURE_AUDIO_HOTWORD, android.permission.CAPTURE_AUDIO_OUTPUT, android.permission.CAPTURE_MEDIA_OUTPUT, android.permission.CAPTURE_TUNER_AUDIO_INPUT, android.permission.CAPTURE_VOICE_COMMUNICATION_OUTPUT, android.permission.RECORD_AUDIO] - Test 3: Same as test 2, but update the PoC app and start another FGS from the job service. This should succeed. Here's the log: 04-13 22:38:43.168 1000 1809 3206 I ActivityManager: Background started FGS: Allowed [callingPackage: com.example.aospoc; callingUid: 10268; uidState: TRNB; uidBFSL: n/a; intent: Intent { cmp=com.example.aospoc/.TestForegroundService2 }; code:ACTIVITY_STARTER; tempAllowListReason:<null>; targetSdkVersion:33; callerTargetSdkVersion:33; startForegroundCount:0; bindFromPackage:null: isBindService:false] Change-Id: I52f97e0148260de678d9ee8eac4dd9f527966e08
Loading
Please register or sign in to comment