blob: 664f0a37a459fbf82c56e0204d4fc95e79931e38 [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;
Adam Hebb82c6a2019-01-17 14:59:02 -080026import android.content.pm.ActivityPresentationInfo;
Wale Ogunwalea6191b42018-05-09 07:41:32 -070027import android.content.pm.ApplicationInfo;
Wale Ogunwale86b74462018-07-02 08:42:43 -070028import android.content.pm.UserInfo;
Wale Ogunwaleee6eca12018-09-19 20:37:53 -070029import android.os.Bundle;
Amith Yamasani0af6fa72016-01-17 15:36:19 -080030import android.os.IBinder;
Wale Ogunwaleee6eca12018-09-19 20:37:53 -070031import android.os.TransactionTooLargeException;
Jorim Jaggibc2aabe2018-03-08 17:27:43 +010032import android.view.RemoteAnimationAdapter;
Amith Yamasani0af6fa72016-01-17 15:36:19 -080033
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070034import java.util.ArrayList;
Amith Yamasanie8222e52016-04-08 15:28:47 -070035import java.util.List;
36
Jeff Brown13014b52014-04-07 19:45:27 -070037/**
38 * Activity manager local system service interface.
39 *
40 * @hide Only for use within the system server.
41 */
42public abstract class ActivityManagerInternal {
Jorim Jaggi275561a2016-02-23 10:11:02 -050043
Winson Chungec1ef092017-10-25 16:22:34 -070044
Wale Ogunwalea6191b42018-05-09 07:41:32 -070045 // 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
Winson Chungec1ef092017-10-25 16:22:34 -070050 /**
Jeff Sharkey923e0b82016-11-16 17:22:48 -070051 * Verify that calling app has access to the given provider.
52 */
53 public abstract String checkContentProviderAccess(String authority, int userId);
54
Jeff Brown13014b52014-04-07 19:45:27 -070055 // Called by the power manager.
Jeff Brownfbe96702014-11-19 18:30:58 -080056 public abstract void onWakefulnessChanged(int wakefulness);
57
Sudheer Shankaf6690102017-10-16 10:20:32 -070058 /**
59 * @return {@code true} if process start is successful, {@code false} otherwise.
60 */
61 public abstract boolean startIsolatedProcess(String entryPoint, String[] mainArgs,
Primiano Tucci810c0522014-07-25 18:03:16 +010062 String processName, String abiOverride, int uid, Runnable crashHandler);
Jeff Brown061ea992015-04-17 19:55:47 -070063
64 /**
Rubin Xuf8451b92016-04-01 15:50:58 +010065 * Kill foreground apps from the specified user.
66 */
67 public abstract void killForegroundAppsForUser(int userHandle);
Felipe Lemea1b79bf2016-05-24 13:06:54 -070068
69 /**
70 * Sets how long a {@link PendingIntent} can be temporarily whitelist to by bypass restrictions
71 * such as Power Save mode.
72 */
Dianne Hackborn98305522017-05-05 17:53:53 -070073 public abstract void setPendingIntentWhitelistDuration(IIntentSender target,
74 IBinder whitelistToken, long duration);
Suprabh Shukla64725012016-06-15 13:19:28 -070075
76 /**
Michal Karpinskiac116df2018-12-10 17:51:42 +000077 * Allows for a {@link PendingIntent} to be whitelisted to start activities from background.
78 */
79 public abstract void setPendingIntentAllowBgActivityStarts(
80 IIntentSender target, IBinder whitelistToken, int flags);
81
82 /**
Dianne Hackborn85e35642017-01-12 15:10:57 -080083 * Allow DeviceIdleController to tell us about what apps are whitelisted.
84 */
Makoto Onukiaf8ff4f2018-06-04 14:44:19 -070085 public abstract void setDeviceIdleWhitelist(int[] allAppids, int[] exceptIdleAppids);
Dianne Hackborn85e35642017-01-12 15:10:57 -080086
87 /**
88 * Update information about which app IDs are on the temp whitelist.
89 */
90 public abstract void updateDeviceIdleTempWhitelist(int[] appids, int changingAppId,
91 boolean adding);
92
93 /**
Makoto Onuki33525d22016-08-03 15:45:24 -070094 * Get the procstate for the UID. The return value will be between
95 * {@link ActivityManager#MIN_PROCESS_STATE} and {@link ActivityManager#MAX_PROCESS_STATE}.
96 * Note if the UID doesn't exist, it'll return {@link ActivityManager#PROCESS_STATE_NONEXISTENT}
97 * (-1).
98 */
99 public abstract int getUidProcessState(int uid);
Jorim Jaggife762342016-10-13 14:33:27 +0200100
101 /**
Sudheer Shankafc46e9b2016-10-21 17:55:27 -0700102 * @return {@code true} if system is ready, {@code false} otherwise.
103 */
104 public abstract boolean isSystemReady();
Jorim Jaggie69c9312016-10-31 18:24:38 -0700105
106 /**
Wale Ogunwaled993a572017-02-05 13:52:09 -0800107 * Sets if the given pid has an overlay UI or not.
108 *
109 * @param pid The pid we are setting overlay UI for.
110 * @param hasOverlayUi True if the process has overlay UI.
111 * @see android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
112 */
113 public abstract void setHasOverlayUi(int pid, boolean hasOverlayUi);
Sudheer Shankae7361852017-03-07 11:51:46 -0800114
115 /**
Jorim Jaggibc2aabe2018-03-08 17:27:43 +0100116 * Sets if the given pid is currently running a remote animation, which is taken a signal for
117 * determining oom adjustment and scheduling behavior.
118 *
119 * @param pid The pid we are setting overlay UI for.
120 * @param runningRemoteAnimation True if the process is running a remote animation, false
121 * otherwise.
122 * @see RemoteAnimationAdapter
123 */
124 public abstract void setRunningRemoteAnimation(int pid, boolean runningRemoteAnimation);
125
126 /**
Sudheer Shankae7361852017-03-07 11:51:46 -0800127 * Called after the network policy rules are updated by
128 * {@link com.android.server.net.NetworkPolicyManagerService} for a specific {@param uid} and
129 * {@param procStateSeq}.
130 */
131 public abstract void notifyNetworkPolicyRulesUpdated(int uid, long procStateSeq);
Karthik Ravi Shankar99493db2017-03-08 18:30:19 -0800132
133 /**
Makoto Onukie098b7592017-11-27 17:50:41 -0800134 * @return true if runtime was restarted, false if it's normal boot
135 */
136 public abstract boolean isRuntimeRestarted();
Felipe Leme2a580d12017-12-11 14:37:35 -0800137
138 /**
Alex Chaub6ef8692018-01-09 14:16:36 +0000139 * Returns if more users can be started without stopping currently running users.
140 */
141 public abstract boolean canStartMoreUsers();
Alex Chau93ae42b2018-01-11 15:10:12 +0000142
143 /**
144 * Sets the user switcher message for switching from {@link android.os.UserHandle#SYSTEM}.
145 */
146 public abstract void setSwitchingFromSystemUserMessage(String switchingFromSystemUserMessage);
147
148 /**
149 * Sets the user switcher message for switching to {@link android.os.UserHandle#SYSTEM}.
150 */
151 public abstract void setSwitchingToSystemUserMessage(String switchingToSystemUserMessage);
Alex Chauc12189b2018-01-16 15:01:15 +0000152
153 /**
154 * Returns maximum number of users that can run simultaneously.
155 */
156 public abstract int getMaxRunningUsers();
Tony Make839d702018-01-22 15:34:46 +0000157
158 /**
Makoto Onukie4918212018-02-06 11:30:15 -0800159 * Whether an UID is active or idle.
160 */
161 public abstract boolean isUidActive(int uid);
Rajeev Kumar22d92b72018-02-07 18:38:36 -0800162
163 /**
164 * Returns a list that contains the memory stats for currently running processes.
Rafal Slawik08621582018-10-15 14:53:07 +0100165 *
166 * Only processes managed by ActivityManagerService are included.
Rajeev Kumar22d92b72018-02-07 18:38:36 -0800167 */
168 public abstract List<ProcessMemoryState> getMemoryStateForProcesses();
Wale Ogunwalea6191b42018-05-09 07:41:32 -0700169
170 /**
Rafal Slawik3bea8952018-11-15 12:39:33 +0000171 * Returns a list that contains the memory high-water mark for currently running processes.
172 *
173 * Only processes managed by ActivityManagerService are included.
174 */
175 public abstract List<ProcessMemoryHighWaterMark> getMemoryHighWaterMarkForProcesses();
176
177 /**
Wale Ogunwalea6191b42018-05-09 07:41:32 -0700178 * Checks to see if the calling pid is allowed to handle the user. Returns adjusted user id as
179 * needed.
180 */
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. */
185 public abstract void enforceCallingPermission(String permission, String func);
186
187 /** Returns the current user id. */
188 public abstract int getCurrentUserId();
189
190 /** Returns true if the user is running. */
191 public abstract boolean isUserRunning(int userId, int flags);
192
193 /** Trims memory usage in the system by removing/stopping unused application processes. */
194 public abstract void trimApplications();
195
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700196 /** Kill the processes in the list due to their tasks been removed. */
197 public abstract void killProcessesForRemovedTask(ArrayList<Object> procsToKill);
198
Riddle Hsu7b766fd2019-01-28 21:14:59 +0800199 /** Kill the process immediately. */
200 public abstract void killProcess(String processName, int uid, String reason);
201
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -0700202 /**
203 * Returns {@code true} if {@code uid} is running an activity from {@code packageName}.
204 */
205 public abstract boolean hasRunningActivity(int uid, @Nullable String packageName);
Wale Ogunwalef6733932018-06-27 05:14:34 -0700206
207 public abstract void updateOomAdj();
Wale Ogunwale53783742018-09-16 10:21:51 -0700208 public abstract void updateCpuStats();
Hui Yu03d12402018-12-06 18:00:37 -0800209
210 /**
211 * Update battery stats on activity usage.
212 * @param activity
213 * @param uid
214 * @param userId
215 * @param started
216 */
217 public abstract void updateBatteryStats(
Wale Ogunwale53783742018-09-16 10:21:51 -0700218 ComponentName activity, int uid, int userId, boolean resumed);
Hui Yu03d12402018-12-06 18:00:37 -0800219
220 /**
221 * Update UsageStats of the activity.
222 * @param activity
223 * @param userId
224 * @param event
225 * @param appToken ActivityRecord's appToken.
Michael Wachenschwanz0b4ab1f2019-01-07 13:59:10 -0800226 * @param taskRoot TaskRecord's root
Hui Yu03d12402018-12-06 18:00:37 -0800227 */
228 public abstract void updateActivityUsageStats(
Michael Wachenschwanz0b4ab1f2019-01-07 13:59:10 -0800229 ComponentName activity, int userId, int event, IBinder appToken,
230 ComponentName taskRoot);
Wale Ogunwale53783742018-09-16 10:21:51 -0700231 public abstract void updateForegroundTimeIfOnBattery(
232 String packageName, int uid, long cpuTimeDiff);
Wale Ogunwalef6733932018-06-27 05:14:34 -0700233 public abstract void sendForegroundProfileChanged(int userId);
Wale Ogunwale86b74462018-07-02 08:42:43 -0700234
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 */
239 public abstract boolean shouldConfirmCredentials(int userId);
Jorim Jaggi402d78e2018-07-09 17:57:10 +0200240
Wale Ogunwale86b74462018-07-02 08:42:43 -0700241 public abstract int[] getCurrentProfileIds();
242 public abstract UserInfo getCurrentUser();
243 public abstract void ensureNotSpecialUser(int userId);
244 public abstract boolean isCurrentProfile(int userId);
245 public abstract boolean hasStartedUserState(int userId);
246 public abstract void finishUserSwitch(Object uss);
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700247
248 /** Schedule the execution of all pending app GCs. */
249 public abstract void scheduleAppGcs();
Felipe Leme8d7f7f42018-07-31 16:14:39 -0700250
251 /** Gets the task id for a given activity. */
252 public abstract int getTaskIdForActivity(@NonNull IBinder token, boolean onlyRoot);
Wale Ogunwale53783742018-09-16 10:21:51 -0700253
Adam Hebb82c6a2019-01-17 14:59:02 -0800254 /** Gets the basic info for a given activity. */
255 public abstract ActivityPresentationInfo getActivityPresentationInfo(@NonNull IBinder token);
256
Wale Ogunwale53783742018-09-16 10:21:51 -0700257 public abstract void setBooting(boolean booting);
258 public abstract boolean isBooting();
259 public abstract void setBooted(boolean booted);
260 public abstract boolean isBooted();
261 public abstract void finishBooting();
Wale Ogunwaleee6eca12018-09-19 20:37:53 -0700262
263 public abstract void tempWhitelistForPendingIntent(int callerPid, int callerUid, int targetUid,
264 long duration, String tag);
Michal Karpinskic99d7182019-02-17 13:15:23 +0000265 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);
Wale Ogunwaleee6eca12018-09-19 20:37:53 -0700270 public abstract ComponentName startServiceInPackage(int uid, Intent service,
Michal Karpinskic8aa91b2019-01-10 16:45:59 +0000271 String resolvedType, boolean fgRequired, String callingPackage, int userId,
272 boolean allowBackgroundActivityStarts) throws TransactionTooLargeException;
Wale Ogunwalec4e63a42018-10-02 13:19:54 -0700273
274 public abstract void disconnectActivityFromServices(Object connectionHolder);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700275 public abstract void cleanUpServices(int userId, ComponentName component, Intent baseIntent);
276 public abstract ActivityInfo getActivityInfoForUser(ActivityInfo aInfo, int userId);
277 public abstract void ensureBootCompleted();
278 public abstract void updateOomLevelsForDisplay(int displayId);
279 public abstract boolean isActivityStartsLoggingEnabled();
Michal Karpinski8596ded2018-11-14 14:43:48 +0000280 /** Returns true if the background activity starts is enabled. */
281 public abstract boolean isBackgroundActivityStartsEnabled();
Michal Karpinski666631b2019-02-26 16:59:11 +0000282 public abstract boolean isPackageNameWhitelistedForBgActivityStarts(String packageName);
Wale Ogunwale342fbe92018-10-09 08:44:10 -0700283 public abstract void reportCurKeyguardUsageEvent(boolean keyguardShowing);
Wale Ogunwale51cc98a2018-10-15 10:41:05 -0700284
285 /** Input dispatch timeout to a window, start the ANR process. */
286 public abstract long inputDispatchingTimedOut(int pid, boolean aboveSystem, String reason);
287 public abstract boolean inputDispatchingTimedOut(Object proc, String activityShortComponentName,
288 ApplicationInfo aInfo, String parentShortComponentName, Object parentProc,
289 boolean aboveSystem, String reason);
Wale Ogunwale2ea36d42018-10-18 10:27:31 -0700290
291 /**
292 * Sends {@link android.content.Intent#ACTION_CONFIGURATION_CHANGED} with all the appropriate
293 * flags.
294 */
295 public abstract void broadcastGlobalConfigurationChanged(int changes, boolean initLocale);
296
297 /**
298 * Sends {@link android.content.Intent#ACTION_CLOSE_SYSTEM_DIALOGS} with all the appropriate
299 * flags.
300 */
301 public abstract void broadcastCloseSystemDialogs(String reason);
Wale Ogunwale5c918702018-10-18 11:06:33 -0700302
303 /**
304 * Kills all background processes, except those matching any of the specified properties.
305 *
306 * @param minTargetSdk the target SDK version at or above which to preserve processes,
307 * or {@code -1} to ignore the target SDK
308 * @param maxProcState the process state at or below which to preserve processes,
309 * or {@code -1} to ignore the process state
310 */
311 public abstract void killAllBackgroundProcessesExcept(int minTargetSdk, int maxProcState);
312
313 /** Starts a given process. */
314 public abstract void startProcess(String processName, ApplicationInfo info,
315 boolean knownToBeDead, String hostingType, ComponentName hostingName);
Wale Ogunwale7056a062018-10-18 15:02:50 -0700316
Vishnu Nair006ee3f2018-11-09 08:36:01 -0800317 /** Starts up the starting activity process for debugging if needed.
318 * This function needs to be called synchronously from WindowManager context so the caller
319 * passes a lock {@code wmLock} and waits to be notified.
320 *
321 * @param wmLock calls {@code notify} on the object to wake up the caller.
322 */
Wale Ogunwale7056a062018-10-18 15:02:50 -0700323 public abstract void setDebugFlagsForStartingActivity(ActivityInfo aInfo, int startFlags,
Vishnu Nair006ee3f2018-11-09 08:36:01 -0800324 ProfilerInfo profilerInfo, Object wmLock);
Sudheer Shanka87915d62018-11-06 10:57:35 -0800325
Sudheer Shanka3a0df3b2018-12-12 12:43:43 -0800326 /** Returns mount mode for process running with given pid */
327 public abstract int getStorageMountMode(int pid, int uid);
Varun Shah98c84e12019-01-03 19:24:24 -0800328
329 /** Returns true if the given uid is the app in the foreground. */
330 public abstract boolean isAppForeground(int uid);
Chandan Nath2c9ae092019-01-15 12:54:28 +0000331
332 /** Remove pending backup for the given userId. */
333 public abstract void clearPendingBackup(int userId);
Hui Yub1d243a2018-12-13 12:02:00 -0800334
335 /**
336 * When power button is very long pressed, call this interface to do some pre-shutdown work
337 * like persisting database etc.
338 */
339 public abstract void prepareForPossibleShutdown();
Jeff Brown13014b52014-04-07 19:45:27 -0700340}