| 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.app.ActivityManager.RestrictionLevel; |
| 26 | import android.content.ComponentName; |
| 27 | import android.content.IIntentReceiver; |
| 28 | import android.content.IIntentSender; |
| 29 | import android.content.Intent; |
| 30 | import android.content.pm.ActivityInfo; |
| 31 | import android.content.pm.ActivityPresentationInfo; |
| 32 | import android.content.pm.ApplicationInfo; |
| 33 | import android.content.pm.UserInfo; |
| 34 | import android.net.Uri; |
| 35 | import android.os.Bundle; |
| 36 | import android.os.IBinder; |
| 37 | import android.os.PowerExemptionManager.ReasonCode; |
| 38 | import android.os.PowerExemptionManager.TempAllowListType; |
| 39 | import android.os.TransactionTooLargeException; |
| 40 | import android.os.WorkSource; |
| 41 | import android.util.ArraySet; |
| 42 | import android.util.Pair; |
| 43 | |
| 44 | import java.util.ArrayList; |
| 45 | import java.util.List; |
| 46 | import java.util.Map; |
| 47 | import java.util.Set; |
| 48 | |
| 49 | /** |
| 50 | * Activity manager local system service interface. |
| 51 | * |
| 52 | * @hide Only for use within the system server. |
| 53 | */ |
| 54 | public abstract class ActivityManagerInternal { |
| 55 | |
| 56 | public enum ServiceNotificationPolicy { |
| 57 | /** |
| 58 | * The Notification is not associated with any foreground service. |
| 59 | */ |
| 60 | NOT_FOREGROUND_SERVICE, |
| 61 | /** |
| 62 | * The Notification is associated with a foreground service, but the |
| 63 | * notification system should handle it just like non-FGS notifications. |
| 64 | */ |
| 65 | SHOW_IMMEDIATELY, |
| 66 | /** |
| 67 | * The Notification is associated with a foreground service, and the |
| 68 | * notification system should ignore it unless it has already been shown (in |
| 69 | * which case it should be used to update the currently displayed UI). |
| 70 | */ |
| 71 | UPDATE_ONLY |
| 72 | } |
| 73 | |
| 74 | // Access modes for handleIncomingUser. |
| 75 | /** |
| 76 | * Allows access to a caller with {@link android.Manifest.permission#INTERACT_ACROSS_USERS}. |
| 77 | */ |
| 78 | public static final int ALLOW_NON_FULL = 0; |
| 79 | /** |
| 80 | * Allows access to a caller with {@link android.Manifest.permission#INTERACT_ACROSS_USERS} |
| 81 | * if in the same profile group. |
| 82 | * Otherwise, {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} is required. |
| 83 | */ |
| 84 | public static final int ALLOW_NON_FULL_IN_PROFILE = 1; |
| 85 | /** |
| 86 | * Allows access to a caller only if it has the full |
| 87 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}. |
| 88 | */ |
| 89 | public static final int ALLOW_FULL_ONLY = 2; |
| 90 | /** |
| 91 | * Allows access to a caller with {@link android.Manifest.permission#INTERACT_ACROSS_PROFILES} |
| 92 | * if in the same profile group. |
| 93 | * Otherwise, {@link android.Manifest.permission#INTERACT_ACROSS_USERS} is required and suffices |
| 94 | * as in {@link #ALLOW_NON_FULL}. |
| 95 | */ |
| 96 | public static final int ALLOW_PROFILES_OR_NON_FULL = 3; |
| 97 | |
| 98 | /** |
| 99 | * Returns profile information in free form string in two separate strings. |
| 100 | * See AppProfiler for the output format. |
| 101 | * The output can only be used for human consumption. The format may change |
| 102 | * in the future. |
| 103 | * Do not call it frequently. |
| 104 | * @param time uptime for the cpu state |
| 105 | * @param lines lines of the cpu state should be returned |
| 106 | * @return a pair of Strings. The first is the current cpu load, the second is the cpu state. |
| 107 | */ |
| 108 | public abstract Pair<String, String> getAppProfileStatsForDebugging(long time, int lines); |
| 109 | |
| 110 | /** |
| 111 | * Verify that calling app has access to the given provider. |
| 112 | */ |
| 113 | public abstract String checkContentProviderAccess(String authority, @UserIdInt int userId); |
| 114 | |
| 115 | /** |
| 116 | * Verify that calling UID has access to the given provider. |
| 117 | */ |
| 118 | public abstract int checkContentProviderUriPermission(Uri uri, @UserIdInt int userId, |
| 119 | int callingUid, int modeFlags); |
| 120 | |
| 121 | // Called by the power manager. |
| 122 | public abstract void onWakefulnessChanged(int wakefulness); |
| 123 | |
| 124 | /** |
| 125 | * @return {@code true} if process start is successful, {@code false} otherwise. |
| 126 | */ |
| 127 | public abstract boolean startIsolatedProcess(String entryPoint, String[] mainArgs, |
| 128 | String processName, String abiOverride, int uid, Runnable crashHandler); |
| 129 | |
| 130 | /** |
| 131 | * Called when a user has been deleted. This can happen during normal device usage |
| 132 | * or just at startup, when partially removed users are purged. Any state persisted by the |
| 133 | * ActivityManager should be purged now. |
| 134 | * |
| 135 | * @param userId The user being cleaned up. |
| 136 | */ |
| 137 | public abstract void onUserRemoved(@UserIdInt int userId); |
| 138 | |
| 139 | /** |
| 140 | * Kill foreground apps from the specified user. |
| 141 | */ |
| 142 | public abstract void killForegroundAppsForUser(@UserIdInt int userId); |
| 143 | |
| 144 | /** |
| 145 | * Sets how long a {@link PendingIntent} can be temporarily allowlisted to bypass restrictions |
| 146 | * such as Power Save mode. |
| 147 | * @param target |
| 148 | * @param allowlistToken |
| 149 | * @param duration temp allowlist duration in milliseconds. |
| 150 | * @param type temp allowlist type defined at {@link TempAllowListType} |
| 151 | * @param reasonCode one of {@link ReasonCode} |
| 152 | * @param reason A human-readable reason for logging purposes. |
| 153 | */ |
| 154 | public abstract void setPendingIntentAllowlistDuration(IIntentSender target, |
| 155 | IBinder allowlistToken, long duration, @TempAllowListType int type, |
| 156 | @ReasonCode int reasonCode, @Nullable String reason); |
| 157 | |
| 158 | /** |
| 159 | * Returns the flags set for a {@link PendingIntent}. |
| 160 | */ |
| 161 | public abstract int getPendingIntentFlags(IIntentSender target); |
| 162 | |
| 163 | /** |
| 164 | * Allows a {@link PendingIntent} to start activities from background. |
| 165 | */ |
| 166 | public abstract void setPendingIntentAllowBgActivityStarts( |
| 167 | IIntentSender target, IBinder allowlistToken, int flags); |
| 168 | |
| 169 | /** |
| 170 | * Voids {@link PendingIntent}'s privilege to start activities from background. |
| 171 | */ |
| 172 | public abstract void clearPendingIntentAllowBgActivityStarts(IIntentSender target, |
| 173 | IBinder allowlistToken); |
| 174 | |
| 175 | /** |
| 176 | * Allow DeviceIdleController to tell us about what apps are allowlisted. |
| 177 | */ |
| 178 | public abstract void setDeviceIdleAllowlist(int[] allAppids, int[] exceptIdleAppids); |
| 179 | |
| 180 | /** |
| 181 | * Update information about which app IDs are on the temp allowlist. |
| 182 | * @param appids the updated list of appIds in temp allowlist. |
| 183 | * If null, it is to update only changingUid. |
| 184 | * @param changingUid uid to add or remove to temp allowlist. |
| 185 | * @param adding true to add to temp allowlist, false to remove from temp allowlist. |
| 186 | * @param durationMs when adding is true, the duration to be in temp allowlist. |
| 187 | * @param type temp allowlist type defined at {@link TempAllowListType}. |
| 188 | * @param reasonCode one of {@link ReasonCode} |
| 189 | * @param reason A human-readable reason for logging purposes. |
| 190 | * @param callingUid the callingUid that setup this temp allowlist, only valid when param adding |
| 191 | * is true. |
| 192 | */ |
| 193 | public abstract void updateDeviceIdleTempAllowlist(@Nullable int[] appids, int changingUid, |
| 194 | boolean adding, long durationMs, @TempAllowListType int type, |
| 195 | @ReasonCode int reasonCode, |
| 196 | @Nullable String reason, int callingUid); |
| 197 | |
| 198 | /** |
| 199 | * Get the procstate for the UID. The return value will be between |
| 200 | * {@link ActivityManager#MIN_PROCESS_STATE} and {@link ActivityManager#MAX_PROCESS_STATE}. |
| 201 | * Note if the UID doesn't exist, it'll return {@link ActivityManager#PROCESS_STATE_NONEXISTENT} |
| 202 | * (-1). |
| 203 | */ |
| 204 | public abstract int getUidProcessState(int uid); |
| 205 | |
| 206 | /** |
| 207 | * Get a map of pid and package name that process of that pid Android/data and Android/obb |
| 208 | * directory is not mounted to lowerfs. |
| 209 | */ |
| 210 | public abstract Map<Integer, String> getProcessesWithPendingBindMounts(int userId); |
| 211 | |
| 212 | /** |
| 213 | * @return {@code true} if system is ready, {@code false} otherwise. |
| 214 | */ |
| 215 | public abstract boolean isSystemReady(); |
| 216 | |
| 217 | /** |
| 218 | * Returns package name given pid. |
| 219 | * |
| 220 | * @param pid The pid we are searching package name for. |
| 221 | */ |
| 222 | @Nullable |
| 223 | public abstract String getPackageNameByPid(int pid); |
| 224 | |
| 225 | /** |
| 226 | * Sets if the given pid has an overlay UI or not. |
| 227 | * |
| 228 | * @param pid The pid we are setting overlay UI for. |
| 229 | * @param hasOverlayUi True if the process has overlay UI. |
| 230 | * @see android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY |
| 231 | */ |
| 232 | public abstract void setHasOverlayUi(int pid, boolean hasOverlayUi); |
| 233 | |
| 234 | /** |
| 235 | * Called after the network policy rules are updated by |
| 236 | * {@link com.android.server.net.NetworkPolicyManagerService} for a specific {@param uid} and |
| 237 | * {@param procStateSeq}. |
| 238 | */ |
| 239 | public abstract void notifyNetworkPolicyRulesUpdated(int uid, long procStateSeq); |
| 240 | |
| 241 | /** |
| 242 | * Inform ActivityManagerService about the latest {@code blockedReasons} for an uid, which |
| 243 | * can be used to understand whether the {@code uid} is allowed to access network or not. |
| 244 | */ |
| 245 | public abstract void onUidBlockedReasonsChanged(int uid, int blockedReasons); |
| 246 | |
| 247 | /** |
| 248 | * @return true if runtime was restarted, false if it's normal boot |
| 249 | */ |
| 250 | public abstract boolean isRuntimeRestarted(); |
| 251 | |
| 252 | /** |
| 253 | * Returns if more users can be started without stopping currently running users. |
| 254 | */ |
| 255 | public abstract boolean canStartMoreUsers(); |
| 256 | |
| 257 | /** |
| 258 | * Sets the user switcher message for switching from {@link android.os.UserHandle#SYSTEM}. |
| 259 | */ |
| 260 | public abstract void setSwitchingFromSystemUserMessage(String switchingFromSystemUserMessage); |
| 261 | |
| 262 | /** |
| 263 | * Sets the user switcher message for switching to {@link android.os.UserHandle#SYSTEM}. |
| 264 | */ |
| 265 | public abstract void setSwitchingToSystemUserMessage(String switchingToSystemUserMessage); |
| 266 | |
| 267 | /** |
| 268 | * Returns maximum number of users that can run simultaneously. |
| 269 | */ |
| 270 | public abstract int getMaxRunningUsers(); |
| 271 | |
| 272 | /** |
| 273 | * Whether an UID is active or idle. |
| 274 | */ |
| 275 | public abstract boolean isUidActive(int uid); |
| 276 | |
| 277 | /** |
| 278 | * Returns a list of running processes along with corresponding uids, pids and their oom score. |
| 279 | * |
| 280 | * Only processes managed by ActivityManagerService are included. |
| 281 | */ |
| 282 | public abstract List<ProcessMemoryState> getMemoryStateForProcesses(); |
| 283 | |
| 284 | /** |
| 285 | * Checks to see if the calling pid is allowed to handle the user. Returns adjusted user id as |
| 286 | * needed. |
| 287 | */ |
| 288 | public abstract int handleIncomingUser(int callingPid, int callingUid, @UserIdInt int userId, |
| 289 | boolean allowAll, int allowMode, String name, String callerPackage); |
| 290 | |
| 291 | /** Checks if the calling binder pid as the permission. */ |
| 292 | public abstract void enforceCallingPermission(String permission, String func); |
| 293 | |
| 294 | /** Returns the current user id. */ |
| 295 | public abstract int getCurrentUserId(); |
| 296 | |
| 297 | /** Returns the currently started user ids. */ |
| 298 | public abstract int[] getStartedUserIds(); |
| 299 | |
| 300 | /** Returns true if the user is running. */ |
| 301 | public abstract boolean isUserRunning(@UserIdInt int userId, int flags); |
| 302 | |
| 303 | /** Trims memory usage in the system by removing/stopping unused application processes. */ |
| 304 | public abstract void trimApplications(); |
| 305 | |
| 306 | /** Kill the processes in the list due to their tasks been removed. */ |
| 307 | public abstract void killProcessesForRemovedTask(ArrayList<Object> procsToKill); |
| 308 | |
| 309 | /** Kill the process immediately. */ |
| 310 | public abstract void killProcess(String processName, int uid, String reason); |
| 311 | |
| 312 | /** |
| 313 | * Returns {@code true} if {@code uid} is running an activity from {@code packageName}. |
| 314 | */ |
| 315 | public abstract boolean hasRunningActivity(int uid, @Nullable String packageName); |
| 316 | |
| 317 | public abstract void updateOomAdj(); |
| 318 | public abstract void updateCpuStats(); |
| 319 | |
| 320 | /** |
| 321 | * Update battery stats on activity usage. |
| 322 | * @param activity |
| 323 | * @param uid |
| 324 | * @param userId |
| 325 | * @param started |
| 326 | */ |
| 327 | public abstract void updateBatteryStats( |
| 328 | ComponentName activity, int uid, @UserIdInt int userId, boolean resumed); |
| 329 | |
| 330 | /** |
| 331 | * Update UsageStats of the activity. |
| 332 | * @param activity |
| 333 | * @param userId |
| 334 | * @param event |
| 335 | * @param appToken ActivityRecord's appToken. |
| 336 | * @param taskRoot Task's root |
| 337 | */ |
| 338 | public abstract void updateActivityUsageStats( |
| 339 | ComponentName activity, @UserIdInt int userId, int event, IBinder appToken, |
| 340 | ComponentName taskRoot); |
| 341 | public abstract void updateForegroundTimeIfOnBattery( |
| 342 | String packageName, int uid, long cpuTimeDiff); |
| 343 | public abstract void sendForegroundProfileChanged(@UserIdInt int userId); |
| 344 | |
| 345 | /** |
| 346 | * Returns whether the given user requires credential entry at this time. This is used to |
| 347 | * intercept activity launches for locked work apps due to work challenge being triggered or |
| 348 | * when the profile user is yet to be unlocked. |
| 349 | */ |
| 350 | public abstract boolean shouldConfirmCredentials(@UserIdInt int userId); |
| 351 | |
| 352 | /** |
| 353 | * Used in conjunction with {@link #noteAlarmStart(PendingIntent, WorkSource, int, String)} to |
| 354 | * note an alarm duration for battery attribution |
| 355 | */ |
| 356 | public abstract void noteAlarmFinish(PendingIntent ps, WorkSource workSource, int sourceUid, |
| 357 | String tag); |
| 358 | |
| 359 | /** |
| 360 | * Used in conjunction with {@link #noteAlarmFinish(PendingIntent, WorkSource, int, String)} to |
| 361 | * note an alarm duration for battery attribution |
| 362 | */ |
| 363 | public abstract void noteAlarmStart(PendingIntent ps, WorkSource workSource, int sourceUid, |
| 364 | String tag); |
| 365 | |
| 366 | /** |
| 367 | * Used to note a wakeup alarm for battery attribution. |
| 368 | */ |
| 369 | public abstract void noteWakeupAlarm(PendingIntent ps, WorkSource workSource, int sourceUid, |
| 370 | String sourcePkg, String tag); |
| 371 | |
| 372 | /** |
| 373 | * Returns whether this app is disallowed to run in the background. |
| 374 | * |
| 375 | * @see ActivityManager#APP_START_MODE_DISABLED |
| 376 | */ |
| 377 | public abstract boolean isAppStartModeDisabled(int uid, String packageName); |
| 378 | |
| 379 | public abstract int[] getCurrentProfileIds(); |
| 380 | public abstract UserInfo getCurrentUser(); |
| 381 | public abstract void ensureNotSpecialUser(@UserIdInt int userId); |
| 382 | public abstract boolean isCurrentProfile(@UserIdInt int userId); |
| 383 | public abstract boolean hasStartedUserState(@UserIdInt int userId); |
| 384 | public abstract void finishUserSwitch(Object uss); |
| 385 | |
| 386 | /** Schedule the execution of all pending app GCs. */ |
| 387 | public abstract void scheduleAppGcs(); |
| 388 | |
| 389 | /** Gets the task id for a given activity. */ |
| 390 | public abstract int getTaskIdForActivity(@NonNull IBinder token, boolean onlyRoot); |
| 391 | |
| 392 | /** Gets the basic info for a given activity. */ |
| 393 | public abstract ActivityPresentationInfo getActivityPresentationInfo(@NonNull IBinder token); |
| 394 | |
| 395 | public abstract void setBooting(boolean booting); |
| 396 | public abstract boolean isBooting(); |
| 397 | public abstract void setBooted(boolean booted); |
| 398 | public abstract boolean isBooted(); |
| 399 | public abstract void finishBooting(); |
| 400 | |
| 401 | /** |
| 402 | * Temp allowlist a UID for PendingIntent. |
| 403 | * @param callerPid the PID that sent the PendingIntent. |
| 404 | * @param callerUid the UID that sent the PendingIntent. |
| 405 | * @param targetUid the UID that is been temp allowlisted. |
| 406 | * @param duration temp allowlist duration in milliseconds. |
| 407 | * @param type temp allowlist type defined at {@link TempAllowListType} |
| 408 | * @param reasonCode one of {@link ReasonCode} |
| 409 | * @param reason |
| 410 | */ |
| 411 | public abstract void tempAllowlistForPendingIntent(int callerPid, int callerUid, int targetUid, |
| 412 | long duration, int type, @ReasonCode int reasonCode, String reason); |
| 413 | |
| 414 | public abstract int broadcastIntentInPackage(String packageName, @Nullable String featureId, |
| 415 | int uid, int realCallingUid, int realCallingPid, Intent intent, String resolvedType, |
| 416 | IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras, |
| 417 | String requiredPermission, Bundle bOptions, boolean serialized, boolean sticky, |
| 418 | @UserIdInt int userId, boolean allowBackgroundActivityStarts, |
| 419 | @Nullable IBinder backgroundActivityStartsToken, @Nullable int[] broadcastAllowList); |
| 420 | |
| 421 | public abstract ComponentName startServiceInPackage(int uid, Intent service, |
| 422 | String resolvedType, boolean fgRequired, String callingPackage, |
| 423 | @Nullable String callingFeatureId, @UserIdInt int userId, |
| 424 | boolean allowBackgroundActivityStarts, |
| 425 | @Nullable IBinder backgroundActivityStartsToken) throws TransactionTooLargeException; |
| 426 | |
| 427 | public abstract void disconnectActivityFromServices(Object connectionHolder); |
| 428 | public abstract void cleanUpServices(@UserIdInt int userId, ComponentName component, |
| 429 | Intent baseIntent); |
| 430 | public abstract ActivityInfo getActivityInfoForUser(ActivityInfo aInfo, @UserIdInt int userId); |
| 431 | public abstract void ensureBootCompleted(); |
| 432 | public abstract void updateOomLevelsForDisplay(int displayId); |
| 433 | public abstract boolean isActivityStartsLoggingEnabled(); |
| 434 | /** Returns true if the background activity starts is enabled. */ |
| 435 | public abstract boolean isBackgroundActivityStartsEnabled(); |
| 436 | public abstract void reportCurKeyguardUsageEvent(boolean keyguardShowing); |
| 437 | |
| 438 | /** @see com.android.server.am.ActivityManagerService#monitor */ |
| 439 | public abstract void monitor(); |
| 440 | |
| 441 | /** Input dispatch timeout to a window, start the ANR process. Return the timeout extension, |
| 442 | * in milliseconds, or 0 to abort dispatch. */ |
| 443 | public abstract long inputDispatchingTimedOut(int pid, boolean aboveSystem, String reason); |
| 444 | public abstract boolean inputDispatchingTimedOut(Object proc, String activityShortComponentName, |
| 445 | ApplicationInfo aInfo, String parentShortComponentName, Object parentProc, |
| 446 | boolean aboveSystem, String reason); |
| 447 | /** |
| 448 | * App started responding to input events. This signal can be used to abort the ANR process and |
| 449 | * hide the ANR dialog. |
| 450 | */ |
| 451 | public abstract void inputDispatchingResumed(int pid); |
| 452 | |
| 453 | /** |
| 454 | * User tapped "wait" in the ANR dialog - reschedule the dialog to be shown again at a later |
| 455 | * time. |
| 456 | * @param data AppNotRespondingDialog.Data object |
| 457 | */ |
| 458 | public abstract void rescheduleAnrDialog(Object data); |
| 459 | |
| 460 | /** |
| 461 | * Sends {@link android.content.Intent#ACTION_CONFIGURATION_CHANGED} with all the appropriate |
| 462 | * flags. |
| 463 | */ |
| 464 | public abstract void broadcastGlobalConfigurationChanged(int changes, boolean initLocale); |
| 465 | |
| 466 | /** |
| 467 | * Sends {@link android.content.Intent#ACTION_CLOSE_SYSTEM_DIALOGS} with all the appropriate |
| 468 | * flags. |
| 469 | */ |
| 470 | public abstract void broadcastCloseSystemDialogs(String reason); |
| 471 | |
| 472 | /** |
| 473 | * Kills all background processes, except those matching any of the specified properties. |
| 474 | * |
| 475 | * @param minTargetSdk the target SDK version at or above which to preserve processes, |
| 476 | * or {@code -1} to ignore the target SDK |
| 477 | * @param maxProcState the process state at or below which to preserve processes, |
| 478 | * or {@code -1} to ignore the process state |
| 479 | */ |
| 480 | public abstract void killAllBackgroundProcessesExcept(int minTargetSdk, int maxProcState); |
| 481 | |
| 482 | /** Starts a given process. */ |
| 483 | public abstract void startProcess(String processName, ApplicationInfo info, |
| 484 | boolean knownToBeDead, boolean isTop, String hostingType, ComponentName hostingName); |
| 485 | |
| 486 | /** Starts up the starting activity process for debugging if needed. |
| 487 | * This function needs to be called synchronously from WindowManager context so the caller |
| 488 | * passes a lock {@code wmLock} and waits to be notified. |
| 489 | * |
| 490 | * @param wmLock calls {@code notify} on the object to wake up the caller. |
| 491 | */ |
| 492 | public abstract void setDebugFlagsForStartingActivity(ActivityInfo aInfo, int startFlags, |
| 493 | ProfilerInfo profilerInfo, Object wmLock); |
| 494 | |
| 495 | /** Returns mount mode for process running with given pid */ |
| 496 | public abstract int getStorageMountMode(int pid, int uid); |
| 497 | |
| 498 | /** Returns true if the given uid is the app in the foreground. */ |
| 499 | public abstract boolean isAppForeground(int uid); |
| 500 | |
| 501 | /** Returns true if the given process name and uid is currently marked 'bad' */ |
| 502 | public abstract boolean isAppBad(String processName, int uid); |
| 503 | |
| 504 | /** Remove pending backup for the given userId. */ |
| 505 | public abstract void clearPendingBackup(@UserIdInt int userId); |
| 506 | |
| 507 | /** |
| 508 | * When power button is very long pressed, call this interface to do some pre-shutdown work |
| 509 | * like persisting database etc. |
| 510 | */ |
| 511 | public abstract void prepareForPossibleShutdown(); |
| 512 | |
| 513 | /** |
| 514 | * Returns {@code true} if {@code uid} is running a foreground service of a specific |
| 515 | * {@code foregroundServiceType}. |
| 516 | */ |
| 517 | public abstract boolean hasRunningForegroundService(int uid, int foregroundServiceType); |
| 518 | |
| 519 | /** |
| 520 | * Returns {@code true} if the given notification channel currently has a |
| 521 | * notification associated with a foreground service. This is an AMS check |
| 522 | * because that is the source of truth for the FGS state. |
| 523 | */ |
| 524 | public abstract boolean hasForegroundServiceNotification(String pkg, @UserIdInt int userId, |
| 525 | String channelId); |
| 526 | |
| 527 | /** |
| 528 | * Tell the service lifecycle logic that the given Notification content is now |
| 529 | * canonical for any foreground-service visibility policy purposes. |
| 530 | * |
| 531 | * Returns a description of any FGs-related policy around the given Notification: |
| 532 | * not associated with an FGS; ensure display; or only update if already displayed. |
| 533 | */ |
| 534 | public abstract ServiceNotificationPolicy applyForegroundServiceNotification( |
| 535 | Notification notification, String tag, int id, String pkg, @UserIdInt int userId); |
| 536 | |
| 537 | /** |
| 538 | * Callback from the notification subsystem that the given FGS notification has |
| 539 | * been evaluated, and either shown or explicitly overlooked. This can happen |
| 540 | * after either Service.startForeground() or NotificationManager.notify(). |
| 541 | */ |
| 542 | public abstract void onForegroundServiceNotificationUpdate(boolean shown, |
| 543 | Notification notification, int id, String pkg, @UserIdInt int userId); |
| 544 | |
| 545 | /** |
| 546 | * Fully stop the given app's processes without restoring service starts or |
| 547 | * bindings, but without the other durable effects of the full-scale |
| 548 | * "force stop" intervention. |
| 549 | */ |
| 550 | public abstract void stopAppForUser(String pkg, @UserIdInt int userId); |
| 551 | |
| 552 | /** |
| 553 | * If the given app has any FGSs whose notifications are in the given channel, |
| 554 | * stop them. |
| 555 | */ |
| 556 | public abstract void stopForegroundServicesForChannel(String pkg, @UserIdInt int userId, |
| 557 | String channelId); |
| 558 | |
| 559 | /** |
| 560 | * Registers the specified {@code processObserver} to be notified of future changes to |
| 561 | * process state. |
| 562 | */ |
| 563 | public abstract void registerProcessObserver(IProcessObserver processObserver); |
| 564 | |
| 565 | /** |
| 566 | * Unregisters the specified {@code processObserver}. |
| 567 | */ |
| 568 | public abstract void unregisterProcessObserver(IProcessObserver processObserver); |
| 569 | |
| 570 | /** |
| 571 | * Gets the uid of the instrumentation source if there is an unfinished instrumentation that |
| 572 | * targets the given uid. |
| 573 | * |
| 574 | * @param uid The uid to be checked for |
| 575 | * |
| 576 | * @return the uid of the instrumentation source, if there is an instrumentation whose target |
| 577 | * application uid matches the given uid, and {@link android.os.Process#INVALID_UID} otherwise. |
| 578 | */ |
| 579 | public abstract int getInstrumentationSourceUid(int uid); |
| 580 | |
| 581 | /** Is this a device owner app? */ |
| 582 | public abstract boolean isDeviceOwner(int uid); |
| 583 | |
| 584 | /** |
| 585 | * Called by DevicePolicyManagerService to set the uid of the device owner. |
| 586 | */ |
| 587 | public abstract void setDeviceOwnerUid(int uid); |
| 588 | |
| 589 | /** Is this a profile owner app? */ |
| 590 | public abstract boolean isProfileOwner(int uid); |
| 591 | |
| 592 | /** |
| 593 | * Called by DevicePolicyManagerService to set the uid of the profile owner. |
| 594 | * @param profileOwnerUids The profile owner UIDs. The ownership of the array is |
| 595 | * passed to callee. |
| 596 | */ |
| 597 | public abstract void setProfileOwnerUid(ArraySet<Integer> profileOwnerUids); |
| 598 | |
| 599 | /** |
| 600 | * Set all associated companion app that belongs to a userId. |
| 601 | * @param userId |
| 602 | * @param companionAppUids ActivityManager will take ownership of this Set, the caller |
| 603 | * shouldn't touch this Set after calling this interface. |
| 604 | */ |
| 605 | public abstract void setCompanionAppUids(int userId, Set<Integer> companionAppUids); |
| 606 | |
| 607 | /** |
| 608 | * is the uid an associated companion app of a userId? |
| 609 | * @param userId |
| 610 | * @param uid |
| 611 | * @return |
| 612 | */ |
| 613 | public abstract boolean isAssociatedCompanionApp(int userId, int uid); |
| 614 | |
| 615 | /** |
| 616 | * Sends a broadcast, assuming the caller to be the system and allowing the inclusion of an |
| 617 | * approved allowlist of app Ids >= {@link android.os.Process#FIRST_APPLICATION_UID} that the |
| 618 | * broadcast my be sent to; any app Ids < {@link android.os.Process#FIRST_APPLICATION_UID} are |
| 619 | * automatically allowlisted. |
| 620 | * |
| 621 | * @see com.android.server.am.ActivityManagerService#broadcastIntentWithFeature( |
| 622 | * IApplicationThread, String, Intent, String, IIntentReceiver, int, String, Bundle, |
| 623 | * String[], int, Bundle, boolean, boolean, int) |
| 624 | */ |
| 625 | public abstract int broadcastIntent(Intent intent, |
| 626 | IIntentReceiver resultTo, |
| 627 | String[] requiredPermissions, boolean serialized, |
| 628 | int userId, int[] appIdAllowList, @Nullable Bundle bOptions); |
| 629 | |
| 630 | /** |
| 631 | * Add uid to the ActivityManagerService PendingStartActivityUids list. |
| 632 | * @param uid uid |
| 633 | * @param pid pid of the ProcessRecord that is pending top. |
| 634 | */ |
| 635 | public abstract void addPendingTopUid(int uid, int pid, @Nullable IApplicationThread thread); |
| 636 | |
| 637 | /** |
| 638 | * Delete uid from the ActivityManagerService PendingStartActivityUids list. |
| 639 | * @param uid uid |
| 640 | * @param nowElapsed starting time of updateOomAdj |
| 641 | */ |
| 642 | public abstract void deletePendingTopUid(int uid, long nowElapsed); |
| 643 | |
| 644 | /** |
| 645 | * Is the uid in ActivityManagerService PendingStartActivityUids list? |
| 646 | * @param uid |
| 647 | * @return true if exists, false otherwise. |
| 648 | */ |
| 649 | public abstract boolean isPendingTopUid(int uid); |
| 650 | |
| 651 | /** |
| 652 | * @return the intent for the given intent sender. |
| 653 | */ |
| 654 | @Nullable |
| 655 | public abstract Intent getIntentForIntentSender(IIntentSender sender); |
| 656 | |
| 657 | /** |
| 658 | * Effectively PendingIntent.getActivityForUser(), but the PendingIntent is |
| 659 | * owned by the given uid rather than by the caller (i.e. the system). |
| 660 | */ |
| 661 | public abstract PendingIntent getPendingIntentActivityAsApp( |
| 662 | int requestCode, @NonNull Intent intent, int flags, Bundle options, |
| 663 | String ownerPkgName, int ownerUid); |
| 664 | |
| 665 | /** |
| 666 | * Effectively PendingIntent.getActivityForUser(), but the PendingIntent is |
| 667 | * owned by the given uid rather than by the caller (i.e. the system). |
| 668 | */ |
| 669 | public abstract PendingIntent getPendingIntentActivityAsApp( |
| 670 | int requestCode, @NonNull Intent[] intents, int flags, Bundle options, |
| 671 | String ownerPkgName, int ownerUid); |
| 672 | |
| 673 | /** |
| 674 | * @return mBootTimeTempAllowlistDuration of ActivityManagerConstants. |
| 675 | */ |
| 676 | public abstract long getBootTimeTempAllowListDuration(); |
| 677 | |
| 678 | /** Register an {@link AnrController} to control the ANR dialog behavior */ |
| 679 | public abstract void registerAnrController(AnrController controller); |
| 680 | |
| 681 | /** Unregister an {@link AnrController} */ |
| 682 | public abstract void unregisterAnrController(AnrController controller); |
| 683 | |
| 684 | /** |
| 685 | * Is the FGS started from an uid temporarily allowed to have while-in-use permission? |
| 686 | */ |
| 687 | public abstract boolean isTempAllowlistedForFgsWhileInUse(int uid); |
| 688 | |
| 689 | /** |
| 690 | * Return the temp allowlist type when server push messaging is over the quota. |
| 691 | */ |
| 692 | public abstract @TempAllowListType int getPushMessagingOverQuotaBehavior(); |
| 693 | |
| 694 | /** |
| 695 | * Return the startForeground() grace period after calling startForegroundService(). |
| 696 | */ |
| 697 | public abstract int getServiceStartForegroundTimeout(); |
| 698 | |
| 699 | /** |
| 700 | * Returns the capability of the given uid |
| 701 | */ |
| 702 | public abstract @ProcessCapability int getUidCapability(int uid); |
| 703 | |
| 704 | /** |
| 705 | * @return The PID list of the isolated process with packages matching the given uid. |
| 706 | */ |
| 707 | @Nullable |
| 708 | public abstract List<Integer> getIsolatedProcesses(int uid); |
| 709 | |
| 710 | /** @see ActivityManagerService#sendIntentSender */ |
| 711 | public abstract int sendIntentSender(IIntentSender target, IBinder allowlistToken, int code, |
| 712 | Intent intent, String resolvedType, |
| 713 | IIntentReceiver finishedReceiver, String requiredPermission, Bundle options); |
| 714 | |
| 715 | /** |
| 716 | * Sets the provider to communicate between voice interaction manager service and |
| 717 | * ActivityManagerService. |
| 718 | */ |
| 719 | public abstract void setVoiceInteractionManagerProvider( |
| 720 | @Nullable VoiceInteractionManagerProvider provider); |
| 721 | |
| 722 | /** |
| 723 | * Sets whether the current foreground user (and its profiles) should be stopped after switched |
| 724 | * out. |
| 725 | */ |
| 726 | public abstract void setStopUserOnSwitch(@StopUserOnSwitch int value); |
| 727 | |
| 728 | /** |
| 729 | * Provides the interface to communicate between voice interaction manager service and |
| 730 | * ActivityManagerService. |
| 731 | */ |
| 732 | public interface VoiceInteractionManagerProvider { |
| 733 | /** |
| 734 | * Notifies the service when an activity is destroyed. |
| 735 | */ |
| 736 | void notifyActivityDestroyed(IBinder activityToken); |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * Get the restriction level of the given UID, if it hosts multiple packages, |
| 741 | * return least restricted level. |
| 742 | */ |
| 743 | public abstract @RestrictionLevel int getRestrictionLevel(int uid); |
| 744 | |
| 745 | /** |
| 746 | * Get the restriction level of the given package for given user id. |
| 747 | */ |
| 748 | public abstract @RestrictionLevel int getRestrictionLevel(String pkg, @UserIdInt int userId); |
| 749 | |
| 750 | /** |
| 751 | * Get whether or not apps would be put into restricted standby bucket automatically |
| 752 | * when it's background-restricted. |
| 753 | */ |
| 754 | public abstract boolean isBgAutoRestrictedBucketFeatureFlagEnabled(); |
| 755 | |
| 756 | /** |
| 757 | * A listener interface, which will be notified on background restriction changes. |
| 758 | */ |
| 759 | public interface AppBackgroundRestrictionListener { |
| 760 | /** |
| 761 | * Called when the background restriction level of given uid/package is changed. |
| 762 | */ |
| 763 | default void onRestrictionLevelChanged(int uid, String packageName, |
| 764 | @RestrictionLevel int newLevel) { |
| 765 | } |
| 766 | |
| 767 | /** |
| 768 | * Called when toggling the feature flag of moving to restricted standby bucket |
| 769 | * automatically on background-restricted. |
| 770 | */ |
| 771 | default void onAutoRestrictedBucketFeatureFlagChanged(boolean autoRestrictedBucket) { |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | /** |
| 776 | * Register the background restriction listener callback. |
| 777 | */ |
| 778 | public abstract void addAppBackgroundRestrictionListener( |
| 779 | @NonNull AppBackgroundRestrictionListener listener); |
| 780 | |
| 781 | /** |
| 782 | * A listener interface, which will be notified on foreground service state changes. |
| 783 | */ |
| 784 | public interface ForegroundServiceStateListener { |
| 785 | /** |
| 786 | * Call when the given process's foreground service state changes. |
| 787 | * |
| 788 | * @param packageName The package name of the process. |
| 789 | * @param uid The UID of the process. |
| 790 | * @param pid The pid of the process. |
| 791 | * @param started {@code true} if the process transits from non-FGS state to FGS state. |
| 792 | */ |
| 793 | void onForegroundServiceStateChanged(String packageName, int uid, int pid, boolean started); |
| 794 | |
| 795 | /** |
| 796 | * Call when the notification of the foreground service is updated. |
| 797 | * |
| 798 | * @param packageName The package name of the process. |
| 799 | * @param uid The UID of the process. |
| 800 | * @param foregroundId The current foreground service notification ID. |
| 801 | * @param canceling The given notification is being canceled. |
| 802 | */ |
| 803 | void onForegroundServiceNotificationUpdated(String packageName, int uid, int foregroundId, |
| 804 | boolean canceling); |
| 805 | } |
| 806 | |
| 807 | /** |
| 808 | * Register the foreground service state change listener callback. |
| 809 | */ |
| 810 | public abstract void addForegroundServiceStateListener( |
| 811 | @NonNull ForegroundServiceStateListener listener); |
| 812 | |
| 813 | /** |
| 814 | * A listener interface, which will be notified on the package sends a broadcast. |
| 815 | */ |
| 816 | public interface BroadcastEventListener { |
| 817 | /** |
| 818 | * Called when the given package/uid is sending a broadcast. |
| 819 | */ |
| 820 | void onSendingBroadcast(String packageName, int uid); |
| 821 | } |
| 822 | |
| 823 | /** |
| 824 | * Register the broadcast event listener callback. |
| 825 | */ |
| 826 | public abstract void addBroadcastEventListener(@NonNull BroadcastEventListener listener); |
| 827 | |
| 828 | /** |
| 829 | * A listener interface, which will be notified on the package binding to a service. |
| 830 | */ |
| 831 | public interface BindServiceEventListener { |
| 832 | /** |
| 833 | * Called when the given package/uid is binding to a service |
| 834 | */ |
| 835 | void onBindingService(String packageName, int uid); |
| 836 | } |
| 837 | |
| 838 | /** |
| 839 | * Register the bind service event listener callback. |
| 840 | */ |
| 841 | public abstract void addBindServiceEventListener(@NonNull BindServiceEventListener listener); |
| 842 | |
| 843 | /** |
| 844 | * Restart android. |
| 845 | */ |
| 846 | public abstract void restart(); |
| 847 | |
| 848 | /** |
| 849 | * Returns some summary statistics of the current PendingIntent queue - sizes and counts. |
| 850 | */ |
| 851 | public abstract List<PendingIntentStats> getPendingIntentStats(); |
| 852 | |
| 853 | /** |
| 854 | * Register the UidObserver for NetworkPolicyManager service. |
| 855 | * |
| 856 | * This is equivalent to calling |
| 857 | * {@link IActivityManager#registerUidObserver(IUidObserver, int, int, String)} but having a |
| 858 | * separate method for NetworkPolicyManager service so that it's UidObserver can be called |
| 859 | * separately outside the usual UidObserver flow. |
| 860 | */ |
| 861 | public abstract void registerNetworkPolicyUidObserver(@NonNull IUidObserver observer, |
| 862 | int which, int cutpoint, @NonNull String callingPackage); |
| 863 | } |