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