blob: 86e658dfdcb1dbb1ca2e1dcad4a2aad9b5595535 [file] [log] [blame]
Jeff Brown13014b52014-04-07 19:45:27 -07001/*
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
17package android.app;
18
Jeff Brown061ea992015-04-17 19:55:47 -070019import android.annotation.NonNull;
Jorim Jaggife762342016-10-13 14:33:27 +020020import android.annotation.Nullable;
Wale Ogunwale53783742018-09-16 10:21:51 -070021import android.content.ComponentName;
Wale Ogunwaleee6eca12018-09-19 20:37:53 -070022import android.content.IIntentReceiver;
Felipe Lemea1b79bf2016-05-24 13:06:54 -070023import android.content.IIntentSender;
Makoto Onukiea11db12016-06-24 15:17:44 -070024import android.content.Intent;
Wale Ogunwale342fbe92018-10-09 08:44:10 -070025import android.content.pm.ActivityInfo;
Wale Ogunwalea6191b42018-05-09 07:41:32 -070026import android.content.pm.ApplicationInfo;
Wale Ogunwale86b74462018-07-02 08:42:43 -070027import android.content.pm.UserInfo;
Wale Ogunwaleee6eca12018-09-19 20:37:53 -070028import android.os.Bundle;
Amith Yamasani0af6fa72016-01-17 15:36:19 -080029import android.os.IBinder;
Wale Ogunwaleee6eca12018-09-19 20:37:53 -070030import android.os.TransactionTooLargeException;
Jorim Jaggibc2aabe2018-03-08 17:27:43 +010031import android.view.RemoteAnimationAdapter;
Amith Yamasani0af6fa72016-01-17 15:36:19 -080032
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070033import java.util.ArrayList;
Amith Yamasanie8222e52016-04-08 15:28:47 -070034import java.util.List;
35
Jeff Brown13014b52014-04-07 19:45:27 -070036/**
37 * Activity manager local system service interface.
38 *
39 * @hide Only for use within the system server.
40 */
41public abstract class ActivityManagerInternal {
Jorim Jaggi275561a2016-02-23 10:11:02 -050042
Winson Chungec1ef092017-10-25 16:22:34 -070043
Wale Ogunwalea6191b42018-05-09 07:41:32 -070044 // Access modes for handleIncomingUser.
45 public static final int ALLOW_NON_FULL = 0;
46 public static final int ALLOW_NON_FULL_IN_PROFILE = 1;
47 public static final int ALLOW_FULL_ONLY = 2;
48
Winson Chungec1ef092017-10-25 16:22:34 -070049 /**
Jeff Sharkey923e0b82016-11-16 17:22:48 -070050 * Verify that calling app has access to the given provider.
51 */
52 public abstract String checkContentProviderAccess(String authority, int userId);
53
Jeff Brown13014b52014-04-07 19:45:27 -070054 // Called by the power manager.
Jeff Brownfbe96702014-11-19 18:30:58 -080055 public abstract void onWakefulnessChanged(int wakefulness);
56
Sudheer Shankaf6690102017-10-16 10:20:32 -070057 /**
58 * @return {@code true} if process start is successful, {@code false} otherwise.
59 */
60 public abstract boolean startIsolatedProcess(String entryPoint, String[] mainArgs,
Primiano Tucci810c0522014-07-25 18:03:16 +010061 String processName, String abiOverride, int uid, Runnable crashHandler);
Jeff Brown061ea992015-04-17 19:55:47 -070062
63 /**
Rubin Xuf8451b92016-04-01 15:50:58 +010064 * Kill foreground apps from the specified user.
65 */
66 public abstract void killForegroundAppsForUser(int userHandle);
Felipe Lemea1b79bf2016-05-24 13:06:54 -070067
68 /**
69 * Sets how long a {@link PendingIntent} can be temporarily whitelist to by bypass restrictions
70 * such as Power Save mode.
71 */
Dianne Hackborn98305522017-05-05 17:53:53 -070072 public abstract void setPendingIntentWhitelistDuration(IIntentSender target,
73 IBinder whitelistToken, long duration);
Suprabh Shukla64725012016-06-15 13:19:28 -070074
75 /**
Michal Karpinskiac116df2018-12-10 17:51:42 +000076 * Allows for a {@link PendingIntent} to be whitelisted to start activities from background.
77 */
78 public abstract void setPendingIntentAllowBgActivityStarts(
79 IIntentSender target, IBinder whitelistToken, int flags);
80
81 /**
Dianne Hackborn85e35642017-01-12 15:10:57 -080082 * Allow DeviceIdleController to tell us about what apps are whitelisted.
83 */
Makoto Onukiaf8ff4f2018-06-04 14:44:19 -070084 public abstract void setDeviceIdleWhitelist(int[] allAppids, int[] exceptIdleAppids);
Dianne Hackborn85e35642017-01-12 15:10:57 -080085
86 /**
87 * Update information about which app IDs are on the temp whitelist.
88 */
89 public abstract void updateDeviceIdleTempWhitelist(int[] appids, int changingAppId,
90 boolean adding);
91
92 /**
Makoto Onuki33525d22016-08-03 15:45:24 -070093 * Get the procstate for the UID. The return value will be between
94 * {@link ActivityManager#MIN_PROCESS_STATE} and {@link ActivityManager#MAX_PROCESS_STATE}.
95 * Note if the UID doesn't exist, it'll return {@link ActivityManager#PROCESS_STATE_NONEXISTENT}
96 * (-1).
97 */
98 public abstract int getUidProcessState(int uid);
Jorim Jaggife762342016-10-13 14:33:27 +020099
100 /**
Sudheer Shankafc46e9b2016-10-21 17:55:27 -0700101 * @return {@code true} if system is ready, {@code false} otherwise.
102 */
103 public abstract boolean isSystemReady();
Jorim Jaggie69c9312016-10-31 18:24:38 -0700104
105 /**
Wale Ogunwaled993a572017-02-05 13:52:09 -0800106 * Sets if the given pid has an overlay UI or not.
107 *
108 * @param pid The pid we are setting overlay UI for.
109 * @param hasOverlayUi True if the process has overlay UI.
110 * @see android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
111 */
112 public abstract void setHasOverlayUi(int pid, boolean hasOverlayUi);
Sudheer Shankae7361852017-03-07 11:51:46 -0800113
114 /**
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100115 * Sets if the given pid is currently running a remote animation, which is taken a signal for
116 * determining oom adjustment and scheduling behavior.
117 *
118 * @param pid The pid we are setting overlay UI for.
119 * @param runningRemoteAnimation True if the process is running a remote animation, false
120 * otherwise.
121 * @see RemoteAnimationAdapter
122 */
123 public abstract void setRunningRemoteAnimation(int pid, boolean runningRemoteAnimation);
124
125 /**
Sudheer Shankae7361852017-03-07 11:51:46 -0800126 * Called after the network policy rules are updated by
127 * {@link com.android.server.net.NetworkPolicyManagerService} for a specific {@param uid} and
128 * {@param procStateSeq}.
129 */
130 public abstract void notifyNetworkPolicyRulesUpdated(int uid, long procStateSeq);
Karthik Ravi Shankar99493db2017-03-08 18:30:19 -0800131
132 /**
Makoto Onukie098b7592017-11-27 17:50:41 -0800133 * @return true if runtime was restarted, false if it's normal boot
134 */
135 public abstract boolean isRuntimeRestarted();
Felipe Leme2a580d12017-12-11 14:37:35 -0800136
137 /**
Alex Chaub6ef8692018-01-09 14:16:36 +0000138 * Returns if more users can be started without stopping currently running users.
139 */
140 public abstract boolean canStartMoreUsers();
Alex Chau93ae42b2018-01-11 15:10:12 +0000141
142 /**
143 * Sets the user switcher message for switching from {@link android.os.UserHandle#SYSTEM}.
144 */
145 public abstract void setSwitchingFromSystemUserMessage(String switchingFromSystemUserMessage);
146
147 /**
148 * Sets the user switcher message for switching to {@link android.os.UserHandle#SYSTEM}.
149 */
150 public abstract void setSwitchingToSystemUserMessage(String switchingToSystemUserMessage);
Alex Chauc12189b2018-01-16 15:01:15 +0000151
152 /**
153 * Returns maximum number of users that can run simultaneously.
154 */
155 public abstract int getMaxRunningUsers();
Tony Make839d702018-01-22 15:34:46 +0000156
157 /**
Makoto Onukie4918212018-02-06 11:30:15 -0800158 * Whether an UID is active or idle.
159 */
160 public abstract boolean isUidActive(int uid);
Rajeev Kumar22d92b72018-02-07 18:38:36 -0800161
162 /**
163 * Returns a list that contains the memory stats for currently running processes.
Rafal Slawik08621582018-10-15 14:53:07 +0100164 *
165 * Only processes managed by ActivityManagerService are included.
Rajeev Kumar22d92b72018-02-07 18:38:36 -0800166 */
167 public abstract List<ProcessMemoryState> getMemoryStateForProcesses();
Wale Ogunwalea6191b42018-05-09 07:41:32 -0700168
169 /**
Rafal Slawik3bea8952018-11-15 12:39:33 +0000170 * Returns a list that contains the memory high-water mark for currently running processes.
171 *
172 * Only processes managed by ActivityManagerService are included.
173 */
174 public abstract List<ProcessMemoryHighWaterMark> getMemoryHighWaterMarkForProcesses();
175
176 /**
Wale Ogunwalea6191b42018-05-09 07:41:32 -0700177 * Checks to see if the calling pid is allowed to handle the user. Returns adjusted user id as
178 * needed.
179 */
180 public abstract int handleIncomingUser(int callingPid, int callingUid, int userId,
181 boolean allowAll, int allowMode, String name, String callerPackage);
182
183 /** Checks if the calling binder pid as the permission. */
184 public abstract void enforceCallingPermission(String permission, String func);
185
186 /** Returns the current user id. */
187 public abstract int getCurrentUserId();
188
189 /** Returns true if the user is running. */
190 public abstract boolean isUserRunning(int userId, int flags);
191
192 /** Trims memory usage in the system by removing/stopping unused application processes. */
193 public abstract void trimApplications();
194
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700195 /** Kill the processes in the list due to their tasks been removed. */
196 public abstract void killProcessesForRemovedTask(ArrayList<Object> procsToKill);
197
198 /**
199 * Returns {@code true} if {@code uid} is running an activity from {@code packageName}.
200 */
201 public abstract boolean hasRunningActivity(int uid, @Nullable String packageName);
Wale Ogunwalef6733932018-06-27 05:14:34 -0700202
203 public abstract void updateOomAdj();
Wale Ogunwale53783742018-09-16 10:21:51 -0700204 public abstract void updateCpuStats();
Hui Yu03d12402018-12-06 18:00:37 -0800205
206 /**
207 * Update battery stats on activity usage.
208 * @param activity
209 * @param uid
210 * @param userId
211 * @param started
212 */
213 public abstract void updateBatteryStats(
Wale Ogunwale53783742018-09-16 10:21:51 -0700214 ComponentName activity, int uid, int userId, boolean resumed);
Hui Yu03d12402018-12-06 18:00:37 -0800215
216 /**
217 * Update UsageStats of the activity.
218 * @param activity
219 * @param userId
220 * @param event
221 * @param appToken ActivityRecord's appToken.
Michael Wachenschwanz0b4ab1f2019-01-07 13:59:10 -0800222 * @param taskRoot TaskRecord's root
Hui Yu03d12402018-12-06 18:00:37 -0800223 */
224 public abstract void updateActivityUsageStats(
Michael Wachenschwanz0b4ab1f2019-01-07 13:59:10 -0800225 ComponentName activity, int userId, int event, IBinder appToken,
226 ComponentName taskRoot);
Wale Ogunwale53783742018-09-16 10:21:51 -0700227 public abstract void updateForegroundTimeIfOnBattery(
228 String packageName, int uid, long cpuTimeDiff);
Wale Ogunwalef6733932018-06-27 05:14:34 -0700229 public abstract void sendForegroundProfileChanged(int userId);
Wale Ogunwale86b74462018-07-02 08:42:43 -0700230
231 /**
232 * Returns whether the given user requires credential entry at this time. This is used to
233 * intercept activity launches for work apps when the Work Challenge is present.
234 */
235 public abstract boolean shouldConfirmCredentials(int userId);
Jorim Jaggi402d78e2018-07-09 17:57:10 +0200236
Wale Ogunwale86b74462018-07-02 08:42:43 -0700237 public abstract int[] getCurrentProfileIds();
238 public abstract UserInfo getCurrentUser();
239 public abstract void ensureNotSpecialUser(int userId);
240 public abstract boolean isCurrentProfile(int userId);
241 public abstract boolean hasStartedUserState(int userId);
242 public abstract void finishUserSwitch(Object uss);
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700243
244 /** Schedule the execution of all pending app GCs. */
245 public abstract void scheduleAppGcs();
Felipe Leme8d7f7f42018-07-31 16:14:39 -0700246
247 /** Gets the task id for a given activity. */
248 public abstract int getTaskIdForActivity(@NonNull IBinder token, boolean onlyRoot);
Wale Ogunwale53783742018-09-16 10:21:51 -0700249
250 public abstract void setBooting(boolean booting);
251 public abstract boolean isBooting();
252 public abstract void setBooted(boolean booted);
253 public abstract boolean isBooted();
254 public abstract void finishBooting();
Wale Ogunwaleee6eca12018-09-19 20:37:53 -0700255
256 public abstract void tempWhitelistForPendingIntent(int callerPid, int callerUid, int targetUid,
257 long duration, String tag);
258 public abstract int broadcastIntentInPackage(String packageName, int uid, Intent intent,
259 String resolvedType, IIntentReceiver resultTo, int resultCode, String resultData,
260 Bundle resultExtras, String requiredPermission, Bundle bOptions, boolean serialized,
Michal Karpinskiac116df2018-12-10 17:51:42 +0000261 boolean sticky, int userId, boolean allowBackgroundActivityStarts);
Wale Ogunwaleee6eca12018-09-19 20:37:53 -0700262 public abstract ComponentName startServiceInPackage(int uid, Intent service,
Michal Karpinskic8aa91b2019-01-10 16:45:59 +0000263 String resolvedType, boolean fgRequired, String callingPackage, int userId,
264 boolean allowBackgroundActivityStarts) throws TransactionTooLargeException;
Wale Ogunwalec4e63a42018-10-02 13:19:54 -0700265
266 public abstract void disconnectActivityFromServices(Object connectionHolder);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700267 public abstract void cleanUpServices(int userId, ComponentName component, Intent baseIntent);
268 public abstract ActivityInfo getActivityInfoForUser(ActivityInfo aInfo, int userId);
269 public abstract void ensureBootCompleted();
270 public abstract void updateOomLevelsForDisplay(int displayId);
271 public abstract boolean isActivityStartsLoggingEnabled();
Michal Karpinski8596ded2018-11-14 14:43:48 +0000272 /** Returns true if the background activity starts is enabled. */
273 public abstract boolean isBackgroundActivityStartsEnabled();
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700274 public abstract void reportCurKeyguardUsageEvent(boolean keyguardShowing);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700275
276 /** Input dispatch timeout to a window, start the ANR process. */
277 public abstract long inputDispatchingTimedOut(int pid, boolean aboveSystem, String reason);
278 public abstract boolean inputDispatchingTimedOut(Object proc, String activityShortComponentName,
279 ApplicationInfo aInfo, String parentShortComponentName, Object parentProc,
280 boolean aboveSystem, String reason);
Wale Ogunwale2ea36d42018-10-18 10:27:31 -0700281
282 /**
283 * Sends {@link android.content.Intent#ACTION_CONFIGURATION_CHANGED} with all the appropriate
284 * flags.
285 */
286 public abstract void broadcastGlobalConfigurationChanged(int changes, boolean initLocale);
287
288 /**
289 * Sends {@link android.content.Intent#ACTION_CLOSE_SYSTEM_DIALOGS} with all the appropriate
290 * flags.
291 */
292 public abstract void broadcastCloseSystemDialogs(String reason);
Wale Ogunwale5c918702018-10-18 11:06:33 -0700293
294 /**
295 * Kills all background processes, except those matching any of the specified properties.
296 *
297 * @param minTargetSdk the target SDK version at or above which to preserve processes,
298 * or {@code -1} to ignore the target SDK
299 * @param maxProcState the process state at or below which to preserve processes,
300 * or {@code -1} to ignore the process state
301 */
302 public abstract void killAllBackgroundProcessesExcept(int minTargetSdk, int maxProcState);
303
304 /** Starts a given process. */
305 public abstract void startProcess(String processName, ApplicationInfo info,
306 boolean knownToBeDead, String hostingType, ComponentName hostingName);
Wale Ogunwale7056a062018-10-18 15:02:50 -0700307
Vishnu Nair006ee3f2018-11-09 08:36:01 -0800308 /** Starts up the starting activity process for debugging if needed.
309 * This function needs to be called synchronously from WindowManager context so the caller
310 * passes a lock {@code wmLock} and waits to be notified.
311 *
312 * @param wmLock calls {@code notify} on the object to wake up the caller.
313 */
Wale Ogunwale7056a062018-10-18 15:02:50 -0700314 public abstract void setDebugFlagsForStartingActivity(ActivityInfo aInfo, int startFlags,
Vishnu Nair006ee3f2018-11-09 08:36:01 -0800315 ProfilerInfo profilerInfo, Object wmLock);
Sudheer Shanka87915d62018-11-06 10:57:35 -0800316
Sudheer Shanka3a0df3b2018-12-12 12:43:43 -0800317 /** Returns mount mode for process running with given pid */
318 public abstract int getStorageMountMode(int pid, int uid);
Varun Shah98c84e12019-01-03 19:24:24 -0800319
320 /** Returns true if the given uid is the app in the foreground. */
321 public abstract boolean isAppForeground(int uid);
Chandan Nath2c9ae092019-01-15 12:54:28 +0000322
323 /** Remove pending backup for the given userId. */
324 public abstract void clearPendingBackup(int userId);
Hui Yub1d243a2018-12-13 12:02:00 -0800325
326 /**
327 * When power button is very long pressed, call this interface to do some pre-shutdown work
328 * like persisting database etc.
329 */
330 public abstract void prepareForPossibleShutdown();
Jeff Brown13014b52014-04-07 19:45:27 -0700331}