Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 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 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 18 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 19 | import static android.Manifest.permission.BIND_VOICE_INTERACTION; |
| 20 | import static android.Manifest.permission.CHANGE_CONFIGURATION; |
| 21 | import static android.Manifest.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS; |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 22 | import static android.Manifest.permission.INTERACT_ACROSS_USERS; |
| 23 | import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 24 | import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 25 | import static android.Manifest.permission.MANAGE_ACTIVITY_STACKS; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 26 | import static android.Manifest.permission.READ_FRAME_BUFFER; |
| 27 | import static android.Manifest.permission.REMOVE_TASKS; |
| 28 | import static android.Manifest.permission.START_TASKS_FROM_RECENTS; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 29 | import static android.Manifest.permission.STOP_APP_SWITCHES; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 30 | import static android.app.ActivityManager.LOCK_TASK_MODE_NONE; |
Jonathan Scott | 9233534 | 2019-12-17 14:46:26 +0000 | [diff] [blame] | 31 | import static android.app.ActivityManagerInternal.ALLOW_NON_FULL; |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 32 | import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 33 | import static android.app.ActivityTaskManager.RESIZE_MODE_PRESERVE_WINDOW; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 34 | import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT; |
| 35 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 36 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 37 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 38 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 39 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
| 40 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 41 | import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 42 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 43 | import static android.content.pm.ApplicationInfo.FLAG_FACTORY_TEST; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 44 | import static android.content.pm.ConfigurationInfo.GL_ES_VERSION_UNDEFINED; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 45 | import static android.content.pm.PackageManager.FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS; |
| 46 | import static android.content.pm.PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 47 | import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 48 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 49 | import static android.os.FactoryTest.FACTORY_TEST_HIGH_LEVEL; |
| 50 | import static android.os.FactoryTest.FACTORY_TEST_LOW_LEVEL; |
| 51 | import static android.os.FactoryTest.FACTORY_TEST_OFF; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 52 | import static android.os.Process.FIRST_APPLICATION_UID; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 53 | import static android.os.Process.SYSTEM_UID; |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 54 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 55 | import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 56 | import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_SIZECOMPAT_FREEFORM; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 57 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES; |
| 58 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RTL; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 59 | import static android.provider.Settings.Global.HIDE_ERROR_DIALOGS; |
| 60 | import static android.provider.Settings.System.FONT_SCALE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 61 | import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_APPLICATION; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 62 | import static android.text.format.DateUtils.MINUTE_IN_MILLIS; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 63 | import static android.view.Display.DEFAULT_DISPLAY; |
| 64 | import static android.view.Display.INVALID_DISPLAY; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 65 | import static android.view.WindowManager.TRANSIT_NONE; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 66 | |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 67 | import static com.android.server.am.ActivityManagerService.ANR_TRACE_DIR; |
| 68 | import static com.android.server.am.ActivityManagerService.MY_PID; |
| 69 | import static com.android.server.am.ActivityManagerService.STOCK_PM_FLAGS; |
| 70 | import static com.android.server.am.ActivityManagerService.dumpStackTraces; |
Wale Ogunwale | f342f06 | 2020-01-27 07:34:13 -0800 | [diff] [blame] | 71 | import static com.android.server.am.ActivityManagerServiceDumpActivitiesProto.ROOT_WINDOW_CONTAINER; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 72 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CONFIG_WILL_CHANGE; |
| 73 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CONTROLLER; |
| 74 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CURRENT_TRACKER; |
| 75 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.Controller.IS_A_MONKEY; |
| 76 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.GLOBAL_CONFIGURATION; |
| 77 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.GOING_TO_SLEEP; |
| 78 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HEAVY_WEIGHT_PROC; |
| 79 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HOME_PROC; |
| 80 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.LAUNCHING_ACTIVITY; |
| 81 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 82 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC_VISIBLE_TIME_MS; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 83 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.SCREEN_COMPAT_PACKAGES; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 84 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.MODE; |
| 85 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.PACKAGE; |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 86 | import static com.android.server.am.EventLogTags.writeBootProgressEnableScreen; |
| 87 | import static com.android.server.am.EventLogTags.writeConfigurationChanged; |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 88 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; |
| 89 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 90 | import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 91 | import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; |
| 92 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
| 93 | import static com.android.server.wm.ActivityStackSupervisor.REMOVE_FROM_RECENTS; |
| 94 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL; |
| 95 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONFIGURATION; |
| 96 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_FOCUS; |
| 97 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_IMMERSIVE; |
| 98 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_LOCKTASK; |
| 99 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STACK; |
| 100 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; |
| 101 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 102 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_VISIBILITY; |
| 103 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFIGURATION; |
| 104 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_FOCUS; |
| 105 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_IMMERSIVE; |
| 106 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_LOCKTASK; |
| 107 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; |
| 108 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; |
| 109 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_VISIBILITY; |
| 110 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 111 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 112 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_CONTENT; |
| 113 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_DATA; |
| 114 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_RECEIVER_EXTRAS; |
| 115 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_STRUCTURE; |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 116 | import static com.android.server.wm.ActivityTaskManagerService.H.REPORT_TIME_TRACKER_MSG; |
| 117 | import static com.android.server.wm.ActivityTaskManagerService.UiHandler.DISMISS_DIALOG_UI_MSG; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 118 | import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; |
| 119 | import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 120 | import static com.android.server.wm.RootWindowContainer.MATCH_TASK_IN_STACKS_ONLY; |
| 121 | import static com.android.server.wm.RootWindowContainer.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 122 | import static com.android.server.wm.Task.LOCK_TASK_AUTH_DONT_LOCK; |
| 123 | import static com.android.server.wm.Task.REPARENT_KEEP_STACK_AT_FRONT; |
| 124 | import static com.android.server.wm.Task.REPARENT_LEAVE_STACK_IN_PLACE; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 125 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 126 | import android.Manifest; |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 127 | import android.annotation.IntDef; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 128 | import android.annotation.NonNull; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 129 | import android.annotation.Nullable; |
| 130 | import android.annotation.UserIdInt; |
| 131 | import android.app.Activity; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 132 | import android.app.ActivityManager; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 133 | import android.app.ActivityManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 134 | import android.app.ActivityOptions; |
| 135 | import android.app.ActivityTaskManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 136 | import android.app.ActivityThread; |
| 137 | import android.app.AlertDialog; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 138 | import android.app.AppGlobals; |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 139 | import android.app.AppOpsManager; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 140 | import android.app.Dialog; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 141 | import android.app.IActivityController; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 142 | import android.app.IActivityTaskManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 143 | import android.app.IApplicationThread; |
| 144 | import android.app.IAssistDataReceiver; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 145 | import android.app.INotificationManager; |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 146 | import android.app.IRequestFinishCallback; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 147 | import android.app.ITaskOrganizerController; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 148 | import android.app.ITaskStackListener; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 149 | import android.app.Notification; |
| 150 | import android.app.NotificationManager; |
| 151 | import android.app.PendingIntent; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 152 | import android.app.PictureInPictureParams; |
| 153 | import android.app.ProfilerInfo; |
| 154 | import android.app.RemoteAction; |
| 155 | import android.app.WaitResult; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 156 | import android.app.WindowConfiguration; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 157 | import android.app.admin.DevicePolicyCache; |
| 158 | import android.app.assist.AssistContent; |
| 159 | import android.app.assist.AssistStructure; |
jorgegil@google.com | 06bc323 | 2019-10-31 14:51:22 -0700 | [diff] [blame] | 160 | import android.app.servertransaction.ClientTransaction; |
| 161 | import android.app.servertransaction.EnterPipRequestedItem; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 162 | import android.app.usage.UsageStatsManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 163 | import android.content.ActivityNotFoundException; |
| 164 | import android.content.ComponentName; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 165 | import android.content.ContentResolver; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 166 | import android.content.Context; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 167 | import android.content.DialogInterface; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 168 | import android.content.IIntentSender; |
| 169 | import android.content.Intent; |
| 170 | import android.content.pm.ActivityInfo; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 171 | import android.content.pm.ApplicationInfo; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 172 | import android.content.pm.ConfigurationInfo; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 173 | import android.content.pm.IPackageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 174 | import android.content.pm.PackageManager; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 175 | import android.content.pm.PackageManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 176 | import android.content.pm.ParceledListSlice; |
| 177 | import android.content.pm.ResolveInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 178 | import android.content.res.CompatibilityInfo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 179 | import android.content.res.Configuration; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 180 | import android.content.res.Resources; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 181 | import android.database.ContentObserver; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 182 | import android.graphics.Bitmap; |
| 183 | import android.graphics.Point; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 184 | import android.graphics.Rect; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 185 | import android.metrics.LogMaker; |
| 186 | import android.net.Uri; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 187 | import android.os.Binder; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 188 | import android.os.Build; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 189 | import android.os.Bundle; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 190 | import android.os.FactoryTest; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 191 | import android.os.FileUtils; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 192 | import android.os.Handler; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 193 | import android.os.IBinder; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 194 | import android.os.IUserManager; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 195 | import android.os.LocaleList; |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 196 | import android.os.Looper; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 197 | import android.os.Message; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 198 | import android.os.PersistableBundle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 199 | import android.os.PowerManager; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 200 | import android.os.PowerManagerInternal; |
Marvin Ramin | 830d4e3 | 2019-03-12 13:16:58 +0100 | [diff] [blame] | 201 | import android.os.Process; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 202 | import android.os.RemoteException; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 203 | import android.os.ServiceManager; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 204 | import android.os.StrictMode; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 205 | import android.os.SystemClock; |
| 206 | import android.os.SystemProperties; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 207 | import android.os.Trace; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 208 | import android.os.UpdateLock; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 209 | import android.os.UserHandle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 210 | import android.os.UserManager; |
| 211 | import android.os.WorkSource; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 212 | import android.os.storage.IStorageManager; |
| 213 | import android.os.storage.StorageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 214 | import android.provider.Settings; |
| 215 | import android.service.voice.IVoiceInteractionSession; |
| 216 | import android.service.voice.VoiceInteractionManagerInternal; |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 217 | import android.sysprop.DisplayProperties; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 218 | import android.telecom.TelecomManager; |
| 219 | import android.text.TextUtils; |
Neil Fuller | 9774681 | 2019-08-19 14:20:50 +0100 | [diff] [blame] | 220 | import android.text.format.TimeMigrationUtils; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 221 | import android.util.ArrayMap; |
Nicholas Sauer | 3f9249f | 2019-09-10 20:23:41 -0700 | [diff] [blame] | 222 | import android.util.ArraySet; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 223 | import android.util.Log; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 224 | import android.util.Slog; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 225 | import android.util.SparseArray; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 226 | import android.util.TimeUtils; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 227 | import android.util.proto.ProtoOutputStream; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 228 | import android.view.IRecentsAnimationRunner; |
| 229 | import android.view.RemoteAnimationAdapter; |
| 230 | import android.view.RemoteAnimationDefinition; |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 231 | import android.view.WindowContainerTransaction; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 232 | import android.view.WindowManager; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 233 | |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 234 | import com.android.internal.R; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 235 | import com.android.internal.annotations.VisibleForTesting; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 236 | import com.android.internal.app.AssistUtils; |
| 237 | import com.android.internal.app.IVoiceInteractor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 238 | import com.android.internal.app.ProcessMap; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 239 | import com.android.internal.logging.MetricsLogger; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 240 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 241 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
| 242 | import com.android.internal.notification.SystemNotificationChannels; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 243 | import com.android.internal.os.TransferPipe; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 244 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 245 | import com.android.internal.policy.IKeyguardDismissCallback; |
| 246 | import com.android.internal.policy.KeyguardDismissCallback; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 247 | import com.android.internal.util.ArrayUtils; |
| 248 | import com.android.internal.util.FastPrintWriter; |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 249 | import com.android.internal.util.FrameworkStatsLog; |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 250 | import com.android.internal.util.function.pooled.PooledConsumer; |
| 251 | import com.android.internal.util.function.pooled.PooledFunction; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 252 | import com.android.internal.util.function.pooled.PooledLambda; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 253 | import com.android.server.AttributeCache; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 254 | import com.android.server.LocalServices; |
| 255 | import com.android.server.SystemService; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 256 | import com.android.server.SystemServiceManager; |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 257 | import com.android.server.UiThread; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 258 | import com.android.server.Watchdog; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 259 | import com.android.server.am.ActivityManagerService; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 260 | import com.android.server.am.ActivityManagerServiceDumpProcessesProto; |
| 261 | import com.android.server.am.AppTimeTracker; |
| 262 | import com.android.server.am.BaseErrorDialog; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 263 | import com.android.server.am.PendingIntentController; |
| 264 | import com.android.server.am.PendingIntentRecord; |
| 265 | import com.android.server.am.UserState; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 266 | import com.android.server.firewall.IntentFirewall; |
Tarandeep Singh | 07b318b | 2019-07-17 11:12:04 -0700 | [diff] [blame] | 267 | import com.android.server.inputmethod.InputMethodSystemProperty; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 268 | import com.android.server.pm.UserManagerService; |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 269 | import com.android.server.policy.PermissionPolicyInternal; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 270 | import com.android.server.uri.UriGrantsManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 271 | import com.android.server.vr.VrManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 272 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 273 | import java.io.BufferedReader; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 274 | import java.io.File; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 275 | import java.io.FileDescriptor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 276 | import java.io.FileOutputStream; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 277 | import java.io.FileReader; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 278 | import java.io.IOException; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 279 | import java.io.PrintWriter; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 280 | import java.io.StringWriter; |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 281 | import java.lang.annotation.ElementType; |
| 282 | import java.lang.annotation.Retention; |
| 283 | import java.lang.annotation.RetentionPolicy; |
| 284 | import java.lang.annotation.Target; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 285 | import java.lang.ref.WeakReference; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 286 | import java.text.DateFormat; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 287 | import java.util.ArrayList; |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 288 | import java.util.Arrays; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 289 | import java.util.Date; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 290 | import java.util.HashMap; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 291 | import java.util.HashSet; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 292 | import java.util.List; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 293 | import java.util.Locale; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 294 | import java.util.Map; |
Daulet Zhanguzin | c6c641f | 2020-01-02 17:18:30 +0000 | [diff] [blame] | 295 | import java.util.Objects; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 296 | import java.util.Set; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 297 | |
| 298 | /** |
| 299 | * System service for managing activities and their containers (task, stacks, displays,... ). |
| 300 | * |
| 301 | * {@hide} |
| 302 | */ |
| 303 | public class ActivityTaskManagerService extends IActivityTaskManager.Stub { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 304 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityTaskManagerService" : TAG_ATM; |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 305 | static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 306 | static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 307 | private static final String TAG_IMMERSIVE = TAG + POSTFIX_IMMERSIVE; |
| 308 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
| 309 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
| 310 | private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 311 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 312 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 313 | // How long we wait until we timeout on key dispatching. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 314 | public static final int KEY_DISPATCHING_TIMEOUT_MS = 5 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 315 | // How long we wait until we timeout on key dispatching during instrumentation. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 316 | static final int INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT_MS = 60 * 1000; |
Michal Karpinski | fc6872e | 2019-05-21 15:18:44 +0100 | [diff] [blame] | 317 | // How long we permit background activity starts after an activity in the process |
| 318 | // started or finished. |
| 319 | static final long ACTIVITY_BG_START_GRACE_PERIOD_MS = 10 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 320 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 321 | /** Used to indicate that an app transition should be animated. */ |
| 322 | static final boolean ANIMATE = true; |
| 323 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 324 | /** Hardware-reported OpenGLES version. */ |
| 325 | final int GL_ES_VERSION; |
| 326 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 327 | public static final String DUMP_ACTIVITIES_CMD = "activities" ; |
| 328 | public static final String DUMP_ACTIVITIES_SHORT_CMD = "a" ; |
| 329 | public static final String DUMP_LASTANR_CMD = "lastanr" ; |
| 330 | public static final String DUMP_LASTANR_TRACES_CMD = "lastanr-traces" ; |
| 331 | public static final String DUMP_STARTER_CMD = "starter" ; |
| 332 | public static final String DUMP_CONTAINERS_CMD = "containers" ; |
| 333 | public static final String DUMP_RECENTS_CMD = "recents" ; |
| 334 | public static final String DUMP_RECENTS_SHORT_CMD = "r" ; |
| 335 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 336 | /** This activity is not being relaunched, or being relaunched for a non-resize reason. */ |
| 337 | public static final int RELAUNCH_REASON_NONE = 0; |
| 338 | /** This activity is being relaunched due to windowing mode change. */ |
| 339 | public static final int RELAUNCH_REASON_WINDOWING_MODE_RESIZE = 1; |
| 340 | /** This activity is being relaunched due to a free-resize operation. */ |
| 341 | public static final int RELAUNCH_REASON_FREE_RESIZE = 2; |
| 342 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 343 | Context mContext; |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 344 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 345 | /** |
| 346 | * This Context is themable and meant for UI display (AlertDialogs, etc.). The theme can |
| 347 | * change at runtime. Use mContext for non-UI purposes. |
| 348 | */ |
| 349 | final Context mUiContext; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 350 | final ActivityThread mSystemThread; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 351 | H mH; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 352 | UiHandler mUiHandler; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 353 | ActivityManagerInternal mAmInternal; |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 354 | UriGrantsManagerInternal mUgmInternal; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 355 | private PackageManagerInternal mPmInternal; |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 356 | private PermissionPolicyInternal mPermissionPolicyInternal; |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 357 | @VisibleForTesting |
| 358 | final ActivityTaskManagerInternal mInternal; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 359 | PowerManagerInternal mPowerManagerInternal; |
| 360 | private UsageStatsManagerInternal mUsageStatsInternal; |
| 361 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 362 | PendingIntentController mPendingIntentController; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 363 | IntentFirewall mIntentFirewall; |
| 364 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 365 | /* Global service lock used by the package the owns this service. */ |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 366 | final WindowManagerGlobalLock mGlobalLock = new WindowManagerGlobalLock(); |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 367 | /** |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 368 | * It is the same instance as {@link #mGlobalLock}, just declared as a type that the |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 369 | * locked-region-code-injection does't recognize it. It is used to skip wrapping priority |
| 370 | * booster for places that are already in the scope of another booster (e.g. computing oom-adj). |
| 371 | * |
| 372 | * @see WindowManagerThreadPriorityBooster |
| 373 | */ |
| 374 | final Object mGlobalLockWithoutBoost = mGlobalLock; |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 375 | ActivityStackSupervisor mStackSupervisor; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 376 | RootWindowContainer mRootWindowContainer; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 377 | WindowManagerService mWindowManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 378 | private UserManagerService mUserManager; |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 379 | private AppOpsManager mAppOpsManager; |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 380 | /** All active uids in the system. */ |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 381 | private final MirrorActiveUids mActiveUids = new MirrorActiveUids(); |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 382 | private final SparseArray<String> mPendingTempWhitelist = new SparseArray<>(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 383 | /** All processes currently running that might have a window organized by name. */ |
| 384 | final ProcessMap<WindowProcessController> mProcessNames = new ProcessMap<>(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 385 | /** All processes we currently have running mapped by pid and uid */ |
| 386 | final WindowProcessControllerMap mProcessMap = new WindowProcessControllerMap(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 387 | /** This is the process holding what we currently consider to be the "home" activity. */ |
| 388 | WindowProcessController mHomeProcess; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 389 | /** The currently running heavy-weight process, if any. */ |
| 390 | WindowProcessController mHeavyWeightProcess = null; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 391 | boolean mHasHeavyWeightFeature; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 392 | /** |
| 393 | * This is the process holding the activity the user last visited that is in a different process |
| 394 | * from the one they are currently in. |
| 395 | */ |
| 396 | WindowProcessController mPreviousProcess; |
| 397 | /** The time at which the previous process was last visible. */ |
| 398 | long mPreviousProcessVisibleTime; |
| 399 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 400 | /** List of intents that were used to start the most recent tasks. */ |
| 401 | private RecentTasks mRecentTasks; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 402 | /** State of external calls telling us if the device is awake or asleep. */ |
| 403 | private boolean mKeyguardShown = false; |
| 404 | |
| 405 | // Wrapper around VoiceInteractionServiceManager |
| 406 | private AssistUtils mAssistUtils; |
| 407 | |
| 408 | // VoiceInteraction session ID that changes for each new request except when |
| 409 | // being called for multi-window assist in a single session. |
| 410 | private int mViSessionId = 1000; |
| 411 | |
| 412 | // How long to wait in getAssistContextExtras for the activity and foreground services |
| 413 | // to respond with the result. |
| 414 | private static final int PENDING_ASSIST_EXTRAS_TIMEOUT = 500; |
| 415 | |
| 416 | // How long top wait when going through the modern assist (which doesn't need to block |
| 417 | // on getting this result before starting to launch its UI). |
| 418 | private static final int PENDING_ASSIST_EXTRAS_LONG_TIMEOUT = 2000; |
| 419 | |
| 420 | // How long to wait in getAutofillAssistStructure() for the activity to respond with the result. |
| 421 | private static final int PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT = 2000; |
| 422 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 423 | // Permission tokens are used to temporarily granted a trusted app the ability to call |
| 424 | // #startActivityAsCaller. A client is expected to dump its token after this time has elapsed, |
| 425 | // showing any appropriate error messages to the user. |
| 426 | private static final long START_AS_CALLER_TOKEN_TIMEOUT = |
| 427 | 10 * MINUTE_IN_MILLIS; |
| 428 | |
| 429 | // How long before the service actually expires a token. This is slightly longer than |
| 430 | // START_AS_CALLER_TOKEN_TIMEOUT, to provide a buffer so clients will rarely encounter the |
| 431 | // expiration exception. |
| 432 | private static final long START_AS_CALLER_TOKEN_TIMEOUT_IMPL = |
| 433 | START_AS_CALLER_TOKEN_TIMEOUT + 2 * 1000; |
| 434 | |
| 435 | // How long the service will remember expired tokens, for the purpose of providing error |
| 436 | // messaging when a client uses an expired token. |
| 437 | private static final long START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT = |
| 438 | START_AS_CALLER_TOKEN_TIMEOUT_IMPL + 20 * MINUTE_IN_MILLIS; |
| 439 | |
| 440 | // Activity tokens of system activities that are delegating their call to |
| 441 | // #startActivityByCaller, keyed by the permissionToken granted to the delegate. |
| 442 | final HashMap<IBinder, IBinder> mStartActivitySources = new HashMap<>(); |
| 443 | |
| 444 | // Permission tokens that have expired, but we remember for error reporting. |
| 445 | final ArrayList<IBinder> mExpiredStartAsCallerTokens = new ArrayList<>(); |
| 446 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 447 | private final ArrayList<PendingAssistExtras> mPendingAssistExtras = new ArrayList<>(); |
| 448 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 449 | // Keeps track of the active voice interaction service component, notified from |
| 450 | // VoiceInteractionManagerService |
| 451 | ComponentName mActiveVoiceInteractionServiceComponent; |
| 452 | |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 453 | // A map userId and all its companion app uids |
| 454 | private final Map<Integer, Set<Integer>> mCompanionAppUidsMap = new ArrayMap<>(); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 455 | |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 456 | VrController mVrController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 457 | KeyguardController mKeyguardController; |
| 458 | private final ClientLifecycleManager mLifecycleManager; |
| 459 | private TaskChangeNotificationController mTaskChangeNotificationController; |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 460 | /** The controller for all operations related to locktask. */ |
| 461 | private LockTaskController mLockTaskController; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 462 | private ActivityStartController mActivityStartController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 463 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 464 | boolean mSuppressResizeConfigChanges; |
| 465 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 466 | final UpdateConfigurationResult mTmpUpdateConfigurationResult = |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 467 | new UpdateConfigurationResult(); |
| 468 | |
| 469 | static final class UpdateConfigurationResult { |
| 470 | // Configuration changes that were updated. |
| 471 | int changes; |
| 472 | // If the activity was relaunched to match the new configuration. |
| 473 | boolean activityRelaunched; |
| 474 | |
| 475 | void reset() { |
| 476 | changes = 0; |
| 477 | activityRelaunched = false; |
| 478 | } |
| 479 | } |
| 480 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 481 | /** Current sequencing integer of the configuration, for skipping old configurations. */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 482 | private int mConfigurationSeq; |
| 483 | // To cache the list of supported system locales |
| 484 | private String[] mSupportedSystemLocales = null; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 485 | |
| 486 | /** |
| 487 | * Temp object used when global and/or display override configuration is updated. It is also |
| 488 | * sent to outer world instead of {@link #getGlobalConfiguration} because we don't trust |
| 489 | * anyone... |
| 490 | */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 491 | private Configuration mTempConfig = new Configuration(); |
| 492 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 493 | /** Temporary to avoid allocations. */ |
| 494 | final StringBuilder mStringBuilder = new StringBuilder(256); |
| 495 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 496 | // Amount of time after a call to stopAppSwitches() during which we will |
| 497 | // prevent further untrusted switches from happening. |
| 498 | private static final long APP_SWITCH_DELAY_TIME = 5 * 1000; |
| 499 | |
| 500 | /** |
| 501 | * The time at which we will allow normal application switches again, |
| 502 | * after a call to {@link #stopAppSwitches()}. |
| 503 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 504 | private long mAppSwitchesAllowedTime; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 505 | /** |
| 506 | * This is set to true after the first switch after mAppSwitchesAllowedTime |
| 507 | * is set; any switches after that will clear the time. |
| 508 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 509 | private boolean mDidAppSwitch; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 510 | |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 511 | /** |
| 512 | * Last stop app switches time, apps finished before this time cannot start background activity |
| 513 | * even if they are in grace period. |
| 514 | */ |
| 515 | private long mLastStopAppSwitchesTime; |
| 516 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 517 | IActivityController mController = null; |
| 518 | boolean mControllerIsAMonkey = false; |
| 519 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 520 | final int mFactoryTest; |
| 521 | |
| 522 | /** Used to control how we initialize the service. */ |
| 523 | ComponentName mTopComponent; |
| 524 | String mTopAction = Intent.ACTION_MAIN; |
| 525 | String mTopData; |
| 526 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 527 | /** Profiling app information. */ |
| 528 | String mProfileApp = null; |
| 529 | WindowProcessController mProfileProc = null; |
| 530 | ProfilerInfo mProfilerInfo = null; |
| 531 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 532 | /** |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 533 | * Dump of the activity state at the time of the last ANR. Cleared after |
| 534 | * {@link WindowManagerService#LAST_ANR_LIFETIME_DURATION_MSECS} |
| 535 | */ |
| 536 | String mLastANRState; |
| 537 | |
| 538 | /** |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 539 | * Used to retain an update lock when the foreground activity is in |
| 540 | * immersive mode. |
| 541 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 542 | private final UpdateLock mUpdateLock = new UpdateLock("immersive"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 543 | |
| 544 | /** |
| 545 | * Packages that are being allowed to perform unrestricted app switches. Mapping is |
| 546 | * User -> Type -> uid. |
| 547 | */ |
| 548 | final SparseArray<ArrayMap<String, Integer>> mAllowAppSwitchUids = new SparseArray<>(); |
| 549 | |
| 550 | /** The dimensions of the thumbnails in the Recents UI. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 551 | private int mThumbnailWidth; |
| 552 | private int mThumbnailHeight; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 553 | |
| 554 | /** |
| 555 | * Flag that indicates if multi-window is enabled. |
| 556 | * |
| 557 | * For any particular form of multi-window to be enabled, generic multi-window must be enabled |
| 558 | * in {@link com.android.internal.R.bool#config_supportsMultiWindow} config or |
| 559 | * {@link Settings.Global#DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES} development option set. |
| 560 | * At least one of the forms of multi-window must be enabled in order for this flag to be |
| 561 | * initialized to 'true'. |
| 562 | * |
| 563 | * @see #mSupportsSplitScreenMultiWindow |
| 564 | * @see #mSupportsFreeformWindowManagement |
| 565 | * @see #mSupportsPictureInPicture |
| 566 | * @see #mSupportsMultiDisplay |
| 567 | */ |
| 568 | boolean mSupportsMultiWindow; |
| 569 | boolean mSupportsSplitScreenMultiWindow; |
| 570 | boolean mSupportsFreeformWindowManagement; |
| 571 | boolean mSupportsPictureInPicture; |
| 572 | boolean mSupportsMultiDisplay; |
| 573 | boolean mForceResizableActivities; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 574 | boolean mSizeCompatFreeform; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 575 | |
| 576 | final List<ActivityTaskManagerInternal.ScreenObserver> mScreenObservers = new ArrayList<>(); |
| 577 | |
| 578 | // VR Vr2d Display Id. |
| 579 | int mVr2dDisplayId = INVALID_DISPLAY; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 580 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 581 | /** |
| 582 | * Set while we are wanting to sleep, to prevent any |
| 583 | * activities from being started/resumed. |
| 584 | * |
| 585 | * TODO(b/33594039): Clarify the actual state transitions represented by mSleeping. |
| 586 | * |
| 587 | * Currently mSleeping is set to true when transitioning into the sleep state, and remains true |
| 588 | * while in the sleep state until there is a pending transition out of sleep, in which case |
| 589 | * mSleeping is set to false, and remains false while awake. |
| 590 | * |
| 591 | * Whether mSleeping can quickly toggled between true/false without the device actually |
| 592 | * display changing states is undefined. |
| 593 | */ |
| 594 | private boolean mSleeping = false; |
| 595 | |
| 596 | /** |
| 597 | * The process state used for processes that are running the top activities. |
| 598 | * This changes between TOP and TOP_SLEEPING to following mSleeping. |
| 599 | */ |
| 600 | int mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
| 601 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 602 | @Retention(RetentionPolicy.SOURCE) |
| 603 | @IntDef({ |
| 604 | LAYOUT_REASON_CONFIG_CHANGED, |
| 605 | LAYOUT_REASON_VISIBILITY_CHANGED, |
| 606 | }) |
| 607 | @interface LayoutReason {} |
| 608 | static final int LAYOUT_REASON_CONFIG_CHANGED = 0x1; |
| 609 | static final int LAYOUT_REASON_VISIBILITY_CHANGED = 0x2; |
| 610 | |
| 611 | /** The reasons to perform surface placement. */ |
| 612 | @LayoutReason |
| 613 | private int mLayoutReasons; |
| 614 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 615 | // Whether we should show our dialogs (ANR, crash, etc) or just perform their default action |
| 616 | // automatically. Important for devices without direct input devices. |
| 617 | private boolean mShowDialogs = true; |
| 618 | |
| 619 | /** Set if we are shutting down the system, similar to sleeping. */ |
| 620 | boolean mShuttingDown = false; |
| 621 | |
| 622 | /** |
| 623 | * We want to hold a wake lock while running a voice interaction session, since |
| 624 | * this may happen with the screen off and we need to keep the CPU running to |
| 625 | * be able to continue to interact with the user. |
| 626 | */ |
| 627 | PowerManager.WakeLock mVoiceWakeLock; |
| 628 | |
| 629 | /** |
| 630 | * Set while we are running a voice interaction. This overrides sleeping while it is active. |
| 631 | */ |
| 632 | IVoiceInteractionSession mRunningVoice; |
| 633 | |
| 634 | /** |
| 635 | * The last resumed activity. This is identical to the current resumed activity most |
| 636 | * of the time but could be different when we're pausing one activity before we resume |
| 637 | * another activity. |
| 638 | */ |
| 639 | ActivityRecord mLastResumedActivity; |
| 640 | |
| 641 | /** |
| 642 | * The activity that is currently being traced as the active resumed activity. |
| 643 | * |
| 644 | * @see #updateResumedAppTrace |
| 645 | */ |
| 646 | private @Nullable ActivityRecord mTracedResumedActivity; |
| 647 | |
| 648 | /** If non-null, we are tracking the time the user spends in the currently focused app. */ |
| 649 | AppTimeTracker mCurAppTimeTracker; |
| 650 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 651 | AppWarnings mAppWarnings; |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 652 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 653 | /** |
| 654 | * Packages that the user has asked to have run in screen size |
| 655 | * compatibility mode instead of filling the screen. |
| 656 | */ |
| 657 | CompatModePackages mCompatModePackages; |
| 658 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 659 | private FontScaleSettingObserver mFontScaleSettingObserver; |
| 660 | |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 661 | /** |
| 662 | * Stores the registration and state of TaskOrganizers in use. |
| 663 | */ |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 664 | TaskOrganizerController mTaskOrganizerController = new TaskOrganizerController(this); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 665 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 666 | private int mDeviceOwnerUid = Process.INVALID_UID; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 667 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 668 | private final class FontScaleSettingObserver extends ContentObserver { |
| 669 | private final Uri mFontScaleUri = Settings.System.getUriFor(FONT_SCALE); |
| 670 | private final Uri mHideErrorDialogsUri = Settings.Global.getUriFor(HIDE_ERROR_DIALOGS); |
| 671 | |
| 672 | public FontScaleSettingObserver() { |
| 673 | super(mH); |
| 674 | final ContentResolver resolver = mContext.getContentResolver(); |
| 675 | resolver.registerContentObserver(mFontScaleUri, false, this, UserHandle.USER_ALL); |
| 676 | resolver.registerContentObserver(mHideErrorDialogsUri, false, this, |
| 677 | UserHandle.USER_ALL); |
| 678 | } |
| 679 | |
| 680 | @Override |
| 681 | public void onChange(boolean selfChange, Uri uri, @UserIdInt int userId) { |
| 682 | if (mFontScaleUri.equals(uri)) { |
| 683 | updateFontScaleIfNeeded(userId); |
| 684 | } else if (mHideErrorDialogsUri.equals(uri)) { |
| 685 | synchronized (mGlobalLock) { |
| 686 | updateShouldShowDialogsLocked(getGlobalConfiguration()); |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 692 | /** Indicates that the method may be invoked frequently or is sensitive to performance. */ |
| 693 | @Target(ElementType.METHOD) |
| 694 | @Retention(RetentionPolicy.SOURCE) |
| 695 | @interface HotPath { |
| 696 | int NONE = 0; |
| 697 | int OOM_ADJUSTMENT = 1; |
| 698 | int LRU_UPDATE = 2; |
| 699 | int PROCESS_CHANGE = 3; |
| 700 | int caller() default NONE; |
| 701 | } |
| 702 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 703 | private final Runnable mUpdateOomAdjRunnable = new Runnable() { |
| 704 | @Override |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 705 | public void run() { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 706 | mAmInternal.updateOomAdj(); |
| 707 | } |
| 708 | }; |
| 709 | |
Charles Chen | 8d98dd2 | 2018-12-26 17:36:54 +0800 | [diff] [blame] | 710 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 711 | public ActivityTaskManagerService(Context context) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 712 | mContext = context; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 713 | mFactoryTest = FactoryTest.getMode(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 714 | mSystemThread = ActivityThread.currentActivityThread(); |
| 715 | mUiContext = mSystemThread.getSystemUiContext(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 716 | mLifecycleManager = new ClientLifecycleManager(); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 717 | mInternal = new LocalService(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 718 | GL_ES_VERSION = SystemProperties.getInt("ro.opengles.version", GL_ES_VERSION_UNDEFINED); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 721 | public void onSystemReady() { |
| 722 | synchronized (mGlobalLock) { |
| 723 | mHasHeavyWeightFeature = mContext.getPackageManager().hasSystemFeature( |
| 724 | PackageManager.FEATURE_CANT_SAVE_STATE); |
| 725 | mAssistUtils = new AssistUtils(mContext); |
| 726 | mVrController.onSystemReady(); |
| 727 | mRecentTasks.onSystemReadyLocked(); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 728 | mStackSupervisor.onSystemReady(); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 729 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 732 | public void onInitPowerManagement() { |
| 733 | synchronized (mGlobalLock) { |
| 734 | mStackSupervisor.initPowerManagement(); |
| 735 | final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 736 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
| 737 | mVoiceWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*voice*"); |
| 738 | mVoiceWakeLock.setReferenceCounted(false); |
| 739 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 742 | public void installSystemProviders() { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 743 | mFontScaleSettingObserver = new FontScaleSettingObserver(); |
| 744 | } |
| 745 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 746 | public void retrieveSettings(ContentResolver resolver) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 747 | final boolean freeformWindowManagement = |
| 748 | mContext.getPackageManager().hasSystemFeature(FEATURE_FREEFORM_WINDOW_MANAGEMENT) |
| 749 | || Settings.Global.getInt( |
| 750 | resolver, DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0; |
| 751 | |
| 752 | final boolean supportsMultiWindow = ActivityTaskManager.supportsMultiWindow(mContext); |
| 753 | final boolean supportsPictureInPicture = supportsMultiWindow && |
| 754 | mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE); |
| 755 | final boolean supportsSplitScreenMultiWindow = |
| 756 | ActivityTaskManager.supportsSplitScreenMultiWindow(mContext); |
| 757 | final boolean supportsMultiDisplay = mContext.getPackageManager() |
| 758 | .hasSystemFeature(FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 759 | final boolean forceRtl = Settings.Global.getInt(resolver, DEVELOPMENT_FORCE_RTL, 0) != 0; |
| 760 | final boolean forceResizable = Settings.Global.getInt( |
| 761 | resolver, DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 762 | final boolean sizeCompatFreeform = Settings.Global.getInt( |
| 763 | resolver, DEVELOPMENT_ENABLE_SIZECOMPAT_FREEFORM, 0) != 0; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 764 | |
| 765 | // Transfer any global setting for forcing RTL layout, into a System Property |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 766 | DisplayProperties.debug_force_rtl(forceRtl); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 767 | |
| 768 | final Configuration configuration = new Configuration(); |
| 769 | Settings.System.getConfiguration(resolver, configuration); |
| 770 | if (forceRtl) { |
| 771 | // This will take care of setting the correct layout direction flags |
| 772 | configuration.setLayoutDirection(configuration.locale); |
| 773 | } |
| 774 | |
| 775 | synchronized (mGlobalLock) { |
| 776 | mForceResizableActivities = forceResizable; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 777 | mSizeCompatFreeform = sizeCompatFreeform; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 778 | final boolean multiWindowFormEnabled = freeformWindowManagement |
| 779 | || supportsSplitScreenMultiWindow |
| 780 | || supportsPictureInPicture |
| 781 | || supportsMultiDisplay; |
| 782 | if ((supportsMultiWindow || forceResizable) && multiWindowFormEnabled) { |
| 783 | mSupportsMultiWindow = true; |
| 784 | mSupportsFreeformWindowManagement = freeformWindowManagement; |
| 785 | mSupportsSplitScreenMultiWindow = supportsSplitScreenMultiWindow; |
| 786 | mSupportsPictureInPicture = supportsPictureInPicture; |
| 787 | mSupportsMultiDisplay = supportsMultiDisplay; |
| 788 | } else { |
| 789 | mSupportsMultiWindow = false; |
| 790 | mSupportsFreeformWindowManagement = false; |
| 791 | mSupportsSplitScreenMultiWindow = false; |
| 792 | mSupportsPictureInPicture = false; |
| 793 | mSupportsMultiDisplay = false; |
| 794 | } |
Garfield Tan | b5910b4 | 2019-03-14 14:50:59 -0700 | [diff] [blame] | 795 | mWindowManager.mRoot.onSettingsRetrieved(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 796 | // This happens before any activities are started, so we can change global configuration |
| 797 | // in-place. |
| 798 | updateConfigurationLocked(configuration, null, true); |
| 799 | final Configuration globalConfig = getGlobalConfiguration(); |
| 800 | if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Initial config: " + globalConfig); |
| 801 | |
| 802 | // Load resources only after the current configuration has been set. |
| 803 | final Resources res = mContext.getResources(); |
| 804 | mThumbnailWidth = res.getDimensionPixelSize( |
| 805 | com.android.internal.R.dimen.thumbnail_width); |
| 806 | mThumbnailHeight = res.getDimensionPixelSize( |
| 807 | com.android.internal.R.dimen.thumbnail_height); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 811 | public WindowManagerGlobalLock getGlobalLock() { |
| 812 | return mGlobalLock; |
| 813 | } |
| 814 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 815 | /** For test purpose only. */ |
| 816 | @VisibleForTesting |
| 817 | public ActivityTaskManagerInternal getAtmInternal() { |
| 818 | return mInternal; |
| 819 | } |
| 820 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 821 | public void initialize(IntentFirewall intentFirewall, PendingIntentController intentController, |
| 822 | Looper looper) { |
| 823 | mH = new H(looper); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 824 | mUiHandler = new UiHandler(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 825 | mIntentFirewall = intentFirewall; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 826 | final File systemDir = SystemServiceManager.ensureSystemDir(); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 827 | mAppWarnings = createAppWarnings(mUiContext, mH, mUiHandler, systemDir); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 828 | mCompatModePackages = new CompatModePackages(this, systemDir, mH); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 829 | mPendingIntentController = intentController; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 830 | mStackSupervisor = createStackSupervisor(); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 831 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 832 | mTaskChangeNotificationController = |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 833 | new TaskChangeNotificationController(mGlobalLock, mStackSupervisor, mH); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 834 | mLockTaskController = new LockTaskController(mContext, mStackSupervisor, mH); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 835 | mActivityStartController = new ActivityStartController(this); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 836 | setRecentTasks(new RecentTasks(this, mStackSupervisor)); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 837 | mVrController = new VrController(mGlobalLock); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 838 | mKeyguardController = mStackSupervisor.getKeyguardController(); |
| 839 | } |
| 840 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 841 | public void onActivityManagerInternalAdded() { |
| 842 | synchronized (mGlobalLock) { |
| 843 | mAmInternal = LocalServices.getService(ActivityManagerInternal.class); |
| 844 | mUgmInternal = LocalServices.getService(UriGrantsManagerInternal.class); |
| 845 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 848 | int increaseConfigurationSeqLocked() { |
| 849 | mConfigurationSeq = Math.max(++mConfigurationSeq, 1); |
| 850 | return mConfigurationSeq; |
| 851 | } |
| 852 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 853 | protected ActivityStackSupervisor createStackSupervisor() { |
| 854 | final ActivityStackSupervisor supervisor = new ActivityStackSupervisor(this, mH.getLooper()); |
| 855 | supervisor.initialize(); |
| 856 | return supervisor; |
| 857 | } |
| 858 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 859 | protected AppWarnings createAppWarnings( |
| 860 | Context uiContext, Handler handler, Handler uiHandler, File systemDir) { |
| 861 | return new AppWarnings(this, uiContext, handler, uiHandler, systemDir); |
| 862 | } |
| 863 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 864 | public void setWindowManager(WindowManagerService wm) { |
| 865 | synchronized (mGlobalLock) { |
| 866 | mWindowManager = wm; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 867 | mRootWindowContainer = wm.mRoot; |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 868 | mTempConfig.setToDefaults(); |
| 869 | mTempConfig.setLocales(LocaleList.getDefault()); |
| 870 | mConfigurationSeq = mTempConfig.seq = 1; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 871 | mRootWindowContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 872 | mLockTaskController.setWindowManager(wm); |
| 873 | mStackSupervisor.setWindowManager(wm); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 874 | mRootWindowContainer.setWindowManager(wm); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 875 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 878 | public void setUsageStatsManager(UsageStatsManagerInternal usageStatsManager) { |
| 879 | synchronized (mGlobalLock) { |
| 880 | mUsageStatsInternal = usageStatsManager; |
| 881 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 882 | } |
| 883 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 884 | UserManagerService getUserManager() { |
| 885 | if (mUserManager == null) { |
| 886 | IBinder b = ServiceManager.getService(Context.USER_SERVICE); |
| 887 | mUserManager = (UserManagerService) IUserManager.Stub.asInterface(b); |
| 888 | } |
| 889 | return mUserManager; |
| 890 | } |
| 891 | |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 892 | AppOpsManager getAppOpsManager() { |
| 893 | if (mAppOpsManager == null) { |
| 894 | mAppOpsManager = mContext.getSystemService(AppOpsManager.class); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 895 | } |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 896 | return mAppOpsManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | boolean hasUserRestriction(String restriction, int userId) { |
| 900 | return getUserManager().hasUserRestriction(restriction, userId); |
| 901 | } |
| 902 | |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 903 | boolean hasSystemAlertWindowPermission(int callingUid, int callingPid, String callingPackage) { |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 904 | final int mode = getAppOpsManager().noteOpNoThrow(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, |
| 905 | callingUid, callingPackage, /* featureId */ null, ""); |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 906 | if (mode == AppOpsManager.MODE_DEFAULT) { |
| 907 | return checkPermission(Manifest.permission.SYSTEM_ALERT_WINDOW, callingPid, callingUid) |
| 908 | == PERMISSION_GRANTED; |
| 909 | } |
| 910 | return mode == AppOpsManager.MODE_ALLOWED; |
| 911 | } |
| 912 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 913 | @VisibleForTesting |
| 914 | protected void setRecentTasks(RecentTasks recentTasks) { |
| 915 | mRecentTasks = recentTasks; |
| 916 | mStackSupervisor.setRecentTasks(recentTasks); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | RecentTasks getRecentTasks() { |
| 920 | return mRecentTasks; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 923 | ClientLifecycleManager getLifecycleManager() { |
| 924 | return mLifecycleManager; |
| 925 | } |
| 926 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 927 | ActivityStartController getActivityStartController() { |
| 928 | return mActivityStartController; |
| 929 | } |
| 930 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 931 | TaskChangeNotificationController getTaskChangeNotificationController() { |
| 932 | return mTaskChangeNotificationController; |
| 933 | } |
| 934 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 935 | LockTaskController getLockTaskController() { |
| 936 | return mLockTaskController; |
| 937 | } |
| 938 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 939 | /** |
| 940 | * Return the global configuration used by the process corresponding to the input pid. This is |
| 941 | * usually the global configuration with some overrides specific to that process. |
| 942 | */ |
| 943 | Configuration getGlobalConfigurationForCallingPid() { |
| 944 | final int pid = Binder.getCallingPid(); |
Yunfan Chen | c2ff6cf | 2018-12-04 16:56:21 -0800 | [diff] [blame] | 945 | return getGlobalConfigurationForPid(pid); |
| 946 | } |
| 947 | |
| 948 | /** |
| 949 | * Return the global configuration used by the process corresponding to the given pid. |
| 950 | */ |
| 951 | Configuration getGlobalConfigurationForPid(int pid) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 952 | if (pid == MY_PID || pid < 0) { |
| 953 | return getGlobalConfiguration(); |
| 954 | } |
| 955 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 956 | final WindowProcessController app = mProcessMap.getProcess(pid); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 957 | return app != null ? app.getConfiguration() : getGlobalConfiguration(); |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | /** |
| 962 | * Return the device configuration info used by the process corresponding to the input pid. |
| 963 | * The value is consistent with the global configuration for the process. |
| 964 | */ |
| 965 | @Override |
| 966 | public ConfigurationInfo getDeviceConfigurationInfo() { |
| 967 | ConfigurationInfo config = new ConfigurationInfo(); |
| 968 | synchronized (mGlobalLock) { |
| 969 | final Configuration globalConfig = getGlobalConfigurationForCallingPid(); |
| 970 | config.reqTouchScreen = globalConfig.touchscreen; |
| 971 | config.reqKeyboardType = globalConfig.keyboard; |
| 972 | config.reqNavigation = globalConfig.navigation; |
| 973 | if (globalConfig.navigation == Configuration.NAVIGATION_DPAD |
| 974 | || globalConfig.navigation == Configuration.NAVIGATION_TRACKBALL) { |
| 975 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 976 | } |
| 977 | if (globalConfig.keyboard != Configuration.KEYBOARD_UNDEFINED |
| 978 | && globalConfig.keyboard != Configuration.KEYBOARD_NOKEYS) { |
| 979 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 980 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 981 | config.reqGlEsVersion = GL_ES_VERSION; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 982 | } |
| 983 | return config; |
| 984 | } |
| 985 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 986 | private void start() { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 987 | LocalServices.addService(ActivityTaskManagerInternal.class, mInternal); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 988 | } |
| 989 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 990 | public static final class Lifecycle extends SystemService { |
| 991 | private final ActivityTaskManagerService mService; |
| 992 | |
| 993 | public Lifecycle(Context context) { |
| 994 | super(context); |
| 995 | mService = new ActivityTaskManagerService(context); |
| 996 | } |
| 997 | |
| 998 | @Override |
| 999 | public void onStart() { |
| 1000 | publishBinderService(Context.ACTIVITY_TASK_SERVICE, mService); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 1001 | mService.start(); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 1004 | @Override |
| 1005 | public void onUnlockUser(int userId) { |
| 1006 | synchronized (mService.getGlobalLock()) { |
Garfield Tan | 0d407f4 | 2019-03-07 11:47:01 -0800 | [diff] [blame] | 1007 | mService.mStackSupervisor.onUserUnlocked(userId); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | @Override |
| 1012 | public void onCleanupUser(int userId) { |
| 1013 | synchronized (mService.getGlobalLock()) { |
| 1014 | mService.mStackSupervisor.mLaunchParamsPersister.onCleanupUser(userId); |
| 1015 | } |
| 1016 | } |
| 1017 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1018 | public ActivityTaskManagerService getService() { |
| 1019 | return mService; |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1024 | public final int startActivity(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1025 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1026 | String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, |
| 1027 | Bundle bOptions) { |
| 1028 | return startActivityAsUser(caller, callingPackage, callingFeatureId, intent, resolvedType, |
| 1029 | resultTo, resultWho, requestCode, startFlags, profilerInfo, bOptions, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1030 | UserHandle.getCallingUserId()); |
| 1031 | } |
| 1032 | |
| 1033 | @Override |
| 1034 | public final int startActivities(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1035 | String callingFeatureId, Intent[] intents, String[] resolvedTypes, IBinder resultTo, |
| 1036 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1037 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1038 | final String reason = "startActivities"; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1039 | enforceNotIsolatedCaller(reason); |
| 1040 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, reason); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1041 | // TODO: Switch to user app stacks here. |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 1042 | return getActivityStartController().startActivities(caller, -1, 0, -1, callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1043 | callingFeatureId, intents, resolvedTypes, resultTo, |
| 1044 | SafeActivityOptions.fromBundle(bOptions), userId, reason, |
| 1045 | null /* originatingPendingIntent */, false /* allowBackgroundActivityStart */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | @Override |
| 1049 | public int startActivityAsUser(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1050 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1051 | String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, |
| 1052 | Bundle bOptions, int userId) { |
| 1053 | return startActivityAsUser(caller, callingPackage, callingFeatureId, intent, resolvedType, |
| 1054 | resultTo, resultWho, requestCode, startFlags, profilerInfo, bOptions, userId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1055 | true /*validateIncomingUser*/); |
| 1056 | } |
| 1057 | |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1058 | private int startActivityAsUser(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1059 | @Nullable String callingFeatureId, Intent intent, String resolvedType, |
| 1060 | IBinder resultTo, String resultWho, int requestCode, int startFlags, |
| 1061 | ProfilerInfo profilerInfo, Bundle bOptions, int userId, boolean validateIncomingUser) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1062 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1063 | enforceNotIsolatedCaller("startActivityAsUser"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1064 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1065 | userId = getActivityStartController().checkTargetUser(userId, validateIncomingUser, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1066 | Binder.getCallingPid(), Binder.getCallingUid(), "startActivityAsUser"); |
| 1067 | |
| 1068 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1069 | return getActivityStartController().obtainStarter(intent, "startActivityAsUser") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1070 | .setCaller(caller) |
| 1071 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1072 | .setCallingFeatureId(callingFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1073 | .setResolvedType(resolvedType) |
| 1074 | .setResultTo(resultTo) |
| 1075 | .setResultWho(resultWho) |
| 1076 | .setRequestCode(requestCode) |
| 1077 | .setStartFlags(startFlags) |
| 1078 | .setProfilerInfo(profilerInfo) |
| 1079 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1080 | .setUserId(userId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1081 | .execute(); |
| 1082 | |
| 1083 | } |
| 1084 | |
| 1085 | @Override |
| 1086 | public int startActivityIntentSender(IApplicationThread caller, IIntentSender target, |
| 1087 | IBinder whitelistToken, Intent fillInIntent, String resolvedType, IBinder resultTo, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1088 | String resultWho, int requestCode, int flagsMask, int flagsValues, Bundle bOptions) { |
| 1089 | enforceNotIsolatedCaller("startActivityIntentSender"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1090 | // Refuse possible leaked file descriptors |
| 1091 | if (fillInIntent != null && fillInIntent.hasFileDescriptors()) { |
| 1092 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1093 | } |
| 1094 | |
| 1095 | if (!(target instanceof PendingIntentRecord)) { |
| 1096 | throw new IllegalArgumentException("Bad PendingIntent object"); |
| 1097 | } |
| 1098 | |
| 1099 | PendingIntentRecord pir = (PendingIntentRecord)target; |
| 1100 | |
| 1101 | synchronized (mGlobalLock) { |
| 1102 | // If this is coming from the currently resumed activity, it is |
| 1103 | // effectively saying that app switches are allowed at this point. |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1104 | final ActivityStack stack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1105 | if (stack.mResumedActivity != null && |
| 1106 | stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1107 | mAppSwitchesAllowedTime = 0; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1108 | } |
| 1109 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1110 | return pir.sendInner(0, fillInIntent, resolvedType, whitelistToken, null, null, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1111 | resultTo, resultWho, requestCode, flagsMask, flagsValues, bOptions); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | @Override |
| 1115 | public boolean startNextMatchingActivity(IBinder callingActivity, Intent intent, |
| 1116 | Bundle bOptions) { |
| 1117 | // Refuse possible leaked file descriptors |
| 1118 | if (intent != null && intent.hasFileDescriptors()) { |
| 1119 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1120 | } |
| 1121 | SafeActivityOptions options = SafeActivityOptions.fromBundle(bOptions); |
| 1122 | |
| 1123 | synchronized (mGlobalLock) { |
| 1124 | final ActivityRecord r = ActivityRecord.isInStackLocked(callingActivity); |
| 1125 | if (r == null) { |
| 1126 | SafeActivityOptions.abort(options); |
| 1127 | return false; |
| 1128 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1129 | if (!r.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1130 | // The caller is not running... d'oh! |
| 1131 | SafeActivityOptions.abort(options); |
| 1132 | return false; |
| 1133 | } |
| 1134 | intent = new Intent(intent); |
| 1135 | // The caller is not allowed to change the data. |
| 1136 | intent.setDataAndType(r.intent.getData(), r.intent.getType()); |
| 1137 | // And we are resetting to find the next component... |
| 1138 | intent.setComponent(null); |
| 1139 | |
| 1140 | final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0); |
| 1141 | |
| 1142 | ActivityInfo aInfo = null; |
| 1143 | try { |
| 1144 | List<ResolveInfo> resolves = |
| 1145 | AppGlobals.getPackageManager().queryIntentActivities( |
| 1146 | intent, r.resolvedType, |
| 1147 | PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS, |
| 1148 | UserHandle.getCallingUserId()).getList(); |
| 1149 | |
| 1150 | // Look for the original activity in the list... |
| 1151 | final int N = resolves != null ? resolves.size() : 0; |
| 1152 | for (int i=0; i<N; i++) { |
| 1153 | ResolveInfo rInfo = resolves.get(i); |
| 1154 | if (rInfo.activityInfo.packageName.equals(r.packageName) |
| 1155 | && rInfo.activityInfo.name.equals(r.info.name)) { |
| 1156 | // We found the current one... the next matching is |
| 1157 | // after it. |
| 1158 | i++; |
| 1159 | if (i<N) { |
| 1160 | aInfo = resolves.get(i).activityInfo; |
| 1161 | } |
| 1162 | if (debug) { |
| 1163 | Slog.v(TAG, "Next matching activity: found current " + r.packageName |
| 1164 | + "/" + r.info.name); |
| 1165 | Slog.v(TAG, "Next matching activity: next is " + ((aInfo == null) |
| 1166 | ? "null" : aInfo.packageName + "/" + aInfo.name)); |
| 1167 | } |
| 1168 | break; |
| 1169 | } |
| 1170 | } |
| 1171 | } catch (RemoteException e) { |
| 1172 | } |
| 1173 | |
| 1174 | if (aInfo == null) { |
| 1175 | // Nobody who is next! |
| 1176 | SafeActivityOptions.abort(options); |
| 1177 | if (debug) Slog.d(TAG, "Next matching activity: nothing found"); |
| 1178 | return false; |
| 1179 | } |
| 1180 | |
| 1181 | intent.setComponent(new ComponentName( |
| 1182 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1183 | intent.setFlags(intent.getFlags()&~( |
| 1184 | Intent.FLAG_ACTIVITY_FORWARD_RESULT| |
| 1185 | Intent.FLAG_ACTIVITY_CLEAR_TOP| |
| 1186 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK| |
| 1187 | FLAG_ACTIVITY_NEW_TASK)); |
| 1188 | |
| 1189 | // Okay now we need to start the new activity, replacing the currently running activity. |
| 1190 | // This is a little tricky because we want to start the new one as if the current one is |
| 1191 | // finished, but not finish the current one first so that there is no flicker. |
| 1192 | // And thus... |
| 1193 | final boolean wasFinishing = r.finishing; |
| 1194 | r.finishing = true; |
| 1195 | |
| 1196 | // Propagate reply information over to the new activity. |
| 1197 | final ActivityRecord resultTo = r.resultTo; |
| 1198 | final String resultWho = r.resultWho; |
| 1199 | final int requestCode = r.requestCode; |
| 1200 | r.resultTo = null; |
| 1201 | if (resultTo != null) { |
| 1202 | resultTo.removeResultsLocked(r, resultWho, requestCode); |
| 1203 | } |
| 1204 | |
| 1205 | final long origId = Binder.clearCallingIdentity(); |
| 1206 | // TODO(b/64750076): Check if calling pid should really be -1. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1207 | final int res = getActivityStartController() |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1208 | .obtainStarter(intent, "startNextMatchingActivity") |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1209 | .setCaller(r.app.getThread()) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1210 | .setResolvedType(r.resolvedType) |
| 1211 | .setActivityInfo(aInfo) |
| 1212 | .setResultTo(resultTo != null ? resultTo.appToken : null) |
| 1213 | .setResultWho(resultWho) |
| 1214 | .setRequestCode(requestCode) |
| 1215 | .setCallingPid(-1) |
| 1216 | .setCallingUid(r.launchedFromUid) |
| 1217 | .setCallingPackage(r.launchedFromPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1218 | .setCallingFeatureId(r.launchedFromFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1219 | .setRealCallingPid(-1) |
| 1220 | .setRealCallingUid(r.launchedFromUid) |
| 1221 | .setActivityOptions(options) |
| 1222 | .execute(); |
| 1223 | Binder.restoreCallingIdentity(origId); |
| 1224 | |
| 1225 | r.finishing = wasFinishing; |
| 1226 | if (res != ActivityManager.START_SUCCESS) { |
| 1227 | return false; |
| 1228 | } |
| 1229 | return true; |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | @Override |
| 1234 | public final WaitResult startActivityAndWait(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1235 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1236 | String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, |
| 1237 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1238 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1239 | final WaitResult res = new WaitResult(); |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1240 | enforceNotIsolatedCaller("startActivityAndWait"); |
| 1241 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 1242 | userId, "startActivityAndWait"); |
| 1243 | // TODO: Switch to user app stacks here. |
| 1244 | getActivityStartController().obtainStarter(intent, "startActivityAndWait") |
| 1245 | .setCaller(caller) |
| 1246 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1247 | .setCallingFeatureId(callingFeatureId) |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1248 | .setResolvedType(resolvedType) |
| 1249 | .setResultTo(resultTo) |
| 1250 | .setResultWho(resultWho) |
| 1251 | .setRequestCode(requestCode) |
| 1252 | .setStartFlags(startFlags) |
| 1253 | .setActivityOptions(bOptions) |
| 1254 | .setUserId(userId) |
| 1255 | .setProfilerInfo(profilerInfo) |
| 1256 | .setWaitResult(res) |
| 1257 | .execute(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1258 | return res; |
| 1259 | } |
| 1260 | |
| 1261 | @Override |
| 1262 | public final int startActivityWithConfig(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1263 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1264 | String resultWho, int requestCode, int startFlags, Configuration config, |
| 1265 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1266 | assertPackageMatchesCallingUid(callingPackage); |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1267 | enforceNotIsolatedCaller("startActivityWithConfig"); |
| 1268 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, |
| 1269 | "startActivityWithConfig"); |
| 1270 | // TODO: Switch to user app stacks here. |
| 1271 | return getActivityStartController().obtainStarter(intent, "startActivityWithConfig") |
| 1272 | .setCaller(caller) |
| 1273 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1274 | .setCallingFeatureId(callingFeatureId) |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1275 | .setResolvedType(resolvedType) |
| 1276 | .setResultTo(resultTo) |
| 1277 | .setResultWho(resultWho) |
| 1278 | .setRequestCode(requestCode) |
| 1279 | .setStartFlags(startFlags) |
| 1280 | .setGlobalConfiguration(config) |
| 1281 | .setActivityOptions(bOptions) |
| 1282 | .setUserId(userId) |
| 1283 | .execute(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 1286 | @Override |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1287 | public IBinder requestStartActivityPermissionToken(IBinder delegatorToken) { |
| 1288 | int callingUid = Binder.getCallingUid(); |
| 1289 | if (UserHandle.getAppId(callingUid) != SYSTEM_UID) { |
| 1290 | throw new SecurityException("Only the system process can request a permission token, " |
| 1291 | + "received request from uid: " + callingUid); |
| 1292 | } |
| 1293 | IBinder permissionToken = new Binder(); |
| 1294 | synchronized (mGlobalLock) { |
| 1295 | mStartActivitySources.put(permissionToken, delegatorToken); |
| 1296 | } |
| 1297 | |
| 1298 | Message expireMsg = PooledLambda.obtainMessage( |
| 1299 | ActivityTaskManagerService::expireStartAsCallerTokenMsg, this, permissionToken); |
| 1300 | mUiHandler.sendMessageDelayed(expireMsg, START_AS_CALLER_TOKEN_TIMEOUT_IMPL); |
| 1301 | |
| 1302 | Message forgetMsg = PooledLambda.obtainMessage( |
| 1303 | ActivityTaskManagerService::forgetStartAsCallerTokenMsg, this, permissionToken); |
| 1304 | mUiHandler.sendMessageDelayed(forgetMsg, START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT); |
| 1305 | |
| 1306 | return permissionToken; |
| 1307 | } |
| 1308 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1309 | @Override |
| 1310 | public final int startActivityAsCaller(IApplicationThread caller, String callingPackage, |
| 1311 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1312 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, IBinder permissionToken, |
| 1313 | boolean ignoreTargetSecurity, int userId) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1314 | // This is very dangerous -- it allows you to perform a start activity (including |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1315 | // permission grants) as any app that may launch one of your own activities. So we only |
| 1316 | // allow this in two cases: |
| 1317 | // 1) The caller is an activity that is part of the core framework, and then only when it |
| 1318 | // is running as the system. |
| 1319 | // 2) The caller provides a valid permissionToken. Permission tokens are one-time use and |
| 1320 | // can only be requested by a system activity, which may then delegate this call to |
| 1321 | // another app. |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1322 | final ActivityRecord sourceRecord; |
| 1323 | final int targetUid; |
| 1324 | final String targetPackage; |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1325 | final String targetFeatureId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1326 | final boolean isResolver; |
| 1327 | synchronized (mGlobalLock) { |
| 1328 | if (resultTo == null) { |
| 1329 | throw new SecurityException("Must be called from an activity"); |
| 1330 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1331 | final IBinder sourceToken; |
| 1332 | if (permissionToken != null) { |
| 1333 | // To even attempt to use a permissionToken, an app must also have this signature |
| 1334 | // permission. |
| 1335 | mAmInternal.enforceCallingPermission( |
| 1336 | android.Manifest.permission.START_ACTIVITY_AS_CALLER, |
| 1337 | "startActivityAsCaller"); |
| 1338 | // If called with a permissionToken, we want the sourceRecord from the delegator |
| 1339 | // activity that requested this token. |
| 1340 | sourceToken = mStartActivitySources.remove(permissionToken); |
| 1341 | if (sourceToken == null) { |
| 1342 | // Invalid permissionToken, check if it recently expired. |
| 1343 | if (mExpiredStartAsCallerTokens.contains(permissionToken)) { |
| 1344 | throw new SecurityException("Called with expired permission token: " |
| 1345 | + permissionToken); |
| 1346 | } else { |
| 1347 | throw new SecurityException("Called with invalid permission token: " |
| 1348 | + permissionToken); |
| 1349 | } |
| 1350 | } |
| 1351 | } else { |
| 1352 | // This method was called directly by the source. |
| 1353 | sourceToken = resultTo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1354 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1355 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1356 | sourceRecord = mRootWindowContainer.isInAnyStack(sourceToken); |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1357 | if (sourceRecord == null) { |
| 1358 | throw new SecurityException("Called with bad activity token: " + sourceToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1359 | } |
| 1360 | if (sourceRecord.app == null) { |
| 1361 | throw new SecurityException("Called without a process attached to activity"); |
| 1362 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1363 | |
| 1364 | // Whether called directly or from a delegate, the source activity must be from the |
| 1365 | // android package. |
| 1366 | if (!sourceRecord.info.packageName.equals("android")) { |
| 1367 | throw new SecurityException("Must be called from an activity that is " |
| 1368 | + "declared in the android package"); |
| 1369 | } |
| 1370 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1371 | if (UserHandle.getAppId(sourceRecord.app.mUid) != SYSTEM_UID) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1372 | // This is still okay, as long as this activity is running under the |
| 1373 | // uid of the original calling activity. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1374 | if (sourceRecord.app.mUid != sourceRecord.launchedFromUid) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1375 | throw new SecurityException( |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1376 | "Calling activity in uid " + sourceRecord.app.mUid |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1377 | + " must be system uid or original calling uid " |
| 1378 | + sourceRecord.launchedFromUid); |
| 1379 | } |
| 1380 | } |
| 1381 | if (ignoreTargetSecurity) { |
| 1382 | if (intent.getComponent() == null) { |
| 1383 | throw new SecurityException( |
| 1384 | "Component must be specified with ignoreTargetSecurity"); |
| 1385 | } |
| 1386 | if (intent.getSelector() != null) { |
| 1387 | throw new SecurityException( |
| 1388 | "Selector not allowed with ignoreTargetSecurity"); |
| 1389 | } |
| 1390 | } |
| 1391 | targetUid = sourceRecord.launchedFromUid; |
| 1392 | targetPackage = sourceRecord.launchedFromPackage; |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1393 | targetFeatureId = sourceRecord.launchedFromFeatureId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1394 | isResolver = sourceRecord.isResolverOrChildActivity(); |
| 1395 | } |
| 1396 | |
| 1397 | if (userId == UserHandle.USER_NULL) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1398 | userId = UserHandle.getUserId(sourceRecord.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | // TODO: Switch to user app stacks here. |
| 1402 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1403 | return getActivityStartController().obtainStarter(intent, "startActivityAsCaller") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1404 | .setCallingUid(targetUid) |
| 1405 | .setCallingPackage(targetPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1406 | .setCallingFeatureId(targetFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1407 | .setResolvedType(resolvedType) |
| 1408 | .setResultTo(resultTo) |
| 1409 | .setResultWho(resultWho) |
| 1410 | .setRequestCode(requestCode) |
| 1411 | .setStartFlags(startFlags) |
| 1412 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1413 | .setUserId(userId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1414 | .setIgnoreTargetSecurity(ignoreTargetSecurity) |
| 1415 | .setFilterCallingUid(isResolver ? 0 /* system */ : targetUid) |
Alan Stokes | 2f4a4ed | 2019-05-08 16:56:45 +0100 | [diff] [blame] | 1416 | // The target may well be in the background, which would normally prevent it |
| 1417 | // from starting an activity. Here we definitely want the start to succeed. |
| 1418 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1419 | .execute(); |
| 1420 | } catch (SecurityException e) { |
| 1421 | // XXX need to figure out how to propagate to original app. |
| 1422 | // A SecurityException here is generally actually a fault of the original |
| 1423 | // calling activity (such as a fairly granting permissions), so propagate it |
| 1424 | // back to them. |
| 1425 | /* |
| 1426 | StringBuilder msg = new StringBuilder(); |
| 1427 | msg.append("While launching"); |
| 1428 | msg.append(intent.toString()); |
| 1429 | msg.append(": "); |
| 1430 | msg.append(e.getMessage()); |
| 1431 | */ |
| 1432 | throw e; |
| 1433 | } |
| 1434 | } |
| 1435 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1436 | int handleIncomingUser(int callingPid, int callingUid, int userId, String name) { |
| 1437 | return mAmInternal.handleIncomingUser(callingPid, callingUid, userId, false /* allowAll */, |
Jonathan Scott | 9233534 | 2019-12-17 14:46:26 +0000 | [diff] [blame] | 1438 | ALLOW_NON_FULL, name, null /* callerPackage */); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1441 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1442 | public int startVoiceActivity(String callingPackage, String callingFeatureId, int callingPid, |
| 1443 | int callingUid, Intent intent, String resolvedType, IVoiceInteractionSession session, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1444 | IVoiceInteractor interactor, int startFlags, ProfilerInfo profilerInfo, |
| 1445 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1446 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1447 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startVoiceActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1448 | if (session == null || interactor == null) { |
| 1449 | throw new NullPointerException("null session or interactor"); |
| 1450 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1451 | userId = handleIncomingUser(callingPid, callingUid, userId, "startVoiceActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1452 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1453 | return getActivityStartController().obtainStarter(intent, "startVoiceActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1454 | .setCallingUid(callingUid) |
| 1455 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1456 | .setCallingFeatureId(callingFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1457 | .setResolvedType(resolvedType) |
| 1458 | .setVoiceSession(session) |
| 1459 | .setVoiceInteractor(interactor) |
| 1460 | .setStartFlags(startFlags) |
| 1461 | .setProfilerInfo(profilerInfo) |
| 1462 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1463 | .setUserId(userId) |
Michal Karpinski | 85fa202 | 2019-02-08 12:05:09 +0000 | [diff] [blame] | 1464 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1465 | .execute(); |
| 1466 | } |
| 1467 | |
| 1468 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1469 | public int startAssistantActivity(String callingPackage, @NonNull String callingFeatureId, |
| 1470 | int callingPid, int callingUid, Intent intent, String resolvedType, Bundle bOptions, |
| 1471 | int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1472 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1473 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startAssistantActivity()"); |
| 1474 | userId = handleIncomingUser(callingPid, callingUid, userId, "startAssistantActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1475 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1476 | return getActivityStartController().obtainStarter(intent, "startAssistantActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1477 | .setCallingUid(callingUid) |
| 1478 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1479 | .setCallingFeatureId(callingFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1480 | .setResolvedType(resolvedType) |
| 1481 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1482 | .setUserId(userId) |
Michal Karpinski | 85fa202 | 2019-02-08 12:05:09 +0000 | [diff] [blame] | 1483 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1484 | .execute(); |
| 1485 | } |
| 1486 | |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1487 | /** |
| 1488 | * Start the recents activity to perform the recents animation. |
| 1489 | * |
| 1490 | * @param intent The intent to start the recents activity. |
| 1491 | * @param recentsAnimationRunner Pass {@code null} to only preload the activity. |
| 1492 | */ |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1493 | @Override |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1494 | public void startRecentsActivity(Intent intent, @Deprecated IAssistDataReceiver unused, |
| 1495 | @Nullable IRecentsAnimationRunner recentsAnimationRunner) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1496 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "startRecentsActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1497 | final int callingPid = Binder.getCallingPid(); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1498 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1499 | final long origId = Binder.clearCallingIdentity(); |
| 1500 | try { |
| 1501 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 1502 | final ComponentName recentsComponent = mRecentTasks.getRecentsComponent(); |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1503 | final String recentsFeatureId = mRecentTasks.getRecentsComponentFeatureId(); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 1504 | final int recentsUid = mRecentTasks.getRecentsComponentUid(); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1505 | final WindowProcessController caller = getProcessController(callingPid, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1506 | |
| 1507 | // Start a new recents animation |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1508 | final RecentsAnimation anim = new RecentsAnimation(this, mStackSupervisor, |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1509 | getActivityStartController(), mWindowManager, intent, recentsComponent, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1510 | recentsFeatureId, recentsUid, caller); |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1511 | if (recentsAnimationRunner == null) { |
| 1512 | anim.preloadRecentsActivity(); |
| 1513 | } else { |
| 1514 | anim.startRecentsActivity(recentsAnimationRunner); |
| 1515 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1516 | } |
| 1517 | } finally { |
| 1518 | Binder.restoreCallingIdentity(origId); |
| 1519 | } |
| 1520 | } |
| 1521 | |
| 1522 | @Override |
| 1523 | public final int startActivityFromRecents(int taskId, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1524 | enforceCallerIsRecentsOrHasPermission(START_TASKS_FROM_RECENTS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1525 | "startActivityFromRecents()"); |
| 1526 | |
| 1527 | final int callingPid = Binder.getCallingPid(); |
| 1528 | final int callingUid = Binder.getCallingUid(); |
| 1529 | final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(bOptions); |
| 1530 | final long origId = Binder.clearCallingIdentity(); |
| 1531 | try { |
| 1532 | synchronized (mGlobalLock) { |
| 1533 | return mStackSupervisor.startActivityFromRecents(callingPid, callingUid, taskId, |
| 1534 | safeOptions); |
| 1535 | } |
| 1536 | } finally { |
| 1537 | Binder.restoreCallingIdentity(origId); |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | /** |
Andrii Kulian | 2eb84b2 | 2018-12-13 18:18:54 -0800 | [diff] [blame] | 1542 | * Public API to check if the client is allowed to start an activity on specified display. |
| 1543 | * |
| 1544 | * If the target display is private or virtual, some restrictions will apply. |
| 1545 | * |
| 1546 | * @param displayId Target display id. |
| 1547 | * @param intent Intent used to launch the activity. |
| 1548 | * @param resolvedType The MIME type of the intent. |
| 1549 | * @param userId The id of the user for whom the call is made. |
| 1550 | * @return {@code true} if a call to start an activity on the target display should succeed and |
| 1551 | * no {@link SecurityException} will be thrown, {@code false} otherwise. |
| 1552 | */ |
| 1553 | @Override |
| 1554 | public final boolean isActivityStartAllowedOnDisplay(int displayId, Intent intent, |
| 1555 | String resolvedType, int userId) { |
| 1556 | final int callingUid = Binder.getCallingUid(); |
| 1557 | final int callingPid = Binder.getCallingPid(); |
| 1558 | final long origId = Binder.clearCallingIdentity(); |
| 1559 | |
| 1560 | try { |
| 1561 | // Collect information about the target of the Intent. |
| 1562 | ActivityInfo aInfo = mStackSupervisor.resolveActivity(intent, resolvedType, |
| 1563 | 0 /* startFlags */, null /* profilerInfo */, userId, |
| 1564 | ActivityStarter.computeResolveFilterUid(callingUid, callingUid, |
| 1565 | UserHandle.USER_NULL)); |
| 1566 | aInfo = mAmInternal.getActivityInfoForUser(aInfo, userId); |
| 1567 | |
| 1568 | synchronized (mGlobalLock) { |
| 1569 | return mStackSupervisor.canPlaceEntityOnDisplay(displayId, callingPid, callingUid, |
| 1570 | aInfo); |
| 1571 | } |
| 1572 | } finally { |
| 1573 | Binder.restoreCallingIdentity(origId); |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | /** |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1578 | * This is the internal entry point for handling Activity.finish(). |
| 1579 | * |
| 1580 | * @param token The Binder token referencing the Activity we want to finish. |
| 1581 | * @param resultCode Result code, if any, from this Activity. |
| 1582 | * @param resultData Result data (Intent), if any, from this Activity. |
| 1583 | * @param finishTask Whether to finish the task associated with this Activity. |
| 1584 | * |
| 1585 | * @return Returns true if the activity successfully finished, or false if it is still running. |
| 1586 | */ |
| 1587 | @Override |
| 1588 | public final boolean finishActivity(IBinder token, int resultCode, Intent resultData, |
| 1589 | int finishTask) { |
| 1590 | // Refuse possible leaked file descriptors |
| 1591 | if (resultData != null && resultData.hasFileDescriptors()) { |
| 1592 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1593 | } |
| 1594 | |
| 1595 | synchronized (mGlobalLock) { |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 1596 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1597 | if (r == null) { |
| 1598 | return true; |
| 1599 | } |
| 1600 | // Keep track of the root activity of the task before we finish it |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1601 | final Task tr = r.getTask(); |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 1602 | final ActivityRecord rootR = tr.getRootActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1603 | if (rootR == null) { |
| 1604 | Slog.w(TAG, "Finishing task with all activities already finished"); |
| 1605 | } |
| 1606 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps can |
| 1607 | // finish. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1608 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1609 | return false; |
| 1610 | } |
| 1611 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1612 | // TODO: There is a dup. of this block of code in ActivityStack.navigateUpToLocked |
| 1613 | // We should consolidate. |
| 1614 | if (mController != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1615 | // Find the first activity that is not finishing. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1616 | final ActivityRecord next = |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 1617 | r.getRootTask().topRunningActivity(token, INVALID_TASK_ID); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1618 | if (next != null) { |
| 1619 | // ask watcher if this is allowed |
| 1620 | boolean resumeOK = true; |
| 1621 | try { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1622 | resumeOK = mController.activityResuming(next.packageName); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1623 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1624 | mController = null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1625 | Watchdog.getInstance().setActivityController(null); |
| 1626 | } |
| 1627 | |
| 1628 | if (!resumeOK) { |
| 1629 | Slog.i(TAG, "Not finishing activity because controller resumed"); |
| 1630 | return false; |
| 1631 | } |
| 1632 | } |
| 1633 | } |
Michal Karpinski | fc6872e | 2019-05-21 15:18:44 +0100 | [diff] [blame] | 1634 | |
| 1635 | // note down that the process has finished an activity and is in background activity |
| 1636 | // starts grace period |
| 1637 | if (r.app != null) { |
| 1638 | r.app.setLastActivityFinishTimeIfNeeded(SystemClock.uptimeMillis()); |
| 1639 | } |
| 1640 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1641 | final long origId = Binder.clearCallingIdentity(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1642 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "finishActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1643 | try { |
| 1644 | boolean res; |
| 1645 | final boolean finishWithRootActivity = |
| 1646 | finishTask == Activity.FINISH_TASK_WITH_ROOT_ACTIVITY; |
| 1647 | if (finishTask == Activity.FINISH_TASK_WITH_ACTIVITY |
| 1648 | || (finishWithRootActivity && r == rootR)) { |
| 1649 | // If requested, remove the task that is associated to this activity only if it |
| 1650 | // was the root activity in the task. The result code and data is ignored |
| 1651 | // because we don't support returning them across task boundaries. Also, to |
| 1652 | // keep backwards compatibility we remove the task from recents when finishing |
| 1653 | // task with root activity. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1654 | mStackSupervisor.removeTask(tr, false /*killProcess*/, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1655 | finishWithRootActivity, "finish-activity"); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1656 | res = true; |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 1657 | // Explicitly dismissing the activity so reset its relaunch flag. |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 1658 | r.mRelaunchReason = RELAUNCH_REASON_NONE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1659 | } else { |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 1660 | r.finishIfPossible(resultCode, resultData, "app-request", true /* oomAdj */); |
Andrii Kulian | 40eda67 | 2019-07-30 15:05:57 -0700 | [diff] [blame] | 1661 | res = r.finishing; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1662 | if (!res) { |
| 1663 | Slog.i(TAG, "Failed to finish by app-request"); |
| 1664 | } |
| 1665 | } |
| 1666 | return res; |
| 1667 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1668 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1669 | Binder.restoreCallingIdentity(origId); |
| 1670 | } |
| 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | @Override |
| 1675 | public boolean finishActivityAffinity(IBinder token) { |
| 1676 | synchronized (mGlobalLock) { |
| 1677 | final long origId = Binder.clearCallingIdentity(); |
| 1678 | try { |
| 1679 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1680 | if (r == null) { |
| 1681 | return false; |
| 1682 | } |
| 1683 | |
| 1684 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps |
| 1685 | // can finish. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1686 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1687 | return false; |
| 1688 | } |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1689 | |
| 1690 | final PooledFunction p = PooledLambda.obtainFunction( |
| 1691 | ActivityRecord::finishIfSameAffinity, r, |
| 1692 | PooledLambda.__(ActivityRecord.class)); |
| 1693 | r.getTask().forAllActivities( |
| 1694 | p, r, true /*includeBoundary*/, true /*traverseTopToBottom*/); |
| 1695 | p.recycle(); |
| 1696 | |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 1697 | return true; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1698 | } finally { |
| 1699 | Binder.restoreCallingIdentity(origId); |
| 1700 | } |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | @Override |
| 1705 | public final void activityIdle(IBinder token, Configuration config, boolean stopProfiling) { |
| 1706 | final long origId = Binder.clearCallingIdentity(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1707 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1708 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1709 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityIdle"); |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 1710 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 1711 | if (r == null) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1712 | return; |
| 1713 | } |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 1714 | mStackSupervisor.activityIdleInternal(r, false /* fromTimeout */, |
| 1715 | false /* processPausingActivities */, config); |
| 1716 | if (stopProfiling && r.hasProcess()) { |
| 1717 | r.app.clearProfilerIfNeeded(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1718 | } |
| 1719 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1720 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1721 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1722 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1723 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | @Override |
| 1727 | public final void activityResumed(IBinder token) { |
| 1728 | final long origId = Binder.clearCallingIdentity(); |
| 1729 | synchronized (mGlobalLock) { |
| 1730 | ActivityRecord.activityResumedLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1731 | } |
| 1732 | Binder.restoreCallingIdentity(origId); |
| 1733 | } |
| 1734 | |
| 1735 | @Override |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 1736 | public final void activityTopResumedStateLost() { |
| 1737 | final long origId = Binder.clearCallingIdentity(); |
| 1738 | synchronized (mGlobalLock) { |
| 1739 | mStackSupervisor.handleTopResumedStateReleased(false /* timeout */); |
| 1740 | } |
| 1741 | Binder.restoreCallingIdentity(origId); |
| 1742 | } |
| 1743 | |
| 1744 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1745 | public final void activityPaused(IBinder token) { |
| 1746 | final long origId = Binder.clearCallingIdentity(); |
| 1747 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1748 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityPaused"); |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 1749 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 1750 | if (r != null) { |
| 1751 | r.activityPaused(false); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1752 | } |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1753 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1754 | } |
| 1755 | Binder.restoreCallingIdentity(origId); |
| 1756 | } |
| 1757 | |
| 1758 | @Override |
| 1759 | public final void activityStopped(IBinder token, Bundle icicle, |
| 1760 | PersistableBundle persistentState, CharSequence description) { |
| 1761 | if (DEBUG_ALL) Slog.v(TAG, "Activity stopped: token=" + token); |
| 1762 | |
| 1763 | // Refuse possible leaked file descriptors |
| 1764 | if (icicle != null && icicle.hasFileDescriptors()) { |
| 1765 | throw new IllegalArgumentException("File descriptors passed in Bundle"); |
| 1766 | } |
| 1767 | |
| 1768 | final long origId = Binder.clearCallingIdentity(); |
| 1769 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1770 | String restartingName = null; |
| 1771 | int restartingUid = 0; |
| 1772 | final ActivityRecord r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1773 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1774 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityStopped"); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1775 | r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1776 | if (r != null) { |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1777 | if (r.attachedToProcess() |
| 1778 | && r.isState(ActivityStack.ActivityState.RESTARTING_PROCESS)) { |
| 1779 | // The activity was requested to restart from |
| 1780 | // {@link #restartActivityProcessIfVisible}. |
| 1781 | restartingName = r.app.mName; |
| 1782 | restartingUid = r.app.mUid; |
| 1783 | } |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 1784 | r.activityStopped(icicle, persistentState, description); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1785 | } |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1786 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1789 | if (restartingName != null) { |
| 1790 | // In order to let the foreground activity can be restarted with its saved state from |
| 1791 | // {@link android.app.Activity#onSaveInstanceState}, the kill operation is postponed |
| 1792 | // until the activity reports stopped with the state. And the activity record will be |
| 1793 | // kept because the record state is restarting, then the activity will be restarted |
| 1794 | // immediately if it is still the top one. |
| 1795 | mStackSupervisor.removeRestartTimeouts(r); |
| 1796 | mAmInternal.killProcess(restartingName, restartingUid, "restartActivityProcess"); |
| 1797 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1798 | mAmInternal.trimApplications(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1799 | |
| 1800 | Binder.restoreCallingIdentity(origId); |
| 1801 | } |
| 1802 | |
| 1803 | @Override |
| 1804 | public final void activityDestroyed(IBinder token) { |
| 1805 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "ACTIVITY DESTROYED: " + token); |
| 1806 | synchronized (mGlobalLock) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1807 | final long origId = Binder.clearCallingIdentity(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1808 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityDestroyed"); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1809 | try { |
| 1810 | final ActivityRecord activity = ActivityRecord.forTokenLocked(token); |
| 1811 | if (activity != null) { |
| 1812 | activity.destroyed("activityDestroyed"); |
| 1813 | } |
| 1814 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1815 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1816 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1817 | } |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | @Override |
| 1822 | public final void activityRelaunched(IBinder token) { |
| 1823 | final long origId = Binder.clearCallingIdentity(); |
| 1824 | synchronized (mGlobalLock) { |
| 1825 | mStackSupervisor.activityRelaunchedLocked(token); |
| 1826 | } |
| 1827 | Binder.restoreCallingIdentity(origId); |
| 1828 | } |
| 1829 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1830 | @Override |
| 1831 | public void setRequestedOrientation(IBinder token, int requestedOrientation) { |
| 1832 | synchronized (mGlobalLock) { |
| 1833 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1834 | if (r == null) { |
| 1835 | return; |
| 1836 | } |
| 1837 | final long origId = Binder.clearCallingIdentity(); |
| 1838 | try { |
| 1839 | r.setRequestedOrientation(requestedOrientation); |
| 1840 | } finally { |
| 1841 | Binder.restoreCallingIdentity(origId); |
| 1842 | } |
| 1843 | } |
| 1844 | } |
| 1845 | |
| 1846 | @Override |
| 1847 | public int getRequestedOrientation(IBinder token) { |
| 1848 | synchronized (mGlobalLock) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1849 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1850 | return (r != null) |
| 1851 | ? r.getRequestedOrientation() : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | @Override |
| 1856 | public void setImmersive(IBinder token, boolean immersive) { |
| 1857 | synchronized (mGlobalLock) { |
| 1858 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1859 | if (r == null) { |
| 1860 | throw new IllegalArgumentException(); |
| 1861 | } |
| 1862 | r.immersive = immersive; |
| 1863 | |
| 1864 | // update associated state if we're frontmost |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1865 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1866 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, "Frontmost changed immersion: "+ r); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1867 | applyUpdateLockStateLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1868 | } |
| 1869 | } |
| 1870 | } |
| 1871 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1872 | void applyUpdateLockStateLocked(ActivityRecord r) { |
| 1873 | // Modifications to the UpdateLock state are done on our handler, outside |
| 1874 | // the activity manager's locks. The new state is determined based on the |
| 1875 | // state *now* of the relevant activity record. The object is passed to |
| 1876 | // the handler solely for logging detail, not to be consulted/modified. |
| 1877 | final boolean nextState = r != null && r.immersive; |
| 1878 | mH.post(() -> { |
| 1879 | if (mUpdateLock.isHeld() != nextState) { |
| 1880 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, |
| 1881 | "Applying new update lock state '" + nextState + "' for " + r); |
| 1882 | if (nextState) { |
| 1883 | mUpdateLock.acquire(); |
| 1884 | } else { |
| 1885 | mUpdateLock.release(); |
| 1886 | } |
| 1887 | } |
| 1888 | }); |
| 1889 | } |
| 1890 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1891 | @Override |
| 1892 | public boolean isImmersive(IBinder token) { |
| 1893 | synchronized (mGlobalLock) { |
| 1894 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1895 | if (r == null) { |
| 1896 | throw new IllegalArgumentException(); |
| 1897 | } |
| 1898 | return r.immersive; |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | @Override |
| 1903 | public boolean isTopActivityImmersive() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1904 | enforceNotIsolatedCaller("isTopActivityImmersive"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1905 | synchronized (mGlobalLock) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1906 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1907 | return (r != null) ? r.immersive : false; |
| 1908 | } |
| 1909 | } |
| 1910 | |
| 1911 | @Override |
| 1912 | public void overridePendingTransition(IBinder token, String packageName, |
| 1913 | int enterAnim, int exitAnim) { |
| 1914 | synchronized (mGlobalLock) { |
| 1915 | ActivityRecord self = ActivityRecord.isInStackLocked(token); |
| 1916 | if (self == null) { |
| 1917 | return; |
| 1918 | } |
| 1919 | |
| 1920 | final long origId = Binder.clearCallingIdentity(); |
| 1921 | |
| 1922 | if (self.isState( |
| 1923 | ActivityStack.ActivityState.RESUMED, ActivityStack.ActivityState.PAUSING)) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1924 | self.getDisplay().mDisplayContent.mAppTransition.overridePendingAppTransition( |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1925 | packageName, enterAnim, exitAnim, null); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | Binder.restoreCallingIdentity(origId); |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | @Override |
| 1933 | public int getFrontActivityScreenCompatMode() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1934 | enforceNotIsolatedCaller("getFrontActivityScreenCompatMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1935 | synchronized (mGlobalLock) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1936 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivity(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1937 | if (r == null) { |
| 1938 | return ActivityManager.COMPAT_MODE_UNKNOWN; |
| 1939 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1940 | return mCompatModePackages.computeCompatModeLocked(r.info.applicationInfo); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | @Override |
| 1945 | public void setFrontActivityScreenCompatMode(int mode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1946 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1947 | "setFrontActivityScreenCompatMode"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1948 | ApplicationInfo ai; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1949 | synchronized (mGlobalLock) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1950 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivity(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1951 | if (r == null) { |
| 1952 | Slog.w(TAG, "setFrontActivityScreenCompatMode failed: no top activity"); |
| 1953 | return; |
| 1954 | } |
| 1955 | ai = r.info.applicationInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1956 | mCompatModePackages.setPackageScreenCompatModeLocked(ai, mode); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1957 | } |
| 1958 | } |
| 1959 | |
| 1960 | @Override |
| 1961 | public int getLaunchedFromUid(IBinder activityToken) { |
| 1962 | ActivityRecord srec; |
| 1963 | synchronized (mGlobalLock) { |
| 1964 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 1965 | } |
| 1966 | if (srec == null) { |
| 1967 | return -1; |
| 1968 | } |
| 1969 | return srec.launchedFromUid; |
| 1970 | } |
| 1971 | |
| 1972 | @Override |
| 1973 | public String getLaunchedFromPackage(IBinder activityToken) { |
| 1974 | ActivityRecord srec; |
| 1975 | synchronized (mGlobalLock) { |
| 1976 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 1977 | } |
| 1978 | if (srec == null) { |
| 1979 | return null; |
| 1980 | } |
| 1981 | return srec.launchedFromPackage; |
| 1982 | } |
| 1983 | |
| 1984 | @Override |
| 1985 | public boolean convertFromTranslucent(IBinder token) { |
| 1986 | final long origId = Binder.clearCallingIdentity(); |
| 1987 | try { |
| 1988 | synchronized (mGlobalLock) { |
| 1989 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1990 | if (r == null) { |
| 1991 | return false; |
| 1992 | } |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 1993 | return r.setOccludesParent(true); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1994 | } |
| 1995 | } finally { |
| 1996 | Binder.restoreCallingIdentity(origId); |
| 1997 | } |
| 1998 | } |
| 1999 | |
| 2000 | @Override |
| 2001 | public boolean convertToTranslucent(IBinder token, Bundle options) { |
| 2002 | SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(options); |
| 2003 | final long origId = Binder.clearCallingIdentity(); |
| 2004 | try { |
| 2005 | synchronized (mGlobalLock) { |
| 2006 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2007 | if (r == null) { |
| 2008 | return false; |
| 2009 | } |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2010 | final ActivityRecord under = r.getTask().getActivityBelow(r); |
| 2011 | if (under != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2012 | under.returningOptions = safeOptions != null ? safeOptions.getOptions(r) : null; |
| 2013 | } |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 2014 | return r.setOccludesParent(false); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2015 | } |
| 2016 | } finally { |
| 2017 | Binder.restoreCallingIdentity(origId); |
| 2018 | } |
| 2019 | } |
| 2020 | |
| 2021 | @Override |
| 2022 | public void notifyActivityDrawn(IBinder token) { |
| 2023 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, "notifyActivityDrawn: token=" + token); |
| 2024 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2025 | ActivityRecord r = mRootWindowContainer.isInAnyStack(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2026 | if (r != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2027 | r.getRootTask().notifyActivityDrawnLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2028 | } |
| 2029 | } |
| 2030 | } |
| 2031 | |
| 2032 | @Override |
| 2033 | public void reportActivityFullyDrawn(IBinder token, boolean restoredFromBundle) { |
| 2034 | synchronized (mGlobalLock) { |
| 2035 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2036 | if (r == null) { |
| 2037 | return; |
| 2038 | } |
| 2039 | r.reportFullyDrawnLocked(restoredFromBundle); |
| 2040 | } |
| 2041 | } |
| 2042 | |
| 2043 | @Override |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2044 | public int getDisplayId(IBinder activityToken) throws RemoteException { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2045 | synchronized (mGlobalLock) { |
| 2046 | final ActivityStack stack = ActivityRecord.getStackLocked(activityToken); |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 2047 | if (stack != null) { |
| 2048 | final int displayId = stack.getDisplayId(); |
| 2049 | return displayId != INVALID_DISPLAY ? displayId : DEFAULT_DISPLAY; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2050 | } |
| 2051 | return DEFAULT_DISPLAY; |
| 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | @Override |
| 2056 | public ActivityManager.StackInfo getFocusedStackInfo() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2057 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2058 | long ident = Binder.clearCallingIdentity(); |
| 2059 | try { |
| 2060 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2061 | ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2062 | if (focusedStack != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2063 | return mRootWindowContainer.getStackInfo(focusedStack.mTaskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2064 | } |
| 2065 | return null; |
| 2066 | } |
| 2067 | } finally { |
| 2068 | Binder.restoreCallingIdentity(ident); |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | @Override |
| 2073 | public void setFocusedStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2074 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2075 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedStack: stackId=" + stackId); |
| 2076 | final long callingId = Binder.clearCallingIdentity(); |
| 2077 | try { |
| 2078 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2079 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2080 | if (stack == null) { |
| 2081 | Slog.w(TAG, "setFocusedStack: No stack with id=" + stackId); |
| 2082 | return; |
| 2083 | } |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2084 | final ActivityRecord r = stack.topRunningActivity(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2085 | if (r != null && r.moveFocusableActivityToTop("setFocusedStack")) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2086 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2087 | } |
| 2088 | } |
| 2089 | } finally { |
| 2090 | Binder.restoreCallingIdentity(callingId); |
| 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | @Override |
| 2095 | public void setFocusedTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2096 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2097 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedTask: taskId=" + taskId); |
| 2098 | final long callingId = Binder.clearCallingIdentity(); |
| 2099 | try { |
| 2100 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2101 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2102 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2103 | if (task == null) { |
| 2104 | return; |
| 2105 | } |
| 2106 | final ActivityRecord r = task.topRunningActivityLocked(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2107 | if (r != null && r.moveFocusableActivityToTop("setFocusedTask")) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2108 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2109 | } |
| 2110 | } |
| 2111 | } finally { |
| 2112 | Binder.restoreCallingIdentity(callingId); |
| 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | @Override |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2117 | public void restartActivityProcessIfVisible(IBinder activityToken) { |
| 2118 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "restartActivityProcess()"); |
| 2119 | final long callingId = Binder.clearCallingIdentity(); |
| 2120 | try { |
| 2121 | synchronized (mGlobalLock) { |
| 2122 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 2123 | if (r == null) { |
| 2124 | return; |
| 2125 | } |
| 2126 | r.restartProcessIfVisible(); |
| 2127 | } |
| 2128 | } finally { |
| 2129 | Binder.restoreCallingIdentity(callingId); |
| 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2134 | public boolean removeTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2135 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2136 | synchronized (mGlobalLock) { |
| 2137 | final long ident = Binder.clearCallingIdentity(); |
| 2138 | try { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2139 | return mStackSupervisor.removeTaskById(taskId, true, REMOVE_FROM_RECENTS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2140 | "remove-task"); |
| 2141 | } finally { |
| 2142 | Binder.restoreCallingIdentity(ident); |
| 2143 | } |
| 2144 | } |
| 2145 | } |
| 2146 | |
| 2147 | @Override |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 2148 | public void removeAllVisibleRecentTasks() { |
| 2149 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeAllVisibleRecentTasks()"); |
| 2150 | synchronized (mGlobalLock) { |
| 2151 | final long ident = Binder.clearCallingIdentity(); |
| 2152 | try { |
Winson Chung | 42fa21f | 2019-04-02 16:23:46 -0700 | [diff] [blame] | 2153 | getRecentTasks().removeAllVisibleTasks(mAmInternal.getCurrentUserId()); |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 2154 | } finally { |
| 2155 | Binder.restoreCallingIdentity(ident); |
| 2156 | } |
| 2157 | } |
| 2158 | } |
| 2159 | |
| 2160 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2161 | public boolean shouldUpRecreateTask(IBinder token, String destAffinity) { |
| 2162 | synchronized (mGlobalLock) { |
| 2163 | final ActivityRecord srec = ActivityRecord.forTokenLocked(token); |
| 2164 | if (srec != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2165 | return srec.getRootTask().shouldUpRecreateTaskLocked(srec, destAffinity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2166 | } |
| 2167 | } |
| 2168 | return false; |
| 2169 | } |
| 2170 | |
| 2171 | @Override |
| 2172 | public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode, |
| 2173 | Intent resultData) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2174 | |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 2175 | synchronized (mGlobalLock) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2176 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2177 | if (r != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2178 | return r.getRootTask().navigateUpTo( |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2179 | r, destIntent, resultCode, resultData); |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 2180 | } |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2181 | return false; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2182 | } |
| 2183 | } |
| 2184 | |
| 2185 | /** |
| 2186 | * Attempts to move a task backwards in z-order (the order of activities within the task is |
| 2187 | * unchanged). |
| 2188 | * |
| 2189 | * There are several possible results of this call: |
| 2190 | * - if the task is locked, then we will show the lock toast |
| 2191 | * - if there is a task behind the provided task, then that task is made visible and resumed as |
| 2192 | * this task is moved to the back |
| 2193 | * - otherwise, if there are no other tasks in the stack: |
| 2194 | * - if this task is in the pinned stack, then we remove the stack completely, which will |
| 2195 | * have the effect of moving the task to the top or bottom of the fullscreen stack |
| 2196 | * (depending on whether it is visible) |
| 2197 | * - otherwise, we simply return home and hide this task |
| 2198 | * |
| 2199 | * @param token A reference to the activity we wish to move |
| 2200 | * @param nonRoot If false then this only works if the activity is the root |
| 2201 | * of a task; if true it will work for any activity in a task. |
| 2202 | * @return Returns true if the move completed, false if not. |
| 2203 | */ |
| 2204 | @Override |
| 2205 | public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2206 | enforceNotIsolatedCaller("moveActivityTaskToBack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2207 | synchronized (mGlobalLock) { |
| 2208 | final long origId = Binder.clearCallingIdentity(); |
| 2209 | try { |
| 2210 | int taskId = ActivityRecord.getTaskForActivityLocked(token, !nonRoot); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2211 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2212 | if (task != null) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2213 | return ActivityRecord.getStackLocked(token).moveTaskToBack(task); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2214 | } |
| 2215 | } finally { |
| 2216 | Binder.restoreCallingIdentity(origId); |
| 2217 | } |
| 2218 | } |
| 2219 | return false; |
| 2220 | } |
| 2221 | |
| 2222 | @Override |
| 2223 | public Rect getTaskBounds(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2224 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getTaskBounds()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2225 | long ident = Binder.clearCallingIdentity(); |
| 2226 | Rect rect = new Rect(); |
| 2227 | try { |
| 2228 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2229 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2230 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2231 | if (task == null) { |
| 2232 | Slog.w(TAG, "getTaskBounds: taskId=" + taskId + " not found"); |
| 2233 | return rect; |
| 2234 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 2235 | if (task.getParent() != null) { |
| 2236 | rect.set(task.getBounds()); |
| 2237 | } else if (task.mLastNonFullscreenBounds != null) { |
| 2238 | rect.set(task.mLastNonFullscreenBounds); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2239 | } |
| 2240 | } |
| 2241 | } finally { |
| 2242 | Binder.restoreCallingIdentity(ident); |
| 2243 | } |
| 2244 | return rect; |
| 2245 | } |
| 2246 | |
| 2247 | @Override |
| 2248 | public ActivityManager.TaskDescription getTaskDescription(int id) { |
| 2249 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2250 | enforceCallerIsRecentsOrHasPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2251 | MANAGE_ACTIVITY_STACKS, "getTaskDescription()"); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2252 | final Task tr = mRootWindowContainer.anyTaskForId(id, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2253 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2254 | if (tr != null) { |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 2255 | return tr.getTaskDescription(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2256 | } |
| 2257 | } |
| 2258 | return null; |
| 2259 | } |
| 2260 | |
| 2261 | @Override |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2262 | public boolean setTaskWindowingMode(int taskId, int windowingMode, boolean toTop) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2263 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2264 | return setTaskWindowingModeSplitScreenPrimary(taskId, |
| 2265 | SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2266 | toTop, ANIMATE, null /* initialBounds */, true /* showRecents */); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2267 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2268 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setTaskWindowingMode()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2269 | synchronized (mGlobalLock) { |
| 2270 | final long ident = Binder.clearCallingIdentity(); |
| 2271 | try { |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2272 | if (WindowConfiguration.isSplitScreenWindowingMode(windowingMode)) { |
| 2273 | return setTaskWindowingModeSplitScreen(taskId, windowingMode, toTop); |
| 2274 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2275 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2276 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2277 | if (task == null) { |
| 2278 | Slog.w(TAG, "setTaskWindowingMode: No task for id=" + taskId); |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2279 | return false; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | if (DEBUG_STACK) Slog.d(TAG_STACK, "setTaskWindowingMode: moving task=" + taskId |
| 2283 | + " to windowingMode=" + windowingMode + " toTop=" + toTop); |
| 2284 | |
| 2285 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2286 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2287 | + " non-standard task " + taskId + " to windowing mode=" |
| 2288 | + windowingMode); |
| 2289 | } |
| 2290 | |
| 2291 | final ActivityStack stack = task.getStack(); |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2292 | // Convert some windowing-mode changes into root-task reparents for split-screen. |
| 2293 | if (stack.getTile() != null) { |
| 2294 | stack.getDisplay().onSplitScreenModeDismissed(); |
| 2295 | } |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2296 | if (toTop) { |
| 2297 | stack.moveToFront("setTaskWindowingMode", task); |
| 2298 | } |
| 2299 | stack.setWindowingMode(windowingMode); |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2300 | stack.getDisplay().ensureActivitiesVisible(null, 0, PRESERVE_WINDOWS, |
| 2301 | true /* notifyClients */); |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2302 | return true; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2303 | } finally { |
| 2304 | Binder.restoreCallingIdentity(ident); |
| 2305 | } |
| 2306 | } |
| 2307 | } |
| 2308 | |
| 2309 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2310 | public String getCallingPackage(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2311 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2312 | ActivityRecord r = getCallingRecordLocked(token); |
| 2313 | return r != null ? r.info.packageName : null; |
| 2314 | } |
| 2315 | } |
| 2316 | |
| 2317 | @Override |
| 2318 | public ComponentName getCallingActivity(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2319 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2320 | ActivityRecord r = getCallingRecordLocked(token); |
| 2321 | return r != null ? r.intent.getComponent() : null; |
| 2322 | } |
| 2323 | } |
| 2324 | |
| 2325 | private ActivityRecord getCallingRecordLocked(IBinder token) { |
| 2326 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2327 | if (r == null) { |
| 2328 | return null; |
| 2329 | } |
| 2330 | return r.resultTo; |
| 2331 | } |
| 2332 | |
| 2333 | @Override |
| 2334 | public void unhandledBack() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2335 | mAmInternal.enforceCallingPermission(android.Manifest.permission.FORCE_BACK, "unhandledBack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2336 | |
| 2337 | synchronized (mGlobalLock) { |
| 2338 | final long origId = Binder.clearCallingIdentity(); |
| 2339 | try { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2340 | getTopDisplayFocusedStack().unhandledBackLocked(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2341 | } finally { |
| 2342 | Binder.restoreCallingIdentity(origId); |
| 2343 | } |
| 2344 | } |
| 2345 | } |
| 2346 | |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2347 | @Override |
| 2348 | public void onBackPressedOnTaskRoot(IBinder token, IRequestFinishCallback callback) { |
| 2349 | synchronized (mGlobalLock) { |
| 2350 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2351 | if (r == null) { |
| 2352 | return; |
| 2353 | } |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2354 | ActivityStack stack = r.getRootTask(); |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2355 | if (stack != null && stack.isSingleTaskInstance()) { |
| 2356 | // Single-task stacks are used for activities which are presented in floating |
| 2357 | // windows above full screen activities. Instead of directly finishing the |
| 2358 | // task, a task change listener is used to notify SystemUI so the action can be |
| 2359 | // handled specially. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2360 | final Task task = r.getTask(); |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2361 | mTaskChangeNotificationController |
| 2362 | .notifyBackPressedOnTaskRoot(task.getTaskInfo()); |
| 2363 | } else { |
| 2364 | try { |
| 2365 | callback.requestFinish(); |
| 2366 | } catch (RemoteException e) { |
| 2367 | Slog.e(TAG, "Failed to invoke request finish callback", e); |
| 2368 | } |
| 2369 | } |
| 2370 | } |
| 2371 | } |
| 2372 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2373 | /** |
| 2374 | * TODO: Add mController hook |
| 2375 | */ |
| 2376 | @Override |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2377 | public void moveTaskToFront(IApplicationThread appThread, String callingPackage, int taskId, |
| 2378 | int flags, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2379 | mAmInternal.enforceCallingPermission(android.Manifest.permission.REORDER_TASKS, "moveTaskToFront()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2380 | |
| 2381 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToFront: moving taskId=" + taskId); |
| 2382 | synchronized (mGlobalLock) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2383 | moveTaskToFrontLocked(appThread, callingPackage, taskId, flags, |
| 2384 | SafeActivityOptions.fromBundle(bOptions), false /* fromRecents */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2385 | } |
| 2386 | } |
| 2387 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2388 | void moveTaskToFrontLocked(@Nullable IApplicationThread appThread, |
| 2389 | @Nullable String callingPackage, int taskId, int flags, SafeActivityOptions options, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2390 | boolean fromRecents) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2391 | final int callingPid = Binder.getCallingPid(); |
| 2392 | final int callingUid = Binder.getCallingUid(); |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 2393 | assertPackageMatchesCallingUid(callingPackage); |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2394 | if (!checkAppSwitchAllowedLocked(callingPid, callingUid, -1, -1, "Task to front")) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2395 | SafeActivityOptions.abort(options); |
| 2396 | return; |
| 2397 | } |
| 2398 | final long origId = Binder.clearCallingIdentity(); |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2399 | WindowProcessController callerApp = null; |
| 2400 | if (appThread != null) { |
| 2401 | callerApp = getProcessController(appThread); |
| 2402 | } |
| 2403 | final ActivityStarter starter = getActivityStartController().obtainStarter( |
| 2404 | null /* intent */, "moveTaskToFront"); |
| 2405 | if (starter.shouldAbortBackgroundActivityStart(callingUid, callingPid, callingPackage, -1, |
| 2406 | -1, callerApp, null, false, null)) { |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 2407 | if (!isBackgroundActivityStartsEnabled()) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2408 | return; |
| 2409 | } |
| 2410 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2411 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2412 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2413 | if (task == null) { |
| 2414 | Slog.d(TAG, "Could not find task for id: "+ taskId); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2415 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2416 | return; |
| 2417 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2418 | if (getLockTaskController().isLockTaskModeViolation(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2419 | Slog.e(TAG, "moveTaskToFront: Attempt to violate Lock Task Mode"); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2420 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2421 | return; |
| 2422 | } |
| 2423 | ActivityOptions realOptions = options != null |
| 2424 | ? options.getOptions(mStackSupervisor) |
| 2425 | : null; |
| 2426 | mStackSupervisor.findTaskToMoveToFront(task, flags, realOptions, "moveTaskToFront", |
| 2427 | false /* forceNonResizable */); |
| 2428 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 2429 | final ActivityRecord topActivity = task.getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2430 | if (topActivity != null) { |
| 2431 | |
| 2432 | // We are reshowing a task, use a starting window to hide the initial draw delay |
| 2433 | // so the transition can start earlier. |
| 2434 | topActivity.showStartingWindow(null /* prev */, false /* newTask */, |
| 2435 | true /* taskSwitch */, fromRecents); |
| 2436 | } |
| 2437 | } finally { |
| 2438 | Binder.restoreCallingIdentity(origId); |
| 2439 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2442 | /** |
| 2443 | * Return true if callingUid is system, or packageName belongs to that callingUid. |
| 2444 | */ |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 2445 | private boolean isSameApp(int callingUid, @Nullable String packageName) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2446 | try { |
| 2447 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 2448 | if (packageName == null) { |
| 2449 | return false; |
| 2450 | } |
| 2451 | final int uid = AppGlobals.getPackageManager().getPackageUid(packageName, |
| 2452 | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 2453 | UserHandle.getUserId(callingUid)); |
| 2454 | return UserHandle.isSameApp(callingUid, uid); |
| 2455 | } |
| 2456 | } catch (RemoteException e) { |
| 2457 | // Should not happen |
| 2458 | } |
| 2459 | return true; |
| 2460 | } |
| 2461 | |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 2462 | /** |
| 2463 | * Checks that the provided package name matches the current calling UID, throws a security |
| 2464 | * exception if it doesn't. |
| 2465 | */ |
| 2466 | void assertPackageMatchesCallingUid(@Nullable String packageName) { |
| 2467 | final int callingUid = Binder.getCallingUid(); |
| 2468 | if (isSameApp(callingUid, packageName)) { |
| 2469 | return; |
| 2470 | } |
| 2471 | final String msg = "Permission Denial: package=" + packageName |
| 2472 | + " does not belong to uid=" + callingUid; |
| 2473 | Slog.w(TAG, msg); |
| 2474 | throw new SecurityException(msg); |
| 2475 | } |
| 2476 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2477 | boolean checkAppSwitchAllowedLocked(int sourcePid, int sourceUid, |
| 2478 | int callingPid, int callingUid, String name) { |
| 2479 | if (mAppSwitchesAllowedTime < SystemClock.uptimeMillis()) { |
| 2480 | return true; |
| 2481 | } |
| 2482 | |
| 2483 | if (getRecentTasks().isCallerRecents(sourceUid)) { |
| 2484 | return true; |
| 2485 | } |
| 2486 | |
| 2487 | int perm = checkComponentPermission(STOP_APP_SWITCHES, sourcePid, sourceUid, -1, true); |
| 2488 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2489 | return true; |
| 2490 | } |
| 2491 | if (checkAllowAppSwitchUid(sourceUid)) { |
| 2492 | return true; |
| 2493 | } |
| 2494 | |
| 2495 | // If the actual IPC caller is different from the logical source, then |
| 2496 | // also see if they are allowed to control app switches. |
| 2497 | if (callingUid != -1 && callingUid != sourceUid) { |
| 2498 | perm = checkComponentPermission(STOP_APP_SWITCHES, callingPid, callingUid, -1, true); |
| 2499 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2500 | return true; |
| 2501 | } |
| 2502 | if (checkAllowAppSwitchUid(callingUid)) { |
| 2503 | return true; |
| 2504 | } |
| 2505 | } |
| 2506 | |
| 2507 | Slog.w(TAG, name + " request from " + sourceUid + " stopped"); |
| 2508 | return false; |
| 2509 | } |
| 2510 | |
| 2511 | private boolean checkAllowAppSwitchUid(int uid) { |
| 2512 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(UserHandle.getUserId(uid)); |
| 2513 | if (types != null) { |
| 2514 | for (int i = types.size() - 1; i >= 0; i--) { |
| 2515 | if (types.valueAt(i).intValue() == uid) { |
| 2516 | return true; |
| 2517 | } |
| 2518 | } |
| 2519 | } |
| 2520 | return false; |
| 2521 | } |
| 2522 | |
| 2523 | @Override |
| 2524 | public void setActivityController(IActivityController controller, boolean imAMonkey) { |
| 2525 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER, |
| 2526 | "setActivityController()"); |
| 2527 | synchronized (mGlobalLock) { |
| 2528 | mController = controller; |
| 2529 | mControllerIsAMonkey = imAMonkey; |
| 2530 | Watchdog.getInstance().setActivityController(controller); |
| 2531 | } |
| 2532 | } |
| 2533 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 2534 | public boolean isControllerAMonkey() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2535 | synchronized (mGlobalLock) { |
| 2536 | return mController != null && mControllerIsAMonkey; |
| 2537 | } |
| 2538 | } |
| 2539 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2540 | @Override |
| 2541 | public int getTaskForActivity(IBinder token, boolean onlyRoot) { |
| 2542 | synchronized (mGlobalLock) { |
| 2543 | return ActivityRecord.getTaskForActivityLocked(token, onlyRoot); |
| 2544 | } |
| 2545 | } |
| 2546 | |
| 2547 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2548 | public List<ActivityManager.RunningTaskInfo> getTasks(int maxNum) { |
| 2549 | return getFilteredTasks(maxNum, ACTIVITY_TYPE_UNDEFINED, WINDOWING_MODE_UNDEFINED); |
| 2550 | } |
| 2551 | |
| 2552 | @Override |
| 2553 | public List<ActivityManager.RunningTaskInfo> getFilteredTasks(int maxNum, |
| 2554 | @WindowConfiguration.ActivityType int ignoreActivityType, |
| 2555 | @WindowConfiguration.WindowingMode int ignoreWindowingMode) { |
| 2556 | final int callingUid = Binder.getCallingUid(); |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 2557 | final int callingPid = Binder.getCallingPid(); |
| 2558 | final boolean crossUser = isCrossUserAllowed(callingPid, callingUid); |
Nicholas Sauer | 3f9249f | 2019-09-10 20:23:41 -0700 | [diff] [blame] | 2559 | final int[] profileIds = getUserManager().getProfileIds( |
| 2560 | UserHandle.getUserId(callingUid), true); |
| 2561 | ArraySet<Integer> callingProfileIds = new ArraySet<>(); |
| 2562 | for (int i = 0; i < profileIds.length; i++) { |
| 2563 | callingProfileIds.add(profileIds[i]); |
| 2564 | } |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2565 | ArrayList<ActivityManager.RunningTaskInfo> list = new ArrayList<>(); |
| 2566 | |
| 2567 | synchronized (mGlobalLock) { |
| 2568 | if (DEBUG_ALL) Slog.v(TAG, "getTasks: max=" + maxNum); |
| 2569 | |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 2570 | final boolean allowed = isGetTasksAllowed("getTasks", callingPid, callingUid); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2571 | mRootWindowContainer.getRunningTasks(maxNum, list, ignoreActivityType, |
Nicholas Sauer | 3f9249f | 2019-09-10 20:23:41 -0700 | [diff] [blame] | 2572 | ignoreWindowingMode, callingUid, allowed, crossUser, callingProfileIds); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | return list; |
| 2576 | } |
| 2577 | |
| 2578 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2579 | public final void finishSubActivity(IBinder token, String resultWho, int requestCode) { |
| 2580 | synchronized (mGlobalLock) { |
| 2581 | final long origId = Binder.clearCallingIdentity(); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2582 | try { |
| 2583 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2584 | if (r == null) return; |
| 2585 | |
| 2586 | final PooledConsumer c = PooledLambda.obtainConsumer( |
| 2587 | ActivityRecord::finishIfSubActivity, PooledLambda.__(ActivityRecord.class), |
| 2588 | r, resultWho, requestCode); |
| 2589 | // TODO: This should probably only loop over the task since you need to be in the |
| 2590 | // same task to return results. |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2591 | r.getRootTask().forAllActivities(c); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2592 | c.recycle(); |
| 2593 | |
| 2594 | updateOomAdj(); |
| 2595 | } finally { |
| 2596 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2597 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2598 | } |
| 2599 | } |
| 2600 | |
| 2601 | @Override |
| 2602 | public boolean willActivityBeVisible(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2603 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2604 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 2605 | if (stack != null) { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2606 | return stack.willActivityBeVisible(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2607 | } |
| 2608 | return false; |
| 2609 | } |
| 2610 | } |
| 2611 | |
| 2612 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2613 | public void moveTaskToStack(int taskId, int stackId, boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2614 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "moveTaskToStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2615 | synchronized (mGlobalLock) { |
| 2616 | final long ident = Binder.clearCallingIdentity(); |
| 2617 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2618 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2619 | if (task == null) { |
| 2620 | Slog.w(TAG, "moveTaskToStack: No task for id=" + taskId); |
| 2621 | return; |
| 2622 | } |
| 2623 | |
| 2624 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToStack: moving task=" + taskId |
| 2625 | + " to stackId=" + stackId + " toTop=" + toTop); |
| 2626 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2627 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2628 | if (stack == null) { |
| 2629 | throw new IllegalStateException( |
| 2630 | "moveTaskToStack: No stack for stackId=" + stackId); |
| 2631 | } |
| 2632 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 2633 | throw new IllegalArgumentException("moveTaskToStack: Attempt to move task " |
| 2634 | + taskId + " to stack " + stackId); |
| 2635 | } |
| 2636 | if (stack.inSplitScreenPrimaryWindowingMode()) { |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 2637 | mWindowManager.setDockedStackCreateStateLocked( |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2638 | SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */); |
| 2639 | } |
| 2640 | task.reparent(stack, toTop, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME, |
| 2641 | "moveTaskToStack"); |
| 2642 | } finally { |
| 2643 | Binder.restoreCallingIdentity(ident); |
| 2644 | } |
| 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | @Override |
Evan Rosky | dbe2ce5 | 2019-07-18 11:13:17 -0700 | [diff] [blame] | 2649 | public void animateResizePinnedStack(int stackId, Rect destBounds, int animationDuration) { |
| 2650 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "animateResizePinnedStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2651 | |
| 2652 | final long ident = Binder.clearCallingIdentity(); |
| 2653 | try { |
| 2654 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2655 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Evan Rosky | dbe2ce5 | 2019-07-18 11:13:17 -0700 | [diff] [blame] | 2656 | if (stack == null) { |
| 2657 | Slog.w(TAG, "resizeStack: stackId " + stackId + " not found."); |
| 2658 | return; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2659 | } |
Evan Rosky | dbe2ce5 | 2019-07-18 11:13:17 -0700 | [diff] [blame] | 2660 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 2661 | throw new IllegalArgumentException("Stack: " + stackId |
| 2662 | + " doesn't support animated resize."); |
| 2663 | } |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2664 | stack.animateResizePinnedStack(destBounds, null /* sourceHintBounds */, |
Evan Rosky | dbe2ce5 | 2019-07-18 11:13:17 -0700 | [diff] [blame] | 2665 | animationDuration, false /* fromFullscreen */); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2666 | } |
| 2667 | } finally { |
| 2668 | Binder.restoreCallingIdentity(ident); |
| 2669 | } |
| 2670 | } |
| 2671 | |
wilsonshih | 5c4cf52 | 2019-01-25 09:03:47 +0800 | [diff] [blame] | 2672 | @Override |
| 2673 | public void offsetPinnedStackBounds(int stackId, Rect compareBounds, int xOffset, int yOffset, |
| 2674 | int animationDuration) { |
| 2675 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "offsetPinnedStackBounds()"); |
| 2676 | |
| 2677 | final long ident = Binder.clearCallingIdentity(); |
| 2678 | try { |
| 2679 | synchronized (mGlobalLock) { |
| 2680 | if (xOffset == 0 && yOffset == 0) { |
| 2681 | return; |
| 2682 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2683 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
wilsonshih | 5c4cf52 | 2019-01-25 09:03:47 +0800 | [diff] [blame] | 2684 | if (stack == null) { |
| 2685 | Slog.w(TAG, "offsetPinnedStackBounds: stackId " + stackId + " not found."); |
| 2686 | return; |
| 2687 | } |
| 2688 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 2689 | throw new IllegalArgumentException("Stack: " + stackId |
| 2690 | + " doesn't support animated resize."); |
| 2691 | } |
| 2692 | final Rect destBounds = new Rect(); |
| 2693 | stack.getAnimationOrCurrentBounds(destBounds); |
wilsonshih | a6e408c | 2019-02-19 17:30:03 +0800 | [diff] [blame] | 2694 | if (destBounds.isEmpty() || !destBounds.equals(compareBounds)) { |
wilsonshih | 5c4cf52 | 2019-01-25 09:03:47 +0800 | [diff] [blame] | 2695 | Slog.w(TAG, "The current stack bounds does not matched! It may be obsolete."); |
| 2696 | return; |
| 2697 | } |
| 2698 | destBounds.offset(xOffset, yOffset); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2699 | stack.animateResizePinnedStack(destBounds, null /* sourceHintBounds */, |
wilsonshih | 5c4cf52 | 2019-01-25 09:03:47 +0800 | [diff] [blame] | 2700 | animationDuration, false /* fromFullscreen */); |
| 2701 | } |
| 2702 | } finally { |
| 2703 | Binder.restoreCallingIdentity(ident); |
| 2704 | } |
| 2705 | } |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2706 | /** |
| 2707 | * Moves the specified task to the primary-split-screen stack. |
| 2708 | * |
| 2709 | * @param taskId Id of task to move. |
| 2710 | * @param createMode The mode the primary split screen stack should be created in if it doesn't |
| 2711 | * exist already. See |
| 2712 | * {@link android.app.ActivityTaskManager#SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT} |
| 2713 | * and |
| 2714 | * {@link android.app.ActivityTaskManager#SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT} |
| 2715 | * @param toTop If the task and stack should be moved to the top. |
| 2716 | * @param animate Whether we should play an animation for the moving the task. |
| 2717 | * @param initialBounds If the primary stack gets created, it will use these bounds for the |
| 2718 | * stack. Pass {@code null} to use default bounds. |
| 2719 | * @param showRecents If the recents activity should be shown on the other side of the task |
| 2720 | * going into split-screen mode. |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2721 | * @return Whether the task was successfully put into splitscreen. |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2722 | */ |
| 2723 | @Override |
| 2724 | public boolean setTaskWindowingModeSplitScreenPrimary(int taskId, int createMode, |
| 2725 | boolean toTop, boolean animate, Rect initialBounds, boolean showRecents) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2726 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2727 | "setTaskWindowingModeSplitScreenPrimary()"); |
| 2728 | synchronized (mGlobalLock) { |
| 2729 | final long ident = Binder.clearCallingIdentity(); |
| 2730 | try { |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2731 | return setTaskWindowingModeSplitScreen(taskId, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, |
| 2732 | toTop); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2733 | } finally { |
| 2734 | Binder.restoreCallingIdentity(ident); |
| 2735 | } |
| 2736 | } |
| 2737 | } |
| 2738 | |
| 2739 | /** |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2740 | * Moves the specified task into a split-screen tile. |
| 2741 | */ |
| 2742 | private boolean setTaskWindowingModeSplitScreen(int taskId, int windowingMode, boolean toTop) { |
| 2743 | if (!WindowConfiguration.isSplitScreenWindowingMode(windowingMode)) { |
| 2744 | throw new IllegalArgumentException("Calling setTaskWindowingModeSplitScreen with non" |
| 2745 | + "split-screen mode: " + windowingMode); |
| 2746 | } |
| 2747 | if (isInLockTaskMode()) { |
| 2748 | Slog.w(TAG, "setTaskWindowingModeSplitScreen: Is in lock task mode=" |
| 2749 | + getLockTaskModeState()); |
| 2750 | return false; |
| 2751 | } |
| 2752 | |
| 2753 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
| 2754 | MATCH_TASK_IN_STACKS_ONLY); |
| 2755 | if (task == null) { |
| 2756 | Slog.w(TAG, "setTaskWindowingModeSplitScreenPrimary: No task for id=" + taskId); |
| 2757 | return false; |
| 2758 | } |
| 2759 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2760 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2761 | + " non-standard task " + taskId + " to split-screen windowing mode"); |
| 2762 | } |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 2763 | if (!task.supportsSplitScreenWindowingMode()) { |
| 2764 | return false; |
| 2765 | } |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2766 | |
| 2767 | final int prevMode = task.getWindowingMode(); |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 2768 | moveTaskToSplitScreenPrimaryTile(task, toTop); |
| 2769 | return prevMode != task.getWindowingMode(); |
| 2770 | } |
| 2771 | |
| 2772 | void moveTaskToSplitScreenPrimaryTile(Task task, boolean toTop) { |
| 2773 | ActivityStack stack = task.getStack(); |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2774 | TaskTile tile = null; |
| 2775 | for (int i = stack.getDisplay().getStackCount() - 1; i >= 0; --i) { |
| 2776 | tile = stack.getDisplay().getStackAt(i).asTile(); |
| 2777 | if (tile != null && tile.getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 2778 | break; |
| 2779 | } |
| 2780 | } |
| 2781 | if (tile == null) { |
| 2782 | throw new IllegalStateException("Can't enter split without associated tile"); |
| 2783 | } |
| 2784 | WindowContainerTransaction wct = new WindowContainerTransaction(); |
| 2785 | wct.reparent(stack.mRemoteToken, tile.mRemoteToken, toTop); |
| 2786 | mTaskOrganizerController.applyContainerTransaction(wct, null); |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | /** |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2790 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 2791 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 2792 | */ |
| 2793 | @Override |
| 2794 | public void removeStacksInWindowingModes(int[] windowingModes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2795 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2796 | "removeStacksInWindowingModes()"); |
| 2797 | |
| 2798 | synchronized (mGlobalLock) { |
| 2799 | final long ident = Binder.clearCallingIdentity(); |
| 2800 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2801 | mRootWindowContainer.removeStacksInWindowingModes(windowingModes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2802 | } finally { |
| 2803 | Binder.restoreCallingIdentity(ident); |
| 2804 | } |
| 2805 | } |
| 2806 | } |
| 2807 | |
| 2808 | @Override |
| 2809 | public void removeStacksWithActivityTypes(int[] activityTypes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2810 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2811 | "removeStacksWithActivityTypes()"); |
| 2812 | |
| 2813 | synchronized (mGlobalLock) { |
| 2814 | final long ident = Binder.clearCallingIdentity(); |
| 2815 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2816 | mRootWindowContainer.removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2817 | } finally { |
| 2818 | Binder.restoreCallingIdentity(ident); |
| 2819 | } |
| 2820 | } |
| 2821 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2822 | |
| 2823 | @Override |
| 2824 | public ParceledListSlice<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, |
| 2825 | int userId) { |
| 2826 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2827 | userId = handleIncomingUser(Binder.getCallingPid(), callingUid, userId, "getRecentTasks"); |
| 2828 | final boolean allowed = isGetTasksAllowed("getRecentTasks", Binder.getCallingPid(), |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2829 | callingUid); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2830 | final boolean detailed = checkGetTasksPermission( |
| 2831 | android.Manifest.permission.GET_DETAILED_TASKS, Binder.getCallingPid(), |
| 2832 | UserHandle.getAppId(callingUid)) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2833 | == PackageManager.PERMISSION_GRANTED; |
| 2834 | |
| 2835 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 2836 | return mRecentTasks.getRecentTasks(maxNum, flags, allowed, detailed, userId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2837 | callingUid); |
| 2838 | } |
| 2839 | } |
| 2840 | |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 2841 | // TODO(148895075): deprecate and replace with task equivalents |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2842 | @Override |
| 2843 | public List<ActivityManager.StackInfo> getAllStackInfos() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2844 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2845 | long ident = Binder.clearCallingIdentity(); |
| 2846 | try { |
| 2847 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2848 | return mRootWindowContainer.getAllStackInfos(INVALID_DISPLAY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2849 | } |
| 2850 | } finally { |
| 2851 | Binder.restoreCallingIdentity(ident); |
| 2852 | } |
| 2853 | } |
| 2854 | |
| 2855 | @Override |
| 2856 | public ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2857 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2858 | long ident = Binder.clearCallingIdentity(); |
| 2859 | try { |
| 2860 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2861 | return mRootWindowContainer.getStackInfo(windowingMode, activityType); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2862 | } |
| 2863 | } finally { |
| 2864 | Binder.restoreCallingIdentity(ident); |
| 2865 | } |
| 2866 | } |
| 2867 | |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 2868 | // TODO(148895075): deprecate and replace with task equivalents |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2869 | @Override |
Evan Rosky | fd43969 | 2019-11-06 16:12:59 -0800 | [diff] [blame] | 2870 | public List<ActivityManager.StackInfo> getAllStackInfosOnDisplay(int displayId) { |
| 2871 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); |
| 2872 | long ident = Binder.clearCallingIdentity(); |
| 2873 | try { |
| 2874 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2875 | return mRootWindowContainer.getAllStackInfos(displayId); |
Evan Rosky | fd43969 | 2019-11-06 16:12:59 -0800 | [diff] [blame] | 2876 | } |
| 2877 | } finally { |
| 2878 | Binder.restoreCallingIdentity(ident); |
| 2879 | } |
| 2880 | } |
| 2881 | |
| 2882 | @Override |
| 2883 | public ActivityManager.StackInfo getStackInfoOnDisplay(int windowingMode, int activityType, |
| 2884 | int displayId) { |
| 2885 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
| 2886 | long ident = Binder.clearCallingIdentity(); |
| 2887 | try { |
| 2888 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2889 | return mRootWindowContainer.getStackInfo(windowingMode, activityType, displayId); |
Evan Rosky | fd43969 | 2019-11-06 16:12:59 -0800 | [diff] [blame] | 2890 | } |
| 2891 | } finally { |
| 2892 | Binder.restoreCallingIdentity(ident); |
| 2893 | } |
| 2894 | } |
| 2895 | |
| 2896 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2897 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2898 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "cancelRecentsAnimation()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2899 | final long callingUid = Binder.getCallingUid(); |
| 2900 | final long origId = Binder.clearCallingIdentity(); |
| 2901 | try { |
| 2902 | synchronized (mGlobalLock) { |
| 2903 | // Cancel the recents animation synchronously (do not hold the WM lock) |
Wale Ogunwale | a441b92 | 2019-06-27 19:21:44 -0700 | [diff] [blame] | 2904 | mWindowManager.cancelRecentsAnimation(restoreHomeStackPosition |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2905 | ? REORDER_MOVE_TO_ORIGINAL_POSITION |
| 2906 | : REORDER_KEEP_IN_PLACE, "cancelRecentsAnimation/uid=" + callingUid); |
| 2907 | } |
| 2908 | } finally { |
| 2909 | Binder.restoreCallingIdentity(origId); |
| 2910 | } |
| 2911 | } |
| 2912 | |
| 2913 | @Override |
| 2914 | public void startLockTaskModeByToken(IBinder token) { |
| 2915 | synchronized (mGlobalLock) { |
| 2916 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2917 | if (r == null) { |
| 2918 | return; |
| 2919 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2920 | startLockTaskModeLocked(r.getTask(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2921 | } |
| 2922 | } |
| 2923 | |
| 2924 | @Override |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2925 | public void startSystemLockTaskMode(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2926 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "startSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2927 | // This makes inner call to look as if it was initiated by system. |
| 2928 | long ident = Binder.clearCallingIdentity(); |
| 2929 | try { |
| 2930 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2931 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2932 | MATCH_TASK_IN_STACKS_ONLY); |
| 2933 | if (task == null) { |
| 2934 | return; |
| 2935 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2936 | |
| 2937 | // When starting lock task mode the stack must be in front and focused |
| 2938 | task.getStack().moveToFront("startSystemLockTaskMode"); |
| 2939 | startLockTaskModeLocked(task, true /* isSystemCaller */); |
| 2940 | } |
| 2941 | } finally { |
| 2942 | Binder.restoreCallingIdentity(ident); |
| 2943 | } |
| 2944 | } |
| 2945 | |
| 2946 | @Override |
| 2947 | public void stopLockTaskModeByToken(IBinder token) { |
| 2948 | synchronized (mGlobalLock) { |
| 2949 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2950 | if (r == null) { |
| 2951 | return; |
| 2952 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2953 | stopLockTaskModeInternal(r.getTask(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2954 | } |
| 2955 | } |
| 2956 | |
| 2957 | /** |
| 2958 | * This API should be called by SystemUI only when user perform certain action to dismiss |
| 2959 | * lock task mode. We should only dismiss pinned lock task mode in this case. |
| 2960 | */ |
| 2961 | @Override |
| 2962 | public void stopSystemLockTaskMode() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2963 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "stopSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2964 | stopLockTaskModeInternal(null, true /* isSystemCaller */); |
| 2965 | } |
| 2966 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2967 | private void startLockTaskModeLocked(@Nullable Task task, boolean isSystemCaller) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2968 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "startLockTaskModeLocked: " + task); |
| 2969 | if (task == null || task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) { |
| 2970 | return; |
| 2971 | } |
| 2972 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2973 | final ActivityStack stack = mRootWindowContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2974 | if (stack == null || task != stack.getTopMostTask()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2975 | throw new IllegalArgumentException("Invalid task, not in foreground"); |
| 2976 | } |
| 2977 | |
| 2978 | // {@code isSystemCaller} is used to distinguish whether this request is initiated by the |
| 2979 | // system or a specific app. |
| 2980 | // * System-initiated requests will only start the pinned mode (screen pinning) |
| 2981 | // * App-initiated requests |
| 2982 | // - will put the device in fully locked mode (LockTask), if the app is whitelisted |
| 2983 | // - will start the pinned mode, otherwise |
| 2984 | final int callingUid = Binder.getCallingUid(); |
| 2985 | long ident = Binder.clearCallingIdentity(); |
| 2986 | try { |
| 2987 | // When a task is locked, dismiss the pinned stack if it exists |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2988 | mRootWindowContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2989 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2990 | getLockTaskController().startLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2991 | } finally { |
| 2992 | Binder.restoreCallingIdentity(ident); |
| 2993 | } |
| 2994 | } |
| 2995 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2996 | private void stopLockTaskModeInternal(@Nullable Task task, boolean isSystemCaller) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2997 | final int callingUid = Binder.getCallingUid(); |
| 2998 | long ident = Binder.clearCallingIdentity(); |
| 2999 | try { |
| 3000 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3001 | getLockTaskController().stopLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3002 | } |
| 3003 | // Launch in-call UI if a call is ongoing. This is necessary to allow stopping the lock |
| 3004 | // task and jumping straight into a call in the case of emergency call back. |
| 3005 | TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
| 3006 | if (tm != null) { |
| 3007 | tm.showInCallScreen(false); |
| 3008 | } |
| 3009 | } finally { |
| 3010 | Binder.restoreCallingIdentity(ident); |
| 3011 | } |
| 3012 | } |
| 3013 | |
| 3014 | @Override |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 3015 | public void updateLockTaskPackages(int userId, String[] packages) { |
| 3016 | final int callingUid = Binder.getCallingUid(); |
| 3017 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 3018 | mAmInternal.enforceCallingPermission(Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
| 3019 | "updateLockTaskPackages()"); |
| 3020 | } |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 3021 | synchronized (mGlobalLock) { |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 3022 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Whitelisting " + userId + ":" |
| 3023 | + Arrays.toString(packages)); |
| 3024 | getLockTaskController().updateLockTaskPackages(userId, packages); |
| 3025 | } |
| 3026 | } |
| 3027 | |
| 3028 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3029 | public boolean isInLockTaskMode() { |
| 3030 | return getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
| 3031 | } |
| 3032 | |
| 3033 | @Override |
| 3034 | public int getLockTaskModeState() { |
| 3035 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3036 | return getLockTaskController().getLockTaskModeState(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3037 | } |
| 3038 | } |
| 3039 | |
| 3040 | @Override |
| 3041 | public void setTaskDescription(IBinder token, ActivityManager.TaskDescription td) { |
| 3042 | synchronized (mGlobalLock) { |
| 3043 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3044 | if (r != null) { |
| 3045 | r.setTaskDescription(td); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3046 | final Task task = r.getTask(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3047 | task.updateTaskDescription(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3048 | } |
| 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | @Override |
| 3053 | public Bundle getActivityOptions(IBinder token) { |
| 3054 | final long origId = Binder.clearCallingIdentity(); |
| 3055 | try { |
| 3056 | synchronized (mGlobalLock) { |
| 3057 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3058 | if (r != null) { |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 3059 | final ActivityOptions activityOptions = r.takeOptionsLocked( |
| 3060 | true /* fromClient */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3061 | return activityOptions == null ? null : activityOptions.toBundle(); |
| 3062 | } |
| 3063 | return null; |
| 3064 | } |
| 3065 | } finally { |
| 3066 | Binder.restoreCallingIdentity(origId); |
| 3067 | } |
| 3068 | } |
| 3069 | |
| 3070 | @Override |
| 3071 | public List<IBinder> getAppTasks(String callingPackage) { |
| 3072 | int callingUid = Binder.getCallingUid(); |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 3073 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3074 | long ident = Binder.clearCallingIdentity(); |
| 3075 | try { |
| 3076 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3077 | return mRecentTasks.getAppTasksList(callingUid, callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3078 | } |
| 3079 | } finally { |
| 3080 | Binder.restoreCallingIdentity(ident); |
| 3081 | } |
| 3082 | } |
| 3083 | |
| 3084 | @Override |
| 3085 | public void finishVoiceTask(IVoiceInteractionSession session) { |
| 3086 | synchronized (mGlobalLock) { |
| 3087 | final long origId = Binder.clearCallingIdentity(); |
| 3088 | try { |
| 3089 | // TODO: VI Consider treating local voice interactions and voice tasks |
| 3090 | // differently here |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3091 | mRootWindowContainer.finishVoiceTask(session); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3092 | } finally { |
| 3093 | Binder.restoreCallingIdentity(origId); |
| 3094 | } |
| 3095 | } |
| 3096 | |
| 3097 | } |
| 3098 | |
| 3099 | @Override |
| 3100 | public boolean isTopOfTask(IBinder token) { |
| 3101 | synchronized (mGlobalLock) { |
| 3102 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3103 | return r != null && r.getTask().getTopNonFinishingActivity() == r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | @Override |
| 3108 | public void notifyLaunchTaskBehindComplete(IBinder token) { |
| 3109 | mStackSupervisor.scheduleLaunchTaskBehindComplete(token); |
| 3110 | } |
| 3111 | |
| 3112 | @Override |
| 3113 | public void notifyEnterAnimationComplete(IBinder token) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3114 | mH.post(() -> { |
| 3115 | synchronized (mGlobalLock) { |
| 3116 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3117 | if (r != null && r.attachedToProcess()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3118 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3119 | r.app.getThread().scheduleEnterAnimationComplete(r.appToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3120 | } catch (RemoteException e) { |
| 3121 | } |
| 3122 | } |
| 3123 | } |
| 3124 | |
| 3125 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | /** Called from an app when assist data is ready. */ |
| 3129 | @Override |
| 3130 | public void reportAssistContextExtras(IBinder token, Bundle extras, AssistStructure structure, |
| 3131 | AssistContent content, Uri referrer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3132 | PendingAssistExtras pae = (PendingAssistExtras) token; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3133 | synchronized (pae) { |
| 3134 | pae.result = extras; |
| 3135 | pae.structure = structure; |
| 3136 | pae.content = content; |
| 3137 | if (referrer != null) { |
| 3138 | pae.extras.putParcelable(Intent.EXTRA_REFERRER, referrer); |
| 3139 | } |
| 3140 | if (structure != null) { |
Winson Chung | 48b2565 | 2018-10-22 14:04:30 -0700 | [diff] [blame] | 3141 | // Pre-fill the task/activity component for all assist data receivers |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3142 | structure.setTaskId(pae.activity.getTask().mTaskId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3143 | structure.setActivityComponent(pae.activity.mActivityComponent); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3144 | structure.setHomeActivity(pae.isHome); |
| 3145 | } |
| 3146 | pae.haveResult = true; |
| 3147 | pae.notifyAll(); |
| 3148 | if (pae.intent == null && pae.receiver == null) { |
| 3149 | // Caller is just waiting for the result. |
| 3150 | return; |
| 3151 | } |
| 3152 | } |
| 3153 | // We are now ready to launch the assist activity. |
| 3154 | IAssistDataReceiver sendReceiver = null; |
| 3155 | Bundle sendBundle = null; |
| 3156 | synchronized (mGlobalLock) { |
| 3157 | buildAssistBundleLocked(pae, extras); |
| 3158 | boolean exists = mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3159 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3160 | if (!exists) { |
| 3161 | // Timed out. |
| 3162 | return; |
| 3163 | } |
| 3164 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3165 | if ((sendReceiver = pae.receiver) != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3166 | // Caller wants result sent back to them. |
| 3167 | sendBundle = new Bundle(); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3168 | sendBundle.putInt(ActivityTaskManagerInternal.ASSIST_TASK_ID, |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3169 | pae.activity.getTask().mTaskId); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3170 | sendBundle.putBinder(ActivityTaskManagerInternal.ASSIST_ACTIVITY_ID, |
| 3171 | pae.activity.assistToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3172 | sendBundle.putBundle(ASSIST_KEY_DATA, pae.extras); |
| 3173 | sendBundle.putParcelable(ASSIST_KEY_STRUCTURE, pae.structure); |
| 3174 | sendBundle.putParcelable(ASSIST_KEY_CONTENT, pae.content); |
| 3175 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3176 | } |
| 3177 | } |
| 3178 | if (sendReceiver != null) { |
| 3179 | try { |
| 3180 | sendReceiver.onHandleAssistData(sendBundle); |
| 3181 | } catch (RemoteException e) { |
| 3182 | } |
| 3183 | return; |
| 3184 | } |
| 3185 | |
| 3186 | final long ident = Binder.clearCallingIdentity(); |
| 3187 | try { |
| 3188 | if (TextUtils.equals(pae.intent.getAction(), |
| 3189 | android.service.voice.VoiceInteractionService.SERVICE_INTERFACE)) { |
Galia Peycheva | bffbfc3 | 2019-06-18 10:11:35 +0200 | [diff] [blame] | 3190 | // Start voice interaction through VoiceInteractionManagerService. |
| 3191 | mAssistUtils.showSessionForActiveService(sendBundle, SHOW_SOURCE_APPLICATION, |
| 3192 | null, null); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3193 | } else { |
| 3194 | pae.intent.replaceExtras(pae.extras); |
| 3195 | pae.intent.setFlags(FLAG_ACTIVITY_NEW_TASK |
| 3196 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 3197 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 3198 | mInternal.closeSystemDialogs("assist"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3199 | |
| 3200 | try { |
| 3201 | mContext.startActivityAsUser(pae.intent, new UserHandle(pae.userHandle)); |
| 3202 | } catch (ActivityNotFoundException e) { |
| 3203 | Slog.w(TAG, "No activity to handle assist action.", e); |
| 3204 | } |
| 3205 | } |
| 3206 | } finally { |
| 3207 | Binder.restoreCallingIdentity(ident); |
| 3208 | } |
| 3209 | } |
| 3210 | |
| 3211 | @Override |
| 3212 | public int addAppTask(IBinder activityToken, Intent intent, |
| 3213 | ActivityManager.TaskDescription description, Bitmap thumbnail) throws RemoteException { |
| 3214 | final int callingUid = Binder.getCallingUid(); |
| 3215 | final long callingIdent = Binder.clearCallingIdentity(); |
| 3216 | |
| 3217 | try { |
| 3218 | synchronized (mGlobalLock) { |
| 3219 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 3220 | if (r == null) { |
| 3221 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 3222 | + activityToken); |
| 3223 | } |
| 3224 | ComponentName comp = intent.getComponent(); |
| 3225 | if (comp == null) { |
| 3226 | throw new IllegalArgumentException("Intent " + intent |
| 3227 | + " must specify explicit component"); |
| 3228 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3229 | if (thumbnail.getWidth() != mThumbnailWidth |
| 3230 | || thumbnail.getHeight() != mThumbnailHeight) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3231 | throw new IllegalArgumentException("Bad thumbnail size: got " |
| 3232 | + thumbnail.getWidth() + "x" + thumbnail.getHeight() + ", require " |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3233 | + mThumbnailWidth + "x" + mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3234 | } |
| 3235 | if (intent.getSelector() != null) { |
| 3236 | intent.setSelector(null); |
| 3237 | } |
| 3238 | if (intent.getSourceBounds() != null) { |
| 3239 | intent.setSourceBounds(null); |
| 3240 | } |
| 3241 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) { |
| 3242 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) == 0) { |
| 3243 | // The caller has added this as an auto-remove task... that makes no |
| 3244 | // sense, so turn off auto-remove. |
| 3245 | intent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS); |
| 3246 | } |
| 3247 | } |
| 3248 | final ActivityInfo ainfo = AppGlobals.getPackageManager().getActivityInfo(comp, |
| 3249 | STOCK_PM_FLAGS, UserHandle.getUserId(callingUid)); |
| 3250 | if (ainfo.applicationInfo.uid != callingUid) { |
| 3251 | throw new SecurityException( |
| 3252 | "Can't add task for another application: target uid=" |
| 3253 | + ainfo.applicationInfo.uid + ", calling uid=" + callingUid); |
| 3254 | } |
| 3255 | |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 3256 | final ActivityStack stack = r.getRootTask(); |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 3257 | final Task task = stack.getDisplay().createStack(stack.getWindowingMode(), |
| 3258 | stack.getActivityType(), !ON_TOP, ainfo, intent); |
| 3259 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3260 | if (!mRecentTasks.addToBottom(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3261 | // The app has too many tasks already and we can't add any more |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 3262 | stack.removeChild(task, "addAppTask"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3263 | return INVALID_TASK_ID; |
| 3264 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 3265 | task.getTaskDescription().copyFrom(description); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3266 | |
| 3267 | // TODO: Send the thumbnail to WM to store it. |
| 3268 | |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 3269 | return task.mTaskId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3270 | } |
| 3271 | } finally { |
| 3272 | Binder.restoreCallingIdentity(callingIdent); |
| 3273 | } |
| 3274 | } |
| 3275 | |
| 3276 | @Override |
| 3277 | public Point getAppTaskThumbnailSize() { |
| 3278 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3279 | return new Point(mThumbnailWidth, mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3280 | } |
| 3281 | } |
| 3282 | |
| 3283 | @Override |
| 3284 | public void setTaskResizeable(int taskId, int resizeableMode) { |
| 3285 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3286 | final Task task = mRootWindowContainer.anyTaskForId( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3287 | taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 3288 | if (task == null) { |
| 3289 | Slog.w(TAG, "setTaskResizeable: taskId=" + taskId + " not found"); |
| 3290 | return; |
| 3291 | } |
| 3292 | task.setResizeMode(resizeableMode); |
| 3293 | } |
| 3294 | } |
| 3295 | |
| 3296 | @Override |
| 3297 | public void resizeTask(int taskId, Rect bounds, int resizeMode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3298 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "resizeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3299 | long ident = Binder.clearCallingIdentity(); |
| 3300 | try { |
| 3301 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3302 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 3303 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3304 | if (task == null) { |
| 3305 | Slog.w(TAG, "resizeTask: taskId=" + taskId + " not found"); |
| 3306 | return; |
| 3307 | } |
| 3308 | // Place the task in the right stack if it isn't there already based on |
| 3309 | // the requested bounds. |
| 3310 | // The stack transition logic is: |
| 3311 | // - a null bounds on a freeform task moves that task to fullscreen |
| 3312 | // - a non-null bounds on a non-freeform (fullscreen OR docked) task moves |
| 3313 | // that task to freeform |
| 3314 | // - otherwise the task is not moved |
| 3315 | ActivityStack stack = task.getStack(); |
| 3316 | if (!task.getWindowConfiguration().canResizeTask()) { |
| 3317 | throw new IllegalArgumentException("resizeTask not allowed on task=" + task); |
| 3318 | } |
| 3319 | if (bounds == null && stack.getWindowingMode() == WINDOWING_MODE_FREEFORM) { |
| 3320 | stack = stack.getDisplay().getOrCreateStack( |
| 3321 | WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), ON_TOP); |
| 3322 | } else if (bounds != null && stack.getWindowingMode() != WINDOWING_MODE_FREEFORM) { |
| 3323 | stack = stack.getDisplay().getOrCreateStack( |
| 3324 | WINDOWING_MODE_FREEFORM, stack.getActivityType(), ON_TOP); |
| 3325 | } |
| 3326 | |
| 3327 | // Reparent the task to the right stack if necessary |
| 3328 | boolean preserveWindow = (resizeMode & RESIZE_MODE_PRESERVE_WINDOW) != 0; |
| 3329 | if (stack != task.getStack()) { |
| 3330 | // Defer resume until the task is resized below |
| 3331 | task.reparent(stack, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, |
| 3332 | DEFER_RESUME, "resizeTask"); |
| 3333 | preserveWindow = false; |
| 3334 | } |
| 3335 | |
| 3336 | // After reparenting (which only resizes the task to the stack bounds), resize the |
| 3337 | // task to the actual bounds provided |
| 3338 | task.resize(bounds, resizeMode, preserveWindow, !DEFER_RESUME); |
| 3339 | } |
| 3340 | } finally { |
| 3341 | Binder.restoreCallingIdentity(ident); |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | @Override |
| 3346 | public boolean releaseActivityInstance(IBinder token) { |
| 3347 | synchronized (mGlobalLock) { |
| 3348 | final long origId = Binder.clearCallingIdentity(); |
| 3349 | try { |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 3350 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3351 | if (r == null || !r.isDestroyable()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3352 | return false; |
| 3353 | } |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 3354 | r.destroyImmediately(true /* removeFromApp */, "app-req"); |
| 3355 | return r.isState(DESTROYING, DESTROYED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3356 | } finally { |
| 3357 | Binder.restoreCallingIdentity(origId); |
| 3358 | } |
| 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | @Override |
| 3363 | public void releaseSomeActivities(IApplicationThread appInt) { |
| 3364 | synchronized (mGlobalLock) { |
| 3365 | final long origId = Binder.clearCallingIdentity(); |
| 3366 | try { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3367 | final WindowProcessController app = getProcessController(appInt); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 3368 | app.releaseSomeActivities("low-mem"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3369 | } finally { |
| 3370 | Binder.restoreCallingIdentity(origId); |
| 3371 | } |
| 3372 | } |
| 3373 | } |
| 3374 | |
| 3375 | @Override |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 3376 | public void setLockScreenShown(boolean keyguardShowing, boolean aodShowing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3377 | if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3378 | != PackageManager.PERMISSION_GRANTED) { |
| 3379 | throw new SecurityException("Requires permission " |
| 3380 | + android.Manifest.permission.DEVICE_POWER); |
| 3381 | } |
| 3382 | |
| 3383 | synchronized (mGlobalLock) { |
| 3384 | long ident = Binder.clearCallingIdentity(); |
| 3385 | if (mKeyguardShown != keyguardShowing) { |
| 3386 | mKeyguardShown = keyguardShowing; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3387 | final Message msg = PooledLambda.obtainMessage( |
| 3388 | ActivityManagerInternal::reportCurKeyguardUsageEvent, mAmInternal, |
| 3389 | keyguardShowing); |
| 3390 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3391 | } |
| 3392 | try { |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 3393 | mKeyguardController.setKeyguardShown(keyguardShowing, aodShowing); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3394 | } finally { |
| 3395 | Binder.restoreCallingIdentity(ident); |
| 3396 | } |
| 3397 | } |
| 3398 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3399 | mH.post(() -> { |
| 3400 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3401 | mScreenObservers.get(i).onKeyguardStateChanged(keyguardShowing); |
| 3402 | } |
| 3403 | }); |
| 3404 | } |
| 3405 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 3406 | public void onScreenAwakeChanged(boolean isAwake) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3407 | mH.post(() -> { |
| 3408 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3409 | mScreenObservers.get(i).onAwakeStateChanged(isAwake); |
| 3410 | } |
| 3411 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3412 | } |
| 3413 | |
| 3414 | @Override |
| 3415 | public Bitmap getTaskDescriptionIcon(String filePath, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3416 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 3417 | userId, "getTaskDescriptionIcon"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3418 | |
| 3419 | final File passedIconFile = new File(filePath); |
| 3420 | final File legitIconFile = new File(TaskPersister.getUserImagesDir(userId), |
| 3421 | passedIconFile.getName()); |
| 3422 | if (!legitIconFile.getPath().equals(filePath) |
| 3423 | || !filePath.contains(ActivityRecord.ACTIVITY_ICON_SUFFIX)) { |
| 3424 | throw new IllegalArgumentException("Bad file path: " + filePath |
| 3425 | + " passed for userId " + userId); |
| 3426 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3427 | return mRecentTasks.getTaskDescriptionIcon(filePath); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3431 | public void removeStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3432 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "removeStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3433 | synchronized (mGlobalLock) { |
| 3434 | final long ident = Binder.clearCallingIdentity(); |
| 3435 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3436 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3437 | if (stack == null) { |
| 3438 | Slog.w(TAG, "removeStack: No stack with id=" + stackId); |
| 3439 | return; |
| 3440 | } |
| 3441 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3442 | throw new IllegalArgumentException( |
| 3443 | "Removing non-standard stack is not allowed."); |
| 3444 | } |
| 3445 | mStackSupervisor.removeStack(stack); |
| 3446 | } finally { |
| 3447 | Binder.restoreCallingIdentity(ident); |
| 3448 | } |
| 3449 | } |
| 3450 | } |
| 3451 | |
| 3452 | @Override |
| 3453 | public void moveStackToDisplay(int stackId, int displayId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3454 | mAmInternal.enforceCallingPermission(INTERNAL_SYSTEM_WINDOW, "moveStackToDisplay()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3455 | |
| 3456 | synchronized (mGlobalLock) { |
| 3457 | final long ident = Binder.clearCallingIdentity(); |
| 3458 | try { |
| 3459 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveStackToDisplay: moving stackId=" + stackId |
| 3460 | + " to displayId=" + displayId); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3461 | mRootWindowContainer.moveStackToDisplay(stackId, displayId, ON_TOP); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3462 | } finally { |
| 3463 | Binder.restoreCallingIdentity(ident); |
| 3464 | } |
| 3465 | } |
| 3466 | } |
| 3467 | |
| 3468 | @Override |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3469 | public void toggleFreeformWindowingMode(IBinder token) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3470 | synchronized (mGlobalLock) { |
| 3471 | long ident = Binder.clearCallingIdentity(); |
| 3472 | try { |
| 3473 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3474 | if (r == null) { |
| 3475 | throw new IllegalArgumentException( |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3476 | "toggleFreeformWindowingMode: No activity record matching token=" |
| 3477 | + token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3478 | } |
| 3479 | |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 3480 | final ActivityStack stack = r.getRootTask(); |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3481 | if (stack == null) { |
| 3482 | throw new IllegalStateException("toggleFreeformWindowingMode: the activity " |
| 3483 | + "doesn't have a stack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3484 | } |
| 3485 | |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3486 | if (!stack.inFreeformWindowingMode() |
| 3487 | && stack.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) { |
| 3488 | throw new IllegalStateException("toggleFreeformWindowingMode: You can only " |
| 3489 | + "toggle between fullscreen and freeform."); |
| 3490 | } |
| 3491 | |
| 3492 | if (stack.inFreeformWindowingMode()) { |
| 3493 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Evan Rosky | 3a8d7fe | 2019-11-06 17:08:35 -0800 | [diff] [blame] | 3494 | } else if (!mSizeCompatFreeform && r.inSizeCompatMode()) { |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 3495 | throw new IllegalStateException("Size-compat windows are currently not" |
| 3496 | + "freeform-enabled"); |
Yunfan Chen | e9c1c31 | 2019-04-18 14:49:15 +0900 | [diff] [blame] | 3497 | } else if (stack.getParent().inFreeformWindowingMode()) { |
| 3498 | // If the window is on a freeform display, set it to undefined. It will be |
| 3499 | // resolved to freeform and it can adjust windowing mode when the display mode |
| 3500 | // changes in runtime. |
| 3501 | stack.setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3502 | } else { |
| 3503 | stack.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 3504 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3505 | } finally { |
| 3506 | Binder.restoreCallingIdentity(ident); |
| 3507 | } |
| 3508 | } |
| 3509 | } |
| 3510 | |
| 3511 | /** Sets the task stack listener that gets callbacks when a task stack changes. */ |
| 3512 | @Override |
| 3513 | public void registerTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3514 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3515 | "registerTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3516 | mTaskChangeNotificationController.registerTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3517 | } |
| 3518 | |
| 3519 | /** Unregister a task stack listener so that it stops receiving callbacks. */ |
| 3520 | @Override |
| 3521 | public void unregisterTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3522 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3523 | "unregisterTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3524 | mTaskChangeNotificationController.unregisterTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3525 | } |
| 3526 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3527 | @Override |
| 3528 | public boolean requestAssistContextExtras(int requestType, IAssistDataReceiver receiver, |
| 3529 | Bundle receiverExtras, IBinder activityToken, boolean focused, boolean newSessionId) { |
| 3530 | return enqueueAssistContext(requestType, null, null, receiver, receiverExtras, |
| 3531 | activityToken, focused, newSessionId, UserHandle.getCallingUserId(), null, |
| 3532 | PENDING_ASSIST_EXTRAS_LONG_TIMEOUT, 0) != null; |
| 3533 | } |
| 3534 | |
| 3535 | @Override |
| 3536 | public boolean requestAutofillData(IAssistDataReceiver receiver, Bundle receiverExtras, |
| 3537 | IBinder activityToken, int flags) { |
| 3538 | return enqueueAssistContext(ActivityManager.ASSIST_CONTEXT_AUTOFILL, null, null, |
| 3539 | receiver, receiverExtras, activityToken, true, true, UserHandle.getCallingUserId(), |
| 3540 | null, PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT, flags) != null; |
| 3541 | } |
| 3542 | |
| 3543 | @Override |
| 3544 | public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle, |
| 3545 | Bundle args) { |
| 3546 | return enqueueAssistContext(requestType, intent, hint, null, null, null, |
| 3547 | true /* focused */, true /* newSessionId */, userHandle, args, |
| 3548 | PENDING_ASSIST_EXTRAS_TIMEOUT, 0) != null; |
| 3549 | } |
| 3550 | |
| 3551 | @Override |
| 3552 | public Bundle getAssistContextExtras(int requestType) { |
| 3553 | PendingAssistExtras pae = enqueueAssistContext(requestType, null, null, null, |
| 3554 | null, null, true /* focused */, true /* newSessionId */, |
| 3555 | UserHandle.getCallingUserId(), null, PENDING_ASSIST_EXTRAS_TIMEOUT, 0); |
| 3556 | if (pae == null) { |
| 3557 | return null; |
| 3558 | } |
| 3559 | synchronized (pae) { |
| 3560 | while (!pae.haveResult) { |
| 3561 | try { |
| 3562 | pae.wait(); |
| 3563 | } catch (InterruptedException e) { |
| 3564 | } |
| 3565 | } |
| 3566 | } |
| 3567 | synchronized (mGlobalLock) { |
| 3568 | buildAssistBundleLocked(pae, pae.result); |
| 3569 | mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3570 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3571 | } |
| 3572 | return pae.extras; |
| 3573 | } |
| 3574 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3575 | /** |
| 3576 | * Binder IPC calls go through the public entry point. |
| 3577 | * This can be called with or without the global lock held. |
| 3578 | */ |
| 3579 | private static int checkCallingPermission(String permission) { |
| 3580 | return checkPermission( |
| 3581 | permission, Binder.getCallingPid(), UserHandle.getAppId(Binder.getCallingUid())); |
| 3582 | } |
| 3583 | |
| 3584 | /** This can be called with or without the global lock held. */ |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3585 | private void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3586 | if (!getRecentTasks().isCallerRecents(Binder.getCallingUid())) { |
| 3587 | mAmInternal.enforceCallingPermission(permission, func); |
| 3588 | } |
| 3589 | } |
| 3590 | |
| 3591 | @VisibleForTesting |
| 3592 | int checkGetTasksPermission(String permission, int pid, int uid) { |
| 3593 | return checkPermission(permission, pid, uid); |
| 3594 | } |
| 3595 | |
| 3596 | static int checkPermission(String permission, int pid, int uid) { |
| 3597 | if (permission == null) { |
| 3598 | return PackageManager.PERMISSION_DENIED; |
| 3599 | } |
| 3600 | return checkComponentPermission(permission, pid, uid, -1, true); |
| 3601 | } |
| 3602 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3603 | public static int checkComponentPermission(String permission, int pid, int uid, |
| 3604 | int owningUid, boolean exported) { |
| 3605 | return ActivityManagerService.checkComponentPermission( |
| 3606 | permission, pid, uid, owningUid, exported); |
| 3607 | } |
| 3608 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3609 | boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 3610 | if (getRecentTasks().isCallerRecents(callingUid)) { |
| 3611 | // Always allow the recents component to get tasks |
| 3612 | return true; |
| 3613 | } |
| 3614 | |
| 3615 | boolean allowed = checkGetTasksPermission(android.Manifest.permission.REAL_GET_TASKS, |
| 3616 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED; |
| 3617 | if (!allowed) { |
| 3618 | if (checkGetTasksPermission(android.Manifest.permission.GET_TASKS, |
| 3619 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED) { |
| 3620 | // Temporary compatibility: some existing apps on the system image may |
| 3621 | // still be requesting the old permission and not switched to the new |
| 3622 | // one; if so, we'll still allow them full access. This means we need |
| 3623 | // to see if they are holding the old permission and are a system app. |
| 3624 | try { |
| 3625 | if (AppGlobals.getPackageManager().isUidPrivileged(callingUid)) { |
| 3626 | allowed = true; |
| 3627 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3628 | + " is using old GET_TASKS but privileged; allowing"); |
| 3629 | } |
| 3630 | } catch (RemoteException e) { |
| 3631 | } |
| 3632 | } |
| 3633 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3634 | + " does not hold REAL_GET_TASKS; limiting output"); |
| 3635 | } |
| 3636 | return allowed; |
| 3637 | } |
| 3638 | |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 3639 | boolean isCrossUserAllowed(int pid, int uid) { |
| 3640 | return checkPermission(INTERACT_ACROSS_USERS, pid, uid) == PERMISSION_GRANTED |
| 3641 | || checkPermission(INTERACT_ACROSS_USERS_FULL, pid, uid) == PERMISSION_GRANTED; |
| 3642 | } |
| 3643 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3644 | private PendingAssistExtras enqueueAssistContext(int requestType, Intent intent, String hint, |
| 3645 | IAssistDataReceiver receiver, Bundle receiverExtras, IBinder activityToken, |
| 3646 | boolean focused, boolean newSessionId, int userHandle, Bundle args, long timeout, |
| 3647 | int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3648 | mAmInternal.enforceCallingPermission(android.Manifest.permission.GET_TOP_ACTIVITY_INFO, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3649 | "enqueueAssistContext()"); |
| 3650 | |
| 3651 | synchronized (mGlobalLock) { |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3652 | ActivityRecord activity = getTopDisplayFocusedStack().getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3653 | if (activity == null) { |
| 3654 | Slog.w(TAG, "getAssistContextExtras failed: no top activity"); |
| 3655 | return null; |
| 3656 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3657 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3658 | Slog.w(TAG, "getAssistContextExtras failed: no process for " + activity); |
| 3659 | return null; |
| 3660 | } |
| 3661 | if (focused) { |
| 3662 | if (activityToken != null) { |
| 3663 | ActivityRecord caller = ActivityRecord.forTokenLocked(activityToken); |
| 3664 | if (activity != caller) { |
| 3665 | Slog.w(TAG, "enqueueAssistContext failed: caller " + caller |
| 3666 | + " is not current top " + activity); |
| 3667 | return null; |
| 3668 | } |
| 3669 | } |
| 3670 | } else { |
| 3671 | activity = ActivityRecord.forTokenLocked(activityToken); |
| 3672 | if (activity == null) { |
| 3673 | Slog.w(TAG, "enqueueAssistContext failed: activity for token=" + activityToken |
| 3674 | + " couldn't be found"); |
| 3675 | return null; |
| 3676 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3677 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3678 | Slog.w(TAG, "enqueueAssistContext failed: no process for " + activity); |
| 3679 | return null; |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | PendingAssistExtras pae; |
| 3684 | Bundle extras = new Bundle(); |
| 3685 | if (args != null) { |
| 3686 | extras.putAll(args); |
| 3687 | } |
| 3688 | extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3689 | extras.putInt(Intent.EXTRA_ASSIST_UID, activity.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3690 | |
| 3691 | pae = new PendingAssistExtras(activity, extras, intent, hint, receiver, receiverExtras, |
| 3692 | userHandle); |
| 3693 | pae.isHome = activity.isActivityTypeHome(); |
| 3694 | |
| 3695 | // Increment the sessionId if necessary |
| 3696 | if (newSessionId) { |
| 3697 | mViSessionId++; |
| 3698 | } |
| 3699 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3700 | activity.app.getThread().requestAssistContextExtras(activity.appToken, pae, |
| 3701 | requestType, mViSessionId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3702 | mPendingAssistExtras.add(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3703 | mUiHandler.postDelayed(pae, timeout); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3704 | } catch (RemoteException e) { |
| 3705 | Slog.w(TAG, "getAssistContextExtras failed: crash calling " + activity); |
| 3706 | return null; |
| 3707 | } |
| 3708 | return pae; |
| 3709 | } |
| 3710 | } |
| 3711 | |
| 3712 | private void buildAssistBundleLocked(PendingAssistExtras pae, Bundle result) { |
| 3713 | if (result != null) { |
| 3714 | pae.extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, result); |
| 3715 | } |
| 3716 | if (pae.hint != null) { |
| 3717 | pae.extras.putBoolean(pae.hint, true); |
| 3718 | } |
| 3719 | } |
| 3720 | |
| 3721 | private void pendingAssistExtrasTimedOut(PendingAssistExtras pae) { |
| 3722 | IAssistDataReceiver receiver; |
| 3723 | synchronized (mGlobalLock) { |
| 3724 | mPendingAssistExtras.remove(pae); |
| 3725 | receiver = pae.receiver; |
| 3726 | } |
| 3727 | if (receiver != null) { |
| 3728 | // Caller wants result sent back to them. |
| 3729 | Bundle sendBundle = new Bundle(); |
| 3730 | // At least return the receiver extras |
| 3731 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3732 | try { |
| 3733 | pae.receiver.onHandleAssistData(sendBundle); |
| 3734 | } catch (RemoteException e) { |
| 3735 | } |
| 3736 | } |
| 3737 | } |
| 3738 | |
| 3739 | public class PendingAssistExtras extends Binder implements Runnable { |
| 3740 | public final ActivityRecord activity; |
| 3741 | public boolean isHome; |
| 3742 | public final Bundle extras; |
| 3743 | public final Intent intent; |
| 3744 | public final String hint; |
| 3745 | public final IAssistDataReceiver receiver; |
| 3746 | public final int userHandle; |
| 3747 | public boolean haveResult = false; |
| 3748 | public Bundle result = null; |
| 3749 | public AssistStructure structure = null; |
| 3750 | public AssistContent content = null; |
| 3751 | public Bundle receiverExtras; |
| 3752 | |
| 3753 | public PendingAssistExtras(ActivityRecord _activity, Bundle _extras, Intent _intent, |
| 3754 | String _hint, IAssistDataReceiver _receiver, Bundle _receiverExtras, |
| 3755 | int _userHandle) { |
| 3756 | activity = _activity; |
| 3757 | extras = _extras; |
| 3758 | intent = _intent; |
| 3759 | hint = _hint; |
| 3760 | receiver = _receiver; |
| 3761 | receiverExtras = _receiverExtras; |
| 3762 | userHandle = _userHandle; |
| 3763 | } |
| 3764 | |
| 3765 | @Override |
| 3766 | public void run() { |
| 3767 | Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from " + activity); |
| 3768 | synchronized (this) { |
| 3769 | haveResult = true; |
| 3770 | notifyAll(); |
| 3771 | } |
| 3772 | pendingAssistExtrasTimedOut(this); |
| 3773 | } |
| 3774 | } |
| 3775 | |
| 3776 | @Override |
| 3777 | public boolean isAssistDataAllowedOnCurrentActivity() { |
| 3778 | int userId; |
| 3779 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3780 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3781 | if (focusedStack == null || focusedStack.isActivityTypeAssistant()) { |
| 3782 | return false; |
| 3783 | } |
| 3784 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3785 | final ActivityRecord activity = focusedStack.getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3786 | if (activity == null) { |
| 3787 | return false; |
| 3788 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3789 | userId = activity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3790 | } |
| 3791 | return !DevicePolicyCache.getInstance().getScreenCaptureDisabled(userId); |
| 3792 | } |
| 3793 | |
| 3794 | @Override |
| 3795 | public boolean showAssistFromActivity(IBinder token, Bundle args) { |
| 3796 | long ident = Binder.clearCallingIdentity(); |
| 3797 | try { |
| 3798 | synchronized (mGlobalLock) { |
| 3799 | ActivityRecord caller = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3800 | ActivityRecord top = getTopDisplayFocusedStack().getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3801 | if (top != caller) { |
| 3802 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3803 | + " is not current top " + top); |
| 3804 | return false; |
| 3805 | } |
| 3806 | if (!top.nowVisible) { |
| 3807 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3808 | + " is not visible"); |
| 3809 | return false; |
| 3810 | } |
| 3811 | } |
| 3812 | return mAssistUtils.showSessionForActiveService(args, SHOW_SOURCE_APPLICATION, null, |
| 3813 | token); |
| 3814 | } finally { |
| 3815 | Binder.restoreCallingIdentity(ident); |
| 3816 | } |
| 3817 | } |
| 3818 | |
| 3819 | @Override |
| 3820 | public boolean isRootVoiceInteraction(IBinder token) { |
| 3821 | synchronized (mGlobalLock) { |
| 3822 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3823 | if (r == null) { |
| 3824 | return false; |
| 3825 | } |
| 3826 | return r.rootVoiceInteraction; |
| 3827 | } |
| 3828 | } |
| 3829 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3830 | private void onLocalVoiceInteractionStartedLocked(IBinder activity, |
| 3831 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 3832 | ActivityRecord activityToCallback = ActivityRecord.forTokenLocked(activity); |
| 3833 | if (activityToCallback == null) return; |
| 3834 | activityToCallback.setVoiceSessionLocked(voiceSession); |
| 3835 | |
| 3836 | // Inform the activity |
| 3837 | try { |
| 3838 | activityToCallback.app.getThread().scheduleLocalVoiceInteractionStarted(activity, |
| 3839 | voiceInteractor); |
| 3840 | long token = Binder.clearCallingIdentity(); |
| 3841 | try { |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 3842 | startRunningVoiceLocked(voiceSession, activityToCallback.info.applicationInfo.uid); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3843 | } finally { |
| 3844 | Binder.restoreCallingIdentity(token); |
| 3845 | } |
| 3846 | // TODO: VI Should we cache the activity so that it's easier to find later |
| 3847 | // rather than scan through all the stacks and activities? |
| 3848 | } catch (RemoteException re) { |
| 3849 | activityToCallback.clearVoiceSessionLocked(); |
| 3850 | // TODO: VI Should this terminate the voice session? |
| 3851 | } |
| 3852 | } |
| 3853 | |
| 3854 | private void startRunningVoiceLocked(IVoiceInteractionSession session, int targetUid) { |
| 3855 | Slog.d(TAG, "<<< startRunningVoiceLocked()"); |
| 3856 | mVoiceWakeLock.setWorkSource(new WorkSource(targetUid)); |
| 3857 | if (mRunningVoice == null || mRunningVoice.asBinder() != session.asBinder()) { |
| 3858 | boolean wasRunningVoice = mRunningVoice != null; |
| 3859 | mRunningVoice = session; |
| 3860 | if (!wasRunningVoice) { |
| 3861 | mVoiceWakeLock.acquire(); |
| 3862 | updateSleepIfNeededLocked(); |
| 3863 | } |
| 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | void finishRunningVoiceLocked() { |
| 3868 | if (mRunningVoice != null) { |
| 3869 | mRunningVoice = null; |
| 3870 | mVoiceWakeLock.release(); |
| 3871 | updateSleepIfNeededLocked(); |
| 3872 | } |
| 3873 | } |
| 3874 | |
| 3875 | @Override |
| 3876 | public void setVoiceKeepAwake(IVoiceInteractionSession session, boolean keepAwake) { |
| 3877 | synchronized (mGlobalLock) { |
| 3878 | if (mRunningVoice != null && mRunningVoice.asBinder() == session.asBinder()) { |
| 3879 | if (keepAwake) { |
| 3880 | mVoiceWakeLock.acquire(); |
| 3881 | } else { |
| 3882 | mVoiceWakeLock.release(); |
| 3883 | } |
| 3884 | } |
| 3885 | } |
| 3886 | } |
| 3887 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3888 | @Override |
| 3889 | public ComponentName getActivityClassForToken(IBinder token) { |
| 3890 | synchronized (mGlobalLock) { |
| 3891 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3892 | if (r == null) { |
| 3893 | return null; |
| 3894 | } |
| 3895 | return r.intent.getComponent(); |
| 3896 | } |
| 3897 | } |
| 3898 | |
| 3899 | @Override |
| 3900 | public String getPackageForToken(IBinder token) { |
| 3901 | synchronized (mGlobalLock) { |
| 3902 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3903 | if (r == null) { |
| 3904 | return null; |
| 3905 | } |
| 3906 | return r.packageName; |
| 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | @Override |
| 3911 | public void showLockTaskEscapeMessage(IBinder token) { |
| 3912 | synchronized (mGlobalLock) { |
| 3913 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3914 | if (r == null) { |
| 3915 | return; |
| 3916 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3917 | getLockTaskController().showLockTaskToast(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3918 | } |
| 3919 | } |
| 3920 | |
| 3921 | @Override |
| 3922 | public void keyguardGoingAway(int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3923 | enforceNotIsolatedCaller("keyguardGoingAway"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3924 | final long token = Binder.clearCallingIdentity(); |
| 3925 | try { |
| 3926 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3927 | mKeyguardController.keyguardGoingAway(flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3928 | } |
| 3929 | } finally { |
| 3930 | Binder.restoreCallingIdentity(token); |
| 3931 | } |
| 3932 | } |
| 3933 | |
| 3934 | /** |
| 3935 | * Try to place task to provided position. The final position might be different depending on |
| 3936 | * current user and stacks state. The task will be moved to target stack if it's currently in |
| 3937 | * different stack. |
| 3938 | */ |
| 3939 | @Override |
| 3940 | public void positionTaskInStack(int taskId, int stackId, int position) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3941 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "positionTaskInStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3942 | synchronized (mGlobalLock) { |
| 3943 | long ident = Binder.clearCallingIdentity(); |
| 3944 | try { |
| 3945 | if (DEBUG_STACK) Slog.d(TAG_STACK, "positionTaskInStack: positioning task=" |
| 3946 | + taskId + " in stackId=" + stackId + " at position=" + position); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3947 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3948 | if (task == null) { |
| 3949 | throw new IllegalArgumentException("positionTaskInStack: no task for id=" |
| 3950 | + taskId); |
| 3951 | } |
| 3952 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3953 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3954 | |
| 3955 | if (stack == null) { |
| 3956 | throw new IllegalArgumentException("positionTaskInStack: no stack for id=" |
| 3957 | + stackId); |
| 3958 | } |
| 3959 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3960 | throw new IllegalArgumentException("positionTaskInStack: Attempt to change" |
| 3961 | + " the position of task " + taskId + " in/to non-standard stack"); |
| 3962 | } |
| 3963 | |
| 3964 | // TODO: Have the callers of this API call a separate reparent method if that is |
| 3965 | // what they intended to do vs. having this method also do reparenting. |
| 3966 | if (task.getStack() == stack) { |
| 3967 | // Change position in current stack. |
| 3968 | stack.positionChildAt(task, position); |
| 3969 | } else { |
| 3970 | // Reparent to new stack. |
| 3971 | task.reparent(stack, position, REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, |
| 3972 | !DEFER_RESUME, "positionTaskInStack"); |
| 3973 | } |
| 3974 | } finally { |
| 3975 | Binder.restoreCallingIdentity(ident); |
| 3976 | } |
| 3977 | } |
| 3978 | } |
| 3979 | |
| 3980 | @Override |
| 3981 | public void reportSizeConfigurations(IBinder token, int[] horizontalSizeConfiguration, |
| 3982 | int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { |
| 3983 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Report configuration: " + token + " " |
Yuichiro Hanada | e7e930b | 2019-06-06 19:07:21 +0900 | [diff] [blame] | 3984 | + Arrays.toString(horizontalSizeConfiguration) + " " |
| 3985 | + Arrays.toString(verticalSizeConfigurations)); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3986 | synchronized (mGlobalLock) { |
| 3987 | ActivityRecord record = ActivityRecord.isInStackLocked(token); |
| 3988 | if (record == null) { |
| 3989 | throw new IllegalArgumentException("reportSizeConfigurations: ActivityRecord not " |
| 3990 | + "found for: " + token); |
| 3991 | } |
| 3992 | record.setSizeConfigurations(horizontalSizeConfiguration, |
| 3993 | verticalSizeConfigurations, smallestSizeConfigurations); |
| 3994 | } |
| 3995 | } |
| 3996 | |
| 3997 | /** |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3998 | * Dismisses Pip |
| 3999 | * @param animate True if the dismissal should be animated. |
| 4000 | * @param animationDuration The duration of the resize animation in milliseconds or -1 if the |
| 4001 | * default animation duration should be used. |
| 4002 | */ |
| 4003 | @Override |
| 4004 | public void dismissPip(boolean animate, int animationDuration) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4005 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "dismissPip()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4006 | final long ident = Binder.clearCallingIdentity(); |
| 4007 | try { |
| 4008 | synchronized (mGlobalLock) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 4009 | final ActivityStack stack = |
Wale Ogunwale | 734b896 | 2020-01-21 12:17:42 -0800 | [diff] [blame] | 4010 | mRootWindowContainer.getDefaultDisplay().getRootPinnedTask(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4011 | if (stack == null) { |
| 4012 | Slog.w(TAG, "dismissPip: pinned stack not found."); |
| 4013 | return; |
| 4014 | } |
| 4015 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 4016 | throw new IllegalArgumentException("Stack: " + stack |
| 4017 | + " doesn't support animated resize."); |
| 4018 | } |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 4019 | /** |
| 4020 | * TODO(b/146594635): Remove all PIP animation code from WM |
| 4021 | * once SysUI handles animation. Don't even try to animate TaskOrganized tasks. |
| 4022 | */ |
| 4023 | if (animate && !stack.isControlledByTaskOrganizer()) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4024 | stack.animateResizePinnedStack(null /* destBounds */, |
| 4025 | null /* sourceHintBounds */, animationDuration, |
| 4026 | false /* fromFullscreen */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4027 | } else { |
Ben Lin | 6db8fb2 | 2019-10-18 16:03:44 -0700 | [diff] [blame] | 4028 | stack.dismissPip(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4029 | } |
| 4030 | } |
| 4031 | } finally { |
| 4032 | Binder.restoreCallingIdentity(ident); |
| 4033 | } |
| 4034 | } |
| 4035 | |
| 4036 | @Override |
| 4037 | public void suppressResizeConfigChanges(boolean suppress) throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4038 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "suppressResizeConfigChanges()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4039 | synchronized (mGlobalLock) { |
| 4040 | mSuppressResizeConfigChanges = suppress; |
| 4041 | } |
| 4042 | } |
| 4043 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4044 | @Override |
| 4045 | // TODO: API should just be about changing windowing modes... |
| 4046 | public void moveTasksToFullscreenStack(int fromStackId, boolean onTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4047 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4048 | "moveTasksToFullscreenStack()"); |
| 4049 | synchronized (mGlobalLock) { |
| 4050 | final long origId = Binder.clearCallingIdentity(); |
| 4051 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4052 | final ActivityStack stack = mRootWindowContainer.getStack(fromStackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4053 | if (stack != null){ |
| 4054 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 4055 | throw new IllegalArgumentException( |
| 4056 | "You can't move tasks from non-standard stacks."); |
| 4057 | } |
| 4058 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, onTop); |
| 4059 | } |
| 4060 | } finally { |
| 4061 | Binder.restoreCallingIdentity(origId); |
| 4062 | } |
| 4063 | } |
| 4064 | } |
| 4065 | |
| 4066 | /** |
| 4067 | * Moves the top activity in the input stackId to the pinned stack. |
| 4068 | * |
| 4069 | * @param stackId Id of stack to move the top activity to pinned stack. |
| 4070 | * @param bounds Bounds to use for pinned stack. |
| 4071 | * |
| 4072 | * @return True if the top activity of the input stack was successfully moved to the pinned |
| 4073 | * stack. |
| 4074 | */ |
| 4075 | @Override |
| 4076 | public boolean moveTopActivityToPinnedStack(int stackId, Rect bounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4077 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4078 | "moveTopActivityToPinnedStack()"); |
| 4079 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4080 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4081 | throw new IllegalStateException("moveTopActivityToPinnedStack:" |
| 4082 | + "Device doesn't support picture-in-picture mode"); |
| 4083 | } |
| 4084 | |
| 4085 | long ident = Binder.clearCallingIdentity(); |
| 4086 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4087 | return mRootWindowContainer.moveTopStackActivityToPinnedStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4088 | } finally { |
| 4089 | Binder.restoreCallingIdentity(ident); |
| 4090 | } |
| 4091 | } |
| 4092 | } |
| 4093 | |
| 4094 | @Override |
| 4095 | public boolean isInMultiWindowMode(IBinder token) { |
| 4096 | final long origId = Binder.clearCallingIdentity(); |
| 4097 | try { |
| 4098 | synchronized (mGlobalLock) { |
| 4099 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4100 | if (r == null) { |
| 4101 | return false; |
| 4102 | } |
| 4103 | // An activity is consider to be in multi-window mode if its task isn't fullscreen. |
| 4104 | return r.inMultiWindowMode(); |
| 4105 | } |
| 4106 | } finally { |
| 4107 | Binder.restoreCallingIdentity(origId); |
| 4108 | } |
| 4109 | } |
| 4110 | |
| 4111 | @Override |
| 4112 | public boolean isInPictureInPictureMode(IBinder token) { |
| 4113 | final long origId = Binder.clearCallingIdentity(); |
| 4114 | try { |
| 4115 | synchronized (mGlobalLock) { |
| 4116 | return isInPictureInPictureMode(ActivityRecord.forTokenLocked(token)); |
| 4117 | } |
| 4118 | } finally { |
| 4119 | Binder.restoreCallingIdentity(origId); |
| 4120 | } |
| 4121 | } |
| 4122 | |
| 4123 | private boolean isInPictureInPictureMode(ActivityRecord r) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 4124 | if (r == null || r.getRootTask() == null || !r.inPinnedWindowingMode() |
| 4125 | || r.getRootTask().isInStackLocked(r) == null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4126 | return false; |
| 4127 | } |
| 4128 | |
| 4129 | // If we are animating to fullscreen then we have already dispatched the PIP mode |
| 4130 | // changed, so we should reflect that check here as well. |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 4131 | final ActivityStack taskStack = r.getRootTask(); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 4132 | return !taskStack.isAnimatingBoundsToFullscreen(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | @Override |
| 4136 | public boolean enterPictureInPictureMode(IBinder token, final PictureInPictureParams params) { |
| 4137 | final long origId = Binder.clearCallingIdentity(); |
| 4138 | try { |
| 4139 | synchronized (mGlobalLock) { |
| 4140 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 4141 | "enterPictureInPictureMode", token, params); |
| 4142 | |
| 4143 | // If the activity is already in picture in picture mode, then just return early |
| 4144 | if (isInPictureInPictureMode(r)) { |
| 4145 | return true; |
| 4146 | } |
| 4147 | |
| 4148 | // Activity supports picture-in-picture, now check that we can enter PiP at this |
| 4149 | // point, if it is |
| 4150 | if (!r.checkEnterPictureInPictureState("enterPictureInPictureMode", |
| 4151 | false /* beforeStopping */)) { |
| 4152 | return false; |
| 4153 | } |
| 4154 | |
| 4155 | final Runnable enterPipRunnable = () -> { |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4156 | synchronized (mGlobalLock) { |
Hyangseok Chae | ed0624e | 2019-11-07 10:15:46 +0900 | [diff] [blame] | 4157 | if (r.getParent() == null) { |
| 4158 | Slog.e(TAG, "Skip enterPictureInPictureMode, destroyed " + r); |
| 4159 | return; |
| 4160 | } |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4161 | // Only update the saved args from the args that are set |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 4162 | r.setPictureInPictureParams(params); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4163 | final float aspectRatio = r.pictureInPictureArgs.getAspectRatio(); |
| 4164 | final List<RemoteAction> actions = r.pictureInPictureArgs.getActions(); |
| 4165 | // Adjust the source bounds by the insets for the transition down |
| 4166 | final Rect sourceBounds = new Rect( |
| 4167 | r.pictureInPictureArgs.getSourceRectHint()); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4168 | mRootWindowContainer.moveActivityToPinnedStack( |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4169 | r, sourceBounds, aspectRatio, "enterPictureInPictureMode"); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 4170 | final ActivityStack stack = r.getRootTask(); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4171 | stack.setPictureInPictureAspectRatio(aspectRatio); |
| 4172 | stack.setPictureInPictureActions(actions); |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 4173 | MetricsLoggerWrapper.logPictureInPictureEnter(mContext, |
| 4174 | r.info.applicationInfo.uid, r.shortComponentName, |
| 4175 | r.supportsEnterPipOnTaskSwitch); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4176 | logPictureInPictureArgs(params); |
| 4177 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4178 | }; |
| 4179 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4180 | if (isKeyguardLocked()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4181 | // If the keyguard is showing or occluded, then try and dismiss it before |
| 4182 | // entering picture-in-picture (this will prompt the user to authenticate if the |
| 4183 | // device is currently locked). |
| 4184 | dismissKeyguard(token, new KeyguardDismissCallback() { |
| 4185 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4186 | public void onDismissSucceeded() { |
| 4187 | mH.post(enterPipRunnable); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4188 | } |
| 4189 | }, null /* message */); |
| 4190 | } else { |
| 4191 | // Enter picture in picture immediately otherwise |
| 4192 | enterPipRunnable.run(); |
| 4193 | } |
| 4194 | return true; |
| 4195 | } |
| 4196 | } finally { |
| 4197 | Binder.restoreCallingIdentity(origId); |
| 4198 | } |
| 4199 | } |
| 4200 | |
| 4201 | @Override |
| 4202 | public void setPictureInPictureParams(IBinder token, final PictureInPictureParams params) { |
| 4203 | final long origId = Binder.clearCallingIdentity(); |
| 4204 | try { |
| 4205 | synchronized (mGlobalLock) { |
| 4206 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 4207 | "setPictureInPictureParams", token, params); |
| 4208 | |
| 4209 | // Only update the saved args from the args that are set |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 4210 | r.setPictureInPictureParams(params); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4211 | if (r.inPinnedWindowingMode()) { |
| 4212 | // If the activity is already in picture-in-picture, update the pinned stack now |
| 4213 | // if it is not already expanding to fullscreen. Otherwise, the arguments will |
| 4214 | // be used the next time the activity enters PiP |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 4215 | final ActivityStack stack = r.getRootTask(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4216 | if (!stack.isAnimatingBoundsToFullscreen()) { |
| 4217 | stack.setPictureInPictureAspectRatio( |
| 4218 | r.pictureInPictureArgs.getAspectRatio()); |
| 4219 | stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions()); |
| 4220 | } |
| 4221 | } |
| 4222 | logPictureInPictureArgs(params); |
| 4223 | } |
| 4224 | } finally { |
| 4225 | Binder.restoreCallingIdentity(origId); |
| 4226 | } |
| 4227 | } |
| 4228 | |
| 4229 | @Override |
| 4230 | public int getMaxNumPictureInPictureActions(IBinder token) { |
| 4231 | // Currently, this is a static constant, but later, we may change this to be dependent on |
| 4232 | // the context of the activity |
| 4233 | return 3; |
| 4234 | } |
| 4235 | |
| 4236 | private void logPictureInPictureArgs(PictureInPictureParams params) { |
| 4237 | if (params.hasSetActions()) { |
| 4238 | MetricsLogger.histogram(mContext, "tron_varz_picture_in_picture_actions_count", |
| 4239 | params.getActions().size()); |
| 4240 | } |
| 4241 | if (params.hasSetAspectRatio()) { |
| 4242 | LogMaker lm = new LogMaker(MetricsEvent.ACTION_PICTURE_IN_PICTURE_ASPECT_RATIO_CHANGED); |
| 4243 | lm.addTaggedData(MetricsEvent.PICTURE_IN_PICTURE_ASPECT_RATIO, params.getAspectRatio()); |
| 4244 | MetricsLogger.action(lm); |
| 4245 | } |
| 4246 | } |
| 4247 | |
| 4248 | /** |
| 4249 | * Checks the state of the system and the activity associated with the given {@param token} to |
| 4250 | * verify that picture-in-picture is supported for that activity. |
| 4251 | * |
| 4252 | * @return the activity record for the given {@param token} if all the checks pass. |
| 4253 | */ |
| 4254 | private ActivityRecord ensureValidPictureInPictureActivityParamsLocked(String caller, |
| 4255 | IBinder token, PictureInPictureParams params) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4256 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4257 | throw new IllegalStateException(caller |
| 4258 | + ": Device doesn't support picture-in-picture mode."); |
| 4259 | } |
| 4260 | |
| 4261 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 4262 | if (r == null) { |
| 4263 | throw new IllegalStateException(caller |
| 4264 | + ": Can't find activity for token=" + token); |
| 4265 | } |
| 4266 | |
| 4267 | if (!r.supportsPictureInPicture()) { |
| 4268 | throw new IllegalStateException(caller |
| 4269 | + ": Current activity does not support picture-in-picture."); |
| 4270 | } |
| 4271 | |
| 4272 | if (params.hasSetAspectRatio() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4273 | && !mWindowManager.isValidPictureInPictureAspectRatio( |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 4274 | r.getDisplay(), params.getAspectRatio())) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4275 | final float minAspectRatio = mContext.getResources().getFloat( |
| 4276 | com.android.internal.R.dimen.config_pictureInPictureMinAspectRatio); |
| 4277 | final float maxAspectRatio = mContext.getResources().getFloat( |
| 4278 | com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio); |
| 4279 | throw new IllegalArgumentException(String.format(caller |
| 4280 | + ": Aspect ratio is too extreme (must be between %f and %f).", |
| 4281 | minAspectRatio, maxAspectRatio)); |
| 4282 | } |
| 4283 | |
| 4284 | // Truncate the number of actions if necessary |
| 4285 | params.truncateActions(getMaxNumPictureInPictureActions(token)); |
| 4286 | |
| 4287 | return r; |
| 4288 | } |
| 4289 | |
| 4290 | @Override |
| 4291 | public IBinder getUriPermissionOwnerForActivity(IBinder activityToken) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4292 | enforceNotIsolatedCaller("getUriPermissionOwnerForActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4293 | synchronized (mGlobalLock) { |
| 4294 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 4295 | if (r == null) { |
| 4296 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 4297 | + activityToken); |
| 4298 | } |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 4299 | return r.getUriPermissionsLocked().getExternalToken(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4300 | } |
| 4301 | } |
| 4302 | |
| 4303 | @Override |
| 4304 | public void resizeDockedStack(Rect dockedBounds, Rect tempDockedTaskBounds, |
| 4305 | Rect tempDockedTaskInsetBounds, |
| 4306 | Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4307 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeDockedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4308 | long ident = Binder.clearCallingIdentity(); |
| 4309 | try { |
| 4310 | synchronized (mGlobalLock) { |
| 4311 | mStackSupervisor.resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, |
| 4312 | tempDockedTaskInsetBounds, tempOtherTaskBounds, tempOtherTaskInsetBounds, |
| 4313 | PRESERVE_WINDOWS); |
| 4314 | } |
| 4315 | } finally { |
| 4316 | Binder.restoreCallingIdentity(ident); |
| 4317 | } |
| 4318 | } |
| 4319 | |
| 4320 | @Override |
| 4321 | public void setSplitScreenResizing(boolean resizing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4322 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setSplitScreenResizing()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4323 | final long ident = Binder.clearCallingIdentity(); |
| 4324 | try { |
| 4325 | synchronized (mGlobalLock) { |
| 4326 | mStackSupervisor.setSplitScreenResizing(resizing); |
| 4327 | } |
| 4328 | } finally { |
| 4329 | Binder.restoreCallingIdentity(ident); |
| 4330 | } |
| 4331 | } |
| 4332 | |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 4333 | @Override |
| 4334 | public ITaskOrganizerController getTaskOrganizerController() { |
| 4335 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, |
| 4336 | "getTaskOrganizerController()"); |
| 4337 | return mTaskOrganizerController; |
| 4338 | } |
| 4339 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4340 | /** |
| 4341 | * Check that we have the features required for VR-related API calls, and throw an exception if |
| 4342 | * not. |
| 4343 | */ |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 4344 | public void enforceSystemHasVrFeature() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4345 | if (!mContext.getPackageManager().hasSystemFeature( |
| 4346 | PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE)) { |
| 4347 | throw new UnsupportedOperationException("VR mode not supported on this device!"); |
| 4348 | } |
| 4349 | } |
| 4350 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4351 | @Override |
| 4352 | public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4353 | enforceSystemHasVrFeature(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4354 | |
| 4355 | final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class); |
| 4356 | |
| 4357 | ActivityRecord r; |
| 4358 | synchronized (mGlobalLock) { |
| 4359 | r = ActivityRecord.isInStackLocked(token); |
| 4360 | } |
| 4361 | |
| 4362 | if (r == null) { |
| 4363 | throw new IllegalArgumentException(); |
| 4364 | } |
| 4365 | |
| 4366 | int err; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4367 | if ((err = vrService.hasVrPackage(packageName, r.mUserId)) != |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4368 | VrManagerInternal.NO_ERROR) { |
| 4369 | return err; |
| 4370 | } |
| 4371 | |
| 4372 | // Clear the binder calling uid since this path may call moveToTask(). |
| 4373 | final long callingId = Binder.clearCallingIdentity(); |
| 4374 | try { |
| 4375 | synchronized (mGlobalLock) { |
| 4376 | r.requestedVrComponent = (enabled) ? packageName : null; |
| 4377 | |
| 4378 | // Update associated state if this activity is currently focused |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 4379 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4380 | applyUpdateVrModeLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4381 | } |
| 4382 | return 0; |
| 4383 | } |
| 4384 | } finally { |
| 4385 | Binder.restoreCallingIdentity(callingId); |
| 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | @Override |
| 4390 | public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) { |
| 4391 | Slog.i(TAG, "Activity tried to startLocalVoiceInteraction"); |
| 4392 | synchronized (mGlobalLock) { |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 4393 | ActivityRecord activity = getTopDisplayFocusedStack().getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4394 | if (ActivityRecord.forTokenLocked(callingActivity) != activity) { |
| 4395 | throw new SecurityException("Only focused activity can call startVoiceInteraction"); |
| 4396 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4397 | if (mRunningVoice != null || activity.getTask().voiceSession != null |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4398 | || activity.voiceSession != null) { |
| 4399 | Slog.w(TAG, "Already in a voice interaction, cannot start new voice interaction"); |
| 4400 | return; |
| 4401 | } |
| 4402 | if (activity.pendingVoiceInteractionStart) { |
| 4403 | Slog.w(TAG, "Pending start of voice interaction already."); |
| 4404 | return; |
| 4405 | } |
| 4406 | activity.pendingVoiceInteractionStart = true; |
| 4407 | } |
| 4408 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4409 | .startLocalVoiceInteraction(callingActivity, options); |
| 4410 | } |
| 4411 | |
| 4412 | @Override |
| 4413 | public void stopLocalVoiceInteraction(IBinder callingActivity) { |
| 4414 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4415 | .stopLocalVoiceInteraction(callingActivity); |
| 4416 | } |
| 4417 | |
| 4418 | @Override |
| 4419 | public boolean supportsLocalVoiceInteraction() { |
| 4420 | return LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4421 | .supportsLocalVoiceInteraction(); |
| 4422 | } |
| 4423 | |
| 4424 | /** Notifies all listeners when the pinned stack animation starts. */ |
| 4425 | @Override |
| 4426 | public void notifyPinnedStackAnimationStarted() { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4427 | mTaskChangeNotificationController.notifyPinnedStackAnimationStarted(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4428 | } |
| 4429 | |
| 4430 | /** Notifies all listeners when the pinned stack animation ends. */ |
| 4431 | @Override |
| 4432 | public void notifyPinnedStackAnimationEnded() { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4433 | mTaskChangeNotificationController.notifyPinnedStackAnimationEnded(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4434 | } |
| 4435 | |
| 4436 | @Override |
Wale Ogunwale | ea5e87f | 2020-02-10 08:33:05 -0800 | [diff] [blame^] | 4437 | public void resizePinnedStack(Rect displayedBounds, Rect configBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4438 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizePinnedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4439 | final long ident = Binder.clearCallingIdentity(); |
| 4440 | try { |
| 4441 | synchronized (mGlobalLock) { |
Wale Ogunwale | ea5e87f | 2020-02-10 08:33:05 -0800 | [diff] [blame^] | 4442 | mStackSupervisor.resizePinnedStack(displayedBounds, configBounds); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4443 | } |
| 4444 | } finally { |
| 4445 | Binder.restoreCallingIdentity(ident); |
| 4446 | } |
| 4447 | } |
| 4448 | |
| 4449 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4450 | public boolean updateConfiguration(Configuration values) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4451 | mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateConfiguration()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4452 | |
| 4453 | synchronized (mGlobalLock) { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 4454 | if (mWindowManager == null) { |
| 4455 | Slog.w(TAG, "Skip updateConfiguration because mWindowManager isn't set"); |
| 4456 | return false; |
| 4457 | } |
| 4458 | |
| 4459 | if (values == null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4460 | // sentinel: fetch the current configuration from the window manager |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4461 | values = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4462 | } |
| 4463 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 4464 | mH.sendMessage(PooledLambda.obtainMessage( |
| 4465 | ActivityManagerInternal::updateOomLevelsForDisplay, mAmInternal, |
| 4466 | DEFAULT_DISPLAY)); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4467 | |
| 4468 | final long origId = Binder.clearCallingIdentity(); |
| 4469 | try { |
| 4470 | if (values != null) { |
| 4471 | Settings.System.clearConfiguration(values); |
| 4472 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4473 | updateConfigurationLocked(values, null, false, false /* persistent */, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4474 | UserHandle.USER_NULL, false /* deferResume */, |
| 4475 | mTmpUpdateConfigurationResult); |
| 4476 | return mTmpUpdateConfigurationResult.changes != 0; |
| 4477 | } finally { |
| 4478 | Binder.restoreCallingIdentity(origId); |
| 4479 | } |
| 4480 | } |
| 4481 | } |
| 4482 | |
| 4483 | @Override |
| 4484 | public void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback, |
| 4485 | CharSequence message) { |
| 4486 | if (message != null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4487 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4488 | Manifest.permission.SHOW_KEYGUARD_MESSAGE, "dismissKeyguard()"); |
| 4489 | } |
| 4490 | final long callingId = Binder.clearCallingIdentity(); |
| 4491 | try { |
| 4492 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4493 | mKeyguardController.dismissKeyguard(token, callback, message); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4494 | } |
| 4495 | } finally { |
| 4496 | Binder.restoreCallingIdentity(callingId); |
| 4497 | } |
| 4498 | } |
| 4499 | |
| 4500 | @Override |
| 4501 | public void cancelTaskWindowTransition(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4502 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4503 | "cancelTaskWindowTransition()"); |
| 4504 | final long ident = Binder.clearCallingIdentity(); |
| 4505 | try { |
| 4506 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4507 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4508 | MATCH_TASK_IN_STACKS_ONLY); |
| 4509 | if (task == null) { |
| 4510 | Slog.w(TAG, "cancelTaskWindowTransition: taskId=" + taskId + " not found"); |
| 4511 | return; |
| 4512 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 4513 | task.cancelTaskWindowTransition(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4514 | } |
| 4515 | } finally { |
| 4516 | Binder.restoreCallingIdentity(ident); |
| 4517 | } |
| 4518 | } |
| 4519 | |
| 4520 | @Override |
| 4521 | public ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4522 | enforceCallerIsRecentsOrHasPermission(READ_FRAME_BUFFER, "getTaskSnapshot()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4523 | final long ident = Binder.clearCallingIdentity(); |
| 4524 | try { |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4525 | return getTaskSnapshot(taskId, reducedResolution, true /* restoreFromDisk */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4526 | } finally { |
| 4527 | Binder.restoreCallingIdentity(ident); |
| 4528 | } |
| 4529 | } |
| 4530 | |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4531 | private ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution, |
| 4532 | boolean restoreFromDisk) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4533 | final Task task; |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4534 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4535 | task = mRootWindowContainer.anyTaskForId(taskId, |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4536 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 4537 | if (task == null) { |
| 4538 | Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found"); |
| 4539 | return null; |
| 4540 | } |
| 4541 | } |
| 4542 | // Don't call this while holding the lock as this operation might hit the disk. |
| 4543 | return task.getSnapshot(reducedResolution, restoreFromDisk); |
| 4544 | } |
| 4545 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4546 | @Override |
| 4547 | public void setDisablePreviewScreenshots(IBinder token, boolean disable) { |
| 4548 | synchronized (mGlobalLock) { |
| 4549 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4550 | if (r == null) { |
| 4551 | Slog.w(TAG, "setDisablePreviewScreenshots: Unable to find activity for token=" |
| 4552 | + token); |
| 4553 | return; |
| 4554 | } |
| 4555 | final long origId = Binder.clearCallingIdentity(); |
| 4556 | try { |
| 4557 | r.setDisablePreviewScreenshots(disable); |
| 4558 | } finally { |
| 4559 | Binder.restoreCallingIdentity(origId); |
| 4560 | } |
| 4561 | } |
| 4562 | } |
| 4563 | |
Riddle Hsu | 440f88b | 2019-11-06 22:17:35 +0800 | [diff] [blame] | 4564 | @Override |
| 4565 | public void invalidateHomeTaskSnapshot(IBinder token) { |
| 4566 | synchronized (mGlobalLock) { |
| 4567 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4568 | if (r == null || !r.isActivityTypeHome()) { |
| 4569 | return; |
| 4570 | } |
| 4571 | mWindowManager.mTaskSnapshotController.removeSnapshotCache(r.getTask().mTaskId); |
| 4572 | } |
| 4573 | } |
| 4574 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4575 | /** Return the user id of the last resumed activity. */ |
| 4576 | @Override |
| 4577 | public @UserIdInt |
| 4578 | int getLastResumedActivityUserId() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4579 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4580 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, "getLastResumedActivityUserId()"); |
| 4581 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4582 | if (mLastResumedActivity == null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4583 | return getCurrentUserId(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4584 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4585 | return mLastResumedActivity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4586 | } |
| 4587 | } |
| 4588 | |
| 4589 | @Override |
| 4590 | public void updateLockTaskFeatures(int userId, int flags) { |
| 4591 | final int callingUid = Binder.getCallingUid(); |
| 4592 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4593 | mAmInternal.enforceCallingPermission(android.Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4594 | "updateLockTaskFeatures()"); |
| 4595 | } |
| 4596 | synchronized (mGlobalLock) { |
| 4597 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Allowing features " + userId + ":0x" + |
| 4598 | Integer.toHexString(flags)); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 4599 | getLockTaskController().updateLockTaskFeatures(userId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4600 | } |
| 4601 | } |
| 4602 | |
| 4603 | @Override |
| 4604 | public void setShowWhenLocked(IBinder token, boolean showWhenLocked) { |
| 4605 | synchronized (mGlobalLock) { |
| 4606 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4607 | if (r == null) { |
| 4608 | return; |
| 4609 | } |
| 4610 | final long origId = Binder.clearCallingIdentity(); |
| 4611 | try { |
| 4612 | r.setShowWhenLocked(showWhenLocked); |
| 4613 | } finally { |
| 4614 | Binder.restoreCallingIdentity(origId); |
| 4615 | } |
| 4616 | } |
| 4617 | } |
| 4618 | |
| 4619 | @Override |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 4620 | public void setInheritShowWhenLocked(IBinder token, boolean inheritShowWhenLocked) { |
| 4621 | synchronized (mGlobalLock) { |
| 4622 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4623 | if (r == null) { |
| 4624 | return; |
| 4625 | } |
| 4626 | final long origId = Binder.clearCallingIdentity(); |
| 4627 | try { |
| 4628 | r.setInheritShowWhenLocked(inheritShowWhenLocked); |
| 4629 | } finally { |
| 4630 | Binder.restoreCallingIdentity(origId); |
| 4631 | } |
| 4632 | } |
| 4633 | } |
| 4634 | |
| 4635 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4636 | public void setTurnScreenOn(IBinder token, boolean turnScreenOn) { |
| 4637 | synchronized (mGlobalLock) { |
| 4638 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4639 | if (r == null) { |
| 4640 | return; |
| 4641 | } |
| 4642 | final long origId = Binder.clearCallingIdentity(); |
| 4643 | try { |
| 4644 | r.setTurnScreenOn(turnScreenOn); |
| 4645 | } finally { |
| 4646 | Binder.restoreCallingIdentity(origId); |
| 4647 | } |
| 4648 | } |
| 4649 | } |
| 4650 | |
| 4651 | @Override |
| 4652 | public void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4653 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4654 | "registerRemoteAnimations"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4655 | definition.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4656 | synchronized (mGlobalLock) { |
| 4657 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4658 | if (r == null) { |
| 4659 | return; |
| 4660 | } |
| 4661 | final long origId = Binder.clearCallingIdentity(); |
| 4662 | try { |
| 4663 | r.registerRemoteAnimations(definition); |
| 4664 | } finally { |
| 4665 | Binder.restoreCallingIdentity(origId); |
| 4666 | } |
| 4667 | } |
| 4668 | } |
| 4669 | |
| 4670 | @Override |
Winson Chung | 10fc25d | 2019-12-10 14:13:56 -0800 | [diff] [blame] | 4671 | public void unregisterRemoteAnimations(IBinder token) { |
| 4672 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
| 4673 | "unregisterRemoteAnimations"); |
| 4674 | synchronized (mGlobalLock) { |
| 4675 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4676 | if (r == null) { |
| 4677 | return; |
| 4678 | } |
| 4679 | final long origId = Binder.clearCallingIdentity(); |
| 4680 | try { |
| 4681 | r.unregisterRemoteAnimations(); |
| 4682 | } finally { |
| 4683 | Binder.restoreCallingIdentity(origId); |
| 4684 | } |
| 4685 | } |
| 4686 | } |
| 4687 | |
| 4688 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4689 | public void registerRemoteAnimationForNextActivityStart(String packageName, |
| 4690 | RemoteAnimationAdapter adapter) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4691 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4692 | "registerRemoteAnimationForNextActivityStart"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4693 | adapter.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4694 | synchronized (mGlobalLock) { |
| 4695 | final long origId = Binder.clearCallingIdentity(); |
| 4696 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4697 | getActivityStartController().registerRemoteAnimationForNextActivityStart( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4698 | packageName, adapter); |
| 4699 | } finally { |
| 4700 | Binder.restoreCallingIdentity(origId); |
| 4701 | } |
| 4702 | } |
| 4703 | } |
| 4704 | |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4705 | @Override |
| 4706 | public void registerRemoteAnimationsForDisplay(int displayId, |
| 4707 | RemoteAnimationDefinition definition) { |
| 4708 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
| 4709 | "registerRemoteAnimations"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4710 | definition.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4711 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4712 | final DisplayContent display = mRootWindowContainer.getDisplayContent(displayId); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4713 | if (display == null) { |
| 4714 | Slog.e(TAG, "Couldn't find display with id: " + displayId); |
| 4715 | return; |
| 4716 | } |
| 4717 | final long origId = Binder.clearCallingIdentity(); |
| 4718 | try { |
| 4719 | display.mDisplayContent.registerRemoteAnimations(definition); |
| 4720 | } finally { |
| 4721 | Binder.restoreCallingIdentity(origId); |
| 4722 | } |
| 4723 | } |
| 4724 | } |
| 4725 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4726 | /** @see android.app.ActivityManager#alwaysShowUnsupportedCompileSdkWarning */ |
| 4727 | @Override |
| 4728 | public void alwaysShowUnsupportedCompileSdkWarning(ComponentName activity) { |
| 4729 | synchronized (mGlobalLock) { |
| 4730 | final long origId = Binder.clearCallingIdentity(); |
| 4731 | try { |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 4732 | mAppWarnings.alwaysShowUnsupportedCompileSdkWarning(activity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4733 | } finally { |
| 4734 | Binder.restoreCallingIdentity(origId); |
| 4735 | } |
| 4736 | } |
| 4737 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 4738 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4739 | @Override |
| 4740 | public void setVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4741 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4742 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4743 | final int pid = Binder.getCallingPid(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 4744 | final WindowProcessController wpc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4745 | mVrController.setVrThreadLocked(tid, pid, wpc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4746 | } |
| 4747 | } |
| 4748 | |
| 4749 | @Override |
| 4750 | public void setPersistentVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4751 | if (checkCallingPermission(Manifest.permission.RESTRICTED_VR_ACCESS) |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4752 | != PERMISSION_GRANTED) { |
| 4753 | final String msg = "Permission Denial: setPersistentVrThread() from pid=" |
| 4754 | + Binder.getCallingPid() |
| 4755 | + ", uid=" + Binder.getCallingUid() |
| 4756 | + " requires " + Manifest.permission.RESTRICTED_VR_ACCESS; |
| 4757 | Slog.w(TAG, msg); |
| 4758 | throw new SecurityException(msg); |
| 4759 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4760 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4761 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4762 | final int pid = Binder.getCallingPid(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 4763 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4764 | mVrController.setPersistentVrThreadLocked(tid, pid, proc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4765 | } |
| 4766 | } |
| 4767 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4768 | @Override |
| 4769 | public void stopAppSwitches() { |
| 4770 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "stopAppSwitches"); |
| 4771 | synchronized (mGlobalLock) { |
| 4772 | mAppSwitchesAllowedTime = SystemClock.uptimeMillis() + APP_SWITCH_DELAY_TIME; |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 4773 | mLastStopAppSwitchesTime = SystemClock.uptimeMillis(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4774 | mDidAppSwitch = false; |
| 4775 | getActivityStartController().schedulePendingActivityLaunches(APP_SWITCH_DELAY_TIME); |
| 4776 | } |
| 4777 | } |
| 4778 | |
| 4779 | @Override |
| 4780 | public void resumeAppSwitches() { |
| 4781 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "resumeAppSwitches"); |
| 4782 | synchronized (mGlobalLock) { |
| 4783 | // Note that we don't execute any pending app switches... we will |
| 4784 | // let those wait until either the timeout, or the next start |
| 4785 | // activity request. |
| 4786 | mAppSwitchesAllowedTime = 0; |
| 4787 | } |
| 4788 | } |
| 4789 | |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 4790 | long getLastStopAppSwitchesTime() { |
| 4791 | return mLastStopAppSwitchesTime; |
| 4792 | } |
| 4793 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4794 | void onStartActivitySetDidAppSwitch() { |
| 4795 | if (mDidAppSwitch) { |
| 4796 | // This is the second allowed switch since we stopped switches, so now just generally |
| 4797 | // allow switches. Use case: |
| 4798 | // - user presses home (switches disabled, switch to home, mDidAppSwitch now true); |
| 4799 | // - user taps a home icon (coming from home so allowed, we hit here and now allow |
| 4800 | // anyone to switch again). |
| 4801 | mAppSwitchesAllowedTime = 0; |
| 4802 | } else { |
| 4803 | mDidAppSwitch = true; |
| 4804 | } |
| 4805 | } |
| 4806 | |
| 4807 | /** @return whether the system should disable UI modes incompatible with VR mode. */ |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4808 | boolean shouldDisableNonVrUiLocked() { |
| 4809 | return mVrController.shouldDisableNonVrUiLocked(); |
| 4810 | } |
| 4811 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4812 | private void applyUpdateVrModeLocked(ActivityRecord r) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4813 | // VR apps are expected to run in a main display. If an app is turning on VR for |
Wale Ogunwale | b8e6b63 | 2019-06-28 15:19:25 +0000 | [diff] [blame] | 4814 | // itself, but isn't on the main display, then move it there before enabling VR Mode. |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4815 | if (r.requestedVrComponent != null && r.getDisplayId() != DEFAULT_DISPLAY) { |
Wale Ogunwale | b8e6b63 | 2019-06-28 15:19:25 +0000 | [diff] [blame] | 4816 | Slog.i(TAG, "Moving " + r.shortComponentName + " from display " + r.getDisplayId() |
| 4817 | + " to main display for VR"); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4818 | mRootWindowContainer.moveStackToDisplay( |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 4819 | r.getRootTaskId(), DEFAULT_DISPLAY, true /* toTop */); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4820 | } |
| 4821 | mH.post(() -> { |
| 4822 | if (!mVrController.onVrModeChanged(r)) { |
| 4823 | return; |
| 4824 | } |
| 4825 | synchronized (mGlobalLock) { |
| 4826 | final boolean disableNonVrUi = mVrController.shouldDisableNonVrUiLocked(); |
| 4827 | mWindowManager.disableNonVrUi(disableNonVrUi); |
| 4828 | if (disableNonVrUi) { |
| 4829 | // If we are in a VR mode where Picture-in-Picture mode is unsupported, |
| 4830 | // then remove the pinned stack. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4831 | mRootWindowContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4832 | } |
| 4833 | } |
| 4834 | }); |
| 4835 | } |
| 4836 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4837 | @Override |
| 4838 | public int getPackageScreenCompatMode(String packageName) { |
| 4839 | enforceNotIsolatedCaller("getPackageScreenCompatMode"); |
| 4840 | synchronized (mGlobalLock) { |
| 4841 | return mCompatModePackages.getPackageScreenCompatModeLocked(packageName); |
| 4842 | } |
| 4843 | } |
| 4844 | |
| 4845 | @Override |
| 4846 | public void setPackageScreenCompatMode(String packageName, int mode) { |
| 4847 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4848 | "setPackageScreenCompatMode"); |
| 4849 | synchronized (mGlobalLock) { |
| 4850 | mCompatModePackages.setPackageScreenCompatModeLocked(packageName, mode); |
| 4851 | } |
| 4852 | } |
| 4853 | |
| 4854 | @Override |
| 4855 | public boolean getPackageAskScreenCompat(String packageName) { |
| 4856 | enforceNotIsolatedCaller("getPackageAskScreenCompat"); |
| 4857 | synchronized (mGlobalLock) { |
| 4858 | return mCompatModePackages.getPackageAskCompatModeLocked(packageName); |
| 4859 | } |
| 4860 | } |
| 4861 | |
| 4862 | @Override |
| 4863 | public void setPackageAskScreenCompat(String packageName, boolean ask) { |
| 4864 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4865 | "setPackageAskScreenCompat"); |
| 4866 | synchronized (mGlobalLock) { |
| 4867 | mCompatModePackages.setPackageAskCompatModeLocked(packageName, ask); |
| 4868 | } |
| 4869 | } |
| 4870 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 4871 | public static String relaunchReasonToString(int relaunchReason) { |
| 4872 | switch (relaunchReason) { |
| 4873 | case RELAUNCH_REASON_WINDOWING_MODE_RESIZE: |
| 4874 | return "window_resize"; |
| 4875 | case RELAUNCH_REASON_FREE_RESIZE: |
| 4876 | return "free_resize"; |
| 4877 | default: |
| 4878 | return null; |
| 4879 | } |
| 4880 | } |
| 4881 | |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4882 | ActivityStack getTopDisplayFocusedStack() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4883 | return mRootWindowContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4884 | } |
| 4885 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4886 | /** Pokes the task persister. */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4887 | void notifyTaskPersisterLocked(Task task, boolean flush) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4888 | mRecentTasks.notifyTaskPersisterLocked(task, flush); |
| 4889 | } |
| 4890 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4891 | boolean isKeyguardLocked() { |
| 4892 | return mKeyguardController.isKeyguardLocked(); |
| 4893 | } |
| 4894 | |
Garfield Tan | 0154863 | 2018-11-27 10:15:48 -0800 | [diff] [blame] | 4895 | /** |
| 4896 | * Clears launch params for the given package. |
| 4897 | * @param packageNames the names of the packages of which the launch params are to be cleared |
| 4898 | */ |
| 4899 | @Override |
| 4900 | public void clearLaunchParamsForPackages(List<String> packageNames) { |
| 4901 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4902 | "clearLaunchParamsForPackages"); |
| 4903 | synchronized (mGlobalLock) { |
| 4904 | for (int i = 0; i < packageNames.size(); ++i) { |
| 4905 | mStackSupervisor.mLaunchParamsPersister.removeRecordForPackage(packageNames.get(i)); |
| 4906 | } |
| 4907 | } |
| 4908 | } |
| 4909 | |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 4910 | /** |
| 4911 | * Makes the display with the given id a single task instance display. I.e the display can only |
| 4912 | * contain one task. |
| 4913 | */ |
| 4914 | @Override |
| 4915 | public void setDisplayToSingleTaskInstance(int displayId) { |
| 4916 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4917 | "setDisplayToSingleTaskInstance"); |
| 4918 | final long origId = Binder.clearCallingIdentity(); |
| 4919 | try { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 4920 | final DisplayContent display = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4921 | mRootWindowContainer.getDisplayContentOrCreate(displayId); |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 4922 | if (display != null) { |
| 4923 | display.setDisplayToSingleTaskInstance(); |
| 4924 | } |
| 4925 | } finally { |
| 4926 | Binder.restoreCallingIdentity(origId); |
| 4927 | } |
| 4928 | } |
| 4929 | |
jorgegil@google.com | 06bc323 | 2019-10-31 14:51:22 -0700 | [diff] [blame] | 4930 | /** |
| 4931 | * Requests that an activity should enter picture-in-picture mode if possible. |
| 4932 | */ |
| 4933 | @Override |
| 4934 | public void requestPictureInPictureMode(IBinder token) throws RemoteException { |
| 4935 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4936 | "requestPictureInPictureMode"); |
| 4937 | final long origId = Binder.clearCallingIdentity(); |
| 4938 | try { |
| 4939 | synchronized (mGlobalLock) { |
| 4940 | final ActivityRecord activity = ActivityRecord.forTokenLocked(token); |
| 4941 | if (activity == null) { |
| 4942 | return; |
| 4943 | } |
| 4944 | |
| 4945 | final boolean canEnterPictureInPicture = activity.checkEnterPictureInPictureState( |
| 4946 | "requestPictureInPictureMode", /* beforeStopping */ false); |
| 4947 | if (!canEnterPictureInPicture) { |
| 4948 | throw new IllegalStateException( |
| 4949 | "Requested PIP on an activity that doesn't support it"); |
| 4950 | } |
| 4951 | |
| 4952 | try { |
| 4953 | final ClientTransaction transaction = ClientTransaction.obtain( |
| 4954 | activity.app.getThread(), |
| 4955 | activity.token); |
| 4956 | transaction.addCallback(EnterPipRequestedItem.obtain()); |
| 4957 | getLifecycleManager().scheduleTransaction(transaction); |
| 4958 | } catch (Exception e) { |
| 4959 | Slog.w(TAG, "Failed to send enter pip requested item: " |
| 4960 | + activity.intent.getComponent(), e); |
| 4961 | } |
| 4962 | } |
| 4963 | } finally { |
| 4964 | Binder.restoreCallingIdentity(origId); |
| 4965 | } |
| 4966 | } |
| 4967 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4968 | void dumpLastANRLocked(PrintWriter pw) { |
| 4969 | pw.println("ACTIVITY MANAGER LAST ANR (dumpsys activity lastanr)"); |
| 4970 | if (mLastANRState == null) { |
| 4971 | pw.println(" <no ANR has occurred since boot>"); |
| 4972 | } else { |
| 4973 | pw.println(mLastANRState); |
| 4974 | } |
| 4975 | } |
| 4976 | |
| 4977 | void dumpLastANRTracesLocked(PrintWriter pw) { |
| 4978 | pw.println("ACTIVITY MANAGER LAST ANR TRACES (dumpsys activity lastanr-traces)"); |
| 4979 | |
| 4980 | final File[] files = new File(ANR_TRACE_DIR).listFiles(); |
| 4981 | if (ArrayUtils.isEmpty(files)) { |
| 4982 | pw.println(" <no ANR has occurred since boot>"); |
| 4983 | return; |
| 4984 | } |
| 4985 | // Find the latest file. |
| 4986 | File latest = null; |
| 4987 | for (File f : files) { |
| 4988 | if ((latest == null) || (latest.lastModified() < f.lastModified())) { |
| 4989 | latest = f; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4990 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4991 | } |
| 4992 | pw.print("File: "); |
| 4993 | pw.print(latest.getName()); |
| 4994 | pw.println(); |
| 4995 | try (BufferedReader in = new BufferedReader(new FileReader(latest))) { |
| 4996 | String line; |
| 4997 | while ((line = in.readLine()) != null) { |
| 4998 | pw.println(line); |
| 4999 | } |
| 5000 | } catch (IOException e) { |
| 5001 | pw.print("Unable to read: "); |
| 5002 | pw.print(e); |
| 5003 | pw.println(); |
| 5004 | } |
| 5005 | } |
| 5006 | |
| 5007 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 5008 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 5009 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage, |
| 5010 | "ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)"); |
| 5011 | } |
| 5012 | |
| 5013 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 5014 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage, String header) { |
| 5015 | pw.println(header); |
| 5016 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5017 | boolean printedAnything = mRootWindowContainer.dumpActivities(fd, pw, dumpAll, dumpClient, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5018 | dumpPackage); |
| 5019 | boolean needSep = printedAnything; |
| 5020 | |
| 5021 | boolean printed = ActivityStackSupervisor.printThisActivity(pw, |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5022 | mRootWindowContainer.getTopResumedActivity(), dumpPackage, needSep, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5023 | " ResumedActivity: "); |
| 5024 | if (printed) { |
| 5025 | printedAnything = true; |
| 5026 | needSep = false; |
| 5027 | } |
| 5028 | |
| 5029 | if (dumpPackage == null) { |
| 5030 | if (needSep) { |
| 5031 | pw.println(); |
| 5032 | } |
| 5033 | printedAnything = true; |
| 5034 | mStackSupervisor.dump(pw, " "); |
| 5035 | } |
| 5036 | |
| 5037 | if (!printedAnything) { |
| 5038 | pw.println(" (nothing)"); |
| 5039 | } |
| 5040 | } |
| 5041 | |
| 5042 | void dumpActivityContainersLocked(PrintWriter pw) { |
Jeff Chang | de32273 | 2019-07-12 12:16:23 +0800 | [diff] [blame] | 5043 | pw.println("ACTIVITY MANAGER CONTAINERS (dumpsys activity containers)"); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5044 | mRootWindowContainer.dumpChildrenNames(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5045 | pw.println(" "); |
| 5046 | } |
| 5047 | |
| 5048 | void dumpActivityStarterLocked(PrintWriter pw, String dumpPackage) { |
| 5049 | pw.println("ACTIVITY MANAGER STARTER (dumpsys activity starter)"); |
| 5050 | getActivityStartController().dump(pw, "", dumpPackage); |
| 5051 | } |
| 5052 | |
| 5053 | /** |
| 5054 | * There are three things that cmd can be: |
| 5055 | * - a flattened component name that matches an existing activity |
| 5056 | * - the cmd arg isn't the flattened component name of an existing activity: |
| 5057 | * dump all activity whose component contains the cmd as a substring |
| 5058 | * - A hex number of the ActivityRecord object instance. |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5059 | * <p> |
| 5060 | * The caller should not hold lock when calling this method because it will wait for the |
| 5061 | * activities to complete the dump. |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5062 | * |
| 5063 | * @param dumpVisibleStacksOnly dump activity with {@param name} only if in a visible stack |
| 5064 | * @param dumpFocusedStackOnly dump activity with {@param name} only if in the focused stack |
| 5065 | */ |
| 5066 | protected boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, String[] args, |
| 5067 | int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, boolean dumpFocusedStackOnly) { |
| 5068 | ArrayList<ActivityRecord> activities; |
| 5069 | |
| 5070 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5071 | activities = mRootWindowContainer.getDumpActivities(name, dumpVisibleStacksOnly, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5072 | dumpFocusedStackOnly); |
| 5073 | } |
| 5074 | |
| 5075 | if (activities.size() <= 0) { |
| 5076 | return false; |
| 5077 | } |
| 5078 | |
| 5079 | String[] newArgs = new String[args.length - opti]; |
| 5080 | System.arraycopy(args, opti, newArgs, 0, args.length - opti); |
| 5081 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5082 | Task lastTask = null; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5083 | boolean needSep = false; |
| 5084 | for (int i = activities.size() - 1; i >= 0; i--) { |
| 5085 | ActivityRecord r = activities.get(i); |
| 5086 | if (needSep) { |
| 5087 | pw.println(); |
| 5088 | } |
| 5089 | needSep = true; |
| 5090 | synchronized (mGlobalLock) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5091 | final Task task = r.getTask(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5092 | if (lastTask != task) { |
| 5093 | lastTask = task; |
| 5094 | pw.print("TASK "); pw.print(lastTask.affinity); |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 5095 | pw.print(" id="); pw.print(lastTask.mTaskId); |
| 5096 | pw.print(" userId="); pw.println(lastTask.mUserId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5097 | if (dumpAll) { |
| 5098 | lastTask.dump(pw, " "); |
| 5099 | } |
| 5100 | } |
| 5101 | } |
| 5102 | dumpActivity(" ", fd, pw, activities.get(i), newArgs, dumpAll); |
| 5103 | } |
| 5104 | return true; |
| 5105 | } |
| 5106 | |
| 5107 | /** |
| 5108 | * Invokes IApplicationThread.dumpActivity() on the thread of the specified activity if |
| 5109 | * there is a thread associated with the activity. |
| 5110 | */ |
| 5111 | private void dumpActivity(String prefix, FileDescriptor fd, PrintWriter pw, |
| 5112 | final ActivityRecord r, String[] args, boolean dumpAll) { |
| 5113 | String innerPrefix = prefix + " "; |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5114 | IApplicationThread appThread = null; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5115 | synchronized (mGlobalLock) { |
| 5116 | pw.print(prefix); pw.print("ACTIVITY "); pw.print(r.shortComponentName); |
| 5117 | pw.print(" "); pw.print(Integer.toHexString(System.identityHashCode(r))); |
| 5118 | pw.print(" pid="); |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5119 | if (r.hasProcess()) { |
| 5120 | pw.println(r.app.getPid()); |
| 5121 | appThread = r.app.getThread(); |
| 5122 | } else { |
| 5123 | pw.println("(not running)"); |
| 5124 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5125 | if (dumpAll) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5126 | r.dump(pw, innerPrefix, true /* dumpAll */); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5127 | } |
| 5128 | } |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5129 | if (appThread != null) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5130 | // flush anything that is already in the PrintWriter since the thread is going |
| 5131 | // to write to the file descriptor directly |
| 5132 | pw.flush(); |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5133 | try (TransferPipe tp = new TransferPipe()) { |
| 5134 | appThread.dumpActivity(tp.getWriteFd(), r.appToken, innerPrefix, args); |
| 5135 | tp.go(fd); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5136 | } catch (IOException e) { |
| 5137 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 5138 | } catch (RemoteException e) { |
| 5139 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 5140 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5141 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5142 | } |
| 5143 | |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 5144 | private void writeSleepStateToProto(ProtoOutputStream proto, int wakeFullness, |
| 5145 | boolean testPssMode) { |
| 5146 | final long sleepToken = proto.start(ActivityManagerServiceDumpProcessesProto.SLEEP_STATUS); |
| 5147 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.WAKEFULNESS, |
| 5148 | PowerManagerInternal.wakefulnessToProtoEnum(wakeFullness)); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5149 | for (ActivityTaskManagerInternal.SleepToken st : mRootWindowContainer.mSleepTokens) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5150 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEP_TOKENS, |
| 5151 | st.toString()); |
| 5152 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5153 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEPING, mSleeping); |
| 5154 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SHUTTING_DOWN, |
| 5155 | mShuttingDown); |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 5156 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.TEST_PSS_MODE, |
| 5157 | testPssMode); |
| 5158 | proto.end(sleepToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5159 | } |
| 5160 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5161 | int getCurrentUserId() { |
| 5162 | return mAmInternal.getCurrentUserId(); |
| 5163 | } |
| 5164 | |
| 5165 | private void enforceNotIsolatedCaller(String caller) { |
| 5166 | if (UserHandle.isIsolated(Binder.getCallingUid())) { |
| 5167 | throw new SecurityException("Isolated process not allowed to call " + caller); |
| 5168 | } |
| 5169 | } |
| 5170 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5171 | public Configuration getConfiguration() { |
| 5172 | Configuration ci; |
| 5173 | synchronized(mGlobalLock) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 5174 | ci = new Configuration(getGlobalConfigurationForCallingPid()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5175 | ci.userSetLocale = false; |
| 5176 | } |
| 5177 | return ci; |
| 5178 | } |
| 5179 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5180 | /** |
| 5181 | * Current global configuration information. Contains general settings for the entire system, |
| 5182 | * also corresponds to the merged configuration of the default display. |
| 5183 | */ |
| 5184 | Configuration getGlobalConfiguration() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5185 | // Return default configuration before mRootWindowContainer initialized, which happens |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 5186 | // while initializing process record for system, see {@link |
| 5187 | // ActivityManagerService#setSystemProcess}. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5188 | return mRootWindowContainer != null ? mRootWindowContainer.getConfiguration() |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 5189 | : new Configuration(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5190 | } |
| 5191 | |
| 5192 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5193 | boolean initLocale) { |
| 5194 | return updateConfigurationLocked(values, starting, initLocale, false /* deferResume */); |
| 5195 | } |
| 5196 | |
| 5197 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5198 | boolean initLocale, boolean deferResume) { |
| 5199 | // pass UserHandle.USER_NULL as userId because we don't persist configuration for any user |
| 5200 | return updateConfigurationLocked(values, starting, initLocale, false /* persistent */, |
| 5201 | UserHandle.USER_NULL, deferResume); |
| 5202 | } |
| 5203 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 5204 | public void updatePersistentConfiguration(Configuration values, @UserIdInt int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5205 | final long origId = Binder.clearCallingIdentity(); |
| 5206 | try { |
| 5207 | synchronized (mGlobalLock) { |
| 5208 | updateConfigurationLocked(values, null, false, true, userId, |
| 5209 | false /* deferResume */); |
| 5210 | } |
| 5211 | } finally { |
| 5212 | Binder.restoreCallingIdentity(origId); |
| 5213 | } |
| 5214 | } |
| 5215 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5216 | private boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5217 | boolean initLocale, boolean persistent, int userId, boolean deferResume) { |
| 5218 | return updateConfigurationLocked(values, starting, initLocale, persistent, userId, |
| 5219 | deferResume, null /* result */); |
| 5220 | } |
| 5221 | |
| 5222 | /** |
| 5223 | * Do either or both things: (1) change the current configuration, and (2) |
| 5224 | * make sure the given activity is running with the (now) current |
| 5225 | * configuration. Returns true if the activity has been left running, or |
| 5226 | * false if <var>starting</var> is being destroyed to match the new |
| 5227 | * configuration. |
| 5228 | * |
| 5229 | * @param userId is only used when persistent parameter is set to true to persist configuration |
| 5230 | * for that particular user |
| 5231 | */ |
| 5232 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5233 | boolean initLocale, boolean persistent, int userId, boolean deferResume, |
| 5234 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 5235 | int changes = 0; |
| 5236 | boolean kept = true; |
| 5237 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5238 | deferWindowLayout(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5239 | try { |
| 5240 | if (values != null) { |
| 5241 | changes = updateGlobalConfigurationLocked(values, initLocale, persistent, userId, |
| 5242 | deferResume); |
| 5243 | } |
| 5244 | |
| 5245 | kept = ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 5246 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5247 | continueWindowLayout(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5248 | } |
| 5249 | |
| 5250 | if (result != null) { |
| 5251 | result.changes = changes; |
| 5252 | result.activityRelaunched = !kept; |
| 5253 | } |
| 5254 | return kept; |
| 5255 | } |
| 5256 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5257 | /** Update default (global) configuration and notify listeners about changes. */ |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5258 | int updateGlobalConfigurationLocked(@NonNull Configuration values, boolean initLocale, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5259 | boolean persistent, int userId, boolean deferResume) { |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5260 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5261 | final DisplayContent defaultDisplay = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5262 | mRootWindowContainer.getDisplayContent(DEFAULT_DISPLAY); |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5263 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5264 | mTempConfig.setTo(getGlobalConfiguration()); |
| 5265 | final int changes = mTempConfig.updateFrom(values); |
| 5266 | if (changes == 0) { |
| 5267 | // Since calling to Activity.setRequestedOrientation leads to freezing the window with |
| 5268 | // setting WindowManagerService.mWaitingForConfig to true, it is important that we call |
| 5269 | // performDisplayOverrideConfigUpdate in order to send the new display configuration |
| 5270 | // (even if there are no actual changes) to unfreeze the window. |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5271 | defaultDisplay.performDisplayOverrideConfigUpdate(values, deferResume); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5272 | return 0; |
| 5273 | } |
| 5274 | |
| 5275 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.i(TAG_CONFIGURATION, |
| 5276 | "Updating global configuration to: " + values); |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5277 | writeConfigurationChanged(changes); |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 5278 | FrameworkStatsLog.write(FrameworkStatsLog.RESOURCE_CONFIGURATION_CHANGED, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5279 | values.colorMode, |
| 5280 | values.densityDpi, |
| 5281 | values.fontScale, |
| 5282 | values.hardKeyboardHidden, |
| 5283 | values.keyboard, |
| 5284 | values.keyboardHidden, |
| 5285 | values.mcc, |
| 5286 | values.mnc, |
| 5287 | values.navigation, |
| 5288 | values.navigationHidden, |
| 5289 | values.orientation, |
| 5290 | values.screenHeightDp, |
| 5291 | values.screenLayout, |
| 5292 | values.screenWidthDp, |
| 5293 | values.smallestScreenWidthDp, |
| 5294 | values.touchscreen, |
| 5295 | values.uiMode); |
| 5296 | |
| 5297 | |
| 5298 | if (!initLocale && !values.getLocales().isEmpty() && values.userSetLocale) { |
| 5299 | final LocaleList locales = values.getLocales(); |
| 5300 | int bestLocaleIndex = 0; |
| 5301 | if (locales.size() > 1) { |
| 5302 | if (mSupportedSystemLocales == null) { |
| 5303 | mSupportedSystemLocales = Resources.getSystem().getAssets().getLocales(); |
| 5304 | } |
| 5305 | bestLocaleIndex = Math.max(0, locales.getFirstMatchIndex(mSupportedSystemLocales)); |
| 5306 | } |
| 5307 | SystemProperties.set("persist.sys.locale", |
| 5308 | locales.get(bestLocaleIndex).toLanguageTag()); |
| 5309 | LocaleList.setDefault(locales, bestLocaleIndex); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5310 | |
| 5311 | final Message m = PooledLambda.obtainMessage( |
| 5312 | ActivityTaskManagerService::sendLocaleToMountDaemonMsg, this, |
| 5313 | locales.get(bestLocaleIndex)); |
| 5314 | mH.sendMessage(m); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5315 | } |
| 5316 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 5317 | mTempConfig.seq = increaseConfigurationSeqLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5318 | |
| 5319 | // Update stored global config and notify everyone about the change. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5320 | mRootWindowContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5321 | |
| 5322 | Slog.i(TAG, "Config changes=" + Integer.toHexString(changes) + " " + mTempConfig); |
| 5323 | // TODO(multi-display): Update UsageEvents#Event to include displayId. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5324 | mUsageStatsInternal.reportConfigurationChange(mTempConfig, mAmInternal.getCurrentUserId()); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5325 | |
| 5326 | // TODO: If our config changes, should we auto dismiss any currently showing dialogs? |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5327 | updateShouldShowDialogsLocked(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5328 | |
| 5329 | AttributeCache ac = AttributeCache.instance(); |
| 5330 | if (ac != null) { |
| 5331 | ac.updateConfiguration(mTempConfig); |
| 5332 | } |
| 5333 | |
| 5334 | // Make sure all resources in our process are updated right now, so that anyone who is going |
| 5335 | // to retrieve resource values after we return will be sure to get the new ones. This is |
| 5336 | // especially important during boot, where the first config change needs to guarantee all |
| 5337 | // resources have that config before following boot code is executed. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5338 | mSystemThread.applyConfigurationToResources(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5339 | |
| 5340 | // We need another copy of global config because we're scheduling some calls instead of |
| 5341 | // running them in place. We need to be sure that object we send will be handled unchanged. |
| 5342 | final Configuration configCopy = new Configuration(mTempConfig); |
| 5343 | if (persistent && Settings.System.hasInterestingConfigurationChanges(changes)) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5344 | final Message msg = PooledLambda.obtainMessage( |
| 5345 | ActivityTaskManagerService::sendPutConfigurationForUserMsg, |
| 5346 | this, userId, configCopy); |
| 5347 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5348 | } |
| 5349 | |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 5350 | SparseArray<WindowProcessController> pidMap = mProcessMap.getPidMap(); |
| 5351 | for (int i = pidMap.size() - 1; i >= 0; i--) { |
| 5352 | final int pid = pidMap.keyAt(i); |
| 5353 | final WindowProcessController app = pidMap.get(pid); |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 5354 | if (DEBUG_CONFIGURATION) { |
| 5355 | Slog.v(TAG_CONFIGURATION, "Update process config of " |
| 5356 | + app.mName + " to new config " + configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5357 | } |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 5358 | app.onConfigurationChanged(configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5359 | } |
| 5360 | |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 5361 | final Message msg = PooledLambda.obtainMessage( |
| 5362 | ActivityManagerInternal::broadcastGlobalConfigurationChanged, |
| 5363 | mAmInternal, changes, initLocale); |
| 5364 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5365 | |
| 5366 | // Override configuration of the default display duplicates global config, so we need to |
| 5367 | // update it also. This will also notify WindowManager about changes. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5368 | defaultDisplay.performDisplayOverrideConfigUpdate(mRootWindowContainer.getConfiguration(), |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5369 | deferResume); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5370 | |
| 5371 | return changes; |
| 5372 | } |
| 5373 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5374 | /** @see WindowSurfacePlacer#deferLayout */ |
| 5375 | void deferWindowLayout() { |
| 5376 | if (!mWindowManager.mWindowPlacerLocked.isLayoutDeferred()) { |
| 5377 | // Reset the reasons at the first entrance because we only care about the changes in the |
| 5378 | // deferred scope. |
| 5379 | mLayoutReasons = 0; |
| 5380 | } |
| 5381 | |
| 5382 | mWindowManager.mWindowPlacerLocked.deferLayout(); |
| 5383 | } |
| 5384 | |
| 5385 | /** @see WindowSurfacePlacer#continueLayout */ |
| 5386 | void continueWindowLayout() { |
| 5387 | mWindowManager.mWindowPlacerLocked.continueLayout(mLayoutReasons != 0); |
| 5388 | if (DEBUG_ALL && !mWindowManager.mWindowPlacerLocked.isLayoutDeferred()) { |
| 5389 | Slog.i(TAG, "continueWindowLayout reason=" + mLayoutReasons); |
| 5390 | } |
| 5391 | } |
| 5392 | |
| 5393 | /** |
| 5394 | * If a reason is added between {@link #deferWindowLayout} and {@link #continueWindowLayout}, |
| 5395 | * it will make sure {@link WindowSurfacePlacer#performSurfacePlacement} is called when the last |
| 5396 | * defer count is gone. |
| 5397 | */ |
| 5398 | void addWindowLayoutReasons(@LayoutReason int reasons) { |
| 5399 | mLayoutReasons |= reasons; |
| 5400 | } |
| 5401 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5402 | private void updateEventDispatchingLocked(boolean booted) { |
| 5403 | mWindowManager.setEventDispatching(booted && !mShuttingDown); |
| 5404 | } |
| 5405 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5406 | private void sendPutConfigurationForUserMsg(int userId, Configuration config) { |
| 5407 | final ContentResolver resolver = mContext.getContentResolver(); |
| 5408 | Settings.System.putConfigurationForUser(resolver, config, userId); |
| 5409 | } |
| 5410 | |
| 5411 | private void sendLocaleToMountDaemonMsg(Locale l) { |
| 5412 | try { |
| 5413 | IBinder service = ServiceManager.getService("mount"); |
| 5414 | IStorageManager storageManager = IStorageManager.Stub.asInterface(service); |
| 5415 | Log.d(TAG, "Storing locale " + l.toLanguageTag() + " for decryption UI"); |
| 5416 | storageManager.setField(StorageManager.SYSTEM_LOCALE_KEY, l.toLanguageTag()); |
| 5417 | } catch (RemoteException e) { |
| 5418 | Log.e(TAG, "Error storing locale for decryption UI", e); |
| 5419 | } |
| 5420 | } |
| 5421 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5422 | private void expireStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5423 | mStartActivitySources.remove(permissionToken); |
| 5424 | mExpiredStartAsCallerTokens.add(permissionToken); |
| 5425 | } |
| 5426 | |
| 5427 | private void forgetStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5428 | mExpiredStartAsCallerTokens.remove(permissionToken); |
| 5429 | } |
| 5430 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5431 | boolean isActivityStartsLoggingEnabled() { |
| 5432 | return mAmInternal.isActivityStartsLoggingEnabled(); |
| 5433 | } |
| 5434 | |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 5435 | boolean isBackgroundActivityStartsEnabled() { |
| 5436 | return mAmInternal.isBackgroundActivityStartsEnabled(); |
| 5437 | } |
| 5438 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5439 | void enableScreenAfterBoot(boolean booted) { |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5440 | writeBootProgressEnableScreen(SystemClock.uptimeMillis()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5441 | mWindowManager.enableScreenAfterBoot(); |
| 5442 | |
| 5443 | synchronized (mGlobalLock) { |
| 5444 | updateEventDispatchingLocked(booted); |
| 5445 | } |
| 5446 | } |
| 5447 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5448 | static long getInputDispatchingTimeoutLocked(ActivityRecord r) { |
| 5449 | if (r == null || !r.hasProcess()) { |
| 5450 | return KEY_DISPATCHING_TIMEOUT_MS; |
| 5451 | } |
| 5452 | return getInputDispatchingTimeoutLocked(r.app); |
| 5453 | } |
| 5454 | |
| 5455 | private static long getInputDispatchingTimeoutLocked(WindowProcessController r) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 5456 | return r != null ? r.getInputDispatchingTimeout() : KEY_DISPATCHING_TIMEOUT_MS; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5457 | } |
| 5458 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5459 | /** |
| 5460 | * Decide based on the configuration whether we should show the ANR, |
| 5461 | * crash, etc dialogs. The idea is that if there is no affordance to |
| 5462 | * press the on-screen buttons, or the user experience would be more |
| 5463 | * greatly impacted than the crash itself, we shouldn't show the dialog. |
| 5464 | * |
| 5465 | * A thought: SystemUI might also want to get told about this, the Power |
| 5466 | * dialog / global actions also might want different behaviors. |
| 5467 | */ |
| 5468 | private void updateShouldShowDialogsLocked(Configuration config) { |
| 5469 | final boolean inputMethodExists = !(config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 5470 | && config.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH |
| 5471 | && config.navigation == Configuration.NAVIGATION_NONAV); |
| 5472 | int modeType = config.uiMode & Configuration.UI_MODE_TYPE_MASK; |
| 5473 | final boolean uiModeSupportsDialogs = (modeType != Configuration.UI_MODE_TYPE_CAR |
| 5474 | && !(modeType == Configuration.UI_MODE_TYPE_WATCH && Build.IS_USER) |
| 5475 | && modeType != Configuration.UI_MODE_TYPE_TELEVISION |
| 5476 | && modeType != Configuration.UI_MODE_TYPE_VR_HEADSET); |
| 5477 | final boolean hideDialogsSet = Settings.Global.getInt(mContext.getContentResolver(), |
| 5478 | HIDE_ERROR_DIALOGS, 0) != 0; |
| 5479 | mShowDialogs = inputMethodExists && uiModeSupportsDialogs && !hideDialogsSet; |
| 5480 | } |
| 5481 | |
| 5482 | private void updateFontScaleIfNeeded(@UserIdInt int userId) { |
| 5483 | final float scaleFactor = Settings.System.getFloatForUser(mContext.getContentResolver(), |
| 5484 | FONT_SCALE, 1.0f, userId); |
| 5485 | |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 5486 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5487 | if (getGlobalConfiguration().fontScale == scaleFactor) { |
| 5488 | return; |
| 5489 | } |
| 5490 | |
| 5491 | final Configuration configuration |
| 5492 | = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
| 5493 | configuration.fontScale = scaleFactor; |
| 5494 | updatePersistentConfiguration(configuration, userId); |
| 5495 | } |
| 5496 | } |
| 5497 | |
| 5498 | // Actually is sleeping or shutting down or whatever else in the future |
| 5499 | // is an inactive state. |
| 5500 | boolean isSleepingOrShuttingDownLocked() { |
| 5501 | return isSleepingLocked() || mShuttingDown; |
| 5502 | } |
| 5503 | |
| 5504 | boolean isSleepingLocked() { |
| 5505 | return mSleeping; |
| 5506 | } |
| 5507 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5508 | /** Update AMS states when an activity is resumed. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5509 | void setResumedActivityUncheckLocked(ActivityRecord r, String reason) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5510 | final Task task = r.getTask(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5511 | if (task.isActivityTypeStandard()) { |
| 5512 | if (mCurAppTimeTracker != r.appTimeTracker) { |
| 5513 | // We are switching app tracking. Complete the current one. |
| 5514 | if (mCurAppTimeTracker != null) { |
| 5515 | mCurAppTimeTracker.stop(); |
| 5516 | mH.obtainMessage( |
| 5517 | REPORT_TIME_TRACKER_MSG, mCurAppTimeTracker).sendToTarget(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5518 | mRootWindowContainer.clearOtherAppTimeTrackers(r.appTimeTracker); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5519 | mCurAppTimeTracker = null; |
| 5520 | } |
| 5521 | if (r.appTimeTracker != null) { |
| 5522 | mCurAppTimeTracker = r.appTimeTracker; |
| 5523 | startTimeTrackingFocusedActivityLocked(); |
| 5524 | } |
| 5525 | } else { |
| 5526 | startTimeTrackingFocusedActivityLocked(); |
| 5527 | } |
| 5528 | } else { |
| 5529 | r.appTimeTracker = null; |
| 5530 | } |
| 5531 | // TODO: VI Maybe r.task.voiceInteractor || r.voiceInteractor != null |
| 5532 | // TODO: Probably not, because we don't want to resume voice on switching |
| 5533 | // back to this activity |
| 5534 | if (task.voiceInteractor != null) { |
| 5535 | startRunningVoiceLocked(task.voiceSession, r.info.applicationInfo.uid); |
| 5536 | } else { |
| 5537 | finishRunningVoiceLocked(); |
| 5538 | |
| 5539 | if (mLastResumedActivity != null) { |
| 5540 | final IVoiceInteractionSession session; |
| 5541 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5542 | final Task lastResumedActivityTask = mLastResumedActivity.getTask(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5543 | if (lastResumedActivityTask != null |
| 5544 | && lastResumedActivityTask.voiceSession != null) { |
| 5545 | session = lastResumedActivityTask.voiceSession; |
| 5546 | } else { |
| 5547 | session = mLastResumedActivity.voiceSession; |
| 5548 | } |
| 5549 | |
| 5550 | if (session != null) { |
| 5551 | // We had been in a voice interaction session, but now focused has |
| 5552 | // move to something different. Just finish the session, we can't |
| 5553 | // return to it and retain the proper state and synchronization with |
| 5554 | // the voice interaction service. |
| 5555 | finishVoiceTask(session); |
| 5556 | } |
| 5557 | } |
| 5558 | } |
| 5559 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5560 | if (mLastResumedActivity != null && r.mUserId != mLastResumedActivity.mUserId) { |
| 5561 | mAmInternal.sendForegroundProfileChanged(r.mUserId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5562 | } |
Bogyun Son | bfb64dc | 2019-12-09 17:50:24 +0900 | [diff] [blame] | 5563 | final Task prevTask = mLastResumedActivity != null ? mLastResumedActivity.getTask() : null; |
| 5564 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5565 | updateResumedAppTrace(r); |
| 5566 | mLastResumedActivity = r; |
| 5567 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 5568 | r.getDisplay().setFocusedApp(r, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5569 | |
Bogyun Son | bfb64dc | 2019-12-09 17:50:24 +0900 | [diff] [blame] | 5570 | if (prevTask == null || task != prevTask) { |
| 5571 | if (prevTask != null) { |
| 5572 | mTaskChangeNotificationController.notifyTaskFocusChanged(prevTask.mTaskId, false); |
| 5573 | } |
| 5574 | mTaskChangeNotificationController.notifyTaskFocusChanged(task.mTaskId, true); |
| 5575 | } |
| 5576 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5577 | applyUpdateLockStateLocked(r); |
| 5578 | applyUpdateVrModeLocked(r); |
| 5579 | |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5580 | EventLogTags.writeWmSetResumedActivity( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5581 | r == null ? -1 : r.mUserId, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5582 | r == null ? "NULL" : r.shortComponentName, |
| 5583 | reason); |
| 5584 | } |
| 5585 | |
| 5586 | ActivityTaskManagerInternal.SleepToken acquireSleepToken(String tag, int displayId) { |
| 5587 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5588 | final ActivityTaskManagerInternal.SleepToken token = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5589 | mRootWindowContainer.createSleepToken(tag, displayId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5590 | updateSleepIfNeededLocked(); |
| 5591 | return token; |
| 5592 | } |
| 5593 | } |
| 5594 | |
| 5595 | void updateSleepIfNeededLocked() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5596 | final boolean shouldSleep = !mRootWindowContainer.hasAwakeDisplay(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5597 | final boolean wasSleeping = mSleeping; |
| 5598 | boolean updateOomAdj = false; |
| 5599 | |
| 5600 | if (!shouldSleep) { |
| 5601 | // If wasSleeping is true, we need to wake up activity manager state from when |
| 5602 | // we started sleeping. In either case, we need to apply the sleep tokens, which |
| 5603 | // will wake up stacks or put them to sleep as appropriate. |
| 5604 | if (wasSleeping) { |
| 5605 | mSleeping = false; |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 5606 | FrameworkStatsLog.write(FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5607 | FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__AWAKE); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5608 | startTimeTrackingFocusedActivityLocked(); |
| 5609 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
Varun Shah | 98694fb | 2019-04-11 09:28:27 -0700 | [diff] [blame] | 5610 | Slog.d(TAG, "Top Process State changed to PROCESS_STATE_TOP"); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5611 | mStackSupervisor.comeOutOfSleepIfNeededLocked(); |
| 5612 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5613 | mRootWindowContainer.applySleepTokens(true /* applyToStacks */); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5614 | if (wasSleeping) { |
| 5615 | updateOomAdj = true; |
| 5616 | } |
| 5617 | } else if (!mSleeping && shouldSleep) { |
| 5618 | mSleeping = true; |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 5619 | FrameworkStatsLog.write(FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5620 | FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__ASLEEP); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5621 | if (mCurAppTimeTracker != null) { |
| 5622 | mCurAppTimeTracker.stop(); |
| 5623 | } |
| 5624 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP_SLEEPING; |
Varun Shah | 98694fb | 2019-04-11 09:28:27 -0700 | [diff] [blame] | 5625 | Slog.d(TAG, "Top Process State changed to PROCESS_STATE_TOP_SLEEPING"); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5626 | mStackSupervisor.goingToSleepLocked(); |
| 5627 | updateResumedAppTrace(null /* resumed */); |
| 5628 | updateOomAdj = true; |
| 5629 | } |
| 5630 | if (updateOomAdj) { |
wilsonshih | 8d096d2 | 2019-08-01 17:46:14 +0800 | [diff] [blame] | 5631 | updateOomAdj(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5632 | } |
| 5633 | } |
| 5634 | |
| 5635 | void updateOomAdj() { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 5636 | mH.removeCallbacks(mUpdateOomAdjRunnable); |
| 5637 | mH.post(mUpdateOomAdjRunnable); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5638 | } |
| 5639 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5640 | void updateCpuStats() { |
| 5641 | mH.post(mAmInternal::updateCpuStats); |
| 5642 | } |
| 5643 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5644 | void updateBatteryStats(ActivityRecord component, boolean resumed) { |
| 5645 | final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::updateBatteryStats, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5646 | mAmInternal, component.mActivityComponent, component.app.mUid, component.mUserId, |
| 5647 | resumed); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5648 | mH.sendMessage(m); |
| 5649 | } |
| 5650 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5651 | void updateActivityUsageStats(ActivityRecord activity, int event) { |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5652 | ComponentName taskRoot = null; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5653 | final Task task = activity.getTask(); |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5654 | if (task != null) { |
| 5655 | final ActivityRecord rootActivity = task.getRootActivity(); |
| 5656 | if (rootActivity != null) { |
| 5657 | taskRoot = rootActivity.mActivityComponent; |
| 5658 | } |
| 5659 | } |
| 5660 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5661 | final Message m = PooledLambda.obtainMessage( |
| 5662 | ActivityManagerInternal::updateActivityUsageStats, mAmInternal, |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5663 | activity.mActivityComponent, activity.mUserId, event, activity.appToken, taskRoot); |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5664 | mH.sendMessage(m); |
| 5665 | } |
| 5666 | |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5667 | void startProcessAsync(ActivityRecord activity, boolean knownToBeDead, boolean isTop, |
| 5668 | String hostingType) { |
| 5669 | try { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5670 | if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) { |
| 5671 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "dispatchingStartProcess:" |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5672 | + activity.processName); |
| 5673 | } |
| 5674 | // Post message to start process to avoid possible deadlock of calling into AMS with the |
| 5675 | // ATMS lock held. |
| 5676 | final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::startProcess, |
| 5677 | mAmInternal, activity.processName, activity.info.applicationInfo, knownToBeDead, |
| 5678 | isTop, hostingType, activity.intent.getComponent()); |
| 5679 | mH.sendMessage(m); |
| 5680 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5681 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5682 | } |
| 5683 | } |
| 5684 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5685 | void setBooting(boolean booting) { |
| 5686 | mAmInternal.setBooting(booting); |
| 5687 | } |
| 5688 | |
| 5689 | boolean isBooting() { |
| 5690 | return mAmInternal.isBooting(); |
| 5691 | } |
| 5692 | |
| 5693 | void setBooted(boolean booted) { |
| 5694 | mAmInternal.setBooted(booted); |
| 5695 | } |
| 5696 | |
| 5697 | boolean isBooted() { |
| 5698 | return mAmInternal.isBooted(); |
| 5699 | } |
| 5700 | |
| 5701 | void postFinishBooting(boolean finishBooting, boolean enableScreen) { |
| 5702 | mH.post(() -> { |
| 5703 | if (finishBooting) { |
| 5704 | mAmInternal.finishBooting(); |
| 5705 | } |
| 5706 | if (enableScreen) { |
| 5707 | mInternal.enableScreenAfterBoot(isBooted()); |
| 5708 | } |
| 5709 | }); |
| 5710 | } |
| 5711 | |
| 5712 | void setHeavyWeightProcess(ActivityRecord root) { |
| 5713 | mHeavyWeightProcess = root.app; |
| 5714 | final Message m = PooledLambda.obtainMessage( |
| 5715 | ActivityTaskManagerService::postHeavyWeightProcessNotification, this, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5716 | root.app, root.intent, root.mUserId); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5717 | mH.sendMessage(m); |
| 5718 | } |
| 5719 | |
| 5720 | void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
| 5721 | if (mHeavyWeightProcess == null || mHeavyWeightProcess != proc) { |
| 5722 | return; |
| 5723 | } |
| 5724 | |
| 5725 | mHeavyWeightProcess = null; |
| 5726 | final Message m = PooledLambda.obtainMessage( |
| 5727 | ActivityTaskManagerService::cancelHeavyWeightProcessNotification, this, |
| 5728 | proc.mUserId); |
| 5729 | mH.sendMessage(m); |
| 5730 | } |
| 5731 | |
| 5732 | private void cancelHeavyWeightProcessNotification(int userId) { |
| 5733 | final INotificationManager inm = NotificationManager.getService(); |
| 5734 | if (inm == null) { |
| 5735 | return; |
| 5736 | } |
| 5737 | try { |
Julia Reynolds | e4a47dd | 2019-06-07 13:40:59 -0400 | [diff] [blame] | 5738 | inm.cancelNotificationWithTag("android", "android", null, |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5739 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, userId); |
| 5740 | } catch (RuntimeException e) { |
| 5741 | Slog.w(TAG, "Error canceling notification for service", e); |
| 5742 | } catch (RemoteException e) { |
| 5743 | } |
| 5744 | |
| 5745 | } |
| 5746 | |
| 5747 | private void postHeavyWeightProcessNotification( |
| 5748 | WindowProcessController proc, Intent intent, int userId) { |
| 5749 | if (proc == null) { |
| 5750 | return; |
| 5751 | } |
| 5752 | |
| 5753 | final INotificationManager inm = NotificationManager.getService(); |
| 5754 | if (inm == null) { |
| 5755 | return; |
| 5756 | } |
| 5757 | |
| 5758 | try { |
| 5759 | Context context = mContext.createPackageContext(proc.mInfo.packageName, 0); |
| 5760 | String text = mContext.getString(R.string.heavy_weight_notification, |
| 5761 | context.getApplicationInfo().loadLabel(context.getPackageManager())); |
| 5762 | Notification notification = |
| 5763 | new Notification.Builder(context, |
| 5764 | SystemNotificationChannels.HEAVY_WEIGHT_APP) |
| 5765 | .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) |
| 5766 | .setWhen(0) |
| 5767 | .setOngoing(true) |
| 5768 | .setTicker(text) |
| 5769 | .setColor(mContext.getColor( |
| 5770 | com.android.internal.R.color.system_notification_accent_color)) |
| 5771 | .setContentTitle(text) |
| 5772 | .setContentText( |
| 5773 | mContext.getText(R.string.heavy_weight_notification_detail)) |
| 5774 | .setContentIntent(PendingIntent.getActivityAsUser(mContext, 0, |
| 5775 | intent, PendingIntent.FLAG_CANCEL_CURRENT, null, |
| 5776 | new UserHandle(userId))) |
| 5777 | .build(); |
| 5778 | try { |
| 5779 | inm.enqueueNotificationWithTag("android", "android", null, |
| 5780 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, notification, userId); |
| 5781 | } catch (RuntimeException e) { |
| 5782 | Slog.w(TAG, "Error showing notification for heavy-weight app", e); |
| 5783 | } catch (RemoteException e) { |
| 5784 | } |
| 5785 | } catch (PackageManager.NameNotFoundException e) { |
| 5786 | Slog.w(TAG, "Unable to create context for heavy notification", e); |
| 5787 | } |
| 5788 | |
| 5789 | } |
| 5790 | |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 5791 | IIntentSender getIntentSenderLocked(int type, String packageName, String featureId, |
| 5792 | int callingUid, int userId, IBinder token, String resultWho, int requestCode, |
| 5793 | Intent[] intents, String[] resolvedTypes, int flags, Bundle bOptions) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5794 | |
| 5795 | ActivityRecord activity = null; |
| 5796 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5797 | activity = ActivityRecord.isInStackLocked(token); |
| 5798 | if (activity == null) { |
| 5799 | Slog.w(TAG, "Failed createPendingResult: activity " + token + " not in any stack"); |
| 5800 | return null; |
| 5801 | } |
| 5802 | if (activity.finishing) { |
| 5803 | Slog.w(TAG, "Failed createPendingResult: activity " + activity + " is finishing"); |
| 5804 | return null; |
| 5805 | } |
| 5806 | } |
| 5807 | |
| 5808 | final PendingIntentRecord rec = mPendingIntentController.getIntentSender(type, packageName, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 5809 | featureId, callingUid, userId, token, resultWho, requestCode, intents, |
| 5810 | resolvedTypes, flags, bOptions); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5811 | final boolean noCreate = (flags & PendingIntent.FLAG_NO_CREATE) != 0; |
| 5812 | if (noCreate) { |
| 5813 | return rec; |
| 5814 | } |
| 5815 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5816 | if (activity.pendingResults == null) { |
| 5817 | activity.pendingResults = new HashSet<>(); |
| 5818 | } |
| 5819 | activity.pendingResults.add(rec.ref); |
| 5820 | } |
| 5821 | return rec; |
| 5822 | } |
| 5823 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 5824 | // TODO(b/111541062): Update app time tracking to make it aware of multiple resumed activities |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5825 | private void startTimeTrackingFocusedActivityLocked() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5826 | final ActivityRecord resumedActivity = mRootWindowContainer.getTopResumedActivity(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5827 | if (!mSleeping && mCurAppTimeTracker != null && resumedActivity != null) { |
| 5828 | mCurAppTimeTracker.start(resumedActivity.packageName); |
| 5829 | } |
| 5830 | } |
| 5831 | |
| 5832 | private void updateResumedAppTrace(@Nullable ActivityRecord resumed) { |
| 5833 | if (mTracedResumedActivity != null) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5834 | Trace.asyncTraceEnd(TRACE_TAG_WINDOW_MANAGER, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5835 | constructResumedTraceName(mTracedResumedActivity.packageName), 0); |
| 5836 | } |
| 5837 | if (resumed != null) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5838 | Trace.asyncTraceBegin(TRACE_TAG_WINDOW_MANAGER, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5839 | constructResumedTraceName(resumed.packageName), 0); |
| 5840 | } |
| 5841 | mTracedResumedActivity = resumed; |
| 5842 | } |
| 5843 | |
| 5844 | private String constructResumedTraceName(String packageName) { |
| 5845 | return "focused app: " + packageName; |
| 5846 | } |
| 5847 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5848 | /** Applies latest configuration and/or visibility updates if needed. */ |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5849 | boolean ensureConfigAndVisibilityAfterUpdate(ActivityRecord starting, int changes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5850 | boolean kept = true; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5851 | final ActivityStack mainStack = mRootWindowContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5852 | // mainStack is null during startup. |
| 5853 | if (mainStack != null) { |
| 5854 | if (changes != 0 && starting == null) { |
| 5855 | // If the configuration changed, and the caller is not already |
| 5856 | // in the process of starting an activity, then find the top |
| 5857 | // activity to check if its configuration needs to change. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 5858 | starting = mainStack.topRunningActivity(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5859 | } |
| 5860 | |
| 5861 | if (starting != null) { |
| 5862 | kept = starting.ensureActivityConfiguration(changes, |
| 5863 | false /* preserveWindow */); |
| 5864 | // And we need to make sure at this point that all other activities |
| 5865 | // are made visible with the correct configuration. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5866 | mRootWindowContainer.ensureActivitiesVisible(starting, changes, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5867 | !PRESERVE_WINDOWS); |
| 5868 | } |
| 5869 | } |
| 5870 | |
| 5871 | return kept; |
| 5872 | } |
| 5873 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5874 | void scheduleAppGcsLocked() { |
| 5875 | mH.post(() -> mAmInternal.scheduleAppGcs()); |
| 5876 | } |
| 5877 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5878 | CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) { |
| 5879 | return mCompatModePackages.compatibilityInfoForPackageLocked(ai); |
| 5880 | } |
| 5881 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5882 | /** |
| 5883 | * Returns the PackageManager. Used by classes hosted by {@link ActivityTaskManagerService}. The |
| 5884 | * PackageManager could be unavailable at construction time and therefore needs to be accessed |
| 5885 | * on demand. |
| 5886 | */ |
| 5887 | IPackageManager getPackageManager() { |
| 5888 | return AppGlobals.getPackageManager(); |
| 5889 | } |
| 5890 | |
| 5891 | PackageManagerInternal getPackageManagerInternalLocked() { |
| 5892 | if (mPmInternal == null) { |
| 5893 | mPmInternal = LocalServices.getService(PackageManagerInternal.class); |
| 5894 | } |
| 5895 | return mPmInternal; |
| 5896 | } |
| 5897 | |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 5898 | PermissionPolicyInternal getPermissionPolicyInternal() { |
| 5899 | if (mPermissionPolicyInternal == null) { |
| 5900 | mPermissionPolicyInternal = LocalServices.getService(PermissionPolicyInternal.class); |
| 5901 | } |
| 5902 | return mPermissionPolicyInternal; |
| 5903 | } |
| 5904 | |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 5905 | AppWarnings getAppWarningsLocked() { |
| 5906 | return mAppWarnings; |
| 5907 | } |
| 5908 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5909 | Intent getHomeIntent() { |
| 5910 | Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null); |
| 5911 | intent.setComponent(mTopComponent); |
| 5912 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5913 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5914 | intent.addCategory(Intent.CATEGORY_HOME); |
| 5915 | } |
| 5916 | return intent; |
| 5917 | } |
| 5918 | |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5919 | /** |
| 5920 | * Return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} to resolve secondary home |
| 5921 | * activities. |
| 5922 | * |
| 5923 | * @param preferredPackage Specify a preferred package name, otherwise use secondary home |
| 5924 | * component defined in config_secondaryHomeComponent. |
| 5925 | * @return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} |
| 5926 | */ |
| 5927 | Intent getSecondaryHomeIntent(String preferredPackage) { |
| 5928 | final Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null); |
Keun young Park | 340546a | 2019-05-06 16:27:44 -0700 | [diff] [blame] | 5929 | final boolean useSystemProvidedLauncher = mContext.getResources().getBoolean( |
| 5930 | com.android.internal.R.bool.config_useSystemProvidedLauncherForSecondary); |
| 5931 | if (preferredPackage == null || useSystemProvidedLauncher) { |
| 5932 | // Using the component stored in config if no package name or forced. |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5933 | final String secondaryHomeComponent = mContext.getResources().getString( |
| 5934 | com.android.internal.R.string.config_secondaryHomeComponent); |
| 5935 | intent.setComponent(ComponentName.unflattenFromString(secondaryHomeComponent)); |
| 5936 | } else { |
| 5937 | intent.setPackage(preferredPackage); |
| 5938 | } |
| 5939 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5940 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5941 | intent.addCategory(Intent.CATEGORY_SECONDARY_HOME); |
| 5942 | } |
| 5943 | return intent; |
| 5944 | } |
| 5945 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5946 | ApplicationInfo getAppInfoForUser(ApplicationInfo info, int userId) { |
| 5947 | if (info == null) return null; |
| 5948 | ApplicationInfo newInfo = new ApplicationInfo(info); |
| 5949 | newInfo.initForUser(userId); |
| 5950 | return newInfo; |
| 5951 | } |
| 5952 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 5953 | WindowProcessController getProcessController(String processName, int uid) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5954 | if (uid == SYSTEM_UID) { |
| 5955 | // The system gets to run in any process. If there are multiple processes with the same |
| 5956 | // uid, just pick the first (this should never happen). |
| 5957 | final SparseArray<WindowProcessController> procs = |
| 5958 | mProcessNames.getMap().get(processName); |
| 5959 | if (procs == null) return null; |
| 5960 | final int procCount = procs.size(); |
| 5961 | for (int i = 0; i < procCount; i++) { |
| 5962 | final int procUid = procs.keyAt(i); |
| 5963 | if (UserHandle.isApp(procUid) || !UserHandle.isSameUser(procUid, uid)) { |
| 5964 | // Don't use an app process or different user process for system component. |
| 5965 | continue; |
| 5966 | } |
| 5967 | return procs.valueAt(i); |
| 5968 | } |
| 5969 | } |
| 5970 | |
| 5971 | return mProcessNames.get(processName, uid); |
| 5972 | } |
| 5973 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5974 | WindowProcessController getProcessController(IApplicationThread thread) { |
| 5975 | if (thread == null) { |
| 5976 | return null; |
| 5977 | } |
| 5978 | |
| 5979 | final IBinder threadBinder = thread.asBinder(); |
| 5980 | final ArrayMap<String, SparseArray<WindowProcessController>> pmap = mProcessNames.getMap(); |
| 5981 | for (int i = pmap.size()-1; i >= 0; i--) { |
| 5982 | final SparseArray<WindowProcessController> procs = pmap.valueAt(i); |
| 5983 | for (int j = procs.size() - 1; j >= 0; j--) { |
| 5984 | final WindowProcessController proc = procs.valueAt(j); |
| 5985 | if (proc.hasThread() && proc.getThread().asBinder() == threadBinder) { |
| 5986 | return proc; |
| 5987 | } |
| 5988 | } |
| 5989 | } |
| 5990 | |
| 5991 | return null; |
| 5992 | } |
| 5993 | |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 5994 | WindowProcessController getProcessController(int pid, int uid) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 5995 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Yunfan Chen | 8546b21 | 2019-04-01 15:34:44 +0900 | [diff] [blame] | 5996 | if (proc == null) return null; |
| 5997 | if (UserHandle.isApp(uid) && proc.mUid == uid) { |
| 5998 | return proc; |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 5999 | } |
| 6000 | return null; |
| 6001 | } |
| 6002 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6003 | int getUidState(int uid) { |
| 6004 | return mActiveUids.getUidState(uid); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 6005 | } |
| 6006 | |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 6007 | boolean isUidForeground(int uid) { |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 6008 | // A uid is considered to be foreground if it has a visible non-toast window. |
| 6009 | return mWindowManager.mRoot.isAnyNonToastWindowVisibleForUid(uid); |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 6010 | } |
| 6011 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 6012 | boolean isDeviceOwner(int uid) { |
| 6013 | return uid >= 0 && mDeviceOwnerUid == uid; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 6014 | } |
| 6015 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 6016 | void setDeviceOwnerUid(int uid) { |
| 6017 | mDeviceOwnerUid = uid; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 6018 | } |
| 6019 | |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 6020 | /** |
| 6021 | * @return whitelist tag for a uid from mPendingTempWhitelist, null if not currently on |
| 6022 | * the whitelist |
| 6023 | */ |
| 6024 | String getPendingTempWhitelistTagForUidLocked(int uid) { |
| 6025 | return mPendingTempWhitelist.get(uid); |
| 6026 | } |
| 6027 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6028 | void logAppTooSlow(WindowProcessController app, long startTime, String msg) { |
| 6029 | if (true || Build.IS_USER) { |
| 6030 | return; |
| 6031 | } |
| 6032 | |
| 6033 | StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 6034 | StrictMode.allowThreadDiskWrites(); |
| 6035 | try { |
| 6036 | File tracesDir = new File("/data/anr"); |
| 6037 | File tracesFile = null; |
| 6038 | try { |
| 6039 | tracesFile = File.createTempFile("app_slow", null, tracesDir); |
| 6040 | |
| 6041 | StringBuilder sb = new StringBuilder(); |
Neil Fuller | 9774681 | 2019-08-19 14:20:50 +0100 | [diff] [blame] | 6042 | String timeString = |
| 6043 | TimeMigrationUtils.formatMillisWithFixedFormat(System.currentTimeMillis()); |
| 6044 | sb.append(timeString); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6045 | sb.append(": "); |
| 6046 | TimeUtils.formatDuration(SystemClock.uptimeMillis()-startTime, sb); |
| 6047 | sb.append(" since "); |
| 6048 | sb.append(msg); |
| 6049 | FileOutputStream fos = new FileOutputStream(tracesFile); |
| 6050 | fos.write(sb.toString().getBytes()); |
| 6051 | if (app == null) { |
| 6052 | fos.write("\n*** No application process!".getBytes()); |
| 6053 | } |
| 6054 | fos.close(); |
| 6055 | FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1); // -rw-rw-rw- |
| 6056 | } catch (IOException e) { |
| 6057 | Slog.w(TAG, "Unable to prepare slow app traces file: " + tracesFile, e); |
| 6058 | return; |
| 6059 | } |
| 6060 | |
| 6061 | if (app != null && app.getPid() > 0) { |
| 6062 | ArrayList<Integer> firstPids = new ArrayList<Integer>(); |
| 6063 | firstPids.add(app.getPid()); |
| 6064 | dumpStackTraces(tracesFile.getAbsolutePath(), firstPids, null, null); |
| 6065 | } |
| 6066 | |
| 6067 | File lastTracesFile = null; |
| 6068 | File curTracesFile = null; |
| 6069 | for (int i=9; i>=0; i--) { |
| 6070 | String name = String.format(Locale.US, "slow%02d.txt", i); |
| 6071 | curTracesFile = new File(tracesDir, name); |
| 6072 | if (curTracesFile.exists()) { |
| 6073 | if (lastTracesFile != null) { |
| 6074 | curTracesFile.renameTo(lastTracesFile); |
| 6075 | } else { |
| 6076 | curTracesFile.delete(); |
| 6077 | } |
| 6078 | } |
| 6079 | lastTracesFile = curTracesFile; |
| 6080 | } |
| 6081 | tracesFile.renameTo(curTracesFile); |
| 6082 | } finally { |
| 6083 | StrictMode.setThreadPolicy(oldPolicy); |
| 6084 | } |
| 6085 | } |
| 6086 | |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 6087 | boolean isAssociatedCompanionApp(int userId, int uid) { |
| 6088 | final Set<Integer> allUids = mCompanionAppUidsMap.get(userId); |
| 6089 | if (allUids == null) { |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 6090 | return false; |
| 6091 | } |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 6092 | return allUids.contains(uid); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 6093 | } |
| 6094 | |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 6095 | void notifySingleTaskDisplayEmpty(int displayId) { |
| 6096 | mTaskChangeNotificationController.notifySingleTaskDisplayEmpty(displayId); |
| 6097 | } |
| 6098 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6099 | final class H extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6100 | static final int REPORT_TIME_TRACKER_MSG = 1; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 6101 | |
| 6102 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 6103 | static final int FIRST_ACTIVITY_STACK_MSG = 100; |
| 6104 | static final int FIRST_SUPERVISOR_STACK_MSG = 200; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6105 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 6106 | H(Looper looper) { |
| 6107 | super(looper); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6108 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6109 | |
| 6110 | @Override |
| 6111 | public void handleMessage(Message msg) { |
| 6112 | switch (msg.what) { |
| 6113 | case REPORT_TIME_TRACKER_MSG: { |
| 6114 | AppTimeTracker tracker = (AppTimeTracker) msg.obj; |
| 6115 | tracker.deliverResult(mContext); |
| 6116 | } break; |
| 6117 | } |
| 6118 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6119 | } |
| 6120 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6121 | final class UiHandler extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6122 | static final int DISMISS_DIALOG_UI_MSG = 1; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6123 | |
| 6124 | public UiHandler() { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 6125 | super(UiThread.get().getLooper(), null, true); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6126 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6127 | |
| 6128 | @Override |
| 6129 | public void handleMessage(Message msg) { |
| 6130 | switch (msg.what) { |
| 6131 | case DISMISS_DIALOG_UI_MSG: { |
| 6132 | final Dialog d = (Dialog) msg.obj; |
| 6133 | d.dismiss(); |
| 6134 | break; |
| 6135 | } |
| 6136 | } |
| 6137 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6138 | } |
| 6139 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6140 | final class LocalService extends ActivityTaskManagerInternal { |
| 6141 | @Override |
| 6142 | public SleepToken acquireSleepToken(String tag, int displayId) { |
Daulet Zhanguzin | c6c641f | 2020-01-02 17:18:30 +0000 | [diff] [blame] | 6143 | Objects.requireNonNull(tag); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6144 | return ActivityTaskManagerService.this.acquireSleepToken(tag, displayId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6145 | } |
| 6146 | |
| 6147 | @Override |
| 6148 | public ComponentName getHomeActivityForUser(int userId) { |
| 6149 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6150 | final ActivityRecord homeActivity = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6151 | mRootWindowContainer.getDefaultDisplayHomeActivityForUser(userId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 6152 | return homeActivity == null ? null : homeActivity.mActivityComponent; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6153 | } |
| 6154 | } |
| 6155 | |
| 6156 | @Override |
| 6157 | public void onLocalVoiceInteractionStarted(IBinder activity, |
| 6158 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 6159 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6160 | onLocalVoiceInteractionStartedLocked(activity, voiceSession, voiceInteractor); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6161 | } |
| 6162 | } |
| 6163 | |
| 6164 | @Override |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 6165 | public void notifySingleTaskDisplayDrawn(int displayId) { |
| 6166 | mTaskChangeNotificationController.notifySingleTaskDisplayDrawn(displayId); |
| 6167 | } |
| 6168 | |
| 6169 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6170 | public void notifyAppTransitionFinished() { |
| 6171 | synchronized (mGlobalLock) { |
| 6172 | mStackSupervisor.notifyAppTransitionDone(); |
| 6173 | } |
| 6174 | } |
| 6175 | |
| 6176 | @Override |
| 6177 | public void notifyAppTransitionCancelled() { |
| 6178 | synchronized (mGlobalLock) { |
| 6179 | mStackSupervisor.notifyAppTransitionDone(); |
| 6180 | } |
| 6181 | } |
| 6182 | |
| 6183 | @Override |
| 6184 | public List<IBinder> getTopVisibleActivities() { |
| 6185 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6186 | return mRootWindowContainer.getTopVisibleActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6187 | } |
| 6188 | } |
| 6189 | |
| 6190 | @Override |
| 6191 | public void notifyDockedStackMinimizedChanged(boolean minimized) { |
| 6192 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6193 | mRootWindowContainer.setDockedStackMinimized(minimized); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6194 | } |
| 6195 | } |
| 6196 | |
| 6197 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6198 | public int startActivitiesAsPackage(String packageName, @Nullable String featureId, |
| 6199 | int userId, Intent[] intents, Bundle bOptions) { |
Daulet Zhanguzin | c6c641f | 2020-01-02 17:18:30 +0000 | [diff] [blame] | 6200 | Objects.requireNonNull(intents, "intents"); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6201 | final String[] resolvedTypes = new String[intents.length]; |
| 6202 | |
| 6203 | // UID of the package on user userId. |
| 6204 | // "= 0" is needed because otherwise catch(RemoteException) would make it look like |
| 6205 | // packageUid may not be initialized. |
| 6206 | int packageUid = 0; |
| 6207 | final long ident = Binder.clearCallingIdentity(); |
| 6208 | |
| 6209 | try { |
| 6210 | for (int i = 0; i < intents.length; i++) { |
| 6211 | resolvedTypes[i] = |
| 6212 | intents[i].resolveTypeIfNeeded(mContext.getContentResolver()); |
| 6213 | } |
| 6214 | |
| 6215 | packageUid = AppGlobals.getPackageManager().getPackageUid( |
| 6216 | packageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId); |
| 6217 | } catch (RemoteException e) { |
| 6218 | // Shouldn't happen. |
| 6219 | } finally { |
| 6220 | Binder.restoreCallingIdentity(ident); |
| 6221 | } |
| 6222 | |
Riddle Hsu | 591bf61 | 2019-02-14 17:55:31 +0800 | [diff] [blame] | 6223 | return getActivityStartController().startActivitiesInPackage( |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6224 | packageUid, packageName, featureId, |
Riddle Hsu | 591bf61 | 2019-02-14 17:55:31 +0800 | [diff] [blame] | 6225 | intents, resolvedTypes, null /* resultTo */, |
| 6226 | SafeActivityOptions.fromBundle(bOptions), userId, |
| 6227 | false /* validateIncomingUser */, null /* originatingPendingIntent */, |
| 6228 | false /* allowBackgroundActivityStart */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6229 | } |
| 6230 | |
| 6231 | @Override |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6232 | public int startActivitiesInPackage(int uid, int realCallingPid, int realCallingUid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6233 | String callingPackage, @Nullable String callingFeatureId, Intent[] intents, |
| 6234 | String[] resolvedTypes, IBinder resultTo, SafeActivityOptions options, int userId, |
| 6235 | boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6236 | boolean allowBackgroundActivityStart) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 6237 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6238 | synchronized (mGlobalLock) { |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6239 | return getActivityStartController().startActivitiesInPackage(uid, realCallingPid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6240 | realCallingUid, callingPackage, callingFeatureId, intents, resolvedTypes, |
| 6241 | resultTo, options, userId, validateIncomingUser, originatingPendingIntent, |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6242 | allowBackgroundActivityStart); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6243 | } |
| 6244 | } |
| 6245 | |
| 6246 | @Override |
| 6247 | public int startActivityInPackage(int uid, int realCallingPid, int realCallingUid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6248 | String callingPackage, @Nullable String callingFeatureId, Intent intent, |
| 6249 | String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 6250 | int startFlags, SafeActivityOptions options, int userId, Task inTask, String reason, |
| 6251 | boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6252 | boolean allowBackgroundActivityStart) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 6253 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6254 | synchronized (mGlobalLock) { |
| 6255 | return getActivityStartController().startActivityInPackage(uid, realCallingPid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6256 | realCallingUid, callingPackage, callingFeatureId, intent, resolvedType, |
| 6257 | resultTo, resultWho, requestCode, startFlags, options, userId, inTask, |
| 6258 | reason, validateIncomingUser, originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6259 | allowBackgroundActivityStart); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6260 | } |
| 6261 | } |
| 6262 | |
| 6263 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6264 | public int startActivityAsUser(IApplicationThread caller, String callerPackage, |
Alex Kershaw | 16406c3 | 2020-02-17 12:28:53 +0000 | [diff] [blame] | 6265 | @Nullable String callerFeatureId, Intent intent, @Nullable IBinder resultTo, |
| 6266 | int startFlags, Bundle options, int userId) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6267 | return ActivityTaskManagerService.this.startActivityAsUser( |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6268 | caller, callerPackage, callerFeatureId, intent, |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6269 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Alex Kershaw | 16406c3 | 2020-02-17 12:28:53 +0000 | [diff] [blame] | 6270 | resultTo, null, 0, startFlags, null, options, userId, |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6271 | false /*validateIncomingUser*/); |
| 6272 | } |
| 6273 | |
| 6274 | @Override |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 6275 | public void notifyKeyguardFlagsChanged(@Nullable Runnable callback, int displayId) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6276 | synchronized (mGlobalLock) { |
| 6277 | |
| 6278 | // We might change the visibilities here, so prepare an empty app transition which |
| 6279 | // might be overridden later if we actually change visibilities. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6280 | final DisplayContent displayContent = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6281 | mRootWindowContainer.getDisplayContent(displayId); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6282 | if (displayContent == null) { |
lumark | 52ea28e | 2018-11-09 17:30:47 +0800 | [diff] [blame] | 6283 | return; |
| 6284 | } |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6285 | final DisplayContent dc = displayContent.mDisplayContent; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6286 | final boolean wasTransitionSet = |
| 6287 | dc.mAppTransition.getAppTransition() != TRANSIT_NONE; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6288 | if (!wasTransitionSet) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6289 | dc.prepareAppTransition(TRANSIT_NONE, false /* alwaysKeepCurrent */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6290 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6291 | mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6292 | |
| 6293 | // If there was a transition set already we don't want to interfere with it as we |
| 6294 | // might be starting it too early. |
| 6295 | if (!wasTransitionSet) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6296 | dc.executeAppTransition(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6297 | } |
| 6298 | } |
| 6299 | if (callback != null) { |
| 6300 | callback.run(); |
| 6301 | } |
| 6302 | } |
| 6303 | |
| 6304 | @Override |
| 6305 | public void notifyKeyguardTrustedChanged() { |
| 6306 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6307 | if (mKeyguardController.isKeyguardShowing(DEFAULT_DISPLAY)) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6308 | mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6309 | } |
| 6310 | } |
| 6311 | } |
| 6312 | |
| 6313 | /** |
| 6314 | * Called after virtual display Id is updated by |
| 6315 | * {@link com.android.server.vr.Vr2dDisplay} with a specific |
| 6316 | * {@param vrVr2dDisplayId}. |
| 6317 | */ |
| 6318 | @Override |
| 6319 | public void setVr2dDisplayId(int vr2dDisplayId) { |
| 6320 | if (DEBUG_STACK) Slog.d(TAG, "setVr2dDisplayId called for: " + vr2dDisplayId); |
| 6321 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6322 | mVr2dDisplayId = vr2dDisplayId; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6323 | } |
| 6324 | } |
| 6325 | |
| 6326 | @Override |
| 6327 | public void setFocusedActivity(IBinder token) { |
| 6328 | synchronized (mGlobalLock) { |
| 6329 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 6330 | if (r == null) { |
| 6331 | throw new IllegalArgumentException( |
| 6332 | "setFocusedActivity: No activity record matching token=" + token); |
| 6333 | } |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 6334 | if (r.moveFocusableActivityToTop("setFocusedActivity")) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6335 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6336 | } |
| 6337 | } |
| 6338 | } |
| 6339 | |
| 6340 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6341 | public void registerScreenObserver(ScreenObserver observer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6342 | mScreenObservers.add(observer); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6343 | } |
| 6344 | |
| 6345 | @Override |
| 6346 | public boolean isCallerRecents(int callingUid) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 6347 | return getRecentTasks().isCallerRecents(callingUid); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6348 | } |
| 6349 | |
| 6350 | @Override |
| 6351 | public boolean isRecentsComponentHomeActivity(int userId) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 6352 | return getRecentTasks().isRecentsComponentHomeActivity(userId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6353 | } |
| 6354 | |
| 6355 | @Override |
| 6356 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
| 6357 | ActivityTaskManagerService.this.cancelRecentsAnimation(restoreHomeStackPosition); |
| 6358 | } |
| 6359 | |
| 6360 | @Override |
| 6361 | public void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6362 | ActivityTaskManagerService.this.enforceCallerIsRecentsOrHasPermission(permission, func); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6363 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6364 | |
| 6365 | @Override |
| 6366 | public void notifyActiveVoiceInteractionServiceChanged(ComponentName component) { |
| 6367 | synchronized (mGlobalLock) { |
| 6368 | mActiveVoiceInteractionServiceComponent = component; |
| 6369 | } |
| 6370 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6371 | |
| 6372 | @Override |
| 6373 | public void setAllowAppSwitches(@NonNull String type, int uid, int userId) { |
| 6374 | if (!mAmInternal.isUserRunning(userId, ActivityManager.FLAG_OR_STOPPED)) { |
| 6375 | return; |
| 6376 | } |
| 6377 | synchronized (mGlobalLock) { |
| 6378 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(userId); |
| 6379 | if (types == null) { |
| 6380 | if (uid < 0) { |
| 6381 | return; |
| 6382 | } |
| 6383 | types = new ArrayMap<>(); |
| 6384 | mAllowAppSwitchUids.put(userId, types); |
| 6385 | } |
| 6386 | if (uid < 0) { |
| 6387 | types.remove(type); |
| 6388 | } else { |
| 6389 | types.put(type, uid); |
| 6390 | } |
| 6391 | } |
| 6392 | } |
| 6393 | |
| 6394 | @Override |
| 6395 | public void onUserStopped(int userId) { |
| 6396 | synchronized (mGlobalLock) { |
| 6397 | getRecentTasks().unloadUserDataFromMemoryLocked(userId); |
| 6398 | mAllowAppSwitchUids.remove(userId); |
| 6399 | } |
| 6400 | } |
| 6401 | |
| 6402 | @Override |
| 6403 | public boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 6404 | synchronized (mGlobalLock) { |
| 6405 | return ActivityTaskManagerService.this.isGetTasksAllowed( |
| 6406 | caller, callingPid, callingUid); |
| 6407 | } |
| 6408 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6409 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6410 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6411 | @Override |
| 6412 | public void onProcessAdded(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6413 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6414 | mProcessNames.put(proc.mName, proc.mUid, proc); |
| 6415 | } |
| 6416 | } |
| 6417 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6418 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6419 | @Override |
| 6420 | public void onProcessRemoved(String name, int uid) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6421 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6422 | mProcessNames.remove(name, uid); |
| 6423 | } |
| 6424 | } |
| 6425 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6426 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6427 | @Override |
| 6428 | public void onCleanUpApplicationRecord(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6429 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6430 | if (proc == mHomeProcess) { |
| 6431 | mHomeProcess = null; |
| 6432 | } |
| 6433 | if (proc == mPreviousProcess) { |
| 6434 | mPreviousProcess = null; |
| 6435 | } |
| 6436 | } |
| 6437 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6438 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6439 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6440 | @Override |
| 6441 | public int getTopProcessState() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6442 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6443 | return mTopProcessState; |
| 6444 | } |
| 6445 | } |
| 6446 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6447 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6448 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6449 | public boolean isHeavyWeightProcess(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6450 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6451 | return proc == mHeavyWeightProcess; |
| 6452 | } |
| 6453 | } |
| 6454 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6455 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6456 | @Override |
| 6457 | public void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6458 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6459 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals(proc); |
| 6460 | } |
| 6461 | } |
| 6462 | |
| 6463 | @Override |
| 6464 | public void finishHeavyWeightApp() { |
| 6465 | synchronized (mGlobalLock) { |
Sudheer Shanka | ee1da27 | 2018-10-20 20:11:44 -0700 | [diff] [blame] | 6466 | if (mHeavyWeightProcess != null) { |
| 6467 | mHeavyWeightProcess.finishActivities(); |
| 6468 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6469 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals( |
| 6470 | mHeavyWeightProcess); |
| 6471 | } |
| 6472 | } |
| 6473 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6474 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6475 | @Override |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6476 | public boolean isSleeping() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6477 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6478 | return isSleepingLocked(); |
| 6479 | } |
| 6480 | } |
| 6481 | |
| 6482 | @Override |
| 6483 | public boolean isShuttingDown() { |
| 6484 | synchronized (mGlobalLock) { |
| 6485 | return mShuttingDown; |
| 6486 | } |
| 6487 | } |
| 6488 | |
| 6489 | @Override |
| 6490 | public boolean shuttingDown(boolean booted, int timeout) { |
| 6491 | synchronized (mGlobalLock) { |
| 6492 | mShuttingDown = true; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6493 | mRootWindowContainer.prepareForShutdown(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6494 | updateEventDispatchingLocked(booted); |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 6495 | notifyTaskPersisterLocked(null, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6496 | return mStackSupervisor.shutdownLocked(timeout); |
| 6497 | } |
| 6498 | } |
| 6499 | |
| 6500 | @Override |
| 6501 | public void enableScreenAfterBoot(boolean booted) { |
| 6502 | synchronized (mGlobalLock) { |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 6503 | writeBootProgressEnableScreen(SystemClock.uptimeMillis()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6504 | mWindowManager.enableScreenAfterBoot(); |
| 6505 | updateEventDispatchingLocked(booted); |
| 6506 | } |
| 6507 | } |
| 6508 | |
| 6509 | @Override |
| 6510 | public boolean showStrictModeViolationDialog() { |
| 6511 | synchronized (mGlobalLock) { |
| 6512 | return mShowDialogs && !mSleeping && !mShuttingDown; |
| 6513 | } |
| 6514 | } |
| 6515 | |
| 6516 | @Override |
| 6517 | public void showSystemReadyErrorDialogsIfNeeded() { |
| 6518 | synchronized (mGlobalLock) { |
| 6519 | try { |
| 6520 | if (AppGlobals.getPackageManager().hasSystemUidErrors()) { |
| 6521 | Slog.e(TAG, "UIDs on the system are inconsistent, you need to wipe your" |
| 6522 | + " data partition or your device will be unstable."); |
| 6523 | mUiHandler.post(() -> { |
| 6524 | if (mShowDialogs) { |
| 6525 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6526 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6527 | d.setCancelable(false); |
| 6528 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6529 | d.setMessage(mUiContext.getText(R.string.system_error_wipe_data)); |
| 6530 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6531 | mUiContext.getText(R.string.ok), |
| 6532 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6533 | d.show(); |
| 6534 | } |
| 6535 | }); |
| 6536 | } |
| 6537 | } catch (RemoteException e) { |
| 6538 | } |
| 6539 | |
| 6540 | if (!Build.isBuildConsistent()) { |
| 6541 | Slog.e(TAG, "Build fingerprint is not consistent, warning user"); |
| 6542 | mUiHandler.post(() -> { |
| 6543 | if (mShowDialogs) { |
| 6544 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6545 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6546 | d.setCancelable(false); |
| 6547 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6548 | d.setMessage(mUiContext.getText(R.string.system_error_manufacturer)); |
| 6549 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6550 | mUiContext.getText(R.string.ok), |
| 6551 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6552 | d.show(); |
| 6553 | } |
| 6554 | }); |
| 6555 | } |
| 6556 | } |
| 6557 | } |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6558 | |
| 6559 | @Override |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6560 | public void onProcessMapped(int pid, WindowProcessController proc) { |
| 6561 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6562 | mProcessMap.put(pid, proc); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6563 | } |
| 6564 | } |
| 6565 | |
| 6566 | @Override |
| 6567 | public void onProcessUnMapped(int pid) { |
| 6568 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6569 | mProcessMap.remove(pid); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6570 | } |
| 6571 | } |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6572 | |
| 6573 | @Override |
| 6574 | public void onPackageDataCleared(String name) { |
| 6575 | synchronized (mGlobalLock) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6576 | mCompatModePackages.handlePackageDataClearedLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6577 | mAppWarnings.onPackageDataCleared(name); |
| 6578 | } |
| 6579 | } |
| 6580 | |
| 6581 | @Override |
| 6582 | public void onPackageUninstalled(String name) { |
| 6583 | synchronized (mGlobalLock) { |
| 6584 | mAppWarnings.onPackageUninstalled(name); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6585 | mCompatModePackages.handlePackageUninstalledLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6586 | } |
| 6587 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6588 | |
| 6589 | @Override |
| 6590 | public void onPackageAdded(String name, boolean replacing) { |
| 6591 | synchronized (mGlobalLock) { |
| 6592 | mCompatModePackages.handlePackageAddedLocked(name, replacing); |
| 6593 | } |
| 6594 | } |
| 6595 | |
| 6596 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6597 | public void onPackageReplaced(ApplicationInfo aInfo) { |
| 6598 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6599 | mRootWindowContainer.updateActivityApplicationInfo(aInfo); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6600 | } |
| 6601 | } |
| 6602 | |
| 6603 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6604 | public CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai) { |
| 6605 | synchronized (mGlobalLock) { |
| 6606 | return compatibilityInfoForPackageLocked(ai); |
| 6607 | } |
| 6608 | } |
| 6609 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6610 | /** |
| 6611 | * Set the corresponding display information for the process global configuration. To be |
| 6612 | * called when we need to show IME on a different display. |
| 6613 | * |
| 6614 | * @param pid The process id associated with the IME window. |
| 6615 | * @param displayId The ID of the display showing the IME. |
| 6616 | */ |
| 6617 | @Override |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6618 | public void onImeWindowSetOnDisplay(final int pid, final int displayId) { |
lumark | 4897353 | 2019-04-12 20:18:15 +0800 | [diff] [blame] | 6619 | // Don't update process-level configuration for Multi-Client IME process since other |
| 6620 | // IMEs on other displays will also receive this configuration change due to IME |
| 6621 | // services use the same application config/context. |
| 6622 | if (InputMethodSystemProperty.MULTI_CLIENT_IME_ENABLED) return; |
lumark | 5df4951 | 2019-04-02 14:56:46 +0800 | [diff] [blame] | 6623 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6624 | if (pid == MY_PID || pid < 0) { |
| 6625 | if (DEBUG_CONFIGURATION) { |
| 6626 | Slog.w(TAG, |
| 6627 | "Trying to update display configuration for system/invalid process."); |
| 6628 | } |
| 6629 | return; |
| 6630 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6631 | synchronized (mGlobalLock) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6632 | final DisplayContent displayContent = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6633 | mRootWindowContainer.getDisplayContent(displayId); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6634 | if (displayContent == null) { |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6635 | // Call might come when display is not yet added or has been removed. |
| 6636 | if (DEBUG_CONFIGURATION) { |
| 6637 | Slog.w(TAG, "Trying to update display configuration for non-existing " |
| 6638 | + "displayId=" + displayId); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6639 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6640 | return; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6641 | } |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6642 | final WindowProcessController process = mProcessMap.getProcess(pid); |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6643 | if (process == null) { |
| 6644 | if (DEBUG_CONFIGURATION) { |
| 6645 | Slog.w(TAG, "Trying to update display configuration for invalid " |
| 6646 | + "process, pid=" + pid); |
| 6647 | } |
| 6648 | return; |
| 6649 | } |
lumark | ddc77fb | 2019-06-27 22:22:23 +0800 | [diff] [blame] | 6650 | process.mIsImeProcess = true; |
Andrii Kulian | fa23a9e | 2019-10-10 15:15:36 -0700 | [diff] [blame] | 6651 | process.registerDisplayConfigurationListener(displayContent); |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6652 | } |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6653 | } |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6654 | |
| 6655 | @Override |
| 6656 | public void sendActivityResult(int callingUid, IBinder activityToken, String resultWho, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 6657 | int requestCode, int resultCode, Intent data) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6658 | synchronized (mGlobalLock) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 6659 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 6660 | if (r != null && r.getRootTask() != null) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 6661 | r.sendResult(callingUid, resultWho, requestCode, resultCode, data); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6662 | } |
| 6663 | } |
| 6664 | } |
| 6665 | |
| 6666 | @Override |
| 6667 | public void clearPendingResultForActivity(IBinder activityToken, |
| 6668 | WeakReference<PendingIntentRecord> pir) { |
| 6669 | synchronized (mGlobalLock) { |
| 6670 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 6671 | if (r != null && r.pendingResults != null) { |
| 6672 | r.pendingResults.remove(pir); |
| 6673 | } |
| 6674 | } |
| 6675 | } |
| 6676 | |
| 6677 | @Override |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6678 | public ActivityTokens getTopActivityForTask(int taskId) { |
| 6679 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6680 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 6681 | if (task == null) { |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6682 | Slog.w(TAG, "getApplicationThreadForTopActivity failed:" |
| 6683 | + " Requested task not found"); |
| 6684 | return null; |
| 6685 | } |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 6686 | final ActivityRecord activity = task.getTopNonFinishingActivity(); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6687 | if (activity == null) { |
| 6688 | Slog.w(TAG, "getApplicationThreadForTopActivity failed:" |
| 6689 | + " Requested activity not found"); |
| 6690 | return null; |
| 6691 | } |
| 6692 | if (!activity.attachedToProcess()) { |
| 6693 | Slog.w(TAG, "getApplicationThreadForTopActivity failed: No process for " |
| 6694 | + activity); |
| 6695 | return null; |
| 6696 | } |
| 6697 | return new ActivityTokens(activity.appToken, activity.assistToken, |
| 6698 | activity.app.getThread()); |
| 6699 | } |
| 6700 | } |
| 6701 | |
| 6702 | @Override |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6703 | public IIntentSender getIntentSender(int type, String packageName, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6704 | @Nullable String featureId, int callingUid, int userId, IBinder token, |
| 6705 | String resultWho, int requestCode, Intent[] intents, String[] resolvedTypes, |
| 6706 | int flags, Bundle bOptions) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6707 | synchronized (mGlobalLock) { |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6708 | return getIntentSenderLocked(type, packageName, featureId, callingUid, userId, |
| 6709 | token, resultWho, requestCode, intents, resolvedTypes, flags, bOptions); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6710 | } |
| 6711 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 6712 | |
| 6713 | @Override |
| 6714 | public ActivityServiceConnectionsHolder getServiceConnectionsHolder(IBinder token) { |
| 6715 | synchronized (mGlobalLock) { |
| 6716 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 6717 | if (r == null) { |
| 6718 | return null; |
| 6719 | } |
| 6720 | if (r.mServiceConnectionsHolder == null) { |
| 6721 | r.mServiceConnectionsHolder = new ActivityServiceConnectionsHolder( |
| 6722 | ActivityTaskManagerService.this, r); |
| 6723 | } |
| 6724 | |
| 6725 | return r.mServiceConnectionsHolder; |
| 6726 | } |
| 6727 | } |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6728 | |
| 6729 | @Override |
| 6730 | public Intent getHomeIntent() { |
| 6731 | synchronized (mGlobalLock) { |
| 6732 | return ActivityTaskManagerService.this.getHomeIntent(); |
| 6733 | } |
| 6734 | } |
| 6735 | |
| 6736 | @Override |
| 6737 | public boolean startHomeActivity(int userId, String reason) { |
| 6738 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6739 | return mRootWindowContainer.startHomeOnDisplay(userId, reason, DEFAULT_DISPLAY); |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6740 | } |
| 6741 | } |
| 6742 | |
| 6743 | @Override |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 6744 | public boolean startHomeOnDisplay(int userId, String reason, int displayId, |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 6745 | boolean allowInstrumenting, boolean fromHomeKey) { |
Chilun | 5fd5654 | 2019-03-21 19:51:37 +0800 | [diff] [blame] | 6746 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6747 | return mRootWindowContainer.startHomeOnDisplay(userId, reason, displayId, |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 6748 | allowInstrumenting, fromHomeKey); |
Chilun | 5fd5654 | 2019-03-21 19:51:37 +0800 | [diff] [blame] | 6749 | } |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 6750 | } |
| 6751 | |
| 6752 | @Override |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6753 | public boolean startHomeOnAllDisplays(int userId, String reason) { |
| 6754 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6755 | return mRootWindowContainer.startHomeOnAllDisplays(userId, reason); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6756 | } |
| 6757 | } |
| 6758 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6759 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6760 | @Override |
| 6761 | public boolean isFactoryTestProcess(WindowProcessController wpc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6762 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6763 | if (mFactoryTest == FACTORY_TEST_OFF) { |
| 6764 | return false; |
| 6765 | } |
| 6766 | if (mFactoryTest == FACTORY_TEST_LOW_LEVEL && mTopComponent != null |
| 6767 | && wpc.mName.equals(mTopComponent.getPackageName())) { |
| 6768 | return true; |
| 6769 | } |
| 6770 | return mFactoryTest == FACTORY_TEST_HIGH_LEVEL |
| 6771 | && (wpc.mInfo.flags & FLAG_FACTORY_TEST) != 0; |
| 6772 | } |
| 6773 | } |
| 6774 | |
| 6775 | @Override |
| 6776 | public void updateTopComponentForFactoryTest() { |
| 6777 | synchronized (mGlobalLock) { |
| 6778 | if (mFactoryTest != FACTORY_TEST_LOW_LEVEL) { |
| 6779 | return; |
| 6780 | } |
| 6781 | final ResolveInfo ri = mContext.getPackageManager() |
| 6782 | .resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST), STOCK_PM_FLAGS); |
| 6783 | final CharSequence errorMsg; |
| 6784 | if (ri != null) { |
| 6785 | final ActivityInfo ai = ri.activityInfo; |
| 6786 | final ApplicationInfo app = ai.applicationInfo; |
| 6787 | if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 6788 | mTopAction = Intent.ACTION_FACTORY_TEST; |
| 6789 | mTopData = null; |
| 6790 | mTopComponent = new ComponentName(app.packageName, ai.name); |
| 6791 | errorMsg = null; |
| 6792 | } else { |
| 6793 | errorMsg = mContext.getResources().getText( |
| 6794 | com.android.internal.R.string.factorytest_not_system); |
| 6795 | } |
| 6796 | } else { |
| 6797 | errorMsg = mContext.getResources().getText( |
| 6798 | com.android.internal.R.string.factorytest_no_action); |
| 6799 | } |
| 6800 | if (errorMsg == null) { |
| 6801 | return; |
| 6802 | } |
| 6803 | |
| 6804 | mTopAction = null; |
| 6805 | mTopData = null; |
| 6806 | mTopComponent = null; |
| 6807 | mUiHandler.post(() -> { |
| 6808 | Dialog d = new FactoryErrorDialog(mUiContext, errorMsg); |
| 6809 | d.show(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 6810 | mAmInternal.ensureBootCompleted(); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6811 | }); |
| 6812 | } |
| 6813 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6814 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6815 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6816 | @Override |
| 6817 | public void handleAppDied(WindowProcessController wpc, boolean restarting, |
| 6818 | Runnable finishInstrumentationCallback) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6819 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6820 | // Remove this application's activities from active lists. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6821 | boolean hasVisibleActivities = mRootWindowContainer.handleAppDied(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6822 | |
| 6823 | wpc.clearRecentTasks(); |
| 6824 | wpc.clearActivities(); |
| 6825 | |
| 6826 | if (wpc.isInstrumenting()) { |
| 6827 | finishInstrumentationCallback.run(); |
| 6828 | } |
| 6829 | |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6830 | if (!restarting && hasVisibleActivities) { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 6831 | deferWindowLayout(); |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6832 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6833 | if (!mRootWindowContainer.resumeFocusedStacksTopActivities()) { |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6834 | // If there was nothing to resume, and we are not already restarting |
| 6835 | // this process, but there is a visible activity that is hosted by the |
| 6836 | // process...then make sure all visible activities are running, taking |
| 6837 | // care of restarting this process. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6838 | mRootWindowContainer.ensureActivitiesVisible(null, 0, |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6839 | !PRESERVE_WINDOWS); |
| 6840 | } |
| 6841 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 6842 | continueWindowLayout(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6843 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6844 | } |
| 6845 | } |
| 6846 | } |
| 6847 | |
| 6848 | @Override |
| 6849 | public void closeSystemDialogs(String reason) { |
| 6850 | enforceNotIsolatedCaller("closeSystemDialogs"); |
| 6851 | |
| 6852 | final int pid = Binder.getCallingPid(); |
| 6853 | final int uid = Binder.getCallingUid(); |
| 6854 | final long origId = Binder.clearCallingIdentity(); |
| 6855 | try { |
| 6856 | synchronized (mGlobalLock) { |
| 6857 | // Only allow this from foreground processes, so that background |
| 6858 | // applications can't abuse it to prevent system UI from being shown. |
| 6859 | if (uid >= FIRST_APPLICATION_UID) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6860 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6861 | if (!proc.isPerceptible()) { |
| 6862 | Slog.w(TAG, "Ignoring closeSystemDialogs " + reason |
| 6863 | + " from background process " + proc); |
| 6864 | return; |
| 6865 | } |
| 6866 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6867 | mWindowManager.closeSystemDialogs(reason); |
| 6868 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6869 | mRootWindowContainer.closeSystemDialogs(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6870 | } |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 6871 | // Call into AM outside the synchronized block. |
| 6872 | mAmInternal.broadcastCloseSystemDialogs(reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6873 | } finally { |
| 6874 | Binder.restoreCallingIdentity(origId); |
| 6875 | } |
| 6876 | } |
| 6877 | |
| 6878 | @Override |
| 6879 | public void cleanupDisabledPackageComponents( |
| 6880 | String packageName, Set<String> disabledClasses, int userId, boolean booted) { |
| 6881 | synchronized (mGlobalLock) { |
| 6882 | // Clean-up disabled activities. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6883 | if (mRootWindowContainer.finishDisabledPackageActivities( |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6884 | packageName, disabledClasses, true, false, userId) && booted) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6885 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 6886 | mStackSupervisor.scheduleIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6887 | } |
| 6888 | |
| 6889 | // Clean-up disabled tasks |
| 6890 | getRecentTasks().cleanupDisabledPackageTasksLocked( |
| 6891 | packageName, disabledClasses, userId); |
| 6892 | } |
| 6893 | } |
| 6894 | |
| 6895 | @Override |
| 6896 | public boolean onForceStopPackage(String packageName, boolean doit, boolean evenPersistent, |
| 6897 | int userId) { |
| 6898 | synchronized (mGlobalLock) { |
| 6899 | |
| 6900 | boolean didSomething = |
| 6901 | getActivityStartController().clearPendingActivityLaunches(packageName); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6902 | didSomething |= mRootWindowContainer.finishDisabledPackageActivities(packageName, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6903 | null, doit, evenPersistent, userId); |
| 6904 | return didSomething; |
| 6905 | } |
| 6906 | } |
| 6907 | |
| 6908 | @Override |
| 6909 | public void resumeTopActivities(boolean scheduleIdle) { |
| 6910 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6911 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6912 | if (scheduleIdle) { |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 6913 | mStackSupervisor.scheduleIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6914 | } |
| 6915 | } |
| 6916 | } |
| 6917 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6918 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6919 | @Override |
| 6920 | public void preBindApplication(WindowProcessController wpc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6921 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6922 | mStackSupervisor.getActivityMetricsLogger().notifyBindApplication(wpc.mInfo); |
| 6923 | } |
| 6924 | } |
| 6925 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6926 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6927 | @Override |
| 6928 | public boolean attachApplication(WindowProcessController wpc) throws RemoteException { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6929 | synchronized (mGlobalLockWithoutBoost) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 6930 | if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) { |
| 6931 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "attachApplication:" + wpc.mName); |
| 6932 | } |
| 6933 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6934 | return mRootWindowContainer.attachApplication(wpc); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 6935 | } finally { |
| 6936 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 6937 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6938 | } |
| 6939 | } |
| 6940 | |
| 6941 | @Override |
| 6942 | public void notifyLockedProfile(@UserIdInt int userId, int currentUserId) { |
| 6943 | try { |
| 6944 | if (!AppGlobals.getPackageManager().isUidPrivileged(Binder.getCallingUid())) { |
| 6945 | throw new SecurityException("Only privileged app can call notifyLockedProfile"); |
| 6946 | } |
| 6947 | } catch (RemoteException ex) { |
| 6948 | throw new SecurityException("Fail to check is caller a privileged app", ex); |
| 6949 | } |
| 6950 | |
| 6951 | synchronized (mGlobalLock) { |
| 6952 | final long ident = Binder.clearCallingIdentity(); |
| 6953 | try { |
| 6954 | if (mAmInternal.shouldConfirmCredentials(userId)) { |
| 6955 | if (mKeyguardController.isKeyguardLocked()) { |
| 6956 | // Showing launcher to avoid user entering credential twice. |
| 6957 | startHomeActivity(currentUserId, "notifyLockedProfile"); |
| 6958 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6959 | mRootWindowContainer.lockAllProfileTasks(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6960 | } |
| 6961 | } finally { |
| 6962 | Binder.restoreCallingIdentity(ident); |
| 6963 | } |
| 6964 | } |
| 6965 | } |
| 6966 | |
| 6967 | @Override |
| 6968 | public void startConfirmDeviceCredentialIntent(Intent intent, Bundle options) { |
| 6969 | mAmInternal.enforceCallingPermission( |
| 6970 | MANAGE_ACTIVITY_STACKS, "startConfirmDeviceCredentialIntent"); |
| 6971 | |
| 6972 | synchronized (mGlobalLock) { |
| 6973 | final long ident = Binder.clearCallingIdentity(); |
| 6974 | try { |
Pavel Grafov | c0fe0a0 | 2019-05-13 18:19:33 +0100 | [diff] [blame] | 6975 | intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 6976 | final ActivityOptions activityOptions = options != null |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6977 | ? new ActivityOptions(options) : ActivityOptions.makeBasic(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6978 | mContext.startActivityAsUser(intent, activityOptions.toBundle(), |
| 6979 | UserHandle.CURRENT); |
| 6980 | } finally { |
| 6981 | Binder.restoreCallingIdentity(ident); |
| 6982 | } |
| 6983 | } |
| 6984 | } |
| 6985 | |
| 6986 | @Override |
| 6987 | public void writeActivitiesToProto(ProtoOutputStream proto) { |
| 6988 | synchronized (mGlobalLock) { |
| 6989 | // The output proto of "activity --proto activities" |
Wale Ogunwale | f342f06 | 2020-01-27 07:34:13 -0800 | [diff] [blame] | 6990 | mRootWindowContainer.dumpDebug( |
| 6991 | proto, ROOT_WINDOW_CONTAINER, WindowTraceLogLevel.ALL); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6992 | } |
| 6993 | } |
| 6994 | |
| 6995 | @Override |
| 6996 | public void saveANRState(String reason) { |
| 6997 | synchronized (mGlobalLock) { |
| 6998 | final StringWriter sw = new StringWriter(); |
| 6999 | final PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
| 7000 | pw.println(" ANR time: " + DateFormat.getDateTimeInstance().format(new Date())); |
| 7001 | if (reason != null) { |
| 7002 | pw.println(" Reason: " + reason); |
| 7003 | } |
| 7004 | pw.println(); |
| 7005 | getActivityStartController().dump(pw, " ", null); |
| 7006 | pw.println(); |
| 7007 | pw.println("-------------------------------------------------------------------------------"); |
| 7008 | dumpActivitiesLocked(null /* fd */, pw, null /* args */, 0 /* opti */, |
| 7009 | true /* dumpAll */, false /* dumpClient */, null /* dumpPackage */, |
| 7010 | "" /* header */); |
| 7011 | pw.println(); |
| 7012 | pw.close(); |
| 7013 | |
| 7014 | mLastANRState = sw.toString(); |
| 7015 | } |
| 7016 | } |
| 7017 | |
| 7018 | @Override |
| 7019 | public void clearSavedANRState() { |
| 7020 | synchronized (mGlobalLock) { |
| 7021 | mLastANRState = null; |
| 7022 | } |
| 7023 | } |
| 7024 | |
| 7025 | @Override |
| 7026 | public void dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args, int opti, |
| 7027 | boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 7028 | synchronized (mGlobalLock) { |
| 7029 | if (DUMP_ACTIVITIES_CMD.equals(cmd) || DUMP_ACTIVITIES_SHORT_CMD.equals(cmd)) { |
| 7030 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage); |
| 7031 | } else if (DUMP_LASTANR_CMD.equals(cmd)) { |
| 7032 | dumpLastANRLocked(pw); |
| 7033 | } else if (DUMP_LASTANR_TRACES_CMD.equals(cmd)) { |
| 7034 | dumpLastANRTracesLocked(pw); |
| 7035 | } else if (DUMP_STARTER_CMD.equals(cmd)) { |
| 7036 | dumpActivityStarterLocked(pw, dumpPackage); |
| 7037 | } else if (DUMP_CONTAINERS_CMD.equals(cmd)) { |
| 7038 | dumpActivityContainersLocked(pw); |
| 7039 | } else if (DUMP_RECENTS_CMD.equals(cmd) || DUMP_RECENTS_SHORT_CMD.equals(cmd)) { |
| 7040 | if (getRecentTasks() != null) { |
| 7041 | getRecentTasks().dump(pw, dumpAll, dumpPackage); |
| 7042 | } |
| 7043 | } |
| 7044 | } |
| 7045 | } |
| 7046 | |
| 7047 | @Override |
| 7048 | public boolean dumpForProcesses(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 7049 | String dumpPackage, int dumpAppId, boolean needSep, boolean testPssMode, |
| 7050 | int wakefulness) { |
| 7051 | synchronized (mGlobalLock) { |
| 7052 | if (mHomeProcess != null && (dumpPackage == null |
| 7053 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
| 7054 | if (needSep) { |
| 7055 | pw.println(); |
| 7056 | needSep = false; |
| 7057 | } |
| 7058 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 7059 | } |
| 7060 | if (mPreviousProcess != null && (dumpPackage == null |
| 7061 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 7062 | if (needSep) { |
| 7063 | pw.println(); |
| 7064 | needSep = false; |
| 7065 | } |
| 7066 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 7067 | } |
| 7068 | if (dumpAll && (mPreviousProcess == null || dumpPackage == null |
| 7069 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 7070 | StringBuilder sb = new StringBuilder(128); |
| 7071 | sb.append(" mPreviousProcessVisibleTime: "); |
| 7072 | TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb); |
| 7073 | pw.println(sb); |
| 7074 | } |
| 7075 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 7076 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
| 7077 | if (needSep) { |
| 7078 | pw.println(); |
| 7079 | needSep = false; |
| 7080 | } |
| 7081 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 7082 | } |
| 7083 | if (dumpPackage == null) { |
| 7084 | pw.println(" mGlobalConfiguration: " + getGlobalConfiguration()); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7085 | mRootWindowContainer.dumpDisplayConfigs(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7086 | } |
| 7087 | if (dumpAll) { |
| 7088 | if (dumpPackage == null) { |
| 7089 | pw.println(" mConfigWillChange: " |
| 7090 | + getTopDisplayFocusedStack().mConfigWillChange); |
| 7091 | } |
| 7092 | if (mCompatModePackages.getPackages().size() > 0) { |
| 7093 | boolean printed = false; |
| 7094 | for (Map.Entry<String, Integer> entry |
| 7095 | : mCompatModePackages.getPackages().entrySet()) { |
| 7096 | String pkg = entry.getKey(); |
| 7097 | int mode = entry.getValue(); |
| 7098 | if (dumpPackage != null && !dumpPackage.equals(pkg)) { |
| 7099 | continue; |
| 7100 | } |
| 7101 | if (!printed) { |
| 7102 | pw.println(" mScreenCompatPackages:"); |
| 7103 | printed = true; |
| 7104 | } |
| 7105 | pw.println(" " + pkg + ": " + mode); |
| 7106 | } |
| 7107 | } |
| 7108 | } |
| 7109 | |
| 7110 | if (dumpPackage == null) { |
| 7111 | pw.println(" mWakefulness=" |
| 7112 | + PowerManagerInternal.wakefulnessToString(wakefulness)); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7113 | pw.println(" mSleepTokens=" + mRootWindowContainer.mSleepTokens); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7114 | if (mRunningVoice != null) { |
| 7115 | pw.println(" mRunningVoice=" + mRunningVoice); |
| 7116 | pw.println(" mVoiceWakeLock" + mVoiceWakeLock); |
| 7117 | } |
| 7118 | pw.println(" mSleeping=" + mSleeping); |
| 7119 | pw.println(" mShuttingDown=" + mShuttingDown + " mTestPssMode=" + testPssMode); |
| 7120 | pw.println(" mVrController=" + mVrController); |
| 7121 | } |
| 7122 | if (mCurAppTimeTracker != null) { |
| 7123 | mCurAppTimeTracker.dumpWithHeader(pw, " ", true); |
| 7124 | } |
| 7125 | if (mAllowAppSwitchUids.size() > 0) { |
| 7126 | boolean printed = false; |
| 7127 | for (int i = 0; i < mAllowAppSwitchUids.size(); i++) { |
| 7128 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.valueAt(i); |
| 7129 | for (int j = 0; j < types.size(); j++) { |
| 7130 | if (dumpPackage == null || |
| 7131 | UserHandle.getAppId(types.valueAt(j).intValue()) == dumpAppId) { |
| 7132 | if (needSep) { |
| 7133 | pw.println(); |
| 7134 | needSep = false; |
| 7135 | } |
| 7136 | if (!printed) { |
| 7137 | pw.println(" mAllowAppSwitchUids:"); |
| 7138 | printed = true; |
| 7139 | } |
| 7140 | pw.print(" User "); |
| 7141 | pw.print(mAllowAppSwitchUids.keyAt(i)); |
| 7142 | pw.print(": Type "); |
| 7143 | pw.print(types.keyAt(j)); |
| 7144 | pw.print(" = "); |
| 7145 | UserHandle.formatUid(pw, types.valueAt(j).intValue()); |
| 7146 | pw.println(); |
| 7147 | } |
| 7148 | } |
| 7149 | } |
| 7150 | } |
| 7151 | if (dumpPackage == null) { |
| 7152 | if (mController != null) { |
| 7153 | pw.println(" mController=" + mController |
| 7154 | + " mControllerIsAMonkey=" + mControllerIsAMonkey); |
| 7155 | } |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 7156 | pw.println(" mGoingToSleepWakeLock=" + mStackSupervisor.mGoingToSleepWakeLock); |
| 7157 | pw.println(" mLaunchingActivityWakeLock=" |
| 7158 | + mStackSupervisor.mLaunchingActivityWakeLock); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7159 | } |
| 7160 | |
| 7161 | return needSep; |
| 7162 | } |
| 7163 | } |
| 7164 | |
| 7165 | @Override |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7166 | public void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage, |
| 7167 | int wakeFullness, boolean testPssMode) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7168 | synchronized (mGlobalLock) { |
| 7169 | if (dumpPackage == null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7170 | getGlobalConfiguration().dumpDebug(proto, GLOBAL_CONFIGURATION); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7171 | proto.write(CONFIG_WILL_CHANGE, getTopDisplayFocusedStack().mConfigWillChange); |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7172 | writeSleepStateToProto(proto, wakeFullness, testPssMode); |
| 7173 | if (mRunningVoice != null) { |
| 7174 | final long vrToken = proto.start( |
| 7175 | ActivityManagerServiceDumpProcessesProto.RUNNING_VOICE); |
| 7176 | proto.write(ActivityManagerServiceDumpProcessesProto.Voice.SESSION, |
| 7177 | mRunningVoice.toString()); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7178 | mVoiceWakeLock.dumpDebug( |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7179 | proto, ActivityManagerServiceDumpProcessesProto.Voice.WAKELOCK); |
| 7180 | proto.end(vrToken); |
| 7181 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7182 | mVrController.dumpDebug(proto, |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7183 | ActivityManagerServiceDumpProcessesProto.VR_CONTROLLER); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7184 | if (mController != null) { |
| 7185 | final long token = proto.start(CONTROLLER); |
Wally Yau | 0eb29f6 | 2020-01-08 10:16:43 -0800 | [diff] [blame] | 7186 | proto.write(ActivityManagerServiceDumpProcessesProto.Controller.CONTROLLER, |
| 7187 | mController.toString()); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7188 | proto.write(IS_A_MONKEY, mControllerIsAMonkey); |
| 7189 | proto.end(token); |
| 7190 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7191 | mStackSupervisor.mGoingToSleepWakeLock.dumpDebug(proto, GOING_TO_SLEEP); |
| 7192 | mStackSupervisor.mLaunchingActivityWakeLock.dumpDebug(proto, |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 7193 | LAUNCHING_ACTIVITY); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7194 | } |
| 7195 | |
| 7196 | if (mHomeProcess != null && (dumpPackage == null |
| 7197 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7198 | mHomeProcess.dumpDebug(proto, HOME_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7199 | } |
| 7200 | |
| 7201 | if (mPreviousProcess != null && (dumpPackage == null |
| 7202 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7203 | mPreviousProcess.dumpDebug(proto, PREVIOUS_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7204 | proto.write(PREVIOUS_PROC_VISIBLE_TIME_MS, mPreviousProcessVisibleTime); |
| 7205 | } |
| 7206 | |
| 7207 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 7208 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7209 | mHeavyWeightProcess.dumpDebug(proto, HEAVY_WEIGHT_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7210 | } |
| 7211 | |
| 7212 | for (Map.Entry<String, Integer> entry |
| 7213 | : mCompatModePackages.getPackages().entrySet()) { |
| 7214 | String pkg = entry.getKey(); |
| 7215 | int mode = entry.getValue(); |
| 7216 | if (dumpPackage == null || dumpPackage.equals(pkg)) { |
| 7217 | long compatToken = proto.start(SCREEN_COMPAT_PACKAGES); |
| 7218 | proto.write(PACKAGE, pkg); |
| 7219 | proto.write(MODE, mode); |
| 7220 | proto.end(compatToken); |
| 7221 | } |
| 7222 | } |
| 7223 | |
| 7224 | if (mCurAppTimeTracker != null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7225 | mCurAppTimeTracker.dumpDebug(proto, CURRENT_TRACKER, true); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7226 | } |
| 7227 | |
| 7228 | } |
| 7229 | } |
| 7230 | |
| 7231 | @Override |
| 7232 | public boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, |
| 7233 | String[] args, int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, |
| 7234 | boolean dumpFocusedStackOnly) { |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 7235 | return ActivityTaskManagerService.this.dumpActivity(fd, pw, name, args, opti, dumpAll, |
| 7236 | dumpVisibleStacksOnly, dumpFocusedStackOnly); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7237 | } |
| 7238 | |
| 7239 | @Override |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 7240 | public void dumpForOom(PrintWriter pw) { |
| 7241 | synchronized (mGlobalLock) { |
| 7242 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 7243 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 7244 | if (mHeavyWeightProcess != null) { |
| 7245 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 7246 | } |
| 7247 | } |
| 7248 | } |
| 7249 | |
| 7250 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7251 | public boolean canGcNow() { |
| 7252 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7253 | return isSleeping() || mRootWindowContainer.allResumedActivitiesIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7254 | } |
| 7255 | } |
| 7256 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7257 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7258 | @Override |
| 7259 | public WindowProcessController getTopApp() { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7260 | synchronized (mGlobalLockWithoutBoost) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7261 | if (mRootWindowContainer == null) { |
| 7262 | // Return null if mRootWindowContainer not yet initialize, while update |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 7263 | // oomadj after AMS created. |
| 7264 | return null; |
| 7265 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7266 | final ActivityRecord top = mRootWindowContainer.getTopResumedActivity(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7267 | return top != null ? top.app : null; |
| 7268 | } |
| 7269 | } |
| 7270 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7271 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7272 | @Override |
| 7273 | public void rankTaskLayersIfNeeded() { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7274 | synchronized (mGlobalLockWithoutBoost) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7275 | if (mRootWindowContainer != null) { |
| 7276 | mRootWindowContainer.rankTaskLayersIfNeeded(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7277 | } |
| 7278 | } |
| 7279 | } |
| 7280 | |
| 7281 | @Override |
| 7282 | public void scheduleDestroyAllActivities(String reason) { |
| 7283 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7284 | mRootWindowContainer.scheduleDestroyAllActivities(reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7285 | } |
| 7286 | } |
| 7287 | |
| 7288 | @Override |
| 7289 | public void removeUser(int userId) { |
| 7290 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7291 | mRootWindowContainer.removeUser(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7292 | } |
| 7293 | } |
| 7294 | |
| 7295 | @Override |
| 7296 | public boolean switchUser(int userId, UserState userState) { |
| 7297 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7298 | return mRootWindowContainer.switchUser(userId, userState); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7299 | } |
| 7300 | } |
| 7301 | |
| 7302 | @Override |
| 7303 | public void onHandleAppCrash(WindowProcessController wpc) { |
| 7304 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7305 | mRootWindowContainer.handleAppCrash(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7306 | } |
| 7307 | } |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 7308 | |
| 7309 | @Override |
| 7310 | public int finishTopCrashedActivities(WindowProcessController crashedApp, String reason) { |
| 7311 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7312 | return mRootWindowContainer.finishTopCrashedActivities(crashedApp, reason); |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 7313 | } |
| 7314 | } |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7315 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7316 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7317 | @Override |
| 7318 | public void onUidActive(int uid, int procState) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7319 | mActiveUids.onUidActive(uid, procState); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7320 | } |
| 7321 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7322 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7323 | @Override |
| 7324 | public void onUidInactive(int uid) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7325 | mActiveUids.onUidInactive(uid); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7326 | } |
| 7327 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7328 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7329 | @Override |
| 7330 | public void onActiveUidsCleared() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7331 | mActiveUids.onActiveUidsCleared(); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7332 | } |
| 7333 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7334 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7335 | @Override |
| 7336 | public void onUidProcStateChanged(int uid, int procState) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7337 | mActiveUids.onUidProcStateChanged(uid, procState); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7338 | } |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7339 | |
| 7340 | @Override |
| 7341 | public void onUidAddedToPendingTempWhitelist(int uid, String tag) { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7342 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7343 | mPendingTempWhitelist.put(uid, tag); |
| 7344 | } |
| 7345 | } |
| 7346 | |
| 7347 | @Override |
| 7348 | public void onUidRemovedFromPendingTempWhitelist(int uid) { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7349 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7350 | mPendingTempWhitelist.remove(uid); |
| 7351 | } |
| 7352 | } |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 7353 | |
| 7354 | @Override |
| 7355 | public boolean handleAppCrashInActivityController(String processName, int pid, |
| 7356 | String shortMsg, String longMsg, long timeMillis, String stackTrace, |
| 7357 | Runnable killCrashingAppCallback) { |
| 7358 | synchronized (mGlobalLock) { |
| 7359 | if (mController == null) { |
| 7360 | return false; |
| 7361 | } |
| 7362 | |
| 7363 | try { |
| 7364 | if (!mController.appCrashed(processName, pid, shortMsg, longMsg, timeMillis, |
| 7365 | stackTrace)) { |
| 7366 | killCrashingAppCallback.run(); |
| 7367 | return true; |
| 7368 | } |
| 7369 | } catch (RemoteException e) { |
| 7370 | mController = null; |
| 7371 | Watchdog.getInstance().setActivityController(null); |
| 7372 | } |
| 7373 | return false; |
| 7374 | } |
| 7375 | } |
Wale Ogunwale | d7889f5 | 2018-10-25 11:03:20 -0700 | [diff] [blame] | 7376 | |
| 7377 | @Override |
| 7378 | public void removeRecentTasksByPackageName(String packageName, int userId) { |
| 7379 | synchronized (mGlobalLock) { |
| 7380 | mRecentTasks.removeTasksByPackageName(packageName, userId); |
| 7381 | } |
| 7382 | } |
| 7383 | |
| 7384 | @Override |
| 7385 | public void cleanupRecentTasksForUser(int userId) { |
| 7386 | synchronized (mGlobalLock) { |
| 7387 | mRecentTasks.cleanupLocked(userId); |
| 7388 | } |
| 7389 | } |
| 7390 | |
| 7391 | @Override |
| 7392 | public void loadRecentTasksForUser(int userId) { |
| 7393 | synchronized (mGlobalLock) { |
| 7394 | mRecentTasks.loadUserRecentsLocked(userId); |
| 7395 | } |
| 7396 | } |
| 7397 | |
| 7398 | @Override |
| 7399 | public void onPackagesSuspendedChanged(String[] packages, boolean suspended, int userId) { |
| 7400 | synchronized (mGlobalLock) { |
| 7401 | mRecentTasks.onPackagesSuspendedChanged(packages, suspended, userId); |
| 7402 | } |
| 7403 | } |
| 7404 | |
| 7405 | @Override |
| 7406 | public void flushRecentTasks() { |
| 7407 | mRecentTasks.flush(); |
| 7408 | } |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 7409 | |
| 7410 | @Override |
| 7411 | public WindowProcessController getHomeProcess() { |
| 7412 | synchronized (mGlobalLock) { |
| 7413 | return mHomeProcess; |
| 7414 | } |
| 7415 | } |
| 7416 | |
| 7417 | @Override |
| 7418 | public WindowProcessController getPreviousProcess() { |
| 7419 | synchronized (mGlobalLock) { |
| 7420 | return mPreviousProcess; |
| 7421 | } |
| 7422 | } |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 7423 | |
| 7424 | @Override |
| 7425 | public void clearLockedTasks(String reason) { |
| 7426 | synchronized (mGlobalLock) { |
| 7427 | getLockTaskController().clearLockedTasks(reason); |
| 7428 | } |
| 7429 | } |
| 7430 | |
| 7431 | @Override |
| 7432 | public void updateUserConfiguration() { |
| 7433 | synchronized (mGlobalLock) { |
| 7434 | final Configuration configuration = new Configuration(getGlobalConfiguration()); |
| 7435 | final int currentUserId = mAmInternal.getCurrentUserId(); |
| 7436 | Settings.System.adjustConfigurationForUser(mContext.getContentResolver(), |
| 7437 | configuration, currentUserId, Settings.System.canWrite(mContext)); |
| 7438 | updateConfigurationLocked(configuration, null /* starting */, |
| 7439 | false /* initLocale */, false /* persistent */, currentUserId, |
| 7440 | false /* deferResume */); |
| 7441 | } |
| 7442 | } |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 7443 | |
| 7444 | @Override |
| 7445 | public boolean canShowErrorDialogs() { |
| 7446 | synchronized (mGlobalLock) { |
| 7447 | return mShowDialogs && !mSleeping && !mShuttingDown |
| 7448 | && !mKeyguardController.isKeyguardOrAodShowing(DEFAULT_DISPLAY) |
| 7449 | && !hasUserRestriction(UserManager.DISALLOW_SYSTEM_ERROR_DIALOGS, |
| 7450 | mAmInternal.getCurrentUserId()) |
| 7451 | && !(UserManager.isDeviceInDemoMode(mContext) |
| 7452 | && mAmInternal.getCurrentUser().isDemo()); |
| 7453 | } |
| 7454 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 7455 | |
| 7456 | @Override |
| 7457 | public void setProfileApp(String profileApp) { |
| 7458 | synchronized (mGlobalLock) { |
| 7459 | mProfileApp = profileApp; |
| 7460 | } |
| 7461 | } |
| 7462 | |
| 7463 | @Override |
| 7464 | public void setProfileProc(WindowProcessController wpc) { |
| 7465 | synchronized (mGlobalLock) { |
| 7466 | mProfileProc = wpc; |
| 7467 | } |
| 7468 | } |
| 7469 | |
| 7470 | @Override |
| 7471 | public void setProfilerInfo(ProfilerInfo profilerInfo) { |
| 7472 | synchronized (mGlobalLock) { |
| 7473 | mProfilerInfo = profilerInfo; |
| 7474 | } |
| 7475 | } |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 7476 | |
| 7477 | @Override |
| 7478 | public ActivityMetricsLaunchObserverRegistry getLaunchObserverRegistry() { |
| 7479 | synchronized (mGlobalLock) { |
| 7480 | return mStackSupervisor.getActivityMetricsLogger().getLaunchObserverRegistry(); |
| 7481 | } |
| 7482 | } |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 7483 | |
| 7484 | @Override |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 7485 | public ActivityManager.TaskSnapshot getTaskSnapshotNoRestore(int taskId, |
| 7486 | boolean reducedResolution) { |
| 7487 | return ActivityTaskManagerService.this.getTaskSnapshot(taskId, reducedResolution, |
| 7488 | false /* restoreFromDisk */); |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 7489 | } |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 7490 | |
| 7491 | @Override |
| 7492 | public boolean isUidForeground(int uid) { |
| 7493 | synchronized (mGlobalLock) { |
| 7494 | return ActivityTaskManagerService.this.isUidForeground(uid); |
| 7495 | } |
| 7496 | } |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7497 | |
| 7498 | @Override |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 7499 | public void setDeviceOwnerUid(int uid) { |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7500 | synchronized (mGlobalLock) { |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 7501 | ActivityTaskManagerService.this.setDeviceOwnerUid(uid); |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7502 | } |
| 7503 | } |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7504 | |
| 7505 | @Override |
| 7506 | public void setCompanionAppPackages(int userId, Set<String> companionAppPackages) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7507 | // Translate package names into UIDs |
| 7508 | final Set<Integer> result = new HashSet<>(); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7509 | for (String pkg : companionAppPackages) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7510 | final int uid = getPackageManagerInternalLocked().getPackageUid(pkg, 0, userId); |
| 7511 | if (uid >= 0) { |
| 7512 | result.add(uid); |
| 7513 | } |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7514 | } |
| 7515 | synchronized (mGlobalLock) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7516 | mCompanionAppUidsMap.put(userId, result); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7517 | } |
| 7518 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 7519 | } |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 7520 | } |