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