1 /* 2 * Copyright (C) 2018 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 com.android.server.wm; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.UserIdInt; 22 import android.app.ActivityManager; 23 import android.app.AppProtoEnums; 24 import android.app.IActivityManager; 25 import android.app.IApplicationThread; 26 import android.app.ProfilerInfo; 27 import android.content.ComponentName; 28 import android.content.IIntentSender; 29 import android.content.Intent; 30 import android.content.pm.ApplicationInfo; 31 import android.content.res.CompatibilityInfo; 32 import android.os.Bundle; 33 import android.os.IBinder; 34 import android.os.RemoteException; 35 import android.os.SystemClock; 36 import android.service.voice.IVoiceInteractionSession; 37 import android.util.Pair; 38 import android.util.SparseIntArray; 39 import android.util.proto.ProtoOutputStream; 40 41 import com.android.internal.app.IVoiceInteractor; 42 import com.android.server.am.PendingIntentRecord; 43 import com.android.server.am.UserState; 44 45 import java.io.FileDescriptor; 46 import java.io.PrintWriter; 47 import java.lang.ref.WeakReference; 48 import java.util.List; 49 import java.util.Set; 50 51 /** 52 * Activity Task manager local system service interface. 53 * @hide Only for use within system server 54 */ 55 public abstract class ActivityTaskManagerInternal { 56 57 /** 58 * Type for {@link #notifyAppTransitionStarting}: The transition was started because we drew 59 * the splash screen. 60 */ 61 public static final int APP_TRANSITION_SPLASH_SCREEN = 62 AppProtoEnums.APP_TRANSITION_SPLASH_SCREEN; // 1 63 64 /** 65 * Type for {@link #notifyAppTransitionStarting}: The transition was started because we all 66 * app windows were drawn 67 */ 68 public static final int APP_TRANSITION_WINDOWS_DRAWN = 69 AppProtoEnums.APP_TRANSITION_WINDOWS_DRAWN; // 2 70 71 /** 72 * Type for {@link #notifyAppTransitionStarting}: The transition was started because of a 73 * timeout. 74 */ 75 public static final int APP_TRANSITION_TIMEOUT = 76 AppProtoEnums.APP_TRANSITION_TIMEOUT; // 3 77 78 /** 79 * Type for {@link #notifyAppTransitionStarting}: The transition was started because of a 80 * we drew a task snapshot. 81 */ 82 public static final int APP_TRANSITION_SNAPSHOT = 83 AppProtoEnums.APP_TRANSITION_SNAPSHOT; // 4 84 85 /** 86 * Type for {@link #notifyAppTransitionStarting}: The transition was started because it was a 87 * recents animation and we only needed to wait on the wallpaper. 88 */ 89 public static final int APP_TRANSITION_RECENTS_ANIM = 90 AppProtoEnums.APP_TRANSITION_RECENTS_ANIM; // 5 91 92 /** 93 * The id of the task source of assist state. 94 */ 95 public static final String ASSIST_TASK_ID = "taskId"; 96 97 /** 98 * The id of the activity source of assist state. 99 */ 100 public static final String ASSIST_ACTIVITY_ID = "activityId"; 101 102 /** 103 * The bundle key to extract the assist data. 104 */ 105 public static final String ASSIST_KEY_DATA = "data"; 106 107 /** 108 * The bundle key to extract the assist structure. 109 */ 110 public static final String ASSIST_KEY_STRUCTURE = "structure"; 111 112 /** 113 * The bundle key to extract the assist content. 114 */ 115 public static final String ASSIST_KEY_CONTENT = "content"; 116 117 /** 118 * The bundle key to extract the assist receiver extras. 119 */ 120 public static final String ASSIST_KEY_RECEIVER_EXTRAS = "receiverExtras"; 121 122 public interface ScreenObserver { onAwakeStateChanged(boolean isAwake)123 void onAwakeStateChanged(boolean isAwake); onKeyguardStateChanged(boolean isShowing)124 void onKeyguardStateChanged(boolean isShowing); 125 } 126 127 /** 128 * Sleep tokens cause the activity manager to put the top activity to sleep. 129 * They are used by components such as dreams that may hide and block interaction 130 * with underlying activities. 131 */ 132 public static abstract class SleepToken { 133 134 /** Releases the sleep token. */ release()135 public abstract void release(); 136 } 137 138 /** 139 * Acquires a sleep token for the specified display with the specified tag. 140 * 141 * @param tag A string identifying the purpose of the token (eg. "Dream"). 142 * @param displayId The display to apply the sleep token to. 143 */ acquireSleepToken(@onNull String tag, int displayId)144 public abstract SleepToken acquireSleepToken(@NonNull String tag, int displayId); 145 146 /** 147 * Returns home activity for the specified user. 148 * 149 * @param userId ID of the user or {@link android.os.UserHandle#USER_ALL} 150 */ getHomeActivityForUser(int userId)151 public abstract ComponentName getHomeActivityForUser(int userId); 152 onLocalVoiceInteractionStarted(IBinder callingActivity, IVoiceInteractionSession mSession, IVoiceInteractor mInteractor)153 public abstract void onLocalVoiceInteractionStarted(IBinder callingActivity, 154 IVoiceInteractionSession mSession, 155 IVoiceInteractor mInteractor); 156 157 /** 158 * Callback for window manager to let activity manager know that we are finally starting the 159 * app transition; 160 * 161 * @param reasons A map from windowing mode to a reason integer why the transition was started, 162 * which must be one of the APP_TRANSITION_* values. 163 * @param timestamp The time at which the app transition started in 164 * {@link SystemClock#uptimeMillis()} timebase. 165 */ notifyAppTransitionStarting(SparseIntArray reasons, long timestamp)166 public abstract void notifyAppTransitionStarting(SparseIntArray reasons, long timestamp); 167 168 /** 169 * Callback for window manager to let activity manager know that the app transition was 170 * cancelled. 171 */ notifyAppTransitionCancelled()172 public abstract void notifyAppTransitionCancelled(); 173 174 /** 175 * Callback for window manager to let activity manager know that the app transition is finished. 176 */ notifyAppTransitionFinished()177 public abstract void notifyAppTransitionFinished(); 178 179 /** 180 * Returns the top activity from each of the currently visible stacks. The first entry will be 181 * the focused activity. 182 */ getTopVisibleActivities()183 public abstract List<IBinder> getTopVisibleActivities(); 184 185 /** 186 * Callback for window manager to let activity manager know that docked stack changes its 187 * minimized state. 188 */ notifyDockedStackMinimizedChanged(boolean minimized)189 public abstract void notifyDockedStackMinimizedChanged(boolean minimized); 190 191 /** 192 * Start activity {@code intents} as if {@code packageName} on user {@code userId} did it. 193 * 194 * - DO NOT call it with the calling UID cleared. 195 * - All the necessary caller permission checks must be done at callsites. 196 * 197 * @return error codes used by {@link IActivityManager#startActivity} and its siblings. 198 */ startActivitiesAsPackage(String packageName, int userId, Intent[] intents, Bundle bOptions)199 public abstract int startActivitiesAsPackage(String packageName, 200 int userId, Intent[] intents, Bundle bOptions); 201 202 /** 203 * Start intents as a package. 204 * 205 * @param uid Make a call as if this UID did. 206 * @param realCallingPid PID of the real caller. 207 * @param realCallingUid UID of the real caller. 208 * @param callingPackage Make a call as if this package did. 209 * @param intents Intents to start. 210 * @param userId Start the intents on this user. 211 * @param validateIncomingUser Set true to skip checking {@code userId} with the calling UID. 212 * @param originatingPendingIntent PendingIntentRecord that originated this activity start or 213 * null if not originated by PendingIntent 214 * @param allowBackgroundActivityStart Whether the background activity start should be allowed 215 * from originatingPendingIntent 216 */ startActivitiesInPackage(int uid, int realCallingPid, int realCallingUid, String callingPackage, Intent[] intents, String[] resolvedTypes, IBinder resultTo, SafeActivityOptions options, int userId, boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, boolean allowBackgroundActivityStart)217 public abstract int startActivitiesInPackage(int uid, int realCallingPid, int realCallingUid, 218 String callingPackage, Intent[] intents, String[] resolvedTypes, IBinder resultTo, 219 SafeActivityOptions options, int userId, boolean validateIncomingUser, 220 PendingIntentRecord originatingPendingIntent, 221 boolean allowBackgroundActivityStart); 222 startActivityInPackage(int uid, int realCallingPid, int realCallingUid, String callingPackage, Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, int startFlags, SafeActivityOptions options, int userId, TaskRecord inTask, String reason, boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, boolean allowBackgroundActivityStart)223 public abstract int startActivityInPackage(int uid, int realCallingPid, int realCallingUid, 224 String callingPackage, Intent intent, String resolvedType, IBinder resultTo, 225 String resultWho, int requestCode, int startFlags, SafeActivityOptions options, 226 int userId, TaskRecord inTask, String reason, boolean validateIncomingUser, 227 PendingIntentRecord originatingPendingIntent, boolean allowBackgroundActivityStart); 228 229 /** 230 * Start activity {@code intent} without calling user-id check. 231 * 232 * - DO NOT call it with the calling UID cleared. 233 * - The caller must do the calling user ID check. 234 * 235 * @return error codes used by {@link IActivityManager#startActivity} and its siblings. 236 */ startActivityAsUser(IApplicationThread caller, String callingPackage, Intent intent, @Nullable Bundle options, int userId)237 public abstract int startActivityAsUser(IApplicationThread caller, String callingPackage, 238 Intent intent, @Nullable Bundle options, int userId); 239 240 /** 241 * Called when Keyguard flags might have changed. 242 * 243 * @param callback Callback to run after activity visibilities have been reevaluated. This can 244 * be used from window manager so that when the callback is called, it's 245 * guaranteed that all apps have their visibility updated accordingly. 246 * @param displayId The id of the display where the keyguard flags changed. 247 */ notifyKeyguardFlagsChanged(@ullable Runnable callback, int displayId)248 public abstract void notifyKeyguardFlagsChanged(@Nullable Runnable callback, int displayId); 249 250 /** 251 * Called when the trusted state of Keyguard has changed. 252 */ notifyKeyguardTrustedChanged()253 public abstract void notifyKeyguardTrustedChanged(); 254 255 /** 256 * Called after virtual display Id is updated by 257 * {@link com.android.server.vr.Vr2dDisplay} with a specific 258 * {@param vr2dDisplayId}. 259 */ setVr2dDisplayId(int vr2dDisplayId)260 public abstract void setVr2dDisplayId(int vr2dDisplayId); 261 262 /** 263 * Set focus on an activity. 264 * @param token The IApplicationToken for the activity 265 */ setFocusedActivity(IBinder token)266 public abstract void setFocusedActivity(IBinder token); 267 registerScreenObserver(ScreenObserver observer)268 public abstract void registerScreenObserver(ScreenObserver observer); 269 270 /** 271 * Returns is the caller has the same uid as the Recents component 272 */ isCallerRecents(int callingUid)273 public abstract boolean isCallerRecents(int callingUid); 274 275 /** 276 * Returns whether the recents component is the home activity for the given user. 277 */ isRecentsComponentHomeActivity(int userId)278 public abstract boolean isRecentsComponentHomeActivity(int userId); 279 280 /** 281 * Cancels any currently running recents animation. 282 */ cancelRecentsAnimation(boolean restoreHomeStackPosition)283 public abstract void cancelRecentsAnimation(boolean restoreHomeStackPosition); 284 285 /** 286 * This enforces {@code func} can only be called if either the caller is Recents activity or 287 * has {@code permission}. 288 */ enforceCallerIsRecentsOrHasPermission(String permission, String func)289 public abstract void enforceCallerIsRecentsOrHasPermission(String permission, String func); 290 291 /** 292 * Called after the voice interaction service has changed. 293 */ notifyActiveVoiceInteractionServiceChanged(ComponentName component)294 public abstract void notifyActiveVoiceInteractionServiceChanged(ComponentName component); 295 296 /** 297 * Set a uid that is allowed to bypass stopped app switches, launching an app 298 * whenever it wants. 299 * 300 * @param type Type of the caller -- unique string the caller supplies to identify itself 301 * and disambiguate with other calles. 302 * @param uid The uid of the app to be allowed, or -1 to clear the uid for this type. 303 * @param userId The user it is allowed for. 304 */ setAllowAppSwitches(@onNull String type, int uid, int userId)305 public abstract void setAllowAppSwitches(@NonNull String type, int uid, int userId); 306 307 /** 308 * Called when a user has been deleted. This can happen during normal device usage 309 * or just at startup, when partially removed users are purged. Any state persisted by the 310 * ActivityManager should be purged now. 311 * 312 * @param userId The user being cleaned up. 313 */ onUserStopped(int userId)314 public abstract void onUserStopped(int userId); isGetTasksAllowed(String caller, int callingPid, int callingUid)315 public abstract boolean isGetTasksAllowed(String caller, int callingPid, int callingUid); 316 onProcessAdded(WindowProcessController proc)317 public abstract void onProcessAdded(WindowProcessController proc); onProcessRemoved(String name, int uid)318 public abstract void onProcessRemoved(String name, int uid); onCleanUpApplicationRecord(WindowProcessController proc)319 public abstract void onCleanUpApplicationRecord(WindowProcessController proc); getTopProcessState()320 public abstract int getTopProcessState(); isHeavyWeightProcess(WindowProcessController proc)321 public abstract boolean isHeavyWeightProcess(WindowProcessController proc); clearHeavyWeightProcessIfEquals(WindowProcessController proc)322 public abstract void clearHeavyWeightProcessIfEquals(WindowProcessController proc); finishHeavyWeightApp()323 public abstract void finishHeavyWeightApp(); 324 isSleeping()325 public abstract boolean isSleeping(); isShuttingDown()326 public abstract boolean isShuttingDown(); shuttingDown(boolean booted, int timeout)327 public abstract boolean shuttingDown(boolean booted, int timeout); enableScreenAfterBoot(boolean booted)328 public abstract void enableScreenAfterBoot(boolean booted); showStrictModeViolationDialog()329 public abstract boolean showStrictModeViolationDialog(); showSystemReadyErrorDialogsIfNeeded()330 public abstract void showSystemReadyErrorDialogsIfNeeded(); 331 onProcessMapped(int pid, WindowProcessController proc)332 public abstract void onProcessMapped(int pid, WindowProcessController proc); onProcessUnMapped(int pid)333 public abstract void onProcessUnMapped(int pid); 334 onPackageDataCleared(String name)335 public abstract void onPackageDataCleared(String name); onPackageUninstalled(String name)336 public abstract void onPackageUninstalled(String name); onPackageAdded(String name, boolean replacing)337 public abstract void onPackageAdded(String name, boolean replacing); onPackageReplaced(ApplicationInfo aInfo)338 public abstract void onPackageReplaced(ApplicationInfo aInfo); 339 compatibilityInfoForPackage(ApplicationInfo ai)340 public abstract CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai); 341 342 public final class ActivityTokens { 343 private final @NonNull IBinder mActivityToken; 344 private final @NonNull IBinder mAssistToken; 345 private final @NonNull IApplicationThread mAppThread; 346 ActivityTokens(@onNull IBinder activityToken, @NonNull IBinder assistToken, @NonNull IApplicationThread appThread)347 public ActivityTokens(@NonNull IBinder activityToken, 348 @NonNull IBinder assistToken, @NonNull IApplicationThread appThread) { 349 mActivityToken = activityToken; 350 mAssistToken = assistToken; 351 mAppThread = appThread; 352 } 353 354 /** 355 * @return The activity token. 356 */ getActivityToken()357 public @NonNull IBinder getActivityToken() { 358 return mActivityToken; 359 } 360 361 /** 362 * @return The assist token. 363 */ getAssistToken()364 public @NonNull IBinder getAssistToken() { 365 return mAssistToken; 366 } 367 368 /** 369 * @return The assist token. 370 */ getApplicationThread()371 public @NonNull IApplicationThread getApplicationThread() { 372 return mAppThread; 373 } 374 } 375 376 /** 377 * Set the corresponding display information for the process global configuration. To be called 378 * when we need to show IME on a different display. 379 * 380 * @param pid The process id associated with the IME window. 381 * @param displayId The ID of the display showing the IME. 382 */ onImeWindowSetOnDisplay(int pid, int displayId)383 public abstract void onImeWindowSetOnDisplay(int pid, int displayId); 384 sendActivityResult(int callingUid, IBinder activityToken, String resultWho, int requestCode, int resultCode, Intent data)385 public abstract void sendActivityResult(int callingUid, IBinder activityToken, 386 String resultWho, int requestCode, int resultCode, Intent data); clearPendingResultForActivity( IBinder activityToken, WeakReference<PendingIntentRecord> pir)387 public abstract void clearPendingResultForActivity( 388 IBinder activityToken, WeakReference<PendingIntentRecord> pir); 389 390 /** 391 * @return the activity token and IApplicationThread for the top activity in the task or null 392 * if there isn't a top activity with a valid process. 393 */ 394 @Nullable getTopActivityForTask(int taskId)395 public abstract ActivityTokens getTopActivityForTask(int taskId); 396 getIntentSender(int type, String packageName, int callingUid, int userId, IBinder token, String resultWho, int requestCode, Intent[] intents, String[] resolvedTypes, int flags, Bundle bOptions)397 public abstract IIntentSender getIntentSender(int type, String packageName, 398 int callingUid, int userId, IBinder token, String resultWho, 399 int requestCode, Intent[] intents, String[] resolvedTypes, int flags, 400 Bundle bOptions); 401 402 /** @return the service connection holder for a given activity token. */ getServiceConnectionsHolder(IBinder token)403 public abstract ActivityServiceConnectionsHolder getServiceConnectionsHolder(IBinder token); 404 405 /** @return The intent used to launch the home activity. */ getHomeIntent()406 public abstract Intent getHomeIntent(); startHomeActivity(int userId, String reason)407 public abstract boolean startHomeActivity(int userId, String reason); 408 /** 409 * This starts home activity on displays that can have system decorations based on displayId - 410 * Default display always use primary home component. 411 * For Secondary displays, the home activity must have category SECONDARY_HOME and then resolves 412 * according to the priorities listed below. 413 * - If default home is not set, always use the secondary home defined in the config. 414 * - Use currently selected primary home activity. 415 * - Use the activity in the same package as currently selected primary home activity. 416 * If there are multiple activities matched, use first one. 417 * - Use the secondary home defined in the config. 418 */ startHomeOnDisplay(int userId, String reason, int displayId, boolean allowInstrumenting, boolean fromHomeKey)419 public abstract boolean startHomeOnDisplay(int userId, String reason, int displayId, 420 boolean allowInstrumenting, boolean fromHomeKey); 421 /** Start home activities on all displays that support system decorations. */ startHomeOnAllDisplays(int userId, String reason)422 public abstract boolean startHomeOnAllDisplays(int userId, String reason); 423 /** @return true if the given process is the factory test process. */ isFactoryTestProcess(WindowProcessController wpc)424 public abstract boolean isFactoryTestProcess(WindowProcessController wpc); updateTopComponentForFactoryTest()425 public abstract void updateTopComponentForFactoryTest(); handleAppDied(WindowProcessController wpc, boolean restarting, Runnable finishInstrumentationCallback)426 public abstract void handleAppDied(WindowProcessController wpc, boolean restarting, 427 Runnable finishInstrumentationCallback); closeSystemDialogs(String reason)428 public abstract void closeSystemDialogs(String reason); 429 430 /** Removes all components (e.g. activities, recents, ...) belonging to a disabled package. */ cleanupDisabledPackageComponents( String packageName, Set<String> disabledClasses, int userId, boolean booted)431 public abstract void cleanupDisabledPackageComponents( 432 String packageName, Set<String> disabledClasses, int userId, boolean booted); 433 434 /** Called whenever AM force stops a package. */ onForceStopPackage(String packageName, boolean doit, boolean evenPersistent, int userId)435 public abstract boolean onForceStopPackage(String packageName, boolean doit, 436 boolean evenPersistent, int userId); 437 /** 438 * Resumes all top activities in the system if they aren't resumed already. 439 * @param scheduleIdle If the idle message should be schedule after the top activities are 440 * resumed. 441 */ resumeTopActivities(boolean scheduleIdle)442 public abstract void resumeTopActivities(boolean scheduleIdle); 443 444 /** Called by AM just before it binds to an application process. */ preBindApplication(WindowProcessController wpc)445 public abstract void preBindApplication(WindowProcessController wpc); 446 447 /** Called by AM when an application process attaches. */ attachApplication(WindowProcessController wpc)448 public abstract boolean attachApplication(WindowProcessController wpc) throws RemoteException; 449 450 /** @see IActivityManager#notifyLockedProfile(int) */ notifyLockedProfile(@serIdInt int userId, int currentUserId)451 public abstract void notifyLockedProfile(@UserIdInt int userId, int currentUserId); 452 453 /** @see IActivityManager#startConfirmDeviceCredentialIntent(Intent, Bundle) */ startConfirmDeviceCredentialIntent(Intent intent, Bundle options)454 public abstract void startConfirmDeviceCredentialIntent(Intent intent, Bundle options); 455 456 /** Writes current activity states to the proto stream. */ writeActivitiesToProto(ProtoOutputStream proto)457 public abstract void writeActivitiesToProto(ProtoOutputStream proto); 458 459 /** 460 * Saves the current activity manager state and includes the saved state in the next dump of 461 * activity manager. 462 */ saveANRState(String reason)463 public abstract void saveANRState(String reason); 464 465 /** Clears the previously saved activity manager ANR state. */ clearSavedANRState()466 public abstract void clearSavedANRState(); 467 468 /** Dump the current state based on the command. */ dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args, int opti, boolean dumpAll, boolean dumpClient, String dumpPackage)469 public abstract void dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args, 470 int opti, boolean dumpAll, boolean dumpClient, String dumpPackage); 471 472 /** Dump the current state for inclusion in process dump. */ dumpForProcesses(FileDescriptor fd, PrintWriter pw, boolean dumpAll, String dumpPackage, int dumpAppId, boolean needSep, boolean testPssMode, int wakefulness)473 public abstract boolean dumpForProcesses(FileDescriptor fd, PrintWriter pw, boolean dumpAll, 474 String dumpPackage, int dumpAppId, boolean needSep, boolean testPssMode, 475 int wakefulness); 476 477 /** Writes the current window process states to the proto stream. */ writeProcessesToProto(ProtoOutputStream proto, String dumpPackage, int wakeFullness, boolean testPssMode)478 public abstract void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage, 479 int wakeFullness, boolean testPssMode); 480 481 /** Dump the current activities state. */ dumpActivity(FileDescriptor fd, PrintWriter pw, String name, String[] args, int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, boolean dumpFocusedStackOnly)482 public abstract boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, 483 String[] args, int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, 484 boolean dumpFocusedStackOnly); 485 486 /** Dump the current state for inclusion in oom dump. */ dumpForOom(PrintWriter pw)487 public abstract void dumpForOom(PrintWriter pw); 488 489 /** @return true if it the activity management system is okay with GC running now. */ canGcNow()490 public abstract boolean canGcNow(); 491 492 /** @return the process for the top-most resumed activity in the system. */ getTopApp()493 public abstract WindowProcessController getTopApp(); 494 495 /** Generate oom-score-adjustment rank for all tasks in the system based on z-order. */ rankTaskLayersIfNeeded()496 public abstract void rankTaskLayersIfNeeded(); 497 498 /** Destroy all activities. */ scheduleDestroyAllActivities(String reason)499 public abstract void scheduleDestroyAllActivities(String reason); 500 501 /** Remove user association with activities. */ removeUser(int userId)502 public abstract void removeUser(int userId); 503 504 /** Switch current focused user for activities. */ switchUser(int userId, UserState userState)505 public abstract boolean switchUser(int userId, UserState userState); 506 507 /** Called whenever an app crashes. */ onHandleAppCrash(WindowProcessController wpc)508 public abstract void onHandleAppCrash(WindowProcessController wpc); 509 510 /** 511 * Finish the topmost activities in all stacks that belong to the crashed app. 512 * @param crashedApp The app that crashed. 513 * @param reason Reason to perform this action. 514 * @return The task id that was finished in this stack, or INVALID_TASK_ID if none was finished. 515 */ finishTopCrashedActivities( WindowProcessController crashedApp, String reason)516 public abstract int finishTopCrashedActivities( 517 WindowProcessController crashedApp, String reason); 518 onUidActive(int uid, int procState)519 public abstract void onUidActive(int uid, int procState); onUidInactive(int uid)520 public abstract void onUidInactive(int uid); onActiveUidsCleared()521 public abstract void onActiveUidsCleared(); onUidProcStateChanged(int uid, int procState)522 public abstract void onUidProcStateChanged(int uid, int procState); 523 onUidAddedToPendingTempWhitelist(int uid, String tag)524 public abstract void onUidAddedToPendingTempWhitelist(int uid, String tag); onUidRemovedFromPendingTempWhitelist(int uid)525 public abstract void onUidRemovedFromPendingTempWhitelist(int uid); 526 527 /** Handle app crash event in {@link android.app.IActivityController} if there is one. */ handleAppCrashInActivityController(String processName, int pid, String shortMsg, String longMsg, long timeMillis, String stackTrace, Runnable killCrashingAppCallback)528 public abstract boolean handleAppCrashInActivityController(String processName, int pid, 529 String shortMsg, String longMsg, long timeMillis, String stackTrace, 530 Runnable killCrashingAppCallback); 531 removeRecentTasksByPackageName(String packageName, int userId)532 public abstract void removeRecentTasksByPackageName(String packageName, int userId); cleanupRecentTasksForUser(int userId)533 public abstract void cleanupRecentTasksForUser(int userId); loadRecentTasksForUser(int userId)534 public abstract void loadRecentTasksForUser(int userId); onPackagesSuspendedChanged(String[] packages, boolean suspended, int userId)535 public abstract void onPackagesSuspendedChanged(String[] packages, boolean suspended, 536 int userId); 537 /** Flush recent tasks to disk. */ flushRecentTasks()538 public abstract void flushRecentTasks(); 539 getHomeProcess()540 public abstract WindowProcessController getHomeProcess(); getPreviousProcess()541 public abstract WindowProcessController getPreviousProcess(); 542 clearLockedTasks(String reason)543 public abstract void clearLockedTasks(String reason); updateUserConfiguration()544 public abstract void updateUserConfiguration(); canShowErrorDialogs()545 public abstract boolean canShowErrorDialogs(); 546 setProfileApp(String profileApp)547 public abstract void setProfileApp(String profileApp); setProfileProc(WindowProcessController wpc)548 public abstract void setProfileProc(WindowProcessController wpc); setProfilerInfo(ProfilerInfo profilerInfo)549 public abstract void setProfilerInfo(ProfilerInfo profilerInfo); 550 getLaunchObserverRegistry()551 public abstract ActivityMetricsLaunchObserverRegistry getLaunchObserverRegistry(); 552 553 /** 554 * Gets bitmap snapshot of the provided task id. 555 */ getTaskSnapshotNoRestore(int taskId, boolean reducedResolution)556 public abstract ActivityManager.TaskSnapshot getTaskSnapshotNoRestore(int taskId, 557 boolean reducedResolution); 558 559 /** Returns true if uid is considered foreground for activity start purposes. */ isUidForeground(int uid)560 public abstract boolean isUidForeground(int uid); 561 562 /** 563 * Called by DevicePolicyManagerService to set the uid of the device owner. 564 */ setDeviceOwnerUid(int uid)565 public abstract void setDeviceOwnerUid(int uid); 566 567 /** Set all associated companion app that belongs to an userId. */ setCompanionAppPackages(int userId, Set<String> companionAppPackages)568 public abstract void setCompanionAppPackages(int userId, Set<String> companionAppPackages); 569 } 570