• 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.content.ComponentName;
22 import android.content.IIntentReceiver;
23 import android.content.IIntentSender;
24 import android.content.Intent;
25 import android.content.pm.ActivityInfo;
26 import android.content.pm.ActivityPresentationInfo;
27 import android.content.pm.ApplicationInfo;
28 import android.content.pm.UserInfo;
29 import android.os.Bundle;
30 import android.os.IBinder;
31 import android.os.TransactionTooLargeException;
32 import android.view.RemoteAnimationAdapter;
33 
34 import java.util.ArrayList;
35 import java.util.List;
36 
37 /**
38  * Activity manager local system service interface.
39  *
40  * @hide Only for use within the system server.
41  */
42 public abstract class ActivityManagerInternal {
43 
44 
45     // Access modes for handleIncomingUser.
46     public static final int ALLOW_NON_FULL = 0;
47     public static final int ALLOW_NON_FULL_IN_PROFILE = 1;
48     public static final int ALLOW_FULL_ONLY = 2;
49 
50     /**
51      * Verify that calling app has access to the given provider.
52      */
checkContentProviderAccess(String authority, int userId)53     public abstract String checkContentProviderAccess(String authority, int userId);
54 
55     // Called by the power manager.
onWakefulnessChanged(int wakefulness)56     public abstract void onWakefulnessChanged(int wakefulness);
57 
58     /**
59      * @return {@code true} if process start is successful, {@code false} otherwise.
60      */
startIsolatedProcess(String entryPoint, String[] mainArgs, String processName, String abiOverride, int uid, Runnable crashHandler)61     public abstract boolean startIsolatedProcess(String entryPoint, String[] mainArgs,
62             String processName, String abiOverride, int uid, Runnable crashHandler);
63 
64     /**
65      * Kill foreground apps from the specified user.
66      */
killForegroundAppsForUser(int userHandle)67     public abstract void killForegroundAppsForUser(int userHandle);
68 
69     /**
70      *  Sets how long a {@link PendingIntent} can be temporarily whitelist to by bypass restrictions
71      *  such as Power Save mode.
72      */
setPendingIntentWhitelistDuration(IIntentSender target, IBinder whitelistToken, long duration)73     public abstract void setPendingIntentWhitelistDuration(IIntentSender target,
74             IBinder whitelistToken, long duration);
75 
76     /**
77      * Allows for a {@link PendingIntent} to be whitelisted to start activities from background.
78      */
setPendingIntentAllowBgActivityStarts( IIntentSender target, IBinder whitelistToken, int flags)79     public abstract void setPendingIntentAllowBgActivityStarts(
80             IIntentSender target, IBinder whitelistToken, int flags);
81 
82     /**
83      * Voids {@link PendingIntent}'s privilege to be whitelisted to start activities from
84      * background.
85      */
clearPendingIntentAllowBgActivityStarts(IIntentSender target, IBinder whitelistToken)86     public abstract void clearPendingIntentAllowBgActivityStarts(IIntentSender target,
87             IBinder whitelistToken);
88 
89     /**
90      * Allow DeviceIdleController to tell us about what apps are whitelisted.
91      */
setDeviceIdleWhitelist(int[] allAppids, int[] exceptIdleAppids)92     public abstract void setDeviceIdleWhitelist(int[] allAppids, int[] exceptIdleAppids);
93 
94     /**
95      * Update information about which app IDs are on the temp whitelist.
96      */
updateDeviceIdleTempWhitelist(int[] appids, int changingAppId, boolean adding)97     public abstract void updateDeviceIdleTempWhitelist(int[] appids, int changingAppId,
98             boolean adding);
99 
100     /**
101      * Get the procstate for the UID.  The return value will be between
102      * {@link ActivityManager#MIN_PROCESS_STATE} and {@link ActivityManager#MAX_PROCESS_STATE}.
103      * Note if the UID doesn't exist, it'll return {@link ActivityManager#PROCESS_STATE_NONEXISTENT}
104      * (-1).
105      */
getUidProcessState(int uid)106     public abstract int getUidProcessState(int uid);
107 
108     /**
109      * @return {@code true} if system is ready, {@code false} otherwise.
110      */
isSystemReady()111     public abstract boolean isSystemReady();
112 
113     /**
114      * Sets if the given pid has an overlay UI or not.
115      *
116      * @param pid The pid we are setting overlay UI for.
117      * @param hasOverlayUi True if the process has overlay UI.
118      * @see android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
119      */
setHasOverlayUi(int pid, boolean hasOverlayUi)120     public abstract void setHasOverlayUi(int pid, boolean hasOverlayUi);
121 
122     /**
123      * Sets if the given pid is currently running a remote animation, which is taken a signal for
124      * determining oom adjustment and scheduling behavior.
125      *
126      * @param pid The pid we are setting overlay UI for.
127      * @param runningRemoteAnimation True if the process is running a remote animation, false
128      *                               otherwise.
129      * @see RemoteAnimationAdapter
130      */
setRunningRemoteAnimation(int pid, boolean runningRemoteAnimation)131     public abstract void setRunningRemoteAnimation(int pid, boolean runningRemoteAnimation);
132 
133     /**
134      * Called after the network policy rules are updated by
135      * {@link com.android.server.net.NetworkPolicyManagerService} for a specific {@param uid} and
136      * {@param procStateSeq}.
137      */
notifyNetworkPolicyRulesUpdated(int uid, long procStateSeq)138     public abstract void notifyNetworkPolicyRulesUpdated(int uid, long procStateSeq);
139 
140     /**
141      * @return true if runtime was restarted, false if it's normal boot
142      */
isRuntimeRestarted()143     public abstract boolean isRuntimeRestarted();
144 
145     /**
146      * Returns if more users can be started without stopping currently running users.
147      */
canStartMoreUsers()148     public abstract boolean canStartMoreUsers();
149 
150     /**
151      * Sets the user switcher message for switching from {@link android.os.UserHandle#SYSTEM}.
152      */
setSwitchingFromSystemUserMessage(String switchingFromSystemUserMessage)153     public abstract void setSwitchingFromSystemUserMessage(String switchingFromSystemUserMessage);
154 
155     /**
156      * Sets the user switcher message for switching to {@link android.os.UserHandle#SYSTEM}.
157      */
setSwitchingToSystemUserMessage(String switchingToSystemUserMessage)158     public abstract void setSwitchingToSystemUserMessage(String switchingToSystemUserMessage);
159 
160     /**
161      * Returns maximum number of users that can run simultaneously.
162      */
getMaxRunningUsers()163     public abstract int getMaxRunningUsers();
164 
165     /**
166      * Whether an UID is active or idle.
167      */
isUidActive(int uid)168     public abstract boolean isUidActive(int uid);
169 
170     /**
171      * Returns a list of running processes along with corresponding uids, pids and their oom score.
172      *
173      * Only processes managed by ActivityManagerService are included.
174      */
getMemoryStateForProcesses()175     public abstract List<ProcessMemoryState> getMemoryStateForProcesses();
176 
177     /**
178      * Checks to see if the calling pid is allowed to handle the user. Returns adjusted user id as
179      * needed.
180      */
handleIncomingUser(int callingPid, int callingUid, int userId, boolean allowAll, int allowMode, String name, String callerPackage)181     public abstract int handleIncomingUser(int callingPid, int callingUid, int userId,
182             boolean allowAll, int allowMode, String name, String callerPackage);
183 
184     /** Checks if the calling binder pid as the permission. */
enforceCallingPermission(String permission, String func)185     public abstract void enforceCallingPermission(String permission, String func);
186 
187     /** Returns the current user id. */
getCurrentUserId()188     public abstract int getCurrentUserId();
189 
190     /** Returns true if the user is running. */
isUserRunning(int userId, int flags)191     public abstract boolean isUserRunning(int userId, int flags);
192 
193     /** Trims memory usage in the system by removing/stopping unused application processes. */
trimApplications()194     public abstract void trimApplications();
195 
196     /** Kill the processes in the list due to their tasks been removed. */
killProcessesForRemovedTask(ArrayList<Object> procsToKill)197     public abstract void killProcessesForRemovedTask(ArrayList<Object> procsToKill);
198 
199     /** Kill the process immediately. */
killProcess(String processName, int uid, String reason)200     public abstract void killProcess(String processName, int uid, String reason);
201 
202     /**
203      * Returns {@code true} if {@code uid} is running an activity from {@code packageName}.
204      */
hasRunningActivity(int uid, @Nullable String packageName)205     public abstract boolean hasRunningActivity(int uid, @Nullable String packageName);
206 
updateOomAdj()207     public abstract void updateOomAdj();
updateCpuStats()208     public abstract void updateCpuStats();
209 
210     /**
211      * Update battery stats on activity usage.
212      * @param activity
213      * @param uid
214      * @param userId
215      * @param started
216      */
updateBatteryStats( ComponentName activity, int uid, int userId, boolean resumed)217     public abstract void updateBatteryStats(
218             ComponentName activity, int uid, int userId, boolean resumed);
219 
220     /**
221      * Update UsageStats of the activity.
222      * @param activity
223      * @param userId
224      * @param event
225      * @param appToken ActivityRecord's appToken.
226      * @param taskRoot TaskRecord's root
227      */
updateActivityUsageStats( ComponentName activity, int userId, int event, IBinder appToken, ComponentName taskRoot)228     public abstract void updateActivityUsageStats(
229             ComponentName activity, int userId, int event, IBinder appToken,
230             ComponentName taskRoot);
updateForegroundTimeIfOnBattery( String packageName, int uid, long cpuTimeDiff)231     public abstract void updateForegroundTimeIfOnBattery(
232             String packageName, int uid, long cpuTimeDiff);
sendForegroundProfileChanged(int userId)233     public abstract void sendForegroundProfileChanged(int userId);
234 
235     /**
236      * Returns whether the given user requires credential entry at this time. This is used to
237      * intercept activity launches for work apps when the Work Challenge is present.
238      */
shouldConfirmCredentials(int userId)239     public abstract boolean shouldConfirmCredentials(int userId);
240 
getCurrentProfileIds()241     public abstract int[] getCurrentProfileIds();
getCurrentUser()242     public abstract UserInfo getCurrentUser();
ensureNotSpecialUser(int userId)243     public abstract void ensureNotSpecialUser(int userId);
isCurrentProfile(int userId)244     public abstract boolean isCurrentProfile(int userId);
hasStartedUserState(int userId)245     public abstract boolean hasStartedUserState(int userId);
finishUserSwitch(Object uss)246     public abstract void finishUserSwitch(Object uss);
247 
248     /** Schedule the execution of all pending app GCs. */
scheduleAppGcs()249     public abstract void scheduleAppGcs();
250 
251     /** Gets the task id for a given activity. */
getTaskIdForActivity(@onNull IBinder token, boolean onlyRoot)252     public abstract int getTaskIdForActivity(@NonNull IBinder token, boolean onlyRoot);
253 
254     /** Gets the basic info for a given activity. */
getActivityPresentationInfo(@onNull IBinder token)255     public abstract ActivityPresentationInfo getActivityPresentationInfo(@NonNull IBinder token);
256 
setBooting(boolean booting)257     public abstract void setBooting(boolean booting);
isBooting()258     public abstract boolean isBooting();
setBooted(boolean booted)259     public abstract void setBooted(boolean booted);
isBooted()260     public abstract boolean isBooted();
finishBooting()261     public abstract void finishBooting();
262 
tempWhitelistForPendingIntent(int callerPid, int callerUid, int targetUid, long duration, String tag)263     public abstract void tempWhitelistForPendingIntent(int callerPid, int callerUid, int targetUid,
264             long duration, String tag);
broadcastIntentInPackage(String packageName, 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, int userId, boolean allowBackgroundActivityStarts)265     public abstract int broadcastIntentInPackage(String packageName, int uid, int realCallingUid,
266             int realCallingPid, Intent intent, String resolvedType, IIntentReceiver resultTo,
267             int resultCode, String resultData, Bundle resultExtras, String requiredPermission,
268             Bundle bOptions, boolean serialized, boolean sticky, int userId,
269             boolean allowBackgroundActivityStarts);
startServiceInPackage(int uid, Intent service, String resolvedType, boolean fgRequired, String callingPackage, int userId, boolean allowBackgroundActivityStarts)270     public abstract ComponentName startServiceInPackage(int uid, Intent service,
271             String resolvedType, boolean fgRequired, String callingPackage, int userId,
272             boolean allowBackgroundActivityStarts) throws TransactionTooLargeException;
273 
disconnectActivityFromServices(Object connectionHolder, Object conns)274     public abstract void disconnectActivityFromServices(Object connectionHolder, Object conns);
cleanUpServices(int userId, ComponentName component, Intent baseIntent)275     public abstract void cleanUpServices(int userId, ComponentName component, Intent baseIntent);
getActivityInfoForUser(ActivityInfo aInfo, int userId)276     public abstract ActivityInfo getActivityInfoForUser(ActivityInfo aInfo, int userId);
ensureBootCompleted()277     public abstract void ensureBootCompleted();
updateOomLevelsForDisplay(int displayId)278     public abstract void updateOomLevelsForDisplay(int displayId);
isActivityStartsLoggingEnabled()279     public abstract boolean isActivityStartsLoggingEnabled();
280     /** Returns true if the background activity starts is enabled. */
isBackgroundActivityStartsEnabled()281     public abstract boolean isBackgroundActivityStartsEnabled();
reportCurKeyguardUsageEvent(boolean keyguardShowing)282     public abstract void reportCurKeyguardUsageEvent(boolean keyguardShowing);
283 
284     /** Input dispatch timeout to a window, start the ANR process. */
inputDispatchingTimedOut(int pid, boolean aboveSystem, String reason)285     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)286     public abstract boolean inputDispatchingTimedOut(Object proc, String activityShortComponentName,
287             ApplicationInfo aInfo, String parentShortComponentName, Object parentProc,
288             boolean aboveSystem, String reason);
289 
290     /**
291      * Sends {@link android.content.Intent#ACTION_CONFIGURATION_CHANGED} with all the appropriate
292      * flags.
293      */
broadcastGlobalConfigurationChanged(int changes, boolean initLocale)294     public abstract void broadcastGlobalConfigurationChanged(int changes, boolean initLocale);
295 
296     /**
297      * Sends {@link android.content.Intent#ACTION_CLOSE_SYSTEM_DIALOGS} with all the appropriate
298      * flags.
299      */
broadcastCloseSystemDialogs(String reason)300     public abstract void broadcastCloseSystemDialogs(String reason);
301 
302     /**
303      * Kills all background processes, except those matching any of the specified properties.
304      *
305      * @param minTargetSdk the target SDK version at or above which to preserve processes,
306      *                     or {@code -1} to ignore the target SDK
307      * @param maxProcState the process state at or below which to preserve processes,
308      *                     or {@code -1} to ignore the process state
309      */
killAllBackgroundProcessesExcept(int minTargetSdk, int maxProcState)310     public abstract void killAllBackgroundProcessesExcept(int minTargetSdk, int maxProcState);
311 
312     /** Starts a given process. */
startProcess(String processName, ApplicationInfo info, boolean knownToBeDead, String hostingType, ComponentName hostingName)313     public abstract void startProcess(String processName, ApplicationInfo info,
314             boolean knownToBeDead, String hostingType, ComponentName hostingName);
315 
316     /** Starts up the starting activity process for debugging if needed.
317      * This function needs to be called synchronously from WindowManager context so the caller
318      * passes a lock {@code wmLock} and waits to be notified.
319      *
320      * @param wmLock calls {@code notify} on the object to wake up the caller.
321     */
setDebugFlagsForStartingActivity(ActivityInfo aInfo, int startFlags, ProfilerInfo profilerInfo, Object wmLock)322     public abstract void setDebugFlagsForStartingActivity(ActivityInfo aInfo, int startFlags,
323             ProfilerInfo profilerInfo, Object wmLock);
324 
325     /** Returns mount mode for process running with given pid */
getStorageMountMode(int pid, int uid)326     public abstract int getStorageMountMode(int pid, int uid);
327 
328     /** Returns true if the given uid is the app in the foreground. */
isAppForeground(int uid)329     public abstract boolean isAppForeground(int uid);
330 
331     /** Returns true if the given uid is currently marked 'bad' */
isAppBad(ApplicationInfo info)332     public abstract boolean isAppBad(ApplicationInfo info);
333 
334     /** Remove pending backup for the given userId. */
clearPendingBackup(int userId)335     public abstract void clearPendingBackup(int userId);
336 
337     /**
338      * When power button is very long pressed, call this interface to do some pre-shutdown work
339      * like persisting database etc.
340      */
prepareForPossibleShutdown()341     public abstract void prepareForPossibleShutdown();
342 
343     /**
344      * Returns {@code true} if {@code uid} is running a foreground service of a specific
345      * {@code foregroundServiceType}.
346      */
hasRunningForegroundService(int uid, int foregroundServiceType)347     public abstract boolean hasRunningForegroundService(int uid, int foregroundServiceType);
348 
349     /**
350      * Registers the specified {@code processObserver} to be notified of future changes to
351      * process state.
352      */
registerProcessObserver(IProcessObserver processObserver)353     public abstract void registerProcessObserver(IProcessObserver processObserver);
354 
355     /**
356      * Unregisters the specified {@code processObserver}.
357      */
unregisterProcessObserver(IProcessObserver processObserver)358     public abstract void unregisterProcessObserver(IProcessObserver processObserver);
359 }
360