1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.app; 18 19 import static android.app.ActivityManager.StopUserOnSwitch; 20 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.annotation.UserIdInt; 24 import android.app.ActivityManager.ProcessCapability; 25 import android.content.ComponentName; 26 import android.content.IIntentReceiver; 27 import android.content.IIntentSender; 28 import android.content.Intent; 29 import android.content.pm.ActivityInfo; 30 import android.content.pm.ActivityPresentationInfo; 31 import android.content.pm.ApplicationInfo; 32 import android.content.pm.UserInfo; 33 import android.net.Uri; 34 import android.os.Bundle; 35 import android.os.IBinder; 36 import android.os.PowerExemptionManager.ReasonCode; 37 import android.os.PowerExemptionManager.TempAllowListType; 38 import android.os.TransactionTooLargeException; 39 import android.os.WorkSource; 40 import android.util.ArraySet; 41 42 import java.util.ArrayList; 43 import java.util.List; 44 import java.util.Map; 45 import java.util.Set; 46 47 /** 48 * Activity manager local system service interface. 49 * 50 * @hide Only for use within the system server. 51 */ 52 public abstract class ActivityManagerInternal { 53 54 public enum ServiceNotificationPolicy { 55 /** 56 * The Notification is not associated with any foreground service. 57 */ 58 NOT_FOREGROUND_SERVICE, 59 /** 60 * The Notification is associated with a foreground service, but the 61 * notification system should handle it just like non-FGS notifications. 62 */ 63 SHOW_IMMEDIATELY, 64 /** 65 * The Notification is associated with a foreground service, and the 66 * notification system should ignore it unless it has already been shown (in 67 * which case it should be used to update the currently displayed UI). 68 */ 69 UPDATE_ONLY 70 } 71 72 // Access modes for handleIncomingUser. 73 public static final int ALLOW_NON_FULL = 0; 74 /** 75 * Allows access to a caller with {@link android.Manifest.permission#INTERACT_ACROSS_USERS} 76 * if in the same profile group. 77 * Otherwise, {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} is required. 78 */ 79 public static final int ALLOW_NON_FULL_IN_PROFILE = 1; 80 public static final int ALLOW_FULL_ONLY = 2; 81 /** 82 * Allows access to a caller with {@link android.Manifest.permission#INTERACT_ACROSS_PROFILES} 83 * or {@link android.Manifest.permission#INTERACT_ACROSS_USERS} if in the same profile group. 84 * Otherwise, {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} is required. 85 */ 86 public static final int ALLOW_ALL_PROFILE_PERMISSIONS_IN_PROFILE = 3; 87 88 /** 89 * Verify that calling app has access to the given provider. 90 */ checkContentProviderAccess(String authority, @UserIdInt int userId)91 public abstract String checkContentProviderAccess(String authority, @UserIdInt int userId); 92 93 /** 94 * Verify that calling UID has access to the given provider. 95 */ checkContentProviderUriPermission(Uri uri, @UserIdInt int userId, int callingUid, int modeFlags)96 public abstract int checkContentProviderUriPermission(Uri uri, @UserIdInt int userId, 97 int callingUid, int modeFlags); 98 99 // Called by the power manager. onWakefulnessChanged(int wakefulness)100 public abstract void onWakefulnessChanged(int wakefulness); 101 102 /** 103 * @return {@code true} if process start is successful, {@code false} otherwise. 104 */ startIsolatedProcess(String entryPoint, String[] mainArgs, String processName, String abiOverride, int uid, Runnable crashHandler)105 public abstract boolean startIsolatedProcess(String entryPoint, String[] mainArgs, 106 String processName, String abiOverride, int uid, Runnable crashHandler); 107 108 /** 109 * Called when a user has been deleted. This can happen during normal device usage 110 * or just at startup, when partially removed users are purged. Any state persisted by the 111 * ActivityManager should be purged now. 112 * 113 * @param userId The user being cleaned up. 114 */ onUserRemoved(@serIdInt int userId)115 public abstract void onUserRemoved(@UserIdInt int userId); 116 117 /** 118 * Kill foreground apps from the specified user. 119 */ killForegroundAppsForUser(@serIdInt int userId)120 public abstract void killForegroundAppsForUser(@UserIdInt int userId); 121 122 /** 123 * Sets how long a {@link PendingIntent} can be temporarily allowlisted to bypass restrictions 124 * such as Power Save mode. 125 * @param target 126 * @param allowlistToken 127 * @param duration temp allowlist duration in milliseconds. 128 * @param type temp allowlist type defined at {@link TempAllowListType} 129 * @param reasonCode one of {@link ReasonCode} 130 * @param reason A human-readable reason for logging purposes. 131 */ setPendingIntentAllowlistDuration(IIntentSender target, IBinder allowlistToken, long duration, @TempAllowListType int type, @ReasonCode int reasonCode, @Nullable String reason)132 public abstract void setPendingIntentAllowlistDuration(IIntentSender target, 133 IBinder allowlistToken, long duration, @TempAllowListType int type, 134 @ReasonCode int reasonCode, @Nullable String reason); 135 136 /** 137 * Returns the flags set for a {@link PendingIntent}. 138 */ getPendingIntentFlags(IIntentSender target)139 public abstract int getPendingIntentFlags(IIntentSender target); 140 141 /** 142 * Allows a {@link PendingIntent} to start activities from background. 143 */ setPendingIntentAllowBgActivityStarts( IIntentSender target, IBinder allowlistToken, int flags)144 public abstract void setPendingIntentAllowBgActivityStarts( 145 IIntentSender target, IBinder allowlistToken, int flags); 146 147 /** 148 * Voids {@link PendingIntent}'s privilege to start activities from background. 149 */ clearPendingIntentAllowBgActivityStarts(IIntentSender target, IBinder allowlistToken)150 public abstract void clearPendingIntentAllowBgActivityStarts(IIntentSender target, 151 IBinder allowlistToken); 152 153 /** 154 * Allow DeviceIdleController to tell us about what apps are allowlisted. 155 */ setDeviceIdleAllowlist(int[] allAppids, int[] exceptIdleAppids)156 public abstract void setDeviceIdleAllowlist(int[] allAppids, int[] exceptIdleAppids); 157 158 /** 159 * Update information about which app IDs are on the temp allowlist. 160 * @param appids the updated list of appIds in temp allowlist. 161 * If null, it is to update only changingUid. 162 * @param changingUid uid to add or remove to temp allowlist. 163 * @param adding true to add to temp allowlist, false to remove from temp allowlist. 164 * @param durationMs when adding is true, the duration to be in temp allowlist. 165 * @param type temp allowlist type defined at {@link TempAllowListType}. 166 * @param reasonCode one of {@link ReasonCode} 167 * @param reason A human-readable reason for logging purposes. 168 * @param callingUid the callingUid that setup this temp allowlist, only valid when param adding 169 * is true. 170 */ updateDeviceIdleTempAllowlist(@ullable int[] appids, int changingUid, boolean adding, long durationMs, @TempAllowListType int type, @ReasonCode int reasonCode, @Nullable String reason, int callingUid)171 public abstract void updateDeviceIdleTempAllowlist(@Nullable int[] appids, int changingUid, 172 boolean adding, long durationMs, @TempAllowListType int type, 173 @ReasonCode int reasonCode, 174 @Nullable String reason, int callingUid); 175 176 /** 177 * Get the procstate for the UID. The return value will be between 178 * {@link ActivityManager#MIN_PROCESS_STATE} and {@link ActivityManager#MAX_PROCESS_STATE}. 179 * Note if the UID doesn't exist, it'll return {@link ActivityManager#PROCESS_STATE_NONEXISTENT} 180 * (-1). 181 */ getUidProcessState(int uid)182 public abstract int getUidProcessState(int uid); 183 184 /** 185 * Get a map of pid and package name that process of that pid Android/data and Android/obb 186 * directory is not mounted to lowerfs. 187 */ getProcessesWithPendingBindMounts(int userId)188 public abstract Map<Integer, String> getProcessesWithPendingBindMounts(int userId); 189 190 /** 191 * @return {@code true} if system is ready, {@code false} otherwise. 192 */ isSystemReady()193 public abstract boolean isSystemReady(); 194 195 /** 196 * Sets if the given pid has an overlay UI or not. 197 * 198 * @param pid The pid we are setting overlay UI for. 199 * @param hasOverlayUi True if the process has overlay UI. 200 * @see android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY 201 */ setHasOverlayUi(int pid, boolean hasOverlayUi)202 public abstract void setHasOverlayUi(int pid, boolean hasOverlayUi); 203 204 /** 205 * Called after the network policy rules are updated by 206 * {@link com.android.server.net.NetworkPolicyManagerService} for a specific {@param uid} and 207 * {@param procStateSeq}. 208 */ notifyNetworkPolicyRulesUpdated(int uid, long procStateSeq)209 public abstract void notifyNetworkPolicyRulesUpdated(int uid, long procStateSeq); 210 211 /** 212 * @return true if runtime was restarted, false if it's normal boot 213 */ isRuntimeRestarted()214 public abstract boolean isRuntimeRestarted(); 215 216 /** 217 * Returns if more users can be started without stopping currently running users. 218 */ canStartMoreUsers()219 public abstract boolean canStartMoreUsers(); 220 221 /** 222 * Sets the user switcher message for switching from {@link android.os.UserHandle#SYSTEM}. 223 */ setSwitchingFromSystemUserMessage(String switchingFromSystemUserMessage)224 public abstract void setSwitchingFromSystemUserMessage(String switchingFromSystemUserMessage); 225 226 /** 227 * Sets the user switcher message for switching to {@link android.os.UserHandle#SYSTEM}. 228 */ setSwitchingToSystemUserMessage(String switchingToSystemUserMessage)229 public abstract void setSwitchingToSystemUserMessage(String switchingToSystemUserMessage); 230 231 /** 232 * Returns maximum number of users that can run simultaneously. 233 */ getMaxRunningUsers()234 public abstract int getMaxRunningUsers(); 235 236 /** 237 * Whether an UID is active or idle. 238 */ isUidActive(int uid)239 public abstract boolean isUidActive(int uid); 240 241 /** 242 * Returns a list of running processes along with corresponding uids, pids and their oom score. 243 * 244 * Only processes managed by ActivityManagerService are included. 245 */ getMemoryStateForProcesses()246 public abstract List<ProcessMemoryState> getMemoryStateForProcesses(); 247 248 /** 249 * Checks to see if the calling pid is allowed to handle the user. Returns adjusted user id as 250 * needed. 251 */ handleIncomingUser(int callingPid, int callingUid, @UserIdInt int userId, boolean allowAll, int allowMode, String name, String callerPackage)252 public abstract int handleIncomingUser(int callingPid, int callingUid, @UserIdInt int userId, 253 boolean allowAll, int allowMode, String name, String callerPackage); 254 255 /** Checks if the calling binder pid as the permission. */ enforceCallingPermission(String permission, String func)256 public abstract void enforceCallingPermission(String permission, String func); 257 258 /** Returns the current user id. */ getCurrentUserId()259 public abstract int getCurrentUserId(); 260 261 /** Returns the currently started user ids. */ getStartedUserIds()262 public abstract int[] getStartedUserIds(); 263 264 /** Returns true if the user is running. */ isUserRunning(@serIdInt int userId, int flags)265 public abstract boolean isUserRunning(@UserIdInt int userId, int flags); 266 267 /** Trims memory usage in the system by removing/stopping unused application processes. */ trimApplications()268 public abstract void trimApplications(); 269 270 /** Kill the processes in the list due to their tasks been removed. */ killProcessesForRemovedTask(ArrayList<Object> procsToKill)271 public abstract void killProcessesForRemovedTask(ArrayList<Object> procsToKill); 272 273 /** Kill the process immediately. */ killProcess(String processName, int uid, String reason)274 public abstract void killProcess(String processName, int uid, String reason); 275 276 /** 277 * Returns {@code true} if {@code uid} is running an activity from {@code packageName}. 278 */ hasRunningActivity(int uid, @Nullable String packageName)279 public abstract boolean hasRunningActivity(int uid, @Nullable String packageName); 280 updateOomAdj()281 public abstract void updateOomAdj(); updateCpuStats()282 public abstract void updateCpuStats(); 283 284 /** 285 * Update battery stats on activity usage. 286 * @param activity 287 * @param uid 288 * @param userId 289 * @param started 290 */ updateBatteryStats( ComponentName activity, int uid, @UserIdInt int userId, boolean resumed)291 public abstract void updateBatteryStats( 292 ComponentName activity, int uid, @UserIdInt int userId, boolean resumed); 293 294 /** 295 * Update UsageStats of the activity. 296 * @param activity 297 * @param userId 298 * @param event 299 * @param appToken ActivityRecord's appToken. 300 * @param taskRoot Task's root 301 */ updateActivityUsageStats( ComponentName activity, @UserIdInt int userId, int event, IBinder appToken, ComponentName taskRoot)302 public abstract void updateActivityUsageStats( 303 ComponentName activity, @UserIdInt int userId, int event, IBinder appToken, 304 ComponentName taskRoot); updateForegroundTimeIfOnBattery( String packageName, int uid, long cpuTimeDiff)305 public abstract void updateForegroundTimeIfOnBattery( 306 String packageName, int uid, long cpuTimeDiff); sendForegroundProfileChanged(@serIdInt int userId)307 public abstract void sendForegroundProfileChanged(@UserIdInt int userId); 308 309 /** 310 * Returns whether the given user requires credential entry at this time. This is used to 311 * intercept activity launches for locked work apps due to work challenge being triggered or 312 * when the profile user is yet to be unlocked. 313 */ shouldConfirmCredentials(@serIdInt int userId)314 public abstract boolean shouldConfirmCredentials(@UserIdInt int userId); 315 316 /** 317 * Used in conjunction with {@link #noteAlarmStart(PendingIntent, WorkSource, int, String)} to 318 * note an alarm duration for battery attribution 319 */ noteAlarmFinish(PendingIntent ps, WorkSource workSource, int sourceUid, String tag)320 public abstract void noteAlarmFinish(PendingIntent ps, WorkSource workSource, int sourceUid, 321 String tag); 322 323 /** 324 * Used in conjunction with {@link #noteAlarmFinish(PendingIntent, WorkSource, int, String)} to 325 * note an alarm duration for battery attribution 326 */ noteAlarmStart(PendingIntent ps, WorkSource workSource, int sourceUid, String tag)327 public abstract void noteAlarmStart(PendingIntent ps, WorkSource workSource, int sourceUid, 328 String tag); 329 330 /** 331 * Used to note a wakeup alarm for battery attribution. 332 */ noteWakeupAlarm(PendingIntent ps, WorkSource workSource, int sourceUid, String sourcePkg, String tag)333 public abstract void noteWakeupAlarm(PendingIntent ps, WorkSource workSource, int sourceUid, 334 String sourcePkg, String tag); 335 336 /** 337 * Returns whether this app is disallowed to run in the background. 338 * 339 * @see ActivityManager#APP_START_MODE_DISABLED 340 */ isAppStartModeDisabled(int uid, String packageName)341 public abstract boolean isAppStartModeDisabled(int uid, String packageName); 342 getCurrentProfileIds()343 public abstract int[] getCurrentProfileIds(); getCurrentUser()344 public abstract UserInfo getCurrentUser(); ensureNotSpecialUser(@serIdInt int userId)345 public abstract void ensureNotSpecialUser(@UserIdInt int userId); isCurrentProfile(@serIdInt int userId)346 public abstract boolean isCurrentProfile(@UserIdInt int userId); hasStartedUserState(@serIdInt int userId)347 public abstract boolean hasStartedUserState(@UserIdInt int userId); finishUserSwitch(Object uss)348 public abstract void finishUserSwitch(Object uss); 349 350 /** Schedule the execution of all pending app GCs. */ scheduleAppGcs()351 public abstract void scheduleAppGcs(); 352 353 /** Gets the task id for a given activity. */ getTaskIdForActivity(@onNull IBinder token, boolean onlyRoot)354 public abstract int getTaskIdForActivity(@NonNull IBinder token, boolean onlyRoot); 355 356 /** Gets the basic info for a given activity. */ getActivityPresentationInfo(@onNull IBinder token)357 public abstract ActivityPresentationInfo getActivityPresentationInfo(@NonNull IBinder token); 358 setBooting(boolean booting)359 public abstract void setBooting(boolean booting); isBooting()360 public abstract boolean isBooting(); setBooted(boolean booted)361 public abstract void setBooted(boolean booted); isBooted()362 public abstract boolean isBooted(); finishBooting()363 public abstract void finishBooting(); 364 365 /** 366 * Temp allowlist a UID for PendingIntent. 367 * @param callerPid the PID that sent the PendingIntent. 368 * @param callerUid the UID that sent the PendingIntent. 369 * @param targetUid the UID that is been temp allowlisted. 370 * @param duration temp allowlist duration in milliseconds. 371 * @param type temp allowlist type defined at {@link TempAllowListType} 372 * @param reasonCode one of {@link ReasonCode} 373 * @param reason 374 */ tempAllowlistForPendingIntent(int callerPid, int callerUid, int targetUid, long duration, int type, @ReasonCode int reasonCode, String reason)375 public abstract void tempAllowlistForPendingIntent(int callerPid, int callerUid, int targetUid, 376 long duration, int type, @ReasonCode int reasonCode, String reason); 377 broadcastIntentInPackage(String packageName, @Nullable String featureId, int uid, int realCallingUid, int realCallingPid, Intent intent, String resolvedType, IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras, String requiredPermission, Bundle bOptions, boolean serialized, boolean sticky, @UserIdInt int userId, boolean allowBackgroundActivityStarts, @Nullable IBinder backgroundActivityStartsToken)378 public abstract int broadcastIntentInPackage(String packageName, @Nullable String featureId, 379 int uid, int realCallingUid, int realCallingPid, Intent intent, String resolvedType, 380 IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras, 381 String requiredPermission, Bundle bOptions, boolean serialized, boolean sticky, 382 @UserIdInt int userId, boolean allowBackgroundActivityStarts, 383 @Nullable IBinder backgroundActivityStartsToken); 384 startServiceInPackage(int uid, Intent service, String resolvedType, boolean fgRequired, String callingPackage, @Nullable String callingFeatureId, @UserIdInt int userId, boolean allowBackgroundActivityStarts, @Nullable IBinder backgroundActivityStartsToken)385 public abstract ComponentName startServiceInPackage(int uid, Intent service, 386 String resolvedType, boolean fgRequired, String callingPackage, 387 @Nullable String callingFeatureId, @UserIdInt int userId, 388 boolean allowBackgroundActivityStarts, 389 @Nullable IBinder backgroundActivityStartsToken) throws TransactionTooLargeException; 390 disconnectActivityFromServices(Object connectionHolder)391 public abstract void disconnectActivityFromServices(Object connectionHolder); cleanUpServices(@serIdInt int userId, ComponentName component, Intent baseIntent)392 public abstract void cleanUpServices(@UserIdInt int userId, ComponentName component, 393 Intent baseIntent); getActivityInfoForUser(ActivityInfo aInfo, @UserIdInt int userId)394 public abstract ActivityInfo getActivityInfoForUser(ActivityInfo aInfo, @UserIdInt int userId); ensureBootCompleted()395 public abstract void ensureBootCompleted(); updateOomLevelsForDisplay(int displayId)396 public abstract void updateOomLevelsForDisplay(int displayId); isActivityStartsLoggingEnabled()397 public abstract boolean isActivityStartsLoggingEnabled(); 398 /** Returns true if the background activity starts is enabled. */ isBackgroundActivityStartsEnabled()399 public abstract boolean isBackgroundActivityStartsEnabled(); reportCurKeyguardUsageEvent(boolean keyguardShowing)400 public abstract void reportCurKeyguardUsageEvent(boolean keyguardShowing); 401 402 /** @see com.android.server.am.ActivityManagerService#monitor */ monitor()403 public abstract void monitor(); 404 405 /** Input dispatch timeout to a window, start the ANR process. Return the timeout extension, 406 * in milliseconds, or 0 to abort dispatch. */ inputDispatchingTimedOut(int pid, boolean aboveSystem, String reason)407 public abstract long inputDispatchingTimedOut(int pid, boolean aboveSystem, String reason); inputDispatchingTimedOut(Object proc, String activityShortComponentName, ApplicationInfo aInfo, String parentShortComponentName, Object parentProc, boolean aboveSystem, String reason)408 public abstract boolean inputDispatchingTimedOut(Object proc, String activityShortComponentName, 409 ApplicationInfo aInfo, String parentShortComponentName, Object parentProc, 410 boolean aboveSystem, String reason); 411 /** 412 * App started responding to input events. This signal can be used to abort the ANR process and 413 * hide the ANR dialog. 414 */ inputDispatchingResumed(int pid)415 public abstract void inputDispatchingResumed(int pid); 416 417 /** 418 * Sends {@link android.content.Intent#ACTION_CONFIGURATION_CHANGED} with all the appropriate 419 * flags. 420 */ broadcastGlobalConfigurationChanged(int changes, boolean initLocale)421 public abstract void broadcastGlobalConfigurationChanged(int changes, boolean initLocale); 422 423 /** 424 * Sends {@link android.content.Intent#ACTION_CLOSE_SYSTEM_DIALOGS} with all the appropriate 425 * flags. 426 */ broadcastCloseSystemDialogs(String reason)427 public abstract void broadcastCloseSystemDialogs(String reason); 428 429 /** 430 * Kills all background processes, except those matching any of the specified properties. 431 * 432 * @param minTargetSdk the target SDK version at or above which to preserve processes, 433 * or {@code -1} to ignore the target SDK 434 * @param maxProcState the process state at or below which to preserve processes, 435 * or {@code -1} to ignore the process state 436 */ killAllBackgroundProcessesExcept(int minTargetSdk, int maxProcState)437 public abstract void killAllBackgroundProcessesExcept(int minTargetSdk, int maxProcState); 438 439 /** Starts a given process. */ startProcess(String processName, ApplicationInfo info, boolean knownToBeDead, boolean isTop, String hostingType, ComponentName hostingName)440 public abstract void startProcess(String processName, ApplicationInfo info, 441 boolean knownToBeDead, boolean isTop, String hostingType, ComponentName hostingName); 442 443 /** Starts up the starting activity process for debugging if needed. 444 * This function needs to be called synchronously from WindowManager context so the caller 445 * passes a lock {@code wmLock} and waits to be notified. 446 * 447 * @param wmLock calls {@code notify} on the object to wake up the caller. 448 */ setDebugFlagsForStartingActivity(ActivityInfo aInfo, int startFlags, ProfilerInfo profilerInfo, Object wmLock)449 public abstract void setDebugFlagsForStartingActivity(ActivityInfo aInfo, int startFlags, 450 ProfilerInfo profilerInfo, Object wmLock); 451 452 /** Returns mount mode for process running with given pid */ getStorageMountMode(int pid, int uid)453 public abstract int getStorageMountMode(int pid, int uid); 454 455 /** Returns true if the given uid is the app in the foreground. */ isAppForeground(int uid)456 public abstract boolean isAppForeground(int uid); 457 458 /** Returns true if the given process name and uid is currently marked 'bad' */ isAppBad(String processName, int uid)459 public abstract boolean isAppBad(String processName, int uid); 460 461 /** Remove pending backup for the given userId. */ clearPendingBackup(@serIdInt int userId)462 public abstract void clearPendingBackup(@UserIdInt int userId); 463 464 /** 465 * When power button is very long pressed, call this interface to do some pre-shutdown work 466 * like persisting database etc. 467 */ prepareForPossibleShutdown()468 public abstract void prepareForPossibleShutdown(); 469 470 /** 471 * Returns {@code true} if {@code uid} is running a foreground service of a specific 472 * {@code foregroundServiceType}. 473 */ hasRunningForegroundService(int uid, int foregroundServiceType)474 public abstract boolean hasRunningForegroundService(int uid, int foregroundServiceType); 475 476 /** 477 * Returns {@code true} if the given notification channel currently has a 478 * notification associated with a foreground service. This is an AMS check 479 * because that is the source of truth for the FGS state. 480 */ hasForegroundServiceNotification(String pkg, @UserIdInt int userId, String channelId)481 public abstract boolean hasForegroundServiceNotification(String pkg, @UserIdInt int userId, 482 String channelId); 483 484 /** 485 * Tell the service lifecycle logic that the given Notification content is now 486 * canonical for any foreground-service visibility policy purposes. 487 * 488 * Returns a description of any FGs-related policy around the given Notification: 489 * not associated with an FGS; ensure display; or only update if already displayed. 490 */ applyForegroundServiceNotification( Notification notification, String tag, int id, String pkg, @UserIdInt int userId)491 public abstract ServiceNotificationPolicy applyForegroundServiceNotification( 492 Notification notification, String tag, int id, String pkg, @UserIdInt int userId); 493 494 /** 495 * Callback from the notification subsystem that the given FGS notification has 496 * been evaluated, and either shown or explicitly overlooked. This can happen 497 * after either Service.startForeground() or NotificationManager.notify(). 498 */ onForegroundServiceNotificationUpdate(boolean shown, Notification notification, int id, String pkg, @UserIdInt int userId)499 public abstract void onForegroundServiceNotificationUpdate(boolean shown, 500 Notification notification, int id, String pkg, @UserIdInt int userId); 501 502 /** 503 * If the given app has any FGSs whose notifications are in the given channel, 504 * stop them. 505 */ stopForegroundServicesForChannel(String pkg, @UserIdInt int userId, String channelId)506 public abstract void stopForegroundServicesForChannel(String pkg, @UserIdInt int userId, 507 String channelId); 508 509 /** 510 * Registers the specified {@code processObserver} to be notified of future changes to 511 * process state. 512 */ registerProcessObserver(IProcessObserver processObserver)513 public abstract void registerProcessObserver(IProcessObserver processObserver); 514 515 /** 516 * Unregisters the specified {@code processObserver}. 517 */ unregisterProcessObserver(IProcessObserver processObserver)518 public abstract void unregisterProcessObserver(IProcessObserver processObserver); 519 520 /** 521 * Checks if there is an unfinished instrumentation that targets the given uid. 522 * 523 * @param uid The uid to be checked for 524 * 525 * @return True, if there is an instrumentation whose target application uid matches the given 526 * uid, false otherwise 527 */ isUidCurrentlyInstrumented(int uid)528 public abstract boolean isUidCurrentlyInstrumented(int uid); 529 530 /** Is this a device owner app? */ isDeviceOwner(int uid)531 public abstract boolean isDeviceOwner(int uid); 532 533 /** 534 * Called by DevicePolicyManagerService to set the uid of the device owner. 535 */ setDeviceOwnerUid(int uid)536 public abstract void setDeviceOwnerUid(int uid); 537 538 /** Is this a profile owner app? */ isProfileOwner(int uid)539 public abstract boolean isProfileOwner(int uid); 540 541 /** 542 * Called by DevicePolicyManagerService to set the uid of the profile owner. 543 * @param profileOwnerUids The profile owner UIDs. The ownership of the array is 544 * passed to callee. 545 */ setProfileOwnerUid(ArraySet<Integer> profileOwnerUids)546 public abstract void setProfileOwnerUid(ArraySet<Integer> profileOwnerUids); 547 548 /** 549 * Set all associated companion app that belongs to a userId. 550 * @param userId 551 * @param companionAppUids ActivityManager will take ownership of this Set, the caller 552 * shouldn't touch this Set after calling this interface. 553 */ setCompanionAppUids(int userId, Set<Integer> companionAppUids)554 public abstract void setCompanionAppUids(int userId, Set<Integer> companionAppUids); 555 556 /** 557 * is the uid an associated companion app of a userId? 558 * @param userId 559 * @param uid 560 * @return 561 */ isAssociatedCompanionApp(int userId, int uid)562 public abstract boolean isAssociatedCompanionApp(int userId, int uid); 563 564 /** 565 * Sends a broadcast, assuming the caller to be the system and allowing the inclusion of an 566 * approved allowlist of app Ids >= {@link android.os.Process#FIRST_APPLICATION_UID} that the 567 * broadcast my be sent to; any app Ids < {@link android.os.Process#FIRST_APPLICATION_UID} are 568 * automatically allowlisted. 569 * 570 * @see com.android.server.am.ActivityManagerService#broadcastIntentWithFeature( 571 * IApplicationThread, String, Intent, String, IIntentReceiver, int, String, Bundle, 572 * String[], int, Bundle, boolean, boolean, int) 573 */ broadcastIntent(Intent intent, IIntentReceiver resultTo, String[] requiredPermissions, boolean serialized, int userId, int[] appIdAllowList, @Nullable Bundle bOptions)574 public abstract int broadcastIntent(Intent intent, 575 IIntentReceiver resultTo, 576 String[] requiredPermissions, boolean serialized, 577 int userId, int[] appIdAllowList, @Nullable Bundle bOptions); 578 579 /** 580 * Add uid to the ActivityManagerService PendingStartActivityUids list. 581 * @param uid uid 582 * @param pid pid of the ProcessRecord that is pending top. 583 */ addPendingTopUid(int uid, int pid)584 public abstract void addPendingTopUid(int uid, int pid); 585 586 /** 587 * Delete uid from the ActivityManagerService PendingStartActivityUids list. 588 * @param uid uid 589 */ deletePendingTopUid(int uid)590 public abstract void deletePendingTopUid(int uid); 591 592 /** 593 * Is the uid in ActivityManagerService PendingStartActivityUids list? 594 * @param uid 595 * @return true if exists, false otherwise. 596 */ isPendingTopUid(int uid)597 public abstract boolean isPendingTopUid(int uid); 598 599 /** 600 * @return the intent for the given intent sender. 601 */ 602 @Nullable getIntentForIntentSender(IIntentSender sender)603 public abstract Intent getIntentForIntentSender(IIntentSender sender); 604 605 /** 606 * Effectively PendingIntent.getActivityForUser(), but the PendingIntent is 607 * owned by the given uid rather than by the caller (i.e. the system). 608 */ getPendingIntentActivityAsApp( int requestCode, @NonNull Intent intent, int flags, Bundle options, String ownerPkgName, int ownerUid)609 public abstract PendingIntent getPendingIntentActivityAsApp( 610 int requestCode, @NonNull Intent intent, int flags, Bundle options, 611 String ownerPkgName, int ownerUid); 612 613 /** 614 * Effectively PendingIntent.getActivityForUser(), but the PendingIntent is 615 * owned by the given uid rather than by the caller (i.e. the system). 616 */ getPendingIntentActivityAsApp( int requestCode, @NonNull Intent[] intents, int flags, Bundle options, String ownerPkgName, int ownerUid)617 public abstract PendingIntent getPendingIntentActivityAsApp( 618 int requestCode, @NonNull Intent[] intents, int flags, Bundle options, 619 String ownerPkgName, int ownerUid); 620 621 /** 622 * @return mBootTimeTempAllowlistDuration of ActivityManagerConstants. 623 */ getBootTimeTempAllowListDuration()624 public abstract long getBootTimeTempAllowListDuration(); 625 626 /** Register an {@link AnrController} to control the ANR dialog behavior */ registerAnrController(AnrController controller)627 public abstract void registerAnrController(AnrController controller); 628 629 /** Unregister an {@link AnrController} */ unregisterAnrController(AnrController controller)630 public abstract void unregisterAnrController(AnrController controller); 631 632 /** 633 * Is the FGS started from an uid temporarily allowed to have while-in-use permission? 634 */ isTempAllowlistedForFgsWhileInUse(int uid)635 public abstract boolean isTempAllowlistedForFgsWhileInUse(int uid); 636 637 /** 638 * Return the temp allowlist type when server push messaging is over the quota. 639 */ getPushMessagingOverQuotaBehavior()640 public abstract @TempAllowListType int getPushMessagingOverQuotaBehavior(); 641 642 /** 643 * Returns the capability of the given uid 644 */ getUidCapability(int uid)645 public abstract @ProcessCapability int getUidCapability(int uid); 646 647 /** 648 * @return The PID list of the isolated process with packages matching the given uid. 649 */ 650 @Nullable getIsolatedProcesses(int uid)651 public abstract List<Integer> getIsolatedProcesses(int uid); 652 653 /** @see ActivityManagerService#sendIntentSender */ sendIntentSender(IIntentSender target, IBinder allowlistToken, int code, Intent intent, String resolvedType, IIntentReceiver finishedReceiver, String requiredPermission, Bundle options)654 public abstract int sendIntentSender(IIntentSender target, IBinder allowlistToken, int code, 655 Intent intent, String resolvedType, 656 IIntentReceiver finishedReceiver, String requiredPermission, Bundle options); 657 658 /** 659 * Sets the provider to communicate between voice interaction manager service and 660 * ActivityManagerService. 661 */ setVoiceInteractionManagerProvider( @ullable VoiceInteractionManagerProvider provider)662 public abstract void setVoiceInteractionManagerProvider( 663 @Nullable VoiceInteractionManagerProvider provider); 664 665 /** 666 * Sets whether the current foreground user (and its profiles) should be stopped after switched 667 * out. 668 */ setStopUserOnSwitch(@topUserOnSwitch int value)669 public abstract void setStopUserOnSwitch(@StopUserOnSwitch int value); 670 671 /** 672 * Provides the interface to communicate between voice interaction manager service and 673 * ActivityManagerService. 674 */ 675 public interface VoiceInteractionManagerProvider { 676 /** 677 * Notifies the service when a high-level activity event has been changed, for example, 678 * an activity was resumed or stopped. 679 */ notifyActivityEventChanged()680 void notifyActivityEventChanged(); 681 } 682 } 683