Loading core/java/android/app/ActivityManagerInternal.java +24 −0 Original line number Diff line number Diff line Loading @@ -1164,6 +1164,30 @@ public abstract class ActivityManagerInternal { */ public abstract void logFgsApiEnd(int apiType, int uid, int pid); /** * Checks whether an app will be able to start a foreground service or not. * * @param pid The process id belonging to the app to be checked. * @param uid The UID of the app to be checked. * @param packageName The package name of the app to be checked. * @return whether the app will be able to start a foreground service or not. */ public abstract boolean canStartForegroundService( int pid, int uid, @NonNull String packageName); /** * Returns {@code true} if a foreground service started by an uid is allowed to have * while-in-use permissions. * * @param pid The process id belonging to the app to be checked. * @param uid The UID of the app to be checked. * @param packageName The package name of the app to be checked. * @return whether the foreground service is allowed to have while-in-use permissions. * @hide */ public abstract boolean canAllowWhileInUsePermissionInFgs( int pid, int uid, @NonNull String packageName); /** * Temporarily allow foreground service started by an uid to have while-in-use permission * for durationMs. Loading services/core/java/com/android/server/media/MediaSessionService.java +9 −10 Original line number Diff line number Diff line Loading @@ -89,12 +89,10 @@ import android.view.ViewConfiguration; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.media.flags.Flags; import com.android.server.LocalManagerRegistry; import com.android.server.LocalServices; import com.android.server.SystemService; import com.android.server.Watchdog; import com.android.server.Watchdog.Monitor; import com.android.server.am.ActivityManagerLocal; import java.io.FileDescriptor; import java.io.PrintWriter; Loading Loading @@ -146,7 +144,6 @@ public class MediaSessionService extends SystemService implements Monitor { private KeyguardManager mKeyguardManager; private AudioManager mAudioManager; private boolean mHasFeatureLeanback; private ActivityManagerLocal mActivityManagerLocal; private ActivityManagerInternal mActivityManagerInternal; // The FullUserRecord of the current users. (i.e. The foreground user that isn't a profile) Loading Loading @@ -232,7 +229,6 @@ public class MediaSessionService extends SystemService implements Monitor { NotificationManager.ACTION_NOTIFICATION_LISTENER_ENABLED_CHANGED); mContext.registerReceiver(mNotificationListenerEnabledChangedReceiver, filter); mActivityManagerLocal = LocalManagerRegistry.getManager(ActivityManagerLocal.class); mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); } Loading Loading @@ -585,18 +581,21 @@ public class MediaSessionService extends SystemService implements Monitor { try { MediaServerUtils.enforcePackageName(mContext, callingPackage, callingUid); if (targetUid != callingUid) { boolean canAllowWhileInUse = mActivityManagerLocal .canAllowWhileInUsePermissionInFgs(callingPid, callingUid, callingPackage); boolean canStartFgs = canAllowWhileInUse || mActivityManagerLocal.canStartForegroundService(callingPid, callingUid, callingPackage); boolean canAllowWhileInUse = mActivityManagerInternal.canAllowWhileInUsePermissionInFgs( callingPid, callingUid, callingPackage); boolean canStartFgs = canAllowWhileInUse || mActivityManagerInternal.canStartForegroundService( callingPid, callingUid, callingPackage); Log.i(TAG, "tempAllowlistTargetPkgIfPossible callingPackage:" + callingPackage + " targetPackage:" + targetPackage + " reason:" + reason + (canAllowWhileInUse ? " [WIU]" : "") + (canStartFgs ? " [FGS]" : "")); if (canAllowWhileInUse) { mActivityManagerLocal.tempAllowWhileInUsePermissionInFgs(targetUid, mActivityManagerInternal.tempAllowWhileInUsePermissionInFgs( targetUid, MediaSessionDeviceConfig .getMediaSessionCallbackFgsWhileInUseTempAllowDurationMs()); } Loading Loading
core/java/android/app/ActivityManagerInternal.java +24 −0 Original line number Diff line number Diff line Loading @@ -1164,6 +1164,30 @@ public abstract class ActivityManagerInternal { */ public abstract void logFgsApiEnd(int apiType, int uid, int pid); /** * Checks whether an app will be able to start a foreground service or not. * * @param pid The process id belonging to the app to be checked. * @param uid The UID of the app to be checked. * @param packageName The package name of the app to be checked. * @return whether the app will be able to start a foreground service or not. */ public abstract boolean canStartForegroundService( int pid, int uid, @NonNull String packageName); /** * Returns {@code true} if a foreground service started by an uid is allowed to have * while-in-use permissions. * * @param pid The process id belonging to the app to be checked. * @param uid The UID of the app to be checked. * @param packageName The package name of the app to be checked. * @return whether the foreground service is allowed to have while-in-use permissions. * @hide */ public abstract boolean canAllowWhileInUsePermissionInFgs( int pid, int uid, @NonNull String packageName); /** * Temporarily allow foreground service started by an uid to have while-in-use permission * for durationMs. Loading
services/core/java/com/android/server/media/MediaSessionService.java +9 −10 Original line number Diff line number Diff line Loading @@ -89,12 +89,10 @@ import android.view.ViewConfiguration; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.media.flags.Flags; import com.android.server.LocalManagerRegistry; import com.android.server.LocalServices; import com.android.server.SystemService; import com.android.server.Watchdog; import com.android.server.Watchdog.Monitor; import com.android.server.am.ActivityManagerLocal; import java.io.FileDescriptor; import java.io.PrintWriter; Loading Loading @@ -146,7 +144,6 @@ public class MediaSessionService extends SystemService implements Monitor { private KeyguardManager mKeyguardManager; private AudioManager mAudioManager; private boolean mHasFeatureLeanback; private ActivityManagerLocal mActivityManagerLocal; private ActivityManagerInternal mActivityManagerInternal; // The FullUserRecord of the current users. (i.e. The foreground user that isn't a profile) Loading Loading @@ -232,7 +229,6 @@ public class MediaSessionService extends SystemService implements Monitor { NotificationManager.ACTION_NOTIFICATION_LISTENER_ENABLED_CHANGED); mContext.registerReceiver(mNotificationListenerEnabledChangedReceiver, filter); mActivityManagerLocal = LocalManagerRegistry.getManager(ActivityManagerLocal.class); mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); } Loading Loading @@ -585,18 +581,21 @@ public class MediaSessionService extends SystemService implements Monitor { try { MediaServerUtils.enforcePackageName(mContext, callingPackage, callingUid); if (targetUid != callingUid) { boolean canAllowWhileInUse = mActivityManagerLocal .canAllowWhileInUsePermissionInFgs(callingPid, callingUid, callingPackage); boolean canStartFgs = canAllowWhileInUse || mActivityManagerLocal.canStartForegroundService(callingPid, callingUid, callingPackage); boolean canAllowWhileInUse = mActivityManagerInternal.canAllowWhileInUsePermissionInFgs( callingPid, callingUid, callingPackage); boolean canStartFgs = canAllowWhileInUse || mActivityManagerInternal.canStartForegroundService( callingPid, callingUid, callingPackage); Log.i(TAG, "tempAllowlistTargetPkgIfPossible callingPackage:" + callingPackage + " targetPackage:" + targetPackage + " reason:" + reason + (canAllowWhileInUse ? " [WIU]" : "") + (canStartFgs ? " [FGS]" : "")); if (canAllowWhileInUse) { mActivityManagerLocal.tempAllowWhileInUsePermissionInFgs(targetUid, mActivityManagerInternal.tempAllowWhileInUsePermissionInFgs( targetUid, MediaSessionDeviceConfig .getMediaSessionCallbackFgsWhileInUseTempAllowDurationMs()); } Loading