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