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

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

Change-Id: I3bfd2bfb535e9fa7b9c0f287d1fe51a6e06beeb5
This commit is contained in:
Hui Yu
2021-06-15 17:49:18 +00:00
committed by Automerger Merge Worker
2 changed files with 26 additions and 7 deletions

View File

@@ -122,6 +122,7 @@ import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.os.PowerExemptionManager;
import android.os.PowerExemptionManager.ReasonCode; import android.os.PowerExemptionManager.ReasonCode;
import android.os.Process; import android.os.Process;
import android.os.RemoteCallback; import android.os.RemoteCallback;
@@ -1850,7 +1851,6 @@ public final class ActiveServices {
notification.flags |= Notification.FLAG_FOREGROUND_SERVICE; notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
r.foregroundNoti = notification; r.foregroundNoti = notification;
r.foregroundServiceType = foregroundServiceType; r.foregroundServiceType = foregroundServiceType;
boolean enterForeground = false;
if (!r.isForeground) { if (!r.isForeground) {
final ServiceMap smap = getServiceMapLocked(r.userId); final ServiceMap smap = getServiceMapLocked(r.userId);
if (smap != null) { if (smap != null) {
@@ -1877,7 +1877,12 @@ public final class ActiveServices {
} }
r.isForeground = true; r.isForeground = true;
r.mLogEntering = 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.mStartForegroundCount++;
r.mFgsEnterTime = SystemClock.uptimeMillis(); r.mFgsEnterTime = SystemClock.uptimeMillis();
if (!stopProcStatsOp) { if (!stopProcStatsOp) {
@@ -6235,12 +6240,22 @@ public final class ActiveServices {
r.packageName, mAm.mConstants.mFgsAtomSampleRate)) { r.packageName, mAm.mConstants.mFgsAtomSampleRate)) {
return; 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, FrameworkStatsLog.write(FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED,
r.appInfo.uid, r.appInfo.uid,
r.shortInstanceName, r.shortInstanceName,
state, state,
r.mAllowWhileInUsePermissionInFgs, allowWhileInUsePermissionInFgs,
r.mAllowStartForeground, fgsStartReasonCode,
r.appInfo.targetSdkVersion, r.appInfo.targetSdkVersion,
r.mRecentCallingUid, r.mRecentCallingUid,
r.mRecentCallerApplicationInfo != null r.mRecentCallerApplicationInfo != null

View File

@@ -18,7 +18,7 @@ package com.android.server.am;
import static android.app.PendingIntent.FLAG_IMMUTABLE; import static android.app.PendingIntent.FLAG_IMMUTABLE;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; 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_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; 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.Binder;
import android.os.Build; import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.os.PowerWhitelistManager; import android.os.PowerExemptionManager;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.Settings; 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. // allow while-in-use permissions in foreground service or not.
// while-in-use permissions in FGS started from background might be restricted. // while-in-use permissions in FGS started from background might be restricted.
boolean mAllowWhileInUsePermissionInFgs; 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. // the most recent package that start/bind this service.
String mRecentCallingPackage; 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 // allow the service becomes foreground service? Service started from background may not be
// allowed to become a foreground service. // 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. // Debug info why mAllowStartForeground is allowed or denied.
String mInfoAllowStartForeground; String mInfoAllowStartForeground;
// Debug info if mAllowStartForeground is allowed because of a temp-allowlist. // Debug info if mAllowStartForeground is allowed because of a temp-allowlist.