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

Commit 4174b46a authored by Hui Yu's avatar Hui Yu Committed by Automerger Merge Worker
Browse files

Merge "Add a new field mAllowStartForegroundAtEntering." into sc-dev am: 507b0f7b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14970592

Change-Id: Id2c3d4568d014a021db9cfa3651dad7c5e11f696
parents 83fe2b33 507b0f7b
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -122,6 +122,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.PowerExemptionManager;
import android.os.PowerExemptionManager.ReasonCode;
import android.os.Process;
import android.os.RemoteCallback;
@@ -1850,7 +1851,6 @@ public final class ActiveServices {
                    notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
                    r.foregroundNoti = notification;
                    r.foregroundServiceType = foregroundServiceType;
                    boolean enterForeground = false;
                    if (!r.isForeground) {
                        final ServiceMap smap = getServiceMapLocked(r.userId);
                        if (smap != null) {
@@ -1877,7 +1877,12 @@ public final class ActiveServices {
                        }
                        r.isForeground = true;
                        r.mLogEntering = true;
                        enterForeground = true;
                        // The logging of FOREGROUND_SERVICE_STATE_CHANGED__STATE__ENTER event could
                        // be deferred, make a copy of mAllowStartForeground and
                        // mAllowWhileInUsePermissionInFgs.
                        r.mAllowStartForegroundAtEntering = r.mAllowStartForeground;
                        r.mAllowWhileInUsePermissionInFgsAtEntering =
                                r.mAllowWhileInUsePermissionInFgs;
                        r.mStartForegroundCount++;
                        r.mFgsEnterTime = SystemClock.uptimeMillis();
                        if (!stopProcStatsOp) {
@@ -6235,12 +6240,22 @@ public final class ActiveServices {
                r.packageName, mAm.mConstants.mFgsAtomSampleRate)) {
            return;
        }
        boolean allowWhileInUsePermissionInFgs;
        @PowerExemptionManager.ReasonCode int fgsStartReasonCode;
        if (state == FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED__STATE__ENTER
                || state == FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED__STATE__EXIT) {
            allowWhileInUsePermissionInFgs = r.mAllowWhileInUsePermissionInFgsAtEntering;
            fgsStartReasonCode = r.mAllowStartForegroundAtEntering;
        } else {
            allowWhileInUsePermissionInFgs = r.mAllowWhileInUsePermissionInFgs;
            fgsStartReasonCode = r.mAllowStartForeground;
        }
        FrameworkStatsLog.write(FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED,
                r.appInfo.uid,
                r.shortInstanceName,
                state,
                r.mAllowWhileInUsePermissionInFgs,
                r.mAllowStartForeground,
                allowWhileInUsePermissionInFgs,
                fgsStartReasonCode,
                r.appInfo.targetSdkVersion,
                r.mRecentCallingUid,
                r.mRecentCallerApplicationInfo != null
+7 −3
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package com.android.server.am;

import static android.app.PendingIntent.FLAG_IMMUTABLE;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
import static android.os.PowerWhitelistManager.REASON_DENIED;
import static android.os.PowerExemptionManager.REASON_DENIED;

import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
@@ -37,7 +37,7 @@ import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.os.PowerWhitelistManager;
import android.os.PowerExemptionManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
@@ -153,6 +153,8 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
    // allow while-in-use permissions in foreground service or not.
    // while-in-use permissions in FGS started from background might be restricted.
    boolean mAllowWhileInUsePermissionInFgs;
    // A copy of mAllowWhileInUsePermissionInFgs's value when the service is entering FGS state.
    boolean mAllowWhileInUsePermissionInFgsAtEntering;

    // the most recent package that start/bind this service.
    String mRecentCallingPackage;
@@ -172,7 +174,9 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN

    // allow the service becomes foreground service? Service started from background may not be
    // allowed to become a foreground service.
    @PowerWhitelistManager.ReasonCode int mAllowStartForeground = REASON_DENIED;
    @PowerExemptionManager.ReasonCode int mAllowStartForeground = REASON_DENIED;
    // A copy of mAllowStartForeground's value when the service is entering FGS state.
    @PowerExemptionManager.ReasonCode int mAllowStartForegroundAtEntering = REASON_DENIED;
    // Debug info why mAllowStartForeground is allowed or denied.
    String mInfoAllowStartForeground;
    // Debug info if mAllowStartForeground is allowed because of a temp-allowlist.