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; |
Galia Peycheva | 45f48d3 | 2020-02-20 15:39:10 +0100 | [diff] [blame] | 34 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_DREAM; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 35 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 36 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 37 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 38 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
| 39 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 40 | import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 41 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 42 | import static android.content.pm.ApplicationInfo.FLAG_FACTORY_TEST; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 43 | import static android.content.pm.ConfigurationInfo.GL_ES_VERSION_UNDEFINED; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 44 | import static android.content.pm.PackageManager.FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS; |
Sergey Nikolaienkov | 30c947d | 2020-04-15 19:55:48 +0200 | [diff] [blame] | 45 | import static android.content.pm.PackageManager.FEATURE_CANT_SAVE_STATE; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 46 | import static android.content.pm.PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT; |
Sergey Nikolaienkov | 30c947d | 2020-04-15 19:55:48 +0200 | [diff] [blame] | 47 | import static android.content.pm.PackageManager.FEATURE_LEANBACK; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 48 | import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 49 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 50 | import static android.os.FactoryTest.FACTORY_TEST_HIGH_LEVEL; |
| 51 | import static android.os.FactoryTest.FACTORY_TEST_LOW_LEVEL; |
| 52 | import static android.os.FactoryTest.FACTORY_TEST_OFF; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 53 | import static android.os.Process.FIRST_APPLICATION_UID; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 54 | import static android.os.Process.SYSTEM_UID; |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 55 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 56 | import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 57 | import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_SIZECOMPAT_FREEFORM; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 58 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES; |
| 59 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RTL; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 60 | import static android.provider.Settings.Global.HIDE_ERROR_DIALOGS; |
| 61 | import static android.provider.Settings.System.FONT_SCALE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 62 | import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_APPLICATION; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 63 | import static android.text.format.DateUtils.MINUTE_IN_MILLIS; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 64 | import static android.view.Display.DEFAULT_DISPLAY; |
| 65 | import static android.view.Display.INVALID_DISPLAY; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 66 | import static android.view.WindowManager.TRANSIT_NONE; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 67 | |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 68 | import static com.android.server.am.ActivityManagerService.ANR_TRACE_DIR; |
| 69 | import static com.android.server.am.ActivityManagerService.MY_PID; |
| 70 | import static com.android.server.am.ActivityManagerService.STOCK_PM_FLAGS; |
| 71 | import static com.android.server.am.ActivityManagerService.dumpStackTraces; |
Wale Ogunwale | f342f06 | 2020-01-27 07:34:13 -0800 | [diff] [blame] | 72 | import static com.android.server.am.ActivityManagerServiceDumpActivitiesProto.ROOT_WINDOW_CONTAINER; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 73 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CONFIG_WILL_CHANGE; |
| 74 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CONTROLLER; |
| 75 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CURRENT_TRACKER; |
| 76 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.Controller.IS_A_MONKEY; |
| 77 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.GLOBAL_CONFIGURATION; |
| 78 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.GOING_TO_SLEEP; |
| 79 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HEAVY_WEIGHT_PROC; |
| 80 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HOME_PROC; |
| 81 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.LAUNCHING_ACTIVITY; |
| 82 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 83 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC_VISIBLE_TIME_MS; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 84 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.SCREEN_COMPAT_PACKAGES; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 85 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.MODE; |
| 86 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.PACKAGE; |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 87 | import static com.android.server.am.EventLogTags.writeBootProgressEnableScreen; |
| 88 | import static com.android.server.am.EventLogTags.writeConfigurationChanged; |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 89 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; |
| 90 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 91 | import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 92 | import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; |
| 93 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
| 94 | import static com.android.server.wm.ActivityStackSupervisor.REMOVE_FROM_RECENTS; |
| 95 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL; |
| 96 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONFIGURATION; |
| 97 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_FOCUS; |
| 98 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_IMMERSIVE; |
| 99 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_LOCKTASK; |
| 100 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STACK; |
| 101 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; |
| 102 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 103 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_VISIBILITY; |
| 104 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFIGURATION; |
| 105 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_FOCUS; |
| 106 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_IMMERSIVE; |
| 107 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_LOCKTASK; |
| 108 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; |
| 109 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; |
| 110 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_VISIBILITY; |
| 111 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 112 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 113 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_CONTENT; |
| 114 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_DATA; |
| 115 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_RECEIVER_EXTRAS; |
| 116 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_STRUCTURE; |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 117 | import static com.android.server.wm.ActivityTaskManagerService.H.REPORT_TIME_TRACKER_MSG; |
| 118 | import static com.android.server.wm.ActivityTaskManagerService.UiHandler.DISMISS_DIALOG_UI_MSG; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 119 | import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; |
| 120 | import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 121 | import static com.android.server.wm.RootWindowContainer.MATCH_TASK_IN_STACKS_ONLY; |
| 122 | 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] | 123 | import static com.android.server.wm.Task.LOCK_TASK_AUTH_DONT_LOCK; |
| 124 | import static com.android.server.wm.Task.REPARENT_KEEP_STACK_AT_FRONT; |
| 125 | import static com.android.server.wm.Task.REPARENT_LEAVE_STACK_IN_PLACE; |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 126 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 127 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 128 | import android.Manifest; |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 129 | import android.annotation.IntDef; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 130 | import android.annotation.NonNull; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 131 | import android.annotation.Nullable; |
| 132 | import android.annotation.UserIdInt; |
| 133 | import android.app.Activity; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 134 | import android.app.ActivityManager; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 135 | import android.app.ActivityManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 136 | import android.app.ActivityOptions; |
| 137 | import android.app.ActivityTaskManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 138 | import android.app.ActivityThread; |
| 139 | import android.app.AlertDialog; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 140 | import android.app.AppGlobals; |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 141 | import android.app.AppOpsManager; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 142 | import android.app.Dialog; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 143 | import android.app.IActivityController; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 144 | import android.app.IActivityTaskManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 145 | import android.app.IApplicationThread; |
| 146 | import android.app.IAssistDataReceiver; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 147 | import android.app.INotificationManager; |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 148 | import android.app.IRequestFinishCallback; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 149 | import android.app.ITaskStackListener; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 150 | import android.app.Notification; |
| 151 | import android.app.NotificationManager; |
| 152 | import android.app.PendingIntent; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 153 | import android.app.PictureInPictureParams; |
| 154 | import android.app.ProfilerInfo; |
| 155 | import android.app.RemoteAction; |
| 156 | import android.app.WaitResult; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 157 | import android.app.WindowConfiguration; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 158 | import android.app.admin.DevicePolicyCache; |
| 159 | import android.app.assist.AssistContent; |
| 160 | import android.app.assist.AssistStructure; |
jorgegil@google.com | 06bc323 | 2019-10-31 14:51:22 -0700 | [diff] [blame] | 161 | import android.app.servertransaction.ClientTransaction; |
| 162 | import android.app.servertransaction.EnterPipRequestedItem; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 163 | import android.app.usage.UsageStatsManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 164 | import android.content.ActivityNotFoundException; |
| 165 | import android.content.ComponentName; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 166 | import android.content.ContentResolver; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 167 | import android.content.Context; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 168 | import android.content.DialogInterface; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 169 | import android.content.IIntentSender; |
| 170 | import android.content.Intent; |
| 171 | import android.content.pm.ActivityInfo; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 172 | import android.content.pm.ApplicationInfo; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 173 | import android.content.pm.ConfigurationInfo; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 174 | import android.content.pm.IPackageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 175 | import android.content.pm.PackageManager; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 176 | import android.content.pm.PackageManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 177 | import android.content.pm.ParceledListSlice; |
| 178 | import android.content.pm.ResolveInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 179 | import android.content.res.CompatibilityInfo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 180 | import android.content.res.Configuration; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 181 | import android.content.res.Resources; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 182 | import android.database.ContentObserver; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 183 | import android.graphics.Bitmap; |
| 184 | import android.graphics.Point; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 185 | import android.graphics.Rect; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 186 | import android.metrics.LogMaker; |
| 187 | import android.net.Uri; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 188 | import android.os.Binder; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 189 | import android.os.Build; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 190 | import android.os.Bundle; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 191 | import android.os.FactoryTest; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 192 | import android.os.FileUtils; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 193 | import android.os.Handler; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 194 | import android.os.IBinder; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 195 | import android.os.IUserManager; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 196 | import android.os.LocaleList; |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 197 | import android.os.Looper; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 198 | import android.os.Message; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 199 | import android.os.PersistableBundle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 200 | import android.os.PowerManager; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 201 | import android.os.PowerManagerInternal; |
Marvin Ramin | 830d4e3 | 2019-03-12 13:16:58 +0100 | [diff] [blame] | 202 | import android.os.Process; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 203 | import android.os.RemoteException; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 204 | import android.os.ServiceManager; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 205 | import android.os.StrictMode; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 206 | import android.os.SystemClock; |
| 207 | import android.os.SystemProperties; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 208 | import android.os.Trace; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 209 | import android.os.UpdateLock; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 210 | import android.os.UserHandle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 211 | import android.os.UserManager; |
| 212 | import android.os.WorkSource; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 213 | import android.os.storage.IStorageManager; |
| 214 | import android.os.storage.StorageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 215 | import android.provider.Settings; |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 216 | import android.service.dreams.DreamActivity; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 217 | import android.service.voice.IVoiceInteractionSession; |
| 218 | import android.service.voice.VoiceInteractionManagerInternal; |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 219 | import android.sysprop.DisplayProperties; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 220 | import android.telecom.TelecomManager; |
| 221 | import android.text.TextUtils; |
Neil Fuller | 9774681 | 2019-08-19 14:20:50 +0100 | [diff] [blame] | 222 | import android.text.format.TimeMigrationUtils; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 223 | import android.util.ArrayMap; |
Nicholas Sauer | 3f9249f | 2019-09-10 20:23:41 -0700 | [diff] [blame] | 224 | import android.util.ArraySet; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 225 | import android.util.Log; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 226 | import android.util.Slog; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 227 | import android.util.SparseArray; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 228 | import android.util.TimeUtils; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 229 | import android.util.proto.ProtoOutputStream; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 230 | import android.view.IRecentsAnimationRunner; |
| 231 | import android.view.RemoteAnimationAdapter; |
| 232 | import android.view.RemoteAnimationDefinition; |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 233 | import android.view.WindowManager; |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 234 | import android.window.IWindowOrganizerController; |
Wale Ogunwale | 5794658 | 2020-03-21 14:29:07 -0700 | [diff] [blame] | 235 | import android.window.WindowContainerTransaction; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 236 | |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 237 | import com.android.internal.R; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 238 | import com.android.internal.annotations.VisibleForTesting; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 239 | import com.android.internal.app.AssistUtils; |
| 240 | import com.android.internal.app.IVoiceInteractor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 241 | import com.android.internal.app.ProcessMap; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 242 | import com.android.internal.logging.MetricsLogger; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 243 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 244 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
| 245 | import com.android.internal.notification.SystemNotificationChannels; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 246 | import com.android.internal.os.TransferPipe; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 247 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 248 | import com.android.internal.policy.IKeyguardDismissCallback; |
| 249 | import com.android.internal.policy.KeyguardDismissCallback; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 250 | import com.android.internal.util.ArrayUtils; |
| 251 | import com.android.internal.util.FastPrintWriter; |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 252 | import com.android.internal.util.FrameworkStatsLog; |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 253 | import com.android.internal.util.function.pooled.PooledConsumer; |
| 254 | import com.android.internal.util.function.pooled.PooledFunction; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 255 | import com.android.internal.util.function.pooled.PooledLambda; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 256 | import com.android.server.AttributeCache; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 257 | import com.android.server.LocalServices; |
| 258 | import com.android.server.SystemService; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 259 | import com.android.server.SystemServiceManager; |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 260 | import com.android.server.UiThread; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 261 | import com.android.server.Watchdog; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 262 | import com.android.server.am.ActivityManagerService; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 263 | import com.android.server.am.ActivityManagerServiceDumpProcessesProto; |
| 264 | import com.android.server.am.AppTimeTracker; |
| 265 | import com.android.server.am.BaseErrorDialog; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 266 | import com.android.server.am.PendingIntentController; |
| 267 | import com.android.server.am.PendingIntentRecord; |
| 268 | import com.android.server.am.UserState; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 269 | import com.android.server.firewall.IntentFirewall; |
Tarandeep Singh | 07b318b | 2019-07-17 11:12:04 -0700 | [diff] [blame] | 270 | import com.android.server.inputmethod.InputMethodSystemProperty; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 271 | import com.android.server.pm.UserManagerService; |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 272 | import com.android.server.policy.PermissionPolicyInternal; |
Jeff Sharkey | 307ea7a | 2020-04-13 10:24:49 -0600 | [diff] [blame] | 273 | import com.android.server.uri.NeededUriGrants; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 274 | import com.android.server.uri.UriGrantsManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 275 | import com.android.server.vr.VrManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 276 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 277 | import java.io.BufferedReader; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 278 | import java.io.File; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 279 | import java.io.FileDescriptor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 280 | import java.io.FileOutputStream; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 281 | import java.io.FileReader; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 282 | import java.io.IOException; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 283 | import java.io.PrintWriter; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 284 | import java.io.StringWriter; |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 285 | import java.lang.annotation.ElementType; |
| 286 | import java.lang.annotation.Retention; |
| 287 | import java.lang.annotation.RetentionPolicy; |
| 288 | import java.lang.annotation.Target; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 289 | import java.lang.ref.WeakReference; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 290 | import java.text.DateFormat; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 291 | import java.util.ArrayList; |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 292 | import java.util.Arrays; |
Jeff Sharkey | 8b0cff7 | 2020-03-09 15:49:01 -0600 | [diff] [blame] | 293 | import java.util.Collection; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 294 | import java.util.Date; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 295 | import java.util.HashMap; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 296 | import java.util.HashSet; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 297 | import java.util.List; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 298 | import java.util.Locale; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 299 | import java.util.Map; |
Daulet Zhanguzin | c6c641f | 2020-01-02 17:18:30 +0000 | [diff] [blame] | 300 | import java.util.Objects; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 301 | import java.util.Set; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 302 | |
| 303 | /** |
| 304 | * System service for managing activities and their containers (task, stacks, displays,... ). |
| 305 | * |
| 306 | * {@hide} |
| 307 | */ |
| 308 | public class ActivityTaskManagerService extends IActivityTaskManager.Stub { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 309 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityTaskManagerService" : TAG_ATM; |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 310 | static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 311 | static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 312 | private static final String TAG_IMMERSIVE = TAG + POSTFIX_IMMERSIVE; |
| 313 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
| 314 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
| 315 | private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 316 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 317 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 318 | // How long we wait until we timeout on key dispatching. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 319 | public static final int KEY_DISPATCHING_TIMEOUT_MS = 5 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 320 | // How long we wait until we timeout on key dispatching during instrumentation. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 321 | static final int INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT_MS = 60 * 1000; |
Michal Karpinski | fc6872e | 2019-05-21 15:18:44 +0100 | [diff] [blame] | 322 | // How long we permit background activity starts after an activity in the process |
| 323 | // started or finished. |
| 324 | static final long ACTIVITY_BG_START_GRACE_PERIOD_MS = 10 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 325 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 326 | /** Used to indicate that an app transition should be animated. */ |
| 327 | static final boolean ANIMATE = true; |
| 328 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 329 | /** Hardware-reported OpenGLES version. */ |
| 330 | final int GL_ES_VERSION; |
| 331 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 332 | public static final String DUMP_ACTIVITIES_CMD = "activities" ; |
| 333 | public static final String DUMP_ACTIVITIES_SHORT_CMD = "a" ; |
| 334 | public static final String DUMP_LASTANR_CMD = "lastanr" ; |
| 335 | public static final String DUMP_LASTANR_TRACES_CMD = "lastanr-traces" ; |
| 336 | public static final String DUMP_STARTER_CMD = "starter" ; |
| 337 | public static final String DUMP_CONTAINERS_CMD = "containers" ; |
| 338 | public static final String DUMP_RECENTS_CMD = "recents" ; |
| 339 | public static final String DUMP_RECENTS_SHORT_CMD = "r" ; |
| 340 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 341 | /** This activity is not being relaunched, or being relaunched for a non-resize reason. */ |
| 342 | public static final int RELAUNCH_REASON_NONE = 0; |
| 343 | /** This activity is being relaunched due to windowing mode change. */ |
| 344 | public static final int RELAUNCH_REASON_WINDOWING_MODE_RESIZE = 1; |
| 345 | /** This activity is being relaunched due to a free-resize operation. */ |
| 346 | public static final int RELAUNCH_REASON_FREE_RESIZE = 2; |
| 347 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 348 | Context mContext; |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 349 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 350 | /** |
| 351 | * This Context is themable and meant for UI display (AlertDialogs, etc.). The theme can |
| 352 | * change at runtime. Use mContext for non-UI purposes. |
| 353 | */ |
| 354 | final Context mUiContext; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 355 | final ActivityThread mSystemThread; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 356 | H mH; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 357 | UiHandler mUiHandler; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 358 | ActivityManagerInternal mAmInternal; |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 359 | UriGrantsManagerInternal mUgmInternal; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 360 | private PackageManagerInternal mPmInternal; |
Darryl L Johnson | a098222 | 2020-02-18 18:21:51 -0800 | [diff] [blame] | 361 | /** The cached sys ui service component name from package manager. */ |
| 362 | private ComponentName mSysUiServiceComponent; |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 363 | private PermissionPolicyInternal mPermissionPolicyInternal; |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 364 | @VisibleForTesting |
| 365 | final ActivityTaskManagerInternal mInternal; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 366 | PowerManagerInternal mPowerManagerInternal; |
| 367 | private UsageStatsManagerInternal mUsageStatsInternal; |
| 368 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 369 | PendingIntentController mPendingIntentController; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 370 | IntentFirewall mIntentFirewall; |
| 371 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 372 | /* Global service lock used by the package the owns this service. */ |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 373 | final WindowManagerGlobalLock mGlobalLock = new WindowManagerGlobalLock(); |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 374 | /** |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 375 | * 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] | 376 | * locked-region-code-injection does't recognize it. It is used to skip wrapping priority |
| 377 | * booster for places that are already in the scope of another booster (e.g. computing oom-adj). |
| 378 | * |
| 379 | * @see WindowManagerThreadPriorityBooster |
| 380 | */ |
| 381 | final Object mGlobalLockWithoutBoost = mGlobalLock; |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 382 | ActivityStackSupervisor mStackSupervisor; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 383 | RootWindowContainer mRootWindowContainer; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 384 | WindowManagerService mWindowManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 385 | private UserManagerService mUserManager; |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 386 | private AppOpsManager mAppOpsManager; |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 387 | /** All active uids in the system. */ |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 388 | private final MirrorActiveUids mActiveUids = new MirrorActiveUids(); |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 389 | private final SparseArray<String> mPendingTempWhitelist = new SparseArray<>(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 390 | /** All processes currently running that might have a window organized by name. */ |
| 391 | final ProcessMap<WindowProcessController> mProcessNames = new ProcessMap<>(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 392 | /** All processes we currently have running mapped by pid and uid */ |
| 393 | final WindowProcessControllerMap mProcessMap = new WindowProcessControllerMap(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 394 | /** This is the process holding what we currently consider to be the "home" activity. */ |
| 395 | WindowProcessController mHomeProcess; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 396 | /** The currently running heavy-weight process, if any. */ |
| 397 | WindowProcessController mHeavyWeightProcess = null; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 398 | boolean mHasHeavyWeightFeature; |
Sergey Nikolaienkov | 30c947d | 2020-04-15 19:55:48 +0200 | [diff] [blame] | 399 | boolean mHasLeanbackFeature; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 400 | /** |
| 401 | * This is the process holding the activity the user last visited that is in a different process |
| 402 | * from the one they are currently in. |
| 403 | */ |
| 404 | WindowProcessController mPreviousProcess; |
| 405 | /** The time at which the previous process was last visible. */ |
| 406 | long mPreviousProcessVisibleTime; |
| 407 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 408 | /** List of intents that were used to start the most recent tasks. */ |
| 409 | private RecentTasks mRecentTasks; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 410 | /** State of external calls telling us if the device is awake or asleep. */ |
| 411 | private boolean mKeyguardShown = false; |
| 412 | |
| 413 | // Wrapper around VoiceInteractionServiceManager |
| 414 | private AssistUtils mAssistUtils; |
| 415 | |
| 416 | // VoiceInteraction session ID that changes for each new request except when |
| 417 | // being called for multi-window assist in a single session. |
| 418 | private int mViSessionId = 1000; |
| 419 | |
| 420 | // How long to wait in getAssistContextExtras for the activity and foreground services |
| 421 | // to respond with the result. |
| 422 | private static final int PENDING_ASSIST_EXTRAS_TIMEOUT = 500; |
| 423 | |
| 424 | // How long top wait when going through the modern assist (which doesn't need to block |
| 425 | // on getting this result before starting to launch its UI). |
| 426 | private static final int PENDING_ASSIST_EXTRAS_LONG_TIMEOUT = 2000; |
| 427 | |
| 428 | // How long to wait in getAutofillAssistStructure() for the activity to respond with the result. |
| 429 | private static final int PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT = 2000; |
| 430 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 431 | // Permission tokens are used to temporarily granted a trusted app the ability to call |
| 432 | // #startActivityAsCaller. A client is expected to dump its token after this time has elapsed, |
| 433 | // showing any appropriate error messages to the user. |
| 434 | private static final long START_AS_CALLER_TOKEN_TIMEOUT = |
| 435 | 10 * MINUTE_IN_MILLIS; |
| 436 | |
| 437 | // How long before the service actually expires a token. This is slightly longer than |
| 438 | // START_AS_CALLER_TOKEN_TIMEOUT, to provide a buffer so clients will rarely encounter the |
| 439 | // expiration exception. |
| 440 | private static final long START_AS_CALLER_TOKEN_TIMEOUT_IMPL = |
| 441 | START_AS_CALLER_TOKEN_TIMEOUT + 2 * 1000; |
| 442 | |
| 443 | // How long the service will remember expired tokens, for the purpose of providing error |
| 444 | // messaging when a client uses an expired token. |
| 445 | private static final long START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT = |
| 446 | START_AS_CALLER_TOKEN_TIMEOUT_IMPL + 20 * MINUTE_IN_MILLIS; |
| 447 | |
| 448 | // Activity tokens of system activities that are delegating their call to |
| 449 | // #startActivityByCaller, keyed by the permissionToken granted to the delegate. |
| 450 | final HashMap<IBinder, IBinder> mStartActivitySources = new HashMap<>(); |
| 451 | |
| 452 | // Permission tokens that have expired, but we remember for error reporting. |
| 453 | final ArrayList<IBinder> mExpiredStartAsCallerTokens = new ArrayList<>(); |
| 454 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 455 | private final ArrayList<PendingAssistExtras> mPendingAssistExtras = new ArrayList<>(); |
| 456 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 457 | // Keeps track of the active voice interaction service component, notified from |
| 458 | // VoiceInteractionManagerService |
| 459 | ComponentName mActiveVoiceInteractionServiceComponent; |
| 460 | |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 461 | // A map userId and all its companion app uids |
| 462 | private final Map<Integer, Set<Integer>> mCompanionAppUidsMap = new ArrayMap<>(); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 463 | |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 464 | VrController mVrController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 465 | KeyguardController mKeyguardController; |
| 466 | private final ClientLifecycleManager mLifecycleManager; |
| 467 | private TaskChangeNotificationController mTaskChangeNotificationController; |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 468 | /** The controller for all operations related to locktask. */ |
| 469 | private LockTaskController mLockTaskController; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 470 | private ActivityStartController mActivityStartController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 471 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 472 | boolean mSuppressResizeConfigChanges; |
| 473 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 474 | final UpdateConfigurationResult mTmpUpdateConfigurationResult = |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 475 | new UpdateConfigurationResult(); |
| 476 | |
| 477 | static final class UpdateConfigurationResult { |
| 478 | // Configuration changes that were updated. |
| 479 | int changes; |
| 480 | // If the activity was relaunched to match the new configuration. |
| 481 | boolean activityRelaunched; |
| 482 | |
| 483 | void reset() { |
| 484 | changes = 0; |
| 485 | activityRelaunched = false; |
| 486 | } |
| 487 | } |
| 488 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 489 | /** Current sequencing integer of the configuration, for skipping old configurations. */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 490 | private int mConfigurationSeq; |
| 491 | // To cache the list of supported system locales |
| 492 | private String[] mSupportedSystemLocales = null; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 493 | |
| 494 | /** |
| 495 | * Temp object used when global and/or display override configuration is updated. It is also |
| 496 | * sent to outer world instead of {@link #getGlobalConfiguration} because we don't trust |
| 497 | * anyone... |
| 498 | */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 499 | private Configuration mTempConfig = new Configuration(); |
| 500 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 501 | /** Temporary to avoid allocations. */ |
| 502 | final StringBuilder mStringBuilder = new StringBuilder(256); |
| 503 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 504 | // Amount of time after a call to stopAppSwitches() during which we will |
| 505 | // prevent further untrusted switches from happening. |
| 506 | private static final long APP_SWITCH_DELAY_TIME = 5 * 1000; |
| 507 | |
| 508 | /** |
| 509 | * The time at which we will allow normal application switches again, |
| 510 | * after a call to {@link #stopAppSwitches()}. |
| 511 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 512 | private long mAppSwitchesAllowedTime; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 513 | /** |
| 514 | * This is set to true after the first switch after mAppSwitchesAllowedTime |
| 515 | * is set; any switches after that will clear the time. |
| 516 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 517 | private boolean mDidAppSwitch; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 518 | |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 519 | /** |
| 520 | * Last stop app switches time, apps finished before this time cannot start background activity |
| 521 | * even if they are in grace period. |
| 522 | */ |
| 523 | private long mLastStopAppSwitchesTime; |
| 524 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 525 | IActivityController mController = null; |
| 526 | boolean mControllerIsAMonkey = false; |
| 527 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 528 | final int mFactoryTest; |
| 529 | |
| 530 | /** Used to control how we initialize the service. */ |
| 531 | ComponentName mTopComponent; |
| 532 | String mTopAction = Intent.ACTION_MAIN; |
| 533 | String mTopData; |
| 534 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 535 | /** Profiling app information. */ |
| 536 | String mProfileApp = null; |
| 537 | WindowProcessController mProfileProc = null; |
| 538 | ProfilerInfo mProfilerInfo = null; |
| 539 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 540 | /** |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 541 | * Dump of the activity state at the time of the last ANR. Cleared after |
| 542 | * {@link WindowManagerService#LAST_ANR_LIFETIME_DURATION_MSECS} |
| 543 | */ |
| 544 | String mLastANRState; |
| 545 | |
| 546 | /** |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 547 | * Used to retain an update lock when the foreground activity is in |
| 548 | * immersive mode. |
| 549 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 550 | private final UpdateLock mUpdateLock = new UpdateLock("immersive"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 551 | |
| 552 | /** |
| 553 | * Packages that are being allowed to perform unrestricted app switches. Mapping is |
| 554 | * User -> Type -> uid. |
| 555 | */ |
| 556 | final SparseArray<ArrayMap<String, Integer>> mAllowAppSwitchUids = new SparseArray<>(); |
| 557 | |
| 558 | /** The dimensions of the thumbnails in the Recents UI. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 559 | private int mThumbnailWidth; |
| 560 | private int mThumbnailHeight; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 561 | |
| 562 | /** |
| 563 | * Flag that indicates if multi-window is enabled. |
| 564 | * |
| 565 | * For any particular form of multi-window to be enabled, generic multi-window must be enabled |
| 566 | * in {@link com.android.internal.R.bool#config_supportsMultiWindow} config or |
| 567 | * {@link Settings.Global#DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES} development option set. |
| 568 | * At least one of the forms of multi-window must be enabled in order for this flag to be |
| 569 | * initialized to 'true'. |
| 570 | * |
| 571 | * @see #mSupportsSplitScreenMultiWindow |
| 572 | * @see #mSupportsFreeformWindowManagement |
| 573 | * @see #mSupportsPictureInPicture |
| 574 | * @see #mSupportsMultiDisplay |
| 575 | */ |
| 576 | boolean mSupportsMultiWindow; |
| 577 | boolean mSupportsSplitScreenMultiWindow; |
| 578 | boolean mSupportsFreeformWindowManagement; |
| 579 | boolean mSupportsPictureInPicture; |
| 580 | boolean mSupportsMultiDisplay; |
| 581 | boolean mForceResizableActivities; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 582 | boolean mSizeCompatFreeform; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 583 | |
| 584 | final List<ActivityTaskManagerInternal.ScreenObserver> mScreenObservers = new ArrayList<>(); |
| 585 | |
| 586 | // VR Vr2d Display Id. |
| 587 | int mVr2dDisplayId = INVALID_DISPLAY; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 588 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 589 | /** |
| 590 | * Set while we are wanting to sleep, to prevent any |
| 591 | * activities from being started/resumed. |
| 592 | * |
| 593 | * TODO(b/33594039): Clarify the actual state transitions represented by mSleeping. |
| 594 | * |
| 595 | * Currently mSleeping is set to true when transitioning into the sleep state, and remains true |
| 596 | * while in the sleep state until there is a pending transition out of sleep, in which case |
| 597 | * mSleeping is set to false, and remains false while awake. |
| 598 | * |
| 599 | * Whether mSleeping can quickly toggled between true/false without the device actually |
| 600 | * display changing states is undefined. |
| 601 | */ |
| 602 | private boolean mSleeping = false; |
| 603 | |
| 604 | /** |
Galia Peycheva | 480275a | 2020-03-18 17:33:42 +0100 | [diff] [blame] | 605 | * The mDreaming state is set by the {@link DreamManagerService} when it receives a request to |
| 606 | * start/stop the dream. It is set to true shortly before the {@link DreamService} is started. |
| 607 | * It is set to false after the {@link DreamService} is stopped. |
| 608 | */ |
| 609 | private boolean mDreaming = false; |
| 610 | |
| 611 | /** |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 612 | * The process state used for processes that are running the top activities. |
| 613 | * This changes between TOP and TOP_SLEEPING to following mSleeping. |
| 614 | */ |
| 615 | int mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
| 616 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 617 | @Retention(RetentionPolicy.SOURCE) |
| 618 | @IntDef({ |
| 619 | LAYOUT_REASON_CONFIG_CHANGED, |
| 620 | LAYOUT_REASON_VISIBILITY_CHANGED, |
| 621 | }) |
| 622 | @interface LayoutReason {} |
| 623 | static final int LAYOUT_REASON_CONFIG_CHANGED = 0x1; |
| 624 | static final int LAYOUT_REASON_VISIBILITY_CHANGED = 0x2; |
| 625 | |
| 626 | /** The reasons to perform surface placement. */ |
| 627 | @LayoutReason |
| 628 | private int mLayoutReasons; |
| 629 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 630 | // Whether we should show our dialogs (ANR, crash, etc) or just perform their default action |
| 631 | // automatically. Important for devices without direct input devices. |
| 632 | private boolean mShowDialogs = true; |
| 633 | |
| 634 | /** Set if we are shutting down the system, similar to sleeping. */ |
| 635 | boolean mShuttingDown = false; |
| 636 | |
| 637 | /** |
| 638 | * We want to hold a wake lock while running a voice interaction session, since |
| 639 | * this may happen with the screen off and we need to keep the CPU running to |
| 640 | * be able to continue to interact with the user. |
| 641 | */ |
| 642 | PowerManager.WakeLock mVoiceWakeLock; |
| 643 | |
| 644 | /** |
| 645 | * Set while we are running a voice interaction. This overrides sleeping while it is active. |
| 646 | */ |
| 647 | IVoiceInteractionSession mRunningVoice; |
| 648 | |
| 649 | /** |
| 650 | * The last resumed activity. This is identical to the current resumed activity most |
| 651 | * of the time but could be different when we're pausing one activity before we resume |
| 652 | * another activity. |
| 653 | */ |
| 654 | ActivityRecord mLastResumedActivity; |
| 655 | |
| 656 | /** |
| 657 | * The activity that is currently being traced as the active resumed activity. |
| 658 | * |
| 659 | * @see #updateResumedAppTrace |
| 660 | */ |
| 661 | private @Nullable ActivityRecord mTracedResumedActivity; |
| 662 | |
| 663 | /** If non-null, we are tracking the time the user spends in the currently focused app. */ |
| 664 | AppTimeTracker mCurAppTimeTracker; |
| 665 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 666 | AppWarnings mAppWarnings; |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 667 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 668 | /** |
| 669 | * Packages that the user has asked to have run in screen size |
| 670 | * compatibility mode instead of filling the screen. |
| 671 | */ |
| 672 | CompatModePackages mCompatModePackages; |
| 673 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 674 | private FontScaleSettingObserver mFontScaleSettingObserver; |
| 675 | |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 676 | WindowOrganizerController mWindowOrganizerController; |
| 677 | TaskOrganizerController mTaskOrganizerController; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 678 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 679 | private int mDeviceOwnerUid = Process.INVALID_UID; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 680 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 681 | private final class FontScaleSettingObserver extends ContentObserver { |
| 682 | private final Uri mFontScaleUri = Settings.System.getUriFor(FONT_SCALE); |
| 683 | private final Uri mHideErrorDialogsUri = Settings.Global.getUriFor(HIDE_ERROR_DIALOGS); |
| 684 | |
| 685 | public FontScaleSettingObserver() { |
| 686 | super(mH); |
| 687 | final ContentResolver resolver = mContext.getContentResolver(); |
| 688 | resolver.registerContentObserver(mFontScaleUri, false, this, UserHandle.USER_ALL); |
| 689 | resolver.registerContentObserver(mHideErrorDialogsUri, false, this, |
| 690 | UserHandle.USER_ALL); |
| 691 | } |
| 692 | |
| 693 | @Override |
Jeff Sharkey | 8b0cff7 | 2020-03-09 15:49:01 -0600 | [diff] [blame] | 694 | public void onChange(boolean selfChange, Collection<Uri> uris, int flags, |
Riddle Hsu | 9c024d1 | 2020-03-09 16:10:07 +0800 | [diff] [blame] | 695 | @UserIdInt int userId) { |
| 696 | for (Uri uri : uris) { |
| 697 | if (mFontScaleUri.equals(uri)) { |
| 698 | updateFontScaleIfNeeded(userId); |
| 699 | } else if (mHideErrorDialogsUri.equals(uri)) { |
| 700 | synchronized (mGlobalLock) { |
| 701 | updateShouldShowDialogsLocked(getGlobalConfiguration()); |
| 702 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 708 | /** Indicates that the method may be invoked frequently or is sensitive to performance. */ |
| 709 | @Target(ElementType.METHOD) |
| 710 | @Retention(RetentionPolicy.SOURCE) |
| 711 | @interface HotPath { |
| 712 | int NONE = 0; |
| 713 | int OOM_ADJUSTMENT = 1; |
| 714 | int LRU_UPDATE = 2; |
| 715 | int PROCESS_CHANGE = 3; |
| 716 | int caller() default NONE; |
| 717 | } |
| 718 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 719 | private final Runnable mUpdateOomAdjRunnable = new Runnable() { |
| 720 | @Override |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 721 | public void run() { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 722 | mAmInternal.updateOomAdj(); |
| 723 | } |
| 724 | }; |
| 725 | |
Charles Chen | 8d98dd2 | 2018-12-26 17:36:54 +0800 | [diff] [blame] | 726 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 727 | public ActivityTaskManagerService(Context context) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 728 | mContext = context; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 729 | mFactoryTest = FactoryTest.getMode(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 730 | mSystemThread = ActivityThread.currentActivityThread(); |
| 731 | mUiContext = mSystemThread.getSystemUiContext(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 732 | mLifecycleManager = new ClientLifecycleManager(); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 733 | mInternal = new LocalService(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 734 | GL_ES_VERSION = SystemProperties.getInt("ro.opengles.version", GL_ES_VERSION_UNDEFINED); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 735 | mWindowOrganizerController = new WindowOrganizerController(this); |
| 736 | mTaskOrganizerController = mWindowOrganizerController.mTaskOrganizerController; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 739 | public void onSystemReady() { |
| 740 | synchronized (mGlobalLock) { |
Sergey Nikolaienkov | 30c947d | 2020-04-15 19:55:48 +0200 | [diff] [blame] | 741 | final PackageManager pm = mContext.getPackageManager(); |
| 742 | mHasHeavyWeightFeature = pm.hasSystemFeature(FEATURE_CANT_SAVE_STATE); |
| 743 | mHasLeanbackFeature = pm.hasSystemFeature(FEATURE_LEANBACK); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 744 | mAssistUtils = new AssistUtils(mContext); |
| 745 | mVrController.onSystemReady(); |
| 746 | mRecentTasks.onSystemReadyLocked(); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 747 | mStackSupervisor.onSystemReady(); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 748 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 751 | public void onInitPowerManagement() { |
| 752 | synchronized (mGlobalLock) { |
| 753 | mStackSupervisor.initPowerManagement(); |
| 754 | final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 755 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
| 756 | mVoiceWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*voice*"); |
| 757 | mVoiceWakeLock.setReferenceCounted(false); |
| 758 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 761 | public void installSystemProviders() { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 762 | mFontScaleSettingObserver = new FontScaleSettingObserver(); |
| 763 | } |
| 764 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 765 | public void retrieveSettings(ContentResolver resolver) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 766 | final boolean freeformWindowManagement = |
| 767 | mContext.getPackageManager().hasSystemFeature(FEATURE_FREEFORM_WINDOW_MANAGEMENT) |
| 768 | || Settings.Global.getInt( |
| 769 | resolver, DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0; |
| 770 | |
| 771 | final boolean supportsMultiWindow = ActivityTaskManager.supportsMultiWindow(mContext); |
| 772 | final boolean supportsPictureInPicture = supportsMultiWindow && |
| 773 | mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE); |
| 774 | final boolean supportsSplitScreenMultiWindow = |
| 775 | ActivityTaskManager.supportsSplitScreenMultiWindow(mContext); |
| 776 | final boolean supportsMultiDisplay = mContext.getPackageManager() |
| 777 | .hasSystemFeature(FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 778 | final boolean forceRtl = Settings.Global.getInt(resolver, DEVELOPMENT_FORCE_RTL, 0) != 0; |
| 779 | final boolean forceResizable = Settings.Global.getInt( |
| 780 | resolver, DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 781 | final boolean sizeCompatFreeform = Settings.Global.getInt( |
| 782 | resolver, DEVELOPMENT_ENABLE_SIZECOMPAT_FREEFORM, 0) != 0; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 783 | |
| 784 | // Transfer any global setting for forcing RTL layout, into a System Property |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 785 | DisplayProperties.debug_force_rtl(forceRtl); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 786 | |
| 787 | final Configuration configuration = new Configuration(); |
| 788 | Settings.System.getConfiguration(resolver, configuration); |
| 789 | if (forceRtl) { |
| 790 | // This will take care of setting the correct layout direction flags |
| 791 | configuration.setLayoutDirection(configuration.locale); |
| 792 | } |
| 793 | |
| 794 | synchronized (mGlobalLock) { |
| 795 | mForceResizableActivities = forceResizable; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 796 | mSizeCompatFreeform = sizeCompatFreeform; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 797 | final boolean multiWindowFormEnabled = freeformWindowManagement |
| 798 | || supportsSplitScreenMultiWindow |
| 799 | || supportsPictureInPicture |
| 800 | || supportsMultiDisplay; |
| 801 | if ((supportsMultiWindow || forceResizable) && multiWindowFormEnabled) { |
| 802 | mSupportsMultiWindow = true; |
| 803 | mSupportsFreeformWindowManagement = freeformWindowManagement; |
| 804 | mSupportsSplitScreenMultiWindow = supportsSplitScreenMultiWindow; |
| 805 | mSupportsPictureInPicture = supportsPictureInPicture; |
| 806 | mSupportsMultiDisplay = supportsMultiDisplay; |
| 807 | } else { |
| 808 | mSupportsMultiWindow = false; |
| 809 | mSupportsFreeformWindowManagement = false; |
| 810 | mSupportsSplitScreenMultiWindow = false; |
| 811 | mSupportsPictureInPicture = false; |
| 812 | mSupportsMultiDisplay = false; |
| 813 | } |
Garfield Tan | b5910b4 | 2019-03-14 14:50:59 -0700 | [diff] [blame] | 814 | mWindowManager.mRoot.onSettingsRetrieved(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 815 | // This happens before any activities are started, so we can change global configuration |
| 816 | // in-place. |
| 817 | updateConfigurationLocked(configuration, null, true); |
| 818 | final Configuration globalConfig = getGlobalConfiguration(); |
| 819 | if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Initial config: " + globalConfig); |
| 820 | |
| 821 | // Load resources only after the current configuration has been set. |
| 822 | final Resources res = mContext.getResources(); |
| 823 | mThumbnailWidth = res.getDimensionPixelSize( |
| 824 | com.android.internal.R.dimen.thumbnail_width); |
| 825 | mThumbnailHeight = res.getDimensionPixelSize( |
| 826 | com.android.internal.R.dimen.thumbnail_height); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 827 | } |
| 828 | } |
| 829 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 830 | public WindowManagerGlobalLock getGlobalLock() { |
| 831 | return mGlobalLock; |
| 832 | } |
| 833 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 834 | /** For test purpose only. */ |
| 835 | @VisibleForTesting |
| 836 | public ActivityTaskManagerInternal getAtmInternal() { |
| 837 | return mInternal; |
| 838 | } |
| 839 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 840 | public void initialize(IntentFirewall intentFirewall, PendingIntentController intentController, |
| 841 | Looper looper) { |
| 842 | mH = new H(looper); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 843 | mUiHandler = new UiHandler(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 844 | mIntentFirewall = intentFirewall; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 845 | final File systemDir = SystemServiceManager.ensureSystemDir(); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 846 | mAppWarnings = createAppWarnings(mUiContext, mH, mUiHandler, systemDir); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 847 | mCompatModePackages = new CompatModePackages(this, systemDir, mH); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 848 | mPendingIntentController = intentController; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 849 | mStackSupervisor = createStackSupervisor(); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 850 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 851 | mTaskChangeNotificationController = |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 852 | new TaskChangeNotificationController(mGlobalLock, mStackSupervisor, mH); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 853 | mLockTaskController = new LockTaskController(mContext, mStackSupervisor, mH); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 854 | mActivityStartController = new ActivityStartController(this); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 855 | setRecentTasks(new RecentTasks(this, mStackSupervisor)); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 856 | mVrController = new VrController(mGlobalLock); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 857 | mKeyguardController = mStackSupervisor.getKeyguardController(); |
| 858 | } |
| 859 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 860 | public void onActivityManagerInternalAdded() { |
| 861 | synchronized (mGlobalLock) { |
| 862 | mAmInternal = LocalServices.getService(ActivityManagerInternal.class); |
| 863 | mUgmInternal = LocalServices.getService(UriGrantsManagerInternal.class); |
| 864 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 867 | int increaseConfigurationSeqLocked() { |
| 868 | mConfigurationSeq = Math.max(++mConfigurationSeq, 1); |
| 869 | return mConfigurationSeq; |
| 870 | } |
| 871 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 872 | protected ActivityStackSupervisor createStackSupervisor() { |
| 873 | final ActivityStackSupervisor supervisor = new ActivityStackSupervisor(this, mH.getLooper()); |
| 874 | supervisor.initialize(); |
| 875 | return supervisor; |
| 876 | } |
| 877 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 878 | protected AppWarnings createAppWarnings( |
| 879 | Context uiContext, Handler handler, Handler uiHandler, File systemDir) { |
| 880 | return new AppWarnings(this, uiContext, handler, uiHandler, systemDir); |
| 881 | } |
| 882 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 883 | public void setWindowManager(WindowManagerService wm) { |
| 884 | synchronized (mGlobalLock) { |
| 885 | mWindowManager = wm; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 886 | mRootWindowContainer = wm.mRoot; |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 887 | mTempConfig.setToDefaults(); |
| 888 | mTempConfig.setLocales(LocaleList.getDefault()); |
| 889 | mConfigurationSeq = mTempConfig.seq = 1; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 890 | mRootWindowContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 891 | mLockTaskController.setWindowManager(wm); |
| 892 | mStackSupervisor.setWindowManager(wm); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 893 | mRootWindowContainer.setWindowManager(wm); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 894 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 897 | public void setUsageStatsManager(UsageStatsManagerInternal usageStatsManager) { |
| 898 | synchronized (mGlobalLock) { |
| 899 | mUsageStatsInternal = usageStatsManager; |
| 900 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 903 | UserManagerService getUserManager() { |
| 904 | if (mUserManager == null) { |
| 905 | IBinder b = ServiceManager.getService(Context.USER_SERVICE); |
| 906 | mUserManager = (UserManagerService) IUserManager.Stub.asInterface(b); |
| 907 | } |
| 908 | return mUserManager; |
| 909 | } |
| 910 | |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 911 | AppOpsManager getAppOpsManager() { |
| 912 | if (mAppOpsManager == null) { |
| 913 | mAppOpsManager = mContext.getSystemService(AppOpsManager.class); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 914 | } |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 915 | return mAppOpsManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | boolean hasUserRestriction(String restriction, int userId) { |
| 919 | return getUserManager().hasUserRestriction(restriction, userId); |
| 920 | } |
| 921 | |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 922 | boolean hasSystemAlertWindowPermission(int callingUid, int callingPid, String callingPackage) { |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 923 | final int mode = getAppOpsManager().noteOpNoThrow(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, |
| 924 | callingUid, callingPackage, /* featureId */ null, ""); |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 925 | if (mode == AppOpsManager.MODE_DEFAULT) { |
| 926 | return checkPermission(Manifest.permission.SYSTEM_ALERT_WINDOW, callingPid, callingUid) |
| 927 | == PERMISSION_GRANTED; |
| 928 | } |
| 929 | return mode == AppOpsManager.MODE_ALLOWED; |
| 930 | } |
| 931 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 932 | @VisibleForTesting |
| 933 | protected void setRecentTasks(RecentTasks recentTasks) { |
| 934 | mRecentTasks = recentTasks; |
| 935 | mStackSupervisor.setRecentTasks(recentTasks); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | RecentTasks getRecentTasks() { |
| 939 | return mRecentTasks; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 940 | } |
| 941 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 942 | ClientLifecycleManager getLifecycleManager() { |
| 943 | return mLifecycleManager; |
| 944 | } |
| 945 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 946 | ActivityStartController getActivityStartController() { |
| 947 | return mActivityStartController; |
| 948 | } |
| 949 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 950 | TaskChangeNotificationController getTaskChangeNotificationController() { |
| 951 | return mTaskChangeNotificationController; |
| 952 | } |
| 953 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 954 | LockTaskController getLockTaskController() { |
| 955 | return mLockTaskController; |
| 956 | } |
| 957 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 958 | /** |
| 959 | * Return the global configuration used by the process corresponding to the input pid. This is |
| 960 | * usually the global configuration with some overrides specific to that process. |
| 961 | */ |
| 962 | Configuration getGlobalConfigurationForCallingPid() { |
| 963 | final int pid = Binder.getCallingPid(); |
Yunfan Chen | c2ff6cf | 2018-12-04 16:56:21 -0800 | [diff] [blame] | 964 | return getGlobalConfigurationForPid(pid); |
| 965 | } |
| 966 | |
| 967 | /** |
| 968 | * Return the global configuration used by the process corresponding to the given pid. |
| 969 | */ |
| 970 | Configuration getGlobalConfigurationForPid(int pid) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 971 | if (pid == MY_PID || pid < 0) { |
| 972 | return getGlobalConfiguration(); |
| 973 | } |
| 974 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 975 | final WindowProcessController app = mProcessMap.getProcess(pid); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 976 | return app != null ? app.getConfiguration() : getGlobalConfiguration(); |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | /** |
| 981 | * Return the device configuration info used by the process corresponding to the input pid. |
| 982 | * The value is consistent with the global configuration for the process. |
| 983 | */ |
| 984 | @Override |
| 985 | public ConfigurationInfo getDeviceConfigurationInfo() { |
| 986 | ConfigurationInfo config = new ConfigurationInfo(); |
| 987 | synchronized (mGlobalLock) { |
| 988 | final Configuration globalConfig = getGlobalConfigurationForCallingPid(); |
| 989 | config.reqTouchScreen = globalConfig.touchscreen; |
| 990 | config.reqKeyboardType = globalConfig.keyboard; |
| 991 | config.reqNavigation = globalConfig.navigation; |
| 992 | if (globalConfig.navigation == Configuration.NAVIGATION_DPAD |
| 993 | || globalConfig.navigation == Configuration.NAVIGATION_TRACKBALL) { |
| 994 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 995 | } |
| 996 | if (globalConfig.keyboard != Configuration.KEYBOARD_UNDEFINED |
| 997 | && globalConfig.keyboard != Configuration.KEYBOARD_NOKEYS) { |
| 998 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 999 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1000 | config.reqGlEsVersion = GL_ES_VERSION; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 1001 | } |
| 1002 | return config; |
| 1003 | } |
| 1004 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 1005 | private void start() { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1006 | LocalServices.addService(ActivityTaskManagerInternal.class, mInternal); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1009 | public static final class Lifecycle extends SystemService { |
| 1010 | private final ActivityTaskManagerService mService; |
| 1011 | |
| 1012 | public Lifecycle(Context context) { |
| 1013 | super(context); |
| 1014 | mService = new ActivityTaskManagerService(context); |
| 1015 | } |
| 1016 | |
| 1017 | @Override |
| 1018 | public void onStart() { |
| 1019 | publishBinderService(Context.ACTIVITY_TASK_SERVICE, mService); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 1020 | mService.start(); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 1023 | @Override |
| 1024 | public void onUnlockUser(int userId) { |
| 1025 | synchronized (mService.getGlobalLock()) { |
Garfield Tan | 0d407f4 | 2019-03-07 11:47:01 -0800 | [diff] [blame] | 1026 | mService.mStackSupervisor.onUserUnlocked(userId); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | @Override |
| 1031 | public void onCleanupUser(int userId) { |
| 1032 | synchronized (mService.getGlobalLock()) { |
| 1033 | mService.mStackSupervisor.mLaunchParamsPersister.onCleanupUser(userId); |
| 1034 | } |
| 1035 | } |
| 1036 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1037 | public ActivityTaskManagerService getService() { |
| 1038 | return mService; |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1043 | public final int startActivity(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1044 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1045 | String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, |
| 1046 | Bundle bOptions) { |
| 1047 | return startActivityAsUser(caller, callingPackage, callingFeatureId, intent, resolvedType, |
| 1048 | resultTo, resultWho, requestCode, startFlags, profilerInfo, bOptions, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1049 | UserHandle.getCallingUserId()); |
| 1050 | } |
| 1051 | |
| 1052 | @Override |
| 1053 | public final int startActivities(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1054 | String callingFeatureId, Intent[] intents, String[] resolvedTypes, IBinder resultTo, |
| 1055 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1056 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1057 | final String reason = "startActivities"; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1058 | enforceNotIsolatedCaller(reason); |
| 1059 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, reason); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1060 | // TODO: Switch to user app stacks here. |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 1061 | return getActivityStartController().startActivities(caller, -1, 0, -1, callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1062 | callingFeatureId, intents, resolvedTypes, resultTo, |
| 1063 | SafeActivityOptions.fromBundle(bOptions), userId, reason, |
| 1064 | null /* originatingPendingIntent */, false /* allowBackgroundActivityStart */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | @Override |
| 1068 | public int startActivityAsUser(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1069 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1070 | String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, |
| 1071 | Bundle bOptions, int userId) { |
| 1072 | return startActivityAsUser(caller, callingPackage, callingFeatureId, intent, resolvedType, |
| 1073 | resultTo, resultWho, requestCode, startFlags, profilerInfo, bOptions, userId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1074 | true /*validateIncomingUser*/); |
| 1075 | } |
| 1076 | |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1077 | private int startActivityAsUser(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1078 | @Nullable String callingFeatureId, Intent intent, String resolvedType, |
| 1079 | IBinder resultTo, String resultWho, int requestCode, int startFlags, |
| 1080 | ProfilerInfo profilerInfo, Bundle bOptions, int userId, boolean validateIncomingUser) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1081 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1082 | enforceNotIsolatedCaller("startActivityAsUser"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1083 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1084 | userId = getActivityStartController().checkTargetUser(userId, validateIncomingUser, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1085 | Binder.getCallingPid(), Binder.getCallingUid(), "startActivityAsUser"); |
| 1086 | |
| 1087 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1088 | return getActivityStartController().obtainStarter(intent, "startActivityAsUser") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1089 | .setCaller(caller) |
| 1090 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1091 | .setCallingFeatureId(callingFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1092 | .setResolvedType(resolvedType) |
| 1093 | .setResultTo(resultTo) |
| 1094 | .setResultWho(resultWho) |
| 1095 | .setRequestCode(requestCode) |
| 1096 | .setStartFlags(startFlags) |
| 1097 | .setProfilerInfo(profilerInfo) |
| 1098 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1099 | .setUserId(userId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1100 | .execute(); |
| 1101 | |
| 1102 | } |
| 1103 | |
| 1104 | @Override |
| 1105 | public int startActivityIntentSender(IApplicationThread caller, IIntentSender target, |
| 1106 | IBinder whitelistToken, Intent fillInIntent, String resolvedType, IBinder resultTo, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1107 | String resultWho, int requestCode, int flagsMask, int flagsValues, Bundle bOptions) { |
| 1108 | enforceNotIsolatedCaller("startActivityIntentSender"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1109 | // Refuse possible leaked file descriptors |
| 1110 | if (fillInIntent != null && fillInIntent.hasFileDescriptors()) { |
| 1111 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1112 | } |
| 1113 | |
| 1114 | if (!(target instanceof PendingIntentRecord)) { |
| 1115 | throw new IllegalArgumentException("Bad PendingIntent object"); |
| 1116 | } |
| 1117 | |
| 1118 | PendingIntentRecord pir = (PendingIntentRecord)target; |
| 1119 | |
| 1120 | synchronized (mGlobalLock) { |
| 1121 | // If this is coming from the currently resumed activity, it is |
| 1122 | // effectively saying that app switches are allowed at this point. |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1123 | final ActivityStack stack = getTopDisplayFocusedStack(); |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 1124 | if (stack != null && stack.mResumedActivity != null |
| 1125 | && stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1126 | mAppSwitchesAllowedTime = 0; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1127 | } |
| 1128 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1129 | return pir.sendInner(0, fillInIntent, resolvedType, whitelistToken, null, null, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1130 | resultTo, resultWho, requestCode, flagsMask, flagsValues, bOptions); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | @Override |
| 1134 | public boolean startNextMatchingActivity(IBinder callingActivity, Intent intent, |
| 1135 | Bundle bOptions) { |
| 1136 | // Refuse possible leaked file descriptors |
| 1137 | if (intent != null && intent.hasFileDescriptors()) { |
| 1138 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1139 | } |
| 1140 | SafeActivityOptions options = SafeActivityOptions.fromBundle(bOptions); |
| 1141 | |
| 1142 | synchronized (mGlobalLock) { |
| 1143 | final ActivityRecord r = ActivityRecord.isInStackLocked(callingActivity); |
| 1144 | if (r == null) { |
| 1145 | SafeActivityOptions.abort(options); |
| 1146 | return false; |
| 1147 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1148 | if (!r.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1149 | // The caller is not running... d'oh! |
| 1150 | SafeActivityOptions.abort(options); |
| 1151 | return false; |
| 1152 | } |
| 1153 | intent = new Intent(intent); |
| 1154 | // The caller is not allowed to change the data. |
| 1155 | intent.setDataAndType(r.intent.getData(), r.intent.getType()); |
| 1156 | // And we are resetting to find the next component... |
| 1157 | intent.setComponent(null); |
| 1158 | |
| 1159 | final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0); |
| 1160 | |
| 1161 | ActivityInfo aInfo = null; |
| 1162 | try { |
| 1163 | List<ResolveInfo> resolves = |
| 1164 | AppGlobals.getPackageManager().queryIntentActivities( |
| 1165 | intent, r.resolvedType, |
| 1166 | PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS, |
| 1167 | UserHandle.getCallingUserId()).getList(); |
| 1168 | |
| 1169 | // Look for the original activity in the list... |
| 1170 | final int N = resolves != null ? resolves.size() : 0; |
| 1171 | for (int i=0; i<N; i++) { |
| 1172 | ResolveInfo rInfo = resolves.get(i); |
| 1173 | if (rInfo.activityInfo.packageName.equals(r.packageName) |
| 1174 | && rInfo.activityInfo.name.equals(r.info.name)) { |
| 1175 | // We found the current one... the next matching is |
| 1176 | // after it. |
| 1177 | i++; |
| 1178 | if (i<N) { |
| 1179 | aInfo = resolves.get(i).activityInfo; |
| 1180 | } |
| 1181 | if (debug) { |
| 1182 | Slog.v(TAG, "Next matching activity: found current " + r.packageName |
| 1183 | + "/" + r.info.name); |
| 1184 | Slog.v(TAG, "Next matching activity: next is " + ((aInfo == null) |
| 1185 | ? "null" : aInfo.packageName + "/" + aInfo.name)); |
| 1186 | } |
| 1187 | break; |
| 1188 | } |
| 1189 | } |
| 1190 | } catch (RemoteException e) { |
| 1191 | } |
| 1192 | |
| 1193 | if (aInfo == null) { |
| 1194 | // Nobody who is next! |
| 1195 | SafeActivityOptions.abort(options); |
| 1196 | if (debug) Slog.d(TAG, "Next matching activity: nothing found"); |
| 1197 | return false; |
| 1198 | } |
| 1199 | |
| 1200 | intent.setComponent(new ComponentName( |
| 1201 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1202 | intent.setFlags(intent.getFlags()&~( |
| 1203 | Intent.FLAG_ACTIVITY_FORWARD_RESULT| |
| 1204 | Intent.FLAG_ACTIVITY_CLEAR_TOP| |
| 1205 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK| |
| 1206 | FLAG_ACTIVITY_NEW_TASK)); |
| 1207 | |
| 1208 | // Okay now we need to start the new activity, replacing the currently running activity. |
| 1209 | // This is a little tricky because we want to start the new one as if the current one is |
| 1210 | // finished, but not finish the current one first so that there is no flicker. |
| 1211 | // And thus... |
| 1212 | final boolean wasFinishing = r.finishing; |
| 1213 | r.finishing = true; |
| 1214 | |
| 1215 | // Propagate reply information over to the new activity. |
| 1216 | final ActivityRecord resultTo = r.resultTo; |
| 1217 | final String resultWho = r.resultWho; |
| 1218 | final int requestCode = r.requestCode; |
| 1219 | r.resultTo = null; |
| 1220 | if (resultTo != null) { |
| 1221 | resultTo.removeResultsLocked(r, resultWho, requestCode); |
| 1222 | } |
| 1223 | |
| 1224 | final long origId = Binder.clearCallingIdentity(); |
| 1225 | // TODO(b/64750076): Check if calling pid should really be -1. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1226 | final int res = getActivityStartController() |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1227 | .obtainStarter(intent, "startNextMatchingActivity") |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1228 | .setCaller(r.app.getThread()) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1229 | .setResolvedType(r.resolvedType) |
| 1230 | .setActivityInfo(aInfo) |
| 1231 | .setResultTo(resultTo != null ? resultTo.appToken : null) |
| 1232 | .setResultWho(resultWho) |
| 1233 | .setRequestCode(requestCode) |
| 1234 | .setCallingPid(-1) |
| 1235 | .setCallingUid(r.launchedFromUid) |
| 1236 | .setCallingPackage(r.launchedFromPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1237 | .setCallingFeatureId(r.launchedFromFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1238 | .setRealCallingPid(-1) |
| 1239 | .setRealCallingUid(r.launchedFromUid) |
| 1240 | .setActivityOptions(options) |
| 1241 | .execute(); |
| 1242 | Binder.restoreCallingIdentity(origId); |
| 1243 | |
| 1244 | r.finishing = wasFinishing; |
| 1245 | if (res != ActivityManager.START_SUCCESS) { |
| 1246 | return false; |
| 1247 | } |
| 1248 | return true; |
| 1249 | } |
| 1250 | } |
| 1251 | |
Galia Peycheva | ed401cc | 2020-03-19 20:28:09 +0100 | [diff] [blame] | 1252 | private void enforceCallerIsDream(String callerPackageName) { |
Galia Peycheva | 52e8922 | 2020-02-18 23:41:43 +0100 | [diff] [blame] | 1253 | final long origId = Binder.clearCallingIdentity(); |
Galia Peycheva | ed401cc | 2020-03-19 20:28:09 +0100 | [diff] [blame] | 1254 | try { |
| 1255 | if (!ActivityRecord.canLaunchDreamActivity(callerPackageName)) { |
| 1256 | throw new SecurityException("The dream activity can be started only when the device" |
| 1257 | + " is dreaming and only by the active dream package."); |
| 1258 | } |
| 1259 | } finally { |
| 1260 | Binder.restoreCallingIdentity(origId); |
Galia Peycheva | 52e8922 | 2020-02-18 23:41:43 +0100 | [diff] [blame] | 1261 | } |
Galia Peycheva | ed401cc | 2020-03-19 20:28:09 +0100 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | @Override |
| 1265 | public boolean startDreamActivity(@NonNull Intent intent) { |
| 1266 | assertPackageMatchesCallingUid(intent.getPackage()); |
| 1267 | enforceCallerIsDream(intent.getPackage()); |
Galia Peycheva | 52e8922 | 2020-02-18 23:41:43 +0100 | [diff] [blame] | 1268 | |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 1269 | final ActivityInfo a = new ActivityInfo(); |
| 1270 | a.theme = com.android.internal.R.style.Theme_Dream; |
| 1271 | a.exported = true; |
| 1272 | a.name = DreamActivity.class.getName(); |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 1273 | a.enabled = true; |
| 1274 | a.launchMode = ActivityInfo.LAUNCH_SINGLE_INSTANCE; |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 1275 | a.persistableMode = ActivityInfo.PERSIST_NEVER; |
| 1276 | a.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 1277 | a.colorMode = ActivityInfo.COLOR_MODE_DEFAULT; |
| 1278 | a.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 1279 | |
Galia Peycheva | 45f48d3 | 2020-02-20 15:39:10 +0100 | [diff] [blame] | 1280 | final ActivityOptions options = ActivityOptions.makeBasic(); |
| 1281 | options.setLaunchActivityType(ACTIVITY_TYPE_DREAM); |
| 1282 | |
Galia Peycheva | ed401cc | 2020-03-19 20:28:09 +0100 | [diff] [blame] | 1283 | synchronized (mGlobalLock) { |
| 1284 | final WindowProcessController process = mProcessMap.getProcess(Binder.getCallingPid()); |
| 1285 | |
| 1286 | a.packageName = process.mInfo.packageName; |
| 1287 | a.applicationInfo = process.mInfo; |
| 1288 | a.processName = process.mInfo.processName; |
| 1289 | a.uiOptions = process.mInfo.uiOptions; |
| 1290 | a.taskAffinity = "android:" + a.packageName + "/dream"; |
| 1291 | |
| 1292 | final int callingUid = Binder.getCallingUid(); |
| 1293 | final int callingPid = Binder.getCallingPid(); |
| 1294 | |
| 1295 | final long origId = Binder.clearCallingIdentity(); |
| 1296 | try { |
| 1297 | getActivityStartController().obtainStarter(intent, "dream") |
| 1298 | .setCallingUid(callingUid) |
| 1299 | .setCallingPid(callingPid) |
| 1300 | .setActivityInfo(a) |
| 1301 | .setActivityOptions(options.toBundle()) |
| 1302 | // To start the dream from background, we need to start it from a persistent |
| 1303 | // system process. Here we set the real calling uid to the system server uid |
| 1304 | .setRealCallingUid(Binder.getCallingUid()) |
| 1305 | .setAllowBackgroundActivityStart(true) |
| 1306 | .execute(); |
| 1307 | return true; |
| 1308 | } finally { |
| 1309 | Binder.restoreCallingIdentity(origId); |
| 1310 | } |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1315 | public final WaitResult startActivityAndWait(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1316 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1317 | String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, |
| 1318 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1319 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1320 | final WaitResult res = new WaitResult(); |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1321 | enforceNotIsolatedCaller("startActivityAndWait"); |
| 1322 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 1323 | userId, "startActivityAndWait"); |
| 1324 | // TODO: Switch to user app stacks here. |
| 1325 | getActivityStartController().obtainStarter(intent, "startActivityAndWait") |
| 1326 | .setCaller(caller) |
| 1327 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1328 | .setCallingFeatureId(callingFeatureId) |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1329 | .setResolvedType(resolvedType) |
| 1330 | .setResultTo(resultTo) |
| 1331 | .setResultWho(resultWho) |
| 1332 | .setRequestCode(requestCode) |
| 1333 | .setStartFlags(startFlags) |
| 1334 | .setActivityOptions(bOptions) |
| 1335 | .setUserId(userId) |
| 1336 | .setProfilerInfo(profilerInfo) |
| 1337 | .setWaitResult(res) |
| 1338 | .execute(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1339 | return res; |
| 1340 | } |
| 1341 | |
| 1342 | @Override |
| 1343 | public final int startActivityWithConfig(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1344 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1345 | String resultWho, int requestCode, int startFlags, Configuration config, |
| 1346 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1347 | assertPackageMatchesCallingUid(callingPackage); |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1348 | enforceNotIsolatedCaller("startActivityWithConfig"); |
| 1349 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, |
| 1350 | "startActivityWithConfig"); |
| 1351 | // TODO: Switch to user app stacks here. |
| 1352 | return getActivityStartController().obtainStarter(intent, "startActivityWithConfig") |
| 1353 | .setCaller(caller) |
| 1354 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1355 | .setCallingFeatureId(callingFeatureId) |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1356 | .setResolvedType(resolvedType) |
| 1357 | .setResultTo(resultTo) |
| 1358 | .setResultWho(resultWho) |
| 1359 | .setRequestCode(requestCode) |
| 1360 | .setStartFlags(startFlags) |
| 1361 | .setGlobalConfiguration(config) |
| 1362 | .setActivityOptions(bOptions) |
| 1363 | .setUserId(userId) |
| 1364 | .execute(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1365 | } |
| 1366 | |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 1367 | @Override |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1368 | public IBinder requestStartActivityPermissionToken(IBinder delegatorToken) { |
| 1369 | int callingUid = Binder.getCallingUid(); |
| 1370 | if (UserHandle.getAppId(callingUid) != SYSTEM_UID) { |
| 1371 | throw new SecurityException("Only the system process can request a permission token, " |
| 1372 | + "received request from uid: " + callingUid); |
| 1373 | } |
| 1374 | IBinder permissionToken = new Binder(); |
| 1375 | synchronized (mGlobalLock) { |
| 1376 | mStartActivitySources.put(permissionToken, delegatorToken); |
| 1377 | } |
| 1378 | |
| 1379 | Message expireMsg = PooledLambda.obtainMessage( |
| 1380 | ActivityTaskManagerService::expireStartAsCallerTokenMsg, this, permissionToken); |
| 1381 | mUiHandler.sendMessageDelayed(expireMsg, START_AS_CALLER_TOKEN_TIMEOUT_IMPL); |
| 1382 | |
| 1383 | Message forgetMsg = PooledLambda.obtainMessage( |
| 1384 | ActivityTaskManagerService::forgetStartAsCallerTokenMsg, this, permissionToken); |
| 1385 | mUiHandler.sendMessageDelayed(forgetMsg, START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT); |
| 1386 | |
| 1387 | return permissionToken; |
| 1388 | } |
| 1389 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1390 | @Override |
| 1391 | public final int startActivityAsCaller(IApplicationThread caller, String callingPackage, |
| 1392 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1393 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, IBinder permissionToken, |
| 1394 | boolean ignoreTargetSecurity, int userId) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1395 | // 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] | 1396 | // permission grants) as any app that may launch one of your own activities. So we only |
| 1397 | // allow this in two cases: |
| 1398 | // 1) The caller is an activity that is part of the core framework, and then only when it |
| 1399 | // is running as the system. |
| 1400 | // 2) The caller provides a valid permissionToken. Permission tokens are one-time use and |
| 1401 | // can only be requested by a system activity, which may then delegate this call to |
| 1402 | // another app. |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1403 | final ActivityRecord sourceRecord; |
| 1404 | final int targetUid; |
| 1405 | final String targetPackage; |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1406 | final String targetFeatureId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1407 | final boolean isResolver; |
| 1408 | synchronized (mGlobalLock) { |
| 1409 | if (resultTo == null) { |
| 1410 | throw new SecurityException("Must be called from an activity"); |
| 1411 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1412 | final IBinder sourceToken; |
| 1413 | if (permissionToken != null) { |
| 1414 | // To even attempt to use a permissionToken, an app must also have this signature |
| 1415 | // permission. |
| 1416 | mAmInternal.enforceCallingPermission( |
| 1417 | android.Manifest.permission.START_ACTIVITY_AS_CALLER, |
| 1418 | "startActivityAsCaller"); |
| 1419 | // If called with a permissionToken, we want the sourceRecord from the delegator |
| 1420 | // activity that requested this token. |
| 1421 | sourceToken = mStartActivitySources.remove(permissionToken); |
| 1422 | if (sourceToken == null) { |
| 1423 | // Invalid permissionToken, check if it recently expired. |
| 1424 | if (mExpiredStartAsCallerTokens.contains(permissionToken)) { |
| 1425 | throw new SecurityException("Called with expired permission token: " |
| 1426 | + permissionToken); |
| 1427 | } else { |
| 1428 | throw new SecurityException("Called with invalid permission token: " |
| 1429 | + permissionToken); |
| 1430 | } |
| 1431 | } |
| 1432 | } else { |
| 1433 | // This method was called directly by the source. |
| 1434 | sourceToken = resultTo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1435 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1436 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1437 | sourceRecord = mRootWindowContainer.isInAnyStack(sourceToken); |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1438 | if (sourceRecord == null) { |
| 1439 | throw new SecurityException("Called with bad activity token: " + sourceToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1440 | } |
| 1441 | if (sourceRecord.app == null) { |
| 1442 | throw new SecurityException("Called without a process attached to activity"); |
| 1443 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1444 | |
| 1445 | // Whether called directly or from a delegate, the source activity must be from the |
| 1446 | // android package. |
| 1447 | if (!sourceRecord.info.packageName.equals("android")) { |
| 1448 | throw new SecurityException("Must be called from an activity that is " |
| 1449 | + "declared in the android package"); |
| 1450 | } |
| 1451 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1452 | if (UserHandle.getAppId(sourceRecord.app.mUid) != SYSTEM_UID) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1453 | // This is still okay, as long as this activity is running under the |
| 1454 | // uid of the original calling activity. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1455 | if (sourceRecord.app.mUid != sourceRecord.launchedFromUid) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1456 | throw new SecurityException( |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1457 | "Calling activity in uid " + sourceRecord.app.mUid |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1458 | + " must be system uid or original calling uid " |
| 1459 | + sourceRecord.launchedFromUid); |
| 1460 | } |
| 1461 | } |
| 1462 | if (ignoreTargetSecurity) { |
| 1463 | if (intent.getComponent() == null) { |
| 1464 | throw new SecurityException( |
| 1465 | "Component must be specified with ignoreTargetSecurity"); |
| 1466 | } |
| 1467 | if (intent.getSelector() != null) { |
| 1468 | throw new SecurityException( |
| 1469 | "Selector not allowed with ignoreTargetSecurity"); |
| 1470 | } |
| 1471 | } |
| 1472 | targetUid = sourceRecord.launchedFromUid; |
| 1473 | targetPackage = sourceRecord.launchedFromPackage; |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1474 | targetFeatureId = sourceRecord.launchedFromFeatureId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1475 | isResolver = sourceRecord.isResolverOrChildActivity(); |
| 1476 | } |
| 1477 | |
| 1478 | if (userId == UserHandle.USER_NULL) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1479 | userId = UserHandle.getUserId(sourceRecord.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | // TODO: Switch to user app stacks here. |
| 1483 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1484 | return getActivityStartController().obtainStarter(intent, "startActivityAsCaller") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1485 | .setCallingUid(targetUid) |
| 1486 | .setCallingPackage(targetPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1487 | .setCallingFeatureId(targetFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1488 | .setResolvedType(resolvedType) |
| 1489 | .setResultTo(resultTo) |
| 1490 | .setResultWho(resultWho) |
| 1491 | .setRequestCode(requestCode) |
| 1492 | .setStartFlags(startFlags) |
| 1493 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1494 | .setUserId(userId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1495 | .setIgnoreTargetSecurity(ignoreTargetSecurity) |
| 1496 | .setFilterCallingUid(isResolver ? 0 /* system */ : targetUid) |
Alan Stokes | 2f4a4ed | 2019-05-08 16:56:45 +0100 | [diff] [blame] | 1497 | // The target may well be in the background, which would normally prevent it |
| 1498 | // from starting an activity. Here we definitely want the start to succeed. |
| 1499 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1500 | .execute(); |
| 1501 | } catch (SecurityException e) { |
| 1502 | // XXX need to figure out how to propagate to original app. |
| 1503 | // A SecurityException here is generally actually a fault of the original |
| 1504 | // calling activity (such as a fairly granting permissions), so propagate it |
| 1505 | // back to them. |
| 1506 | /* |
| 1507 | StringBuilder msg = new StringBuilder(); |
| 1508 | msg.append("While launching"); |
| 1509 | msg.append(intent.toString()); |
| 1510 | msg.append(": "); |
| 1511 | msg.append(e.getMessage()); |
| 1512 | */ |
| 1513 | throw e; |
| 1514 | } |
| 1515 | } |
| 1516 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1517 | int handleIncomingUser(int callingPid, int callingUid, int userId, String name) { |
| 1518 | return mAmInternal.handleIncomingUser(callingPid, callingUid, userId, false /* allowAll */, |
Jonathan Scott | 9233534 | 2019-12-17 14:46:26 +0000 | [diff] [blame] | 1519 | ALLOW_NON_FULL, name, null /* callerPackage */); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1522 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1523 | public int startVoiceActivity(String callingPackage, String callingFeatureId, int callingPid, |
| 1524 | int callingUid, Intent intent, String resolvedType, IVoiceInteractionSession session, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1525 | IVoiceInteractor interactor, int startFlags, ProfilerInfo profilerInfo, |
| 1526 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1527 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1528 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startVoiceActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1529 | if (session == null || interactor == null) { |
| 1530 | throw new NullPointerException("null session or interactor"); |
| 1531 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1532 | userId = handleIncomingUser(callingPid, callingUid, userId, "startVoiceActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1533 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1534 | return getActivityStartController().obtainStarter(intent, "startVoiceActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1535 | .setCallingUid(callingUid) |
| 1536 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1537 | .setCallingFeatureId(callingFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1538 | .setResolvedType(resolvedType) |
| 1539 | .setVoiceSession(session) |
| 1540 | .setVoiceInteractor(interactor) |
| 1541 | .setStartFlags(startFlags) |
| 1542 | .setProfilerInfo(profilerInfo) |
| 1543 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1544 | .setUserId(userId) |
Michal Karpinski | 85fa202 | 2019-02-08 12:05:09 +0000 | [diff] [blame] | 1545 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1546 | .execute(); |
| 1547 | } |
| 1548 | |
| 1549 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1550 | public int startAssistantActivity(String callingPackage, @NonNull String callingFeatureId, |
| 1551 | int callingPid, int callingUid, Intent intent, String resolvedType, Bundle bOptions, |
| 1552 | int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1553 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1554 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startAssistantActivity()"); |
| 1555 | userId = handleIncomingUser(callingPid, callingUid, userId, "startAssistantActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1556 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1557 | return getActivityStartController().obtainStarter(intent, "startAssistantActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1558 | .setCallingUid(callingUid) |
| 1559 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1560 | .setCallingFeatureId(callingFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1561 | .setResolvedType(resolvedType) |
| 1562 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1563 | .setUserId(userId) |
Michal Karpinski | 85fa202 | 2019-02-08 12:05:09 +0000 | [diff] [blame] | 1564 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1565 | .execute(); |
| 1566 | } |
| 1567 | |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1568 | /** |
| 1569 | * Start the recents activity to perform the recents animation. |
| 1570 | * |
| 1571 | * @param intent The intent to start the recents activity. |
| 1572 | * @param recentsAnimationRunner Pass {@code null} to only preload the activity. |
| 1573 | */ |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1574 | @Override |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1575 | public void startRecentsActivity(Intent intent, @Deprecated IAssistDataReceiver unused, |
| 1576 | @Nullable IRecentsAnimationRunner recentsAnimationRunner) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1577 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "startRecentsActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1578 | final int callingPid = Binder.getCallingPid(); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1579 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1580 | final long origId = Binder.clearCallingIdentity(); |
| 1581 | try { |
| 1582 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 1583 | final ComponentName recentsComponent = mRecentTasks.getRecentsComponent(); |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1584 | final String recentsFeatureId = mRecentTasks.getRecentsComponentFeatureId(); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 1585 | final int recentsUid = mRecentTasks.getRecentsComponentUid(); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1586 | final WindowProcessController caller = getProcessController(callingPid, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1587 | |
| 1588 | // Start a new recents animation |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1589 | final RecentsAnimation anim = new RecentsAnimation(this, mStackSupervisor, |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1590 | getActivityStartController(), mWindowManager, intent, recentsComponent, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1591 | recentsFeatureId, recentsUid, caller); |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1592 | if (recentsAnimationRunner == null) { |
| 1593 | anim.preloadRecentsActivity(); |
| 1594 | } else { |
| 1595 | anim.startRecentsActivity(recentsAnimationRunner); |
| 1596 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1597 | } |
| 1598 | } finally { |
| 1599 | Binder.restoreCallingIdentity(origId); |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | @Override |
| 1604 | public final int startActivityFromRecents(int taskId, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1605 | enforceCallerIsRecentsOrHasPermission(START_TASKS_FROM_RECENTS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1606 | "startActivityFromRecents()"); |
| 1607 | |
| 1608 | final int callingPid = Binder.getCallingPid(); |
| 1609 | final int callingUid = Binder.getCallingUid(); |
| 1610 | final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(bOptions); |
| 1611 | final long origId = Binder.clearCallingIdentity(); |
| 1612 | try { |
| 1613 | synchronized (mGlobalLock) { |
| 1614 | return mStackSupervisor.startActivityFromRecents(callingPid, callingUid, taskId, |
| 1615 | safeOptions); |
| 1616 | } |
| 1617 | } finally { |
| 1618 | Binder.restoreCallingIdentity(origId); |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | /** |
Andrii Kulian | 2eb84b2 | 2018-12-13 18:18:54 -0800 | [diff] [blame] | 1623 | * Public API to check if the client is allowed to start an activity on specified display. |
| 1624 | * |
| 1625 | * If the target display is private or virtual, some restrictions will apply. |
| 1626 | * |
| 1627 | * @param displayId Target display id. |
| 1628 | * @param intent Intent used to launch the activity. |
| 1629 | * @param resolvedType The MIME type of the intent. |
| 1630 | * @param userId The id of the user for whom the call is made. |
| 1631 | * @return {@code true} if a call to start an activity on the target display should succeed and |
| 1632 | * no {@link SecurityException} will be thrown, {@code false} otherwise. |
| 1633 | */ |
| 1634 | @Override |
| 1635 | public final boolean isActivityStartAllowedOnDisplay(int displayId, Intent intent, |
| 1636 | String resolvedType, int userId) { |
| 1637 | final int callingUid = Binder.getCallingUid(); |
| 1638 | final int callingPid = Binder.getCallingPid(); |
| 1639 | final long origId = Binder.clearCallingIdentity(); |
| 1640 | |
| 1641 | try { |
| 1642 | // Collect information about the target of the Intent. |
| 1643 | ActivityInfo aInfo = mStackSupervisor.resolveActivity(intent, resolvedType, |
| 1644 | 0 /* startFlags */, null /* profilerInfo */, userId, |
| 1645 | ActivityStarter.computeResolveFilterUid(callingUid, callingUid, |
| 1646 | UserHandle.USER_NULL)); |
| 1647 | aInfo = mAmInternal.getActivityInfoForUser(aInfo, userId); |
| 1648 | |
| 1649 | synchronized (mGlobalLock) { |
| 1650 | return mStackSupervisor.canPlaceEntityOnDisplay(displayId, callingPid, callingUid, |
| 1651 | aInfo); |
| 1652 | } |
| 1653 | } finally { |
| 1654 | Binder.restoreCallingIdentity(origId); |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | /** |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1659 | * This is the internal entry point for handling Activity.finish(). |
| 1660 | * |
| 1661 | * @param token The Binder token referencing the Activity we want to finish. |
| 1662 | * @param resultCode Result code, if any, from this Activity. |
| 1663 | * @param resultData Result data (Intent), if any, from this Activity. |
| 1664 | * @param finishTask Whether to finish the task associated with this Activity. |
| 1665 | * |
| 1666 | * @return Returns true if the activity successfully finished, or false if it is still running. |
| 1667 | */ |
| 1668 | @Override |
| 1669 | public final boolean finishActivity(IBinder token, int resultCode, Intent resultData, |
| 1670 | int finishTask) { |
| 1671 | // Refuse possible leaked file descriptors |
| 1672 | if (resultData != null && resultData.hasFileDescriptors()) { |
| 1673 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1674 | } |
| 1675 | |
Jeff Sharkey | 307ea7a | 2020-04-13 10:24:49 -0600 | [diff] [blame] | 1676 | final ActivityRecord r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1677 | synchronized (mGlobalLock) { |
Jeff Sharkey | 307ea7a | 2020-04-13 10:24:49 -0600 | [diff] [blame] | 1678 | r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1679 | if (r == null) { |
| 1680 | return true; |
| 1681 | } |
Jeff Sharkey | 307ea7a | 2020-04-13 10:24:49 -0600 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | // Carefully collect grants without holding lock |
| 1685 | final NeededUriGrants resultGrants = collectGrants(resultData, r.resultTo); |
| 1686 | |
| 1687 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1688 | // 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] | 1689 | final Task tr = r.getTask(); |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 1690 | final ActivityRecord rootR = tr.getRootActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1691 | if (rootR == null) { |
| 1692 | Slog.w(TAG, "Finishing task with all activities already finished"); |
| 1693 | } |
| 1694 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps can |
| 1695 | // finish. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1696 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1697 | return false; |
| 1698 | } |
| 1699 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1700 | // TODO: There is a dup. of this block of code in ActivityStack.navigateUpToLocked |
| 1701 | // We should consolidate. |
| 1702 | if (mController != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1703 | // Find the first activity that is not finishing. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1704 | final ActivityRecord next = |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 1705 | r.getRootTask().topRunningActivity(token, INVALID_TASK_ID); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1706 | if (next != null) { |
| 1707 | // ask watcher if this is allowed |
| 1708 | boolean resumeOK = true; |
| 1709 | try { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1710 | resumeOK = mController.activityResuming(next.packageName); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1711 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1712 | mController = null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1713 | Watchdog.getInstance().setActivityController(null); |
| 1714 | } |
| 1715 | |
| 1716 | if (!resumeOK) { |
| 1717 | Slog.i(TAG, "Not finishing activity because controller resumed"); |
| 1718 | return false; |
| 1719 | } |
| 1720 | } |
| 1721 | } |
Michal Karpinski | fc6872e | 2019-05-21 15:18:44 +0100 | [diff] [blame] | 1722 | |
| 1723 | // note down that the process has finished an activity and is in background activity |
| 1724 | // starts grace period |
| 1725 | if (r.app != null) { |
| 1726 | r.app.setLastActivityFinishTimeIfNeeded(SystemClock.uptimeMillis()); |
| 1727 | } |
| 1728 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1729 | final long origId = Binder.clearCallingIdentity(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1730 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "finishActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1731 | try { |
| 1732 | boolean res; |
| 1733 | final boolean finishWithRootActivity = |
| 1734 | finishTask == Activity.FINISH_TASK_WITH_ROOT_ACTIVITY; |
| 1735 | if (finishTask == Activity.FINISH_TASK_WITH_ACTIVITY |
| 1736 | || (finishWithRootActivity && r == rootR)) { |
| 1737 | // If requested, remove the task that is associated to this activity only if it |
| 1738 | // was the root activity in the task. The result code and data is ignored |
| 1739 | // because we don't support returning them across task boundaries. Also, to |
| 1740 | // keep backwards compatibility we remove the task from recents when finishing |
| 1741 | // task with root activity. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1742 | mStackSupervisor.removeTask(tr, false /*killProcess*/, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1743 | finishWithRootActivity, "finish-activity"); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1744 | res = true; |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 1745 | // Explicitly dismissing the activity so reset its relaunch flag. |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 1746 | r.mRelaunchReason = RELAUNCH_REASON_NONE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1747 | } else { |
Jeff Sharkey | 307ea7a | 2020-04-13 10:24:49 -0600 | [diff] [blame] | 1748 | r.finishIfPossible(resultCode, resultData, resultGrants, |
| 1749 | "app-request", true /* oomAdj */); |
Andrii Kulian | 40eda67 | 2019-07-30 15:05:57 -0700 | [diff] [blame] | 1750 | res = r.finishing; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1751 | if (!res) { |
| 1752 | Slog.i(TAG, "Failed to finish by app-request"); |
| 1753 | } |
| 1754 | } |
| 1755 | return res; |
| 1756 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1757 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1758 | Binder.restoreCallingIdentity(origId); |
| 1759 | } |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | @Override |
| 1764 | public boolean finishActivityAffinity(IBinder token) { |
| 1765 | synchronized (mGlobalLock) { |
| 1766 | final long origId = Binder.clearCallingIdentity(); |
| 1767 | try { |
| 1768 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1769 | if (r == null) { |
| 1770 | return false; |
| 1771 | } |
| 1772 | |
| 1773 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps |
| 1774 | // can finish. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1775 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1776 | return false; |
| 1777 | } |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1778 | |
| 1779 | final PooledFunction p = PooledLambda.obtainFunction( |
| 1780 | ActivityRecord::finishIfSameAffinity, r, |
| 1781 | PooledLambda.__(ActivityRecord.class)); |
| 1782 | r.getTask().forAllActivities( |
| 1783 | p, r, true /*includeBoundary*/, true /*traverseTopToBottom*/); |
| 1784 | p.recycle(); |
| 1785 | |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 1786 | return true; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1787 | } finally { |
| 1788 | Binder.restoreCallingIdentity(origId); |
| 1789 | } |
| 1790 | } |
| 1791 | } |
| 1792 | |
| 1793 | @Override |
| 1794 | public final void activityIdle(IBinder token, Configuration config, boolean stopProfiling) { |
| 1795 | final long origId = Binder.clearCallingIdentity(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1796 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1797 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1798 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityIdle"); |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 1799 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 1800 | if (r == null) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1801 | return; |
| 1802 | } |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 1803 | mStackSupervisor.activityIdleInternal(r, false /* fromTimeout */, |
| 1804 | false /* processPausingActivities */, config); |
| 1805 | if (stopProfiling && r.hasProcess()) { |
| 1806 | r.app.clearProfilerIfNeeded(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1807 | } |
| 1808 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1809 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1810 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1811 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1812 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | @Override |
| 1816 | public final void activityResumed(IBinder token) { |
| 1817 | final long origId = Binder.clearCallingIdentity(); |
| 1818 | synchronized (mGlobalLock) { |
| 1819 | ActivityRecord.activityResumedLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1820 | } |
| 1821 | Binder.restoreCallingIdentity(origId); |
| 1822 | } |
| 1823 | |
| 1824 | @Override |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 1825 | public final void activityTopResumedStateLost() { |
| 1826 | final long origId = Binder.clearCallingIdentity(); |
| 1827 | synchronized (mGlobalLock) { |
| 1828 | mStackSupervisor.handleTopResumedStateReleased(false /* timeout */); |
| 1829 | } |
| 1830 | Binder.restoreCallingIdentity(origId); |
| 1831 | } |
| 1832 | |
| 1833 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1834 | public final void activityPaused(IBinder token) { |
| 1835 | final long origId = Binder.clearCallingIdentity(); |
| 1836 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1837 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityPaused"); |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 1838 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 1839 | if (r != null) { |
| 1840 | r.activityPaused(false); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1841 | } |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1842 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1843 | } |
| 1844 | Binder.restoreCallingIdentity(origId); |
| 1845 | } |
| 1846 | |
| 1847 | @Override |
| 1848 | public final void activityStopped(IBinder token, Bundle icicle, |
| 1849 | PersistableBundle persistentState, CharSequence description) { |
| 1850 | if (DEBUG_ALL) Slog.v(TAG, "Activity stopped: token=" + token); |
| 1851 | |
| 1852 | // Refuse possible leaked file descriptors |
| 1853 | if (icicle != null && icicle.hasFileDescriptors()) { |
| 1854 | throw new IllegalArgumentException("File descriptors passed in Bundle"); |
| 1855 | } |
| 1856 | |
| 1857 | final long origId = Binder.clearCallingIdentity(); |
| 1858 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1859 | String restartingName = null; |
| 1860 | int restartingUid = 0; |
| 1861 | final ActivityRecord r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1862 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1863 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityStopped"); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1864 | r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1865 | if (r != null) { |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1866 | if (r.attachedToProcess() |
| 1867 | && r.isState(ActivityStack.ActivityState.RESTARTING_PROCESS)) { |
| 1868 | // The activity was requested to restart from |
| 1869 | // {@link #restartActivityProcessIfVisible}. |
| 1870 | restartingName = r.app.mName; |
| 1871 | restartingUid = r.app.mUid; |
| 1872 | } |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 1873 | r.activityStopped(icicle, persistentState, description); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1874 | } |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1875 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1876 | } |
| 1877 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1878 | if (restartingName != null) { |
| 1879 | // In order to let the foreground activity can be restarted with its saved state from |
| 1880 | // {@link android.app.Activity#onSaveInstanceState}, the kill operation is postponed |
| 1881 | // until the activity reports stopped with the state. And the activity record will be |
| 1882 | // kept because the record state is restarting, then the activity will be restarted |
| 1883 | // immediately if it is still the top one. |
| 1884 | mStackSupervisor.removeRestartTimeouts(r); |
| 1885 | mAmInternal.killProcess(restartingName, restartingUid, "restartActivityProcess"); |
| 1886 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1887 | mAmInternal.trimApplications(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1888 | |
| 1889 | Binder.restoreCallingIdentity(origId); |
| 1890 | } |
| 1891 | |
| 1892 | @Override |
| 1893 | public final void activityDestroyed(IBinder token) { |
| 1894 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "ACTIVITY DESTROYED: " + token); |
| 1895 | synchronized (mGlobalLock) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1896 | final long origId = Binder.clearCallingIdentity(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1897 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityDestroyed"); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1898 | try { |
| 1899 | final ActivityRecord activity = ActivityRecord.forTokenLocked(token); |
| 1900 | if (activity != null) { |
| 1901 | activity.destroyed("activityDestroyed"); |
| 1902 | } |
| 1903 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1904 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1905 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1906 | } |
| 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | @Override |
| 1911 | public final void activityRelaunched(IBinder token) { |
| 1912 | final long origId = Binder.clearCallingIdentity(); |
| 1913 | synchronized (mGlobalLock) { |
| 1914 | mStackSupervisor.activityRelaunchedLocked(token); |
| 1915 | } |
| 1916 | Binder.restoreCallingIdentity(origId); |
| 1917 | } |
| 1918 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1919 | @Override |
| 1920 | public void setRequestedOrientation(IBinder token, int requestedOrientation) { |
| 1921 | synchronized (mGlobalLock) { |
| 1922 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1923 | if (r == null) { |
| 1924 | return; |
| 1925 | } |
| 1926 | final long origId = Binder.clearCallingIdentity(); |
| 1927 | try { |
| 1928 | r.setRequestedOrientation(requestedOrientation); |
| 1929 | } finally { |
| 1930 | Binder.restoreCallingIdentity(origId); |
| 1931 | } |
| 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | @Override |
| 1936 | public int getRequestedOrientation(IBinder token) { |
| 1937 | synchronized (mGlobalLock) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1938 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1939 | return (r != null) |
| 1940 | ? r.getRequestedOrientation() : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | @Override |
| 1945 | public void setImmersive(IBinder token, boolean immersive) { |
| 1946 | synchronized (mGlobalLock) { |
| 1947 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1948 | if (r == null) { |
| 1949 | throw new IllegalArgumentException(); |
| 1950 | } |
| 1951 | r.immersive = immersive; |
| 1952 | |
| 1953 | // update associated state if we're frontmost |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1954 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1955 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, "Frontmost changed immersion: "+ r); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1956 | applyUpdateLockStateLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1957 | } |
| 1958 | } |
| 1959 | } |
| 1960 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1961 | void applyUpdateLockStateLocked(ActivityRecord r) { |
| 1962 | // Modifications to the UpdateLock state are done on our handler, outside |
| 1963 | // the activity manager's locks. The new state is determined based on the |
| 1964 | // state *now* of the relevant activity record. The object is passed to |
| 1965 | // the handler solely for logging detail, not to be consulted/modified. |
| 1966 | final boolean nextState = r != null && r.immersive; |
| 1967 | mH.post(() -> { |
| 1968 | if (mUpdateLock.isHeld() != nextState) { |
| 1969 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, |
| 1970 | "Applying new update lock state '" + nextState + "' for " + r); |
| 1971 | if (nextState) { |
| 1972 | mUpdateLock.acquire(); |
| 1973 | } else { |
| 1974 | mUpdateLock.release(); |
| 1975 | } |
| 1976 | } |
| 1977 | }); |
| 1978 | } |
| 1979 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1980 | @Override |
| 1981 | public boolean isImmersive(IBinder token) { |
| 1982 | synchronized (mGlobalLock) { |
| 1983 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1984 | if (r == null) { |
| 1985 | throw new IllegalArgumentException(); |
| 1986 | } |
| 1987 | return r.immersive; |
| 1988 | } |
| 1989 | } |
| 1990 | |
| 1991 | @Override |
| 1992 | public boolean isTopActivityImmersive() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1993 | enforceNotIsolatedCaller("isTopActivityImmersive"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1994 | synchronized (mGlobalLock) { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 1995 | final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); |
| 1996 | if (topFocusedStack == null) { |
| 1997 | return false; |
| 1998 | } |
| 1999 | |
| 2000 | final ActivityRecord r = topFocusedStack.topRunningActivity(); |
| 2001 | return r != null && r.immersive; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2002 | } |
| 2003 | } |
| 2004 | |
| 2005 | @Override |
| 2006 | public void overridePendingTransition(IBinder token, String packageName, |
| 2007 | int enterAnim, int exitAnim) { |
| 2008 | synchronized (mGlobalLock) { |
| 2009 | ActivityRecord self = ActivityRecord.isInStackLocked(token); |
| 2010 | if (self == null) { |
| 2011 | return; |
| 2012 | } |
| 2013 | |
| 2014 | final long origId = Binder.clearCallingIdentity(); |
| 2015 | |
| 2016 | if (self.isState( |
| 2017 | ActivityStack.ActivityState.RESUMED, ActivityStack.ActivityState.PAUSING)) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2018 | self.getDisplay().mDisplayContent.mAppTransition.overridePendingAppTransition( |
Ming-Shin Lu | b6d7002 | 2020-03-27 23:51:56 +0800 | [diff] [blame] | 2019 | packageName, enterAnim, exitAnim, null, null); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | Binder.restoreCallingIdentity(origId); |
| 2023 | } |
| 2024 | } |
| 2025 | |
| 2026 | @Override |
| 2027 | public int getFrontActivityScreenCompatMode() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2028 | enforceNotIsolatedCaller("getFrontActivityScreenCompatMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2029 | synchronized (mGlobalLock) { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 2030 | final ActivityStack stack = getTopDisplayFocusedStack(); |
| 2031 | final ActivityRecord r = stack != null ? stack.topRunningActivity() : null; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2032 | if (r == null) { |
| 2033 | return ActivityManager.COMPAT_MODE_UNKNOWN; |
| 2034 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 2035 | return mCompatModePackages.computeCompatModeLocked(r.info.applicationInfo); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | @Override |
| 2040 | public void setFrontActivityScreenCompatMode(int mode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2041 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2042 | "setFrontActivityScreenCompatMode"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2043 | ApplicationInfo ai; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2044 | synchronized (mGlobalLock) { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 2045 | final ActivityStack stack = getTopDisplayFocusedStack(); |
| 2046 | final ActivityRecord r = stack != null ? stack.topRunningActivity() : null; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2047 | if (r == null) { |
| 2048 | Slog.w(TAG, "setFrontActivityScreenCompatMode failed: no top activity"); |
| 2049 | return; |
| 2050 | } |
| 2051 | ai = r.info.applicationInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 2052 | mCompatModePackages.setPackageScreenCompatModeLocked(ai, mode); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | @Override |
| 2057 | public int getLaunchedFromUid(IBinder activityToken) { |
| 2058 | ActivityRecord srec; |
| 2059 | synchronized (mGlobalLock) { |
| 2060 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 2061 | } |
| 2062 | if (srec == null) { |
| 2063 | return -1; |
| 2064 | } |
| 2065 | return srec.launchedFromUid; |
| 2066 | } |
| 2067 | |
| 2068 | @Override |
| 2069 | public String getLaunchedFromPackage(IBinder activityToken) { |
| 2070 | ActivityRecord srec; |
| 2071 | synchronized (mGlobalLock) { |
| 2072 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 2073 | } |
| 2074 | if (srec == null) { |
| 2075 | return null; |
| 2076 | } |
| 2077 | return srec.launchedFromPackage; |
| 2078 | } |
| 2079 | |
| 2080 | @Override |
| 2081 | public boolean convertFromTranslucent(IBinder token) { |
| 2082 | final long origId = Binder.clearCallingIdentity(); |
| 2083 | try { |
| 2084 | synchronized (mGlobalLock) { |
| 2085 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2086 | if (r == null) { |
| 2087 | return false; |
| 2088 | } |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 2089 | return r.setOccludesParent(true); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2090 | } |
| 2091 | } finally { |
| 2092 | Binder.restoreCallingIdentity(origId); |
| 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | @Override |
| 2097 | public boolean convertToTranslucent(IBinder token, Bundle options) { |
| 2098 | SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(options); |
| 2099 | final long origId = Binder.clearCallingIdentity(); |
| 2100 | try { |
| 2101 | synchronized (mGlobalLock) { |
| 2102 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2103 | if (r == null) { |
| 2104 | return false; |
| 2105 | } |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2106 | final ActivityRecord under = r.getTask().getActivityBelow(r); |
| 2107 | if (under != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2108 | under.returningOptions = safeOptions != null ? safeOptions.getOptions(r) : null; |
| 2109 | } |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 2110 | return r.setOccludesParent(false); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2111 | } |
| 2112 | } finally { |
| 2113 | Binder.restoreCallingIdentity(origId); |
| 2114 | } |
| 2115 | } |
| 2116 | |
| 2117 | @Override |
| 2118 | public void notifyActivityDrawn(IBinder token) { |
| 2119 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, "notifyActivityDrawn: token=" + token); |
| 2120 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2121 | ActivityRecord r = mRootWindowContainer.isInAnyStack(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2122 | if (r != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2123 | r.getRootTask().notifyActivityDrawnLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2124 | } |
| 2125 | } |
| 2126 | } |
| 2127 | |
| 2128 | @Override |
| 2129 | public void reportActivityFullyDrawn(IBinder token, boolean restoredFromBundle) { |
| 2130 | synchronized (mGlobalLock) { |
| 2131 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2132 | if (r == null) { |
| 2133 | return; |
| 2134 | } |
| 2135 | r.reportFullyDrawnLocked(restoredFromBundle); |
| 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | @Override |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2140 | public int getDisplayId(IBinder activityToken) throws RemoteException { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2141 | synchronized (mGlobalLock) { |
| 2142 | final ActivityStack stack = ActivityRecord.getStackLocked(activityToken); |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 2143 | if (stack != null) { |
| 2144 | final int displayId = stack.getDisplayId(); |
| 2145 | return displayId != INVALID_DISPLAY ? displayId : DEFAULT_DISPLAY; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2146 | } |
| 2147 | return DEFAULT_DISPLAY; |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | @Override |
| 2152 | public ActivityManager.StackInfo getFocusedStackInfo() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2153 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2154 | long ident = Binder.clearCallingIdentity(); |
| 2155 | try { |
| 2156 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2157 | ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2158 | if (focusedStack != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2159 | return mRootWindowContainer.getStackInfo(focusedStack.mTaskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2160 | } |
| 2161 | return null; |
| 2162 | } |
| 2163 | } finally { |
| 2164 | Binder.restoreCallingIdentity(ident); |
| 2165 | } |
| 2166 | } |
| 2167 | |
| 2168 | @Override |
| 2169 | public void setFocusedStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2170 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2171 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedStack: stackId=" + stackId); |
| 2172 | final long callingId = Binder.clearCallingIdentity(); |
| 2173 | try { |
| 2174 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2175 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2176 | if (stack == null) { |
| 2177 | Slog.w(TAG, "setFocusedStack: No stack with id=" + stackId); |
| 2178 | return; |
| 2179 | } |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2180 | final ActivityRecord r = stack.topRunningActivity(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2181 | if (r != null && r.moveFocusableActivityToTop("setFocusedStack")) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2182 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2183 | } |
| 2184 | } |
| 2185 | } finally { |
| 2186 | Binder.restoreCallingIdentity(callingId); |
| 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | @Override |
| 2191 | public void setFocusedTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2192 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2193 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedTask: taskId=" + taskId); |
| 2194 | final long callingId = Binder.clearCallingIdentity(); |
| 2195 | try { |
| 2196 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2197 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2198 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2199 | if (task == null) { |
| 2200 | return; |
| 2201 | } |
| 2202 | final ActivityRecord r = task.topRunningActivityLocked(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2203 | if (r != null && r.moveFocusableActivityToTop("setFocusedTask")) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2204 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | } finally { |
| 2208 | Binder.restoreCallingIdentity(callingId); |
| 2209 | } |
| 2210 | } |
| 2211 | |
| 2212 | @Override |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2213 | public void restartActivityProcessIfVisible(IBinder activityToken) { |
| 2214 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "restartActivityProcess()"); |
| 2215 | final long callingId = Binder.clearCallingIdentity(); |
| 2216 | try { |
| 2217 | synchronized (mGlobalLock) { |
| 2218 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 2219 | if (r == null) { |
| 2220 | return; |
| 2221 | } |
| 2222 | r.restartProcessIfVisible(); |
| 2223 | } |
| 2224 | } finally { |
| 2225 | Binder.restoreCallingIdentity(callingId); |
| 2226 | } |
| 2227 | } |
| 2228 | |
| 2229 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2230 | public boolean removeTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2231 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2232 | synchronized (mGlobalLock) { |
| 2233 | final long ident = Binder.clearCallingIdentity(); |
| 2234 | try { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2235 | return mStackSupervisor.removeTaskById(taskId, true, REMOVE_FROM_RECENTS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2236 | "remove-task"); |
| 2237 | } finally { |
| 2238 | Binder.restoreCallingIdentity(ident); |
| 2239 | } |
| 2240 | } |
| 2241 | } |
| 2242 | |
| 2243 | @Override |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 2244 | public void removeAllVisibleRecentTasks() { |
| 2245 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeAllVisibleRecentTasks()"); |
| 2246 | synchronized (mGlobalLock) { |
| 2247 | final long ident = Binder.clearCallingIdentity(); |
| 2248 | try { |
Winson Chung | 42fa21f | 2019-04-02 16:23:46 -0700 | [diff] [blame] | 2249 | getRecentTasks().removeAllVisibleTasks(mAmInternal.getCurrentUserId()); |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 2250 | } finally { |
| 2251 | Binder.restoreCallingIdentity(ident); |
| 2252 | } |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2257 | public boolean shouldUpRecreateTask(IBinder token, String destAffinity) { |
| 2258 | synchronized (mGlobalLock) { |
| 2259 | final ActivityRecord srec = ActivityRecord.forTokenLocked(token); |
| 2260 | if (srec != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2261 | return srec.getRootTask().shouldUpRecreateTaskLocked(srec, destAffinity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2262 | } |
| 2263 | } |
| 2264 | return false; |
| 2265 | } |
| 2266 | |
| 2267 | @Override |
| 2268 | public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode, |
| 2269 | Intent resultData) { |
Jeff Sharkey | 307ea7a | 2020-04-13 10:24:49 -0600 | [diff] [blame] | 2270 | final ActivityRecord r; |
| 2271 | synchronized (mGlobalLock) { |
| 2272 | r = ActivityRecord.isInStackLocked(token); |
| 2273 | if (r == null) { |
| 2274 | return false; |
| 2275 | } |
| 2276 | } |
| 2277 | |
| 2278 | // Carefully collect grants without holding lock |
| 2279 | final NeededUriGrants destGrants = collectGrants(destIntent, r); |
| 2280 | final NeededUriGrants resultGrants = collectGrants(resultData, r.resultTo); |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2281 | |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 2282 | synchronized (mGlobalLock) { |
Jeff Sharkey | 307ea7a | 2020-04-13 10:24:49 -0600 | [diff] [blame] | 2283 | return r.getRootTask().navigateUpTo( |
| 2284 | r, destIntent, destGrants, resultCode, resultData, resultGrants); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2285 | } |
| 2286 | } |
| 2287 | |
| 2288 | /** |
| 2289 | * Attempts to move a task backwards in z-order (the order of activities within the task is |
| 2290 | * unchanged). |
| 2291 | * |
| 2292 | * There are several possible results of this call: |
| 2293 | * - if the task is locked, then we will show the lock toast |
| 2294 | * - if there is a task behind the provided task, then that task is made visible and resumed as |
| 2295 | * this task is moved to the back |
| 2296 | * - otherwise, if there are no other tasks in the stack: |
| 2297 | * - if this task is in the pinned stack, then we remove the stack completely, which will |
| 2298 | * have the effect of moving the task to the top or bottom of the fullscreen stack |
| 2299 | * (depending on whether it is visible) |
| 2300 | * - otherwise, we simply return home and hide this task |
| 2301 | * |
| 2302 | * @param token A reference to the activity we wish to move |
| 2303 | * @param nonRoot If false then this only works if the activity is the root |
| 2304 | * of a task; if true it will work for any activity in a task. |
| 2305 | * @return Returns true if the move completed, false if not. |
| 2306 | */ |
| 2307 | @Override |
| 2308 | public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2309 | enforceNotIsolatedCaller("moveActivityTaskToBack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2310 | synchronized (mGlobalLock) { |
| 2311 | final long origId = Binder.clearCallingIdentity(); |
| 2312 | try { |
| 2313 | int taskId = ActivityRecord.getTaskForActivityLocked(token, !nonRoot); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2314 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2315 | if (task != null) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2316 | return ActivityRecord.getStackLocked(token).moveTaskToBack(task); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2317 | } |
| 2318 | } finally { |
| 2319 | Binder.restoreCallingIdentity(origId); |
| 2320 | } |
| 2321 | } |
| 2322 | return false; |
| 2323 | } |
| 2324 | |
| 2325 | @Override |
| 2326 | public Rect getTaskBounds(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2327 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getTaskBounds()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2328 | long ident = Binder.clearCallingIdentity(); |
| 2329 | Rect rect = new Rect(); |
| 2330 | try { |
| 2331 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2332 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2333 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2334 | if (task == null) { |
| 2335 | Slog.w(TAG, "getTaskBounds: taskId=" + taskId + " not found"); |
| 2336 | return rect; |
| 2337 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 2338 | if (task.getParent() != null) { |
| 2339 | rect.set(task.getBounds()); |
| 2340 | } else if (task.mLastNonFullscreenBounds != null) { |
| 2341 | rect.set(task.mLastNonFullscreenBounds); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2342 | } |
| 2343 | } |
| 2344 | } finally { |
| 2345 | Binder.restoreCallingIdentity(ident); |
| 2346 | } |
| 2347 | return rect; |
| 2348 | } |
| 2349 | |
| 2350 | @Override |
| 2351 | public ActivityManager.TaskDescription getTaskDescription(int id) { |
| 2352 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2353 | enforceCallerIsRecentsOrHasPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2354 | MANAGE_ACTIVITY_STACKS, "getTaskDescription()"); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2355 | final Task tr = mRootWindowContainer.anyTaskForId(id, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2356 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2357 | if (tr != null) { |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 2358 | return tr.getTaskDescription(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2359 | } |
| 2360 | } |
| 2361 | return null; |
| 2362 | } |
| 2363 | |
| 2364 | @Override |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2365 | public boolean setTaskWindowingMode(int taskId, int windowingMode, boolean toTop) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2366 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 2367 | return setTaskWindowingModeSplitScreenPrimary(taskId, toTop); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2368 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2369 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setTaskWindowingMode()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2370 | synchronized (mGlobalLock) { |
| 2371 | final long ident = Binder.clearCallingIdentity(); |
| 2372 | try { |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2373 | if (WindowConfiguration.isSplitScreenWindowingMode(windowingMode)) { |
| 2374 | return setTaskWindowingModeSplitScreen(taskId, windowingMode, toTop); |
| 2375 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2376 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2377 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2378 | if (task == null) { |
| 2379 | Slog.w(TAG, "setTaskWindowingMode: No task for id=" + taskId); |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2380 | return false; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | if (DEBUG_STACK) Slog.d(TAG_STACK, "setTaskWindowingMode: moving task=" + taskId |
| 2384 | + " to windowingMode=" + windowingMode + " toTop=" + toTop); |
| 2385 | |
| 2386 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2387 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2388 | + " non-standard task " + taskId + " to windowing mode=" |
| 2389 | + windowingMode); |
| 2390 | } |
| 2391 | |
| 2392 | final ActivityStack stack = task.getStack(); |
| 2393 | if (toTop) { |
| 2394 | stack.moveToFront("setTaskWindowingMode", task); |
| 2395 | } |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2396 | // Convert some windowing-mode changes into root-task reparents for split-screen. |
| 2397 | if (stack.inSplitScreenWindowingMode()) { |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 2398 | stack.getDisplayArea().onSplitScreenModeDismissed(); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2399 | |
| 2400 | } else { |
| 2401 | stack.setWindowingMode(windowingMode); |
| 2402 | stack.getDisplay().ensureActivitiesVisible(null, 0, PRESERVE_WINDOWS, |
| 2403 | true /* notifyClients */); |
| 2404 | } |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2405 | return true; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2406 | } finally { |
| 2407 | Binder.restoreCallingIdentity(ident); |
| 2408 | } |
| 2409 | } |
| 2410 | } |
| 2411 | |
| 2412 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2413 | public String getCallingPackage(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2414 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2415 | ActivityRecord r = getCallingRecordLocked(token); |
| 2416 | return r != null ? r.info.packageName : null; |
| 2417 | } |
| 2418 | } |
| 2419 | |
| 2420 | @Override |
| 2421 | public ComponentName getCallingActivity(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2422 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2423 | ActivityRecord r = getCallingRecordLocked(token); |
| 2424 | return r != null ? r.intent.getComponent() : null; |
| 2425 | } |
| 2426 | } |
| 2427 | |
| 2428 | private ActivityRecord getCallingRecordLocked(IBinder token) { |
| 2429 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2430 | if (r == null) { |
| 2431 | return null; |
| 2432 | } |
| 2433 | return r.resultTo; |
| 2434 | } |
| 2435 | |
Jeff Sharkey | 307ea7a | 2020-04-13 10:24:49 -0600 | [diff] [blame] | 2436 | private NeededUriGrants collectGrants(Intent intent, ActivityRecord target) { |
| 2437 | if (target != null) { |
| 2438 | return mUgmInternal.checkGrantUriPermissionFromIntent(intent, |
| 2439 | Binder.getCallingUid(), target.packageName, target.mUserId); |
| 2440 | } else { |
| 2441 | return null; |
| 2442 | } |
| 2443 | } |
| 2444 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2445 | @Override |
| 2446 | public void unhandledBack() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2447 | mAmInternal.enforceCallingPermission(android.Manifest.permission.FORCE_BACK, "unhandledBack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2448 | |
| 2449 | synchronized (mGlobalLock) { |
| 2450 | final long origId = Binder.clearCallingIdentity(); |
| 2451 | try { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 2452 | final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); |
| 2453 | if (topFocusedStack != null) { |
| 2454 | topFocusedStack.unhandledBackLocked(); |
| 2455 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2456 | } finally { |
| 2457 | Binder.restoreCallingIdentity(origId); |
| 2458 | } |
| 2459 | } |
| 2460 | } |
| 2461 | |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2462 | @Override |
| 2463 | public void onBackPressedOnTaskRoot(IBinder token, IRequestFinishCallback callback) { |
| 2464 | synchronized (mGlobalLock) { |
| 2465 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2466 | if (r == null) { |
| 2467 | return; |
| 2468 | } |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2469 | ActivityStack stack = r.getRootTask(); |
Winson Chung | a1f869d | 2020-03-21 23:02:48 -0700 | [diff] [blame] | 2470 | final TaskOrganizerController taskOrgController = |
| 2471 | mWindowOrganizerController.mTaskOrganizerController; |
| 2472 | if (taskOrgController.handleInterceptBackPressedOnTaskRoot(stack)) { |
| 2473 | // This task is handled by a task organizer that has requested the back pressed |
| 2474 | // callback |
| 2475 | } else if (stack != null && (stack.isSingleTaskInstance())) { |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2476 | // Single-task stacks are used for activities which are presented in floating |
| 2477 | // windows above full screen activities. Instead of directly finishing the |
| 2478 | // task, a task change listener is used to notify SystemUI so the action can be |
| 2479 | // handled specially. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2480 | final Task task = r.getTask(); |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2481 | mTaskChangeNotificationController |
| 2482 | .notifyBackPressedOnTaskRoot(task.getTaskInfo()); |
| 2483 | } else { |
| 2484 | try { |
| 2485 | callback.requestFinish(); |
| 2486 | } catch (RemoteException e) { |
| 2487 | Slog.e(TAG, "Failed to invoke request finish callback", e); |
| 2488 | } |
| 2489 | } |
| 2490 | } |
| 2491 | } |
| 2492 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2493 | /** |
| 2494 | * TODO: Add mController hook |
| 2495 | */ |
| 2496 | @Override |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2497 | public void moveTaskToFront(IApplicationThread appThread, String callingPackage, int taskId, |
| 2498 | int flags, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2499 | mAmInternal.enforceCallingPermission(android.Manifest.permission.REORDER_TASKS, "moveTaskToFront()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2500 | |
| 2501 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToFront: moving taskId=" + taskId); |
| 2502 | synchronized (mGlobalLock) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2503 | moveTaskToFrontLocked(appThread, callingPackage, taskId, flags, |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 2504 | SafeActivityOptions.fromBundle(bOptions)); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2505 | } |
| 2506 | } |
| 2507 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2508 | void moveTaskToFrontLocked(@Nullable IApplicationThread appThread, |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 2509 | @Nullable String callingPackage, int taskId, int flags, SafeActivityOptions options) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2510 | final int callingPid = Binder.getCallingPid(); |
| 2511 | final int callingUid = Binder.getCallingUid(); |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 2512 | assertPackageMatchesCallingUid(callingPackage); |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2513 | if (!checkAppSwitchAllowedLocked(callingPid, callingUid, -1, -1, "Task to front")) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2514 | SafeActivityOptions.abort(options); |
| 2515 | return; |
| 2516 | } |
| 2517 | final long origId = Binder.clearCallingIdentity(); |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2518 | WindowProcessController callerApp = null; |
| 2519 | if (appThread != null) { |
| 2520 | callerApp = getProcessController(appThread); |
| 2521 | } |
| 2522 | final ActivityStarter starter = getActivityStartController().obtainStarter( |
| 2523 | null /* intent */, "moveTaskToFront"); |
| 2524 | if (starter.shouldAbortBackgroundActivityStart(callingUid, callingPid, callingPackage, -1, |
Galia Peycheva | ed401cc | 2020-03-19 20:28:09 +0100 | [diff] [blame] | 2525 | -1, callerApp, null, false, null)) { |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 2526 | if (!isBackgroundActivityStartsEnabled()) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2527 | return; |
| 2528 | } |
| 2529 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2530 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2531 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2532 | if (task == null) { |
| 2533 | Slog.d(TAG, "Could not find task for id: "+ taskId); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2534 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2535 | return; |
| 2536 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2537 | if (getLockTaskController().isLockTaskModeViolation(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2538 | Slog.e(TAG, "moveTaskToFront: Attempt to violate Lock Task Mode"); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2539 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2540 | return; |
| 2541 | } |
| 2542 | ActivityOptions realOptions = options != null |
| 2543 | ? options.getOptions(mStackSupervisor) |
| 2544 | : null; |
| 2545 | mStackSupervisor.findTaskToMoveToFront(task, flags, realOptions, "moveTaskToFront", |
| 2546 | false /* forceNonResizable */); |
| 2547 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 2548 | final ActivityRecord topActivity = task.getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2549 | if (topActivity != null) { |
| 2550 | |
| 2551 | // We are reshowing a task, use a starting window to hide the initial draw delay |
| 2552 | // so the transition can start earlier. |
| 2553 | topActivity.showStartingWindow(null /* prev */, false /* newTask */, |
Riddle Hsu | eae6ef3e | 2020-05-13 01:07:33 +0800 | [diff] [blame] | 2554 | true /* taskSwitch */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2555 | } |
| 2556 | } finally { |
| 2557 | Binder.restoreCallingIdentity(origId); |
| 2558 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2559 | } |
| 2560 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2561 | /** |
| 2562 | * Return true if callingUid is system, or packageName belongs to that callingUid. |
| 2563 | */ |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 2564 | private boolean isSameApp(int callingUid, @Nullable String packageName) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2565 | try { |
| 2566 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 2567 | if (packageName == null) { |
| 2568 | return false; |
| 2569 | } |
| 2570 | final int uid = AppGlobals.getPackageManager().getPackageUid(packageName, |
| 2571 | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 2572 | UserHandle.getUserId(callingUid)); |
| 2573 | return UserHandle.isSameApp(callingUid, uid); |
| 2574 | } |
| 2575 | } catch (RemoteException e) { |
| 2576 | // Should not happen |
| 2577 | } |
| 2578 | return true; |
| 2579 | } |
| 2580 | |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 2581 | /** |
| 2582 | * Checks that the provided package name matches the current calling UID, throws a security |
| 2583 | * exception if it doesn't. |
| 2584 | */ |
| 2585 | void assertPackageMatchesCallingUid(@Nullable String packageName) { |
| 2586 | final int callingUid = Binder.getCallingUid(); |
| 2587 | if (isSameApp(callingUid, packageName)) { |
| 2588 | return; |
| 2589 | } |
| 2590 | final String msg = "Permission Denial: package=" + packageName |
| 2591 | + " does not belong to uid=" + callingUid; |
| 2592 | Slog.w(TAG, msg); |
| 2593 | throw new SecurityException(msg); |
| 2594 | } |
| 2595 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2596 | boolean checkAppSwitchAllowedLocked(int sourcePid, int sourceUid, |
| 2597 | int callingPid, int callingUid, String name) { |
| 2598 | if (mAppSwitchesAllowedTime < SystemClock.uptimeMillis()) { |
| 2599 | return true; |
| 2600 | } |
| 2601 | |
| 2602 | if (getRecentTasks().isCallerRecents(sourceUid)) { |
| 2603 | return true; |
| 2604 | } |
| 2605 | |
| 2606 | int perm = checkComponentPermission(STOP_APP_SWITCHES, sourcePid, sourceUid, -1, true); |
| 2607 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2608 | return true; |
| 2609 | } |
| 2610 | if (checkAllowAppSwitchUid(sourceUid)) { |
| 2611 | return true; |
| 2612 | } |
| 2613 | |
| 2614 | // If the actual IPC caller is different from the logical source, then |
| 2615 | // also see if they are allowed to control app switches. |
| 2616 | if (callingUid != -1 && callingUid != sourceUid) { |
| 2617 | perm = checkComponentPermission(STOP_APP_SWITCHES, callingPid, callingUid, -1, true); |
| 2618 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2619 | return true; |
| 2620 | } |
| 2621 | if (checkAllowAppSwitchUid(callingUid)) { |
| 2622 | return true; |
| 2623 | } |
| 2624 | } |
| 2625 | |
| 2626 | Slog.w(TAG, name + " request from " + sourceUid + " stopped"); |
| 2627 | return false; |
| 2628 | } |
| 2629 | |
| 2630 | private boolean checkAllowAppSwitchUid(int uid) { |
| 2631 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(UserHandle.getUserId(uid)); |
| 2632 | if (types != null) { |
| 2633 | for (int i = types.size() - 1; i >= 0; i--) { |
| 2634 | if (types.valueAt(i).intValue() == uid) { |
| 2635 | return true; |
| 2636 | } |
| 2637 | } |
| 2638 | } |
| 2639 | return false; |
| 2640 | } |
| 2641 | |
| 2642 | @Override |
| 2643 | public void setActivityController(IActivityController controller, boolean imAMonkey) { |
| 2644 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER, |
| 2645 | "setActivityController()"); |
| 2646 | synchronized (mGlobalLock) { |
| 2647 | mController = controller; |
| 2648 | mControllerIsAMonkey = imAMonkey; |
| 2649 | Watchdog.getInstance().setActivityController(controller); |
| 2650 | } |
| 2651 | } |
| 2652 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 2653 | public boolean isControllerAMonkey() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2654 | synchronized (mGlobalLock) { |
| 2655 | return mController != null && mControllerIsAMonkey; |
| 2656 | } |
| 2657 | } |
| 2658 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2659 | @Override |
| 2660 | public int getTaskForActivity(IBinder token, boolean onlyRoot) { |
| 2661 | synchronized (mGlobalLock) { |
| 2662 | return ActivityRecord.getTaskForActivityLocked(token, onlyRoot); |
| 2663 | } |
| 2664 | } |
| 2665 | |
| 2666 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2667 | public List<ActivityManager.RunningTaskInfo> getTasks(int maxNum) { |
Winson Chung | e5ab017 | 2020-03-21 23:00:24 -0700 | [diff] [blame] | 2668 | return getFilteredTasks(maxNum, false /* filterForVisibleRecents */); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
Winson Chung | e5ab017 | 2020-03-21 23:00:24 -0700 | [diff] [blame] | 2671 | /** |
| 2672 | * @param filterOnlyVisibleRecents whether to filter the tasks based on whether they would ever |
| 2673 | * be visible in the recent task list in systemui |
| 2674 | */ |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2675 | @Override |
| 2676 | public List<ActivityManager.RunningTaskInfo> getFilteredTasks(int maxNum, |
Winson Chung | e5ab017 | 2020-03-21 23:00:24 -0700 | [diff] [blame] | 2677 | boolean filterOnlyVisibleRecents) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2678 | final int callingUid = Binder.getCallingUid(); |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 2679 | final int callingPid = Binder.getCallingPid(); |
| 2680 | final boolean crossUser = isCrossUserAllowed(callingPid, callingUid); |
Nicholas Sauer | 3f9249f | 2019-09-10 20:23:41 -0700 | [diff] [blame] | 2681 | final int[] profileIds = getUserManager().getProfileIds( |
| 2682 | UserHandle.getUserId(callingUid), true); |
| 2683 | ArraySet<Integer> callingProfileIds = new ArraySet<>(); |
| 2684 | for (int i = 0; i < profileIds.length; i++) { |
| 2685 | callingProfileIds.add(profileIds[i]); |
| 2686 | } |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2687 | ArrayList<ActivityManager.RunningTaskInfo> list = new ArrayList<>(); |
| 2688 | |
| 2689 | synchronized (mGlobalLock) { |
| 2690 | if (DEBUG_ALL) Slog.v(TAG, "getTasks: max=" + maxNum); |
| 2691 | |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 2692 | final boolean allowed = isGetTasksAllowed("getTasks", callingPid, callingUid); |
Winson Chung | e5ab017 | 2020-03-21 23:00:24 -0700 | [diff] [blame] | 2693 | mRootWindowContainer.getRunningTasks(maxNum, list, filterOnlyVisibleRecents, callingUid, |
| 2694 | allowed, crossUser, callingProfileIds); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | return list; |
| 2698 | } |
| 2699 | |
| 2700 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2701 | public final void finishSubActivity(IBinder token, String resultWho, int requestCode) { |
| 2702 | synchronized (mGlobalLock) { |
| 2703 | final long origId = Binder.clearCallingIdentity(); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2704 | try { |
| 2705 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2706 | if (r == null) return; |
| 2707 | |
| 2708 | final PooledConsumer c = PooledLambda.obtainConsumer( |
| 2709 | ActivityRecord::finishIfSubActivity, PooledLambda.__(ActivityRecord.class), |
| 2710 | r, resultWho, requestCode); |
| 2711 | // TODO: This should probably only loop over the task since you need to be in the |
| 2712 | // same task to return results. |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2713 | r.getRootTask().forAllActivities(c); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2714 | c.recycle(); |
| 2715 | |
| 2716 | updateOomAdj(); |
| 2717 | } finally { |
| 2718 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2719 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2720 | } |
| 2721 | } |
| 2722 | |
| 2723 | @Override |
| 2724 | public boolean willActivityBeVisible(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2725 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2726 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 2727 | if (stack != null) { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2728 | return stack.willActivityBeVisible(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2729 | } |
| 2730 | return false; |
| 2731 | } |
| 2732 | } |
| 2733 | |
| 2734 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2735 | public void moveTaskToStack(int taskId, int stackId, boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2736 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "moveTaskToStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2737 | synchronized (mGlobalLock) { |
| 2738 | final long ident = Binder.clearCallingIdentity(); |
| 2739 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2740 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2741 | if (task == null) { |
| 2742 | Slog.w(TAG, "moveTaskToStack: No task for id=" + taskId); |
| 2743 | return; |
| 2744 | } |
| 2745 | |
| 2746 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToStack: moving task=" + taskId |
| 2747 | + " to stackId=" + stackId + " toTop=" + toTop); |
| 2748 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2749 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2750 | if (stack == null) { |
| 2751 | throw new IllegalStateException( |
| 2752 | "moveTaskToStack: No stack for stackId=" + stackId); |
| 2753 | } |
| 2754 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 2755 | throw new IllegalArgumentException("moveTaskToStack: Attempt to move task " |
| 2756 | + taskId + " to stack " + stackId); |
| 2757 | } |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2758 | task.reparent(stack, toTop, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME, |
| 2759 | "moveTaskToStack"); |
| 2760 | } finally { |
| 2761 | Binder.restoreCallingIdentity(ident); |
| 2762 | } |
| 2763 | } |
| 2764 | } |
| 2765 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2766 | /** |
| 2767 | * Moves the specified task to the primary-split-screen stack. |
| 2768 | * |
| 2769 | * @param taskId Id of task to move. |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2770 | * @param toTop If the task and stack should be moved to the top. |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2771 | * @return Whether the task was successfully put into splitscreen. |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2772 | */ |
| 2773 | @Override |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 2774 | public boolean setTaskWindowingModeSplitScreenPrimary(int taskId, boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2775 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2776 | "setTaskWindowingModeSplitScreenPrimary()"); |
| 2777 | synchronized (mGlobalLock) { |
| 2778 | final long ident = Binder.clearCallingIdentity(); |
| 2779 | try { |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2780 | return setTaskWindowingModeSplitScreen(taskId, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, |
| 2781 | toTop); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2782 | } finally { |
| 2783 | Binder.restoreCallingIdentity(ident); |
| 2784 | } |
| 2785 | } |
| 2786 | } |
| 2787 | |
| 2788 | /** |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2789 | * Moves the specified task into a split-screen tile. |
| 2790 | */ |
| 2791 | private boolean setTaskWindowingModeSplitScreen(int taskId, int windowingMode, boolean toTop) { |
| 2792 | if (!WindowConfiguration.isSplitScreenWindowingMode(windowingMode)) { |
| 2793 | throw new IllegalArgumentException("Calling setTaskWindowingModeSplitScreen with non" |
| 2794 | + "split-screen mode: " + windowingMode); |
| 2795 | } |
| 2796 | if (isInLockTaskMode()) { |
| 2797 | Slog.w(TAG, "setTaskWindowingModeSplitScreen: Is in lock task mode=" |
| 2798 | + getLockTaskModeState()); |
| 2799 | return false; |
| 2800 | } |
| 2801 | |
| 2802 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
| 2803 | MATCH_TASK_IN_STACKS_ONLY); |
| 2804 | if (task == null) { |
| 2805 | Slog.w(TAG, "setTaskWindowingModeSplitScreenPrimary: No task for id=" + taskId); |
| 2806 | return false; |
| 2807 | } |
| 2808 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2809 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2810 | + " non-standard task " + taskId + " to split-screen windowing mode"); |
| 2811 | } |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 2812 | if (!task.supportsSplitScreenWindowingMode()) { |
| 2813 | return false; |
| 2814 | } |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2815 | |
| 2816 | final int prevMode = task.getWindowingMode(); |
Louis Chang | cf3d145 | 2020-04-16 16:36:05 +0800 | [diff] [blame] | 2817 | if (prevMode == windowingMode) { |
| 2818 | // The task is already in split-screen and with correct windowing mode. |
| 2819 | return true; |
| 2820 | } |
| 2821 | |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2822 | moveTaskToSplitScreenPrimaryTask(task, toTop); |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 2823 | return prevMode != task.getWindowingMode(); |
| 2824 | } |
| 2825 | |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2826 | void moveTaskToSplitScreenPrimaryTask(Task task, boolean toTop) { |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 2827 | final TaskDisplayArea taskDisplayArea = task.getDisplayArea(); |
| 2828 | final ActivityStack primarySplitTask = taskDisplayArea.getRootSplitScreenPrimaryTask(); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2829 | if (primarySplitTask == null) { |
| 2830 | throw new IllegalStateException("Can't enter split without associated organized task"); |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2831 | } |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2832 | |
| 2833 | if (toTop) { |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 2834 | taskDisplayArea.positionStackAt(POSITION_TOP, primarySplitTask, |
Andrii Kulian | 9ea12da | 2020-03-27 17:16:38 -0700 | [diff] [blame] | 2835 | false /* includingParents */); |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2836 | } |
| 2837 | WindowContainerTransaction wct = new WindowContainerTransaction(); |
Wale Ogunwale | 465b1e1 | 2020-03-31 12:15:51 -0700 | [diff] [blame] | 2838 | // Clear out current windowing mode before reparenting to split taks. |
| 2839 | wct.setWindowingMode( |
| 2840 | task.getStack().mRemoteToken.toWindowContainerToken(), WINDOWING_MODE_UNDEFINED); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 2841 | wct.reparent(task.getStack().mRemoteToken.toWindowContainerToken(), |
| 2842 | primarySplitTask.mRemoteToken.toWindowContainerToken(), toTop); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 2843 | mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | /** |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2847 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 2848 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 2849 | */ |
| 2850 | @Override |
| 2851 | public void removeStacksInWindowingModes(int[] windowingModes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2852 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2853 | "removeStacksInWindowingModes()"); |
| 2854 | |
| 2855 | synchronized (mGlobalLock) { |
| 2856 | final long ident = Binder.clearCallingIdentity(); |
| 2857 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2858 | mRootWindowContainer.removeStacksInWindowingModes(windowingModes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2859 | } finally { |
| 2860 | Binder.restoreCallingIdentity(ident); |
| 2861 | } |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | @Override |
| 2866 | public void removeStacksWithActivityTypes(int[] activityTypes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2867 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2868 | "removeStacksWithActivityTypes()"); |
| 2869 | |
| 2870 | synchronized (mGlobalLock) { |
| 2871 | final long ident = Binder.clearCallingIdentity(); |
| 2872 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2873 | mRootWindowContainer.removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2874 | } finally { |
| 2875 | Binder.restoreCallingIdentity(ident); |
| 2876 | } |
| 2877 | } |
| 2878 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2879 | |
| 2880 | @Override |
| 2881 | public ParceledListSlice<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, |
| 2882 | int userId) { |
| 2883 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2884 | userId = handleIncomingUser(Binder.getCallingPid(), callingUid, userId, "getRecentTasks"); |
| 2885 | final boolean allowed = isGetTasksAllowed("getRecentTasks", Binder.getCallingPid(), |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2886 | callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2887 | synchronized (mGlobalLock) { |
Winson Chung | 66b08f0 | 2020-03-03 14:32:35 -0800 | [diff] [blame] | 2888 | return mRecentTasks.getRecentTasks(maxNum, flags, allowed, userId, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2889 | } |
| 2890 | } |
| 2891 | |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 2892 | // TODO(148895075): deprecate and replace with task equivalents |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2893 | @Override |
| 2894 | public List<ActivityManager.StackInfo> getAllStackInfos() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2895 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2896 | long ident = Binder.clearCallingIdentity(); |
| 2897 | try { |
| 2898 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2899 | return mRootWindowContainer.getAllStackInfos(INVALID_DISPLAY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2900 | } |
| 2901 | } finally { |
| 2902 | Binder.restoreCallingIdentity(ident); |
| 2903 | } |
| 2904 | } |
| 2905 | |
| 2906 | @Override |
| 2907 | public ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2908 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2909 | long ident = Binder.clearCallingIdentity(); |
| 2910 | try { |
| 2911 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2912 | return mRootWindowContainer.getStackInfo(windowingMode, activityType); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2913 | } |
| 2914 | } finally { |
| 2915 | Binder.restoreCallingIdentity(ident); |
| 2916 | } |
| 2917 | } |
| 2918 | |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 2919 | // TODO(148895075): deprecate and replace with task equivalents |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2920 | @Override |
Evan Rosky | fd43969 | 2019-11-06 16:12:59 -0800 | [diff] [blame] | 2921 | public List<ActivityManager.StackInfo> getAllStackInfosOnDisplay(int displayId) { |
| 2922 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); |
| 2923 | long ident = Binder.clearCallingIdentity(); |
| 2924 | try { |
| 2925 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2926 | return mRootWindowContainer.getAllStackInfos(displayId); |
Evan Rosky | fd43969 | 2019-11-06 16:12:59 -0800 | [diff] [blame] | 2927 | } |
| 2928 | } finally { |
| 2929 | Binder.restoreCallingIdentity(ident); |
| 2930 | } |
| 2931 | } |
| 2932 | |
| 2933 | @Override |
| 2934 | public ActivityManager.StackInfo getStackInfoOnDisplay(int windowingMode, int activityType, |
| 2935 | int displayId) { |
| 2936 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
| 2937 | long ident = Binder.clearCallingIdentity(); |
| 2938 | try { |
| 2939 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2940 | return mRootWindowContainer.getStackInfo(windowingMode, activityType, displayId); |
Evan Rosky | fd43969 | 2019-11-06 16:12:59 -0800 | [diff] [blame] | 2941 | } |
| 2942 | } finally { |
| 2943 | Binder.restoreCallingIdentity(ident); |
| 2944 | } |
| 2945 | } |
| 2946 | |
| 2947 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2948 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2949 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "cancelRecentsAnimation()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2950 | final long callingUid = Binder.getCallingUid(); |
| 2951 | final long origId = Binder.clearCallingIdentity(); |
| 2952 | try { |
| 2953 | synchronized (mGlobalLock) { |
| 2954 | // Cancel the recents animation synchronously (do not hold the WM lock) |
Wale Ogunwale | a441b92 | 2019-06-27 19:21:44 -0700 | [diff] [blame] | 2955 | mWindowManager.cancelRecentsAnimation(restoreHomeStackPosition |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2956 | ? REORDER_MOVE_TO_ORIGINAL_POSITION |
| 2957 | : REORDER_KEEP_IN_PLACE, "cancelRecentsAnimation/uid=" + callingUid); |
| 2958 | } |
| 2959 | } finally { |
| 2960 | Binder.restoreCallingIdentity(origId); |
| 2961 | } |
| 2962 | } |
| 2963 | |
| 2964 | @Override |
| 2965 | public void startLockTaskModeByToken(IBinder token) { |
| 2966 | synchronized (mGlobalLock) { |
| 2967 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2968 | if (r == null) { |
| 2969 | return; |
| 2970 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2971 | startLockTaskModeLocked(r.getTask(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2972 | } |
| 2973 | } |
| 2974 | |
| 2975 | @Override |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2976 | public void startSystemLockTaskMode(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2977 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "startSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2978 | // This makes inner call to look as if it was initiated by system. |
| 2979 | long ident = Binder.clearCallingIdentity(); |
| 2980 | try { |
| 2981 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2982 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2983 | MATCH_TASK_IN_STACKS_ONLY); |
| 2984 | if (task == null) { |
| 2985 | return; |
| 2986 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2987 | |
| 2988 | // When starting lock task mode the stack must be in front and focused |
| 2989 | task.getStack().moveToFront("startSystemLockTaskMode"); |
| 2990 | startLockTaskModeLocked(task, true /* isSystemCaller */); |
| 2991 | } |
| 2992 | } finally { |
| 2993 | Binder.restoreCallingIdentity(ident); |
| 2994 | } |
| 2995 | } |
| 2996 | |
| 2997 | @Override |
| 2998 | public void stopLockTaskModeByToken(IBinder token) { |
| 2999 | synchronized (mGlobalLock) { |
| 3000 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3001 | if (r == null) { |
| 3002 | return; |
| 3003 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3004 | stopLockTaskModeInternal(r.getTask(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3005 | } |
| 3006 | } |
| 3007 | |
| 3008 | /** |
| 3009 | * This API should be called by SystemUI only when user perform certain action to dismiss |
| 3010 | * lock task mode. We should only dismiss pinned lock task mode in this case. |
| 3011 | */ |
| 3012 | @Override |
| 3013 | public void stopSystemLockTaskMode() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3014 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "stopSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3015 | stopLockTaskModeInternal(null, true /* isSystemCaller */); |
| 3016 | } |
| 3017 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3018 | private void startLockTaskModeLocked(@Nullable Task task, boolean isSystemCaller) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3019 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "startLockTaskModeLocked: " + task); |
| 3020 | if (task == null || task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) { |
| 3021 | return; |
| 3022 | } |
| 3023 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3024 | final ActivityStack stack = mRootWindowContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 3025 | if (stack == null || task != stack.getTopMostTask()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3026 | throw new IllegalArgumentException("Invalid task, not in foreground"); |
| 3027 | } |
| 3028 | |
| 3029 | // {@code isSystemCaller} is used to distinguish whether this request is initiated by the |
| 3030 | // system or a specific app. |
| 3031 | // * System-initiated requests will only start the pinned mode (screen pinning) |
| 3032 | // * App-initiated requests |
| 3033 | // - will put the device in fully locked mode (LockTask), if the app is whitelisted |
| 3034 | // - will start the pinned mode, otherwise |
| 3035 | final int callingUid = Binder.getCallingUid(); |
| 3036 | long ident = Binder.clearCallingIdentity(); |
| 3037 | try { |
| 3038 | // When a task is locked, dismiss the pinned stack if it exists |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3039 | mRootWindowContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3040 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3041 | getLockTaskController().startLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3042 | } finally { |
| 3043 | Binder.restoreCallingIdentity(ident); |
| 3044 | } |
| 3045 | } |
| 3046 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3047 | private void stopLockTaskModeInternal(@Nullable Task task, boolean isSystemCaller) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3048 | final int callingUid = Binder.getCallingUid(); |
| 3049 | long ident = Binder.clearCallingIdentity(); |
| 3050 | try { |
| 3051 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3052 | getLockTaskController().stopLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3053 | } |
| 3054 | // Launch in-call UI if a call is ongoing. This is necessary to allow stopping the lock |
| 3055 | // task and jumping straight into a call in the case of emergency call back. |
| 3056 | TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
| 3057 | if (tm != null) { |
| 3058 | tm.showInCallScreen(false); |
| 3059 | } |
| 3060 | } finally { |
| 3061 | Binder.restoreCallingIdentity(ident); |
| 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | @Override |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 3066 | public void updateLockTaskPackages(int userId, String[] packages) { |
| 3067 | final int callingUid = Binder.getCallingUid(); |
| 3068 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 3069 | mAmInternal.enforceCallingPermission(Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
| 3070 | "updateLockTaskPackages()"); |
| 3071 | } |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 3072 | synchronized (mGlobalLock) { |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 3073 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Whitelisting " + userId + ":" |
| 3074 | + Arrays.toString(packages)); |
| 3075 | getLockTaskController().updateLockTaskPackages(userId, packages); |
| 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3080 | public boolean isInLockTaskMode() { |
| 3081 | return getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
| 3082 | } |
| 3083 | |
| 3084 | @Override |
| 3085 | public int getLockTaskModeState() { |
| 3086 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3087 | return getLockTaskController().getLockTaskModeState(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3088 | } |
| 3089 | } |
| 3090 | |
| 3091 | @Override |
| 3092 | public void setTaskDescription(IBinder token, ActivityManager.TaskDescription td) { |
| 3093 | synchronized (mGlobalLock) { |
| 3094 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3095 | if (r != null) { |
| 3096 | r.setTaskDescription(td); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3097 | } |
| 3098 | } |
| 3099 | } |
| 3100 | |
| 3101 | @Override |
| 3102 | public Bundle getActivityOptions(IBinder token) { |
| 3103 | final long origId = Binder.clearCallingIdentity(); |
| 3104 | try { |
| 3105 | synchronized (mGlobalLock) { |
| 3106 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3107 | if (r != null) { |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 3108 | final ActivityOptions activityOptions = r.takeOptionsLocked( |
| 3109 | true /* fromClient */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3110 | return activityOptions == null ? null : activityOptions.toBundle(); |
| 3111 | } |
| 3112 | return null; |
| 3113 | } |
| 3114 | } finally { |
| 3115 | Binder.restoreCallingIdentity(origId); |
| 3116 | } |
| 3117 | } |
| 3118 | |
| 3119 | @Override |
| 3120 | public List<IBinder> getAppTasks(String callingPackage) { |
| 3121 | int callingUid = Binder.getCallingUid(); |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 3122 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3123 | long ident = Binder.clearCallingIdentity(); |
| 3124 | try { |
| 3125 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3126 | return mRecentTasks.getAppTasksList(callingUid, callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3127 | } |
| 3128 | } finally { |
| 3129 | Binder.restoreCallingIdentity(ident); |
| 3130 | } |
| 3131 | } |
| 3132 | |
| 3133 | @Override |
| 3134 | public void finishVoiceTask(IVoiceInteractionSession session) { |
| 3135 | synchronized (mGlobalLock) { |
| 3136 | final long origId = Binder.clearCallingIdentity(); |
| 3137 | try { |
| 3138 | // TODO: VI Consider treating local voice interactions and voice tasks |
| 3139 | // differently here |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3140 | mRootWindowContainer.finishVoiceTask(session); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3141 | } finally { |
| 3142 | Binder.restoreCallingIdentity(origId); |
| 3143 | } |
| 3144 | } |
| 3145 | |
| 3146 | } |
| 3147 | |
| 3148 | @Override |
| 3149 | public boolean isTopOfTask(IBinder token) { |
| 3150 | synchronized (mGlobalLock) { |
| 3151 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3152 | return r != null && r.getTask().getTopNonFinishingActivity() == r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3153 | } |
| 3154 | } |
| 3155 | |
| 3156 | @Override |
| 3157 | public void notifyLaunchTaskBehindComplete(IBinder token) { |
| 3158 | mStackSupervisor.scheduleLaunchTaskBehindComplete(token); |
| 3159 | } |
| 3160 | |
| 3161 | @Override |
| 3162 | public void notifyEnterAnimationComplete(IBinder token) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3163 | mH.post(() -> { |
| 3164 | synchronized (mGlobalLock) { |
| 3165 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3166 | if (r != null && r.attachedToProcess()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3167 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3168 | r.app.getThread().scheduleEnterAnimationComplete(r.appToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3169 | } catch (RemoteException e) { |
| 3170 | } |
| 3171 | } |
| 3172 | } |
| 3173 | |
| 3174 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | /** Called from an app when assist data is ready. */ |
| 3178 | @Override |
| 3179 | public void reportAssistContextExtras(IBinder token, Bundle extras, AssistStructure structure, |
| 3180 | AssistContent content, Uri referrer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3181 | PendingAssistExtras pae = (PendingAssistExtras) token; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3182 | synchronized (pae) { |
| 3183 | pae.result = extras; |
| 3184 | pae.structure = structure; |
| 3185 | pae.content = content; |
| 3186 | if (referrer != null) { |
| 3187 | pae.extras.putParcelable(Intent.EXTRA_REFERRER, referrer); |
| 3188 | } |
| 3189 | if (structure != null) { |
Winson Chung | 48b2565 | 2018-10-22 14:04:30 -0700 | [diff] [blame] | 3190 | // Pre-fill the task/activity component for all assist data receivers |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3191 | structure.setTaskId(pae.activity.getTask().mTaskId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3192 | structure.setActivityComponent(pae.activity.mActivityComponent); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3193 | structure.setHomeActivity(pae.isHome); |
| 3194 | } |
| 3195 | pae.haveResult = true; |
| 3196 | pae.notifyAll(); |
| 3197 | if (pae.intent == null && pae.receiver == null) { |
| 3198 | // Caller is just waiting for the result. |
| 3199 | return; |
| 3200 | } |
| 3201 | } |
| 3202 | // We are now ready to launch the assist activity. |
| 3203 | IAssistDataReceiver sendReceiver = null; |
| 3204 | Bundle sendBundle = null; |
| 3205 | synchronized (mGlobalLock) { |
| 3206 | buildAssistBundleLocked(pae, extras); |
| 3207 | boolean exists = mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3208 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3209 | if (!exists) { |
| 3210 | // Timed out. |
| 3211 | return; |
| 3212 | } |
| 3213 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3214 | if ((sendReceiver = pae.receiver) != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3215 | // Caller wants result sent back to them. |
| 3216 | sendBundle = new Bundle(); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3217 | sendBundle.putInt(ActivityTaskManagerInternal.ASSIST_TASK_ID, |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3218 | pae.activity.getTask().mTaskId); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3219 | sendBundle.putBinder(ActivityTaskManagerInternal.ASSIST_ACTIVITY_ID, |
| 3220 | pae.activity.assistToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3221 | sendBundle.putBundle(ASSIST_KEY_DATA, pae.extras); |
| 3222 | sendBundle.putParcelable(ASSIST_KEY_STRUCTURE, pae.structure); |
| 3223 | sendBundle.putParcelable(ASSIST_KEY_CONTENT, pae.content); |
| 3224 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3225 | } |
| 3226 | } |
| 3227 | if (sendReceiver != null) { |
| 3228 | try { |
| 3229 | sendReceiver.onHandleAssistData(sendBundle); |
| 3230 | } catch (RemoteException e) { |
| 3231 | } |
| 3232 | return; |
| 3233 | } |
| 3234 | |
| 3235 | final long ident = Binder.clearCallingIdentity(); |
| 3236 | try { |
| 3237 | if (TextUtils.equals(pae.intent.getAction(), |
| 3238 | android.service.voice.VoiceInteractionService.SERVICE_INTERFACE)) { |
Galia Peycheva | bffbfc3 | 2019-06-18 10:11:35 +0200 | [diff] [blame] | 3239 | // Start voice interaction through VoiceInteractionManagerService. |
Galia Peycheva | 969f995 | 2020-05-11 20:26:45 +0200 | [diff] [blame] | 3240 | mAssistUtils.showSessionForActiveService(pae.extras, SHOW_SOURCE_APPLICATION, |
Galia Peycheva | bffbfc3 | 2019-06-18 10:11:35 +0200 | [diff] [blame] | 3241 | null, null); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3242 | } else { |
| 3243 | pae.intent.replaceExtras(pae.extras); |
| 3244 | pae.intent.setFlags(FLAG_ACTIVITY_NEW_TASK |
| 3245 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 3246 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 3247 | mInternal.closeSystemDialogs("assist"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3248 | |
| 3249 | try { |
| 3250 | mContext.startActivityAsUser(pae.intent, new UserHandle(pae.userHandle)); |
| 3251 | } catch (ActivityNotFoundException e) { |
| 3252 | Slog.w(TAG, "No activity to handle assist action.", e); |
| 3253 | } |
| 3254 | } |
| 3255 | } finally { |
| 3256 | Binder.restoreCallingIdentity(ident); |
| 3257 | } |
| 3258 | } |
| 3259 | |
| 3260 | @Override |
| 3261 | public int addAppTask(IBinder activityToken, Intent intent, |
| 3262 | ActivityManager.TaskDescription description, Bitmap thumbnail) throws RemoteException { |
| 3263 | final int callingUid = Binder.getCallingUid(); |
| 3264 | final long callingIdent = Binder.clearCallingIdentity(); |
| 3265 | |
| 3266 | try { |
| 3267 | synchronized (mGlobalLock) { |
| 3268 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 3269 | if (r == null) { |
| 3270 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 3271 | + activityToken); |
| 3272 | } |
| 3273 | ComponentName comp = intent.getComponent(); |
| 3274 | if (comp == null) { |
| 3275 | throw new IllegalArgumentException("Intent " + intent |
| 3276 | + " must specify explicit component"); |
| 3277 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3278 | if (thumbnail.getWidth() != mThumbnailWidth |
| 3279 | || thumbnail.getHeight() != mThumbnailHeight) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3280 | throw new IllegalArgumentException("Bad thumbnail size: got " |
| 3281 | + thumbnail.getWidth() + "x" + thumbnail.getHeight() + ", require " |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3282 | + mThumbnailWidth + "x" + mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3283 | } |
| 3284 | if (intent.getSelector() != null) { |
| 3285 | intent.setSelector(null); |
| 3286 | } |
| 3287 | if (intent.getSourceBounds() != null) { |
| 3288 | intent.setSourceBounds(null); |
| 3289 | } |
| 3290 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) { |
| 3291 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) == 0) { |
| 3292 | // The caller has added this as an auto-remove task... that makes no |
| 3293 | // sense, so turn off auto-remove. |
| 3294 | intent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS); |
| 3295 | } |
| 3296 | } |
| 3297 | final ActivityInfo ainfo = AppGlobals.getPackageManager().getActivityInfo(comp, |
| 3298 | STOCK_PM_FLAGS, UserHandle.getUserId(callingUid)); |
| 3299 | if (ainfo.applicationInfo.uid != callingUid) { |
| 3300 | throw new SecurityException( |
| 3301 | "Can't add task for another application: target uid=" |
| 3302 | + ainfo.applicationInfo.uid + ", calling uid=" + callingUid); |
| 3303 | } |
| 3304 | |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 3305 | final ActivityStack stack = r.getRootTask(); |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 3306 | final Task task = stack.getDisplayArea().createStack(stack.getWindowingMode(), |
| 3307 | stack.getActivityType(), !ON_TOP, ainfo, intent, |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 3308 | false /* createdByOrganizer */); |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 3309 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3310 | if (!mRecentTasks.addToBottom(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3311 | // 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] | 3312 | stack.removeChild(task, "addAppTask"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3313 | return INVALID_TASK_ID; |
| 3314 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 3315 | task.getTaskDescription().copyFrom(description); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3316 | |
| 3317 | // TODO: Send the thumbnail to WM to store it. |
| 3318 | |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 3319 | return task.mTaskId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3320 | } |
| 3321 | } finally { |
| 3322 | Binder.restoreCallingIdentity(callingIdent); |
| 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | @Override |
| 3327 | public Point getAppTaskThumbnailSize() { |
| 3328 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3329 | return new Point(mThumbnailWidth, mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3330 | } |
| 3331 | } |
| 3332 | |
| 3333 | @Override |
| 3334 | public void setTaskResizeable(int taskId, int resizeableMode) { |
| 3335 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3336 | final Task task = mRootWindowContainer.anyTaskForId( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3337 | taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 3338 | if (task == null) { |
| 3339 | Slog.w(TAG, "setTaskResizeable: taskId=" + taskId + " not found"); |
| 3340 | return; |
| 3341 | } |
| 3342 | task.setResizeMode(resizeableMode); |
| 3343 | } |
| 3344 | } |
| 3345 | |
| 3346 | @Override |
Daichi Hirono | fa23f60 | 2020-05-14 06:15:59 +0000 | [diff] [blame] | 3347 | public boolean resizeTask(int taskId, Rect bounds, int resizeMode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3348 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "resizeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3349 | long ident = Binder.clearCallingIdentity(); |
| 3350 | try { |
| 3351 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3352 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 3353 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3354 | if (task == null) { |
| 3355 | Slog.w(TAG, "resizeTask: taskId=" + taskId + " not found"); |
Daichi Hirono | fa23f60 | 2020-05-14 06:15:59 +0000 | [diff] [blame] | 3356 | return false; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3357 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3358 | if (!task.getWindowConfiguration().canResizeTask()) { |
Daichi Hirono | fa23f60 | 2020-05-14 06:15:59 +0000 | [diff] [blame] | 3359 | Slog.w(TAG, "resizeTask not allowed on task=" + task); |
| 3360 | return false; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3361 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3362 | |
| 3363 | // Reparent the task to the right stack if necessary |
| 3364 | boolean preserveWindow = (resizeMode & RESIZE_MODE_PRESERVE_WINDOW) != 0; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3365 | |
| 3366 | // After reparenting (which only resizes the task to the stack bounds), resize the |
| 3367 | // task to the actual bounds provided |
Daichi Hirono | fa23f60 | 2020-05-14 06:15:59 +0000 | [diff] [blame] | 3368 | return task.resize(bounds, resizeMode, preserveWindow); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3369 | } |
| 3370 | } finally { |
| 3371 | Binder.restoreCallingIdentity(ident); |
| 3372 | } |
| 3373 | } |
| 3374 | |
| 3375 | @Override |
| 3376 | public boolean releaseActivityInstance(IBinder token) { |
| 3377 | synchronized (mGlobalLock) { |
| 3378 | final long origId = Binder.clearCallingIdentity(); |
| 3379 | try { |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 3380 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3381 | if (r == null || !r.isDestroyable()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3382 | return false; |
| 3383 | } |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 3384 | r.destroyImmediately(true /* removeFromApp */, "app-req"); |
| 3385 | return r.isState(DESTROYING, DESTROYED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3386 | } finally { |
| 3387 | Binder.restoreCallingIdentity(origId); |
| 3388 | } |
| 3389 | } |
| 3390 | } |
| 3391 | |
| 3392 | @Override |
| 3393 | public void releaseSomeActivities(IApplicationThread appInt) { |
| 3394 | synchronized (mGlobalLock) { |
| 3395 | final long origId = Binder.clearCallingIdentity(); |
| 3396 | try { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3397 | final WindowProcessController app = getProcessController(appInt); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 3398 | app.releaseSomeActivities("low-mem"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3399 | } finally { |
| 3400 | Binder.restoreCallingIdentity(origId); |
| 3401 | } |
| 3402 | } |
| 3403 | } |
| 3404 | |
| 3405 | @Override |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 3406 | public void setLockScreenShown(boolean keyguardShowing, boolean aodShowing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3407 | if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3408 | != PackageManager.PERMISSION_GRANTED) { |
| 3409 | throw new SecurityException("Requires permission " |
| 3410 | + android.Manifest.permission.DEVICE_POWER); |
| 3411 | } |
| 3412 | |
| 3413 | synchronized (mGlobalLock) { |
| 3414 | long ident = Binder.clearCallingIdentity(); |
| 3415 | if (mKeyguardShown != keyguardShowing) { |
| 3416 | mKeyguardShown = keyguardShowing; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3417 | final Message msg = PooledLambda.obtainMessage( |
| 3418 | ActivityManagerInternal::reportCurKeyguardUsageEvent, mAmInternal, |
| 3419 | keyguardShowing); |
| 3420 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3421 | } |
| 3422 | try { |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 3423 | mKeyguardController.setKeyguardShown(keyguardShowing, aodShowing); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3424 | } finally { |
| 3425 | Binder.restoreCallingIdentity(ident); |
| 3426 | } |
| 3427 | } |
| 3428 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3429 | mH.post(() -> { |
| 3430 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3431 | mScreenObservers.get(i).onKeyguardStateChanged(keyguardShowing); |
| 3432 | } |
| 3433 | }); |
| 3434 | } |
| 3435 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 3436 | public void onScreenAwakeChanged(boolean isAwake) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3437 | mH.post(() -> { |
| 3438 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3439 | mScreenObservers.get(i).onAwakeStateChanged(isAwake); |
| 3440 | } |
| 3441 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3442 | } |
| 3443 | |
| 3444 | @Override |
| 3445 | public Bitmap getTaskDescriptionIcon(String filePath, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3446 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 3447 | userId, "getTaskDescriptionIcon"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3448 | |
| 3449 | final File passedIconFile = new File(filePath); |
| 3450 | final File legitIconFile = new File(TaskPersister.getUserImagesDir(userId), |
| 3451 | passedIconFile.getName()); |
| 3452 | if (!legitIconFile.getPath().equals(filePath) |
| 3453 | || !filePath.contains(ActivityRecord.ACTIVITY_ICON_SUFFIX)) { |
| 3454 | throw new IllegalArgumentException("Bad file path: " + filePath |
| 3455 | + " passed for userId " + userId); |
| 3456 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3457 | return mRecentTasks.getTaskDescriptionIcon(filePath); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3458 | } |
| 3459 | |
| 3460 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3461 | public void removeStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3462 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "removeStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3463 | synchronized (mGlobalLock) { |
| 3464 | final long ident = Binder.clearCallingIdentity(); |
| 3465 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3466 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3467 | if (stack == null) { |
| 3468 | Slog.w(TAG, "removeStack: No stack with id=" + stackId); |
| 3469 | return; |
| 3470 | } |
| 3471 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3472 | throw new IllegalArgumentException( |
| 3473 | "Removing non-standard stack is not allowed."); |
| 3474 | } |
| 3475 | mStackSupervisor.removeStack(stack); |
| 3476 | } finally { |
| 3477 | Binder.restoreCallingIdentity(ident); |
| 3478 | } |
| 3479 | } |
| 3480 | } |
| 3481 | |
| 3482 | @Override |
| 3483 | public void moveStackToDisplay(int stackId, int displayId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3484 | mAmInternal.enforceCallingPermission(INTERNAL_SYSTEM_WINDOW, "moveStackToDisplay()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3485 | |
| 3486 | synchronized (mGlobalLock) { |
| 3487 | final long ident = Binder.clearCallingIdentity(); |
| 3488 | try { |
| 3489 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveStackToDisplay: moving stackId=" + stackId |
| 3490 | + " to displayId=" + displayId); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3491 | mRootWindowContainer.moveStackToDisplay(stackId, displayId, ON_TOP); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3492 | } finally { |
| 3493 | Binder.restoreCallingIdentity(ident); |
| 3494 | } |
| 3495 | } |
| 3496 | } |
| 3497 | |
| 3498 | @Override |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3499 | public void toggleFreeformWindowingMode(IBinder token) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3500 | synchronized (mGlobalLock) { |
| 3501 | long ident = Binder.clearCallingIdentity(); |
| 3502 | try { |
| 3503 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3504 | if (r == null) { |
| 3505 | throw new IllegalArgumentException( |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3506 | "toggleFreeformWindowingMode: No activity record matching token=" |
| 3507 | + token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3508 | } |
| 3509 | |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 3510 | final ActivityStack stack = r.getRootTask(); |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3511 | if (stack == null) { |
| 3512 | throw new IllegalStateException("toggleFreeformWindowingMode: the activity " |
| 3513 | + "doesn't have a stack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3514 | } |
| 3515 | |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3516 | if (!stack.inFreeformWindowingMode() |
| 3517 | && stack.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) { |
| 3518 | throw new IllegalStateException("toggleFreeformWindowingMode: You can only " |
| 3519 | + "toggle between fullscreen and freeform."); |
| 3520 | } |
| 3521 | |
| 3522 | if (stack.inFreeformWindowingMode()) { |
| 3523 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Evan Rosky | 3a8d7fe | 2019-11-06 17:08:35 -0800 | [diff] [blame] | 3524 | } else if (!mSizeCompatFreeform && r.inSizeCompatMode()) { |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 3525 | throw new IllegalStateException("Size-compat windows are currently not" |
| 3526 | + "freeform-enabled"); |
Yunfan Chen | e9c1c31 | 2019-04-18 14:49:15 +0900 | [diff] [blame] | 3527 | } else if (stack.getParent().inFreeformWindowingMode()) { |
| 3528 | // If the window is on a freeform display, set it to undefined. It will be |
| 3529 | // resolved to freeform and it can adjust windowing mode when the display mode |
| 3530 | // changes in runtime. |
| 3531 | stack.setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3532 | } else { |
| 3533 | stack.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 3534 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3535 | } finally { |
| 3536 | Binder.restoreCallingIdentity(ident); |
| 3537 | } |
| 3538 | } |
| 3539 | } |
| 3540 | |
| 3541 | /** Sets the task stack listener that gets callbacks when a task stack changes. */ |
| 3542 | @Override |
| 3543 | public void registerTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3544 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3545 | "registerTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3546 | mTaskChangeNotificationController.registerTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | /** Unregister a task stack listener so that it stops receiving callbacks. */ |
| 3550 | @Override |
| 3551 | public void unregisterTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3552 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3553 | "unregisterTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3554 | mTaskChangeNotificationController.unregisterTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3555 | } |
| 3556 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3557 | @Override |
| 3558 | public boolean requestAssistContextExtras(int requestType, IAssistDataReceiver receiver, |
| 3559 | Bundle receiverExtras, IBinder activityToken, boolean focused, boolean newSessionId) { |
| 3560 | return enqueueAssistContext(requestType, null, null, receiver, receiverExtras, |
| 3561 | activityToken, focused, newSessionId, UserHandle.getCallingUserId(), null, |
| 3562 | PENDING_ASSIST_EXTRAS_LONG_TIMEOUT, 0) != null; |
| 3563 | } |
| 3564 | |
| 3565 | @Override |
| 3566 | public boolean requestAutofillData(IAssistDataReceiver receiver, Bundle receiverExtras, |
| 3567 | IBinder activityToken, int flags) { |
| 3568 | return enqueueAssistContext(ActivityManager.ASSIST_CONTEXT_AUTOFILL, null, null, |
| 3569 | receiver, receiverExtras, activityToken, true, true, UserHandle.getCallingUserId(), |
| 3570 | null, PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT, flags) != null; |
| 3571 | } |
| 3572 | |
| 3573 | @Override |
| 3574 | public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle, |
| 3575 | Bundle args) { |
| 3576 | return enqueueAssistContext(requestType, intent, hint, null, null, null, |
| 3577 | true /* focused */, true /* newSessionId */, userHandle, args, |
| 3578 | PENDING_ASSIST_EXTRAS_TIMEOUT, 0) != null; |
| 3579 | } |
| 3580 | |
| 3581 | @Override |
| 3582 | public Bundle getAssistContextExtras(int requestType) { |
| 3583 | PendingAssistExtras pae = enqueueAssistContext(requestType, null, null, null, |
| 3584 | null, null, true /* focused */, true /* newSessionId */, |
| 3585 | UserHandle.getCallingUserId(), null, PENDING_ASSIST_EXTRAS_TIMEOUT, 0); |
| 3586 | if (pae == null) { |
| 3587 | return null; |
| 3588 | } |
| 3589 | synchronized (pae) { |
| 3590 | while (!pae.haveResult) { |
| 3591 | try { |
| 3592 | pae.wait(); |
| 3593 | } catch (InterruptedException e) { |
| 3594 | } |
| 3595 | } |
| 3596 | } |
| 3597 | synchronized (mGlobalLock) { |
| 3598 | buildAssistBundleLocked(pae, pae.result); |
| 3599 | mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3600 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3601 | } |
| 3602 | return pae.extras; |
| 3603 | } |
| 3604 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3605 | /** |
| 3606 | * Binder IPC calls go through the public entry point. |
| 3607 | * This can be called with or without the global lock held. |
| 3608 | */ |
| 3609 | private static int checkCallingPermission(String permission) { |
| 3610 | return checkPermission( |
| 3611 | permission, Binder.getCallingPid(), UserHandle.getAppId(Binder.getCallingUid())); |
| 3612 | } |
| 3613 | |
| 3614 | /** This can be called with or without the global lock held. */ |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3615 | private void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3616 | if (!getRecentTasks().isCallerRecents(Binder.getCallingUid())) { |
| 3617 | mAmInternal.enforceCallingPermission(permission, func); |
| 3618 | } |
| 3619 | } |
| 3620 | |
| 3621 | @VisibleForTesting |
| 3622 | int checkGetTasksPermission(String permission, int pid, int uid) { |
| 3623 | return checkPermission(permission, pid, uid); |
| 3624 | } |
| 3625 | |
| 3626 | static int checkPermission(String permission, int pid, int uid) { |
| 3627 | if (permission == null) { |
| 3628 | return PackageManager.PERMISSION_DENIED; |
| 3629 | } |
| 3630 | return checkComponentPermission(permission, pid, uid, -1, true); |
| 3631 | } |
| 3632 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3633 | public static int checkComponentPermission(String permission, int pid, int uid, |
| 3634 | int owningUid, boolean exported) { |
| 3635 | return ActivityManagerService.checkComponentPermission( |
| 3636 | permission, pid, uid, owningUid, exported); |
| 3637 | } |
| 3638 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3639 | boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 3640 | if (getRecentTasks().isCallerRecents(callingUid)) { |
| 3641 | // Always allow the recents component to get tasks |
| 3642 | return true; |
| 3643 | } |
| 3644 | |
| 3645 | boolean allowed = checkGetTasksPermission(android.Manifest.permission.REAL_GET_TASKS, |
| 3646 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED; |
| 3647 | if (!allowed) { |
| 3648 | if (checkGetTasksPermission(android.Manifest.permission.GET_TASKS, |
| 3649 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED) { |
| 3650 | // Temporary compatibility: some existing apps on the system image may |
| 3651 | // still be requesting the old permission and not switched to the new |
| 3652 | // one; if so, we'll still allow them full access. This means we need |
| 3653 | // to see if they are holding the old permission and are a system app. |
| 3654 | try { |
| 3655 | if (AppGlobals.getPackageManager().isUidPrivileged(callingUid)) { |
| 3656 | allowed = true; |
| 3657 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3658 | + " is using old GET_TASKS but privileged; allowing"); |
| 3659 | } |
| 3660 | } catch (RemoteException e) { |
| 3661 | } |
| 3662 | } |
| 3663 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3664 | + " does not hold REAL_GET_TASKS; limiting output"); |
| 3665 | } |
| 3666 | return allowed; |
| 3667 | } |
| 3668 | |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 3669 | boolean isCrossUserAllowed(int pid, int uid) { |
| 3670 | return checkPermission(INTERACT_ACROSS_USERS, pid, uid) == PERMISSION_GRANTED |
| 3671 | || checkPermission(INTERACT_ACROSS_USERS_FULL, pid, uid) == PERMISSION_GRANTED; |
| 3672 | } |
| 3673 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3674 | private PendingAssistExtras enqueueAssistContext(int requestType, Intent intent, String hint, |
| 3675 | IAssistDataReceiver receiver, Bundle receiverExtras, IBinder activityToken, |
| 3676 | boolean focused, boolean newSessionId, int userHandle, Bundle args, long timeout, |
| 3677 | int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3678 | mAmInternal.enforceCallingPermission(android.Manifest.permission.GET_TOP_ACTIVITY_INFO, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3679 | "enqueueAssistContext()"); |
| 3680 | |
| 3681 | synchronized (mGlobalLock) { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 3682 | final ActivityStack stack = getTopDisplayFocusedStack(); |
| 3683 | ActivityRecord activity = stack != null ? stack.getTopNonFinishingActivity() : null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3684 | if (activity == null) { |
| 3685 | Slog.w(TAG, "getAssistContextExtras failed: no top activity"); |
| 3686 | return null; |
| 3687 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3688 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3689 | Slog.w(TAG, "getAssistContextExtras failed: no process for " + activity); |
| 3690 | return null; |
| 3691 | } |
| 3692 | if (focused) { |
| 3693 | if (activityToken != null) { |
| 3694 | ActivityRecord caller = ActivityRecord.forTokenLocked(activityToken); |
| 3695 | if (activity != caller) { |
| 3696 | Slog.w(TAG, "enqueueAssistContext failed: caller " + caller |
| 3697 | + " is not current top " + activity); |
| 3698 | return null; |
| 3699 | } |
| 3700 | } |
| 3701 | } else { |
| 3702 | activity = ActivityRecord.forTokenLocked(activityToken); |
| 3703 | if (activity == null) { |
| 3704 | Slog.w(TAG, "enqueueAssistContext failed: activity for token=" + activityToken |
| 3705 | + " couldn't be found"); |
| 3706 | return null; |
| 3707 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3708 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3709 | Slog.w(TAG, "enqueueAssistContext failed: no process for " + activity); |
| 3710 | return null; |
| 3711 | } |
| 3712 | } |
| 3713 | |
| 3714 | PendingAssistExtras pae; |
| 3715 | Bundle extras = new Bundle(); |
| 3716 | if (args != null) { |
| 3717 | extras.putAll(args); |
| 3718 | } |
| 3719 | extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3720 | extras.putInt(Intent.EXTRA_ASSIST_UID, activity.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3721 | |
| 3722 | pae = new PendingAssistExtras(activity, extras, intent, hint, receiver, receiverExtras, |
| 3723 | userHandle); |
| 3724 | pae.isHome = activity.isActivityTypeHome(); |
| 3725 | |
| 3726 | // Increment the sessionId if necessary |
| 3727 | if (newSessionId) { |
| 3728 | mViSessionId++; |
| 3729 | } |
| 3730 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3731 | activity.app.getThread().requestAssistContextExtras(activity.appToken, pae, |
| 3732 | requestType, mViSessionId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3733 | mPendingAssistExtras.add(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3734 | mUiHandler.postDelayed(pae, timeout); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3735 | } catch (RemoteException e) { |
| 3736 | Slog.w(TAG, "getAssistContextExtras failed: crash calling " + activity); |
| 3737 | return null; |
| 3738 | } |
| 3739 | return pae; |
| 3740 | } |
| 3741 | } |
| 3742 | |
| 3743 | private void buildAssistBundleLocked(PendingAssistExtras pae, Bundle result) { |
| 3744 | if (result != null) { |
| 3745 | pae.extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, result); |
| 3746 | } |
| 3747 | if (pae.hint != null) { |
| 3748 | pae.extras.putBoolean(pae.hint, true); |
| 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | private void pendingAssistExtrasTimedOut(PendingAssistExtras pae) { |
| 3753 | IAssistDataReceiver receiver; |
| 3754 | synchronized (mGlobalLock) { |
| 3755 | mPendingAssistExtras.remove(pae); |
| 3756 | receiver = pae.receiver; |
| 3757 | } |
| 3758 | if (receiver != null) { |
| 3759 | // Caller wants result sent back to them. |
| 3760 | Bundle sendBundle = new Bundle(); |
| 3761 | // At least return the receiver extras |
| 3762 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3763 | try { |
| 3764 | pae.receiver.onHandleAssistData(sendBundle); |
| 3765 | } catch (RemoteException e) { |
| 3766 | } |
| 3767 | } |
| 3768 | } |
| 3769 | |
| 3770 | public class PendingAssistExtras extends Binder implements Runnable { |
| 3771 | public final ActivityRecord activity; |
| 3772 | public boolean isHome; |
| 3773 | public final Bundle extras; |
| 3774 | public final Intent intent; |
| 3775 | public final String hint; |
| 3776 | public final IAssistDataReceiver receiver; |
| 3777 | public final int userHandle; |
| 3778 | public boolean haveResult = false; |
| 3779 | public Bundle result = null; |
| 3780 | public AssistStructure structure = null; |
| 3781 | public AssistContent content = null; |
| 3782 | public Bundle receiverExtras; |
| 3783 | |
| 3784 | public PendingAssistExtras(ActivityRecord _activity, Bundle _extras, Intent _intent, |
| 3785 | String _hint, IAssistDataReceiver _receiver, Bundle _receiverExtras, |
| 3786 | int _userHandle) { |
| 3787 | activity = _activity; |
| 3788 | extras = _extras; |
| 3789 | intent = _intent; |
| 3790 | hint = _hint; |
| 3791 | receiver = _receiver; |
| 3792 | receiverExtras = _receiverExtras; |
| 3793 | userHandle = _userHandle; |
| 3794 | } |
| 3795 | |
| 3796 | @Override |
| 3797 | public void run() { |
| 3798 | Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from " + activity); |
| 3799 | synchronized (this) { |
| 3800 | haveResult = true; |
| 3801 | notifyAll(); |
| 3802 | } |
| 3803 | pendingAssistExtrasTimedOut(this); |
| 3804 | } |
| 3805 | } |
| 3806 | |
| 3807 | @Override |
| 3808 | public boolean isAssistDataAllowedOnCurrentActivity() { |
| 3809 | int userId; |
| 3810 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3811 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3812 | if (focusedStack == null || focusedStack.isActivityTypeAssistant()) { |
| 3813 | return false; |
| 3814 | } |
| 3815 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3816 | final ActivityRecord activity = focusedStack.getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3817 | if (activity == null) { |
| 3818 | return false; |
| 3819 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3820 | userId = activity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3821 | } |
| 3822 | return !DevicePolicyCache.getInstance().getScreenCaptureDisabled(userId); |
| 3823 | } |
| 3824 | |
| 3825 | @Override |
| 3826 | public boolean showAssistFromActivity(IBinder token, Bundle args) { |
| 3827 | long ident = Binder.clearCallingIdentity(); |
| 3828 | try { |
| 3829 | synchronized (mGlobalLock) { |
| 3830 | ActivityRecord caller = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3831 | ActivityRecord top = getTopDisplayFocusedStack().getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3832 | if (top != caller) { |
| 3833 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3834 | + " is not current top " + top); |
| 3835 | return false; |
| 3836 | } |
| 3837 | if (!top.nowVisible) { |
| 3838 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3839 | + " is not visible"); |
| 3840 | return false; |
| 3841 | } |
| 3842 | } |
| 3843 | return mAssistUtils.showSessionForActiveService(args, SHOW_SOURCE_APPLICATION, null, |
| 3844 | token); |
| 3845 | } finally { |
| 3846 | Binder.restoreCallingIdentity(ident); |
| 3847 | } |
| 3848 | } |
| 3849 | |
| 3850 | @Override |
| 3851 | public boolean isRootVoiceInteraction(IBinder token) { |
| 3852 | synchronized (mGlobalLock) { |
| 3853 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3854 | if (r == null) { |
| 3855 | return false; |
| 3856 | } |
| 3857 | return r.rootVoiceInteraction; |
| 3858 | } |
| 3859 | } |
| 3860 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3861 | private void onLocalVoiceInteractionStartedLocked(IBinder activity, |
| 3862 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 3863 | ActivityRecord activityToCallback = ActivityRecord.forTokenLocked(activity); |
| 3864 | if (activityToCallback == null) return; |
| 3865 | activityToCallback.setVoiceSessionLocked(voiceSession); |
| 3866 | |
| 3867 | // Inform the activity |
| 3868 | try { |
| 3869 | activityToCallback.app.getThread().scheduleLocalVoiceInteractionStarted(activity, |
| 3870 | voiceInteractor); |
| 3871 | long token = Binder.clearCallingIdentity(); |
| 3872 | try { |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 3873 | startRunningVoiceLocked(voiceSession, activityToCallback.info.applicationInfo.uid); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3874 | } finally { |
| 3875 | Binder.restoreCallingIdentity(token); |
| 3876 | } |
| 3877 | // TODO: VI Should we cache the activity so that it's easier to find later |
| 3878 | // rather than scan through all the stacks and activities? |
| 3879 | } catch (RemoteException re) { |
| 3880 | activityToCallback.clearVoiceSessionLocked(); |
| 3881 | // TODO: VI Should this terminate the voice session? |
| 3882 | } |
| 3883 | } |
| 3884 | |
| 3885 | private void startRunningVoiceLocked(IVoiceInteractionSession session, int targetUid) { |
| 3886 | Slog.d(TAG, "<<< startRunningVoiceLocked()"); |
| 3887 | mVoiceWakeLock.setWorkSource(new WorkSource(targetUid)); |
| 3888 | if (mRunningVoice == null || mRunningVoice.asBinder() != session.asBinder()) { |
| 3889 | boolean wasRunningVoice = mRunningVoice != null; |
| 3890 | mRunningVoice = session; |
| 3891 | if (!wasRunningVoice) { |
| 3892 | mVoiceWakeLock.acquire(); |
| 3893 | updateSleepIfNeededLocked(); |
| 3894 | } |
| 3895 | } |
| 3896 | } |
| 3897 | |
| 3898 | void finishRunningVoiceLocked() { |
| 3899 | if (mRunningVoice != null) { |
| 3900 | mRunningVoice = null; |
| 3901 | mVoiceWakeLock.release(); |
| 3902 | updateSleepIfNeededLocked(); |
| 3903 | } |
| 3904 | } |
| 3905 | |
| 3906 | @Override |
| 3907 | public void setVoiceKeepAwake(IVoiceInteractionSession session, boolean keepAwake) { |
| 3908 | synchronized (mGlobalLock) { |
| 3909 | if (mRunningVoice != null && mRunningVoice.asBinder() == session.asBinder()) { |
| 3910 | if (keepAwake) { |
| 3911 | mVoiceWakeLock.acquire(); |
| 3912 | } else { |
| 3913 | mVoiceWakeLock.release(); |
| 3914 | } |
| 3915 | } |
| 3916 | } |
| 3917 | } |
| 3918 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3919 | @Override |
| 3920 | public ComponentName getActivityClassForToken(IBinder token) { |
| 3921 | synchronized (mGlobalLock) { |
| 3922 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3923 | if (r == null) { |
| 3924 | return null; |
| 3925 | } |
| 3926 | return r.intent.getComponent(); |
| 3927 | } |
| 3928 | } |
| 3929 | |
| 3930 | @Override |
| 3931 | public String getPackageForToken(IBinder token) { |
| 3932 | synchronized (mGlobalLock) { |
| 3933 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3934 | if (r == null) { |
| 3935 | return null; |
| 3936 | } |
| 3937 | return r.packageName; |
| 3938 | } |
| 3939 | } |
| 3940 | |
| 3941 | @Override |
| 3942 | public void showLockTaskEscapeMessage(IBinder token) { |
| 3943 | synchronized (mGlobalLock) { |
| 3944 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3945 | if (r == null) { |
| 3946 | return; |
| 3947 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3948 | getLockTaskController().showLockTaskToast(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3949 | } |
| 3950 | } |
| 3951 | |
| 3952 | @Override |
| 3953 | public void keyguardGoingAway(int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3954 | enforceNotIsolatedCaller("keyguardGoingAway"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3955 | final long token = Binder.clearCallingIdentity(); |
| 3956 | try { |
| 3957 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3958 | mKeyguardController.keyguardGoingAway(flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3959 | } |
| 3960 | } finally { |
| 3961 | Binder.restoreCallingIdentity(token); |
| 3962 | } |
| 3963 | } |
| 3964 | |
| 3965 | /** |
| 3966 | * Try to place task to provided position. The final position might be different depending on |
| 3967 | * current user and stacks state. The task will be moved to target stack if it's currently in |
| 3968 | * different stack. |
| 3969 | */ |
| 3970 | @Override |
| 3971 | public void positionTaskInStack(int taskId, int stackId, int position) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3972 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "positionTaskInStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3973 | synchronized (mGlobalLock) { |
| 3974 | long ident = Binder.clearCallingIdentity(); |
| 3975 | try { |
| 3976 | if (DEBUG_STACK) Slog.d(TAG_STACK, "positionTaskInStack: positioning task=" |
| 3977 | + taskId + " in stackId=" + stackId + " at position=" + position); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3978 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3979 | if (task == null) { |
| 3980 | throw new IllegalArgumentException("positionTaskInStack: no task for id=" |
| 3981 | + taskId); |
| 3982 | } |
| 3983 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3984 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3985 | |
| 3986 | if (stack == null) { |
| 3987 | throw new IllegalArgumentException("positionTaskInStack: no stack for id=" |
| 3988 | + stackId); |
| 3989 | } |
| 3990 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3991 | throw new IllegalArgumentException("positionTaskInStack: Attempt to change" |
| 3992 | + " the position of task " + taskId + " in/to non-standard stack"); |
| 3993 | } |
| 3994 | |
| 3995 | // TODO: Have the callers of this API call a separate reparent method if that is |
| 3996 | // what they intended to do vs. having this method also do reparenting. |
| 3997 | if (task.getStack() == stack) { |
| 3998 | // Change position in current stack. |
| 3999 | stack.positionChildAt(task, position); |
| 4000 | } else { |
| 4001 | // Reparent to new stack. |
| 4002 | task.reparent(stack, position, REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, |
| 4003 | !DEFER_RESUME, "positionTaskInStack"); |
| 4004 | } |
| 4005 | } finally { |
| 4006 | Binder.restoreCallingIdentity(ident); |
| 4007 | } |
| 4008 | } |
| 4009 | } |
| 4010 | |
| 4011 | @Override |
| 4012 | public void reportSizeConfigurations(IBinder token, int[] horizontalSizeConfiguration, |
| 4013 | int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { |
| 4014 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Report configuration: " + token + " " |
Yuichiro Hanada | e7e930b | 2019-06-06 19:07:21 +0900 | [diff] [blame] | 4015 | + Arrays.toString(horizontalSizeConfiguration) + " " |
| 4016 | + Arrays.toString(verticalSizeConfigurations)); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4017 | synchronized (mGlobalLock) { |
| 4018 | ActivityRecord record = ActivityRecord.isInStackLocked(token); |
| 4019 | if (record == null) { |
| 4020 | throw new IllegalArgumentException("reportSizeConfigurations: ActivityRecord not " |
| 4021 | + "found for: " + token); |
| 4022 | } |
| 4023 | record.setSizeConfigurations(horizontalSizeConfiguration, |
| 4024 | verticalSizeConfigurations, smallestSizeConfigurations); |
| 4025 | } |
| 4026 | } |
| 4027 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4028 | @Override |
| 4029 | public void suppressResizeConfigChanges(boolean suppress) throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4030 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "suppressResizeConfigChanges()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4031 | synchronized (mGlobalLock) { |
| 4032 | mSuppressResizeConfigChanges = suppress; |
| 4033 | } |
| 4034 | } |
| 4035 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4036 | /** |
| 4037 | * Moves the top activity in the input stackId to the pinned stack. |
| 4038 | * |
| 4039 | * @param stackId Id of stack to move the top activity to pinned stack. |
| 4040 | * @param bounds Bounds to use for pinned stack. |
| 4041 | * |
| 4042 | * @return True if the top activity of the input stack was successfully moved to the pinned |
| 4043 | * stack. |
| 4044 | */ |
| 4045 | @Override |
| 4046 | public boolean moveTopActivityToPinnedStack(int stackId, Rect bounds) { |
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 | "moveTopActivityToPinnedStack()"); |
| 4049 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4050 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4051 | throw new IllegalStateException("moveTopActivityToPinnedStack:" |
| 4052 | + "Device doesn't support picture-in-picture mode"); |
| 4053 | } |
| 4054 | |
| 4055 | long ident = Binder.clearCallingIdentity(); |
| 4056 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4057 | return mRootWindowContainer.moveTopStackActivityToPinnedStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4058 | } finally { |
| 4059 | Binder.restoreCallingIdentity(ident); |
| 4060 | } |
| 4061 | } |
| 4062 | } |
| 4063 | |
Hongwei Wang | 5711b8f | 2019-11-15 15:44:12 -0800 | [diff] [blame] | 4064 | @VisibleForTesting |
| 4065 | boolean isInPictureInPictureMode(ActivityRecord r) { |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 4066 | return r != null |
| 4067 | && r.getRootTask() != null |
| 4068 | && r.inPinnedWindowingMode() |
Wale Ogunwale | 0db64ac | 2020-04-11 10:00:42 -0700 | [diff] [blame] | 4069 | && r.getRootTask().isInTask(r) != null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | @Override |
| 4073 | public boolean enterPictureInPictureMode(IBinder token, final PictureInPictureParams params) { |
| 4074 | final long origId = Binder.clearCallingIdentity(); |
| 4075 | try { |
| 4076 | synchronized (mGlobalLock) { |
| 4077 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 4078 | "enterPictureInPictureMode", token, params); |
| 4079 | |
| 4080 | // If the activity is already in picture in picture mode, then just return early |
| 4081 | if (isInPictureInPictureMode(r)) { |
| 4082 | return true; |
| 4083 | } |
| 4084 | |
| 4085 | // Activity supports picture-in-picture, now check that we can enter PiP at this |
| 4086 | // point, if it is |
| 4087 | if (!r.checkEnterPictureInPictureState("enterPictureInPictureMode", |
| 4088 | false /* beforeStopping */)) { |
| 4089 | return false; |
| 4090 | } |
| 4091 | |
| 4092 | final Runnable enterPipRunnable = () -> { |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4093 | synchronized (mGlobalLock) { |
Hyangseok Chae | ed0624e | 2019-11-07 10:15:46 +0900 | [diff] [blame] | 4094 | if (r.getParent() == null) { |
| 4095 | Slog.e(TAG, "Skip enterPictureInPictureMode, destroyed " + r); |
| 4096 | return; |
| 4097 | } |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4098 | // Only update the saved args from the args that are set |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 4099 | r.setPictureInPictureParams(params); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4100 | final float aspectRatio = r.pictureInPictureArgs.getAspectRatio(); |
| 4101 | final List<RemoteAction> actions = r.pictureInPictureArgs.getActions(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4102 | mRootWindowContainer.moveActivityToPinnedStack( |
Hongwei Wang | e8e3286 | 2020-04-08 13:23:45 -0700 | [diff] [blame] | 4103 | r, "enterPictureInPictureMode"); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 4104 | final ActivityStack stack = r.getRootTask(); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4105 | stack.setPictureInPictureAspectRatio(aspectRatio); |
| 4106 | stack.setPictureInPictureActions(actions); |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 4107 | MetricsLoggerWrapper.logPictureInPictureEnter(mContext, |
| 4108 | r.info.applicationInfo.uid, r.shortComponentName, |
| 4109 | r.supportsEnterPipOnTaskSwitch); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4110 | logPictureInPictureArgs(params); |
| 4111 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4112 | }; |
| 4113 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4114 | if (isKeyguardLocked()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4115 | // If the keyguard is showing or occluded, then try and dismiss it before |
| 4116 | // entering picture-in-picture (this will prompt the user to authenticate if the |
| 4117 | // device is currently locked). |
| 4118 | dismissKeyguard(token, new KeyguardDismissCallback() { |
| 4119 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4120 | public void onDismissSucceeded() { |
| 4121 | mH.post(enterPipRunnable); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4122 | } |
| 4123 | }, null /* message */); |
| 4124 | } else { |
| 4125 | // Enter picture in picture immediately otherwise |
| 4126 | enterPipRunnable.run(); |
| 4127 | } |
| 4128 | return true; |
| 4129 | } |
| 4130 | } finally { |
| 4131 | Binder.restoreCallingIdentity(origId); |
| 4132 | } |
| 4133 | } |
| 4134 | |
| 4135 | @Override |
| 4136 | public void setPictureInPictureParams(IBinder token, final PictureInPictureParams params) { |
| 4137 | final long origId = Binder.clearCallingIdentity(); |
| 4138 | try { |
| 4139 | synchronized (mGlobalLock) { |
| 4140 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 4141 | "setPictureInPictureParams", token, params); |
| 4142 | |
| 4143 | // Only update the saved args from the args that are set |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 4144 | r.setPictureInPictureParams(params); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4145 | if (r.inPinnedWindowingMode()) { |
| 4146 | // If the activity is already in picture-in-picture, update the pinned stack now |
| 4147 | // if it is not already expanding to fullscreen. Otherwise, the arguments will |
| 4148 | // be used the next time the activity enters PiP |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 4149 | final ActivityStack stack = r.getRootTask(); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 4150 | stack.setPictureInPictureAspectRatio( |
| 4151 | r.pictureInPictureArgs.getAspectRatio()); |
| 4152 | stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4153 | } |
| 4154 | logPictureInPictureArgs(params); |
| 4155 | } |
| 4156 | } finally { |
| 4157 | Binder.restoreCallingIdentity(origId); |
| 4158 | } |
| 4159 | } |
| 4160 | |
| 4161 | @Override |
| 4162 | public int getMaxNumPictureInPictureActions(IBinder token) { |
| 4163 | // Currently, this is a static constant, but later, we may change this to be dependent on |
| 4164 | // the context of the activity |
| 4165 | return 3; |
| 4166 | } |
| 4167 | |
| 4168 | private void logPictureInPictureArgs(PictureInPictureParams params) { |
| 4169 | if (params.hasSetActions()) { |
| 4170 | MetricsLogger.histogram(mContext, "tron_varz_picture_in_picture_actions_count", |
| 4171 | params.getActions().size()); |
| 4172 | } |
| 4173 | if (params.hasSetAspectRatio()) { |
| 4174 | LogMaker lm = new LogMaker(MetricsEvent.ACTION_PICTURE_IN_PICTURE_ASPECT_RATIO_CHANGED); |
| 4175 | lm.addTaggedData(MetricsEvent.PICTURE_IN_PICTURE_ASPECT_RATIO, params.getAspectRatio()); |
| 4176 | MetricsLogger.action(lm); |
| 4177 | } |
| 4178 | } |
| 4179 | |
| 4180 | /** |
| 4181 | * Checks the state of the system and the activity associated with the given {@param token} to |
| 4182 | * verify that picture-in-picture is supported for that activity. |
| 4183 | * |
| 4184 | * @return the activity record for the given {@param token} if all the checks pass. |
| 4185 | */ |
| 4186 | private ActivityRecord ensureValidPictureInPictureActivityParamsLocked(String caller, |
| 4187 | IBinder token, PictureInPictureParams params) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4188 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4189 | throw new IllegalStateException(caller |
| 4190 | + ": Device doesn't support picture-in-picture mode."); |
| 4191 | } |
| 4192 | |
| 4193 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 4194 | if (r == null) { |
| 4195 | throw new IllegalStateException(caller |
| 4196 | + ": Can't find activity for token=" + token); |
| 4197 | } |
| 4198 | |
| 4199 | if (!r.supportsPictureInPicture()) { |
| 4200 | throw new IllegalStateException(caller |
| 4201 | + ": Current activity does not support picture-in-picture."); |
| 4202 | } |
| 4203 | |
| 4204 | if (params.hasSetAspectRatio() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4205 | && !mWindowManager.isValidPictureInPictureAspectRatio( |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 4206 | r.getDisplay(), params.getAspectRatio())) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4207 | final float minAspectRatio = mContext.getResources().getFloat( |
| 4208 | com.android.internal.R.dimen.config_pictureInPictureMinAspectRatio); |
| 4209 | final float maxAspectRatio = mContext.getResources().getFloat( |
| 4210 | com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio); |
| 4211 | throw new IllegalArgumentException(String.format(caller |
| 4212 | + ": Aspect ratio is too extreme (must be between %f and %f).", |
| 4213 | minAspectRatio, maxAspectRatio)); |
| 4214 | } |
| 4215 | |
| 4216 | // Truncate the number of actions if necessary |
| 4217 | params.truncateActions(getMaxNumPictureInPictureActions(token)); |
| 4218 | |
| 4219 | return r; |
| 4220 | } |
| 4221 | |
| 4222 | @Override |
| 4223 | public IBinder getUriPermissionOwnerForActivity(IBinder activityToken) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4224 | enforceNotIsolatedCaller("getUriPermissionOwnerForActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4225 | synchronized (mGlobalLock) { |
| 4226 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 4227 | if (r == null) { |
| 4228 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 4229 | + activityToken); |
| 4230 | } |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 4231 | return r.getUriPermissionsLocked().getExternalToken(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4232 | } |
| 4233 | } |
| 4234 | |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 4235 | // TODO(b/149338177): remove when CTS no-longer requires it |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4236 | @Override |
| 4237 | public void resizeDockedStack(Rect dockedBounds, Rect tempDockedTaskBounds, |
| 4238 | Rect tempDockedTaskInsetBounds, |
| 4239 | Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4240 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeDockedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4241 | long ident = Binder.clearCallingIdentity(); |
| 4242 | try { |
| 4243 | synchronized (mGlobalLock) { |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 4244 | final TaskDisplayArea tc = mRootWindowContainer.getDefaultTaskDisplayArea(); |
| 4245 | final Task primary = tc.getRootSplitScreenPrimaryTask(); |
| 4246 | final Task secondary = tc.getTask(t -> t.mCreatedByOrganizer && t.isRootTask() |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 4247 | && t.inSplitScreenSecondaryWindowingMode()); |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 4248 | if (primary == null || secondary == null) { |
| 4249 | return; |
| 4250 | } |
| 4251 | final WindowContainerTransaction wct = new WindowContainerTransaction(); |
| 4252 | final Rect primaryRect = |
| 4253 | tempDockedTaskInsetBounds != null ? tempDockedTaskInsetBounds |
| 4254 | : (tempDockedTaskBounds != null ? tempDockedTaskBounds |
| 4255 | : dockedBounds); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 4256 | wct.setBounds(primary.mRemoteToken.toWindowContainerToken(), primaryRect); |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 4257 | Rect otherRect = tempOtherTaskInsetBounds != null ? tempOtherTaskInsetBounds |
| 4258 | : tempOtherTaskBounds; |
| 4259 | if (otherRect == null) { |
| 4260 | // Temporary estimation... again this is just for tests. |
| 4261 | otherRect = new Rect(secondary.getBounds()); |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 4262 | if (tc.getBounds().width() > tc.getBounds().height()) { |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 4263 | otherRect.left = primaryRect.right + 6; |
| 4264 | } else { |
| 4265 | otherRect.top = primaryRect.bottom + 6; |
| 4266 | } |
| 4267 | } |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 4268 | wct.setBounds(secondary.mRemoteToken.toWindowContainerToken(), otherRect); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 4269 | mWindowOrganizerController.applyTransaction(wct); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4270 | } |
| 4271 | } finally { |
| 4272 | Binder.restoreCallingIdentity(ident); |
| 4273 | } |
| 4274 | } |
| 4275 | |
| 4276 | @Override |
| 4277 | public void setSplitScreenResizing(boolean resizing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4278 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setSplitScreenResizing()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4279 | final long ident = Binder.clearCallingIdentity(); |
| 4280 | try { |
| 4281 | synchronized (mGlobalLock) { |
| 4282 | mStackSupervisor.setSplitScreenResizing(resizing); |
| 4283 | } |
| 4284 | } finally { |
| 4285 | Binder.restoreCallingIdentity(ident); |
| 4286 | } |
| 4287 | } |
| 4288 | |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 4289 | @Override |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 4290 | public IWindowOrganizerController getWindowOrganizerController() { |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 4291 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 4292 | "getWindowOrganizerController()"); |
| 4293 | return mWindowOrganizerController; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 4294 | } |
| 4295 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4296 | /** |
| 4297 | * Check that we have the features required for VR-related API calls, and throw an exception if |
| 4298 | * not. |
| 4299 | */ |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 4300 | public void enforceSystemHasVrFeature() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4301 | if (!mContext.getPackageManager().hasSystemFeature( |
| 4302 | PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE)) { |
| 4303 | throw new UnsupportedOperationException("VR mode not supported on this device!"); |
| 4304 | } |
| 4305 | } |
| 4306 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4307 | @Override |
| 4308 | public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4309 | enforceSystemHasVrFeature(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4310 | |
| 4311 | final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class); |
| 4312 | |
| 4313 | ActivityRecord r; |
| 4314 | synchronized (mGlobalLock) { |
| 4315 | r = ActivityRecord.isInStackLocked(token); |
| 4316 | } |
| 4317 | |
| 4318 | if (r == null) { |
| 4319 | throw new IllegalArgumentException(); |
| 4320 | } |
| 4321 | |
| 4322 | int err; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4323 | if ((err = vrService.hasVrPackage(packageName, r.mUserId)) != |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4324 | VrManagerInternal.NO_ERROR) { |
| 4325 | return err; |
| 4326 | } |
| 4327 | |
| 4328 | // Clear the binder calling uid since this path may call moveToTask(). |
| 4329 | final long callingId = Binder.clearCallingIdentity(); |
| 4330 | try { |
| 4331 | synchronized (mGlobalLock) { |
| 4332 | r.requestedVrComponent = (enabled) ? packageName : null; |
| 4333 | |
| 4334 | // Update associated state if this activity is currently focused |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 4335 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4336 | applyUpdateVrModeLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4337 | } |
| 4338 | return 0; |
| 4339 | } |
| 4340 | } finally { |
| 4341 | Binder.restoreCallingIdentity(callingId); |
| 4342 | } |
| 4343 | } |
| 4344 | |
| 4345 | @Override |
| 4346 | public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) { |
| 4347 | Slog.i(TAG, "Activity tried to startLocalVoiceInteraction"); |
| 4348 | synchronized (mGlobalLock) { |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 4349 | ActivityRecord activity = getTopDisplayFocusedStack().getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4350 | if (ActivityRecord.forTokenLocked(callingActivity) != activity) { |
| 4351 | throw new SecurityException("Only focused activity can call startVoiceInteraction"); |
| 4352 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4353 | if (mRunningVoice != null || activity.getTask().voiceSession != null |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4354 | || activity.voiceSession != null) { |
| 4355 | Slog.w(TAG, "Already in a voice interaction, cannot start new voice interaction"); |
| 4356 | return; |
| 4357 | } |
| 4358 | if (activity.pendingVoiceInteractionStart) { |
| 4359 | Slog.w(TAG, "Pending start of voice interaction already."); |
| 4360 | return; |
| 4361 | } |
| 4362 | activity.pendingVoiceInteractionStart = true; |
| 4363 | } |
| 4364 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4365 | .startLocalVoiceInteraction(callingActivity, options); |
| 4366 | } |
| 4367 | |
| 4368 | @Override |
| 4369 | public void stopLocalVoiceInteraction(IBinder callingActivity) { |
| 4370 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4371 | .stopLocalVoiceInteraction(callingActivity); |
| 4372 | } |
| 4373 | |
| 4374 | @Override |
| 4375 | public boolean supportsLocalVoiceInteraction() { |
| 4376 | return LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4377 | .supportsLocalVoiceInteraction(); |
| 4378 | } |
| 4379 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4380 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4381 | public boolean updateConfiguration(Configuration values) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4382 | mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateConfiguration()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4383 | |
| 4384 | synchronized (mGlobalLock) { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 4385 | if (mWindowManager == null) { |
| 4386 | Slog.w(TAG, "Skip updateConfiguration because mWindowManager isn't set"); |
| 4387 | return false; |
| 4388 | } |
| 4389 | |
| 4390 | if (values == null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4391 | // sentinel: fetch the current configuration from the window manager |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4392 | values = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4393 | } |
| 4394 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 4395 | mH.sendMessage(PooledLambda.obtainMessage( |
| 4396 | ActivityManagerInternal::updateOomLevelsForDisplay, mAmInternal, |
| 4397 | DEFAULT_DISPLAY)); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4398 | |
| 4399 | final long origId = Binder.clearCallingIdentity(); |
| 4400 | try { |
| 4401 | if (values != null) { |
| 4402 | Settings.System.clearConfiguration(values); |
| 4403 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4404 | updateConfigurationLocked(values, null, false, false /* persistent */, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4405 | UserHandle.USER_NULL, false /* deferResume */, |
| 4406 | mTmpUpdateConfigurationResult); |
| 4407 | return mTmpUpdateConfigurationResult.changes != 0; |
| 4408 | } finally { |
| 4409 | Binder.restoreCallingIdentity(origId); |
| 4410 | } |
| 4411 | } |
| 4412 | } |
| 4413 | |
| 4414 | @Override |
| 4415 | public void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback, |
| 4416 | CharSequence message) { |
| 4417 | if (message != null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4418 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4419 | Manifest.permission.SHOW_KEYGUARD_MESSAGE, "dismissKeyguard()"); |
| 4420 | } |
| 4421 | final long callingId = Binder.clearCallingIdentity(); |
| 4422 | try { |
| 4423 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4424 | mKeyguardController.dismissKeyguard(token, callback, message); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4425 | } |
| 4426 | } finally { |
| 4427 | Binder.restoreCallingIdentity(callingId); |
| 4428 | } |
| 4429 | } |
| 4430 | |
| 4431 | @Override |
| 4432 | public void cancelTaskWindowTransition(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4433 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4434 | "cancelTaskWindowTransition()"); |
| 4435 | final long ident = Binder.clearCallingIdentity(); |
| 4436 | try { |
| 4437 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4438 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4439 | MATCH_TASK_IN_STACKS_ONLY); |
| 4440 | if (task == null) { |
| 4441 | Slog.w(TAG, "cancelTaskWindowTransition: taskId=" + taskId + " not found"); |
| 4442 | return; |
| 4443 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 4444 | task.cancelTaskWindowTransition(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4445 | } |
| 4446 | } finally { |
| 4447 | Binder.restoreCallingIdentity(ident); |
| 4448 | } |
| 4449 | } |
| 4450 | |
| 4451 | @Override |
Peter Kalauskas | 4dc0460 | 2020-02-12 18:49:03 -0800 | [diff] [blame] | 4452 | public ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4453 | enforceCallerIsRecentsOrHasPermission(READ_FRAME_BUFFER, "getTaskSnapshot()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4454 | final long ident = Binder.clearCallingIdentity(); |
| 4455 | try { |
Peter Kalauskas | 4dc0460 | 2020-02-12 18:49:03 -0800 | [diff] [blame] | 4456 | return getTaskSnapshot(taskId, isLowResolution, true /* restoreFromDisk */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4457 | } finally { |
| 4458 | Binder.restoreCallingIdentity(ident); |
| 4459 | } |
| 4460 | } |
| 4461 | |
Peter Kalauskas | 4dc0460 | 2020-02-12 18:49:03 -0800 | [diff] [blame] | 4462 | private ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution, |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4463 | boolean restoreFromDisk) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4464 | final Task task; |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4465 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4466 | task = mRootWindowContainer.anyTaskForId(taskId, |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4467 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 4468 | if (task == null) { |
| 4469 | Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found"); |
| 4470 | return null; |
| 4471 | } |
| 4472 | } |
| 4473 | // Don't call this while holding the lock as this operation might hit the disk. |
Peter Kalauskas | 4dc0460 | 2020-02-12 18:49:03 -0800 | [diff] [blame] | 4474 | return task.getSnapshot(isLowResolution, restoreFromDisk); |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4475 | } |
| 4476 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4477 | @Override |
| 4478 | public void setDisablePreviewScreenshots(IBinder token, boolean disable) { |
| 4479 | synchronized (mGlobalLock) { |
| 4480 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4481 | if (r == null) { |
| 4482 | Slog.w(TAG, "setDisablePreviewScreenshots: Unable to find activity for token=" |
| 4483 | + token); |
| 4484 | return; |
| 4485 | } |
| 4486 | final long origId = Binder.clearCallingIdentity(); |
| 4487 | try { |
| 4488 | r.setDisablePreviewScreenshots(disable); |
| 4489 | } finally { |
| 4490 | Binder.restoreCallingIdentity(origId); |
| 4491 | } |
| 4492 | } |
| 4493 | } |
| 4494 | |
Riddle Hsu | 440f88b | 2019-11-06 22:17:35 +0800 | [diff] [blame] | 4495 | @Override |
| 4496 | public void invalidateHomeTaskSnapshot(IBinder token) { |
| 4497 | synchronized (mGlobalLock) { |
| 4498 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4499 | if (r == null || !r.isActivityTypeHome()) { |
| 4500 | return; |
| 4501 | } |
| 4502 | mWindowManager.mTaskSnapshotController.removeSnapshotCache(r.getTask().mTaskId); |
| 4503 | } |
| 4504 | } |
| 4505 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4506 | /** Return the user id of the last resumed activity. */ |
| 4507 | @Override |
| 4508 | public @UserIdInt |
| 4509 | int getLastResumedActivityUserId() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4510 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4511 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, "getLastResumedActivityUserId()"); |
| 4512 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4513 | if (mLastResumedActivity == null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4514 | return getCurrentUserId(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4515 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4516 | return mLastResumedActivity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4517 | } |
| 4518 | } |
| 4519 | |
| 4520 | @Override |
| 4521 | public void updateLockTaskFeatures(int userId, int flags) { |
| 4522 | final int callingUid = Binder.getCallingUid(); |
| 4523 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4524 | mAmInternal.enforceCallingPermission(android.Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4525 | "updateLockTaskFeatures()"); |
| 4526 | } |
| 4527 | synchronized (mGlobalLock) { |
| 4528 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Allowing features " + userId + ":0x" + |
| 4529 | Integer.toHexString(flags)); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 4530 | getLockTaskController().updateLockTaskFeatures(userId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4531 | } |
| 4532 | } |
| 4533 | |
| 4534 | @Override |
| 4535 | public void setShowWhenLocked(IBinder token, boolean showWhenLocked) { |
| 4536 | synchronized (mGlobalLock) { |
| 4537 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4538 | if (r == null) { |
| 4539 | return; |
| 4540 | } |
| 4541 | final long origId = Binder.clearCallingIdentity(); |
| 4542 | try { |
| 4543 | r.setShowWhenLocked(showWhenLocked); |
| 4544 | } finally { |
| 4545 | Binder.restoreCallingIdentity(origId); |
| 4546 | } |
| 4547 | } |
| 4548 | } |
| 4549 | |
| 4550 | @Override |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 4551 | public void setInheritShowWhenLocked(IBinder token, boolean inheritShowWhenLocked) { |
| 4552 | synchronized (mGlobalLock) { |
| 4553 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4554 | if (r == null) { |
| 4555 | return; |
| 4556 | } |
| 4557 | final long origId = Binder.clearCallingIdentity(); |
| 4558 | try { |
| 4559 | r.setInheritShowWhenLocked(inheritShowWhenLocked); |
| 4560 | } finally { |
| 4561 | Binder.restoreCallingIdentity(origId); |
| 4562 | } |
| 4563 | } |
| 4564 | } |
| 4565 | |
| 4566 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4567 | public void setTurnScreenOn(IBinder token, boolean turnScreenOn) { |
| 4568 | synchronized (mGlobalLock) { |
| 4569 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4570 | if (r == null) { |
| 4571 | return; |
| 4572 | } |
| 4573 | final long origId = Binder.clearCallingIdentity(); |
| 4574 | try { |
| 4575 | r.setTurnScreenOn(turnScreenOn); |
| 4576 | } finally { |
| 4577 | Binder.restoreCallingIdentity(origId); |
| 4578 | } |
| 4579 | } |
| 4580 | } |
| 4581 | |
| 4582 | @Override |
| 4583 | public void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4584 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4585 | "registerRemoteAnimations"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4586 | definition.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4587 | synchronized (mGlobalLock) { |
| 4588 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4589 | if (r == null) { |
| 4590 | return; |
| 4591 | } |
| 4592 | final long origId = Binder.clearCallingIdentity(); |
| 4593 | try { |
| 4594 | r.registerRemoteAnimations(definition); |
| 4595 | } finally { |
| 4596 | Binder.restoreCallingIdentity(origId); |
| 4597 | } |
| 4598 | } |
| 4599 | } |
| 4600 | |
| 4601 | @Override |
Winson Chung | 10fc25d | 2019-12-10 14:13:56 -0800 | [diff] [blame] | 4602 | public void unregisterRemoteAnimations(IBinder token) { |
| 4603 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
| 4604 | "unregisterRemoteAnimations"); |
| 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.unregisterRemoteAnimations(); |
| 4613 | } finally { |
| 4614 | Binder.restoreCallingIdentity(origId); |
| 4615 | } |
| 4616 | } |
| 4617 | } |
| 4618 | |
| 4619 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4620 | public void registerRemoteAnimationForNextActivityStart(String packageName, |
| 4621 | RemoteAnimationAdapter adapter) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4622 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4623 | "registerRemoteAnimationForNextActivityStart"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4624 | adapter.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4625 | synchronized (mGlobalLock) { |
| 4626 | final long origId = Binder.clearCallingIdentity(); |
| 4627 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4628 | getActivityStartController().registerRemoteAnimationForNextActivityStart( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4629 | packageName, adapter); |
| 4630 | } finally { |
| 4631 | Binder.restoreCallingIdentity(origId); |
| 4632 | } |
| 4633 | } |
| 4634 | } |
| 4635 | |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4636 | @Override |
| 4637 | public void registerRemoteAnimationsForDisplay(int displayId, |
| 4638 | RemoteAnimationDefinition definition) { |
| 4639 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
| 4640 | "registerRemoteAnimations"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4641 | definition.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4642 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4643 | final DisplayContent display = mRootWindowContainer.getDisplayContent(displayId); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4644 | if (display == null) { |
| 4645 | Slog.e(TAG, "Couldn't find display with id: " + displayId); |
| 4646 | return; |
| 4647 | } |
| 4648 | final long origId = Binder.clearCallingIdentity(); |
| 4649 | try { |
| 4650 | display.mDisplayContent.registerRemoteAnimations(definition); |
| 4651 | } finally { |
| 4652 | Binder.restoreCallingIdentity(origId); |
| 4653 | } |
| 4654 | } |
| 4655 | } |
| 4656 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4657 | /** @see android.app.ActivityManager#alwaysShowUnsupportedCompileSdkWarning */ |
| 4658 | @Override |
| 4659 | public void alwaysShowUnsupportedCompileSdkWarning(ComponentName activity) { |
| 4660 | synchronized (mGlobalLock) { |
| 4661 | final long origId = Binder.clearCallingIdentity(); |
| 4662 | try { |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 4663 | mAppWarnings.alwaysShowUnsupportedCompileSdkWarning(activity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4664 | } finally { |
| 4665 | Binder.restoreCallingIdentity(origId); |
| 4666 | } |
| 4667 | } |
| 4668 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 4669 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4670 | @Override |
| 4671 | public void setVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4672 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4673 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4674 | final int pid = Binder.getCallingPid(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 4675 | final WindowProcessController wpc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4676 | mVrController.setVrThreadLocked(tid, pid, wpc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4677 | } |
| 4678 | } |
| 4679 | |
| 4680 | @Override |
| 4681 | public void setPersistentVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4682 | if (checkCallingPermission(Manifest.permission.RESTRICTED_VR_ACCESS) |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4683 | != PERMISSION_GRANTED) { |
| 4684 | final String msg = "Permission Denial: setPersistentVrThread() from pid=" |
| 4685 | + Binder.getCallingPid() |
| 4686 | + ", uid=" + Binder.getCallingUid() |
| 4687 | + " requires " + Manifest.permission.RESTRICTED_VR_ACCESS; |
| 4688 | Slog.w(TAG, msg); |
| 4689 | throw new SecurityException(msg); |
| 4690 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4691 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4692 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4693 | final int pid = Binder.getCallingPid(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 4694 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4695 | mVrController.setPersistentVrThreadLocked(tid, pid, proc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4696 | } |
| 4697 | } |
| 4698 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4699 | @Override |
| 4700 | public void stopAppSwitches() { |
| 4701 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "stopAppSwitches"); |
| 4702 | synchronized (mGlobalLock) { |
| 4703 | mAppSwitchesAllowedTime = SystemClock.uptimeMillis() + APP_SWITCH_DELAY_TIME; |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 4704 | mLastStopAppSwitchesTime = SystemClock.uptimeMillis(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4705 | mDidAppSwitch = false; |
| 4706 | getActivityStartController().schedulePendingActivityLaunches(APP_SWITCH_DELAY_TIME); |
| 4707 | } |
| 4708 | } |
| 4709 | |
| 4710 | @Override |
| 4711 | public void resumeAppSwitches() { |
| 4712 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "resumeAppSwitches"); |
| 4713 | synchronized (mGlobalLock) { |
| 4714 | // Note that we don't execute any pending app switches... we will |
| 4715 | // let those wait until either the timeout, or the next start |
| 4716 | // activity request. |
| 4717 | mAppSwitchesAllowedTime = 0; |
| 4718 | } |
| 4719 | } |
| 4720 | |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 4721 | long getLastStopAppSwitchesTime() { |
| 4722 | return mLastStopAppSwitchesTime; |
| 4723 | } |
| 4724 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4725 | void onStartActivitySetDidAppSwitch() { |
| 4726 | if (mDidAppSwitch) { |
| 4727 | // This is the second allowed switch since we stopped switches, so now just generally |
| 4728 | // allow switches. Use case: |
| 4729 | // - user presses home (switches disabled, switch to home, mDidAppSwitch now true); |
| 4730 | // - user taps a home icon (coming from home so allowed, we hit here and now allow |
| 4731 | // anyone to switch again). |
| 4732 | mAppSwitchesAllowedTime = 0; |
| 4733 | } else { |
| 4734 | mDidAppSwitch = true; |
| 4735 | } |
| 4736 | } |
| 4737 | |
| 4738 | /** @return whether the system should disable UI modes incompatible with VR mode. */ |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4739 | boolean shouldDisableNonVrUiLocked() { |
| 4740 | return mVrController.shouldDisableNonVrUiLocked(); |
| 4741 | } |
| 4742 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4743 | private void applyUpdateVrModeLocked(ActivityRecord r) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4744 | // 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] | 4745 | // 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] | 4746 | if (r.requestedVrComponent != null && r.getDisplayId() != DEFAULT_DISPLAY) { |
Wale Ogunwale | b8e6b63 | 2019-06-28 15:19:25 +0000 | [diff] [blame] | 4747 | Slog.i(TAG, "Moving " + r.shortComponentName + " from display " + r.getDisplayId() |
| 4748 | + " to main display for VR"); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4749 | mRootWindowContainer.moveStackToDisplay( |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 4750 | r.getRootTaskId(), DEFAULT_DISPLAY, true /* toTop */); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4751 | } |
| 4752 | mH.post(() -> { |
| 4753 | if (!mVrController.onVrModeChanged(r)) { |
| 4754 | return; |
| 4755 | } |
| 4756 | synchronized (mGlobalLock) { |
| 4757 | final boolean disableNonVrUi = mVrController.shouldDisableNonVrUiLocked(); |
| 4758 | mWindowManager.disableNonVrUi(disableNonVrUi); |
| 4759 | if (disableNonVrUi) { |
| 4760 | // If we are in a VR mode where Picture-in-Picture mode is unsupported, |
| 4761 | // then remove the pinned stack. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4762 | mRootWindowContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4763 | } |
| 4764 | } |
| 4765 | }); |
| 4766 | } |
| 4767 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4768 | @Override |
| 4769 | public int getPackageScreenCompatMode(String packageName) { |
| 4770 | enforceNotIsolatedCaller("getPackageScreenCompatMode"); |
| 4771 | synchronized (mGlobalLock) { |
| 4772 | return mCompatModePackages.getPackageScreenCompatModeLocked(packageName); |
| 4773 | } |
| 4774 | } |
| 4775 | |
| 4776 | @Override |
| 4777 | public void setPackageScreenCompatMode(String packageName, int mode) { |
| 4778 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4779 | "setPackageScreenCompatMode"); |
| 4780 | synchronized (mGlobalLock) { |
| 4781 | mCompatModePackages.setPackageScreenCompatModeLocked(packageName, mode); |
| 4782 | } |
| 4783 | } |
| 4784 | |
| 4785 | @Override |
| 4786 | public boolean getPackageAskScreenCompat(String packageName) { |
| 4787 | enforceNotIsolatedCaller("getPackageAskScreenCompat"); |
| 4788 | synchronized (mGlobalLock) { |
| 4789 | return mCompatModePackages.getPackageAskCompatModeLocked(packageName); |
| 4790 | } |
| 4791 | } |
| 4792 | |
| 4793 | @Override |
| 4794 | public void setPackageAskScreenCompat(String packageName, boolean ask) { |
| 4795 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4796 | "setPackageAskScreenCompat"); |
| 4797 | synchronized (mGlobalLock) { |
| 4798 | mCompatModePackages.setPackageAskCompatModeLocked(packageName, ask); |
| 4799 | } |
| 4800 | } |
| 4801 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 4802 | public static String relaunchReasonToString(int relaunchReason) { |
| 4803 | switch (relaunchReason) { |
| 4804 | case RELAUNCH_REASON_WINDOWING_MODE_RESIZE: |
| 4805 | return "window_resize"; |
| 4806 | case RELAUNCH_REASON_FREE_RESIZE: |
| 4807 | return "free_resize"; |
| 4808 | default: |
| 4809 | return null; |
| 4810 | } |
| 4811 | } |
| 4812 | |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4813 | ActivityStack getTopDisplayFocusedStack() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4814 | return mRootWindowContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4815 | } |
| 4816 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4817 | /** Pokes the task persister. */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4818 | void notifyTaskPersisterLocked(Task task, boolean flush) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4819 | mRecentTasks.notifyTaskPersisterLocked(task, flush); |
| 4820 | } |
| 4821 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4822 | boolean isKeyguardLocked() { |
| 4823 | return mKeyguardController.isKeyguardLocked(); |
| 4824 | } |
| 4825 | |
Garfield Tan | 0154863 | 2018-11-27 10:15:48 -0800 | [diff] [blame] | 4826 | /** |
| 4827 | * Clears launch params for the given package. |
| 4828 | * @param packageNames the names of the packages of which the launch params are to be cleared |
| 4829 | */ |
| 4830 | @Override |
| 4831 | public void clearLaunchParamsForPackages(List<String> packageNames) { |
| 4832 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4833 | "clearLaunchParamsForPackages"); |
| 4834 | synchronized (mGlobalLock) { |
| 4835 | for (int i = 0; i < packageNames.size(); ++i) { |
| 4836 | mStackSupervisor.mLaunchParamsPersister.removeRecordForPackage(packageNames.get(i)); |
| 4837 | } |
| 4838 | } |
| 4839 | } |
| 4840 | |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 4841 | /** |
| 4842 | * Makes the display with the given id a single task instance display. I.e the display can only |
| 4843 | * contain one task. |
| 4844 | */ |
| 4845 | @Override |
| 4846 | public void setDisplayToSingleTaskInstance(int displayId) { |
| 4847 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4848 | "setDisplayToSingleTaskInstance"); |
| 4849 | final long origId = Binder.clearCallingIdentity(); |
| 4850 | try { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 4851 | final DisplayContent display = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4852 | mRootWindowContainer.getDisplayContentOrCreate(displayId); |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 4853 | if (display != null) { |
| 4854 | display.setDisplayToSingleTaskInstance(); |
| 4855 | } |
| 4856 | } finally { |
| 4857 | Binder.restoreCallingIdentity(origId); |
| 4858 | } |
| 4859 | } |
| 4860 | |
jorgegil@google.com | 06bc323 | 2019-10-31 14:51:22 -0700 | [diff] [blame] | 4861 | /** |
| 4862 | * Requests that an activity should enter picture-in-picture mode if possible. |
| 4863 | */ |
| 4864 | @Override |
| 4865 | public void requestPictureInPictureMode(IBinder token) throws RemoteException { |
| 4866 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4867 | "requestPictureInPictureMode"); |
| 4868 | final long origId = Binder.clearCallingIdentity(); |
| 4869 | try { |
| 4870 | synchronized (mGlobalLock) { |
| 4871 | final ActivityRecord activity = ActivityRecord.forTokenLocked(token); |
| 4872 | if (activity == null) { |
| 4873 | return; |
| 4874 | } |
| 4875 | |
| 4876 | final boolean canEnterPictureInPicture = activity.checkEnterPictureInPictureState( |
| 4877 | "requestPictureInPictureMode", /* beforeStopping */ false); |
| 4878 | if (!canEnterPictureInPicture) { |
| 4879 | throw new IllegalStateException( |
| 4880 | "Requested PIP on an activity that doesn't support it"); |
| 4881 | } |
| 4882 | |
| 4883 | try { |
| 4884 | final ClientTransaction transaction = ClientTransaction.obtain( |
| 4885 | activity.app.getThread(), |
| 4886 | activity.token); |
| 4887 | transaction.addCallback(EnterPipRequestedItem.obtain()); |
| 4888 | getLifecycleManager().scheduleTransaction(transaction); |
| 4889 | } catch (Exception e) { |
| 4890 | Slog.w(TAG, "Failed to send enter pip requested item: " |
| 4891 | + activity.intent.getComponent(), e); |
| 4892 | } |
| 4893 | } |
| 4894 | } finally { |
| 4895 | Binder.restoreCallingIdentity(origId); |
| 4896 | } |
| 4897 | } |
| 4898 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4899 | void dumpLastANRLocked(PrintWriter pw) { |
| 4900 | pw.println("ACTIVITY MANAGER LAST ANR (dumpsys activity lastanr)"); |
| 4901 | if (mLastANRState == null) { |
| 4902 | pw.println(" <no ANR has occurred since boot>"); |
| 4903 | } else { |
| 4904 | pw.println(mLastANRState); |
| 4905 | } |
| 4906 | } |
| 4907 | |
| 4908 | void dumpLastANRTracesLocked(PrintWriter pw) { |
| 4909 | pw.println("ACTIVITY MANAGER LAST ANR TRACES (dumpsys activity lastanr-traces)"); |
| 4910 | |
| 4911 | final File[] files = new File(ANR_TRACE_DIR).listFiles(); |
| 4912 | if (ArrayUtils.isEmpty(files)) { |
| 4913 | pw.println(" <no ANR has occurred since boot>"); |
| 4914 | return; |
| 4915 | } |
| 4916 | // Find the latest file. |
| 4917 | File latest = null; |
| 4918 | for (File f : files) { |
| 4919 | if ((latest == null) || (latest.lastModified() < f.lastModified())) { |
| 4920 | latest = f; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4921 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4922 | } |
| 4923 | pw.print("File: "); |
| 4924 | pw.print(latest.getName()); |
| 4925 | pw.println(); |
| 4926 | try (BufferedReader in = new BufferedReader(new FileReader(latest))) { |
| 4927 | String line; |
| 4928 | while ((line = in.readLine()) != null) { |
| 4929 | pw.println(line); |
| 4930 | } |
| 4931 | } catch (IOException e) { |
| 4932 | pw.print("Unable to read: "); |
| 4933 | pw.print(e); |
| 4934 | pw.println(); |
| 4935 | } |
| 4936 | } |
| 4937 | |
| 4938 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4939 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 4940 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage, |
| 4941 | "ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)"); |
| 4942 | } |
| 4943 | |
| 4944 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4945 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage, String header) { |
| 4946 | pw.println(header); |
| 4947 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4948 | boolean printedAnything = mRootWindowContainer.dumpActivities(fd, pw, dumpAll, dumpClient, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4949 | dumpPackage); |
| 4950 | boolean needSep = printedAnything; |
| 4951 | |
| 4952 | boolean printed = ActivityStackSupervisor.printThisActivity(pw, |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4953 | mRootWindowContainer.getTopResumedActivity(), dumpPackage, needSep, |
Dianne Hackborn | 9106f2a | 2020-04-30 16:23:20 -0700 | [diff] [blame] | 4954 | " ResumedActivity: ", null); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4955 | if (printed) { |
| 4956 | printedAnything = true; |
| 4957 | needSep = false; |
| 4958 | } |
| 4959 | |
| 4960 | if (dumpPackage == null) { |
| 4961 | if (needSep) { |
| 4962 | pw.println(); |
| 4963 | } |
| 4964 | printedAnything = true; |
| 4965 | mStackSupervisor.dump(pw, " "); |
Winson Chung | 268eccb | 2020-03-26 13:43:44 -0700 | [diff] [blame] | 4966 | mTaskOrganizerController.dump(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4967 | } |
| 4968 | |
| 4969 | if (!printedAnything) { |
| 4970 | pw.println(" (nothing)"); |
| 4971 | } |
| 4972 | } |
| 4973 | |
| 4974 | void dumpActivityContainersLocked(PrintWriter pw) { |
Jeff Chang | de32273 | 2019-07-12 12:16:23 +0800 | [diff] [blame] | 4975 | pw.println("ACTIVITY MANAGER CONTAINERS (dumpsys activity containers)"); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4976 | mRootWindowContainer.dumpChildrenNames(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4977 | pw.println(" "); |
| 4978 | } |
| 4979 | |
| 4980 | void dumpActivityStarterLocked(PrintWriter pw, String dumpPackage) { |
| 4981 | pw.println("ACTIVITY MANAGER STARTER (dumpsys activity starter)"); |
| 4982 | getActivityStartController().dump(pw, "", dumpPackage); |
| 4983 | } |
| 4984 | |
| 4985 | /** |
| 4986 | * There are three things that cmd can be: |
| 4987 | * - a flattened component name that matches an existing activity |
| 4988 | * - the cmd arg isn't the flattened component name of an existing activity: |
| 4989 | * dump all activity whose component contains the cmd as a substring |
| 4990 | * - A hex number of the ActivityRecord object instance. |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 4991 | * <p> |
| 4992 | * The caller should not hold lock when calling this method because it will wait for the |
| 4993 | * activities to complete the dump. |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4994 | * |
| 4995 | * @param dumpVisibleStacksOnly dump activity with {@param name} only if in a visible stack |
| 4996 | * @param dumpFocusedStackOnly dump activity with {@param name} only if in the focused stack |
| 4997 | */ |
| 4998 | protected boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, String[] args, |
| 4999 | int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, boolean dumpFocusedStackOnly) { |
| 5000 | ArrayList<ActivityRecord> activities; |
| 5001 | |
| 5002 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5003 | activities = mRootWindowContainer.getDumpActivities(name, dumpVisibleStacksOnly, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5004 | dumpFocusedStackOnly); |
| 5005 | } |
| 5006 | |
| 5007 | if (activities.size() <= 0) { |
| 5008 | return false; |
| 5009 | } |
| 5010 | |
| 5011 | String[] newArgs = new String[args.length - opti]; |
| 5012 | System.arraycopy(args, opti, newArgs, 0, args.length - opti); |
| 5013 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5014 | Task lastTask = null; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5015 | boolean needSep = false; |
| 5016 | for (int i = activities.size() - 1; i >= 0; i--) { |
| 5017 | ActivityRecord r = activities.get(i); |
| 5018 | if (needSep) { |
| 5019 | pw.println(); |
| 5020 | } |
| 5021 | needSep = true; |
| 5022 | synchronized (mGlobalLock) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5023 | final Task task = r.getTask(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5024 | if (lastTask != task) { |
| 5025 | lastTask = task; |
| 5026 | pw.print("TASK "); pw.print(lastTask.affinity); |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 5027 | pw.print(" id="); pw.print(lastTask.mTaskId); |
| 5028 | pw.print(" userId="); pw.println(lastTask.mUserId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5029 | if (dumpAll) { |
| 5030 | lastTask.dump(pw, " "); |
| 5031 | } |
| 5032 | } |
| 5033 | } |
| 5034 | dumpActivity(" ", fd, pw, activities.get(i), newArgs, dumpAll); |
| 5035 | } |
| 5036 | return true; |
| 5037 | } |
| 5038 | |
| 5039 | /** |
| 5040 | * Invokes IApplicationThread.dumpActivity() on the thread of the specified activity if |
| 5041 | * there is a thread associated with the activity. |
| 5042 | */ |
| 5043 | private void dumpActivity(String prefix, FileDescriptor fd, PrintWriter pw, |
| 5044 | final ActivityRecord r, String[] args, boolean dumpAll) { |
| 5045 | String innerPrefix = prefix + " "; |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5046 | IApplicationThread appThread = null; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5047 | synchronized (mGlobalLock) { |
| 5048 | pw.print(prefix); pw.print("ACTIVITY "); pw.print(r.shortComponentName); |
| 5049 | pw.print(" "); pw.print(Integer.toHexString(System.identityHashCode(r))); |
| 5050 | pw.print(" pid="); |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5051 | if (r.hasProcess()) { |
| 5052 | pw.println(r.app.getPid()); |
| 5053 | appThread = r.app.getThread(); |
| 5054 | } else { |
| 5055 | pw.println("(not running)"); |
| 5056 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5057 | if (dumpAll) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5058 | r.dump(pw, innerPrefix, true /* dumpAll */); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5059 | } |
| 5060 | } |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5061 | if (appThread != null) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5062 | // flush anything that is already in the PrintWriter since the thread is going |
| 5063 | // to write to the file descriptor directly |
| 5064 | pw.flush(); |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5065 | try (TransferPipe tp = new TransferPipe()) { |
| 5066 | appThread.dumpActivity(tp.getWriteFd(), r.appToken, innerPrefix, args); |
| 5067 | tp.go(fd); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5068 | } catch (IOException e) { |
| 5069 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 5070 | } catch (RemoteException e) { |
| 5071 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 5072 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5073 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5074 | } |
| 5075 | |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 5076 | private void writeSleepStateToProto(ProtoOutputStream proto, int wakeFullness, |
| 5077 | boolean testPssMode) { |
| 5078 | final long sleepToken = proto.start(ActivityManagerServiceDumpProcessesProto.SLEEP_STATUS); |
| 5079 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.WAKEFULNESS, |
| 5080 | PowerManagerInternal.wakefulnessToProtoEnum(wakeFullness)); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5081 | for (ActivityTaskManagerInternal.SleepToken st : mRootWindowContainer.mSleepTokens) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5082 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEP_TOKENS, |
| 5083 | st.toString()); |
| 5084 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5085 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEPING, mSleeping); |
| 5086 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SHUTTING_DOWN, |
| 5087 | mShuttingDown); |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 5088 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.TEST_PSS_MODE, |
| 5089 | testPssMode); |
| 5090 | proto.end(sleepToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5091 | } |
| 5092 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5093 | int getCurrentUserId() { |
| 5094 | return mAmInternal.getCurrentUserId(); |
| 5095 | } |
| 5096 | |
| 5097 | private void enforceNotIsolatedCaller(String caller) { |
| 5098 | if (UserHandle.isIsolated(Binder.getCallingUid())) { |
| 5099 | throw new SecurityException("Isolated process not allowed to call " + caller); |
| 5100 | } |
| 5101 | } |
| 5102 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5103 | public Configuration getConfiguration() { |
| 5104 | Configuration ci; |
| 5105 | synchronized(mGlobalLock) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 5106 | ci = new Configuration(getGlobalConfigurationForCallingPid()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5107 | ci.userSetLocale = false; |
| 5108 | } |
| 5109 | return ci; |
| 5110 | } |
| 5111 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5112 | /** |
| 5113 | * Current global configuration information. Contains general settings for the entire system, |
| 5114 | * also corresponds to the merged configuration of the default display. |
| 5115 | */ |
| 5116 | Configuration getGlobalConfiguration() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5117 | // Return default configuration before mRootWindowContainer initialized, which happens |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 5118 | // while initializing process record for system, see {@link |
| 5119 | // ActivityManagerService#setSystemProcess}. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5120 | return mRootWindowContainer != null ? mRootWindowContainer.getConfiguration() |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 5121 | : new Configuration(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5122 | } |
| 5123 | |
| 5124 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5125 | boolean initLocale) { |
| 5126 | return updateConfigurationLocked(values, starting, initLocale, false /* deferResume */); |
| 5127 | } |
| 5128 | |
| 5129 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5130 | boolean initLocale, boolean deferResume) { |
| 5131 | // pass UserHandle.USER_NULL as userId because we don't persist configuration for any user |
| 5132 | return updateConfigurationLocked(values, starting, initLocale, false /* persistent */, |
| 5133 | UserHandle.USER_NULL, deferResume); |
| 5134 | } |
| 5135 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 5136 | public void updatePersistentConfiguration(Configuration values, @UserIdInt int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5137 | final long origId = Binder.clearCallingIdentity(); |
| 5138 | try { |
| 5139 | synchronized (mGlobalLock) { |
| 5140 | updateConfigurationLocked(values, null, false, true, userId, |
| 5141 | false /* deferResume */); |
| 5142 | } |
| 5143 | } finally { |
| 5144 | Binder.restoreCallingIdentity(origId); |
| 5145 | } |
| 5146 | } |
| 5147 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5148 | private boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5149 | boolean initLocale, boolean persistent, int userId, boolean deferResume) { |
| 5150 | return updateConfigurationLocked(values, starting, initLocale, persistent, userId, |
| 5151 | deferResume, null /* result */); |
| 5152 | } |
| 5153 | |
| 5154 | /** |
| 5155 | * Do either or both things: (1) change the current configuration, and (2) |
| 5156 | * make sure the given activity is running with the (now) current |
| 5157 | * configuration. Returns true if the activity has been left running, or |
| 5158 | * false if <var>starting</var> is being destroyed to match the new |
| 5159 | * configuration. |
| 5160 | * |
| 5161 | * @param userId is only used when persistent parameter is set to true to persist configuration |
| 5162 | * for that particular user |
| 5163 | */ |
| 5164 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5165 | boolean initLocale, boolean persistent, int userId, boolean deferResume, |
| 5166 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 5167 | int changes = 0; |
| 5168 | boolean kept = true; |
| 5169 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5170 | deferWindowLayout(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5171 | try { |
| 5172 | if (values != null) { |
| 5173 | changes = updateGlobalConfigurationLocked(values, initLocale, persistent, userId, |
| 5174 | deferResume); |
| 5175 | } |
| 5176 | |
| 5177 | kept = ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 5178 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5179 | continueWindowLayout(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5180 | } |
| 5181 | |
| 5182 | if (result != null) { |
| 5183 | result.changes = changes; |
| 5184 | result.activityRelaunched = !kept; |
| 5185 | } |
| 5186 | return kept; |
| 5187 | } |
| 5188 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5189 | /** Update default (global) configuration and notify listeners about changes. */ |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5190 | int updateGlobalConfigurationLocked(@NonNull Configuration values, boolean initLocale, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5191 | boolean persistent, int userId, boolean deferResume) { |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5192 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5193 | final DisplayContent defaultDisplay = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5194 | mRootWindowContainer.getDisplayContent(DEFAULT_DISPLAY); |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5195 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5196 | mTempConfig.setTo(getGlobalConfiguration()); |
| 5197 | final int changes = mTempConfig.updateFrom(values); |
| 5198 | if (changes == 0) { |
| 5199 | // Since calling to Activity.setRequestedOrientation leads to freezing the window with |
| 5200 | // setting WindowManagerService.mWaitingForConfig to true, it is important that we call |
| 5201 | // performDisplayOverrideConfigUpdate in order to send the new display configuration |
| 5202 | // (even if there are no actual changes) to unfreeze the window. |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5203 | defaultDisplay.performDisplayOverrideConfigUpdate(values, deferResume); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5204 | return 0; |
| 5205 | } |
| 5206 | |
| 5207 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.i(TAG_CONFIGURATION, |
| 5208 | "Updating global configuration to: " + values); |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5209 | writeConfigurationChanged(changes); |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 5210 | FrameworkStatsLog.write(FrameworkStatsLog.RESOURCE_CONFIGURATION_CHANGED, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5211 | values.colorMode, |
| 5212 | values.densityDpi, |
| 5213 | values.fontScale, |
| 5214 | values.hardKeyboardHidden, |
| 5215 | values.keyboard, |
| 5216 | values.keyboardHidden, |
| 5217 | values.mcc, |
| 5218 | values.mnc, |
| 5219 | values.navigation, |
| 5220 | values.navigationHidden, |
| 5221 | values.orientation, |
| 5222 | values.screenHeightDp, |
| 5223 | values.screenLayout, |
| 5224 | values.screenWidthDp, |
| 5225 | values.smallestScreenWidthDp, |
| 5226 | values.touchscreen, |
| 5227 | values.uiMode); |
| 5228 | |
| 5229 | |
| 5230 | if (!initLocale && !values.getLocales().isEmpty() && values.userSetLocale) { |
| 5231 | final LocaleList locales = values.getLocales(); |
| 5232 | int bestLocaleIndex = 0; |
| 5233 | if (locales.size() > 1) { |
| 5234 | if (mSupportedSystemLocales == null) { |
| 5235 | mSupportedSystemLocales = Resources.getSystem().getAssets().getLocales(); |
| 5236 | } |
| 5237 | bestLocaleIndex = Math.max(0, locales.getFirstMatchIndex(mSupportedSystemLocales)); |
| 5238 | } |
| 5239 | SystemProperties.set("persist.sys.locale", |
| 5240 | locales.get(bestLocaleIndex).toLanguageTag()); |
| 5241 | LocaleList.setDefault(locales, bestLocaleIndex); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5242 | |
| 5243 | final Message m = PooledLambda.obtainMessage( |
| 5244 | ActivityTaskManagerService::sendLocaleToMountDaemonMsg, this, |
| 5245 | locales.get(bestLocaleIndex)); |
| 5246 | mH.sendMessage(m); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5247 | } |
| 5248 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 5249 | mTempConfig.seq = increaseConfigurationSeqLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5250 | |
| 5251 | // Update stored global config and notify everyone about the change. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5252 | mRootWindowContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5253 | |
| 5254 | Slog.i(TAG, "Config changes=" + Integer.toHexString(changes) + " " + mTempConfig); |
| 5255 | // TODO(multi-display): Update UsageEvents#Event to include displayId. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5256 | mUsageStatsInternal.reportConfigurationChange(mTempConfig, mAmInternal.getCurrentUserId()); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5257 | |
| 5258 | // 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] | 5259 | updateShouldShowDialogsLocked(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5260 | |
| 5261 | AttributeCache ac = AttributeCache.instance(); |
| 5262 | if (ac != null) { |
| 5263 | ac.updateConfiguration(mTempConfig); |
| 5264 | } |
| 5265 | |
| 5266 | // Make sure all resources in our process are updated right now, so that anyone who is going |
| 5267 | // to retrieve resource values after we return will be sure to get the new ones. This is |
| 5268 | // especially important during boot, where the first config change needs to guarantee all |
| 5269 | // resources have that config before following boot code is executed. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5270 | mSystemThread.applyConfigurationToResources(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5271 | |
| 5272 | // We need another copy of global config because we're scheduling some calls instead of |
| 5273 | // running them in place. We need to be sure that object we send will be handled unchanged. |
| 5274 | final Configuration configCopy = new Configuration(mTempConfig); |
| 5275 | if (persistent && Settings.System.hasInterestingConfigurationChanges(changes)) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5276 | final Message msg = PooledLambda.obtainMessage( |
| 5277 | ActivityTaskManagerService::sendPutConfigurationForUserMsg, |
| 5278 | this, userId, configCopy); |
| 5279 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5280 | } |
| 5281 | |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 5282 | SparseArray<WindowProcessController> pidMap = mProcessMap.getPidMap(); |
| 5283 | for (int i = pidMap.size() - 1; i >= 0; i--) { |
| 5284 | final int pid = pidMap.keyAt(i); |
| 5285 | final WindowProcessController app = pidMap.get(pid); |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 5286 | if (DEBUG_CONFIGURATION) { |
| 5287 | Slog.v(TAG_CONFIGURATION, "Update process config of " |
| 5288 | + app.mName + " to new config " + configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5289 | } |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 5290 | app.onConfigurationChanged(configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5291 | } |
| 5292 | |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 5293 | final Message msg = PooledLambda.obtainMessage( |
| 5294 | ActivityManagerInternal::broadcastGlobalConfigurationChanged, |
| 5295 | mAmInternal, changes, initLocale); |
| 5296 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5297 | |
| 5298 | // Override configuration of the default display duplicates global config, so we need to |
| 5299 | // update it also. This will also notify WindowManager about changes. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5300 | defaultDisplay.performDisplayOverrideConfigUpdate(mRootWindowContainer.getConfiguration(), |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5301 | deferResume); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5302 | |
| 5303 | return changes; |
| 5304 | } |
| 5305 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5306 | /** @see WindowSurfacePlacer#deferLayout */ |
| 5307 | void deferWindowLayout() { |
| 5308 | if (!mWindowManager.mWindowPlacerLocked.isLayoutDeferred()) { |
| 5309 | // Reset the reasons at the first entrance because we only care about the changes in the |
| 5310 | // deferred scope. |
| 5311 | mLayoutReasons = 0; |
| 5312 | } |
| 5313 | |
| 5314 | mWindowManager.mWindowPlacerLocked.deferLayout(); |
| 5315 | } |
| 5316 | |
| 5317 | /** @see WindowSurfacePlacer#continueLayout */ |
| 5318 | void continueWindowLayout() { |
| 5319 | mWindowManager.mWindowPlacerLocked.continueLayout(mLayoutReasons != 0); |
| 5320 | if (DEBUG_ALL && !mWindowManager.mWindowPlacerLocked.isLayoutDeferred()) { |
| 5321 | Slog.i(TAG, "continueWindowLayout reason=" + mLayoutReasons); |
| 5322 | } |
| 5323 | } |
| 5324 | |
| 5325 | /** |
| 5326 | * If a reason is added between {@link #deferWindowLayout} and {@link #continueWindowLayout}, |
| 5327 | * it will make sure {@link WindowSurfacePlacer#performSurfacePlacement} is called when the last |
| 5328 | * defer count is gone. |
| 5329 | */ |
| 5330 | void addWindowLayoutReasons(@LayoutReason int reasons) { |
| 5331 | mLayoutReasons |= reasons; |
| 5332 | } |
| 5333 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5334 | private void updateEventDispatchingLocked(boolean booted) { |
| 5335 | mWindowManager.setEventDispatching(booted && !mShuttingDown); |
| 5336 | } |
| 5337 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5338 | private void sendPutConfigurationForUserMsg(int userId, Configuration config) { |
| 5339 | final ContentResolver resolver = mContext.getContentResolver(); |
| 5340 | Settings.System.putConfigurationForUser(resolver, config, userId); |
| 5341 | } |
| 5342 | |
| 5343 | private void sendLocaleToMountDaemonMsg(Locale l) { |
| 5344 | try { |
| 5345 | IBinder service = ServiceManager.getService("mount"); |
| 5346 | IStorageManager storageManager = IStorageManager.Stub.asInterface(service); |
| 5347 | Log.d(TAG, "Storing locale " + l.toLanguageTag() + " for decryption UI"); |
| 5348 | storageManager.setField(StorageManager.SYSTEM_LOCALE_KEY, l.toLanguageTag()); |
| 5349 | } catch (RemoteException e) { |
| 5350 | Log.e(TAG, "Error storing locale for decryption UI", e); |
| 5351 | } |
| 5352 | } |
| 5353 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5354 | private void expireStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5355 | mStartActivitySources.remove(permissionToken); |
| 5356 | mExpiredStartAsCallerTokens.add(permissionToken); |
| 5357 | } |
| 5358 | |
| 5359 | private void forgetStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5360 | mExpiredStartAsCallerTokens.remove(permissionToken); |
| 5361 | } |
| 5362 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5363 | boolean isActivityStartsLoggingEnabled() { |
| 5364 | return mAmInternal.isActivityStartsLoggingEnabled(); |
| 5365 | } |
| 5366 | |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 5367 | boolean isBackgroundActivityStartsEnabled() { |
| 5368 | return mAmInternal.isBackgroundActivityStartsEnabled(); |
| 5369 | } |
| 5370 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5371 | void enableScreenAfterBoot(boolean booted) { |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5372 | writeBootProgressEnableScreen(SystemClock.uptimeMillis()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5373 | mWindowManager.enableScreenAfterBoot(); |
| 5374 | |
| 5375 | synchronized (mGlobalLock) { |
| 5376 | updateEventDispatchingLocked(booted); |
| 5377 | } |
| 5378 | } |
| 5379 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5380 | static long getInputDispatchingTimeoutLocked(ActivityRecord r) { |
| 5381 | if (r == null || !r.hasProcess()) { |
| 5382 | return KEY_DISPATCHING_TIMEOUT_MS; |
| 5383 | } |
| 5384 | return getInputDispatchingTimeoutLocked(r.app); |
| 5385 | } |
| 5386 | |
| 5387 | private static long getInputDispatchingTimeoutLocked(WindowProcessController r) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 5388 | return r != null ? r.getInputDispatchingTimeout() : KEY_DISPATCHING_TIMEOUT_MS; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5389 | } |
| 5390 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5391 | /** |
| 5392 | * Decide based on the configuration whether we should show the ANR, |
| 5393 | * crash, etc dialogs. The idea is that if there is no affordance to |
| 5394 | * press the on-screen buttons, or the user experience would be more |
| 5395 | * greatly impacted than the crash itself, we shouldn't show the dialog. |
| 5396 | * |
| 5397 | * A thought: SystemUI might also want to get told about this, the Power |
| 5398 | * dialog / global actions also might want different behaviors. |
| 5399 | */ |
| 5400 | private void updateShouldShowDialogsLocked(Configuration config) { |
| 5401 | final boolean inputMethodExists = !(config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 5402 | && config.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH |
| 5403 | && config.navigation == Configuration.NAVIGATION_NONAV); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5404 | final boolean hideDialogsSet = Settings.Global.getInt(mContext.getContentResolver(), |
| 5405 | HIDE_ERROR_DIALOGS, 0) != 0; |
Yuncheol Heo | 5d9b271 | 2020-04-16 17:31:32 -0700 | [diff] [blame] | 5406 | mShowDialogs = inputMethodExists |
| 5407 | && ActivityTaskManager.currentUiModeSupportsErrorDialogs(mContext) |
| 5408 | && !hideDialogsSet; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5409 | } |
| 5410 | |
| 5411 | private void updateFontScaleIfNeeded(@UserIdInt int userId) { |
| 5412 | final float scaleFactor = Settings.System.getFloatForUser(mContext.getContentResolver(), |
| 5413 | FONT_SCALE, 1.0f, userId); |
| 5414 | |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 5415 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5416 | if (getGlobalConfiguration().fontScale == scaleFactor) { |
| 5417 | return; |
| 5418 | } |
| 5419 | |
| 5420 | final Configuration configuration |
| 5421 | = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
| 5422 | configuration.fontScale = scaleFactor; |
| 5423 | updatePersistentConfiguration(configuration, userId); |
| 5424 | } |
| 5425 | } |
| 5426 | |
| 5427 | // Actually is sleeping or shutting down or whatever else in the future |
| 5428 | // is an inactive state. |
| 5429 | boolean isSleepingOrShuttingDownLocked() { |
| 5430 | return isSleepingLocked() || mShuttingDown; |
| 5431 | } |
| 5432 | |
| 5433 | boolean isSleepingLocked() { |
| 5434 | return mSleeping; |
| 5435 | } |
| 5436 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5437 | /** Update AMS states when an activity is resumed. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5438 | void setResumedActivityUncheckLocked(ActivityRecord r, String reason) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5439 | final Task task = r.getTask(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5440 | if (task.isActivityTypeStandard()) { |
| 5441 | if (mCurAppTimeTracker != r.appTimeTracker) { |
| 5442 | // We are switching app tracking. Complete the current one. |
| 5443 | if (mCurAppTimeTracker != null) { |
| 5444 | mCurAppTimeTracker.stop(); |
| 5445 | mH.obtainMessage( |
| 5446 | REPORT_TIME_TRACKER_MSG, mCurAppTimeTracker).sendToTarget(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5447 | mRootWindowContainer.clearOtherAppTimeTrackers(r.appTimeTracker); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5448 | mCurAppTimeTracker = null; |
| 5449 | } |
| 5450 | if (r.appTimeTracker != null) { |
| 5451 | mCurAppTimeTracker = r.appTimeTracker; |
| 5452 | startTimeTrackingFocusedActivityLocked(); |
| 5453 | } |
| 5454 | } else { |
| 5455 | startTimeTrackingFocusedActivityLocked(); |
| 5456 | } |
| 5457 | } else { |
| 5458 | r.appTimeTracker = null; |
| 5459 | } |
| 5460 | // TODO: VI Maybe r.task.voiceInteractor || r.voiceInteractor != null |
| 5461 | // TODO: Probably not, because we don't want to resume voice on switching |
| 5462 | // back to this activity |
| 5463 | if (task.voiceInteractor != null) { |
| 5464 | startRunningVoiceLocked(task.voiceSession, r.info.applicationInfo.uid); |
| 5465 | } else { |
| 5466 | finishRunningVoiceLocked(); |
| 5467 | |
| 5468 | if (mLastResumedActivity != null) { |
| 5469 | final IVoiceInteractionSession session; |
| 5470 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5471 | final Task lastResumedActivityTask = mLastResumedActivity.getTask(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5472 | if (lastResumedActivityTask != null |
| 5473 | && lastResumedActivityTask.voiceSession != null) { |
| 5474 | session = lastResumedActivityTask.voiceSession; |
| 5475 | } else { |
| 5476 | session = mLastResumedActivity.voiceSession; |
| 5477 | } |
| 5478 | |
| 5479 | if (session != null) { |
| 5480 | // We had been in a voice interaction session, but now focused has |
| 5481 | // move to something different. Just finish the session, we can't |
| 5482 | // return to it and retain the proper state and synchronization with |
| 5483 | // the voice interaction service. |
| 5484 | finishVoiceTask(session); |
| 5485 | } |
| 5486 | } |
| 5487 | } |
| 5488 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5489 | if (mLastResumedActivity != null && r.mUserId != mLastResumedActivity.mUserId) { |
| 5490 | mAmInternal.sendForegroundProfileChanged(r.mUserId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5491 | } |
Bogyun Son | bfb64dc | 2019-12-09 17:50:24 +0900 | [diff] [blame] | 5492 | final Task prevTask = mLastResumedActivity != null ? mLastResumedActivity.getTask() : null; |
| 5493 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5494 | updateResumedAppTrace(r); |
| 5495 | mLastResumedActivity = r; |
| 5496 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 5497 | r.getDisplay().setFocusedApp(r, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5498 | |
Bogyun Son | bfb64dc | 2019-12-09 17:50:24 +0900 | [diff] [blame] | 5499 | if (prevTask == null || task != prevTask) { |
| 5500 | if (prevTask != null) { |
| 5501 | mTaskChangeNotificationController.notifyTaskFocusChanged(prevTask.mTaskId, false); |
| 5502 | } |
| 5503 | mTaskChangeNotificationController.notifyTaskFocusChanged(task.mTaskId, true); |
| 5504 | } |
| 5505 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5506 | applyUpdateLockStateLocked(r); |
| 5507 | applyUpdateVrModeLocked(r); |
| 5508 | |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5509 | EventLogTags.writeWmSetResumedActivity( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5510 | r == null ? -1 : r.mUserId, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5511 | r == null ? "NULL" : r.shortComponentName, |
| 5512 | reason); |
| 5513 | } |
| 5514 | |
| 5515 | ActivityTaskManagerInternal.SleepToken acquireSleepToken(String tag, int displayId) { |
| 5516 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5517 | final ActivityTaskManagerInternal.SleepToken token = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5518 | mRootWindowContainer.createSleepToken(tag, displayId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5519 | updateSleepIfNeededLocked(); |
| 5520 | return token; |
| 5521 | } |
| 5522 | } |
| 5523 | |
| 5524 | void updateSleepIfNeededLocked() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5525 | final boolean shouldSleep = !mRootWindowContainer.hasAwakeDisplay(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5526 | final boolean wasSleeping = mSleeping; |
| 5527 | boolean updateOomAdj = false; |
| 5528 | |
| 5529 | if (!shouldSleep) { |
| 5530 | // If wasSleeping is true, we need to wake up activity manager state from when |
| 5531 | // we started sleeping. In either case, we need to apply the sleep tokens, which |
| 5532 | // will wake up stacks or put them to sleep as appropriate. |
| 5533 | if (wasSleeping) { |
| 5534 | mSleeping = false; |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 5535 | FrameworkStatsLog.write(FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5536 | FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__AWAKE); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5537 | startTimeTrackingFocusedActivityLocked(); |
| 5538 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
Varun Shah | 98694fb | 2019-04-11 09:28:27 -0700 | [diff] [blame] | 5539 | Slog.d(TAG, "Top Process State changed to PROCESS_STATE_TOP"); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5540 | mStackSupervisor.comeOutOfSleepIfNeededLocked(); |
| 5541 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5542 | mRootWindowContainer.applySleepTokens(true /* applyToStacks */); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5543 | if (wasSleeping) { |
| 5544 | updateOomAdj = true; |
| 5545 | } |
| 5546 | } else if (!mSleeping && shouldSleep) { |
| 5547 | mSleeping = true; |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 5548 | FrameworkStatsLog.write(FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5549 | FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__ASLEEP); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5550 | if (mCurAppTimeTracker != null) { |
| 5551 | mCurAppTimeTracker.stop(); |
| 5552 | } |
| 5553 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP_SLEEPING; |
Varun Shah | 98694fb | 2019-04-11 09:28:27 -0700 | [diff] [blame] | 5554 | Slog.d(TAG, "Top Process State changed to PROCESS_STATE_TOP_SLEEPING"); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5555 | mStackSupervisor.goingToSleepLocked(); |
| 5556 | updateResumedAppTrace(null /* resumed */); |
| 5557 | updateOomAdj = true; |
| 5558 | } |
| 5559 | if (updateOomAdj) { |
wilsonshih | 8d096d2 | 2019-08-01 17:46:14 +0800 | [diff] [blame] | 5560 | updateOomAdj(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5561 | } |
| 5562 | } |
| 5563 | |
| 5564 | void updateOomAdj() { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 5565 | mH.removeCallbacks(mUpdateOomAdjRunnable); |
| 5566 | mH.post(mUpdateOomAdjRunnable); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5567 | } |
| 5568 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5569 | void updateCpuStats() { |
| 5570 | mH.post(mAmInternal::updateCpuStats); |
| 5571 | } |
| 5572 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5573 | void updateBatteryStats(ActivityRecord component, boolean resumed) { |
| 5574 | final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::updateBatteryStats, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5575 | mAmInternal, component.mActivityComponent, component.app.mUid, component.mUserId, |
| 5576 | resumed); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5577 | mH.sendMessage(m); |
| 5578 | } |
| 5579 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5580 | void updateActivityUsageStats(ActivityRecord activity, int event) { |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5581 | ComponentName taskRoot = null; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5582 | final Task task = activity.getTask(); |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5583 | if (task != null) { |
| 5584 | final ActivityRecord rootActivity = task.getRootActivity(); |
| 5585 | if (rootActivity != null) { |
| 5586 | taskRoot = rootActivity.mActivityComponent; |
| 5587 | } |
| 5588 | } |
| 5589 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5590 | final Message m = PooledLambda.obtainMessage( |
| 5591 | ActivityManagerInternal::updateActivityUsageStats, mAmInternal, |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5592 | activity.mActivityComponent, activity.mUserId, event, activity.appToken, taskRoot); |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5593 | mH.sendMessage(m); |
| 5594 | } |
| 5595 | |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5596 | void startProcessAsync(ActivityRecord activity, boolean knownToBeDead, boolean isTop, |
| 5597 | String hostingType) { |
| 5598 | try { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5599 | if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) { |
| 5600 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "dispatchingStartProcess:" |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5601 | + activity.processName); |
| 5602 | } |
| 5603 | // Post message to start process to avoid possible deadlock of calling into AMS with the |
| 5604 | // ATMS lock held. |
| 5605 | final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::startProcess, |
| 5606 | mAmInternal, activity.processName, activity.info.applicationInfo, knownToBeDead, |
| 5607 | isTop, hostingType, activity.intent.getComponent()); |
| 5608 | mH.sendMessage(m); |
| 5609 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5610 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5611 | } |
| 5612 | } |
| 5613 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5614 | void setBooting(boolean booting) { |
| 5615 | mAmInternal.setBooting(booting); |
| 5616 | } |
| 5617 | |
| 5618 | boolean isBooting() { |
| 5619 | return mAmInternal.isBooting(); |
| 5620 | } |
| 5621 | |
| 5622 | void setBooted(boolean booted) { |
| 5623 | mAmInternal.setBooted(booted); |
| 5624 | } |
| 5625 | |
| 5626 | boolean isBooted() { |
| 5627 | return mAmInternal.isBooted(); |
| 5628 | } |
| 5629 | |
| 5630 | void postFinishBooting(boolean finishBooting, boolean enableScreen) { |
| 5631 | mH.post(() -> { |
| 5632 | if (finishBooting) { |
| 5633 | mAmInternal.finishBooting(); |
| 5634 | } |
| 5635 | if (enableScreen) { |
| 5636 | mInternal.enableScreenAfterBoot(isBooted()); |
| 5637 | } |
| 5638 | }); |
| 5639 | } |
| 5640 | |
| 5641 | void setHeavyWeightProcess(ActivityRecord root) { |
| 5642 | mHeavyWeightProcess = root.app; |
| 5643 | final Message m = PooledLambda.obtainMessage( |
| 5644 | ActivityTaskManagerService::postHeavyWeightProcessNotification, this, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5645 | root.app, root.intent, root.mUserId); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5646 | mH.sendMessage(m); |
| 5647 | } |
| 5648 | |
| 5649 | void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
| 5650 | if (mHeavyWeightProcess == null || mHeavyWeightProcess != proc) { |
| 5651 | return; |
| 5652 | } |
| 5653 | |
| 5654 | mHeavyWeightProcess = null; |
| 5655 | final Message m = PooledLambda.obtainMessage( |
| 5656 | ActivityTaskManagerService::cancelHeavyWeightProcessNotification, this, |
| 5657 | proc.mUserId); |
| 5658 | mH.sendMessage(m); |
| 5659 | } |
| 5660 | |
| 5661 | private void cancelHeavyWeightProcessNotification(int userId) { |
| 5662 | final INotificationManager inm = NotificationManager.getService(); |
| 5663 | if (inm == null) { |
| 5664 | return; |
| 5665 | } |
| 5666 | try { |
Julia Reynolds | e4a47dd | 2019-06-07 13:40:59 -0400 | [diff] [blame] | 5667 | inm.cancelNotificationWithTag("android", "android", null, |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5668 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, userId); |
| 5669 | } catch (RuntimeException e) { |
| 5670 | Slog.w(TAG, "Error canceling notification for service", e); |
| 5671 | } catch (RemoteException e) { |
| 5672 | } |
| 5673 | |
| 5674 | } |
| 5675 | |
| 5676 | private void postHeavyWeightProcessNotification( |
| 5677 | WindowProcessController proc, Intent intent, int userId) { |
| 5678 | if (proc == null) { |
| 5679 | return; |
| 5680 | } |
| 5681 | |
| 5682 | final INotificationManager inm = NotificationManager.getService(); |
| 5683 | if (inm == null) { |
| 5684 | return; |
| 5685 | } |
| 5686 | |
| 5687 | try { |
| 5688 | Context context = mContext.createPackageContext(proc.mInfo.packageName, 0); |
| 5689 | String text = mContext.getString(R.string.heavy_weight_notification, |
| 5690 | context.getApplicationInfo().loadLabel(context.getPackageManager())); |
| 5691 | Notification notification = |
| 5692 | new Notification.Builder(context, |
| 5693 | SystemNotificationChannels.HEAVY_WEIGHT_APP) |
| 5694 | .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) |
| 5695 | .setWhen(0) |
| 5696 | .setOngoing(true) |
| 5697 | .setTicker(text) |
| 5698 | .setColor(mContext.getColor( |
| 5699 | com.android.internal.R.color.system_notification_accent_color)) |
| 5700 | .setContentTitle(text) |
| 5701 | .setContentText( |
| 5702 | mContext.getText(R.string.heavy_weight_notification_detail)) |
| 5703 | .setContentIntent(PendingIntent.getActivityAsUser(mContext, 0, |
| 5704 | intent, PendingIntent.FLAG_CANCEL_CURRENT, null, |
| 5705 | new UserHandle(userId))) |
| 5706 | .build(); |
| 5707 | try { |
| 5708 | inm.enqueueNotificationWithTag("android", "android", null, |
| 5709 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, notification, userId); |
| 5710 | } catch (RuntimeException e) { |
| 5711 | Slog.w(TAG, "Error showing notification for heavy-weight app", e); |
| 5712 | } catch (RemoteException e) { |
| 5713 | } |
| 5714 | } catch (PackageManager.NameNotFoundException e) { |
| 5715 | Slog.w(TAG, "Unable to create context for heavy notification", e); |
| 5716 | } |
| 5717 | |
| 5718 | } |
| 5719 | |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 5720 | IIntentSender getIntentSenderLocked(int type, String packageName, String featureId, |
| 5721 | int callingUid, int userId, IBinder token, String resultWho, int requestCode, |
| 5722 | Intent[] intents, String[] resolvedTypes, int flags, Bundle bOptions) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5723 | |
| 5724 | ActivityRecord activity = null; |
| 5725 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5726 | activity = ActivityRecord.isInStackLocked(token); |
| 5727 | if (activity == null) { |
| 5728 | Slog.w(TAG, "Failed createPendingResult: activity " + token + " not in any stack"); |
| 5729 | return null; |
| 5730 | } |
| 5731 | if (activity.finishing) { |
| 5732 | Slog.w(TAG, "Failed createPendingResult: activity " + activity + " is finishing"); |
| 5733 | return null; |
| 5734 | } |
| 5735 | } |
| 5736 | |
| 5737 | final PendingIntentRecord rec = mPendingIntentController.getIntentSender(type, packageName, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 5738 | featureId, callingUid, userId, token, resultWho, requestCode, intents, |
| 5739 | resolvedTypes, flags, bOptions); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5740 | final boolean noCreate = (flags & PendingIntent.FLAG_NO_CREATE) != 0; |
| 5741 | if (noCreate) { |
| 5742 | return rec; |
| 5743 | } |
| 5744 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5745 | if (activity.pendingResults == null) { |
| 5746 | activity.pendingResults = new HashSet<>(); |
| 5747 | } |
| 5748 | activity.pendingResults.add(rec.ref); |
| 5749 | } |
| 5750 | return rec; |
| 5751 | } |
| 5752 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 5753 | // 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] | 5754 | private void startTimeTrackingFocusedActivityLocked() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5755 | final ActivityRecord resumedActivity = mRootWindowContainer.getTopResumedActivity(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5756 | if (!mSleeping && mCurAppTimeTracker != null && resumedActivity != null) { |
| 5757 | mCurAppTimeTracker.start(resumedActivity.packageName); |
| 5758 | } |
| 5759 | } |
| 5760 | |
| 5761 | private void updateResumedAppTrace(@Nullable ActivityRecord resumed) { |
| 5762 | if (mTracedResumedActivity != null) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5763 | Trace.asyncTraceEnd(TRACE_TAG_WINDOW_MANAGER, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5764 | constructResumedTraceName(mTracedResumedActivity.packageName), 0); |
| 5765 | } |
| 5766 | if (resumed != null) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5767 | Trace.asyncTraceBegin(TRACE_TAG_WINDOW_MANAGER, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5768 | constructResumedTraceName(resumed.packageName), 0); |
| 5769 | } |
| 5770 | mTracedResumedActivity = resumed; |
| 5771 | } |
| 5772 | |
| 5773 | private String constructResumedTraceName(String packageName) { |
| 5774 | return "focused app: " + packageName; |
| 5775 | } |
| 5776 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5777 | /** Applies latest configuration and/or visibility updates if needed. */ |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5778 | boolean ensureConfigAndVisibilityAfterUpdate(ActivityRecord starting, int changes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5779 | boolean kept = true; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5780 | final ActivityStack mainStack = mRootWindowContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5781 | // mainStack is null during startup. |
| 5782 | if (mainStack != null) { |
| 5783 | if (changes != 0 && starting == null) { |
| 5784 | // If the configuration changed, and the caller is not already |
| 5785 | // in the process of starting an activity, then find the top |
| 5786 | // activity to check if its configuration needs to change. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 5787 | starting = mainStack.topRunningActivity(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5788 | } |
| 5789 | |
| 5790 | if (starting != null) { |
| 5791 | kept = starting.ensureActivityConfiguration(changes, |
| 5792 | false /* preserveWindow */); |
| 5793 | // And we need to make sure at this point that all other activities |
| 5794 | // are made visible with the correct configuration. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5795 | mRootWindowContainer.ensureActivitiesVisible(starting, changes, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5796 | !PRESERVE_WINDOWS); |
| 5797 | } |
| 5798 | } |
| 5799 | |
| 5800 | return kept; |
| 5801 | } |
| 5802 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5803 | void scheduleAppGcsLocked() { |
| 5804 | mH.post(() -> mAmInternal.scheduleAppGcs()); |
| 5805 | } |
| 5806 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5807 | CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) { |
| 5808 | return mCompatModePackages.compatibilityInfoForPackageLocked(ai); |
| 5809 | } |
| 5810 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5811 | /** |
| 5812 | * Returns the PackageManager. Used by classes hosted by {@link ActivityTaskManagerService}. The |
| 5813 | * PackageManager could be unavailable at construction time and therefore needs to be accessed |
| 5814 | * on demand. |
| 5815 | */ |
| 5816 | IPackageManager getPackageManager() { |
| 5817 | return AppGlobals.getPackageManager(); |
| 5818 | } |
| 5819 | |
| 5820 | PackageManagerInternal getPackageManagerInternalLocked() { |
| 5821 | if (mPmInternal == null) { |
| 5822 | mPmInternal = LocalServices.getService(PackageManagerInternal.class); |
| 5823 | } |
| 5824 | return mPmInternal; |
| 5825 | } |
| 5826 | |
Darryl L Johnson | a098222 | 2020-02-18 18:21:51 -0800 | [diff] [blame] | 5827 | ComponentName getSysUiServiceComponentLocked() { |
| 5828 | if (mSysUiServiceComponent == null) { |
| 5829 | final PackageManagerInternal pm = getPackageManagerInternalLocked(); |
| 5830 | mSysUiServiceComponent = pm.getSystemUiServiceComponent(); |
| 5831 | } |
| 5832 | return mSysUiServiceComponent; |
| 5833 | } |
| 5834 | |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 5835 | PermissionPolicyInternal getPermissionPolicyInternal() { |
| 5836 | if (mPermissionPolicyInternal == null) { |
| 5837 | mPermissionPolicyInternal = LocalServices.getService(PermissionPolicyInternal.class); |
| 5838 | } |
| 5839 | return mPermissionPolicyInternal; |
| 5840 | } |
| 5841 | |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 5842 | AppWarnings getAppWarningsLocked() { |
| 5843 | return mAppWarnings; |
| 5844 | } |
| 5845 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5846 | Intent getHomeIntent() { |
| 5847 | Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null); |
| 5848 | intent.setComponent(mTopComponent); |
| 5849 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5850 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5851 | intent.addCategory(Intent.CATEGORY_HOME); |
| 5852 | } |
| 5853 | return intent; |
| 5854 | } |
| 5855 | |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5856 | /** |
| 5857 | * Return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} to resolve secondary home |
| 5858 | * activities. |
| 5859 | * |
Chilun | 939b05c | 2020-02-19 14:50:59 +0800 | [diff] [blame] | 5860 | * @param preferredPackage Specify a preferred package name, otherwise use the package name |
| 5861 | * defined in config_secondaryHomePackage. |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5862 | * @return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} |
| 5863 | */ |
| 5864 | Intent getSecondaryHomeIntent(String preferredPackage) { |
| 5865 | 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] | 5866 | final boolean useSystemProvidedLauncher = mContext.getResources().getBoolean( |
| 5867 | com.android.internal.R.bool.config_useSystemProvidedLauncherForSecondary); |
| 5868 | if (preferredPackage == null || useSystemProvidedLauncher) { |
Chilun | 939b05c | 2020-02-19 14:50:59 +0800 | [diff] [blame] | 5869 | // Using the package name stored in config if no preferred package name or forced. |
| 5870 | final String secondaryHomePackage = mContext.getResources().getString( |
| 5871 | com.android.internal.R.string.config_secondaryHomePackage); |
| 5872 | intent.setPackage(secondaryHomePackage); |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5873 | } else { |
| 5874 | intent.setPackage(preferredPackage); |
| 5875 | } |
| 5876 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5877 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5878 | intent.addCategory(Intent.CATEGORY_SECONDARY_HOME); |
| 5879 | } |
| 5880 | return intent; |
| 5881 | } |
| 5882 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5883 | ApplicationInfo getAppInfoForUser(ApplicationInfo info, int userId) { |
| 5884 | if (info == null) return null; |
| 5885 | ApplicationInfo newInfo = new ApplicationInfo(info); |
| 5886 | newInfo.initForUser(userId); |
| 5887 | return newInfo; |
| 5888 | } |
| 5889 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 5890 | WindowProcessController getProcessController(String processName, int uid) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5891 | if (uid == SYSTEM_UID) { |
| 5892 | // The system gets to run in any process. If there are multiple processes with the same |
| 5893 | // uid, just pick the first (this should never happen). |
| 5894 | final SparseArray<WindowProcessController> procs = |
| 5895 | mProcessNames.getMap().get(processName); |
| 5896 | if (procs == null) return null; |
| 5897 | final int procCount = procs.size(); |
| 5898 | for (int i = 0; i < procCount; i++) { |
| 5899 | final int procUid = procs.keyAt(i); |
| 5900 | if (UserHandle.isApp(procUid) || !UserHandle.isSameUser(procUid, uid)) { |
| 5901 | // Don't use an app process or different user process for system component. |
| 5902 | continue; |
| 5903 | } |
| 5904 | return procs.valueAt(i); |
| 5905 | } |
| 5906 | } |
| 5907 | |
| 5908 | return mProcessNames.get(processName, uid); |
| 5909 | } |
| 5910 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5911 | WindowProcessController getProcessController(IApplicationThread thread) { |
| 5912 | if (thread == null) { |
| 5913 | return null; |
| 5914 | } |
| 5915 | |
| 5916 | final IBinder threadBinder = thread.asBinder(); |
| 5917 | final ArrayMap<String, SparseArray<WindowProcessController>> pmap = mProcessNames.getMap(); |
| 5918 | for (int i = pmap.size()-1; i >= 0; i--) { |
| 5919 | final SparseArray<WindowProcessController> procs = pmap.valueAt(i); |
| 5920 | for (int j = procs.size() - 1; j >= 0; j--) { |
| 5921 | final WindowProcessController proc = procs.valueAt(j); |
| 5922 | if (proc.hasThread() && proc.getThread().asBinder() == threadBinder) { |
| 5923 | return proc; |
| 5924 | } |
| 5925 | } |
| 5926 | } |
| 5927 | |
| 5928 | return null; |
| 5929 | } |
| 5930 | |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 5931 | WindowProcessController getProcessController(int pid, int uid) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 5932 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Yunfan Chen | 8546b21 | 2019-04-01 15:34:44 +0900 | [diff] [blame] | 5933 | if (proc == null) return null; |
| 5934 | if (UserHandle.isApp(uid) && proc.mUid == uid) { |
| 5935 | return proc; |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 5936 | } |
| 5937 | return null; |
| 5938 | } |
| 5939 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 5940 | int getUidState(int uid) { |
| 5941 | return mActiveUids.getUidState(uid); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 5942 | } |
| 5943 | |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 5944 | boolean isUidForeground(int uid) { |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 5945 | // A uid is considered to be foreground if it has a visible non-toast window. |
| 5946 | return mWindowManager.mRoot.isAnyNonToastWindowVisibleForUid(uid); |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 5947 | } |
| 5948 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 5949 | boolean isDeviceOwner(int uid) { |
| 5950 | return uid >= 0 && mDeviceOwnerUid == uid; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 5951 | } |
| 5952 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 5953 | void setDeviceOwnerUid(int uid) { |
| 5954 | mDeviceOwnerUid = uid; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 5955 | } |
| 5956 | |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 5957 | /** |
| 5958 | * @return whitelist tag for a uid from mPendingTempWhitelist, null if not currently on |
| 5959 | * the whitelist |
| 5960 | */ |
| 5961 | String getPendingTempWhitelistTagForUidLocked(int uid) { |
| 5962 | return mPendingTempWhitelist.get(uid); |
| 5963 | } |
| 5964 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5965 | void logAppTooSlow(WindowProcessController app, long startTime, String msg) { |
| 5966 | if (true || Build.IS_USER) { |
| 5967 | return; |
| 5968 | } |
| 5969 | |
| 5970 | StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 5971 | StrictMode.allowThreadDiskWrites(); |
| 5972 | try { |
| 5973 | File tracesDir = new File("/data/anr"); |
| 5974 | File tracesFile = null; |
| 5975 | try { |
| 5976 | tracesFile = File.createTempFile("app_slow", null, tracesDir); |
| 5977 | |
| 5978 | StringBuilder sb = new StringBuilder(); |
Neil Fuller | 9774681 | 2019-08-19 14:20:50 +0100 | [diff] [blame] | 5979 | String timeString = |
| 5980 | TimeMigrationUtils.formatMillisWithFixedFormat(System.currentTimeMillis()); |
| 5981 | sb.append(timeString); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5982 | sb.append(": "); |
| 5983 | TimeUtils.formatDuration(SystemClock.uptimeMillis()-startTime, sb); |
| 5984 | sb.append(" since "); |
| 5985 | sb.append(msg); |
| 5986 | FileOutputStream fos = new FileOutputStream(tracesFile); |
| 5987 | fos.write(sb.toString().getBytes()); |
| 5988 | if (app == null) { |
| 5989 | fos.write("\n*** No application process!".getBytes()); |
| 5990 | } |
| 5991 | fos.close(); |
| 5992 | FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1); // -rw-rw-rw- |
| 5993 | } catch (IOException e) { |
| 5994 | Slog.w(TAG, "Unable to prepare slow app traces file: " + tracesFile, e); |
| 5995 | return; |
| 5996 | } |
| 5997 | |
| 5998 | if (app != null && app.getPid() > 0) { |
| 5999 | ArrayList<Integer> firstPids = new ArrayList<Integer>(); |
| 6000 | firstPids.add(app.getPid()); |
| 6001 | dumpStackTraces(tracesFile.getAbsolutePath(), firstPids, null, null); |
| 6002 | } |
| 6003 | |
| 6004 | File lastTracesFile = null; |
| 6005 | File curTracesFile = null; |
| 6006 | for (int i=9; i>=0; i--) { |
| 6007 | String name = String.format(Locale.US, "slow%02d.txt", i); |
| 6008 | curTracesFile = new File(tracesDir, name); |
| 6009 | if (curTracesFile.exists()) { |
| 6010 | if (lastTracesFile != null) { |
| 6011 | curTracesFile.renameTo(lastTracesFile); |
| 6012 | } else { |
| 6013 | curTracesFile.delete(); |
| 6014 | } |
| 6015 | } |
| 6016 | lastTracesFile = curTracesFile; |
| 6017 | } |
| 6018 | tracesFile.renameTo(curTracesFile); |
| 6019 | } finally { |
| 6020 | StrictMode.setThreadPolicy(oldPolicy); |
| 6021 | } |
| 6022 | } |
| 6023 | |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 6024 | boolean isAssociatedCompanionApp(int userId, int uid) { |
| 6025 | final Set<Integer> allUids = mCompanionAppUidsMap.get(userId); |
| 6026 | if (allUids == null) { |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 6027 | return false; |
| 6028 | } |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 6029 | return allUids.contains(uid); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 6030 | } |
| 6031 | |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 6032 | void notifySingleTaskDisplayEmpty(int displayId) { |
| 6033 | mTaskChangeNotificationController.notifySingleTaskDisplayEmpty(displayId); |
| 6034 | } |
| 6035 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6036 | final class H extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6037 | static final int REPORT_TIME_TRACKER_MSG = 1; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 6038 | |
| 6039 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 6040 | static final int FIRST_ACTIVITY_STACK_MSG = 100; |
| 6041 | static final int FIRST_SUPERVISOR_STACK_MSG = 200; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6042 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 6043 | H(Looper looper) { |
| 6044 | super(looper); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6045 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6046 | |
| 6047 | @Override |
| 6048 | public void handleMessage(Message msg) { |
| 6049 | switch (msg.what) { |
| 6050 | case REPORT_TIME_TRACKER_MSG: { |
| 6051 | AppTimeTracker tracker = (AppTimeTracker) msg.obj; |
| 6052 | tracker.deliverResult(mContext); |
| 6053 | } break; |
| 6054 | } |
| 6055 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6056 | } |
| 6057 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6058 | final class UiHandler extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6059 | static final int DISMISS_DIALOG_UI_MSG = 1; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6060 | |
| 6061 | public UiHandler() { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 6062 | super(UiThread.get().getLooper(), null, true); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6063 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6064 | |
| 6065 | @Override |
| 6066 | public void handleMessage(Message msg) { |
| 6067 | switch (msg.what) { |
| 6068 | case DISMISS_DIALOG_UI_MSG: { |
| 6069 | final Dialog d = (Dialog) msg.obj; |
| 6070 | d.dismiss(); |
| 6071 | break; |
| 6072 | } |
| 6073 | } |
| 6074 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6075 | } |
| 6076 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6077 | final class LocalService extends ActivityTaskManagerInternal { |
| 6078 | @Override |
| 6079 | public SleepToken acquireSleepToken(String tag, int displayId) { |
Daulet Zhanguzin | c6c641f | 2020-01-02 17:18:30 +0000 | [diff] [blame] | 6080 | Objects.requireNonNull(tag); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6081 | return ActivityTaskManagerService.this.acquireSleepToken(tag, displayId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6082 | } |
| 6083 | |
| 6084 | @Override |
| 6085 | public ComponentName getHomeActivityForUser(int userId) { |
| 6086 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6087 | final ActivityRecord homeActivity = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6088 | mRootWindowContainer.getDefaultDisplayHomeActivityForUser(userId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 6089 | return homeActivity == null ? null : homeActivity.mActivityComponent; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6090 | } |
| 6091 | } |
| 6092 | |
| 6093 | @Override |
| 6094 | public void onLocalVoiceInteractionStarted(IBinder activity, |
| 6095 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 6096 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6097 | onLocalVoiceInteractionStartedLocked(activity, voiceSession, voiceInteractor); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6098 | } |
| 6099 | } |
| 6100 | |
| 6101 | @Override |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 6102 | public void notifySingleTaskDisplayDrawn(int displayId) { |
| 6103 | mTaskChangeNotificationController.notifySingleTaskDisplayDrawn(displayId); |
| 6104 | } |
| 6105 | |
| 6106 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6107 | public List<IBinder> getTopVisibleActivities() { |
| 6108 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6109 | return mRootWindowContainer.getTopVisibleActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6110 | } |
| 6111 | } |
| 6112 | |
| 6113 | @Override |
Bernardo Rufino | e6cb310 | 2020-03-06 20:33:11 +0000 | [diff] [blame] | 6114 | public boolean hasResumedActivity(int uid) { |
| 6115 | synchronized (mGlobalLock) { |
| 6116 | final ArraySet<WindowProcessController> processes = mProcessMap.getProcesses(uid); |
| 6117 | for (int i = 0, n = processes.size(); i < n; i++) { |
| 6118 | final WindowProcessController process = processes.valueAt(i); |
| 6119 | if (process.hasResumedActivity()) { |
| 6120 | return true; |
| 6121 | } |
| 6122 | } |
| 6123 | } |
| 6124 | return false; |
| 6125 | } |
| 6126 | |
| 6127 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6128 | public int startActivitiesAsPackage(String packageName, @Nullable String featureId, |
| 6129 | int userId, Intent[] intents, Bundle bOptions) { |
Daulet Zhanguzin | c6c641f | 2020-01-02 17:18:30 +0000 | [diff] [blame] | 6130 | Objects.requireNonNull(intents, "intents"); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6131 | final String[] resolvedTypes = new String[intents.length]; |
| 6132 | |
| 6133 | // UID of the package on user userId. |
| 6134 | // "= 0" is needed because otherwise catch(RemoteException) would make it look like |
| 6135 | // packageUid may not be initialized. |
| 6136 | int packageUid = 0; |
| 6137 | final long ident = Binder.clearCallingIdentity(); |
| 6138 | |
| 6139 | try { |
| 6140 | for (int i = 0; i < intents.length; i++) { |
| 6141 | resolvedTypes[i] = |
| 6142 | intents[i].resolveTypeIfNeeded(mContext.getContentResolver()); |
| 6143 | } |
| 6144 | |
| 6145 | packageUid = AppGlobals.getPackageManager().getPackageUid( |
| 6146 | packageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId); |
| 6147 | } catch (RemoteException e) { |
| 6148 | // Shouldn't happen. |
| 6149 | } finally { |
| 6150 | Binder.restoreCallingIdentity(ident); |
| 6151 | } |
| 6152 | |
Riddle Hsu | 591bf61 | 2019-02-14 17:55:31 +0800 | [diff] [blame] | 6153 | return getActivityStartController().startActivitiesInPackage( |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6154 | packageUid, packageName, featureId, |
Riddle Hsu | 591bf61 | 2019-02-14 17:55:31 +0800 | [diff] [blame] | 6155 | intents, resolvedTypes, null /* resultTo */, |
| 6156 | SafeActivityOptions.fromBundle(bOptions), userId, |
| 6157 | false /* validateIncomingUser */, null /* originatingPendingIntent */, |
| 6158 | false /* allowBackgroundActivityStart */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6159 | } |
| 6160 | |
| 6161 | @Override |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6162 | public int startActivitiesInPackage(int uid, int realCallingPid, int realCallingUid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6163 | String callingPackage, @Nullable String callingFeatureId, Intent[] intents, |
| 6164 | String[] resolvedTypes, IBinder resultTo, SafeActivityOptions options, int userId, |
| 6165 | boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6166 | boolean allowBackgroundActivityStart) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 6167 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6168 | synchronized (mGlobalLock) { |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6169 | return getActivityStartController().startActivitiesInPackage(uid, realCallingPid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6170 | realCallingUid, callingPackage, callingFeatureId, intents, resolvedTypes, |
| 6171 | resultTo, options, userId, validateIncomingUser, originatingPendingIntent, |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6172 | allowBackgroundActivityStart); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6173 | } |
| 6174 | } |
| 6175 | |
| 6176 | @Override |
| 6177 | public int startActivityInPackage(int uid, int realCallingPid, int realCallingUid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6178 | String callingPackage, @Nullable String callingFeatureId, Intent intent, |
| 6179 | String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 6180 | int startFlags, SafeActivityOptions options, int userId, Task inTask, String reason, |
| 6181 | boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6182 | boolean allowBackgroundActivityStart) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 6183 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6184 | synchronized (mGlobalLock) { |
| 6185 | return getActivityStartController().startActivityInPackage(uid, realCallingPid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6186 | realCallingUid, callingPackage, callingFeatureId, intent, resolvedType, |
| 6187 | resultTo, resultWho, requestCode, startFlags, options, userId, inTask, |
| 6188 | reason, validateIncomingUser, originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6189 | allowBackgroundActivityStart); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6190 | } |
| 6191 | } |
| 6192 | |
| 6193 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6194 | public int startActivityAsUser(IApplicationThread caller, String callerPackage, |
Alex Kershaw | 16406c3 | 2020-02-17 12:28:53 +0000 | [diff] [blame] | 6195 | @Nullable String callerFeatureId, Intent intent, @Nullable IBinder resultTo, |
| 6196 | int startFlags, Bundle options, int userId) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6197 | return ActivityTaskManagerService.this.startActivityAsUser( |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6198 | caller, callerPackage, callerFeatureId, intent, |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6199 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Alex Kershaw | 16406c3 | 2020-02-17 12:28:53 +0000 | [diff] [blame] | 6200 | resultTo, null, 0, startFlags, null, options, userId, |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6201 | false /*validateIncomingUser*/); |
| 6202 | } |
| 6203 | |
| 6204 | @Override |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 6205 | public void notifyKeyguardFlagsChanged(@Nullable Runnable callback, int displayId) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6206 | synchronized (mGlobalLock) { |
| 6207 | |
| 6208 | // We might change the visibilities here, so prepare an empty app transition which |
| 6209 | // might be overridden later if we actually change visibilities. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6210 | final DisplayContent displayContent = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6211 | mRootWindowContainer.getDisplayContent(displayId); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6212 | if (displayContent == null) { |
lumark | 52ea28e | 2018-11-09 17:30:47 +0800 | [diff] [blame] | 6213 | return; |
| 6214 | } |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6215 | final DisplayContent dc = displayContent.mDisplayContent; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6216 | final boolean wasTransitionSet = |
| 6217 | dc.mAppTransition.getAppTransition() != TRANSIT_NONE; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6218 | if (!wasTransitionSet) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6219 | dc.prepareAppTransition(TRANSIT_NONE, false /* alwaysKeepCurrent */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6220 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6221 | mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6222 | |
| 6223 | // If there was a transition set already we don't want to interfere with it as we |
| 6224 | // might be starting it too early. |
| 6225 | if (!wasTransitionSet) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6226 | dc.executeAppTransition(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6227 | } |
| 6228 | } |
| 6229 | if (callback != null) { |
| 6230 | callback.run(); |
| 6231 | } |
| 6232 | } |
| 6233 | |
| 6234 | @Override |
| 6235 | public void notifyKeyguardTrustedChanged() { |
| 6236 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6237 | if (mKeyguardController.isKeyguardShowing(DEFAULT_DISPLAY)) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6238 | mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6239 | } |
| 6240 | } |
| 6241 | } |
| 6242 | |
| 6243 | /** |
| 6244 | * Called after virtual display Id is updated by |
| 6245 | * {@link com.android.server.vr.Vr2dDisplay} with a specific |
| 6246 | * {@param vrVr2dDisplayId}. |
| 6247 | */ |
| 6248 | @Override |
| 6249 | public void setVr2dDisplayId(int vr2dDisplayId) { |
| 6250 | if (DEBUG_STACK) Slog.d(TAG, "setVr2dDisplayId called for: " + vr2dDisplayId); |
| 6251 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6252 | mVr2dDisplayId = vr2dDisplayId; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6253 | } |
| 6254 | } |
| 6255 | |
| 6256 | @Override |
| 6257 | public void setFocusedActivity(IBinder token) { |
| 6258 | synchronized (mGlobalLock) { |
| 6259 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 6260 | if (r == null) { |
| 6261 | throw new IllegalArgumentException( |
| 6262 | "setFocusedActivity: No activity record matching token=" + token); |
| 6263 | } |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 6264 | if (r.moveFocusableActivityToTop("setFocusedActivity")) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6265 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6266 | } |
| 6267 | } |
| 6268 | } |
| 6269 | |
| 6270 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6271 | public void registerScreenObserver(ScreenObserver observer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6272 | mScreenObservers.add(observer); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6273 | } |
| 6274 | |
| 6275 | @Override |
| 6276 | public boolean isCallerRecents(int callingUid) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 6277 | return getRecentTasks().isCallerRecents(callingUid); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6278 | } |
| 6279 | |
| 6280 | @Override |
| 6281 | public boolean isRecentsComponentHomeActivity(int userId) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 6282 | return getRecentTasks().isRecentsComponentHomeActivity(userId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6283 | } |
| 6284 | |
| 6285 | @Override |
| 6286 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
| 6287 | ActivityTaskManagerService.this.cancelRecentsAnimation(restoreHomeStackPosition); |
| 6288 | } |
| 6289 | |
| 6290 | @Override |
| 6291 | public void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6292 | ActivityTaskManagerService.this.enforceCallerIsRecentsOrHasPermission(permission, func); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6293 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6294 | |
| 6295 | @Override |
| 6296 | public void notifyActiveVoiceInteractionServiceChanged(ComponentName component) { |
| 6297 | synchronized (mGlobalLock) { |
| 6298 | mActiveVoiceInteractionServiceComponent = component; |
| 6299 | } |
| 6300 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6301 | |
| 6302 | @Override |
Galia Peycheva | 480275a | 2020-03-18 17:33:42 +0100 | [diff] [blame] | 6303 | public void notifyDreamStateChanged(boolean dreaming) { |
| 6304 | synchronized (mGlobalLock) { |
| 6305 | mDreaming = dreaming; |
| 6306 | } |
| 6307 | } |
| 6308 | |
| 6309 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6310 | public void setAllowAppSwitches(@NonNull String type, int uid, int userId) { |
| 6311 | if (!mAmInternal.isUserRunning(userId, ActivityManager.FLAG_OR_STOPPED)) { |
| 6312 | return; |
| 6313 | } |
| 6314 | synchronized (mGlobalLock) { |
| 6315 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(userId); |
| 6316 | if (types == null) { |
| 6317 | if (uid < 0) { |
| 6318 | return; |
| 6319 | } |
| 6320 | types = new ArrayMap<>(); |
| 6321 | mAllowAppSwitchUids.put(userId, types); |
| 6322 | } |
| 6323 | if (uid < 0) { |
| 6324 | types.remove(type); |
| 6325 | } else { |
| 6326 | types.put(type, uid); |
| 6327 | } |
| 6328 | } |
| 6329 | } |
| 6330 | |
| 6331 | @Override |
| 6332 | public void onUserStopped(int userId) { |
| 6333 | synchronized (mGlobalLock) { |
| 6334 | getRecentTasks().unloadUserDataFromMemoryLocked(userId); |
| 6335 | mAllowAppSwitchUids.remove(userId); |
| 6336 | } |
| 6337 | } |
| 6338 | |
| 6339 | @Override |
| 6340 | public boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 6341 | synchronized (mGlobalLock) { |
| 6342 | return ActivityTaskManagerService.this.isGetTasksAllowed( |
| 6343 | caller, callingPid, callingUid); |
| 6344 | } |
| 6345 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6346 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6347 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6348 | @Override |
| 6349 | public void onProcessAdded(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6350 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6351 | mProcessNames.put(proc.mName, proc.mUid, proc); |
| 6352 | } |
| 6353 | } |
| 6354 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6355 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6356 | @Override |
| 6357 | public void onProcessRemoved(String name, int uid) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6358 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6359 | mProcessNames.remove(name, uid); |
| 6360 | } |
| 6361 | } |
| 6362 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6363 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6364 | @Override |
| 6365 | public void onCleanUpApplicationRecord(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6366 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6367 | if (proc == mHomeProcess) { |
| 6368 | mHomeProcess = null; |
| 6369 | } |
| 6370 | if (proc == mPreviousProcess) { |
| 6371 | mPreviousProcess = null; |
| 6372 | } |
| 6373 | } |
| 6374 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6375 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6376 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6377 | @Override |
| 6378 | public int getTopProcessState() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6379 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6380 | return mTopProcessState; |
| 6381 | } |
| 6382 | } |
| 6383 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6384 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6385 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6386 | public boolean isHeavyWeightProcess(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6387 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6388 | return proc == mHeavyWeightProcess; |
| 6389 | } |
| 6390 | } |
| 6391 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6392 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6393 | @Override |
| 6394 | public void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6395 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6396 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals(proc); |
| 6397 | } |
| 6398 | } |
| 6399 | |
| 6400 | @Override |
| 6401 | public void finishHeavyWeightApp() { |
| 6402 | synchronized (mGlobalLock) { |
Sudheer Shanka | ee1da27 | 2018-10-20 20:11:44 -0700 | [diff] [blame] | 6403 | if (mHeavyWeightProcess != null) { |
| 6404 | mHeavyWeightProcess.finishActivities(); |
| 6405 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6406 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals( |
| 6407 | mHeavyWeightProcess); |
| 6408 | } |
| 6409 | } |
| 6410 | |
Galia Peycheva | 480275a | 2020-03-18 17:33:42 +0100 | [diff] [blame] | 6411 | @Override |
| 6412 | public boolean isDreaming() { |
| 6413 | synchronized (mGlobalLock) { |
| 6414 | return mDreaming; |
| 6415 | } |
| 6416 | } |
| 6417 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6418 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6419 | @Override |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6420 | public boolean isSleeping() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6421 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6422 | return isSleepingLocked(); |
| 6423 | } |
| 6424 | } |
| 6425 | |
| 6426 | @Override |
| 6427 | public boolean isShuttingDown() { |
| 6428 | synchronized (mGlobalLock) { |
| 6429 | return mShuttingDown; |
| 6430 | } |
| 6431 | } |
| 6432 | |
| 6433 | @Override |
| 6434 | public boolean shuttingDown(boolean booted, int timeout) { |
| 6435 | synchronized (mGlobalLock) { |
| 6436 | mShuttingDown = true; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6437 | mRootWindowContainer.prepareForShutdown(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6438 | updateEventDispatchingLocked(booted); |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 6439 | notifyTaskPersisterLocked(null, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6440 | return mStackSupervisor.shutdownLocked(timeout); |
| 6441 | } |
| 6442 | } |
| 6443 | |
| 6444 | @Override |
| 6445 | public void enableScreenAfterBoot(boolean booted) { |
| 6446 | synchronized (mGlobalLock) { |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 6447 | writeBootProgressEnableScreen(SystemClock.uptimeMillis()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6448 | mWindowManager.enableScreenAfterBoot(); |
| 6449 | updateEventDispatchingLocked(booted); |
| 6450 | } |
| 6451 | } |
| 6452 | |
| 6453 | @Override |
| 6454 | public boolean showStrictModeViolationDialog() { |
| 6455 | synchronized (mGlobalLock) { |
| 6456 | return mShowDialogs && !mSleeping && !mShuttingDown; |
| 6457 | } |
| 6458 | } |
| 6459 | |
| 6460 | @Override |
| 6461 | public void showSystemReadyErrorDialogsIfNeeded() { |
| 6462 | synchronized (mGlobalLock) { |
| 6463 | try { |
| 6464 | if (AppGlobals.getPackageManager().hasSystemUidErrors()) { |
| 6465 | Slog.e(TAG, "UIDs on the system are inconsistent, you need to wipe your" |
| 6466 | + " data partition or your device will be unstable."); |
| 6467 | mUiHandler.post(() -> { |
| 6468 | if (mShowDialogs) { |
| 6469 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6470 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6471 | d.setCancelable(false); |
| 6472 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6473 | d.setMessage(mUiContext.getText(R.string.system_error_wipe_data)); |
| 6474 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6475 | mUiContext.getText(R.string.ok), |
| 6476 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6477 | d.show(); |
| 6478 | } |
| 6479 | }); |
| 6480 | } |
| 6481 | } catch (RemoteException e) { |
| 6482 | } |
| 6483 | |
| 6484 | if (!Build.isBuildConsistent()) { |
| 6485 | Slog.e(TAG, "Build fingerprint is not consistent, warning user"); |
| 6486 | mUiHandler.post(() -> { |
| 6487 | if (mShowDialogs) { |
| 6488 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6489 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6490 | d.setCancelable(false); |
| 6491 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6492 | d.setMessage(mUiContext.getText(R.string.system_error_manufacturer)); |
| 6493 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6494 | mUiContext.getText(R.string.ok), |
| 6495 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6496 | d.show(); |
| 6497 | } |
| 6498 | }); |
| 6499 | } |
| 6500 | } |
| 6501 | } |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6502 | |
| 6503 | @Override |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6504 | public void onProcessMapped(int pid, WindowProcessController proc) { |
| 6505 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6506 | mProcessMap.put(pid, proc); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6507 | } |
| 6508 | } |
| 6509 | |
| 6510 | @Override |
| 6511 | public void onProcessUnMapped(int pid) { |
| 6512 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6513 | mProcessMap.remove(pid); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6514 | } |
| 6515 | } |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6516 | |
| 6517 | @Override |
| 6518 | public void onPackageDataCleared(String name) { |
| 6519 | synchronized (mGlobalLock) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6520 | mCompatModePackages.handlePackageDataClearedLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6521 | mAppWarnings.onPackageDataCleared(name); |
| 6522 | } |
| 6523 | } |
| 6524 | |
| 6525 | @Override |
| 6526 | public void onPackageUninstalled(String name) { |
| 6527 | synchronized (mGlobalLock) { |
| 6528 | mAppWarnings.onPackageUninstalled(name); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6529 | mCompatModePackages.handlePackageUninstalledLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6530 | } |
| 6531 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6532 | |
| 6533 | @Override |
| 6534 | public void onPackageAdded(String name, boolean replacing) { |
| 6535 | synchronized (mGlobalLock) { |
| 6536 | mCompatModePackages.handlePackageAddedLocked(name, replacing); |
| 6537 | } |
| 6538 | } |
| 6539 | |
| 6540 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6541 | public void onPackageReplaced(ApplicationInfo aInfo) { |
| 6542 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6543 | mRootWindowContainer.updateActivityApplicationInfo(aInfo); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6544 | } |
| 6545 | } |
| 6546 | |
| 6547 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6548 | public CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai) { |
| 6549 | synchronized (mGlobalLock) { |
| 6550 | return compatibilityInfoForPackageLocked(ai); |
| 6551 | } |
| 6552 | } |
| 6553 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6554 | /** |
| 6555 | * Set the corresponding display information for the process global configuration. To be |
| 6556 | * called when we need to show IME on a different display. |
| 6557 | * |
| 6558 | * @param pid The process id associated with the IME window. |
| 6559 | * @param displayId The ID of the display showing the IME. |
| 6560 | */ |
| 6561 | @Override |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6562 | public void onImeWindowSetOnDisplay(final int pid, final int displayId) { |
lumark | 4897353 | 2019-04-12 20:18:15 +0800 | [diff] [blame] | 6563 | // Don't update process-level configuration for Multi-Client IME process since other |
| 6564 | // IMEs on other displays will also receive this configuration change due to IME |
| 6565 | // services use the same application config/context. |
| 6566 | if (InputMethodSystemProperty.MULTI_CLIENT_IME_ENABLED) return; |
lumark | 5df4951 | 2019-04-02 14:56:46 +0800 | [diff] [blame] | 6567 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6568 | if (pid == MY_PID || pid < 0) { |
| 6569 | if (DEBUG_CONFIGURATION) { |
| 6570 | Slog.w(TAG, |
| 6571 | "Trying to update display configuration for system/invalid process."); |
| 6572 | } |
| 6573 | return; |
| 6574 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6575 | synchronized (mGlobalLock) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6576 | final DisplayContent displayContent = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6577 | mRootWindowContainer.getDisplayContent(displayId); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6578 | if (displayContent == null) { |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6579 | // Call might come when display is not yet added or has been removed. |
| 6580 | if (DEBUG_CONFIGURATION) { |
| 6581 | Slog.w(TAG, "Trying to update display configuration for non-existing " |
| 6582 | + "displayId=" + displayId); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6583 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6584 | return; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6585 | } |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6586 | final WindowProcessController process = mProcessMap.getProcess(pid); |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6587 | if (process == null) { |
| 6588 | if (DEBUG_CONFIGURATION) { |
| 6589 | Slog.w(TAG, "Trying to update display configuration for invalid " |
| 6590 | + "process, pid=" + pid); |
| 6591 | } |
| 6592 | return; |
| 6593 | } |
Andrii Kulian | fa23a9e | 2019-10-10 15:15:36 -0700 | [diff] [blame] | 6594 | process.registerDisplayConfigurationListener(displayContent); |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6595 | } |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6596 | } |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6597 | |
| 6598 | @Override |
| 6599 | public void sendActivityResult(int callingUid, IBinder activityToken, String resultWho, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 6600 | int requestCode, int resultCode, Intent data) { |
Jeff Sharkey | 307ea7a | 2020-04-13 10:24:49 -0600 | [diff] [blame] | 6601 | final ActivityRecord r; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6602 | synchronized (mGlobalLock) { |
Jeff Sharkey | 307ea7a | 2020-04-13 10:24:49 -0600 | [diff] [blame] | 6603 | r = ActivityRecord.isInStackLocked(activityToken); |
| 6604 | if (r == null || r.getRootTask() == null) { |
| 6605 | return; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6606 | } |
| 6607 | } |
Jeff Sharkey | 307ea7a | 2020-04-13 10:24:49 -0600 | [diff] [blame] | 6608 | |
| 6609 | // Carefully collect grants without holding lock |
| 6610 | final NeededUriGrants dataGrants = collectGrants(data, r); |
| 6611 | |
| 6612 | synchronized (mGlobalLock) { |
| 6613 | r.sendResult(callingUid, resultWho, requestCode, resultCode, data, dataGrants); |
| 6614 | } |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6615 | } |
| 6616 | |
| 6617 | @Override |
| 6618 | public void clearPendingResultForActivity(IBinder activityToken, |
| 6619 | WeakReference<PendingIntentRecord> pir) { |
| 6620 | synchronized (mGlobalLock) { |
| 6621 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 6622 | if (r != null && r.pendingResults != null) { |
| 6623 | r.pendingResults.remove(pir); |
| 6624 | } |
| 6625 | } |
| 6626 | } |
| 6627 | |
| 6628 | @Override |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6629 | public ActivityTokens getTopActivityForTask(int taskId) { |
| 6630 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6631 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 6632 | if (task == null) { |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6633 | Slog.w(TAG, "getApplicationThreadForTopActivity failed:" |
| 6634 | + " Requested task not found"); |
| 6635 | return null; |
| 6636 | } |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 6637 | final ActivityRecord activity = task.getTopNonFinishingActivity(); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6638 | if (activity == null) { |
| 6639 | Slog.w(TAG, "getApplicationThreadForTopActivity failed:" |
| 6640 | + " Requested activity not found"); |
| 6641 | return null; |
| 6642 | } |
| 6643 | if (!activity.attachedToProcess()) { |
| 6644 | Slog.w(TAG, "getApplicationThreadForTopActivity failed: No process for " |
| 6645 | + activity); |
| 6646 | return null; |
| 6647 | } |
| 6648 | return new ActivityTokens(activity.appToken, activity.assistToken, |
| 6649 | activity.app.getThread()); |
| 6650 | } |
| 6651 | } |
| 6652 | |
| 6653 | @Override |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6654 | public IIntentSender getIntentSender(int type, String packageName, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6655 | @Nullable String featureId, int callingUid, int userId, IBinder token, |
| 6656 | String resultWho, int requestCode, Intent[] intents, String[] resolvedTypes, |
| 6657 | int flags, Bundle bOptions) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6658 | synchronized (mGlobalLock) { |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6659 | return getIntentSenderLocked(type, packageName, featureId, callingUid, userId, |
| 6660 | token, resultWho, requestCode, intents, resolvedTypes, flags, bOptions); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6661 | } |
| 6662 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 6663 | |
| 6664 | @Override |
| 6665 | public ActivityServiceConnectionsHolder getServiceConnectionsHolder(IBinder token) { |
| 6666 | synchronized (mGlobalLock) { |
| 6667 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 6668 | if (r == null) { |
| 6669 | return null; |
| 6670 | } |
| 6671 | if (r.mServiceConnectionsHolder == null) { |
| 6672 | r.mServiceConnectionsHolder = new ActivityServiceConnectionsHolder( |
| 6673 | ActivityTaskManagerService.this, r); |
| 6674 | } |
| 6675 | |
| 6676 | return r.mServiceConnectionsHolder; |
| 6677 | } |
| 6678 | } |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6679 | |
| 6680 | @Override |
| 6681 | public Intent getHomeIntent() { |
| 6682 | synchronized (mGlobalLock) { |
| 6683 | return ActivityTaskManagerService.this.getHomeIntent(); |
| 6684 | } |
| 6685 | } |
| 6686 | |
| 6687 | @Override |
| 6688 | public boolean startHomeActivity(int userId, String reason) { |
| 6689 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6690 | return mRootWindowContainer.startHomeOnDisplay(userId, reason, DEFAULT_DISPLAY); |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6691 | } |
| 6692 | } |
| 6693 | |
| 6694 | @Override |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 6695 | public boolean startHomeOnDisplay(int userId, String reason, int displayId, |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 6696 | boolean allowInstrumenting, boolean fromHomeKey) { |
Chilun | 5fd5654 | 2019-03-21 19:51:37 +0800 | [diff] [blame] | 6697 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6698 | return mRootWindowContainer.startHomeOnDisplay(userId, reason, displayId, |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 6699 | allowInstrumenting, fromHomeKey); |
Chilun | 5fd5654 | 2019-03-21 19:51:37 +0800 | [diff] [blame] | 6700 | } |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 6701 | } |
| 6702 | |
| 6703 | @Override |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6704 | public boolean startHomeOnAllDisplays(int userId, String reason) { |
| 6705 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6706 | return mRootWindowContainer.startHomeOnAllDisplays(userId, reason); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6707 | } |
| 6708 | } |
| 6709 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6710 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6711 | @Override |
| 6712 | public boolean isFactoryTestProcess(WindowProcessController wpc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6713 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6714 | if (mFactoryTest == FACTORY_TEST_OFF) { |
| 6715 | return false; |
| 6716 | } |
| 6717 | if (mFactoryTest == FACTORY_TEST_LOW_LEVEL && mTopComponent != null |
| 6718 | && wpc.mName.equals(mTopComponent.getPackageName())) { |
| 6719 | return true; |
| 6720 | } |
| 6721 | return mFactoryTest == FACTORY_TEST_HIGH_LEVEL |
| 6722 | && (wpc.mInfo.flags & FLAG_FACTORY_TEST) != 0; |
| 6723 | } |
| 6724 | } |
| 6725 | |
| 6726 | @Override |
| 6727 | public void updateTopComponentForFactoryTest() { |
| 6728 | synchronized (mGlobalLock) { |
| 6729 | if (mFactoryTest != FACTORY_TEST_LOW_LEVEL) { |
| 6730 | return; |
| 6731 | } |
| 6732 | final ResolveInfo ri = mContext.getPackageManager() |
| 6733 | .resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST), STOCK_PM_FLAGS); |
| 6734 | final CharSequence errorMsg; |
| 6735 | if (ri != null) { |
| 6736 | final ActivityInfo ai = ri.activityInfo; |
| 6737 | final ApplicationInfo app = ai.applicationInfo; |
| 6738 | if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 6739 | mTopAction = Intent.ACTION_FACTORY_TEST; |
| 6740 | mTopData = null; |
| 6741 | mTopComponent = new ComponentName(app.packageName, ai.name); |
| 6742 | errorMsg = null; |
| 6743 | } else { |
| 6744 | errorMsg = mContext.getResources().getText( |
| 6745 | com.android.internal.R.string.factorytest_not_system); |
| 6746 | } |
| 6747 | } else { |
| 6748 | errorMsg = mContext.getResources().getText( |
| 6749 | com.android.internal.R.string.factorytest_no_action); |
| 6750 | } |
| 6751 | if (errorMsg == null) { |
| 6752 | return; |
| 6753 | } |
| 6754 | |
| 6755 | mTopAction = null; |
| 6756 | mTopData = null; |
| 6757 | mTopComponent = null; |
| 6758 | mUiHandler.post(() -> { |
| 6759 | Dialog d = new FactoryErrorDialog(mUiContext, errorMsg); |
| 6760 | d.show(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 6761 | mAmInternal.ensureBootCompleted(); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6762 | }); |
| 6763 | } |
| 6764 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6765 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6766 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6767 | @Override |
| 6768 | public void handleAppDied(WindowProcessController wpc, boolean restarting, |
| 6769 | Runnable finishInstrumentationCallback) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6770 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6771 | // Remove this application's activities from active lists. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6772 | boolean hasVisibleActivities = mRootWindowContainer.handleAppDied(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6773 | |
| 6774 | wpc.clearRecentTasks(); |
| 6775 | wpc.clearActivities(); |
| 6776 | |
| 6777 | if (wpc.isInstrumenting()) { |
| 6778 | finishInstrumentationCallback.run(); |
| 6779 | } |
| 6780 | |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6781 | if (!restarting && hasVisibleActivities) { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 6782 | deferWindowLayout(); |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6783 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6784 | if (!mRootWindowContainer.resumeFocusedStacksTopActivities()) { |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6785 | // If there was nothing to resume, and we are not already restarting |
| 6786 | // this process, but there is a visible activity that is hosted by the |
| 6787 | // process...then make sure all visible activities are running, taking |
| 6788 | // care of restarting this process. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6789 | mRootWindowContainer.ensureActivitiesVisible(null, 0, |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6790 | !PRESERVE_WINDOWS); |
| 6791 | } |
| 6792 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 6793 | continueWindowLayout(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6794 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6795 | } |
| 6796 | } |
| 6797 | } |
| 6798 | |
| 6799 | @Override |
| 6800 | public void closeSystemDialogs(String reason) { |
| 6801 | enforceNotIsolatedCaller("closeSystemDialogs"); |
| 6802 | |
| 6803 | final int pid = Binder.getCallingPid(); |
| 6804 | final int uid = Binder.getCallingUid(); |
| 6805 | final long origId = Binder.clearCallingIdentity(); |
| 6806 | try { |
| 6807 | synchronized (mGlobalLock) { |
| 6808 | // Only allow this from foreground processes, so that background |
| 6809 | // applications can't abuse it to prevent system UI from being shown. |
| 6810 | if (uid >= FIRST_APPLICATION_UID) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6811 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6812 | if (!proc.isPerceptible()) { |
| 6813 | Slog.w(TAG, "Ignoring closeSystemDialogs " + reason |
| 6814 | + " from background process " + proc); |
| 6815 | return; |
| 6816 | } |
| 6817 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6818 | mWindowManager.closeSystemDialogs(reason); |
| 6819 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6820 | mRootWindowContainer.closeSystemDialogs(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6821 | } |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 6822 | // Call into AM outside the synchronized block. |
| 6823 | mAmInternal.broadcastCloseSystemDialogs(reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6824 | } finally { |
| 6825 | Binder.restoreCallingIdentity(origId); |
| 6826 | } |
| 6827 | } |
| 6828 | |
| 6829 | @Override |
| 6830 | public void cleanupDisabledPackageComponents( |
| 6831 | String packageName, Set<String> disabledClasses, int userId, boolean booted) { |
| 6832 | synchronized (mGlobalLock) { |
| 6833 | // Clean-up disabled activities. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6834 | if (mRootWindowContainer.finishDisabledPackageActivities( |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6835 | packageName, disabledClasses, true, false, userId) && booted) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6836 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 6837 | mStackSupervisor.scheduleIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6838 | } |
| 6839 | |
| 6840 | // Clean-up disabled tasks |
| 6841 | getRecentTasks().cleanupDisabledPackageTasksLocked( |
| 6842 | packageName, disabledClasses, userId); |
| 6843 | } |
| 6844 | } |
| 6845 | |
| 6846 | @Override |
| 6847 | public boolean onForceStopPackage(String packageName, boolean doit, boolean evenPersistent, |
| 6848 | int userId) { |
| 6849 | synchronized (mGlobalLock) { |
| 6850 | |
| 6851 | boolean didSomething = |
| 6852 | getActivityStartController().clearPendingActivityLaunches(packageName); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6853 | didSomething |= mRootWindowContainer.finishDisabledPackageActivities(packageName, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6854 | null, doit, evenPersistent, userId); |
| 6855 | return didSomething; |
| 6856 | } |
| 6857 | } |
| 6858 | |
| 6859 | @Override |
| 6860 | public void resumeTopActivities(boolean scheduleIdle) { |
| 6861 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6862 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6863 | if (scheduleIdle) { |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 6864 | mStackSupervisor.scheduleIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6865 | } |
| 6866 | } |
| 6867 | } |
| 6868 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6869 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6870 | @Override |
| 6871 | public void preBindApplication(WindowProcessController wpc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6872 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6873 | mStackSupervisor.getActivityMetricsLogger().notifyBindApplication(wpc.mInfo); |
| 6874 | } |
| 6875 | } |
| 6876 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6877 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6878 | @Override |
| 6879 | public boolean attachApplication(WindowProcessController wpc) throws RemoteException { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6880 | synchronized (mGlobalLockWithoutBoost) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 6881 | if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) { |
| 6882 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "attachApplication:" + wpc.mName); |
| 6883 | } |
| 6884 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6885 | return mRootWindowContainer.attachApplication(wpc); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 6886 | } finally { |
| 6887 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 6888 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6889 | } |
| 6890 | } |
| 6891 | |
| 6892 | @Override |
| 6893 | public void notifyLockedProfile(@UserIdInt int userId, int currentUserId) { |
| 6894 | try { |
| 6895 | if (!AppGlobals.getPackageManager().isUidPrivileged(Binder.getCallingUid())) { |
| 6896 | throw new SecurityException("Only privileged app can call notifyLockedProfile"); |
| 6897 | } |
| 6898 | } catch (RemoteException ex) { |
| 6899 | throw new SecurityException("Fail to check is caller a privileged app", ex); |
| 6900 | } |
| 6901 | |
| 6902 | synchronized (mGlobalLock) { |
| 6903 | final long ident = Binder.clearCallingIdentity(); |
| 6904 | try { |
| 6905 | if (mAmInternal.shouldConfirmCredentials(userId)) { |
| 6906 | if (mKeyguardController.isKeyguardLocked()) { |
| 6907 | // Showing launcher to avoid user entering credential twice. |
| 6908 | startHomeActivity(currentUserId, "notifyLockedProfile"); |
| 6909 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6910 | mRootWindowContainer.lockAllProfileTasks(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6911 | } |
| 6912 | } finally { |
| 6913 | Binder.restoreCallingIdentity(ident); |
| 6914 | } |
| 6915 | } |
| 6916 | } |
| 6917 | |
| 6918 | @Override |
| 6919 | public void startConfirmDeviceCredentialIntent(Intent intent, Bundle options) { |
| 6920 | mAmInternal.enforceCallingPermission( |
| 6921 | MANAGE_ACTIVITY_STACKS, "startConfirmDeviceCredentialIntent"); |
| 6922 | |
| 6923 | synchronized (mGlobalLock) { |
| 6924 | final long ident = Binder.clearCallingIdentity(); |
| 6925 | try { |
Pavel Grafov | c0fe0a0 | 2019-05-13 18:19:33 +0100 | [diff] [blame] | 6926 | intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 6927 | final ActivityOptions activityOptions = options != null |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6928 | ? new ActivityOptions(options) : ActivityOptions.makeBasic(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6929 | mContext.startActivityAsUser(intent, activityOptions.toBundle(), |
| 6930 | UserHandle.CURRENT); |
| 6931 | } finally { |
| 6932 | Binder.restoreCallingIdentity(ident); |
| 6933 | } |
| 6934 | } |
| 6935 | } |
| 6936 | |
| 6937 | @Override |
| 6938 | public void writeActivitiesToProto(ProtoOutputStream proto) { |
| 6939 | synchronized (mGlobalLock) { |
| 6940 | // The output proto of "activity --proto activities" |
Wale Ogunwale | f342f06 | 2020-01-27 07:34:13 -0800 | [diff] [blame] | 6941 | mRootWindowContainer.dumpDebug( |
| 6942 | proto, ROOT_WINDOW_CONTAINER, WindowTraceLogLevel.ALL); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6943 | } |
| 6944 | } |
| 6945 | |
| 6946 | @Override |
| 6947 | public void saveANRState(String reason) { |
| 6948 | synchronized (mGlobalLock) { |
| 6949 | final StringWriter sw = new StringWriter(); |
| 6950 | final PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
| 6951 | pw.println(" ANR time: " + DateFormat.getDateTimeInstance().format(new Date())); |
| 6952 | if (reason != null) { |
| 6953 | pw.println(" Reason: " + reason); |
| 6954 | } |
| 6955 | pw.println(); |
| 6956 | getActivityStartController().dump(pw, " ", null); |
| 6957 | pw.println(); |
| 6958 | pw.println("-------------------------------------------------------------------------------"); |
| 6959 | dumpActivitiesLocked(null /* fd */, pw, null /* args */, 0 /* opti */, |
| 6960 | true /* dumpAll */, false /* dumpClient */, null /* dumpPackage */, |
| 6961 | "" /* header */); |
| 6962 | pw.println(); |
| 6963 | pw.close(); |
| 6964 | |
| 6965 | mLastANRState = sw.toString(); |
| 6966 | } |
| 6967 | } |
| 6968 | |
| 6969 | @Override |
| 6970 | public void clearSavedANRState() { |
| 6971 | synchronized (mGlobalLock) { |
| 6972 | mLastANRState = null; |
| 6973 | } |
| 6974 | } |
| 6975 | |
| 6976 | @Override |
| 6977 | public void dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args, int opti, |
| 6978 | boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 6979 | synchronized (mGlobalLock) { |
| 6980 | if (DUMP_ACTIVITIES_CMD.equals(cmd) || DUMP_ACTIVITIES_SHORT_CMD.equals(cmd)) { |
| 6981 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage); |
| 6982 | } else if (DUMP_LASTANR_CMD.equals(cmd)) { |
| 6983 | dumpLastANRLocked(pw); |
| 6984 | } else if (DUMP_LASTANR_TRACES_CMD.equals(cmd)) { |
| 6985 | dumpLastANRTracesLocked(pw); |
| 6986 | } else if (DUMP_STARTER_CMD.equals(cmd)) { |
| 6987 | dumpActivityStarterLocked(pw, dumpPackage); |
| 6988 | } else if (DUMP_CONTAINERS_CMD.equals(cmd)) { |
| 6989 | dumpActivityContainersLocked(pw); |
| 6990 | } else if (DUMP_RECENTS_CMD.equals(cmd) || DUMP_RECENTS_SHORT_CMD.equals(cmd)) { |
| 6991 | if (getRecentTasks() != null) { |
| 6992 | getRecentTasks().dump(pw, dumpAll, dumpPackage); |
| 6993 | } |
| 6994 | } |
| 6995 | } |
| 6996 | } |
| 6997 | |
| 6998 | @Override |
| 6999 | public boolean dumpForProcesses(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 7000 | String dumpPackage, int dumpAppId, boolean needSep, boolean testPssMode, |
| 7001 | int wakefulness) { |
| 7002 | synchronized (mGlobalLock) { |
| 7003 | if (mHomeProcess != null && (dumpPackage == null |
| 7004 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
| 7005 | if (needSep) { |
| 7006 | pw.println(); |
| 7007 | needSep = false; |
| 7008 | } |
| 7009 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 7010 | } |
| 7011 | if (mPreviousProcess != null && (dumpPackage == null |
| 7012 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 7013 | if (needSep) { |
| 7014 | pw.println(); |
| 7015 | needSep = false; |
| 7016 | } |
| 7017 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 7018 | } |
| 7019 | if (dumpAll && (mPreviousProcess == null || dumpPackage == null |
| 7020 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 7021 | StringBuilder sb = new StringBuilder(128); |
| 7022 | sb.append(" mPreviousProcessVisibleTime: "); |
| 7023 | TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb); |
| 7024 | pw.println(sb); |
| 7025 | } |
| 7026 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 7027 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
| 7028 | if (needSep) { |
| 7029 | pw.println(); |
| 7030 | needSep = false; |
| 7031 | } |
| 7032 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 7033 | } |
| 7034 | if (dumpPackage == null) { |
| 7035 | pw.println(" mGlobalConfiguration: " + getGlobalConfiguration()); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7036 | mRootWindowContainer.dumpDisplayConfigs(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7037 | } |
| 7038 | if (dumpAll) { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 7039 | final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); |
| 7040 | if (dumpPackage == null && topFocusedStack != null) { |
| 7041 | pw.println(" mConfigWillChange: " + topFocusedStack.mConfigWillChange); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7042 | } |
| 7043 | if (mCompatModePackages.getPackages().size() > 0) { |
| 7044 | boolean printed = false; |
| 7045 | for (Map.Entry<String, Integer> entry |
| 7046 | : mCompatModePackages.getPackages().entrySet()) { |
| 7047 | String pkg = entry.getKey(); |
| 7048 | int mode = entry.getValue(); |
| 7049 | if (dumpPackage != null && !dumpPackage.equals(pkg)) { |
| 7050 | continue; |
| 7051 | } |
| 7052 | if (!printed) { |
| 7053 | pw.println(" mScreenCompatPackages:"); |
| 7054 | printed = true; |
| 7055 | } |
| 7056 | pw.println(" " + pkg + ": " + mode); |
| 7057 | } |
| 7058 | } |
| 7059 | } |
| 7060 | |
| 7061 | if (dumpPackage == null) { |
| 7062 | pw.println(" mWakefulness=" |
| 7063 | + PowerManagerInternal.wakefulnessToString(wakefulness)); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7064 | pw.println(" mSleepTokens=" + mRootWindowContainer.mSleepTokens); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7065 | if (mRunningVoice != null) { |
| 7066 | pw.println(" mRunningVoice=" + mRunningVoice); |
| 7067 | pw.println(" mVoiceWakeLock" + mVoiceWakeLock); |
| 7068 | } |
| 7069 | pw.println(" mSleeping=" + mSleeping); |
| 7070 | pw.println(" mShuttingDown=" + mShuttingDown + " mTestPssMode=" + testPssMode); |
| 7071 | pw.println(" mVrController=" + mVrController); |
| 7072 | } |
| 7073 | if (mCurAppTimeTracker != null) { |
| 7074 | mCurAppTimeTracker.dumpWithHeader(pw, " ", true); |
| 7075 | } |
| 7076 | if (mAllowAppSwitchUids.size() > 0) { |
| 7077 | boolean printed = false; |
| 7078 | for (int i = 0; i < mAllowAppSwitchUids.size(); i++) { |
| 7079 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.valueAt(i); |
| 7080 | for (int j = 0; j < types.size(); j++) { |
| 7081 | if (dumpPackage == null || |
| 7082 | UserHandle.getAppId(types.valueAt(j).intValue()) == dumpAppId) { |
| 7083 | if (needSep) { |
| 7084 | pw.println(); |
| 7085 | needSep = false; |
| 7086 | } |
| 7087 | if (!printed) { |
| 7088 | pw.println(" mAllowAppSwitchUids:"); |
| 7089 | printed = true; |
| 7090 | } |
| 7091 | pw.print(" User "); |
| 7092 | pw.print(mAllowAppSwitchUids.keyAt(i)); |
| 7093 | pw.print(": Type "); |
| 7094 | pw.print(types.keyAt(j)); |
| 7095 | pw.print(" = "); |
| 7096 | UserHandle.formatUid(pw, types.valueAt(j).intValue()); |
| 7097 | pw.println(); |
| 7098 | } |
| 7099 | } |
| 7100 | } |
| 7101 | } |
| 7102 | if (dumpPackage == null) { |
| 7103 | if (mController != null) { |
| 7104 | pw.println(" mController=" + mController |
| 7105 | + " mControllerIsAMonkey=" + mControllerIsAMonkey); |
| 7106 | } |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 7107 | pw.println(" mGoingToSleepWakeLock=" + mStackSupervisor.mGoingToSleepWakeLock); |
| 7108 | pw.println(" mLaunchingActivityWakeLock=" |
| 7109 | + mStackSupervisor.mLaunchingActivityWakeLock); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7110 | } |
| 7111 | |
| 7112 | return needSep; |
| 7113 | } |
| 7114 | } |
| 7115 | |
| 7116 | @Override |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7117 | public void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage, |
| 7118 | int wakeFullness, boolean testPssMode) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7119 | synchronized (mGlobalLock) { |
| 7120 | if (dumpPackage == null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7121 | getGlobalConfiguration().dumpDebug(proto, GLOBAL_CONFIGURATION); |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 7122 | final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); |
| 7123 | if (topFocusedStack != null) { |
| 7124 | proto.write(CONFIG_WILL_CHANGE, topFocusedStack.mConfigWillChange); |
| 7125 | } |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7126 | writeSleepStateToProto(proto, wakeFullness, testPssMode); |
| 7127 | if (mRunningVoice != null) { |
| 7128 | final long vrToken = proto.start( |
| 7129 | ActivityManagerServiceDumpProcessesProto.RUNNING_VOICE); |
| 7130 | proto.write(ActivityManagerServiceDumpProcessesProto.Voice.SESSION, |
| 7131 | mRunningVoice.toString()); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7132 | mVoiceWakeLock.dumpDebug( |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7133 | proto, ActivityManagerServiceDumpProcessesProto.Voice.WAKELOCK); |
| 7134 | proto.end(vrToken); |
| 7135 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7136 | mVrController.dumpDebug(proto, |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7137 | ActivityManagerServiceDumpProcessesProto.VR_CONTROLLER); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7138 | if (mController != null) { |
| 7139 | final long token = proto.start(CONTROLLER); |
Wally Yau | 0eb29f6 | 2020-01-08 10:16:43 -0800 | [diff] [blame] | 7140 | proto.write(ActivityManagerServiceDumpProcessesProto.Controller.CONTROLLER, |
| 7141 | mController.toString()); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7142 | proto.write(IS_A_MONKEY, mControllerIsAMonkey); |
| 7143 | proto.end(token); |
| 7144 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7145 | mStackSupervisor.mGoingToSleepWakeLock.dumpDebug(proto, GOING_TO_SLEEP); |
| 7146 | mStackSupervisor.mLaunchingActivityWakeLock.dumpDebug(proto, |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 7147 | LAUNCHING_ACTIVITY); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7148 | } |
| 7149 | |
| 7150 | if (mHomeProcess != null && (dumpPackage == null |
| 7151 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7152 | mHomeProcess.dumpDebug(proto, HOME_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7153 | } |
| 7154 | |
| 7155 | if (mPreviousProcess != null && (dumpPackage == null |
| 7156 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7157 | mPreviousProcess.dumpDebug(proto, PREVIOUS_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7158 | proto.write(PREVIOUS_PROC_VISIBLE_TIME_MS, mPreviousProcessVisibleTime); |
| 7159 | } |
| 7160 | |
| 7161 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 7162 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7163 | mHeavyWeightProcess.dumpDebug(proto, HEAVY_WEIGHT_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7164 | } |
| 7165 | |
| 7166 | for (Map.Entry<String, Integer> entry |
| 7167 | : mCompatModePackages.getPackages().entrySet()) { |
| 7168 | String pkg = entry.getKey(); |
| 7169 | int mode = entry.getValue(); |
| 7170 | if (dumpPackage == null || dumpPackage.equals(pkg)) { |
| 7171 | long compatToken = proto.start(SCREEN_COMPAT_PACKAGES); |
| 7172 | proto.write(PACKAGE, pkg); |
| 7173 | proto.write(MODE, mode); |
| 7174 | proto.end(compatToken); |
| 7175 | } |
| 7176 | } |
| 7177 | |
| 7178 | if (mCurAppTimeTracker != null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7179 | mCurAppTimeTracker.dumpDebug(proto, CURRENT_TRACKER, true); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7180 | } |
| 7181 | |
| 7182 | } |
| 7183 | } |
| 7184 | |
| 7185 | @Override |
| 7186 | public boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, |
| 7187 | String[] args, int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, |
| 7188 | boolean dumpFocusedStackOnly) { |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 7189 | return ActivityTaskManagerService.this.dumpActivity(fd, pw, name, args, opti, dumpAll, |
| 7190 | dumpVisibleStacksOnly, dumpFocusedStackOnly); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7191 | } |
| 7192 | |
| 7193 | @Override |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 7194 | public void dumpForOom(PrintWriter pw) { |
| 7195 | synchronized (mGlobalLock) { |
| 7196 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 7197 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 7198 | if (mHeavyWeightProcess != null) { |
| 7199 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 7200 | } |
| 7201 | } |
| 7202 | } |
| 7203 | |
| 7204 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7205 | public boolean canGcNow() { |
| 7206 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7207 | return isSleeping() || mRootWindowContainer.allResumedActivitiesIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7208 | } |
| 7209 | } |
| 7210 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7211 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7212 | @Override |
| 7213 | public WindowProcessController getTopApp() { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7214 | synchronized (mGlobalLockWithoutBoost) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7215 | if (mRootWindowContainer == null) { |
| 7216 | // Return null if mRootWindowContainer not yet initialize, while update |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 7217 | // oomadj after AMS created. |
| 7218 | return null; |
| 7219 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7220 | final ActivityRecord top = mRootWindowContainer.getTopResumedActivity(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7221 | return top != null ? top.app : null; |
| 7222 | } |
| 7223 | } |
| 7224 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7225 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7226 | @Override |
| 7227 | public void rankTaskLayersIfNeeded() { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7228 | synchronized (mGlobalLockWithoutBoost) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7229 | if (mRootWindowContainer != null) { |
| 7230 | mRootWindowContainer.rankTaskLayersIfNeeded(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7231 | } |
| 7232 | } |
| 7233 | } |
| 7234 | |
| 7235 | @Override |
| 7236 | public void scheduleDestroyAllActivities(String reason) { |
| 7237 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7238 | mRootWindowContainer.scheduleDestroyAllActivities(reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7239 | } |
| 7240 | } |
| 7241 | |
| 7242 | @Override |
| 7243 | public void removeUser(int userId) { |
| 7244 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7245 | mRootWindowContainer.removeUser(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7246 | } |
| 7247 | } |
| 7248 | |
| 7249 | @Override |
| 7250 | public boolean switchUser(int userId, UserState userState) { |
| 7251 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7252 | return mRootWindowContainer.switchUser(userId, userState); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7253 | } |
| 7254 | } |
| 7255 | |
| 7256 | @Override |
| 7257 | public void onHandleAppCrash(WindowProcessController wpc) { |
| 7258 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7259 | mRootWindowContainer.handleAppCrash(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7260 | } |
| 7261 | } |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 7262 | |
| 7263 | @Override |
| 7264 | public int finishTopCrashedActivities(WindowProcessController crashedApp, String reason) { |
| 7265 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7266 | return mRootWindowContainer.finishTopCrashedActivities(crashedApp, reason); |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 7267 | } |
| 7268 | } |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7269 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7270 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7271 | @Override |
| 7272 | public void onUidActive(int uid, int procState) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7273 | mActiveUids.onUidActive(uid, procState); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7274 | } |
| 7275 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7276 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7277 | @Override |
| 7278 | public void onUidInactive(int uid) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7279 | mActiveUids.onUidInactive(uid); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7280 | } |
| 7281 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7282 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7283 | @Override |
| 7284 | public void onActiveUidsCleared() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7285 | mActiveUids.onActiveUidsCleared(); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7286 | } |
| 7287 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7288 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7289 | @Override |
| 7290 | public void onUidProcStateChanged(int uid, int procState) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7291 | mActiveUids.onUidProcStateChanged(uid, procState); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7292 | } |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7293 | |
| 7294 | @Override |
| 7295 | public void onUidAddedToPendingTempWhitelist(int uid, String tag) { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7296 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7297 | mPendingTempWhitelist.put(uid, tag); |
| 7298 | } |
| 7299 | } |
| 7300 | |
| 7301 | @Override |
| 7302 | public void onUidRemovedFromPendingTempWhitelist(int uid) { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7303 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7304 | mPendingTempWhitelist.remove(uid); |
| 7305 | } |
| 7306 | } |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 7307 | |
| 7308 | @Override |
| 7309 | public boolean handleAppCrashInActivityController(String processName, int pid, |
| 7310 | String shortMsg, String longMsg, long timeMillis, String stackTrace, |
| 7311 | Runnable killCrashingAppCallback) { |
| 7312 | synchronized (mGlobalLock) { |
| 7313 | if (mController == null) { |
| 7314 | return false; |
| 7315 | } |
| 7316 | |
| 7317 | try { |
| 7318 | if (!mController.appCrashed(processName, pid, shortMsg, longMsg, timeMillis, |
| 7319 | stackTrace)) { |
| 7320 | killCrashingAppCallback.run(); |
| 7321 | return true; |
| 7322 | } |
| 7323 | } catch (RemoteException e) { |
| 7324 | mController = null; |
| 7325 | Watchdog.getInstance().setActivityController(null); |
| 7326 | } |
| 7327 | return false; |
| 7328 | } |
| 7329 | } |
Wale Ogunwale | d7889f5 | 2018-10-25 11:03:20 -0700 | [diff] [blame] | 7330 | |
| 7331 | @Override |
| 7332 | public void removeRecentTasksByPackageName(String packageName, int userId) { |
| 7333 | synchronized (mGlobalLock) { |
| 7334 | mRecentTasks.removeTasksByPackageName(packageName, userId); |
| 7335 | } |
| 7336 | } |
| 7337 | |
| 7338 | @Override |
| 7339 | public void cleanupRecentTasksForUser(int userId) { |
| 7340 | synchronized (mGlobalLock) { |
| 7341 | mRecentTasks.cleanupLocked(userId); |
| 7342 | } |
| 7343 | } |
| 7344 | |
| 7345 | @Override |
| 7346 | public void loadRecentTasksForUser(int userId) { |
| 7347 | synchronized (mGlobalLock) { |
| 7348 | mRecentTasks.loadUserRecentsLocked(userId); |
| 7349 | } |
| 7350 | } |
| 7351 | |
| 7352 | @Override |
| 7353 | public void onPackagesSuspendedChanged(String[] packages, boolean suspended, int userId) { |
| 7354 | synchronized (mGlobalLock) { |
| 7355 | mRecentTasks.onPackagesSuspendedChanged(packages, suspended, userId); |
| 7356 | } |
| 7357 | } |
| 7358 | |
| 7359 | @Override |
| 7360 | public void flushRecentTasks() { |
| 7361 | mRecentTasks.flush(); |
| 7362 | } |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 7363 | |
| 7364 | @Override |
| 7365 | public WindowProcessController getHomeProcess() { |
| 7366 | synchronized (mGlobalLock) { |
| 7367 | return mHomeProcess; |
| 7368 | } |
| 7369 | } |
| 7370 | |
| 7371 | @Override |
| 7372 | public WindowProcessController getPreviousProcess() { |
| 7373 | synchronized (mGlobalLock) { |
| 7374 | return mPreviousProcess; |
| 7375 | } |
| 7376 | } |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 7377 | |
| 7378 | @Override |
| 7379 | public void clearLockedTasks(String reason) { |
| 7380 | synchronized (mGlobalLock) { |
| 7381 | getLockTaskController().clearLockedTasks(reason); |
| 7382 | } |
| 7383 | } |
| 7384 | |
| 7385 | @Override |
| 7386 | public void updateUserConfiguration() { |
| 7387 | synchronized (mGlobalLock) { |
| 7388 | final Configuration configuration = new Configuration(getGlobalConfiguration()); |
| 7389 | final int currentUserId = mAmInternal.getCurrentUserId(); |
| 7390 | Settings.System.adjustConfigurationForUser(mContext.getContentResolver(), |
| 7391 | configuration, currentUserId, Settings.System.canWrite(mContext)); |
| 7392 | updateConfigurationLocked(configuration, null /* starting */, |
| 7393 | false /* initLocale */, false /* persistent */, currentUserId, |
| 7394 | false /* deferResume */); |
| 7395 | } |
| 7396 | } |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 7397 | |
| 7398 | @Override |
| 7399 | public boolean canShowErrorDialogs() { |
| 7400 | synchronized (mGlobalLock) { |
| 7401 | return mShowDialogs && !mSleeping && !mShuttingDown |
| 7402 | && !mKeyguardController.isKeyguardOrAodShowing(DEFAULT_DISPLAY) |
| 7403 | && !hasUserRestriction(UserManager.DISALLOW_SYSTEM_ERROR_DIALOGS, |
| 7404 | mAmInternal.getCurrentUserId()) |
| 7405 | && !(UserManager.isDeviceInDemoMode(mContext) |
| 7406 | && mAmInternal.getCurrentUser().isDemo()); |
| 7407 | } |
| 7408 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 7409 | |
| 7410 | @Override |
| 7411 | public void setProfileApp(String profileApp) { |
| 7412 | synchronized (mGlobalLock) { |
| 7413 | mProfileApp = profileApp; |
| 7414 | } |
| 7415 | } |
| 7416 | |
| 7417 | @Override |
| 7418 | public void setProfileProc(WindowProcessController wpc) { |
| 7419 | synchronized (mGlobalLock) { |
| 7420 | mProfileProc = wpc; |
| 7421 | } |
| 7422 | } |
| 7423 | |
| 7424 | @Override |
| 7425 | public void setProfilerInfo(ProfilerInfo profilerInfo) { |
| 7426 | synchronized (mGlobalLock) { |
| 7427 | mProfilerInfo = profilerInfo; |
| 7428 | } |
| 7429 | } |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 7430 | |
| 7431 | @Override |
| 7432 | public ActivityMetricsLaunchObserverRegistry getLaunchObserverRegistry() { |
| 7433 | synchronized (mGlobalLock) { |
| 7434 | return mStackSupervisor.getActivityMetricsLogger().getLaunchObserverRegistry(); |
| 7435 | } |
| 7436 | } |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 7437 | |
| 7438 | @Override |
Zak Cohen | 84b4318 | 2020-03-09 14:36:01 -0700 | [diff] [blame] | 7439 | public ActivityManager.TaskSnapshot getTaskSnapshotBlocking( |
| 7440 | int taskId, boolean isLowResolution) { |
Peter Kalauskas | 4dc0460 | 2020-02-12 18:49:03 -0800 | [diff] [blame] | 7441 | return ActivityTaskManagerService.this.getTaskSnapshot(taskId, isLowResolution, |
Zak Cohen | 84b4318 | 2020-03-09 14:36:01 -0700 | [diff] [blame] | 7442 | true /* restoreFromDisk */); |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 7443 | } |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 7444 | |
| 7445 | @Override |
| 7446 | public boolean isUidForeground(int uid) { |
| 7447 | synchronized (mGlobalLock) { |
| 7448 | return ActivityTaskManagerService.this.isUidForeground(uid); |
| 7449 | } |
| 7450 | } |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7451 | |
| 7452 | @Override |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 7453 | public void setDeviceOwnerUid(int uid) { |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7454 | synchronized (mGlobalLock) { |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 7455 | ActivityTaskManagerService.this.setDeviceOwnerUid(uid); |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7456 | } |
| 7457 | } |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7458 | |
| 7459 | @Override |
| 7460 | public void setCompanionAppPackages(int userId, Set<String> companionAppPackages) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7461 | // Translate package names into UIDs |
| 7462 | final Set<Integer> result = new HashSet<>(); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7463 | for (String pkg : companionAppPackages) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7464 | final int uid = getPackageManagerInternalLocked().getPackageUid(pkg, 0, userId); |
| 7465 | if (uid >= 0) { |
| 7466 | result.add(uid); |
| 7467 | } |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7468 | } |
| 7469 | synchronized (mGlobalLock) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7470 | mCompanionAppUidsMap.put(userId, result); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7471 | } |
| 7472 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 7473 | } |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 7474 | } |