Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3de0b9f authored by Hui Yu's avatar Hui Yu
Browse files

Debug missing foregrounsServiceType does not need procstate to be

foreground service.

This CL is a continuation of ag/10556520, If manifest missing foregrounsServiceType
 camera/microphone in manifest file and the process is asking for camera/microphone ops,
generate a WTF log.

Do this also for targetSdkVersion lower than R so we know they need it
if targetSdkVersion is R.

The process state does not need to be strictly foreground service state,
it can be any other foreground state, the process just have a foreground
service running.

Also change the WTF log frequency to up to one per 10 minutes because
we only see about 80 WTF logs per day. The server can handle more.

Bug: 150892326
Test: atest cts/tests/app/src/android/app/cts/ActivityManagerProcessStateTest.java
atest cts/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java

Change-Id: I35bf3768d0dc6ed6aa6011189f6b6d92b51029b5
parent 00a77668
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -1520,8 +1520,16 @@ public final class OomAdjuster {
                                        != 0 ? PROCESS_CAPABILITY_FOREGROUND_MICROPHONE
                                        : TEMP_PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;
                    } else {
                        capabilityFromFGS |= PROCESS_CAPABILITY_FOREGROUND_CAMERA
                                | PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;
                        // Remove fgsType check and assign PROCESS_CAPABILITY_FOREGROUND_CAMERA
                        // and MICROPHONE when finish debugging.
                        capabilityFromFGS |=
                                (fgsType & FOREGROUND_SERVICE_TYPE_CAMERA)
                                        != 0 ? PROCESS_CAPABILITY_FOREGROUND_CAMERA
                                        : TEMP_PROCESS_CAPABILITY_FOREGROUND_CAMERA;
                        capabilityFromFGS |=
                                (fgsType & FOREGROUND_SERVICE_TYPE_MICROPHONE)
                                        != 0 ? PROCESS_CAPABILITY_FOREGROUND_MICROPHONE
                                        : TEMP_PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;
                    }
                }
            }
+9 −5
Original line number Diff line number Diff line
@@ -670,15 +670,19 @@ public class AppOpsService extends IAppOpsService.Stub {
        }

        // TODO: remove this toast after feature development is done
        // If the procstate is foreground service and while-in-use permission is denied, show a
        // toast message to ask user to file a bugreport so we know how many apps are impacted by
        // the new background started foreground service while-in-use permission restriction.
        // For DEBUG_FGS_ALLOW_WHILE_IN_USE, if the procstate is foreground service and while-in-use
        // permission is denied, show a toast message and generate a WTF log so we know
        // how many apps are impacted by the new background started foreground service while-in-use
        // permission restriction.
        // For DEBUG_FGS_ENFORCE_TYPE, The process has a foreground service that does not have
        // camera/microphone foregroundServiceType in manifest file, and the process is asking
        // AppOps for camera/microphone ops, show a toast message and generate a WTF log.
        void maybeShowWhileInUseDebugToast(int op, int mode) {
            if (state != UID_STATE_FOREGROUND_SERVICE) {
            if (mode == DEBUG_FGS_ALLOW_WHILE_IN_USE && state != UID_STATE_FOREGROUND_SERVICE) {
                return;
            }
            final long now = System.currentTimeMillis();
            if (lastTimeShowDebugToast == 0 ||  now - lastTimeShowDebugToast > 3600000) {
            if (lastTimeShowDebugToast == 0 ||  now - lastTimeShowDebugToast > 600000) {
                lastTimeShowDebugToast = now;
                mHandler.sendMessage(PooledLambda.obtainMessage(
                        ActivityManagerInternal::showWhileInUseDebugToast,