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.IIntentSender; 23 import android.content.Intent; 24 import android.content.res.Configuration; 25 import android.os.Bundle; 26 import android.os.IBinder; 27 import android.os.SystemClock; 28 import android.service.voice.IVoiceInteractionSession; 29 import android.util.SparseIntArray; 30 import android.view.RemoteAnimationAdapter; 31 32 import com.android.internal.app.IVoiceInteractor; 33 34 import java.util.List; 35 36 /** 37 * Activity manager local system service interface. 38 * 39 * @hide Only for use within the system server. 40 */ 41 public abstract class ActivityManagerInternal { 42 43 /** 44 * Type for {@link #notifyAppTransitionStarting}: The transition was started because we drew 45 * the splash screen. 46 */ 47 public static final int APP_TRANSITION_SPLASH_SCREEN = 48 AppProtoEnums.APP_TRANSITION_SPLASH_SCREEN; // 1 49 50 /** 51 * Type for {@link #notifyAppTransitionStarting}: The transition was started because we all 52 * app windows were drawn 53 */ 54 public static final int APP_TRANSITION_WINDOWS_DRAWN = 55 AppProtoEnums.APP_TRANSITION_WINDOWS_DRAWN; // 2 56 57 /** 58 * Type for {@link #notifyAppTransitionStarting}: The transition was started because of a 59 * timeout. 60 */ 61 public static final int APP_TRANSITION_TIMEOUT = 62 AppProtoEnums.APP_TRANSITION_TIMEOUT; // 3 63 64 /** 65 * Type for {@link #notifyAppTransitionStarting}: The transition was started because of a 66 * we drew a task snapshot. 67 */ 68 public static final int APP_TRANSITION_SNAPSHOT = 69 AppProtoEnums.APP_TRANSITION_SNAPSHOT; // 4 70 71 /** 72 * Type for {@link #notifyAppTransitionStarting}: The transition was started because it was a 73 * recents animation and we only needed to wait on the wallpaper. 74 */ 75 public static final int APP_TRANSITION_RECENTS_ANIM = 76 AppProtoEnums.APP_TRANSITION_RECENTS_ANIM; // 5 77 78 /** 79 * The bundle key to extract the assist data. 80 */ 81 public static final String ASSIST_KEY_DATA = "data"; 82 83 /** 84 * The bundle key to extract the assist structure. 85 */ 86 public static final String ASSIST_KEY_STRUCTURE = "structure"; 87 88 /** 89 * The bundle key to extract the assist content. 90 */ 91 public static final String ASSIST_KEY_CONTENT = "content"; 92 93 /** 94 * The bundle key to extract the assist receiver extras. 95 */ 96 public static final String ASSIST_KEY_RECEIVER_EXTRAS = "receiverExtras"; 97 98 99 /** 100 * Grant Uri permissions from one app to another. This method only extends 101 * permission grants if {@code callingUid} has permission to them. 102 */ grantUriPermissionFromIntent(int callingUid, String targetPkg, Intent intent, int targetUserId)103 public abstract void grantUriPermissionFromIntent(int callingUid, String targetPkg, 104 Intent intent, int targetUserId); 105 106 /** 107 * Verify that calling app has access to the given provider. 108 */ checkContentProviderAccess(String authority, int userId)109 public abstract String checkContentProviderAccess(String authority, int userId); 110 111 // Called by the power manager. onWakefulnessChanged(int wakefulness)112 public abstract void onWakefulnessChanged(int wakefulness); 113 114 /** 115 * @return {@code true} if process start is successful, {@code false} otherwise. 116 */ startIsolatedProcess(String entryPoint, String[] mainArgs, String processName, String abiOverride, int uid, Runnable crashHandler)117 public abstract boolean startIsolatedProcess(String entryPoint, String[] mainArgs, 118 String processName, String abiOverride, int uid, Runnable crashHandler); 119 120 /** 121 * Acquires a sleep token for the specified display with the specified tag. 122 * 123 * @param tag A string identifying the purpose of the token (eg. "Dream"). 124 * @param displayId The display to apply the sleep token to. 125 */ acquireSleepToken(@onNull String tag, int displayId)126 public abstract SleepToken acquireSleepToken(@NonNull String tag, int displayId); 127 128 /** 129 * Sleep tokens cause the activity manager to put the top activity to sleep. 130 * They are used by components such as dreams that may hide and block interaction 131 * with underlying activities. 132 */ 133 public static abstract class SleepToken { 134 135 /** 136 * Releases the sleep token. 137 */ release()138 public abstract void release(); 139 } 140 141 /** 142 * Returns home activity for the specified user. 143 * 144 * @param userId ID of the user or {@link android.os.UserHandle#USER_ALL} 145 */ getHomeActivityForUser(int userId)146 public abstract ComponentName getHomeActivityForUser(int userId); 147 148 /** 149 * Called when a user has been deleted. This can happen during normal device usage 150 * or just at startup, when partially removed users are purged. Any state persisted by the 151 * ActivityManager should be purged now. 152 * 153 * @param userId The user being cleaned up. 154 */ onUserRemoved(int userId)155 public abstract void onUserRemoved(int userId); 156 onLocalVoiceInteractionStarted(IBinder callingActivity, IVoiceInteractionSession mSession, IVoiceInteractor mInteractor)157 public abstract void onLocalVoiceInteractionStarted(IBinder callingActivity, 158 IVoiceInteractionSession mSession, 159 IVoiceInteractor mInteractor); 160 161 /** 162 * Callback for window manager to let activity manager know that we are finally starting the 163 * app transition; 164 * 165 * @param reasons A map from windowing mode to a reason integer why the transition was started, 166 * which must be one of the APP_TRANSITION_* values. 167 * @param timestamp The time at which the app transition started in 168 * {@link SystemClock#uptimeMillis()} timebase. 169 */ notifyAppTransitionStarting(SparseIntArray reasons, long timestamp)170 public abstract void notifyAppTransitionStarting(SparseIntArray reasons, long timestamp); 171 172 /** 173 * Callback for window manager to let activity manager know that the app transition was 174 * cancelled. 175 */ notifyAppTransitionCancelled()176 public abstract void notifyAppTransitionCancelled(); 177 178 /** 179 * Callback for window manager to let activity manager know that the app transition is finished. 180 */ notifyAppTransitionFinished()181 public abstract void notifyAppTransitionFinished(); 182 183 /** 184 * Returns the top activity from each of the currently visible stacks. The first entry will be 185 * the focused activity. 186 */ getTopVisibleActivities()187 public abstract List<IBinder> getTopVisibleActivities(); 188 189 /** 190 * Callback for window manager to let activity manager know that docked stack changes its 191 * minimized state. 192 */ notifyDockedStackMinimizedChanged(boolean minimized)193 public abstract void notifyDockedStackMinimizedChanged(boolean minimized); 194 195 /** 196 * Kill foreground apps from the specified user. 197 */ killForegroundAppsForUser(int userHandle)198 public abstract void killForegroundAppsForUser(int userHandle); 199 200 /** 201 * Sets how long a {@link PendingIntent} can be temporarily whitelist to by bypass restrictions 202 * such as Power Save mode. 203 */ setPendingIntentWhitelistDuration(IIntentSender target, IBinder whitelistToken, long duration)204 public abstract void setPendingIntentWhitelistDuration(IIntentSender target, 205 IBinder whitelistToken, long duration); 206 207 /** 208 * Allow DeviceIdleController to tell us about what apps are whitelisted. 209 */ setDeviceIdleWhitelist(int[] allAppids, int[] exceptIdleAppids)210 public abstract void setDeviceIdleWhitelist(int[] allAppids, int[] exceptIdleAppids); 211 212 /** 213 * Update information about which app IDs are on the temp whitelist. 214 */ updateDeviceIdleTempWhitelist(int[] appids, int changingAppId, boolean adding)215 public abstract void updateDeviceIdleTempWhitelist(int[] appids, int changingAppId, 216 boolean adding); 217 218 /** 219 * Updates and persists the {@link Configuration} for a given user. 220 * 221 * @param values the configuration to update 222 * @param userId the user to update the configuration for 223 */ updatePersistentConfigurationForUser(@onNull Configuration values, int userId)224 public abstract void updatePersistentConfigurationForUser(@NonNull Configuration values, 225 int userId); 226 227 /** 228 * Start activity {@code intents} as if {@code packageName} on user {@code userId} did it. 229 * 230 * - DO NOT call it with the calling UID cleared. 231 * - All the necessary caller permission checks must be done at callsites. 232 * 233 * @return error codes used by {@link IActivityManager#startActivity} and its siblings. 234 */ startActivitiesAsPackage(String packageName, int userId, Intent[] intents, Bundle bOptions)235 public abstract int startActivitiesAsPackage(String packageName, 236 int userId, Intent[] intents, Bundle bOptions); 237 238 /** 239 * Start activity {@code intent} without calling user-id check. 240 * 241 * - DO NOT call it with the calling UID cleared. 242 * - The caller must do the calling user ID check. 243 * 244 * @return error codes used by {@link IActivityManager#startActivity} and its siblings. 245 */ startActivityAsUser(IApplicationThread caller, String callingPackage, Intent intent, @Nullable Bundle options, int userId)246 public abstract int startActivityAsUser(IApplicationThread caller, String callingPackage, 247 Intent intent, @Nullable Bundle options, int userId); 248 249 /** 250 * Get the procstate for the UID. The return value will be between 251 * {@link ActivityManager#MIN_PROCESS_STATE} and {@link ActivityManager#MAX_PROCESS_STATE}. 252 * Note if the UID doesn't exist, it'll return {@link ActivityManager#PROCESS_STATE_NONEXISTENT} 253 * (-1). 254 */ getUidProcessState(int uid)255 public abstract int getUidProcessState(int uid); 256 257 /** 258 * Called when Keyguard flags might have changed. 259 * 260 * @param callback Callback to run after activity visibilities have been reevaluated. This can 261 * be used from window manager so that when the callback is called, it's 262 * guaranteed that all apps have their visibility updated accordingly. 263 */ notifyKeyguardFlagsChanged(@ullable Runnable callback)264 public abstract void notifyKeyguardFlagsChanged(@Nullable Runnable callback); 265 266 /** 267 * @return {@code true} if system is ready, {@code false} otherwise. 268 */ isSystemReady()269 public abstract boolean isSystemReady(); 270 271 /** 272 * Called when the trusted state of Keyguard has changed. 273 */ notifyKeyguardTrustedChanged()274 public abstract void notifyKeyguardTrustedChanged(); 275 276 /** 277 * Sets if the given pid has an overlay UI or not. 278 * 279 * @param pid The pid we are setting overlay UI for. 280 * @param hasOverlayUi True if the process has overlay UI. 281 * @see android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY 282 */ setHasOverlayUi(int pid, boolean hasOverlayUi)283 public abstract void setHasOverlayUi(int pid, boolean hasOverlayUi); 284 285 /** 286 * Sets if the given pid is currently running a remote animation, which is taken a signal for 287 * determining oom adjustment and scheduling behavior. 288 * 289 * @param pid The pid we are setting overlay UI for. 290 * @param runningRemoteAnimation True if the process is running a remote animation, false 291 * otherwise. 292 * @see RemoteAnimationAdapter 293 */ setRunningRemoteAnimation(int pid, boolean runningRemoteAnimation)294 public abstract void setRunningRemoteAnimation(int pid, boolean runningRemoteAnimation); 295 296 /** 297 * Called after the network policy rules are updated by 298 * {@link com.android.server.net.NetworkPolicyManagerService} for a specific {@param uid} and 299 * {@param procStateSeq}. 300 */ notifyNetworkPolicyRulesUpdated(int uid, long procStateSeq)301 public abstract void notifyNetworkPolicyRulesUpdated(int uid, long procStateSeq); 302 303 /** 304 * Called after the voice interaction service has changed. 305 */ notifyActiveVoiceInteractionServiceChanged(ComponentName component)306 public abstract void notifyActiveVoiceInteractionServiceChanged(ComponentName component); 307 308 /** 309 * Called after virtual display Id is updated by 310 * {@link com.android.server.vr.Vr2dDisplay} with a specific 311 * {@param vr2dDisplayId}. 312 */ setVr2dDisplayId(int vr2dDisplayId)313 public abstract void setVr2dDisplayId(int vr2dDisplayId); 314 315 /** 316 * Saves the current activity manager state and includes the saved state in the next dump of 317 * activity manager. 318 */ saveANRState(String reason)319 public abstract void saveANRState(String reason); 320 321 /** 322 * Clears the previously saved activity manager ANR state. 323 */ clearSavedANRState()324 public abstract void clearSavedANRState(); 325 326 /** 327 * Set focus on an activity. 328 * @param token The IApplicationToken for the activity 329 */ setFocusedActivity(IBinder token)330 public abstract void setFocusedActivity(IBinder token); 331 332 /** 333 * Set a uid that is allowed to bypass stopped app switches, launching an app 334 * whenever it wants. 335 * 336 * @param type Type of the caller -- unique string the caller supplies to identify itself 337 * and disambiguate with other calles. 338 * @param uid The uid of the app to be allowed, or -1 to clear the uid for this type. 339 * @param userId The user it is allowed for. 340 */ setAllowAppSwitches(@onNull String type, int uid, int userId)341 public abstract void setAllowAppSwitches(@NonNull String type, int uid, int userId); 342 343 /** 344 * @return true if runtime was restarted, false if it's normal boot 345 */ isRuntimeRestarted()346 public abstract boolean isRuntimeRestarted(); 347 348 /** 349 * Returns {@code true} if {@code uid} is running an activity from {@code packageName}. 350 */ hasRunningActivity(int uid, @Nullable String packageName)351 public abstract boolean hasRunningActivity(int uid, @Nullable String packageName); 352 353 public interface ScreenObserver { onAwakeStateChanged(boolean isAwake)354 public void onAwakeStateChanged(boolean isAwake); onKeyguardStateChanged(boolean isShowing)355 public void onKeyguardStateChanged(boolean isShowing); 356 } 357 registerScreenObserver(ScreenObserver observer)358 public abstract void registerScreenObserver(ScreenObserver observer); 359 360 /** 361 * Returns if more users can be started without stopping currently running users. 362 */ canStartMoreUsers()363 public abstract boolean canStartMoreUsers(); 364 365 /** 366 * Sets the user switcher message for switching from {@link android.os.UserHandle#SYSTEM}. 367 */ setSwitchingFromSystemUserMessage(String switchingFromSystemUserMessage)368 public abstract void setSwitchingFromSystemUserMessage(String switchingFromSystemUserMessage); 369 370 /** 371 * Sets the user switcher message for switching to {@link android.os.UserHandle#SYSTEM}. 372 */ setSwitchingToSystemUserMessage(String switchingToSystemUserMessage)373 public abstract void setSwitchingToSystemUserMessage(String switchingToSystemUserMessage); 374 375 /** 376 * Returns maximum number of users that can run simultaneously. 377 */ getMaxRunningUsers()378 public abstract int getMaxRunningUsers(); 379 380 /** 381 * Returns is the caller has the same uid as the Recents component 382 */ isCallerRecents(int callingUid)383 public abstract boolean isCallerRecents(int callingUid); 384 385 /** 386 * Returns whether the recents component is the home activity for the given user. 387 */ isRecentsComponentHomeActivity(int userId)388 public abstract boolean isRecentsComponentHomeActivity(int userId); 389 390 /** 391 * Cancels any currently running recents animation. 392 */ cancelRecentsAnimation(boolean restoreHomeStackPosition)393 public abstract void cancelRecentsAnimation(boolean restoreHomeStackPosition); 394 395 /** 396 * Whether an UID is active or idle. 397 */ isUidActive(int uid)398 public abstract boolean isUidActive(int uid); 399 400 /** 401 * Returns a list that contains the memory stats for currently running processes. 402 */ getMemoryStateForProcesses()403 public abstract List<ProcessMemoryState> getMemoryStateForProcesses(); 404 405 /** 406 * This enforces {@code func} can only be called if either the caller is Recents activity or 407 * has {@code permission}. 408 */ enforceCallerIsRecentsOrHasPermission(String permission, String func)409 public abstract void enforceCallerIsRecentsOrHasPermission(String permission, String func); 410 } 411