1 /* 2 * Copyright (C) 2018 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 com.android.server.wm; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.UserIdInt; 22 import android.app.ActivityManager; 23 import android.app.AppProtoEnums; 24 import android.app.BackgroundStartPrivileges; 25 import android.app.IActivityManager; 26 import android.app.IAppTask; 27 import android.app.IApplicationThread; 28 import android.app.ITaskStackListener; 29 import android.app.ProfilerInfo; 30 import android.content.ComponentName; 31 import android.content.IIntentSender; 32 import android.content.Intent; 33 import android.content.pm.ApplicationInfo; 34 import android.content.res.CompatibilityInfo; 35 import android.content.res.Configuration; 36 import android.os.Bundle; 37 import android.os.IBinder; 38 import android.os.LocaleList; 39 import android.os.RemoteException; 40 import android.service.voice.IVoiceInteractionSession; 41 import android.util.IntArray; 42 import android.util.proto.ProtoOutputStream; 43 import android.window.TaskSnapshot; 44 45 import com.android.internal.annotations.VisibleForTesting; 46 import com.android.internal.app.IVoiceInteractor; 47 import com.android.server.am.PendingIntentRecord; 48 import com.android.server.am.UserState; 49 50 import java.io.FileDescriptor; 51 import java.io.PrintWriter; 52 import java.lang.ref.WeakReference; 53 import java.util.List; 54 import java.util.Set; 55 56 /** 57 * Activity Task manager local system service interface. 58 * @hide Only for use within system server 59 */ 60 public abstract class ActivityTaskManagerInternal { 61 62 /** 63 * Type for {@link #notifyAppTransitionStarting}: The transition was started because we drew 64 * the splash screen. 65 */ 66 public static final int APP_TRANSITION_SPLASH_SCREEN = 67 AppProtoEnums.APP_TRANSITION_SPLASH_SCREEN; // 1 68 69 /** 70 * Type for {@link #notifyAppTransitionStarting}: The transition was started because we all 71 * app windows were drawn 72 */ 73 public static final int APP_TRANSITION_WINDOWS_DRAWN = 74 AppProtoEnums.APP_TRANSITION_WINDOWS_DRAWN; // 2 75 76 /** 77 * Type for {@link #notifyAppTransitionStarting}: The transition was started because of a 78 * timeout. 79 */ 80 public static final int APP_TRANSITION_TIMEOUT = 81 AppProtoEnums.APP_TRANSITION_TIMEOUT; // 3 82 83 /** 84 * Type for {@link #notifyAppTransitionStarting}: The transition was started because of a 85 * we drew a task snapshot. 86 */ 87 public static final int APP_TRANSITION_SNAPSHOT = 88 AppProtoEnums.APP_TRANSITION_SNAPSHOT; // 4 89 90 /** 91 * Type for {@link #notifyAppTransitionStarting}: The transition was started because it was a 92 * recents animation and we only needed to wait on the wallpaper. 93 */ 94 public static final int APP_TRANSITION_RECENTS_ANIM = 95 AppProtoEnums.APP_TRANSITION_RECENTS_ANIM; // 5 96 97 /** 98 * The id of the task source of assist state. 99 */ 100 public static final String ASSIST_TASK_ID = "taskId"; 101 102 /** 103 * The id of the activity source of assist state. 104 */ 105 public static final String ASSIST_ACTIVITY_ID = "activityId"; 106 107 /** 108 * The bundle key to extract the assist data. 109 */ 110 public static final String ASSIST_KEY_DATA = "data"; 111 112 /** 113 * The bundle key to extract the assist structure. 114 */ 115 public static final String ASSIST_KEY_STRUCTURE = "structure"; 116 117 /** 118 * The bundle key to extract the assist content. 119 */ 120 public static final String ASSIST_KEY_CONTENT = "content"; 121 122 /** 123 * The bundle key to extract the assist receiver extras. 124 */ 125 public static final String ASSIST_KEY_RECEIVER_EXTRAS = "receiverExtras"; 126 127 public interface ScreenObserver { onAwakeStateChanged(boolean isAwake)128 void onAwakeStateChanged(boolean isAwake); onKeyguardStateChanged(boolean isShowing)129 void onKeyguardStateChanged(boolean isShowing); 130 } 131 132 /** 133 * Sleep tokens cause the activity manager to put the top activity to sleep. 134 * They are used by components such as dreams that may hide and block interaction 135 * with underlying activities. 136 * The Acquirer provides an interface that encapsulates the underlying work, so the user does 137 * not need to handle the token by him/herself. 138 */ 139 public interface SleepTokenAcquirer { 140 141 /** 142 * Acquires a sleep token. 143 * @param displayId The display to apply to. 144 */ acquire(int displayId)145 void acquire(int displayId); 146 147 /** 148 * Acquires a sleep token. 149 * @param displayId The display to apply to. 150 * @param isSwappingDisplay Whether the display is swapping to another physical display. 151 */ acquire(int displayId, boolean isSwappingDisplay)152 void acquire(int displayId, boolean isSwappingDisplay); 153 154 /** 155 * Releases the sleep token. 156 * @param displayId The display to apply to. 157 */ release(int displayId)158 void release(int displayId); 159 } 160 161 /** 162 * Creates a sleep token acquirer for the specified display with the specified tag. 163 * 164 * @param tag A string identifying the purpose (eg. "Dream"). 165 */ createSleepTokenAcquirer(@onNull String tag)166 public abstract SleepTokenAcquirer createSleepTokenAcquirer(@NonNull String tag); 167 168 /** 169 * Returns home activity for the specified user. 170 * 171 * @param userId ID of the user or {@link android.os.UserHandle#USER_ALL} 172 */ getHomeActivityForUser(int userId)173 public abstract ComponentName getHomeActivityForUser(int userId); 174 onLocalVoiceInteractionStarted(IBinder callingActivity, IVoiceInteractionSession mSession, IVoiceInteractor mInteractor)175 public abstract void onLocalVoiceInteractionStarted(IBinder callingActivity, 176 IVoiceInteractionSession mSession, 177 IVoiceInteractor mInteractor); 178 179 /** 180 * Returns the top activity from each of the currently visible root tasks, and the related task 181 * id. The first entry will be the focused activity. 182 * 183 * <p>NOTE: If the top activity is in the split screen, the other activities in the same split 184 * screen will also be returned. 185 */ getTopVisibleActivities()186 public abstract List<ActivityAssistInfo> getTopVisibleActivities(); 187 188 /** 189 * Returns whether {@code uid} has any resumed activity. 190 */ hasResumedActivity(int uid)191 public abstract boolean hasResumedActivity(int uid); 192 193 /** 194 * Start activity {@code intents} as if {@code packageName/featureId} on user {@code userId} did 195 * it. 196 * 197 * - DO NOT call it with the calling UID cleared. 198 * - All the necessary caller permission checks must be done at callsites. 199 * 200 * @return error codes used by {@link IActivityManager#startActivity} and its siblings. 201 */ startActivitiesAsPackage(String packageName, String featureId, int userId, Intent[] intents, Bundle bOptions)202 public abstract int startActivitiesAsPackage(String packageName, String featureId, 203 int userId, Intent[] intents, Bundle bOptions); 204 205 /** 206 * Start intents as a package. 207 * 208 * @param uid Make a call as if this UID did. 209 * @param realCallingPid PID of the real caller. 210 * @param realCallingUid UID of the real caller. 211 * @param callingPackage Make a call as if this package did. 212 * @param callingFeatureId Make a call as if this feature in the package did. 213 * @param intents Intents to start. 214 * @param userId Start the intents on this user. 215 * @param validateIncomingUser Set true to skip checking {@code userId} with the calling UID. 216 * @param originatingPendingIntent PendingIntentRecord that originated this activity start or 217 * null if not originated by PendingIntent 218 * @param forcedBalByPiSender If set to allow, the 219 * PendingIntent's sender will try to force allow background activity starts. 220 * This is only possible if the sender of the PendingIntent is a system process. 221 */ startActivitiesInPackage(int uid, int realCallingPid, int realCallingUid, String callingPackage, @Nullable String callingFeatureId, Intent[] intents, String[] resolvedTypes, IBinder resultTo, SafeActivityOptions options, int userId, boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, BackgroundStartPrivileges forcedBalByPiSender)222 public abstract int startActivitiesInPackage(int uid, int realCallingPid, int realCallingUid, 223 String callingPackage, @Nullable String callingFeatureId, Intent[] intents, 224 String[] resolvedTypes, IBinder resultTo, SafeActivityOptions options, int userId, 225 boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, 226 BackgroundStartPrivileges forcedBalByPiSender); 227 228 /** 229 * Start intent as a package. 230 * 231 * @param uid Make a call as if this UID did. 232 * @param realCallingPid PID of the real caller. 233 * @param realCallingUid UID of the real caller. 234 * @param callingPackage Make a call as if this package did. 235 * @param callingFeatureId Make a call as if this feature in the package did. 236 * @param intent Intent to start. 237 * @param userId Start the intents on this user. 238 * @param validateIncomingUser Set true to skip checking {@code userId} with the calling UID. 239 * @param originatingPendingIntent PendingIntentRecord that originated this activity start or 240 * null if not originated by PendingIntent 241 * @param forcedBalByPiSender If set to allow, the 242 * PendingIntent's sender will try to force allow background activity starts. 243 * This is only possible if the sender of the PendingIntent is a system process. 244 */ startActivityInPackage(int uid, int realCallingPid, int realCallingUid, String callingPackage, @Nullable String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, int startFlags, SafeActivityOptions options, int userId, Task inTask, String reason, boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, BackgroundStartPrivileges forcedBalByPiSender)245 public abstract int startActivityInPackage(int uid, int realCallingPid, int realCallingUid, 246 String callingPackage, @Nullable String callingFeatureId, Intent intent, 247 String resolvedType, IBinder resultTo, String resultWho, int requestCode, 248 int startFlags, SafeActivityOptions options, int userId, Task inTask, String reason, 249 boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, 250 BackgroundStartPrivileges forcedBalByPiSender); 251 252 /** 253 * Callback to be called on certain activity start scenarios. 254 * 255 * @see BackgroundActivityStartCallback 256 */ setBackgroundActivityStartCallback( @ullable BackgroundActivityStartCallback callback)257 public abstract void setBackgroundActivityStartCallback( 258 @Nullable BackgroundActivityStartCallback callback); 259 260 /** 261 * Sets the list of UIDs that contain an active accessibility service. 262 */ setAccessibilityServiceUids(IntArray uids)263 public abstract void setAccessibilityServiceUids(IntArray uids); 264 265 /** 266 * Start activity {@code intent} without calling user-id check. 267 * 268 * - DO NOT call it with the calling UID cleared. 269 * - The caller must do the calling user ID check. 270 * 271 * @return error codes used by {@link IActivityManager#startActivity} and its siblings. 272 */ startActivityAsUser(IApplicationThread caller, String callingPackage, @Nullable String callingFeatureId, Intent intent, @Nullable IBinder resultTo, int startFlags, @Nullable Bundle options, int userId)273 public abstract int startActivityAsUser(IApplicationThread caller, String callingPackage, 274 @Nullable String callingFeatureId, Intent intent, @Nullable IBinder resultTo, 275 int startFlags, @Nullable Bundle options, int userId); 276 277 /** 278 * Start activity {@code intent} with initially under screenshot. The screen of launching 279 * display will be frozen before transition occur. 280 * 281 * - DO NOT call it with the calling UID cleared. 282 * - The caller must do the calling user ID check. 283 * 284 * @return error codes used by {@link IActivityManager#startActivity} and its siblings. 285 */ startActivityWithScreenshot(@onNull Intent intent, @NonNull String callingPackage, int callingUid, int callingPid, @Nullable IBinder resultTo, @Nullable Bundle options, int userId)286 public abstract int startActivityWithScreenshot(@NonNull Intent intent, 287 @NonNull String callingPackage, int callingUid, int callingPid, 288 @Nullable IBinder resultTo, @Nullable Bundle options, int userId); 289 290 /** 291 * Called after virtual display Id is updated by 292 * {@link com.android.server.vr.Vr2dDisplay} with a specific 293 * {@param vr2dDisplayId}. 294 */ setVr2dDisplayId(int vr2dDisplayId)295 public abstract void setVr2dDisplayId(int vr2dDisplayId); 296 297 /** 298 * Registers a {@link ScreenObserver}. 299 */ registerScreenObserver(ScreenObserver observer)300 public abstract void registerScreenObserver(ScreenObserver observer); 301 302 /** 303 * Unregisters the given {@link ScreenObserver}. 304 */ unregisterScreenObserver(ScreenObserver observer)305 public abstract void unregisterScreenObserver(ScreenObserver observer); 306 307 /** 308 * Returns is the caller has the same uid as the Recents component 309 */ isCallerRecents(int callingUid)310 public abstract boolean isCallerRecents(int callingUid); 311 312 /** 313 * Returns whether the recents component is the home activity for the given user. 314 */ isRecentsComponentHomeActivity(int userId)315 public abstract boolean isRecentsComponentHomeActivity(int userId); 316 317 /** 318 * Returns true if the app can close system dialogs. Otherwise it either throws a {@link 319 * SecurityException} or returns false with a logcat message depending on whether the app 320 * targets SDK level {@link android.os.Build.VERSION_CODES#S} or not. 321 */ checkCanCloseSystemDialogs(int pid, int uid, @Nullable String packageName)322 public abstract boolean checkCanCloseSystemDialogs(int pid, int uid, 323 @Nullable String packageName); 324 325 /** 326 * Returns whether the app can close system dialogs or not. 327 */ canCloseSystemDialogs(int pid, int uid)328 public abstract boolean canCloseSystemDialogs(int pid, int uid); 329 330 /** 331 * Called after the voice interaction service has changed. 332 */ notifyActiveVoiceInteractionServiceChanged(ComponentName component)333 public abstract void notifyActiveVoiceInteractionServiceChanged(ComponentName component); 334 335 /** 336 * Called when the device changes its dreaming state. 337 * 338 * @param activeDreamComponent The currently active dream. If null, the device is not dreaming. 339 */ notifyActiveDreamChanged(@ullable ComponentName activeDreamComponent)340 public abstract void notifyActiveDreamChanged(@Nullable ComponentName activeDreamComponent); 341 342 /** 343 * Starts a dream activity in the DreamService's process. 344 */ startDreamActivity(@onNull Intent intent, int callingUid, int callingPid)345 public abstract IAppTask startDreamActivity(@NonNull Intent intent, int callingUid, 346 int callingPid); 347 348 /** 349 * Set a uid that is allowed to bypass stopped app switches, launching an app 350 * whenever it wants. 351 * 352 * @param type Type of the caller -- unique string the caller supplies to identify itself 353 * and disambiguate with other calles. 354 * @param uid The uid of the app to be allowed, or -1 to clear the uid for this type. 355 * @param userId The user it is allowed for. 356 */ setAllowAppSwitches(@onNull String type, int uid, int userId)357 public abstract void setAllowAppSwitches(@NonNull String type, int uid, int userId); 358 359 /** 360 * Called when a user has been stopped. 361 * 362 * @param userId The user being stopped. 363 */ onUserStopped(int userId)364 public abstract void onUserStopped(int userId); isGetTasksAllowed(String caller, int callingPid, int callingUid)365 public abstract boolean isGetTasksAllowed(String caller, int callingPid, int callingUid); 366 onProcessAdded(WindowProcessController proc)367 public abstract void onProcessAdded(WindowProcessController proc); onProcessRemoved(String name, int uid)368 public abstract void onProcessRemoved(String name, int uid); onCleanUpApplicationRecord(WindowProcessController proc)369 public abstract void onCleanUpApplicationRecord(WindowProcessController proc); getTopProcessState()370 public abstract int getTopProcessState(); useTopSchedGroupForTopProcess()371 public abstract boolean useTopSchedGroupForTopProcess(); clearHeavyWeightProcessIfEquals(WindowProcessController proc)372 public abstract void clearHeavyWeightProcessIfEquals(WindowProcessController proc); finishHeavyWeightApp()373 public abstract void finishHeavyWeightApp(); 374 isSleeping()375 public abstract boolean isSleeping(); isShuttingDown()376 public abstract boolean isShuttingDown(); shuttingDown(boolean booted, int timeout)377 public abstract boolean shuttingDown(boolean booted, int timeout); enableScreenAfterBoot(boolean booted)378 public abstract void enableScreenAfterBoot(boolean booted); showStrictModeViolationDialog()379 public abstract boolean showStrictModeViolationDialog(); showSystemReadyErrorDialogsIfNeeded()380 public abstract void showSystemReadyErrorDialogsIfNeeded(); 381 onProcessMapped(int pid, WindowProcessController proc)382 public abstract void onProcessMapped(int pid, WindowProcessController proc); onProcessUnMapped(int pid)383 public abstract void onProcessUnMapped(int pid); 384 onPackageDataCleared(String name, int userId)385 public abstract void onPackageDataCleared(String name, int userId); onPackageUninstalled(String name, int userId)386 public abstract void onPackageUninstalled(String name, int userId); onPackageAdded(String name, boolean replacing)387 public abstract void onPackageAdded(String name, boolean replacing); onPackageReplaced(ApplicationInfo aInfo)388 public abstract void onPackageReplaced(ApplicationInfo aInfo); 389 compatibilityInfoForPackage(ApplicationInfo ai)390 public abstract CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai); 391 392 public final class ActivityTokens { 393 private final @NonNull IBinder mActivityToken; 394 private final @NonNull IBinder mAssistToken; 395 private final @NonNull IBinder mShareableActivityToken; 396 private final @NonNull IApplicationThread mAppThread; 397 private final int mUid; 398 ActivityTokens(@onNull IBinder activityToken, @NonNull IBinder assistToken, @NonNull IApplicationThread appThread, @NonNull IBinder shareableActivityToken, int uid)399 public ActivityTokens(@NonNull IBinder activityToken, 400 @NonNull IBinder assistToken, @NonNull IApplicationThread appThread, 401 @NonNull IBinder shareableActivityToken, int uid) { 402 mActivityToken = activityToken; 403 mAssistToken = assistToken; 404 mAppThread = appThread; 405 mShareableActivityToken = shareableActivityToken; 406 mUid = uid; 407 } 408 409 /** 410 * @return The activity token. 411 */ getActivityToken()412 public @NonNull IBinder getActivityToken() { 413 return mActivityToken; 414 } 415 416 /** 417 * @return The assist token. 418 */ getAssistToken()419 public @NonNull IBinder getAssistToken() { 420 return mAssistToken; 421 } 422 423 /** 424 * @return The sharable activity token.. 425 */ getShareableActivityToken()426 public @NonNull IBinder getShareableActivityToken() { 427 return mShareableActivityToken; 428 } 429 430 /** 431 * @return The assist token. 432 */ getApplicationThread()433 public @NonNull IApplicationThread getApplicationThread() { 434 return mAppThread; 435 } 436 437 /** 438 * @return The UID of the activity 439 */ getUid()440 public int getUid() { 441 return mUid; 442 } 443 } 444 sendActivityResult(int callingUid, IBinder activityToken, String resultWho, int requestCode, int resultCode, Intent data)445 public abstract void sendActivityResult(int callingUid, IBinder activityToken, 446 String resultWho, int requestCode, int resultCode, Intent data); clearPendingResultForActivity( IBinder activityToken, WeakReference<PendingIntentRecord> pir)447 public abstract void clearPendingResultForActivity( 448 IBinder activityToken, WeakReference<PendingIntentRecord> pir); 449 450 /** Returns the component name of the activity token. */ 451 @Nullable getActivityName(IBinder activityToken)452 public abstract ComponentName getActivityName(IBinder activityToken); 453 454 /** 455 * Returns non-finishing Activity that have a process attached for the given task and the token 456 * with the activity token and the IApplicationThread or null if there is no Activity with a 457 * valid process. Given the null token for the task will return the top Activity in the task. 458 * 459 * @param taskId the Activity task id. 460 * @param token the Activity token, set null if get top Activity for the given task id. 461 */ 462 @Nullable getAttachedNonFinishingActivityForTask(int taskId, IBinder token)463 public abstract ActivityTokens getAttachedNonFinishingActivityForTask(int taskId, 464 IBinder token); 465 getIntentSender(int type, String packageName, @Nullable String featureId, int callingUid, int userId, IBinder token, String resultWho, int requestCode, Intent[] intents, String[] resolvedTypes, int flags, Bundle bOptions)466 public abstract IIntentSender getIntentSender(int type, String packageName, 467 @Nullable String featureId, int callingUid, int userId, IBinder token, String resultWho, 468 int requestCode, Intent[] intents, String[] resolvedTypes, int flags, 469 Bundle bOptions); 470 471 /** @return the service connection holder for a given activity token. */ getServiceConnectionsHolder(IBinder token)472 public abstract ActivityServiceConnectionsHolder getServiceConnectionsHolder(IBinder token); 473 474 /** @return The intent used to launch the home activity. */ getHomeIntent()475 public abstract Intent getHomeIntent(); startHomeActivity(int userId, String reason)476 public abstract boolean startHomeActivity(int userId, String reason); 477 /** 478 * This starts home activity on displays that can have system decorations based on displayId - 479 * Default display always use primary home component. 480 * For Secondary displays, the home activity must have category SECONDARY_HOME and then resolves 481 * according to the priorities listed below. 482 * - If default home is not set, always use the secondary home defined in the config. 483 * - Use currently selected primary home activity. 484 * - Use the activity in the same package as currently selected primary home activity. 485 * If there are multiple activities matched, use first one. 486 * - Use the secondary home defined in the config. 487 */ startHomeOnDisplay(int userId, String reason, int displayId, boolean allowInstrumenting, boolean fromHomeKey)488 public abstract boolean startHomeOnDisplay(int userId, String reason, int displayId, 489 boolean allowInstrumenting, boolean fromHomeKey); 490 /** Start home activities on all displays that support system decorations. */ startHomeOnAllDisplays(int userId, String reason)491 public abstract boolean startHomeOnAllDisplays(int userId, String reason); updateTopComponentForFactoryTest()492 public abstract void updateTopComponentForFactoryTest(); handleAppDied(WindowProcessController wpc, boolean restarting, Runnable finishInstrumentationCallback)493 public abstract void handleAppDied(WindowProcessController wpc, boolean restarting, 494 Runnable finishInstrumentationCallback); closeSystemDialogs(String reason)495 public abstract void closeSystemDialogs(String reason); 496 497 /** Removes all components (e.g. activities, recents, ...) belonging to a disabled package. */ cleanupDisabledPackageComponents( String packageName, Set<String> disabledClasses, int userId, boolean booted)498 public abstract void cleanupDisabledPackageComponents( 499 String packageName, Set<String> disabledClasses, int userId, boolean booted); 500 501 /** Called whenever AM force stops a package. */ onForceStopPackage(String packageName, boolean doit, boolean evenPersistent, int userId)502 public abstract boolean onForceStopPackage(String packageName, boolean doit, 503 boolean evenPersistent, int userId); 504 /** 505 * Resumes all top activities in the system if they aren't resumed already. 506 * @param scheduleIdle If the idle message should be schedule after the top activities are 507 * resumed. 508 */ resumeTopActivities(boolean scheduleIdle)509 public abstract void resumeTopActivities(boolean scheduleIdle); 510 511 /** Called by AM just before it binds to an application process. */ preBindApplication(WindowProcessController wpc)512 public abstract void preBindApplication(WindowProcessController wpc); 513 514 /** Called by AM when an application process attaches. */ attachApplication(WindowProcessController wpc)515 public abstract boolean attachApplication(WindowProcessController wpc) throws RemoteException; 516 517 /** @see IActivityManager#notifyLockedProfile(int) */ notifyLockedProfile(@serIdInt int userId)518 public abstract void notifyLockedProfile(@UserIdInt int userId); 519 520 /** @see IActivityManager#startConfirmDeviceCredentialIntent(Intent, Bundle) */ startConfirmDeviceCredentialIntent(Intent intent, Bundle options)521 public abstract void startConfirmDeviceCredentialIntent(Intent intent, Bundle options); 522 523 /** Writes current activity states to the proto stream. */ writeActivitiesToProto(ProtoOutputStream proto)524 public abstract void writeActivitiesToProto(ProtoOutputStream proto); 525 526 /** Dump the current state based on the command and filters. */ dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args, int opti, boolean dumpAll, boolean dumpClient, String dumpPackage, int displayIdFilter)527 public abstract void dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args, 528 int opti, boolean dumpAll, boolean dumpClient, String dumpPackage, 529 int displayIdFilter); 530 531 /** Dump the current state for inclusion in process dump. */ dumpForProcesses(FileDescriptor fd, PrintWriter pw, boolean dumpAll, String dumpPackage, int dumpAppId, boolean needSep, boolean testPssMode, int wakefulness)532 public abstract boolean dumpForProcesses(FileDescriptor fd, PrintWriter pw, boolean dumpAll, 533 String dumpPackage, int dumpAppId, boolean needSep, boolean testPssMode, 534 int wakefulness); 535 536 /** Writes the current window process states to the proto stream. */ writeProcessesToProto(ProtoOutputStream proto, String dumpPackage, int wakeFullness, boolean testPssMode)537 public abstract void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage, 538 int wakeFullness, boolean testPssMode); 539 540 /** Dump the current activities state. */ dumpActivity(FileDescriptor fd, PrintWriter pw, String name, String[] args, int opti, boolean dumpAll, boolean dumpVisibleRootTasksOnly, boolean dumpFocusedRootTaskOnly, int displayIdFilter, @UserIdInt int userId)541 public abstract boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, 542 String[] args, int opti, boolean dumpAll, boolean dumpVisibleRootTasksOnly, 543 boolean dumpFocusedRootTaskOnly, int displayIdFilter, @UserIdInt int userId); 544 545 /** Dump the current state for inclusion in oom dump. */ dumpForOom(PrintWriter pw)546 public abstract void dumpForOom(PrintWriter pw); 547 548 /** @return true if it the activity management system is okay with GC running now. */ canGcNow()549 public abstract boolean canGcNow(); 550 551 /** @return the process for the top-most resumed activity in the system. */ getTopApp()552 public abstract WindowProcessController getTopApp(); 553 554 /** Destroy all activities. */ scheduleDestroyAllActivities(String reason)555 public abstract void scheduleDestroyAllActivities(String reason); 556 557 /** Remove user association with activities. */ removeUser(int userId)558 public abstract void removeUser(int userId); 559 560 /** Switch current focused user for activities. */ switchUser(int userId, UserState userState)561 public abstract boolean switchUser(int userId, UserState userState); 562 563 /** Called whenever an app crashes. */ onHandleAppCrash(WindowProcessController wpc)564 public abstract void onHandleAppCrash(WindowProcessController wpc); 565 566 /** 567 * Finish the topmost activities in all stacks that belong to the crashed app. 568 * @param crashedApp The app that crashed. 569 * @param reason Reason to perform this action. 570 * @return The task id that was finished in this stack, or INVALID_TASK_ID if none was finished. 571 */ finishTopCrashedActivities( WindowProcessController crashedApp, String reason)572 public abstract int finishTopCrashedActivities( 573 WindowProcessController crashedApp, String reason); 574 onUidActive(int uid, int procState)575 public abstract void onUidActive(int uid, int procState); onUidInactive(int uid)576 public abstract void onUidInactive(int uid); onUidProcStateChanged(int uid, int procState)577 public abstract void onUidProcStateChanged(int uid, int procState); 578 579 /** Handle app crash event in {@link android.app.IActivityController} if there is one. */ handleAppCrashInActivityController(String processName, int pid, String shortMsg, String longMsg, long timeMillis, String stackTrace, Runnable killCrashingAppCallback)580 public abstract boolean handleAppCrashInActivityController(String processName, int pid, 581 String shortMsg, String longMsg, long timeMillis, String stackTrace, 582 Runnable killCrashingAppCallback); 583 removeRecentTasksByPackageName(String packageName, int userId)584 public abstract void removeRecentTasksByPackageName(String packageName, int userId); cleanupRecentTasksForUser(int userId)585 public abstract void cleanupRecentTasksForUser(int userId); loadRecentTasksForUser(int userId)586 public abstract void loadRecentTasksForUser(int userId); onPackagesSuspendedChanged(String[] packages, boolean suspended, int userId)587 public abstract void onPackagesSuspendedChanged(String[] packages, boolean suspended, 588 int userId); 589 /** Flush recent tasks to disk. */ flushRecentTasks()590 public abstract void flushRecentTasks(); 591 clearLockedTasks(String reason)592 public abstract void clearLockedTasks(String reason); updateUserConfiguration()593 public abstract void updateUserConfiguration(); canShowErrorDialogs()594 public abstract boolean canShowErrorDialogs(); 595 setProfileApp(String profileApp)596 public abstract void setProfileApp(String profileApp); setProfileProc(WindowProcessController wpc)597 public abstract void setProfileProc(WindowProcessController wpc); setProfilerInfo(ProfilerInfo profilerInfo)598 public abstract void setProfilerInfo(ProfilerInfo profilerInfo); 599 getLaunchObserverRegistry()600 public abstract ActivityMetricsLaunchObserverRegistry getLaunchObserverRegistry(); 601 602 /** 603 * Returns the URI permission owner associated with the given activity (see 604 * {@link ActivityRecord#getUriPermissionsLocked()}). If the passed-in activity token is 605 * invalid, returns null. 606 */ 607 @Nullable getUriPermissionOwnerForActivity(@onNull IBinder activityToken)608 public abstract IBinder getUriPermissionOwnerForActivity(@NonNull IBinder activityToken); 609 610 /** 611 * Gets bitmap snapshot of the provided task id. 612 * 613 * <p>Warning! this may restore the snapshot from disk so can block, don't call in a latency 614 * sensitive environment. 615 */ getTaskSnapshotBlocking(int taskId, boolean isLowResolution)616 public abstract TaskSnapshot getTaskSnapshotBlocking(int taskId, 617 boolean isLowResolution); 618 619 /** Returns true if uid is considered foreground for activity start purposes. */ isUidForeground(int uid)620 public abstract boolean isUidForeground(int uid); 621 622 /** 623 * Called by DevicePolicyManagerService to set the uid of the device owner. 624 */ setDeviceOwnerUid(int uid)625 public abstract void setDeviceOwnerUid(int uid); 626 627 /** 628 * Called by DevicePolicyManagerService to set the uids of the profile owners. 629 */ setProfileOwnerUids(Set<Integer> uids)630 public abstract void setProfileOwnerUids(Set<Integer> uids); 631 632 /** 633 * Set all associated companion app that belongs to a userId. 634 * @param userId 635 * @param companionAppUids ActivityTaskManager will take ownership of this Set, the caller 636 * shouldn't touch the Set after calling this interface. 637 */ setCompanionAppUids(int userId, Set<Integer> companionAppUids)638 public abstract void setCompanionAppUids(int userId, Set<Integer> companionAppUids); 639 640 /** 641 * @param packageName The package to check 642 * @return Whether the package is the base of any locked task 643 */ isBaseOfLockedTask(String packageName)644 public abstract boolean isBaseOfLockedTask(String packageName); 645 646 /** 647 * Creates an interface to update configuration for the calling application. 648 */ createPackageConfigurationUpdater()649 public abstract PackageConfigurationUpdater createPackageConfigurationUpdater(); 650 651 /** 652 * Creates an interface to update configuration for an arbitrary application specified by it's 653 * packageName and userId. 654 */ createPackageConfigurationUpdater( String packageName, int userId)655 public abstract PackageConfigurationUpdater createPackageConfigurationUpdater( 656 String packageName, int userId); 657 658 /** 659 * Retrieves and returns the app-specific configuration for an arbitrary application specified 660 * by its packageName and userId. Returns null if no app-specific configuration has been set. 661 */ 662 @Nullable getApplicationConfig(String packageName, int userId)663 public abstract PackageConfig getApplicationConfig(String packageName, 664 int userId); 665 666 /** 667 * Holds app-specific configurations. 668 */ 669 public static class PackageConfig { 670 /** 671 * nightMode for the application, null if app-specific nightMode is not set. 672 */ 673 @Nullable 674 public final Integer mNightMode; 675 676 /** 677 * {@link LocaleList} for the application, null if app-specific locales are not set. 678 */ 679 @Nullable 680 public final LocaleList mLocales; 681 682 /** 683 * Gender for the application, null if app-specific grammatical gender is not set. 684 */ 685 @Nullable 686 public final @Configuration.GrammaticalGender 687 Integer mGrammaticalGender; 688 689 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) PackageConfig(Integer nightMode, LocaleList locales, @Configuration.GrammaticalGender Integer grammaticalGender)690 public PackageConfig(Integer nightMode, LocaleList locales, 691 @Configuration.GrammaticalGender Integer grammaticalGender) { 692 mNightMode = nightMode; 693 mLocales = locales; 694 mGrammaticalGender = grammaticalGender; 695 } 696 697 /** 698 * Returns the string representation of the app-specific configuration. 699 */ 700 @Override toString()701 public String toString() { 702 return "PackageConfig: nightMode " + mNightMode + " locales " + mLocales; 703 } 704 } 705 706 /** 707 * An interface to update configuration for an application, and will persist override 708 * configuration for this package. 709 */ 710 public interface PackageConfigurationUpdater { 711 /** 712 * Sets the dark mode for the current application. This setting is persisted and will 713 * override the system configuration for this application. 714 */ setNightMode(int nightMode)715 PackageConfigurationUpdater setNightMode(int nightMode); 716 717 /** 718 * Sets the app-specific locales for the application referenced by this updater. 719 * This setting is persisted and will overlay on top of the system locales for 720 * the said application. 721 * @return the current {@link PackageConfigurationUpdater} updated with the provided locale. 722 * 723 * <p>NOTE: This method should not be called by clients directly to set app locales, 724 * instead use the {@link LocaleManagerService#setApplicationLocales} 725 */ setLocales(LocaleList locales)726 PackageConfigurationUpdater setLocales(LocaleList locales); 727 728 /** 729 * Sets the gender for the current application. This setting is persisted and will 730 * override the system configuration for this application. 731 */ setGrammaticalGender( @onfiguration.GrammaticalGender int gender)732 PackageConfigurationUpdater setGrammaticalGender( 733 @Configuration.GrammaticalGender int gender); 734 735 /** 736 * Commit changes. 737 * @return true if the configuration changes were persisted, 738 * false if there were no changes, or if erroneous inputs were provided, such as: 739 * <ui> 740 * <li>Invalid packageName</li> 741 * <li>Invalid userId</li> 742 * <li>no WindowProcessController found for the package</li> 743 * </ui> 744 */ commit()745 boolean commit(); 746 } 747 748 /** 749 * A utility method to check AppOps and PackageManager for SYSTEM_ALERT_WINDOW permission. 750 */ hasSystemAlertWindowPermission(int callingUid, int callingPid, String callingPackage)751 public abstract boolean hasSystemAlertWindowPermission(int callingUid, int callingPid, 752 String callingPackage); 753 754 /** 755 * Registers a callback which can intercept activity starts. 756 * @throws IllegalArgumentException if duplicate ids are provided or the provided {@code 757 * callback} is null 758 * @see ActivityInterceptorCallbackRegistry 759 * #registerActivityInterceptorCallback(int, ActivityInterceptorCallback) 760 */ registerActivityStartInterceptor( @ctivityInterceptorCallback.OrderedId int id, ActivityInterceptorCallback callback)761 public abstract void registerActivityStartInterceptor( 762 @ActivityInterceptorCallback.OrderedId int id, 763 ActivityInterceptorCallback callback); 764 765 /** 766 * Unregisters an {@link ActivityInterceptorCallback}. 767 * @throws IllegalArgumentException if id is not registered 768 * @see ActivityInterceptorCallbackRegistry#unregisterActivityInterceptorCallback(int) 769 */ unregisterActivityStartInterceptor( @ctivityInterceptorCallback.OrderedId int id)770 public abstract void unregisterActivityStartInterceptor( 771 @ActivityInterceptorCallback.OrderedId int id); 772 773 /** Get the most recent task excluding the first running task (the one on the front most). */ getMostRecentTaskFromBackground()774 public abstract ActivityManager.RecentTaskInfo getMostRecentTaskFromBackground(); 775 776 /** Get the app tasks for a package */ getAppTasks(String pkgName, int uid)777 public abstract List<ActivityManager.AppTask> getAppTasks(String pkgName, int uid); 778 779 /** 780 * Determine if there exists a task which meets the criteria set by the PermissionPolicyService 781 * to show a system-owned permission dialog over, for a given package 782 * @see PermissionPolicyInternal.shouldShowNotificationDialogForTask 783 * 784 * @param pkgName The package whose activity must be top 785 * @param uid The uid that must have a top activity 786 * @return a task ID if a valid task ID is found. Otherwise, return INVALID_TASK_ID 787 */ getTaskToShowPermissionDialogOn(String pkgName, int uid)788 public abstract int getTaskToShowPermissionDialogOn(String pkgName, int uid); 789 790 /** 791 * Attempts to restart the process associated with the top most Activity associated with the 792 * given {@code packageName} in the task associated with the given {@code taskId}. 793 * 794 * This will request the process of the activity to restart with its saved state (via 795 * {@link android.app.Activity#onSaveInstanceState(Bundle)}) if possible. If the activity is in 796 * background the process will be killed keeping its record. 797 */ restartTaskActivityProcessIfVisible( int taskId, @NonNull String packageName)798 public abstract void restartTaskActivityProcessIfVisible( 799 int taskId, @NonNull String packageName); 800 801 /** Sets the task stack listener that gets callbacks when a task stack changes. */ registerTaskStackListener(ITaskStackListener listener)802 public abstract void registerTaskStackListener(ITaskStackListener listener); 803 804 /** Unregister a task stack listener so that it stops receiving callbacks. */; unregisterTaskStackListener(ITaskStackListener listener)805 public abstract void unregisterTaskStackListener(ITaskStackListener listener); 806 807 /** 808 * Gets the id of the display the activity was launched on. 809 * @param token The activity token. 810 */ getDisplayId(IBinder token)811 public abstract int getDisplayId(IBinder token); 812 813 /** 814 * Register a {@link CompatScaleProvider}. 815 */ registerCompatScaleProvider( @ompatScaleProvider.CompatScaleModeOrderId int id, @NonNull CompatScaleProvider provider)816 public abstract void registerCompatScaleProvider( 817 @CompatScaleProvider.CompatScaleModeOrderId int id, 818 @NonNull CompatScaleProvider provider); 819 820 /** 821 * Unregister a {@link CompatScaleProvider}. 822 */ unregisterCompatScaleProvider( @ompatScaleProvider.CompatScaleModeOrderId int id)823 public abstract void unregisterCompatScaleProvider( 824 @CompatScaleProvider.CompatScaleModeOrderId int id); 825 826 /** Returns whether assist data is allowed. */ isAssistDataAllowed()827 public abstract boolean isAssistDataAllowed(); 828 } 829