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