1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.app;
18 
19 import android.app.ActivityManager;
20 import android.app.ActivityTaskManager;
21 import android.app.ApplicationStartInfo;
22 import android.app.ApplicationErrorReport;
23 import android.app.ApplicationExitInfo;
24 import android.app.ContentProviderHolder;
25 import android.app.GrantedUriPermission;
26 import android.app.IApplicationStartInfoCompleteListener;
27 import android.app.IApplicationThread;
28 import android.app.IActivityController;
29 import android.app.IAppTask;
30 import android.app.IForegroundServiceObserver;
31 import android.app.IInstrumentationWatcher;
32 import android.app.IProcessObserver;
33 import android.app.IServiceConnection;
34 import android.app.IStopUserCallback;
35 import android.app.ITaskStackListener;
36 import android.app.IUiAutomationConnection;
37 import android.app.IUidFrozenStateChangedCallback;
38 import android.app.IUidObserver;
39 import android.app.IUserSwitchObserver;
40 import android.app.Notification;
41 import android.app.PendingIntent;
42 import android.app.PictureInPictureParams;
43 import android.app.ProfilerInfo;
44 import android.app.WaitResult;
45 import android.app.assist.AssistContent;
46 import android.app.assist.AssistStructure;
47 import android.content.ComponentName;
48 import android.content.IIntentReceiver;
49 import android.content.IIntentSender;
50 import android.content.Intent;
51 import android.content.IntentFilter;
52 import android.content.IntentSender;
53 import android.content.pm.ApplicationInfo;
54 import android.content.pm.ConfigurationInfo;
55 import android.content.pm.IPackageDataObserver;
56 import android.content.pm.ParceledListSlice;
57 import android.content.pm.ProviderInfo;
58 import android.content.pm.ResolveInfo;
59 import android.content.pm.UserInfo;
60 import android.content.res.Configuration;
61 import android.content.LocusId;
62 import android.graphics.Bitmap;
63 import android.graphics.GraphicBuffer;
64 import android.graphics.Point;
65 import android.graphics.Rect;
66 import android.net.Uri;
67 import android.os.Bundle;
68 import android.os.Debug;
69 import android.os.IBinder;
70 import android.os.IProgressListener;
71 import android.os.ParcelFileDescriptor;
72 import android.os.PersistableBundle;
73 import android.os.RemoteCallback;
74 import android.os.StrictMode;
75 import android.os.WorkSource;
76 import android.service.voice.IVoiceInteractionSession;
77 import android.view.RemoteAnimationDefinition;
78 import android.view.RemoteAnimationAdapter;
79 import com.android.internal.app.IVoiceInteractor;
80 import com.android.internal.os.IResultReceiver;
81 import com.android.internal.policy.IKeyguardDismissCallback;
82 
83 import java.util.List;
84 
85 /**
86  * System private API for talking with the activity manager service.  This
87  * provides calls from the application back to the activity manager.
88  *
89  * {@hide}
90  */
91 interface IActivityManager {
92     // WARNING: when these transactions are updated, check if they are any callers on the native
93     // side. If so, make sure they are using the correct transaction ids and arguments.
94     // If a transaction which will also be used on the native side is being inserted, add it to
95     // below block of transactions.
96 
97     // Since these transactions are also called from native code, these must be kept in sync with
98     // the ones in frameworks/native/libs/binder/include_activitymanager/binder/ActivityManager.h
99     // =============== Beginning of transactions used on native side as well ======================
openContentUri(in String uriString)100     ParcelFileDescriptor openContentUri(in String uriString);
registerUidObserver(in IUidObserver observer, int which, int cutpoint, String callingPackage)101     void registerUidObserver(in IUidObserver observer, int which, int cutpoint,
102             String callingPackage);
unregisterUidObserver(in IUidObserver observer)103     void unregisterUidObserver(in IUidObserver observer);
104 
105     /**
106      * Registers a UidObserver with a uid filter.
107      *
108      * @param observer The UidObserver implementation to register.
109      * @param which    A bitmask of events to observe. See ActivityManager.UID_OBSERVER_*.
110      * @param cutpoint The cutpoint for onUidStateChanged events. When the state crosses this
111      *                 threshold in either direction, onUidStateChanged will be called.
112      * @param callingPackage The name of the calling package.
113      * @param uids     A list of uids to watch. If all uids are to be watched, use
114      *                 registerUidObserver instead.
115      * @throws RemoteException
116      * @return Returns A binder token identifying the UidObserver registration.
117      */
118     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS)")
registerUidObserverForUids(in IUidObserver observer, int which, int cutpoint, String callingPackage, in int[] uids)119     IBinder registerUidObserverForUids(in IUidObserver observer, int which, int cutpoint,
120             String callingPackage, in int[] uids);
121 
122     /**
123      * Adds a uid to the list of uids that a UidObserver will receive updates about.
124      *
125      * @param observerToken  The binder token identifying the UidObserver registration.
126      * @param callingPackage The name of the calling package.
127      * @param uid            The uid to watch.
128      * @throws RemoteException
129      */
addUidToObserver(in IBinder observerToken, String callingPackage, int uid)130     void addUidToObserver(in IBinder observerToken, String callingPackage, int uid);
131 
132     /**
133      * Removes a uid from the list of uids that a UidObserver will receive updates about.
134      *
135      * @param observerToken  The binder token identifying the UidObserver registration.
136      * @param callingPackage The name of the calling package.
137      * @param uid            The uid to stop watching.
138      * @throws RemoteException
139      */
removeUidFromObserver(in IBinder observerToken, String callingPackage, int uid)140     void removeUidFromObserver(in IBinder observerToken, String callingPackage, int uid);
141 
isUidActive(int uid, String callingPackage)142     boolean isUidActive(int uid, String callingPackage);
143     @JavaPassthrough(annotation=
144             "@android.annotation.RequiresPermission(allOf = {android.Manifest.permission.PACKAGE_USAGE_STATS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}, conditional = true)")
getUidProcessState(int uid, in String callingPackage)145     int getUidProcessState(int uid, in String callingPackage);
146     @UnsupportedAppUsage
checkPermission(in String permission, int pid, int uid)147     int checkPermission(in String permission, int pid, int uid);
148 
149     /** Logs start of an API call to associate with an FGS, used for FGS Type Metrics */
logFgsApiBegin(int apiType, int appUid, int appPid)150     oneway void logFgsApiBegin(int apiType, int appUid, int appPid);
151 
152     /** Logs stop of an API call to associate with an FGS, used for FGS Type Metrics */
logFgsApiEnd(int apiType, int appUid, int appPid)153     oneway void logFgsApiEnd(int apiType, int appUid, int appPid);
154 
155     /** Logs API state change to associate with an FGS, used for FGS Type Metrics */
logFgsApiStateChanged(int apiType, int state, int appUid, int appPid)156     oneway void logFgsApiStateChanged(int apiType, int state, int appUid, int appPid);
157     // =============== End of transactions used on native side as well ============================
158 
159     // Special low-level communication with activity manager.
handleApplicationCrash(in IBinder app, in ApplicationErrorReport.ParcelableCrashInfo crashInfo)160     void handleApplicationCrash(in IBinder app,
161             in ApplicationErrorReport.ParcelableCrashInfo crashInfo);
162     /** @deprecated Use {@link #startActivityWithFeature} instead */
163     @UnsupportedAppUsage(maxTargetSdk=29, publicAlternatives="Use {@link android.content.Context#startActivity(android.content.Intent)} instead")
startActivity(in IApplicationThread caller, in String callingPackage, in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho, int requestCode, int flags, in ProfilerInfo profilerInfo, in Bundle options)164     int startActivity(in IApplicationThread caller, in String callingPackage, in Intent intent,
165             in String resolvedType, in IBinder resultTo, in String resultWho, int requestCode,
166             int flags, in ProfilerInfo profilerInfo, in Bundle options);
startActivityWithFeature(in IApplicationThread caller, in String callingPackage, in String callingFeatureId, in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho, int requestCode, int flags, in ProfilerInfo profilerInfo, in Bundle options)167     int startActivityWithFeature(in IApplicationThread caller, in String callingPackage,
168             in String callingFeatureId, in Intent intent, in String resolvedType,
169             in IBinder resultTo, in String resultWho, int requestCode, int flags,
170             in ProfilerInfo profilerInfo, in Bundle options);
171     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
unhandledBack()172     void unhandledBack();
173     @UnsupportedAppUsage
finishActivity(in IBinder token, int code, in Intent data, int finishTask)174     boolean finishActivity(in IBinder token, int code, in Intent data, int finishTask);
175     @UnsupportedAppUsage(maxTargetSdk=29, publicAlternatives="Use {@link android.content.Context#registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter)} instead")
registerReceiver(in IApplicationThread caller, in String callerPackage, in IIntentReceiver receiver, in IntentFilter filter, in String requiredPermission, int userId, int flags)176     Intent registerReceiver(in IApplicationThread caller, in String callerPackage,
177             in IIntentReceiver receiver, in IntentFilter filter,
178             in String requiredPermission, int userId, int flags);
registerReceiverWithFeature(in IApplicationThread caller, in String callerPackage, in String callingFeatureId, in String receiverId, in IIntentReceiver receiver, in IntentFilter filter, in String requiredPermission, int userId, int flags)179     Intent registerReceiverWithFeature(in IApplicationThread caller, in String callerPackage,
180             in String callingFeatureId, in String receiverId, in IIntentReceiver receiver,
181             in IntentFilter filter, in String requiredPermission, int userId, int flags);
182     @UnsupportedAppUsage
unregisterReceiver(in IIntentReceiver receiver)183     void unregisterReceiver(in IIntentReceiver receiver);
184     /** @deprecated Use {@link #broadcastIntentWithFeature} instead */
185     @UnsupportedAppUsage(maxTargetSdk=29, publicAlternatives="Use {@link android.content.Context#sendBroadcast(android.content.Intent)} instead")
broadcastIntent(in IApplicationThread caller, in Intent intent, in String resolvedType, in IIntentReceiver resultTo, int resultCode, in String resultData, in Bundle map, in String[] requiredPermissions, int appOp, in Bundle options, boolean serialized, boolean sticky, int userId)186     int broadcastIntent(in IApplicationThread caller, in Intent intent,
187             in String resolvedType, in IIntentReceiver resultTo, int resultCode,
188             in String resultData, in Bundle map, in String[] requiredPermissions,
189             int appOp, in Bundle options, boolean serialized, boolean sticky, int userId);
broadcastIntentWithFeature(in IApplicationThread caller, in String callingFeatureId, in Intent intent, in String resolvedType, in IIntentReceiver resultTo, int resultCode, in String resultData, in Bundle map, in String[] requiredPermissions, in String[] excludePermissions, in String[] excludePackages, int appOp, in Bundle options, boolean serialized, boolean sticky, int userId)190     int broadcastIntentWithFeature(in IApplicationThread caller, in String callingFeatureId,
191             in Intent intent, in String resolvedType, in IIntentReceiver resultTo, int resultCode,
192             in String resultData, in Bundle map, in String[] requiredPermissions, in String[] excludePermissions,
193             in String[] excludePackages, int appOp, in Bundle options, boolean serialized, boolean sticky, int userId);
unbroadcastIntent(in IApplicationThread caller, in Intent intent, int userId)194     void unbroadcastIntent(in IApplicationThread caller, in Intent intent, int userId);
195     @UnsupportedAppUsage
finishReceiver(in IBinder who, int resultCode, in String resultData, in Bundle map, boolean abortBroadcast, int flags)196     oneway void finishReceiver(in IBinder who, int resultCode, in String resultData, in Bundle map,
197             boolean abortBroadcast, int flags);
attachApplication(in IApplicationThread app, long startSeq)198     void attachApplication(in IApplicationThread app, long startSeq);
finishAttachApplication(long startSeq, long timestampApplicationOnCreateNs)199     void finishAttachApplication(long startSeq, long timestampApplicationOnCreateNs);
getTasks(int maxNum)200     List<ActivityManager.RunningTaskInfo> getTasks(int maxNum);
201     @UnsupportedAppUsage
moveTaskToFront(in IApplicationThread caller, in String callingPackage, int task, int flags, in Bundle options)202     void moveTaskToFront(in IApplicationThread caller, in String callingPackage, int task,
203             int flags, in Bundle options);
204     @UnsupportedAppUsage
getTaskForActivity(in IBinder token, in boolean onlyRoot)205     int getTaskForActivity(in IBinder token, in boolean onlyRoot);
getContentProvider(in IApplicationThread caller, in String callingPackage, in String name, int userId, boolean stable)206     ContentProviderHolder getContentProvider(in IApplicationThread caller, in String callingPackage,
207             in String name, int userId, boolean stable);
208     @UnsupportedAppUsage
publishContentProviders(in IApplicationThread caller, in List<ContentProviderHolder> providers)209     void publishContentProviders(in IApplicationThread caller,
210             in List<ContentProviderHolder> providers);
refContentProvider(in IBinder connection, int stableDelta, int unstableDelta)211     boolean refContentProvider(in IBinder connection, int stableDelta, int unstableDelta);
getRunningServiceControlPanel(in ComponentName service)212     PendingIntent getRunningServiceControlPanel(in ComponentName service);
startService(in IApplicationThread caller, in Intent service, in String resolvedType, boolean requireForeground, in String callingPackage, in String callingFeatureId, int userId)213     ComponentName startService(in IApplicationThread caller, in Intent service,
214             in String resolvedType, boolean requireForeground, in String callingPackage,
215             in String callingFeatureId, int userId);
216     @UnsupportedAppUsage
stopService(in IApplicationThread caller, in Intent service, in String resolvedType, int userId)217     int stopService(in IApplicationThread caller, in Intent service,
218             in String resolvedType, int userId);
219     // Currently keeping old bindService because it is on the greylist
220     @UnsupportedAppUsage
bindService(in IApplicationThread caller, in IBinder token, in Intent service, in String resolvedType, in IServiceConnection connection, long flags, in String callingPackage, int userId)221     int bindService(in IApplicationThread caller, in IBinder token, in Intent service,
222             in String resolvedType, in IServiceConnection connection, long flags,
223             in String callingPackage, int userId);
bindServiceInstance(in IApplicationThread caller, in IBinder token, in Intent service, in String resolvedType, in IServiceConnection connection, long flags, in String instanceName, in String callingPackage, int userId)224     int bindServiceInstance(in IApplicationThread caller, in IBinder token, in Intent service,
225             in String resolvedType, in IServiceConnection connection, long flags,
226             in String instanceName, in String callingPackage, int userId);
updateServiceGroup(in IServiceConnection connection, int group, int importance)227     void updateServiceGroup(in IServiceConnection connection, int group, int importance);
228     @UnsupportedAppUsage
unbindService(in IServiceConnection connection)229     boolean unbindService(in IServiceConnection connection);
publishService(in IBinder token, in Intent intent, in IBinder service)230     void publishService(in IBinder token, in Intent intent, in IBinder service);
231     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
setDebugApp(in String packageName, boolean waitForDebugger, boolean persistent)232     void setDebugApp(in String packageName, boolean waitForDebugger, boolean persistent);
setAgentApp(in String packageName, @nullable String agent)233     void setAgentApp(in String packageName, @nullable String agent);
234     @UnsupportedAppUsage
setAlwaysFinish(boolean enabled)235     void setAlwaysFinish(boolean enabled);
236     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
startInstrumentation(in ComponentName className, in String profileFile, int flags, in Bundle arguments, in IInstrumentationWatcher watcher, in IUiAutomationConnection connection, int userId, in String abiOverride)237     boolean startInstrumentation(in ComponentName className, in String profileFile,
238             int flags, in Bundle arguments, in IInstrumentationWatcher watcher,
239             in IUiAutomationConnection connection, int userId,
240             in String abiOverride);
addInstrumentationResults(in IApplicationThread target, in Bundle results)241     void addInstrumentationResults(in IApplicationThread target, in Bundle results);
finishInstrumentation(in IApplicationThread target, int resultCode, in Bundle results)242     void finishInstrumentation(in IApplicationThread target, int resultCode,
243             in Bundle results);
244     /**
245      * @return A copy of global {@link Configuration}, contains general settings for the entire
246      *         system. Corresponds to the configuration of the default display.
247      * @throws RemoteException
248      */
249     @UnsupportedAppUsage
getConfiguration()250     Configuration getConfiguration();
251     /**
252      * Updates global configuration and applies changes to the entire system.
253      * @param values Update values for global configuration. If null is passed it will request the
254      *               Window Manager to compute new config for the default display.
255      * @throws RemoteException
256      * @return Returns true if the configuration was updated.
257      */
258     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
updateConfiguration(in Configuration values)259     boolean updateConfiguration(in Configuration values);
260     /**
261      * Updates mcc mnc configuration and applies changes to the entire system.
262      *
263      * @param mcc mcc configuration to update.
264      * @param mnc mnc configuration to update.
265      * @throws RemoteException; IllegalArgumentException if mcc or mnc is null.
266      * @return Returns {@code true} if the configuration was updated;
267      *         {@code false} otherwise.
268      */
updateMccMncConfiguration(in String mcc, in String mnc)269     boolean updateMccMncConfiguration(in String mcc, in String mnc);
stopServiceToken(in ComponentName className, in IBinder token, int startId)270     boolean stopServiceToken(in ComponentName className, in IBinder token, int startId);
271     @UnsupportedAppUsage
setProcessLimit(int max)272     void setProcessLimit(int max);
273     @UnsupportedAppUsage
getProcessLimit()274     int getProcessLimit();
checkUriPermission(in Uri uri, int pid, int uid, int mode, int userId, in IBinder callerToken)275     int checkUriPermission(in Uri uri, int pid, int uid, int mode, int userId,
276             in IBinder callerToken);
checkContentUriPermissionFull(in Uri uri, int pid, int uid, int mode, int userId)277     int checkContentUriPermissionFull(in Uri uri, int pid, int uid, int mode, int userId);
checkUriPermissions(in List<Uri> uris, int pid, int uid, int mode, int userId, in IBinder callerToken)278     int[] checkUriPermissions(in List<Uri> uris, int pid, int uid, int mode, int userId,
279                 in IBinder callerToken);
grantUriPermission(in IApplicationThread caller, in String targetPkg, in Uri uri, int mode, int userId)280     void grantUriPermission(in IApplicationThread caller, in String targetPkg, in Uri uri,
281             int mode, int userId);
revokeUriPermission(in IApplicationThread caller, in String targetPkg, in Uri uri, int mode, int userId)282     void revokeUriPermission(in IApplicationThread caller, in String targetPkg, in Uri uri,
283             int mode, int userId);
284     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
setActivityController(in IActivityController watcher, boolean imAMonkey)285     void setActivityController(in IActivityController watcher, boolean imAMonkey);
showWaitingForDebugger(in IApplicationThread who, boolean waiting)286     void showWaitingForDebugger(in IApplicationThread who, boolean waiting);
287     /*
288      * This will deliver the specified signal to all the persistent processes. Currently only
289      * SIGUSR1 is delivered. All others are ignored.
290      */
signalPersistentProcesses(int signal)291     void signalPersistentProcesses(int signal);
292 
293     @UnsupportedAppUsage
getRecentTasks(int maxNum, int flags, int userId)294     ParceledListSlice getRecentTasks(int maxNum, int flags, int userId);
295     @UnsupportedAppUsage
serviceDoneExecuting(in IBinder token, int type, int startId, int res, in Intent intent)296     oneway void serviceDoneExecuting(in IBinder token, int type, int startId, int res,
297             in Intent intent);
298     /** @deprecated  Use {@link #getIntentSenderWithFeature} instead */
299     @UnsupportedAppUsage(maxTargetSdk=29, publicAlternatives="Use {@link PendingIntent#getIntentSender()} instead")
getIntentSender(int type, in String packageName, in IBinder token, in String resultWho, int requestCode, in Intent[] intents, in String[] resolvedTypes, int flags, in Bundle options, int userId)300     IIntentSender getIntentSender(int type, in String packageName, in IBinder token,
301             in String resultWho, int requestCode, in Intent[] intents, in String[] resolvedTypes,
302             int flags, in Bundle options, int userId);
getIntentSenderWithFeature(int type, in String packageName, in String featureId, in IBinder token, in String resultWho, int requestCode, in Intent[] intents, in String[] resolvedTypes, int flags, in Bundle options, int userId)303     IIntentSender getIntentSenderWithFeature(int type, in String packageName, in String featureId,
304             in IBinder token, in String resultWho, int requestCode, in Intent[] intents,
305             in String[] resolvedTypes, int flags, in Bundle options, int userId);
cancelIntentSender(in IIntentSender sender)306     void cancelIntentSender(in IIntentSender sender);
getInfoForIntentSender(in IIntentSender sender)307     ActivityManager.PendingIntentInfo getInfoForIntentSender(in IIntentSender sender);
308     /**
309       This method used to be called registerIntentSenderCancelListener(), was void, and
310       would call `receiver` if the PI has already been canceled.
311       Now it returns false if the PI is cancelled, without calling `receiver`.
312       The method was renamed to catch calls to the original method.
313      */
registerIntentSenderCancelListenerEx(in IIntentSender sender, in IResultReceiver receiver)314     boolean registerIntentSenderCancelListenerEx(in IIntentSender sender,
315         in IResultReceiver receiver);
unregisterIntentSenderCancelListener(in IIntentSender sender, in IResultReceiver receiver)316     void unregisterIntentSenderCancelListener(in IIntentSender sender, in IResultReceiver receiver);
enterSafeMode()317     void enterSafeMode();
noteWakeupAlarm(in IIntentSender sender, in WorkSource workSource, int sourceUid, in String sourcePkg, in String tag)318     void noteWakeupAlarm(in IIntentSender sender, in WorkSource workSource, int sourceUid,
319             in String sourcePkg, in String tag);
removeContentProvider(in IBinder connection, boolean stable)320     oneway void removeContentProvider(in IBinder connection, boolean stable);
321     @UnsupportedAppUsage
setRequestedOrientation(in IBinder token, int requestedOrientation)322     void setRequestedOrientation(in IBinder token, int requestedOrientation);
unbindFinished(in IBinder token, in Intent service, boolean doRebind)323     void unbindFinished(in IBinder token, in Intent service, boolean doRebind);
324     @UnsupportedAppUsage
setProcessImportant(in IBinder token, int pid, boolean isForeground, String reason)325     void setProcessImportant(in IBinder token, int pid, boolean isForeground, String reason);
setServiceForeground(in ComponentName className, in IBinder token, int id, in Notification notification, int flags, int foregroundServiceType)326     void setServiceForeground(in ComponentName className, in IBinder token,
327             int id, in Notification notification, int flags, int foregroundServiceType);
getForegroundServiceType(in ComponentName className, in IBinder token)328     int getForegroundServiceType(in ComponentName className, in IBinder token);
329     @UnsupportedAppUsage
moveActivityTaskToBack(in IBinder token, boolean nonRoot)330     boolean moveActivityTaskToBack(in IBinder token, boolean nonRoot);
331     @UnsupportedAppUsage
getMemoryInfo(out ActivityManager.MemoryInfo outInfo)332     void getMemoryInfo(out ActivityManager.MemoryInfo outInfo);
getProcessesInErrorState()333     List<ActivityManager.ProcessErrorStateInfo> getProcessesInErrorState();
clearApplicationUserData(in String packageName, boolean keepState, in IPackageDataObserver observer, int userId)334     boolean clearApplicationUserData(in String packageName, boolean keepState,
335             in IPackageDataObserver observer, int userId);
stopAppForUser(in String packageName, int userId)336     void stopAppForUser(in String packageName, int userId);
337     /** Returns {@code false} if the callback could not be registered, {@true} otherwise. */
registerForegroundServiceObserver(in IForegroundServiceObserver callback)338     boolean registerForegroundServiceObserver(in IForegroundServiceObserver callback);
339     @UnsupportedAppUsage
forceStopPackage(in String packageName, int userId)340     void forceStopPackage(in String packageName, int userId);
forceStopPackageEvenWhenStopping(in String packageName, int userId)341     void forceStopPackageEvenWhenStopping(in String packageName, int userId);
killPids(in int[] pids, in String reason, boolean secure)342     boolean killPids(in int[] pids, in String reason, boolean secure);
343     @UnsupportedAppUsage
getServices(int maxNum, int flags)344     List<ActivityManager.RunningServiceInfo> getServices(int maxNum, int flags);
345     // Retrieve running application processes in the system
346     @UnsupportedAppUsage
getRunningAppProcesses()347     List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses();
peekService(in Intent service, in String resolvedType, in String callingPackage)348     IBinder peekService(in Intent service, in String resolvedType, in String callingPackage);
349     // Turn on/off profiling in a particular process.
350     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
profileControl(in String process, int userId, boolean start, in ProfilerInfo profilerInfo, int profileType)351     boolean profileControl(in String process, int userId, boolean start,
352             in ProfilerInfo profilerInfo, int profileType);
353     @UnsupportedAppUsage
shutdown(int timeout)354     boolean shutdown(int timeout);
355     @UnsupportedAppUsage
stopAppSwitches()356     void stopAppSwitches();
357     @UnsupportedAppUsage
resumeAppSwitches()358     void resumeAppSwitches();
bindBackupAgent(in String packageName, int backupRestoreMode, int targetUserId, int backupDestination)359     boolean bindBackupAgent(in String packageName, int backupRestoreMode, int targetUserId,
360             int backupDestination);
backupAgentCreated(in String packageName, in IBinder agent, int userId)361     void backupAgentCreated(in String packageName, in IBinder agent, int userId);
unbindBackupAgent(in ApplicationInfo appInfo)362     void unbindBackupAgent(in ApplicationInfo appInfo);
handleIncomingUser(int callingPid, int callingUid, int userId, boolean allowAll, boolean requireFull, in String name, in String callerPackage)363     int handleIncomingUser(int callingPid, int callingUid, int userId, boolean allowAll,
364             boolean requireFull, in String name, in String callerPackage);
addPackageDependency(in String packageName)365     void addPackageDependency(in String packageName);
killApplication(in String pkg, int appId, int userId, in String reason, int exitInfoReason)366     void killApplication(in String pkg, int appId, int userId, in String reason,
367             int exitInfoReason);
368     @UnsupportedAppUsage
closeSystemDialogs(in String reason)369     void closeSystemDialogs(in String reason);
370     @UnsupportedAppUsage
getProcessMemoryInfo(in int[] pids)371     Debug.MemoryInfo[] getProcessMemoryInfo(in int[] pids);
killApplicationProcess(in String processName, int uid)372     void killApplicationProcess(in String processName, int uid);
373     // Special low-level communication with activity manager.
handleApplicationWtf(in IBinder app, in String tag, boolean system, in ApplicationErrorReport.ParcelableCrashInfo crashInfo, int immediateCallerPid)374     boolean handleApplicationWtf(in IBinder app, in String tag, boolean system,
375             in ApplicationErrorReport.ParcelableCrashInfo crashInfo, int immediateCallerPid);
376     @UnsupportedAppUsage
killBackgroundProcesses(in String packageName, int userId)377     void killBackgroundProcesses(in String packageName, int userId);
isUserAMonkey()378     boolean isUserAMonkey();
379     // Retrieve info of applications installed on external media that are currently
380     // running.
getRunningExternalApplications()381     List<ApplicationInfo> getRunningExternalApplications();
382     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
finishHeavyWeightApp()383     void finishHeavyWeightApp();
384     // A StrictMode violation to be handled.
385     @UnsupportedAppUsage
handleApplicationStrictModeViolation(in IBinder app, int penaltyMask, in StrictMode.ViolationInfo crashInfo)386     void handleApplicationStrictModeViolation(in IBinder app, int penaltyMask,
387             in StrictMode.ViolationInfo crashInfo);
registerStrictModeCallback(in IBinder binder)388     void registerStrictModeCallback(in IBinder binder);
isTopActivityImmersive()389     boolean isTopActivityImmersive();
crashApplicationWithType(int uid, int initialPid, in String packageName, int userId, in String message, boolean force, int exceptionTypeId)390     void crashApplicationWithType(int uid, int initialPid, in String packageName, int userId,
391             in String message, boolean force, int exceptionTypeId);
crashApplicationWithTypeWithExtras(int uid, int initialPid, in String packageName, int userId, in String message, boolean force, int exceptionTypeId, in Bundle extras)392     void crashApplicationWithTypeWithExtras(int uid, int initialPid, in String packageName,
393             int userId, in String message, boolean force, int exceptionTypeId, in Bundle extras);
getMimeTypeFilterAsync(in Uri uri, int userId, in RemoteCallback resultCallback)394     oneway void getMimeTypeFilterAsync(in Uri uri, int userId, in RemoteCallback resultCallback);
395     // Cause the specified process to dump the specified heap.
dumpHeap(in String process, int userId, boolean managed, boolean mallocInfo, boolean runGc, in String dumpBitmaps, in String path, in ParcelFileDescriptor fd, in RemoteCallback finishCallback)396     boolean dumpHeap(in String process, int userId, boolean managed, boolean mallocInfo,
397             boolean runGc, in String dumpBitmaps, in String path, in ParcelFileDescriptor fd,
398             in RemoteCallback finishCallback);
399     @UnsupportedAppUsage
isUserRunning(int userid, int flags)400     boolean isUserRunning(int userid, int flags);
401     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
setPackageScreenCompatMode(in String packageName, int mode)402     void setPackageScreenCompatMode(in String packageName, int mode);
403     @UnsupportedAppUsage
switchUser(int userid)404     boolean switchUser(int userid);
getSwitchingFromUserMessage()405     String getSwitchingFromUserMessage();
getSwitchingToUserMessage()406     String getSwitchingToUserMessage();
407     @UnsupportedAppUsage
setStopUserOnSwitch(int value)408     void setStopUserOnSwitch(int value);
removeTask(int taskId)409     boolean removeTask(int taskId);
410     @UnsupportedAppUsage
registerProcessObserver(in IProcessObserver observer)411     void registerProcessObserver(in IProcessObserver observer);
412     @UnsupportedAppUsage
unregisterProcessObserver(in IProcessObserver observer)413     void unregisterProcessObserver(in IProcessObserver observer);
isIntentSenderTargetedToPackage(in IIntentSender sender)414     boolean isIntentSenderTargetedToPackage(in IIntentSender sender);
415     @UnsupportedAppUsage
updatePersistentConfiguration(in Configuration values)416     void updatePersistentConfiguration(in Configuration values);
updatePersistentConfigurationWithAttribution(in Configuration values, String callingPackageName, String callingAttributionTag)417     void updatePersistentConfigurationWithAttribution(in Configuration values,
418             String callingPackageName, String callingAttributionTag);
419     @UnsupportedAppUsage
getProcessPss(in int[] pids)420     long[] getProcessPss(in int[] pids);
showBootMessage(in CharSequence msg, boolean always)421     void showBootMessage(in CharSequence msg, boolean always);
422     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
killAllBackgroundProcesses()423     void killAllBackgroundProcesses();
getContentProviderExternal(in String name, int userId, in IBinder token, String tag)424     ContentProviderHolder getContentProviderExternal(in String name, int userId,
425             in IBinder token, String tag);
426     /** @deprecated - Use {@link #removeContentProviderExternalAsUser} which takes a user ID. */
427     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
removeContentProviderExternal(in String name, in IBinder token)428     void removeContentProviderExternal(in String name, in IBinder token);
removeContentProviderExternalAsUser(in String name, in IBinder token, int userId)429     void removeContentProviderExternalAsUser(in String name, in IBinder token, int userId);
430     // Get memory information about the calling process.
getMyMemoryState(out ActivityManager.RunningAppProcessInfo outInfo)431     void getMyMemoryState(out ActivityManager.RunningAppProcessInfo outInfo);
killProcessesBelowForeground(in String reason)432     boolean killProcessesBelowForeground(in String reason);
433     @UnsupportedAppUsage
getCurrentUser()434     UserInfo getCurrentUser();
getCurrentUserId()435     int getCurrentUserId();
436     // This is not public because you need to be very careful in how you
437     // manage your activity to make sure it is always the uid you expect.
438     @UnsupportedAppUsage
getLaunchedFromUid(in IBinder activityToken)439     int getLaunchedFromUid(in IBinder activityToken);
440     @UnsupportedAppUsage
unstableProviderDied(in IBinder connection)441     void unstableProviderDied(in IBinder connection);
442     @UnsupportedAppUsage
isIntentSenderAnActivity(in IIntentSender sender)443     boolean isIntentSenderAnActivity(in IIntentSender sender);
444     /** @deprecated Use {@link startActivityAsUserWithFeature} instead */
445     @UnsupportedAppUsage(maxTargetSdk=29, publicAlternatives="Use {@code android.content.Context#createContextAsUser(android.os.UserHandle, int)} and {@link android.content.Context#startActivity(android.content.Intent)} instead")
startActivityAsUser(in IApplicationThread caller, in String callingPackage, in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho, int requestCode, int flags, in ProfilerInfo profilerInfo, in Bundle options, int userId)446     int startActivityAsUser(in IApplicationThread caller, in String callingPackage,
447             in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho,
448             int requestCode, int flags, in ProfilerInfo profilerInfo,
449             in Bundle options, int userId);
startActivityAsUserWithFeature(in IApplicationThread caller, in String callingPackage, in String callingFeatureId, in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho, int requestCode, int flags, in ProfilerInfo profilerInfo, in Bundle options, int userId)450     int startActivityAsUserWithFeature(in IApplicationThread caller, in String callingPackage,
451             in String callingFeatureId, in Intent intent, in String resolvedType,
452             in IBinder resultTo, in String resultWho, int requestCode, int flags,
453             in ProfilerInfo profilerInfo, in Bundle options, int userId);
454     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
stopUser(int userid, boolean stopProfileRegardlessOfParent, in IStopUserCallback callback)455     int stopUser(int userid, boolean stopProfileRegardlessOfParent, in IStopUserCallback callback);
stopUserWithCallback(int userid, in IStopUserCallback callback)456     int stopUserWithCallback(int userid, in IStopUserCallback callback);
stopUserExceptCertainProfiles(int userid, boolean stopProfileRegardlessOfParent, in IStopUserCallback callback)457     int stopUserExceptCertainProfiles(int userid, boolean stopProfileRegardlessOfParent, in IStopUserCallback callback);
458     /**
459      * Check {@link com.android.server.am.ActivityManagerService#stopUserWithDelayedLocking(int, IStopUserCallback)}
460      * for details.
461      */
stopUserWithDelayedLocking(int userid, in IStopUserCallback callback)462     int stopUserWithDelayedLocking(int userid, in IStopUserCallback callback);
463 
464     @UnsupportedAppUsage
registerUserSwitchObserver(in IUserSwitchObserver observer, in String name)465     void registerUserSwitchObserver(in IUserSwitchObserver observer, in String name);
unregisterUserSwitchObserver(in IUserSwitchObserver observer)466     void unregisterUserSwitchObserver(in IUserSwitchObserver observer);
getRunningUserIds()467     int[] getRunningUserIds();
468 
469     // Request a heap dump for the system server.
requestSystemServerHeapDump()470     void requestSystemServerHeapDump();
471 
requestBugReport(int bugreportType)472     void requestBugReport(int bugreportType);
requestBugReportWithDescription(in @ullable String shareTitle, in @nullable String shareDescription, int bugreportType)473     void requestBugReportWithDescription(in @nullable String shareTitle,
474                 in @nullable String shareDescription, int bugreportType);
475 
476     /**
477      *  Takes a telephony bug report and notifies the user with the title and description
478      *  that are passed to this API as parameters
479      *
480      *  @param shareTitle should be a valid legible string less than 50 chars long
481      *  @param shareDescription should be less than 150 chars long
482      *
483      *  @throws IllegalArgumentException if shareTitle or shareDescription is too big or if the
484      *          paremeters cannot be encoding to an UTF-8 charset.
485      */
requestTelephonyBugReport(in String shareTitle, in String shareDescription)486     void requestTelephonyBugReport(in String shareTitle, in String shareDescription);
487 
488     /**
489      *  This method is only used by Wifi.
490      *
491      *  Takes a minimal bugreport of Wifi-related state.
492      *
493      *  @param shareTitle should be a valid legible string less than 50 chars long
494      *  @param shareDescription should be less than 150 chars long
495      *
496      *  @throws IllegalArgumentException if shareTitle or shareDescription is too big or if the
497      *          parameters cannot be encoding to an UTF-8 charset.
498      */
requestWifiBugReport(in String shareTitle, in String shareDescription)499     void requestWifiBugReport(in String shareTitle, in String shareDescription);
requestInteractiveBugReportWithDescription(in String shareTitle, in String shareDescription)500     void requestInteractiveBugReportWithDescription(in String shareTitle,
501             in String shareDescription);
502 
requestInteractiveBugReport()503     void requestInteractiveBugReport();
requestBugReportWithExtraAttachment(in Uri extraAttachment)504     void requestBugReportWithExtraAttachment(in Uri extraAttachment);
requestFullBugReport()505     void requestFullBugReport();
requestRemoteBugReport(long nonce)506     void requestRemoteBugReport(long nonce);
launchBugReportHandlerApp()507     boolean launchBugReportHandlerApp();
getBugreportWhitelistedPackages()508     List<String> getBugreportWhitelistedPackages();
509 
510     @UnsupportedAppUsage
getIntentForIntentSender(in IIntentSender sender)511     Intent getIntentForIntentSender(in IIntentSender sender);
512     // This is not public because you need to be very careful in how you
513     // manage your activity to make sure it is always the uid you expect.
514     @UnsupportedAppUsage
getLaunchedFromPackage(in IBinder activityToken)515     String getLaunchedFromPackage(in IBinder activityToken);
killUid(int appId, int userId, in String reason)516     void killUid(int appId, int userId, in String reason);
setUserIsMonkey(boolean monkey)517     void setUserIsMonkey(boolean monkey);
518     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
hang(in IBinder who, boolean allowRestart)519     void hang(in IBinder who, boolean allowRestart);
520 
getAllRootTaskInfos()521     List<ActivityTaskManager.RootTaskInfo> getAllRootTaskInfos();
moveTaskToRootTask(int taskId, int rootTaskId, boolean toTop)522     void moveTaskToRootTask(int taskId, int rootTaskId, boolean toTop);
setFocusedRootTask(int taskId)523     void setFocusedRootTask(int taskId);
getFocusedRootTaskInfo()524     ActivityTaskManager.RootTaskInfo getFocusedRootTaskInfo();
525     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
restart()526     void restart();
performIdleMaintenance()527     void performIdleMaintenance();
appNotRespondingViaProvider(in IBinder connection)528     void appNotRespondingViaProvider(in IBinder connection);
529     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
getTaskBounds(int taskId)530     Rect getTaskBounds(int taskId);
531     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
setProcessMemoryTrimLevel(in String process, int userId, int level)532     boolean setProcessMemoryTrimLevel(in String process, int userId, int level);
533 
534 
535     // Start of L transactions
getTagForIntentSender(in IIntentSender sender, in String prefix)536     String getTagForIntentSender(in IIntentSender sender, in String prefix);
537 
538     /**
539       * Starts a user in the background (i.e., while another user is running in the foreground).
540       *
541       * Notice that a background user is "invisible" and cannot launch activities. Starting on
542       * Android U, all users started with this method are invisible, even profiles (prior to Android
543       * U, profiles started with this method would be visible if its parent was the current user) -
544       * if you want to start a profile visible, you should call {@code startProfile()} instead.
545       */
546     @UnsupportedAppUsage
startUserInBackground(int userid)547     boolean startUserInBackground(int userid);
548 
549     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
isInLockTaskMode()550     boolean isInLockTaskMode();
551     @UnsupportedAppUsage
startActivityFromRecents(int taskId, in Bundle options)552     int startActivityFromRecents(int taskId, in Bundle options);
553     @UnsupportedAppUsage
startSystemLockTaskMode(int taskId)554     void startSystemLockTaskMode(int taskId);
555     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
isTopOfTask(in IBinder token)556     boolean isTopOfTask(in IBinder token);
bootAnimationComplete()557     void bootAnimationComplete();
558 
559     /**
560      * Used by {@link com.android.systemui.theme.ThemeOverlayController} to notify when color
561      * palette is ready.
562      *
563      * @param userId The ID of the user where ThemeOverlayController is ready.
564      *
565      * @throws RemoteException
566      */
setThemeOverlayReady(int userId)567     void setThemeOverlayReady(int userId);
568 
569     @UnsupportedAppUsage
registerTaskStackListener(in ITaskStackListener listener)570     void registerTaskStackListener(in ITaskStackListener listener);
unregisterTaskStackListener(in ITaskStackListener listener)571     void unregisterTaskStackListener(in ITaskStackListener listener);
notifyCleartextNetwork(int uid, in byte[] firstPacket)572     void notifyCleartextNetwork(int uid, in byte[] firstPacket);
573     @UnsupportedAppUsage
setTaskResizeable(int taskId, int resizeableMode)574     void setTaskResizeable(int taskId, int resizeableMode);
575     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
resizeTask(int taskId, in Rect bounds, int resizeMode)576     void resizeTask(int taskId, in Rect bounds, int resizeMode);
577     @UnsupportedAppUsage
getLockTaskModeState()578     int getLockTaskModeState();
579     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
setDumpHeapDebugLimit(in String processName, int uid, long maxMemSize, in String reportPackage)580     void setDumpHeapDebugLimit(in String processName, int uid, long maxMemSize,
581             in String reportPackage);
dumpHeapFinished(in String path)582     void dumpHeapFinished(in String path);
updateLockTaskPackages(int userId, in String[] packages)583     void updateLockTaskPackages(int userId, in String[] packages);
noteAlarmStart(in IIntentSender sender, in WorkSource workSource, int sourceUid, in String tag)584     void noteAlarmStart(in IIntentSender sender, in WorkSource workSource, int sourceUid, in String tag);
noteAlarmFinish(in IIntentSender sender, in WorkSource workSource, int sourceUid, in String tag)585     void noteAlarmFinish(in IIntentSender sender, in WorkSource workSource, int sourceUid, in String tag);
586     @UnsupportedAppUsage
getPackageProcessState(in String packageName, in String callingPackage)587     int getPackageProcessState(in String packageName, in String callingPackage);
588 
589     // Start of N transactions
590     // Start Binder transaction tracking for all applications.
591     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
startBinderTracking()592     boolean startBinderTracking();
593     // Stop Binder transaction tracking for all applications and dump trace data to the given file
594     // descriptor.
595     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
stopBinderTrackingAndDump(in ParcelFileDescriptor fd)596     boolean stopBinderTrackingAndDump(in ParcelFileDescriptor fd);
597 
598     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
suppressResizeConfigChanges(boolean suppress)599     void suppressResizeConfigChanges(boolean suppress);
600 
601     /**
602      * @deprecated Use {@link #unlockUser2(int, IProgressListener)} instead, since the token and
603      * secret arguments no longer do anything.  This method still exists only because it is marked
604      * with {@code @UnsupportedAppUsage}, so it might not be safe to remove it or change its
605      * signature.
606      */
607     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
unlockUser(int userid, in byte[] token, in byte[] secret, in IProgressListener listener)608     boolean unlockUser(int userid, in byte[] token, in byte[] secret,
609             in IProgressListener listener);
610 
611     /**
612      * Tries to unlock the given user.
613      * <p>
614      * This will succeed only if the user's CE storage key is already unlocked or if the user
615      * doesn't have a lockscreen credential set.
616      *
617      * @param userId The ID of the user to unlock.
618      * @param listener An optional progress listener.
619      *
620      * @return true if the user was successfully unlocked, otherwise false.
621      */
unlockUser2(int userId, in IProgressListener listener)622     boolean unlockUser2(int userId, in IProgressListener listener);
623 
killPackageDependents(in String packageName, int userId)624     void killPackageDependents(in String packageName, int userId);
makePackageIdle(String packageName, int userId)625     void makePackageIdle(String packageName, int userId);
setDeterministicUidIdle(boolean deterministic)626     void setDeterministicUidIdle(boolean deterministic);
getMemoryTrimLevel()627     int getMemoryTrimLevel();
isVrModePackageEnabled(in ComponentName packageName)628     boolean isVrModePackageEnabled(in ComponentName packageName);
notifyLockedProfile(int userId)629     void notifyLockedProfile(int userId);
startConfirmDeviceCredentialIntent(in Intent intent, in Bundle options)630     void startConfirmDeviceCredentialIntent(in Intent intent, in Bundle options);
631     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
sendIdleJobTrigger()632     void sendIdleJobTrigger();
sendIntentSender(in IApplicationThread caller, in IIntentSender target, in IBinder whitelistToken, int code, in Intent intent, in String resolvedType, in IIntentReceiver finishedReceiver, in String requiredPermission, in Bundle options)633     int sendIntentSender(in IApplicationThread caller, in IIntentSender target,
634             in IBinder whitelistToken, int code,
635             in Intent intent, in String resolvedType, in IIntentReceiver finishedReceiver,
636             in String requiredPermission, in Bundle options);
isBackgroundRestricted(in String packageName)637     boolean isBackgroundRestricted(in String packageName);
638 
639     // Start of N MR1 transactions
setRenderThread(int tid)640     void setRenderThread(int tid);
641     /**
642      * Lets activity manager know whether the calling process is currently showing "top-level" UI
643      * that is not an activity, i.e. windows on the screen the user is currently interacting with.
644      *
645      * <p>This flag can only be set for persistent processes.
646      *
647      * @param hasTopUi Whether the calling process has "top-level" UI.
648      */
setHasTopUi(boolean hasTopUi)649     void setHasTopUi(boolean hasTopUi);
650 
651     // Start of O transactions
652     /** Cancels the window transitions for the given task. */
653     @UnsupportedAppUsage
cancelTaskWindowTransition(int taskId)654     void cancelTaskWindowTransition(int taskId);
scheduleApplicationInfoChanged(in List<String> packageNames, int userId)655     void scheduleApplicationInfoChanged(in List<String> packageNames, int userId);
setPersistentVrThread(int tid)656     void setPersistentVrThread(int tid);
657 
waitForNetworkStateUpdate(long procStateSeq)658     void waitForNetworkStateUpdate(long procStateSeq);
659     /**
660      * Add a bare uid to the background restrictions whitelist.  Only the system uid may call this.
661      */
backgroundAllowlistUid(int uid)662     void backgroundAllowlistUid(int uid);
663 
664     // Start of P transactions
665     /**
666      *  Similar to {@link #startUserInBackground(int userId), but with a listener to report
667      *  user unlock progress.
668      */
startUserInBackgroundWithListener(int userid, IProgressListener unlockProgressListener)669     boolean startUserInBackgroundWithListener(int userid, IProgressListener unlockProgressListener);
670 
671     /**
672      * Method for the shell UID to start deletating its permission identity to an
673      * active instrumenation. The shell can delegate permissions only to one active
674      * instrumentation at a time. An active instrumentation is one running and
675      * started from the shell.
676      */
startDelegateShellPermissionIdentity(int uid, in String[] permissions)677     void startDelegateShellPermissionIdentity(int uid, in String[] permissions);
678 
679     /**
680      * Method for the shell UID to stop deletating its permission identity to an
681      * active instrumenation. An active instrumentation is one running and
682      * started from the shell.
683      */
stopDelegateShellPermissionIdentity()684     void stopDelegateShellPermissionIdentity();
685 
686     /**
687      * Method for the shell UID to get currently adopted permissions for an active instrumentation.
688      * An active instrumentation is one running and started from the shell.
689      */
getDelegatedShellPermissions()690     List<String> getDelegatedShellPermissions();
691 
692     /** Returns a file descriptor that'll be closed when the system server process dies. */
getLifeMonitor()693     ParcelFileDescriptor getLifeMonitor();
694 
695     /**
696      * Start user, if it us not already running, and bring it to foreground.
697      * unlockProgressListener can be null if monitoring progress is not necessary.
698      */
startUserInForegroundWithListener(int userid, IProgressListener unlockProgressListener)699     boolean startUserInForegroundWithListener(int userid, IProgressListener unlockProgressListener);
700 
701     /**
702      * Method for the app to tell system that it's wedged and would like to trigger an ANR.
703      */
appNotResponding(String reason)704     void appNotResponding(String reason);
705 
706     /**
707      * Return a list of {@link ApplicationStartInfo} records.
708      *
709      * <p class="note"> Note: System stores historical information in a ring buffer, older
710      * records would be overwritten by newer records. </p>
711      *
712      * @param packageName Optional, an empty value means match all packages belonging to the
713      *                    caller's UID. If this package belongs to another UID, you must hold
714      *                    {@link android.Manifest.permission#DUMP} in order to retrieve it.
715      * @param maxNum      Optional, the maximum number of results should be returned; A value of 0
716      *                    means to ignore this parameter and return all matching records
717      * @param userId      The userId in the multi-user environment.
718      *
719      * @return a list of {@link ApplicationStartInfo} records with the matching criteria, sorted in
720      *         the order from most recent to least recent.
721      */
getHistoricalProcessStartReasons(String packageName, int maxNum, int userId)722     ParceledListSlice<ApplicationStartInfo> getHistoricalProcessStartReasons(String packageName,
723             int maxNum, int userId);
724 
725 
726     /**
727      * Sets a callback for {@link ApplicationStartInfo} upon completion of collecting startup data.
728      *
729      * <p class="note"> Note: completion of startup is no guaranteed and as such this callback may not occur.</p>
730      *
731      * @param listener    A listener to for the callback upon completion of startup data collection.
732      * @param userId      The userId in the multi-user environment.
733      */
addApplicationStartInfoCompleteListener(IApplicationStartInfoCompleteListener listener, int userId)734     void addApplicationStartInfoCompleteListener(IApplicationStartInfoCompleteListener listener,
735             int userId);
736 
737 
738     /**
739      * Removes callback for {@link ApplicationStartInfo} upon completion of collecting startup data.
740      *
741      * @param userId      The userId in the multi-user environment.
742      */
removeApplicationStartInfoCompleteListener(IApplicationStartInfoCompleteListener listener, int userId)743     void removeApplicationStartInfoCompleteListener(IApplicationStartInfoCompleteListener listener,
744             int userId);
745 
746 
747     /**
748      * Adds a timestamp of the moment called to the calling apps most recent
749      * {@link ApplicationStartInfo}.
750      *
751      *
752      * @param key         Unique key for timestamp.
753      * @param timestampNs Clock monotonic time in nanoseconds of event to be
754      *                    recorded.
755      * @param userId      The userId in the multi-user environment.
756      */
addStartInfoTimestamp(int key, long timestampNs, int userId)757     void addStartInfoTimestamp(int key, long timestampNs, int userId);
758 
759     /**
760     * Reports view related timestamps to be added to the calling apps most
761     * recent {@link ApplicationStartInfo}.
762     *
763     * @param renderThreadDrawStartTimeNs Clock monotonic time in nanoseconds of RenderThread draw start
764     * @param framePresentedTimeNs        Clock monotonic time in nanoseconds of frame presented
765     */
reportStartInfoViewTimestamps(long renderThreadDrawStartTimeNs, long framePresentedTimeNs)766     oneway void reportStartInfoViewTimestamps(long renderThreadDrawStartTimeNs, long framePresentedTimeNs);
767 
768     /**
769      * Return a list of {@link ApplicationExitInfo} records.
770      *
771      * <p class="note"> Note: System stores these historical information in a ring buffer, older
772      * records would be overwritten by newer records. </p>
773      *
774      * <p class="note"> Note: In the case that this application bound to an external service with
775      * flag {@link android.content.Context#BIND_EXTERNAL_SERVICE}, the process of that external
776      * service will be included in this package's exit info. </p>
777      *
778      * @param packageName Optional, an empty value means match all packages belonging to the
779      *                    caller's UID. If this package belongs to another UID, you must hold
780      *                    {@link android.Manifest.permission#DUMP} in order to retrieve it.
781      * @param pid         Optional, it could be a process ID that used to belong to this package but
782      *                    died later; A value of 0 means to ignore this parameter and return all
783      *                    matching records.
784      * @param maxNum      Optional, the maximum number of results should be returned; A value of 0
785      *                    means to ignore this parameter and return all matching records
786      * @param userId      The userId in the multi-user environment.
787      *
788      * @return a list of {@link ApplicationExitInfo} records with the matching criteria, sorted in
789      *         the order from most recent to least recent.
790      */
getHistoricalProcessExitReasons(String packageName, int pid, int maxNum, int userId)791     ParceledListSlice<ApplicationExitInfo> getHistoricalProcessExitReasons(String packageName,
792             int pid, int maxNum, int userId);
793 
794     /*
795      * Kill the given PIDs, but the killing will be delayed until the device is idle
796      * and the given process is imperceptible.
797      */
killProcessesWhenImperceptible(in int[] pids, String reason)798     void killProcessesWhenImperceptible(in int[] pids, String reason);
799 
800     /**
801      * Set locus context for a given activity.
802      * @param activity
803      * @param locusId a unique, stable id that identifies this activity instance from others.
804      * @param appToken ActivityRecord's appToken.
805      */
setActivityLocusContext(in ComponentName activity, in LocusId locusId, in IBinder appToken)806     void setActivityLocusContext(in ComponentName activity, in LocusId locusId,
807             in IBinder appToken);
808 
809     /**
810      * Set custom state data for this process. It will be included in the record of
811      * {@link ApplicationExitInfo} on the death of the current calling process; the new process
812      * of the app can retrieve this state data by calling
813      * {@link ApplicationExitInfo#getProcessStateSummary} on the record returned by
814      * {@link #getHistoricalProcessExitReasons}.
815      *
816      * <p> This would be useful for the calling app to save its stateful data: if it's
817      * killed later for any reason, the new process of the app can know what the
818      * previous process of the app was doing. For instance, you could use this to encode
819      * the current level in a game, or a set of features/experiments that were enabled. Later you
820      * could analyze under what circumstances the app tends to crash or use too much memory.
821      * However, it's not suggested to rely on this to restore the applications previous UI state
822      * or so, it's only meant for analyzing application healthy status.</p>
823      *
824      * <p> System might decide to throttle the calls to this API; so call this API in a reasonable
825      * manner, excessive calls to this API could result a {@link java.lang.RuntimeException}.
826      * </p>
827      *
828      * @param state The customized state data
829      */
setProcessStateSummary(in byte[] state)830     void setProcessStateSummary(in byte[] state);
831 
832     /**
833      * Return whether the app freezer is supported (true) or not (false) by this system.
834      */
isAppFreezerSupported()835     boolean isAppFreezerSupported();
836 
837     /**
838      * Return whether the app freezer is enabled (true) or not (false) by this system.
839      */
isAppFreezerEnabled()840     boolean isAppFreezerEnabled();
841 
842     /**
843      * Kills uid with the reason of permission change.
844      */
killUidForPermissionChange(int appId, int userId, String reason)845     void killUidForPermissionChange(int appId, int userId, String reason);
846 
847     /**
848      * Resets the state of the {@link com.android.server.am.AppErrors} instance.
849      * This is intended for testing within the CTS only and is protected by
850      * android.permission.RESET_APP_ERRORS.
851      */
resetAppErrors()852     void resetAppErrors();
853 
854     /**
855      * Control the app freezer state. Returns true in case of success, false if the operation
856      * didn't succeed (for example, when the app freezer isn't supported).
857      * Handling the freezer state via this method is reentrant, that is it can be
858      * disabled and re-enabled multiple times in parallel. As long as there's a 1:1 disable to
859      * enable match, the freezer is re-enabled at last enable only.
860      * @param enable set it to true to enable the app freezer, false to disable it.
861      */
enableAppFreezer(in boolean enable)862     boolean enableAppFreezer(in boolean enable);
863 
864     /**
865      * Suppress or reenable the rate limit on foreground service notification deferral.
866      * This is for use within CTS and is protected by android.permission.WRITE_DEVICE_CONFIG.
867      *
868      * @param enable false to suppress rate-limit policy; true to reenable it.
869      */
enableFgsNotificationRateLimit(in boolean enable)870     boolean enableFgsNotificationRateLimit(in boolean enable);
871 
872     /**
873      * Holds the AM lock for the specified amount of milliseconds.
874      * This is intended for use by the tests that need to imitate lock contention.
875      * The token should be obtained by
876      * {@link android.content.pm.PackageManager#getHoldLockToken()}.
877      */
holdLock(in IBinder token, in int durationMs)878     void holdLock(in IBinder token, in int durationMs);
879 
880     /**
881      * Starts a profile.
882      * @param userId the user id of the profile.
883      * @return true if the profile has been successfully started or if the profile is already
884      * running, false if profile failed to start.
885      * @throws IllegalArgumentException if the user is not a profile.
886      */
startProfile(int userId)887     boolean startProfile(int userId);
888 
889     /**
890      * Stops a profile.
891      * @param userId the user id of the profile.
892      * @return true if the profile has been successfully stopped or is already stopped. Otherwise
893      * the exceptions listed below are thrown.
894      * @throws IllegalArgumentException if the user is not a profile.
895      */
stopProfile(int userId)896     boolean stopProfile(int userId);
897 
898     /** Called by PendingIntent.queryIntentComponents() */
queryIntentComponentsForIntentSender(in IIntentSender sender, int matchFlags)899     ParceledListSlice queryIntentComponentsForIntentSender(in IIntentSender sender, int matchFlags);
900 
901     @JavaPassthrough(annotation=
902             "@android.annotation.RequiresPermission(allOf = {android.Manifest.permission.PACKAGE_USAGE_STATS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}, conditional = true)")
getUidProcessCapabilities(int uid, in String callingPackage)903     int getUidProcessCapabilities(int uid, in String callingPackage);
904 
905     /** Blocks until all broadcast queues become idle. */
waitForBroadcastIdle()906     void waitForBroadcastIdle();
waitForBroadcastBarrier()907     void waitForBroadcastBarrier();
908 
909     /** Delays delivering broadcasts to the specified package. */
910     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.DUMP)")
forceDelayBroadcastDelivery(in String targetPackage, long delayedDurationMs)911     void forceDelayBroadcastDelivery(in String targetPackage, long delayedDurationMs);
912 
913     /** Checks if the process represented by the given pid is frozen. */
914     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.DUMP)")
isProcessFrozen(int pid)915     boolean isProcessFrozen(int pid);
916 
917     /**
918      * @return The reason code of whether or not the given UID should be exempted from background
919      * restrictions here.
920      *
921      * <p>
922      * Note: Call it with caution as it'll try to acquire locks in other services.
923      * </p>
924      */
getBackgroundRestrictionExemptionReason(int uid)925     int getBackgroundRestrictionExemptionReason(int uid);
926 
927     // Start (?) of T transactions
928     /**
929      * Similar to {@link #startUserInBackgroundWithListener(int userId, IProgressListener unlockProgressListener)},
930      * but setting the user as the visible user of that display (i.e., allowing the user and its
931      * running profiles to launch activities on that display).
932      *
933      * <p>Typically used only by automotive builds when the vehicle has multiple displays.
934      */
935     @JavaPassthrough(annotation=
936             "@android.annotation.RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}, conditional = true)")
startUserInBackgroundVisibleOnDisplay(int userid, int displayId, IProgressListener unlockProgressListener)937     boolean startUserInBackgroundVisibleOnDisplay(int userid, int displayId, IProgressListener unlockProgressListener);
938 
939     /**
940      * Similar to {@link #startProfile(int userId)}, but with a listener to report user unlock
941      * progress.
942      */
startProfileWithListener(int userid, IProgressListener unlockProgressListener)943     boolean startProfileWithListener(int userid, IProgressListener unlockProgressListener);
944 
restartUserInBackground(int userId, int userStartMode)945     int restartUserInBackground(int userId, int userStartMode);
946 
947     /**
948      * Gets the ids of displays that can be used on {@link #startUserInBackgroundVisibleOnDisplay(int userId, int displayId)}.
949      *
950      * <p>Typically used only by automotive builds when the vehicle has multiple displays.
951      */
getDisplayIdsForStartingVisibleBackgroundUsers()952     @nullable int[] getDisplayIdsForStartingVisibleBackgroundUsers();
953 
954     /** Returns if the service is a short-service is still "alive" and past the timeout. */
shouldServiceTimeOut(in ComponentName className, in IBinder token)955     boolean shouldServiceTimeOut(in ComponentName className, in IBinder token);
956     /** Returns if the service has a time-limit restricted type and is past the time limit. */
hasServiceTimeLimitExceeded(in ComponentName className, in IBinder token)957     boolean hasServiceTimeLimitExceeded(in ComponentName className, in IBinder token);
958 
registerUidFrozenStateChangedCallback(in IUidFrozenStateChangedCallback callback)959     void registerUidFrozenStateChangedCallback(in IUidFrozenStateChangedCallback callback);
960     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS)")
unregisterUidFrozenStateChangedCallback(in IUidFrozenStateChangedCallback callback)961     void unregisterUidFrozenStateChangedCallback(in IUidFrozenStateChangedCallback callback);
962     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS)")
getUidFrozenState(in int[] uids)963     int[] getUidFrozenState(in int[] uids);
964 
checkPermissionForDevice(in String permission, int pid, int uid, int deviceId)965     int checkPermissionForDevice(in String permission, int pid, int uid, int deviceId);
966 
967     /**
968      * Notify AMS about binder transactions to frozen apps.
969      *
970      * @param debugPid The binder transaction sender
971      * @param code The binder transaction code
972      * @param flags The binder transaction flags
973      * @param err The binder transaction error
974      */
frozenBinderTransactionDetected(int debugPid, int code, int flags, int err)975     oneway void frozenBinderTransactionDetected(int debugPid, int code, int flags, int err);
getBindingUidProcessState(int uid, in String callingPackage)976     int getBindingUidProcessState(int uid, in String callingPackage);
977 
978     /**
979      * Return the timestampe (in the elapsed timebase) when the UID became idle from active
980      * last time (regardless of if the UID is still idle, or became active again).
981      * This is useful when trying to detect whether an UID has ever became idle since a certain
982      * time in the past.
983      */
getUidLastIdleElapsedTime(int uid, in String callingPackage)984     long getUidLastIdleElapsedTime(int uid, in String callingPackage);
985 
986     /**
987      * Adds permission to be overridden to the given state. Must be called from root user.
988      *
989      * @param originatingUid The UID of the instrumented app that initialized the override
990      * @param uid The UID of the app whose permission will be overridden
991      * @param permission The permission whose state will be overridden
992      * @param result The state to override the permission to
993      *
994      * @see PackageManager.PermissionResult
995      */
addOverridePermissionState(int originatingUid, int uid, String permission, int result)996     void addOverridePermissionState(int originatingUid, int uid, String permission, int result);
997 
998     /**
999      * Removes overridden permission. Must be called from root user.
1000      *
1001      * @param originatingUid The UID of the instrumented app that initialized the override
1002      * @param uid The UID of the app whose permission is overridden
1003      * @param permission The permission whose state will no longer be overridden
1004      */
removeOverridePermissionState(int originatingUid, int uid, String permission)1005     void removeOverridePermissionState(int originatingUid, int uid, String permission);
1006 
1007     /**
1008      * Clears all overridden permissions for the given UID. Must be called from root user.
1009      *
1010      * @param originatingUid The UID of the instrumented app that initialized the override
1011      * @param uid The UID of the app whose permissions will no longer be overridden
1012      */
clearOverridePermissionStates(int originatingUid, int uid)1013     void clearOverridePermissionStates(int originatingUid, int uid);
1014 
1015     /**
1016      * Clears all overridden permissions on the device. Must be called from root user.
1017      *
1018      * @param originatingUid The UID of the instrumented app that initialized the override
1019      */
clearAllOverridePermissionStates(int originatingUid)1020     void clearAllOverridePermissionStates(int originatingUid);
1021 
1022     /**
1023      * Request the system to log the reason for restricting / unrestricting an app.
1024      * @see ActivityManager#noteAppRestrictionEnabled
1025      */
1026     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.DEVICE_POWER)")
noteAppRestrictionEnabled(in String packageName, int uid, int restrictionType, boolean enabled, int reason, in String subReason, int source, long threshold)1027     void noteAppRestrictionEnabled(in String packageName, int uid, int restrictionType,
1028             boolean enabled, int reason, in String subReason, int source, long threshold);
1029 }
1030