• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.UserIdInt;
22 import android.app.ActivityManager.ProcessCapability;
23 import android.content.ComponentName;
24 import android.content.IIntentReceiver;
25 import android.content.IIntentSender;
26 import android.content.Intent;
27 import android.content.pm.ActivityInfo;
28 import android.content.pm.ActivityPresentationInfo;
29 import android.content.pm.ApplicationInfo;
30 import android.content.pm.UserInfo;
31 import android.net.Uri;
32 import android.os.Bundle;
33 import android.os.IBinder;
34 import android.os.PowerExemptionManager.ReasonCode;
35 import android.os.PowerExemptionManager.TempAllowListType;
36 import android.os.TransactionTooLargeException;
37 import android.os.WorkSource;
38 import android.util.ArraySet;
39 
40 import java.util.ArrayList;
41 import java.util.List;
42 import java.util.Map;
43 import java.util.Set;
44 
45 /**
46  * Activity manager local system service interface.
47  *
48  * @hide Only for use within the system server.
49  */
50 public abstract class ActivityManagerInternal {
51 
52     public enum ServiceNotificationPolicy {
53         /**
54          * The Notification is not associated with any foreground service.
55          */
56         NOT_FOREGROUND_SERVICE,
57         /**
58          * The Notification is associated with a foreground service, but the
59          * notification system should handle it just like non-FGS notifications.
60          */
61         SHOW_IMMEDIATELY,
62         /**
63          * The Notification is associated with a foreground service, and the
64          * notification system should ignore it unless it has already been shown (in
65          * which case it should be used to update the currently displayed UI).
66          */
67         UPDATE_ONLY
68     }
69 
70     // Access modes for handleIncomingUser.
71     public static final int ALLOW_NON_FULL = 0;
72     /**
73      * Allows access to a caller with {@link android.Manifest.permission#INTERACT_ACROSS_USERS}
74      * if in the same profile group.
75      * Otherwise, {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} is required.
76      */
77     public static final int ALLOW_NON_FULL_IN_PROFILE = 1;
78     public static final int ALLOW_FULL_ONLY = 2;
79     /**
80      * Allows access to a caller with {@link android.Manifest.permission#INTERACT_ACROSS_PROFILES}
81      * or {@link android.Manifest.permission#INTERACT_ACROSS_USERS} if in the same profile group.
82      * Otherwise, {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} is required.
83      */
84     public static final int ALLOW_ALL_PROFILE_PERMISSIONS_IN_PROFILE = 3;
85 
86     /**
87      * Verify that calling app has access to the given provider.
88      */
checkContentProviderAccess(String authority, @UserIdInt int userId)89     public abstract String checkContentProviderAccess(String authority, @UserIdInt int userId);
90 
91     /**
92      * Verify that calling UID has access to the given provider.
93      */
checkContentProviderUriPermission(Uri uri, @UserIdInt int userId, int callingUid, int modeFlags)94     public abstract int checkContentProviderUriPermission(Uri uri, @UserIdInt int userId,
95             int callingUid, int modeFlags);
96 
97     // Called by the power manager.
onWakefulnessChanged(int wakefulness)98     public abstract void onWakefulnessChanged(int wakefulness);
99 
100     /**
101      * @return {@code true} if process start is successful, {@code false} otherwise.
102      */
startIsolatedProcess(String entryPoint, String[] mainArgs, String processName, String abiOverride, int uid, Runnable crashHandler)103     public abstract boolean startIsolatedProcess(String entryPoint, String[] mainArgs,
104             String processName, String abiOverride, int uid, Runnable crashHandler);
105 
106     /**
107      * Called when a user has been deleted. This can happen during normal device usage
108      * or just at startup, when partially removed users are purged. Any state persisted by the
109      * ActivityManager should be purged now.
110      *
111      * @param userId The user being cleaned up.
112      */
onUserRemoved(@serIdInt int userId)113     public abstract void onUserRemoved(@UserIdInt int userId);
114 
115     /**
116      * Kill foreground apps from the specified user.
117      */
killForegroundAppsForUser(@serIdInt int userId)118     public abstract void killForegroundAppsForUser(@UserIdInt int userId);
119 
120     /**
121      * Sets how long a {@link PendingIntent} can be temporarily allowlisted to bypass restrictions
122      * such as Power Save mode.
123      * @param target
124      * @param allowlistToken
125      * @param duration temp allowlist duration in milliseconds.
126      * @param type temp allowlist type defined at {@link TempAllowListType}
127      * @param reasonCode one of {@link ReasonCode}
128      * @param reason A human-readable reason for logging purposes.
129      */
setPendingIntentAllowlistDuration(IIntentSender target, IBinder allowlistToken, long duration, @TempAllowListType int type, @ReasonCode int reasonCode, @Nullable String reason)130     public abstract void setPendingIntentAllowlistDuration(IIntentSender target,
131             IBinder allowlistToken, long duration, @TempAllowListType int type,
132             @ReasonCode int reasonCode, @Nullable String reason);
133 
134     /**
135      * Returns the flags set for a {@link PendingIntent}.
136      */
getPendingIntentFlags(IIntentSender target)137     public abstract int getPendingIntentFlags(IIntentSender target);
138 
139     /**
140      * Allows a {@link PendingIntent} to start activities from background.
141      */
setPendingIntentAllowBgActivityStarts( IIntentSender target, IBinder allowlistToken, int flags)142     public abstract void setPendingIntentAllowBgActivityStarts(
143             IIntentSender target, IBinder allowlistToken, int flags);
144 
145     /**
146      * Voids {@link PendingIntent}'s privilege to start activities from background.
147      */
clearPendingIntentAllowBgActivityStarts(IIntentSender target, IBinder allowlistToken)148     public abstract void clearPendingIntentAllowBgActivityStarts(IIntentSender target,
149             IBinder allowlistToken);
150 
151     /**
152      * Allow DeviceIdleController to tell us about what apps are allowlisted.
153      */
setDeviceIdleAllowlist(int[] allAppids, int[] exceptIdleAppids)154     public abstract void setDeviceIdleAllowlist(int[] allAppids, int[] exceptIdleAppids);
155 
156     /**
157      * Update information about which app IDs are on the temp allowlist.
158      * @param appids the updated list of appIds in temp allowlist.
159      * @param changingUid uid to add or remove to temp allowlist.
160      * @param adding true to add to temp allowlist, false to remove from temp allowlist.
161      * @param durationMs when adding is true, the duration to be in temp allowlist.
162      * @param type temp allowlist type defined at {@link TempAllowListType}.
163      * @param reasonCode one of {@link ReasonCode}
164      * @param reason A human-readable reason for logging purposes.
165      * @param callingUid the callingUid that setup this temp allowlist, only valid when param adding
166      *                   is true.
167      */
updateDeviceIdleTempAllowlist(int[] appids, int changingUid, boolean adding, long durationMs, @TempAllowListType int type, @ReasonCode int reasonCode, @Nullable String reason, int callingUid)168     public abstract void updateDeviceIdleTempAllowlist(int[] appids, int changingUid,
169             boolean adding, long durationMs, @TempAllowListType int type,
170             @ReasonCode int reasonCode,
171             @Nullable String reason, int callingUid);
172 
173     /**
174      * Get the procstate for the UID.  The return value will be between
175      * {@link ActivityManager#MIN_PROCESS_STATE} and {@link ActivityManager#MAX_PROCESS_STATE}.
176      * Note if the UID doesn't exist, it'll return {@link ActivityManager#PROCESS_STATE_NONEXISTENT}
177      * (-1).
178      */
getUidProcessState(int uid)179     public abstract int getUidProcessState(int uid);
180 
181     /**
182      * Get a map of pid and package name that process of that pid Android/data and Android/obb
183      * directory is not mounted to lowerfs.
184      */
getProcessesWithPendingBindMounts(int userId)185     public abstract Map<Integer, String> getProcessesWithPendingBindMounts(int userId);
186 
187     /**
188      * @return {@code true} if system is ready, {@code false} otherwise.
189      */
isSystemReady()190     public abstract boolean isSystemReady();
191 
192     /**
193      * Sets if the given pid has an overlay UI or not.
194      *
195      * @param pid The pid we are setting overlay UI for.
196      * @param hasOverlayUi True if the process has overlay UI.
197      * @see android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
198      */
setHasOverlayUi(int pid, boolean hasOverlayUi)199     public abstract void setHasOverlayUi(int pid, boolean hasOverlayUi);
200 
201     /**
202      * Called after the network policy rules are updated by
203      * {@link com.android.server.net.NetworkPolicyManagerService} for a specific {@param uid} and
204      * {@param procStateSeq}.
205      */
notifyNetworkPolicyRulesUpdated(int uid, long procStateSeq)206     public abstract void notifyNetworkPolicyRulesUpdated(int uid, long procStateSeq);
207 
208     /**
209      * @return true if runtime was restarted, false if it's normal boot
210      */
isRuntimeRestarted()211     public abstract boolean isRuntimeRestarted();
212 
213     /**
214      * Returns if more users can be started without stopping currently running users.
215      */
canStartMoreUsers()216     public abstract boolean canStartMoreUsers();
217 
218     /**
219      * Sets the user switcher message for switching from {@link android.os.UserHandle#SYSTEM}.
220      */
setSwitchingFromSystemUserMessage(String switchingFromSystemUserMessage)221     public abstract void setSwitchingFromSystemUserMessage(String switchingFromSystemUserMessage);
222 
223     /**
224      * Sets the user switcher message for switching to {@link android.os.UserHandle#SYSTEM}.
225      */
setSwitchingToSystemUserMessage(String switchingToSystemUserMessage)226     public abstract void setSwitchingToSystemUserMessage(String switchingToSystemUserMessage);
227 
228     /**
229      * Returns maximum number of users that can run simultaneously.
230      */
getMaxRunningUsers()231     public abstract int getMaxRunningUsers();
232 
233     /**
234      * Whether an UID is active or idle.
235      */
isUidActive(int uid)236     public abstract boolean isUidActive(int uid);
237 
238     /**
239      * Returns a list of running processes along with corresponding uids, pids and their oom score.
240      *
241      * Only processes managed by ActivityManagerService are included.
242      */
getMemoryStateForProcesses()243     public abstract List<ProcessMemoryState> getMemoryStateForProcesses();
244 
245     /**
246      * Checks to see if the calling pid is allowed to handle the user. Returns adjusted user id as
247      * needed.
248      */
handleIncomingUser(int callingPid, int callingUid, @UserIdInt int userId, boolean allowAll, int allowMode, String name, String callerPackage)249     public abstract int handleIncomingUser(int callingPid, int callingUid, @UserIdInt int userId,
250             boolean allowAll, int allowMode, String name, String callerPackage);
251 
252     /** Checks if the calling binder pid as the permission. */
enforceCallingPermission(String permission, String func)253     public abstract void enforceCallingPermission(String permission, String func);
254 
255     /** Returns the current user id. */
getCurrentUserId()256     public abstract int getCurrentUserId();
257 
258     /** Returns the currently started user ids. */
getStartedUserIds()259     public abstract int[] getStartedUserIds();
260 
261     /** Returns true if the user is running. */
isUserRunning(@serIdInt int userId, int flags)262     public abstract boolean isUserRunning(@UserIdInt int userId, int flags);
263 
264     /** Trims memory usage in the system by removing/stopping unused application processes. */
trimApplications()265     public abstract void trimApplications();
266 
267     /** Kill the processes in the list due to their tasks been removed. */
killProcessesForRemovedTask(ArrayList<Object> procsToKill)268     public abstract void killProcessesForRemovedTask(ArrayList<Object> procsToKill);
269 
270     /** Kill the process immediately. */
killProcess(String processName, int uid, String reason)271     public abstract void killProcess(String processName, int uid, String reason);
272 
273     /**
274      * Returns {@code true} if {@code uid} is running an activity from {@code packageName}.
275      */
hasRunningActivity(int uid, @Nullable String packageName)276     public abstract boolean hasRunningActivity(int uid, @Nullable String packageName);
277 
updateOomAdj()278     public abstract void updateOomAdj();
updateCpuStats()279     public abstract void updateCpuStats();
280 
281     /**
282      * Update battery stats on activity usage.
283      * @param activity
284      * @param uid
285      * @param userId
286      * @param started
287      */
updateBatteryStats( ComponentName activity, int uid, @UserIdInt int userId, boolean resumed)288     public abstract void updateBatteryStats(
289             ComponentName activity, int uid, @UserIdInt int userId, boolean resumed);
290 
291     /**
292      * Update UsageStats of the activity.
293      * @param activity
294      * @param userId
295      * @param event
296      * @param appToken ActivityRecord's appToken.
297      * @param taskRoot Task's root
298      */
updateActivityUsageStats( ComponentName activity, @UserIdInt int userId, int event, IBinder appToken, ComponentName taskRoot)299     public abstract void updateActivityUsageStats(
300             ComponentName activity, @UserIdInt int userId, int event, IBinder appToken,
301             ComponentName taskRoot);
updateForegroundTimeIfOnBattery( String packageName, int uid, long cpuTimeDiff)302     public abstract void updateForegroundTimeIfOnBattery(
303             String packageName, int uid, long cpuTimeDiff);
sendForegroundProfileChanged(@serIdInt int userId)304     public abstract void sendForegroundProfileChanged(@UserIdInt int userId);
305 
306     /**
307      * Returns whether the given user requires credential entry at this time. This is used to
308      * intercept activity launches for locked work apps due to work challenge being triggered or
309      * when the profile user is yet to be unlocked.
310      */
shouldConfirmCredentials(@serIdInt int userId)311     public abstract boolean shouldConfirmCredentials(@UserIdInt int userId);
312 
313     /**
314      * Used in conjunction with {@link #noteAlarmStart(PendingIntent, WorkSource, int, String)} to
315      * note an alarm duration for battery attribution
316      */
noteAlarmFinish(PendingIntent ps, WorkSource workSource, int sourceUid, String tag)317     public abstract void noteAlarmFinish(PendingIntent ps, WorkSource workSource, int sourceUid,
318             String tag);
319 
320     /**
321      * Used in conjunction with {@link #noteAlarmFinish(PendingIntent, WorkSource, int, String)} to
322      * note an alarm duration for battery attribution
323      */
noteAlarmStart(PendingIntent ps, WorkSource workSource, int sourceUid, String tag)324     public abstract void noteAlarmStart(PendingIntent ps, WorkSource workSource, int sourceUid,
325             String tag);
326 
327     /**
328      * Used to note a wakeup alarm for battery attribution.
329      */
noteWakeupAlarm(PendingIntent ps, WorkSource workSource, int sourceUid, String sourcePkg, String tag)330     public abstract void noteWakeupAlarm(PendingIntent ps, WorkSource workSource, int sourceUid,
331             String sourcePkg, String tag);
332 
333     /**
334      * Returns whether this app is disallowed to run in the background.
335      *
336      * @see ActivityManager#APP_START_MODE_DISABLED
337      */
isAppStartModeDisabled(int uid, String packageName)338     public abstract boolean isAppStartModeDisabled(int uid, String packageName);
339 
getCurrentProfileIds()340     public abstract int[] getCurrentProfileIds();
getCurrentUser()341     public abstract UserInfo getCurrentUser();
ensureNotSpecialUser(@serIdInt int userId)342     public abstract void ensureNotSpecialUser(@UserIdInt int userId);
isCurrentProfile(@serIdInt int userId)343     public abstract boolean isCurrentProfile(@UserIdInt int userId);
hasStartedUserState(@serIdInt int userId)344     public abstract boolean hasStartedUserState(@UserIdInt int userId);
finishUserSwitch(Object uss)345     public abstract void finishUserSwitch(Object uss);
346 
347     /** Schedule the execution of all pending app GCs. */
scheduleAppGcs()348     public abstract void scheduleAppGcs();
349 
350     /** Gets the task id for a given activity. */
getTaskIdForActivity(@onNull IBinder token, boolean onlyRoot)351     public abstract int getTaskIdForActivity(@NonNull IBinder token, boolean onlyRoot);
352 
353     /** Gets the basic info for a given activity. */
getActivityPresentationInfo(@onNull IBinder token)354     public abstract ActivityPresentationInfo getActivityPresentationInfo(@NonNull IBinder token);
355 
setBooting(boolean booting)356     public abstract void setBooting(boolean booting);
isBooting()357     public abstract boolean isBooting();
setBooted(boolean booted)358     public abstract void setBooted(boolean booted);
isBooted()359     public abstract boolean isBooted();
finishBooting()360     public abstract void finishBooting();
361 
362     /**
363      * Temp allowlist a UID for PendingIntent.
364      * @param callerPid the PID that sent the PendingIntent.
365      * @param callerUid the UID that sent the PendingIntent.
366      * @param targetUid the UID that is been temp allowlisted.
367      * @param duration temp allowlist duration in milliseconds.
368      * @param type temp allowlist type defined at {@link TempAllowListType}
369      * @param reasonCode one of {@link ReasonCode}
370      * @param reason
371      */
tempAllowlistForPendingIntent(int callerPid, int callerUid, int targetUid, long duration, int type, @ReasonCode int reasonCode, String reason)372     public abstract void tempAllowlistForPendingIntent(int callerPid, int callerUid, int targetUid,
373             long duration, int type, @ReasonCode int reasonCode, String reason);
374 
broadcastIntentInPackage(String packageName, @Nullable String featureId, int uid, int realCallingUid, int realCallingPid, Intent intent, String resolvedType, IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras, String requiredPermission, Bundle bOptions, boolean serialized, boolean sticky, @UserIdInt int userId, boolean allowBackgroundActivityStarts, @Nullable IBinder backgroundActivityStartsToken)375     public abstract int broadcastIntentInPackage(String packageName, @Nullable String featureId,
376             int uid, int realCallingUid, int realCallingPid, Intent intent, String resolvedType,
377             IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras,
378             String requiredPermission, Bundle bOptions, boolean serialized, boolean sticky,
379             @UserIdInt int userId, boolean allowBackgroundActivityStarts,
380             @Nullable IBinder backgroundActivityStartsToken);
381 
startServiceInPackage(int uid, Intent service, String resolvedType, boolean fgRequired, String callingPackage, @Nullable String callingFeatureId, @UserIdInt int userId, boolean allowBackgroundActivityStarts, @Nullable IBinder backgroundActivityStartsToken)382     public abstract ComponentName startServiceInPackage(int uid, Intent service,
383             String resolvedType, boolean fgRequired, String callingPackage,
384             @Nullable String callingFeatureId, @UserIdInt int userId,
385             boolean allowBackgroundActivityStarts,
386             @Nullable IBinder backgroundActivityStartsToken) throws TransactionTooLargeException;
387 
disconnectActivityFromServices(Object connectionHolder)388     public abstract void disconnectActivityFromServices(Object connectionHolder);
cleanUpServices(@serIdInt int userId, ComponentName component, Intent baseIntent)389     public abstract void cleanUpServices(@UserIdInt int userId, ComponentName component,
390             Intent baseIntent);
getActivityInfoForUser(ActivityInfo aInfo, @UserIdInt int userId)391     public abstract ActivityInfo getActivityInfoForUser(ActivityInfo aInfo, @UserIdInt int userId);
ensureBootCompleted()392     public abstract void ensureBootCompleted();
updateOomLevelsForDisplay(int displayId)393     public abstract void updateOomLevelsForDisplay(int displayId);
isActivityStartsLoggingEnabled()394     public abstract boolean isActivityStartsLoggingEnabled();
395     /** Returns true if the background activity starts is enabled. */
isBackgroundActivityStartsEnabled()396     public abstract boolean isBackgroundActivityStartsEnabled();
reportCurKeyguardUsageEvent(boolean keyguardShowing)397     public abstract void reportCurKeyguardUsageEvent(boolean keyguardShowing);
398 
399     /** @see com.android.server.am.ActivityManagerService#monitor */
monitor()400     public abstract void monitor();
401 
402     /** Input dispatch timeout to a window, start the ANR process. Return the timeout extension,
403      * in milliseconds, or 0 to abort dispatch. */
inputDispatchingTimedOut(int pid, boolean aboveSystem, String reason)404     public abstract long inputDispatchingTimedOut(int pid, boolean aboveSystem, String reason);
inputDispatchingTimedOut(Object proc, String activityShortComponentName, ApplicationInfo aInfo, String parentShortComponentName, Object parentProc, boolean aboveSystem, String reason)405     public abstract boolean inputDispatchingTimedOut(Object proc, String activityShortComponentName,
406             ApplicationInfo aInfo, String parentShortComponentName, Object parentProc,
407             boolean aboveSystem, String reason);
408     /**
409      * App started responding to input events. This signal can be used to abort the ANR process and
410      * hide the ANR dialog.
411      */
inputDispatchingResumed(int pid)412     public abstract void inputDispatchingResumed(int pid);
413 
414     /**
415      * Sends {@link android.content.Intent#ACTION_CONFIGURATION_CHANGED} with all the appropriate
416      * flags.
417      */
broadcastGlobalConfigurationChanged(int changes, boolean initLocale)418     public abstract void broadcastGlobalConfigurationChanged(int changes, boolean initLocale);
419 
420     /**
421      * Sends {@link android.content.Intent#ACTION_CLOSE_SYSTEM_DIALOGS} with all the appropriate
422      * flags.
423      */
broadcastCloseSystemDialogs(String reason)424     public abstract void broadcastCloseSystemDialogs(String reason);
425 
426     /**
427      * Kills all background processes, except those matching any of the specified properties.
428      *
429      * @param minTargetSdk the target SDK version at or above which to preserve processes,
430      *                     or {@code -1} to ignore the target SDK
431      * @param maxProcState the process state at or below which to preserve processes,
432      *                     or {@code -1} to ignore the process state
433      */
killAllBackgroundProcessesExcept(int minTargetSdk, int maxProcState)434     public abstract void killAllBackgroundProcessesExcept(int minTargetSdk, int maxProcState);
435 
436     /** Starts a given process. */
startProcess(String processName, ApplicationInfo info, boolean knownToBeDead, boolean isTop, String hostingType, ComponentName hostingName)437     public abstract void startProcess(String processName, ApplicationInfo info,
438             boolean knownToBeDead, boolean isTop, String hostingType, ComponentName hostingName);
439 
440     /** Starts up the starting activity process for debugging if needed.
441      * This function needs to be called synchronously from WindowManager context so the caller
442      * passes a lock {@code wmLock} and waits to be notified.
443      *
444      * @param wmLock calls {@code notify} on the object to wake up the caller.
445     */
setDebugFlagsForStartingActivity(ActivityInfo aInfo, int startFlags, ProfilerInfo profilerInfo, Object wmLock)446     public abstract void setDebugFlagsForStartingActivity(ActivityInfo aInfo, int startFlags,
447             ProfilerInfo profilerInfo, Object wmLock);
448 
449     /** Returns mount mode for process running with given pid */
getStorageMountMode(int pid, int uid)450     public abstract int getStorageMountMode(int pid, int uid);
451 
452     /** Returns true if the given uid is the app in the foreground. */
isAppForeground(int uid)453     public abstract boolean isAppForeground(int uid);
454 
455     /** Returns true if the given process name and uid is currently marked 'bad' */
isAppBad(String processName, int uid)456     public abstract boolean isAppBad(String processName, int uid);
457 
458     /** Remove pending backup for the given userId. */
clearPendingBackup(@serIdInt int userId)459     public abstract void clearPendingBackup(@UserIdInt int userId);
460 
461     /**
462      * When power button is very long pressed, call this interface to do some pre-shutdown work
463      * like persisting database etc.
464      */
prepareForPossibleShutdown()465     public abstract void prepareForPossibleShutdown();
466 
467     /**
468      * Returns {@code true} if {@code uid} is running a foreground service of a specific
469      * {@code foregroundServiceType}.
470      */
hasRunningForegroundService(int uid, int foregroundServiceType)471     public abstract boolean hasRunningForegroundService(int uid, int foregroundServiceType);
472 
473     /**
474      * Returns {@code true} if the given notification channel currently has a
475      * notification associated with a foreground service.  This is an AMS check
476      * because that is the source of truth for the FGS state.
477      */
hasForegroundServiceNotification(String pkg, @UserIdInt int userId, String channelId)478     public abstract boolean hasForegroundServiceNotification(String pkg, @UserIdInt int userId,
479             String channelId);
480 
481     /**
482      * Tell the service lifecycle logic that the given Notification content is now
483      * canonical for any foreground-service visibility policy purposes.
484      *
485      * Returns a description of any FGs-related policy around the given Notification:
486      * not associated with an FGS; ensure display; or only update if already displayed.
487      */
applyForegroundServiceNotification( Notification notification, String tag, int id, String pkg, @UserIdInt int userId)488     public abstract ServiceNotificationPolicy applyForegroundServiceNotification(
489             Notification notification, String tag, int id, String pkg, @UserIdInt int userId);
490 
491     /**
492      * Callback from the notification subsystem that the given FGS notification has
493      * been evaluated, and either shown or explicitly overlooked.  This can happen
494      * after either Service.startForeground() or NotificationManager.notify().
495      */
onForegroundServiceNotificationUpdate(boolean shown, Notification notification, int id, String pkg, @UserIdInt int userId)496     public abstract void onForegroundServiceNotificationUpdate(boolean shown,
497             Notification notification, int id, String pkg, @UserIdInt int userId);
498 
499     /**
500      * If the given app has any FGSs whose notifications are in the given channel,
501      * stop them.
502      */
stopForegroundServicesForChannel(String pkg, @UserIdInt int userId, String channelId)503     public abstract void stopForegroundServicesForChannel(String pkg, @UserIdInt int userId,
504             String channelId);
505 
506     /**
507      * Registers the specified {@code processObserver} to be notified of future changes to
508      * process state.
509      */
registerProcessObserver(IProcessObserver processObserver)510     public abstract void registerProcessObserver(IProcessObserver processObserver);
511 
512     /**
513      * Unregisters the specified {@code processObserver}.
514      */
unregisterProcessObserver(IProcessObserver processObserver)515     public abstract void unregisterProcessObserver(IProcessObserver processObserver);
516 
517     /**
518      * Checks if there is an unfinished instrumentation that targets the given uid.
519      *
520      * @param uid The uid to be checked for
521      *
522      * @return True, if there is an instrumentation whose target application uid matches the given
523      * uid, false otherwise
524      */
isUidCurrentlyInstrumented(int uid)525     public abstract boolean isUidCurrentlyInstrumented(int uid);
526 
527     /** Is this a device owner app? */
isDeviceOwner(int uid)528     public abstract boolean isDeviceOwner(int uid);
529 
530     /**
531      * Called by DevicePolicyManagerService to set the uid of the device owner.
532      */
setDeviceOwnerUid(int uid)533     public abstract void setDeviceOwnerUid(int uid);
534 
535     /** Is this a profile owner app? */
isProfileOwner(int uid)536     public abstract boolean isProfileOwner(int uid);
537 
538     /**
539      * Called by DevicePolicyManagerService to set the uid of the profile owner.
540      * @param profileOwnerUids The profile owner UIDs. The ownership of the array is
541      *                         passed to callee.
542      */
setProfileOwnerUid(ArraySet<Integer> profileOwnerUids)543     public abstract void setProfileOwnerUid(ArraySet<Integer> profileOwnerUids);
544 
545     /**
546      * Set all associated companion app that belongs to a userId.
547      * @param userId
548      * @param companionAppUids  ActivityManager will take ownership of this Set, the caller
549      *                          shouldn't touch this Set after calling this interface.
550      */
setCompanionAppUids(int userId, Set<Integer> companionAppUids)551     public abstract void setCompanionAppUids(int userId, Set<Integer> companionAppUids);
552 
553     /**
554      * is the uid an associated companion app of a userId?
555      * @param userId
556      * @param uid
557      * @return
558      */
isAssociatedCompanionApp(int userId, int uid)559     public abstract boolean isAssociatedCompanionApp(int userId, int uid);
560 
561     /**
562      * Sends a broadcast, assuming the caller to be the system and allowing the inclusion of an
563      * approved allowlist of app Ids >= {@link android.os.Process#FIRST_APPLICATION_UID} that the
564      * broadcast my be sent to; any app Ids < {@link android.os.Process#FIRST_APPLICATION_UID} are
565      * automatically allowlisted.
566      *
567      * @see com.android.server.am.ActivityManagerService#broadcastIntentWithFeature(
568      *      IApplicationThread, String, Intent, String, IIntentReceiver, int, String, Bundle,
569      *      String[], int, Bundle, boolean, boolean, int)
570      */
broadcastIntent(Intent intent, IIntentReceiver resultTo, String[] requiredPermissions, boolean serialized, int userId, int[] appIdAllowList, @Nullable Bundle bOptions)571     public abstract int broadcastIntent(Intent intent,
572             IIntentReceiver resultTo,
573             String[] requiredPermissions, boolean serialized,
574             int userId, int[] appIdAllowList, @Nullable Bundle bOptions);
575 
576     /**
577      * Add uid to the ActivityManagerService PendingStartActivityUids list.
578      * @param uid uid
579      * @param pid pid of the ProcessRecord that is pending top.
580      */
addPendingTopUid(int uid, int pid)581     public abstract void addPendingTopUid(int uid, int pid);
582 
583     /**
584      * Delete uid from the ActivityManagerService PendingStartActivityUids list.
585      * @param uid uid
586      */
deletePendingTopUid(int uid)587     public abstract void deletePendingTopUid(int uid);
588 
589     /**
590      * Is the uid in ActivityManagerService PendingStartActivityUids list?
591      * @param uid
592      * @return true if exists, false otherwise.
593      */
isPendingTopUid(int uid)594     public abstract boolean isPendingTopUid(int uid);
595 
596     /**
597      * @return the intent for the given intent sender.
598      */
599     @Nullable
getIntentForIntentSender(IIntentSender sender)600     public abstract Intent getIntentForIntentSender(IIntentSender sender);
601 
602     /**
603      * Effectively PendingIntent.getActivityForUser(), but the PendingIntent is
604      * owned by the given uid rather than by the caller (i.e. the system).
605      */
getPendingIntentActivityAsApp( int requestCode, @NonNull Intent intent, int flags, Bundle options, String ownerPkgName, int ownerUid)606     public abstract PendingIntent getPendingIntentActivityAsApp(
607             int requestCode, @NonNull Intent intent, int flags, Bundle options,
608             String ownerPkgName, int ownerUid);
609 
610     /**
611      * Effectively PendingIntent.getActivityForUser(), but the PendingIntent is
612      * owned by the given uid rather than by the caller (i.e. the system).
613      */
getPendingIntentActivityAsApp( int requestCode, @NonNull Intent[] intents, int flags, Bundle options, String ownerPkgName, int ownerUid)614     public abstract PendingIntent getPendingIntentActivityAsApp(
615             int requestCode, @NonNull Intent[] intents, int flags, Bundle options,
616             String ownerPkgName, int ownerUid);
617 
618     /**
619      * @return mBootTimeTempAllowlistDuration of ActivityManagerConstants.
620      */
getBootTimeTempAllowListDuration()621     public abstract long getBootTimeTempAllowListDuration();
622 
623     /** Register an {@link AnrController} to control the ANR dialog behavior */
registerAnrController(AnrController controller)624     public abstract void registerAnrController(AnrController controller);
625 
626     /** Unregister an {@link AnrController} */
unregisterAnrController(AnrController controller)627     public abstract void unregisterAnrController(AnrController controller);
628 
629     /**
630      * Is the FGS started from an uid temporarily allowed to have while-in-use permission?
631      */
isTempAllowlistedForFgsWhileInUse(int uid)632     public abstract boolean isTempAllowlistedForFgsWhileInUse(int uid);
633 
634     /**
635      * Return the temp allowlist type when server push messaging is over the quota.
636      */
getPushMessagingOverQuotaBehavior()637     public abstract @TempAllowListType int getPushMessagingOverQuotaBehavior();
638 
639     /**
640      * Returns the capability of the given uid
641      */
getUidCapability(int uid)642     public abstract @ProcessCapability int getUidCapability(int uid);
643 
644     /**
645      * @return The PID list of the isolated process with packages matching the given uid.
646      */
647     @Nullable
getIsolatedProcesses(int uid)648     public abstract List<Integer> getIsolatedProcesses(int uid);
649 }
650