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; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 273 | import com.android.server.uri.UriGrantsManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 274 | import com.android.server.vr.VrManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 275 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 276 | import java.io.BufferedReader; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 277 | import java.io.File; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 278 | import java.io.FileDescriptor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 279 | import java.io.FileOutputStream; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 280 | import java.io.FileReader; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 281 | import java.io.IOException; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 282 | import java.io.PrintWriter; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 283 | import java.io.StringWriter; |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 284 | import java.lang.annotation.ElementType; |
| 285 | import java.lang.annotation.Retention; |
| 286 | import java.lang.annotation.RetentionPolicy; |
| 287 | import java.lang.annotation.Target; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 288 | import java.lang.ref.WeakReference; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 289 | import java.text.DateFormat; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 290 | import java.util.ArrayList; |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 291 | import java.util.Arrays; |
Jeff Sharkey | 8b0cff7 | 2020-03-09 15:49:01 -0600 | [diff] [blame] | 292 | import java.util.Collection; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 293 | import java.util.Date; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 294 | import java.util.HashMap; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 295 | import java.util.HashSet; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 296 | import java.util.List; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 297 | import java.util.Locale; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 298 | import java.util.Map; |
Daulet Zhanguzin | c6c641f | 2020-01-02 17:18:30 +0000 | [diff] [blame] | 299 | import java.util.Objects; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 300 | import java.util.Set; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 301 | |
| 302 | /** |
| 303 | * System service for managing activities and their containers (task, stacks, displays,... ). |
| 304 | * |
| 305 | * {@hide} |
| 306 | */ |
| 307 | public class ActivityTaskManagerService extends IActivityTaskManager.Stub { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 308 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityTaskManagerService" : TAG_ATM; |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 309 | static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 310 | static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 311 | private static final String TAG_IMMERSIVE = TAG + POSTFIX_IMMERSIVE; |
| 312 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
| 313 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
| 314 | private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 315 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 316 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 317 | // How long we wait until we timeout on key dispatching. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 318 | public static final int KEY_DISPATCHING_TIMEOUT_MS = 5 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 319 | // How long we wait until we timeout on key dispatching during instrumentation. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 320 | static final int INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT_MS = 60 * 1000; |
Michal Karpinski | fc6872e | 2019-05-21 15:18:44 +0100 | [diff] [blame] | 321 | // How long we permit background activity starts after an activity in the process |
| 322 | // started or finished. |
| 323 | static final long ACTIVITY_BG_START_GRACE_PERIOD_MS = 10 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 324 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 325 | /** Used to indicate that an app transition should be animated. */ |
| 326 | static final boolean ANIMATE = true; |
| 327 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 328 | /** Hardware-reported OpenGLES version. */ |
| 329 | final int GL_ES_VERSION; |
| 330 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 331 | public static final String DUMP_ACTIVITIES_CMD = "activities" ; |
| 332 | public static final String DUMP_ACTIVITIES_SHORT_CMD = "a" ; |
| 333 | public static final String DUMP_LASTANR_CMD = "lastanr" ; |
| 334 | public static final String DUMP_LASTANR_TRACES_CMD = "lastanr-traces" ; |
| 335 | public static final String DUMP_STARTER_CMD = "starter" ; |
| 336 | public static final String DUMP_CONTAINERS_CMD = "containers" ; |
| 337 | public static final String DUMP_RECENTS_CMD = "recents" ; |
| 338 | public static final String DUMP_RECENTS_SHORT_CMD = "r" ; |
| 339 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 340 | /** This activity is not being relaunched, or being relaunched for a non-resize reason. */ |
| 341 | public static final int RELAUNCH_REASON_NONE = 0; |
| 342 | /** This activity is being relaunched due to windowing mode change. */ |
| 343 | public static final int RELAUNCH_REASON_WINDOWING_MODE_RESIZE = 1; |
| 344 | /** This activity is being relaunched due to a free-resize operation. */ |
| 345 | public static final int RELAUNCH_REASON_FREE_RESIZE = 2; |
| 346 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 347 | Context mContext; |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 348 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 349 | /** |
| 350 | * This Context is themable and meant for UI display (AlertDialogs, etc.). The theme can |
| 351 | * change at runtime. Use mContext for non-UI purposes. |
| 352 | */ |
| 353 | final Context mUiContext; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 354 | final ActivityThread mSystemThread; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 355 | H mH; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 356 | UiHandler mUiHandler; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 357 | ActivityManagerInternal mAmInternal; |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 358 | UriGrantsManagerInternal mUgmInternal; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 359 | private PackageManagerInternal mPmInternal; |
Darryl L Johnson | a098222 | 2020-02-18 18:21:51 -0800 | [diff] [blame] | 360 | /** The cached sys ui service component name from package manager. */ |
| 361 | private ComponentName mSysUiServiceComponent; |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 362 | private PermissionPolicyInternal mPermissionPolicyInternal; |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 363 | @VisibleForTesting |
| 364 | final ActivityTaskManagerInternal mInternal; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 365 | PowerManagerInternal mPowerManagerInternal; |
| 366 | private UsageStatsManagerInternal mUsageStatsInternal; |
| 367 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 368 | PendingIntentController mPendingIntentController; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 369 | IntentFirewall mIntentFirewall; |
| 370 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 371 | /* Global service lock used by the package the owns this service. */ |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 372 | final WindowManagerGlobalLock mGlobalLock = new WindowManagerGlobalLock(); |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 373 | /** |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 374 | * 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] | 375 | * locked-region-code-injection does't recognize it. It is used to skip wrapping priority |
| 376 | * booster for places that are already in the scope of another booster (e.g. computing oom-adj). |
| 377 | * |
| 378 | * @see WindowManagerThreadPriorityBooster |
| 379 | */ |
| 380 | final Object mGlobalLockWithoutBoost = mGlobalLock; |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 381 | ActivityStackSupervisor mStackSupervisor; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 382 | RootWindowContainer mRootWindowContainer; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 383 | WindowManagerService mWindowManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 384 | private UserManagerService mUserManager; |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 385 | private AppOpsManager mAppOpsManager; |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 386 | /** All active uids in the system. */ |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 387 | private final MirrorActiveUids mActiveUids = new MirrorActiveUids(); |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 388 | private final SparseArray<String> mPendingTempWhitelist = new SparseArray<>(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 389 | /** All processes currently running that might have a window organized by name. */ |
| 390 | final ProcessMap<WindowProcessController> mProcessNames = new ProcessMap<>(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 391 | /** All processes we currently have running mapped by pid and uid */ |
| 392 | final WindowProcessControllerMap mProcessMap = new WindowProcessControllerMap(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 393 | /** This is the process holding what we currently consider to be the "home" activity. */ |
| 394 | WindowProcessController mHomeProcess; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 395 | /** The currently running heavy-weight process, if any. */ |
| 396 | WindowProcessController mHeavyWeightProcess = null; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 397 | boolean mHasHeavyWeightFeature; |
Sergey Nikolaienkov | 30c947d | 2020-04-15 19:55:48 +0200 | [diff] [blame] | 398 | boolean mHasLeanbackFeature; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 399 | /** |
| 400 | * This is the process holding the activity the user last visited that is in a different process |
| 401 | * from the one they are currently in. |
| 402 | */ |
| 403 | WindowProcessController mPreviousProcess; |
| 404 | /** The time at which the previous process was last visible. */ |
| 405 | long mPreviousProcessVisibleTime; |
| 406 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 407 | /** List of intents that were used to start the most recent tasks. */ |
| 408 | private RecentTasks mRecentTasks; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 409 | /** State of external calls telling us if the device is awake or asleep. */ |
| 410 | private boolean mKeyguardShown = false; |
| 411 | |
| 412 | // Wrapper around VoiceInteractionServiceManager |
| 413 | private AssistUtils mAssistUtils; |
| 414 | |
| 415 | // VoiceInteraction session ID that changes for each new request except when |
| 416 | // being called for multi-window assist in a single session. |
| 417 | private int mViSessionId = 1000; |
| 418 | |
| 419 | // How long to wait in getAssistContextExtras for the activity and foreground services |
| 420 | // to respond with the result. |
| 421 | private static final int PENDING_ASSIST_EXTRAS_TIMEOUT = 500; |
| 422 | |
| 423 | // How long top wait when going through the modern assist (which doesn't need to block |
| 424 | // on getting this result before starting to launch its UI). |
| 425 | private static final int PENDING_ASSIST_EXTRAS_LONG_TIMEOUT = 2000; |
| 426 | |
| 427 | // How long to wait in getAutofillAssistStructure() for the activity to respond with the result. |
| 428 | private static final int PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT = 2000; |
| 429 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 430 | // Permission tokens are used to temporarily granted a trusted app the ability to call |
| 431 | // #startActivityAsCaller. A client is expected to dump its token after this time has elapsed, |
| 432 | // showing any appropriate error messages to the user. |
| 433 | private static final long START_AS_CALLER_TOKEN_TIMEOUT = |
| 434 | 10 * MINUTE_IN_MILLIS; |
| 435 | |
| 436 | // How long before the service actually expires a token. This is slightly longer than |
| 437 | // START_AS_CALLER_TOKEN_TIMEOUT, to provide a buffer so clients will rarely encounter the |
| 438 | // expiration exception. |
| 439 | private static final long START_AS_CALLER_TOKEN_TIMEOUT_IMPL = |
| 440 | START_AS_CALLER_TOKEN_TIMEOUT + 2 * 1000; |
| 441 | |
| 442 | // How long the service will remember expired tokens, for the purpose of providing error |
| 443 | // messaging when a client uses an expired token. |
| 444 | private static final long START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT = |
| 445 | START_AS_CALLER_TOKEN_TIMEOUT_IMPL + 20 * MINUTE_IN_MILLIS; |
| 446 | |
| 447 | // Activity tokens of system activities that are delegating their call to |
| 448 | // #startActivityByCaller, keyed by the permissionToken granted to the delegate. |
| 449 | final HashMap<IBinder, IBinder> mStartActivitySources = new HashMap<>(); |
| 450 | |
| 451 | // Permission tokens that have expired, but we remember for error reporting. |
| 452 | final ArrayList<IBinder> mExpiredStartAsCallerTokens = new ArrayList<>(); |
| 453 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 454 | private final ArrayList<PendingAssistExtras> mPendingAssistExtras = new ArrayList<>(); |
| 455 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 456 | // Keeps track of the active voice interaction service component, notified from |
| 457 | // VoiceInteractionManagerService |
| 458 | ComponentName mActiveVoiceInteractionServiceComponent; |
| 459 | |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 460 | // A map userId and all its companion app uids |
| 461 | private final Map<Integer, Set<Integer>> mCompanionAppUidsMap = new ArrayMap<>(); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 462 | |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 463 | VrController mVrController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 464 | KeyguardController mKeyguardController; |
| 465 | private final ClientLifecycleManager mLifecycleManager; |
| 466 | private TaskChangeNotificationController mTaskChangeNotificationController; |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 467 | /** The controller for all operations related to locktask. */ |
| 468 | private LockTaskController mLockTaskController; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 469 | private ActivityStartController mActivityStartController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 470 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 471 | boolean mSuppressResizeConfigChanges; |
| 472 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 473 | final UpdateConfigurationResult mTmpUpdateConfigurationResult = |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 474 | new UpdateConfigurationResult(); |
| 475 | |
| 476 | static final class UpdateConfigurationResult { |
| 477 | // Configuration changes that were updated. |
| 478 | int changes; |
| 479 | // If the activity was relaunched to match the new configuration. |
| 480 | boolean activityRelaunched; |
| 481 | |
| 482 | void reset() { |
| 483 | changes = 0; |
| 484 | activityRelaunched = false; |
| 485 | } |
| 486 | } |
| 487 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 488 | /** Current sequencing integer of the configuration, for skipping old configurations. */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 489 | private int mConfigurationSeq; |
| 490 | // To cache the list of supported system locales |
| 491 | private String[] mSupportedSystemLocales = null; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 492 | |
| 493 | /** |
| 494 | * Temp object used when global and/or display override configuration is updated. It is also |
| 495 | * sent to outer world instead of {@link #getGlobalConfiguration} because we don't trust |
| 496 | * anyone... |
| 497 | */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 498 | private Configuration mTempConfig = new Configuration(); |
| 499 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 500 | /** Temporary to avoid allocations. */ |
| 501 | final StringBuilder mStringBuilder = new StringBuilder(256); |
| 502 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 503 | // Amount of time after a call to stopAppSwitches() during which we will |
| 504 | // prevent further untrusted switches from happening. |
| 505 | private static final long APP_SWITCH_DELAY_TIME = 5 * 1000; |
| 506 | |
| 507 | /** |
| 508 | * The time at which we will allow normal application switches again, |
| 509 | * after a call to {@link #stopAppSwitches()}. |
| 510 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 511 | private long mAppSwitchesAllowedTime; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 512 | /** |
| 513 | * This is set to true after the first switch after mAppSwitchesAllowedTime |
| 514 | * is set; any switches after that will clear the time. |
| 515 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 516 | private boolean mDidAppSwitch; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 517 | |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 518 | /** |
| 519 | * Last stop app switches time, apps finished before this time cannot start background activity |
| 520 | * even if they are in grace period. |
| 521 | */ |
| 522 | private long mLastStopAppSwitchesTime; |
| 523 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 524 | IActivityController mController = null; |
| 525 | boolean mControllerIsAMonkey = false; |
| 526 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 527 | final int mFactoryTest; |
| 528 | |
| 529 | /** Used to control how we initialize the service. */ |
| 530 | ComponentName mTopComponent; |
| 531 | String mTopAction = Intent.ACTION_MAIN; |
| 532 | String mTopData; |
| 533 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 534 | /** Profiling app information. */ |
| 535 | String mProfileApp = null; |
| 536 | WindowProcessController mProfileProc = null; |
| 537 | ProfilerInfo mProfilerInfo = null; |
| 538 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 539 | /** |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 540 | * Dump of the activity state at the time of the last ANR. Cleared after |
| 541 | * {@link WindowManagerService#LAST_ANR_LIFETIME_DURATION_MSECS} |
| 542 | */ |
| 543 | String mLastANRState; |
| 544 | |
| 545 | /** |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 546 | * Used to retain an update lock when the foreground activity is in |
| 547 | * immersive mode. |
| 548 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 549 | private final UpdateLock mUpdateLock = new UpdateLock("immersive"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 550 | |
| 551 | /** |
| 552 | * Packages that are being allowed to perform unrestricted app switches. Mapping is |
| 553 | * User -> Type -> uid. |
| 554 | */ |
| 555 | final SparseArray<ArrayMap<String, Integer>> mAllowAppSwitchUids = new SparseArray<>(); |
| 556 | |
| 557 | /** The dimensions of the thumbnails in the Recents UI. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 558 | private int mThumbnailWidth; |
| 559 | private int mThumbnailHeight; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 560 | |
| 561 | /** |
| 562 | * Flag that indicates if multi-window is enabled. |
| 563 | * |
| 564 | * For any particular form of multi-window to be enabled, generic multi-window must be enabled |
| 565 | * in {@link com.android.internal.R.bool#config_supportsMultiWindow} config or |
| 566 | * {@link Settings.Global#DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES} development option set. |
| 567 | * At least one of the forms of multi-window must be enabled in order for this flag to be |
| 568 | * initialized to 'true'. |
| 569 | * |
| 570 | * @see #mSupportsSplitScreenMultiWindow |
| 571 | * @see #mSupportsFreeformWindowManagement |
| 572 | * @see #mSupportsPictureInPicture |
| 573 | * @see #mSupportsMultiDisplay |
| 574 | */ |
| 575 | boolean mSupportsMultiWindow; |
| 576 | boolean mSupportsSplitScreenMultiWindow; |
| 577 | boolean mSupportsFreeformWindowManagement; |
| 578 | boolean mSupportsPictureInPicture; |
| 579 | boolean mSupportsMultiDisplay; |
| 580 | boolean mForceResizableActivities; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 581 | boolean mSizeCompatFreeform; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 582 | |
| 583 | final List<ActivityTaskManagerInternal.ScreenObserver> mScreenObservers = new ArrayList<>(); |
| 584 | |
| 585 | // VR Vr2d Display Id. |
| 586 | int mVr2dDisplayId = INVALID_DISPLAY; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 587 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 588 | /** |
| 589 | * Set while we are wanting to sleep, to prevent any |
| 590 | * activities from being started/resumed. |
| 591 | * |
| 592 | * TODO(b/33594039): Clarify the actual state transitions represented by mSleeping. |
| 593 | * |
| 594 | * Currently mSleeping is set to true when transitioning into the sleep state, and remains true |
| 595 | * while in the sleep state until there is a pending transition out of sleep, in which case |
| 596 | * mSleeping is set to false, and remains false while awake. |
| 597 | * |
| 598 | * Whether mSleeping can quickly toggled between true/false without the device actually |
| 599 | * display changing states is undefined. |
| 600 | */ |
| 601 | private boolean mSleeping = false; |
| 602 | |
| 603 | /** |
Galia Peycheva | 480275a | 2020-03-18 17:33:42 +0100 | [diff] [blame] | 604 | * The mDreaming state is set by the {@link DreamManagerService} when it receives a request to |
| 605 | * start/stop the dream. It is set to true shortly before the {@link DreamService} is started. |
| 606 | * It is set to false after the {@link DreamService} is stopped. |
| 607 | */ |
| 608 | private boolean mDreaming = false; |
| 609 | |
| 610 | /** |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 611 | * The process state used for processes that are running the top activities. |
| 612 | * This changes between TOP and TOP_SLEEPING to following mSleeping. |
| 613 | */ |
| 614 | int mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
| 615 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 616 | @Retention(RetentionPolicy.SOURCE) |
| 617 | @IntDef({ |
| 618 | LAYOUT_REASON_CONFIG_CHANGED, |
| 619 | LAYOUT_REASON_VISIBILITY_CHANGED, |
| 620 | }) |
| 621 | @interface LayoutReason {} |
| 622 | static final int LAYOUT_REASON_CONFIG_CHANGED = 0x1; |
| 623 | static final int LAYOUT_REASON_VISIBILITY_CHANGED = 0x2; |
| 624 | |
| 625 | /** The reasons to perform surface placement. */ |
| 626 | @LayoutReason |
| 627 | private int mLayoutReasons; |
| 628 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 629 | // Whether we should show our dialogs (ANR, crash, etc) or just perform their default action |
| 630 | // automatically. Important for devices without direct input devices. |
| 631 | private boolean mShowDialogs = true; |
| 632 | |
| 633 | /** Set if we are shutting down the system, similar to sleeping. */ |
| 634 | boolean mShuttingDown = false; |
| 635 | |
| 636 | /** |
| 637 | * We want to hold a wake lock while running a voice interaction session, since |
| 638 | * this may happen with the screen off and we need to keep the CPU running to |
| 639 | * be able to continue to interact with the user. |
| 640 | */ |
| 641 | PowerManager.WakeLock mVoiceWakeLock; |
| 642 | |
| 643 | /** |
| 644 | * Set while we are running a voice interaction. This overrides sleeping while it is active. |
| 645 | */ |
| 646 | IVoiceInteractionSession mRunningVoice; |
| 647 | |
| 648 | /** |
| 649 | * The last resumed activity. This is identical to the current resumed activity most |
| 650 | * of the time but could be different when we're pausing one activity before we resume |
| 651 | * another activity. |
| 652 | */ |
| 653 | ActivityRecord mLastResumedActivity; |
| 654 | |
| 655 | /** |
| 656 | * The activity that is currently being traced as the active resumed activity. |
| 657 | * |
| 658 | * @see #updateResumedAppTrace |
| 659 | */ |
| 660 | private @Nullable ActivityRecord mTracedResumedActivity; |
| 661 | |
| 662 | /** If non-null, we are tracking the time the user spends in the currently focused app. */ |
| 663 | AppTimeTracker mCurAppTimeTracker; |
| 664 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 665 | AppWarnings mAppWarnings; |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 666 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 667 | /** |
| 668 | * Packages that the user has asked to have run in screen size |
| 669 | * compatibility mode instead of filling the screen. |
| 670 | */ |
| 671 | CompatModePackages mCompatModePackages; |
| 672 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 673 | private FontScaleSettingObserver mFontScaleSettingObserver; |
| 674 | |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 675 | WindowOrganizerController mWindowOrganizerController; |
| 676 | TaskOrganizerController mTaskOrganizerController; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 677 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 678 | private int mDeviceOwnerUid = Process.INVALID_UID; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 679 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 680 | private final class FontScaleSettingObserver extends ContentObserver { |
| 681 | private final Uri mFontScaleUri = Settings.System.getUriFor(FONT_SCALE); |
| 682 | private final Uri mHideErrorDialogsUri = Settings.Global.getUriFor(HIDE_ERROR_DIALOGS); |
| 683 | |
| 684 | public FontScaleSettingObserver() { |
| 685 | super(mH); |
| 686 | final ContentResolver resolver = mContext.getContentResolver(); |
| 687 | resolver.registerContentObserver(mFontScaleUri, false, this, UserHandle.USER_ALL); |
| 688 | resolver.registerContentObserver(mHideErrorDialogsUri, false, this, |
| 689 | UserHandle.USER_ALL); |
| 690 | } |
| 691 | |
| 692 | @Override |
Jeff Sharkey | 8b0cff7 | 2020-03-09 15:49:01 -0600 | [diff] [blame] | 693 | public void onChange(boolean selfChange, Collection<Uri> uris, int flags, |
Riddle Hsu | 9c024d1 | 2020-03-09 16:10:07 +0800 | [diff] [blame] | 694 | @UserIdInt int userId) { |
| 695 | for (Uri uri : uris) { |
| 696 | if (mFontScaleUri.equals(uri)) { |
| 697 | updateFontScaleIfNeeded(userId); |
| 698 | } else if (mHideErrorDialogsUri.equals(uri)) { |
| 699 | synchronized (mGlobalLock) { |
| 700 | updateShouldShowDialogsLocked(getGlobalConfiguration()); |
| 701 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 707 | /** Indicates that the method may be invoked frequently or is sensitive to performance. */ |
| 708 | @Target(ElementType.METHOD) |
| 709 | @Retention(RetentionPolicy.SOURCE) |
| 710 | @interface HotPath { |
| 711 | int NONE = 0; |
| 712 | int OOM_ADJUSTMENT = 1; |
| 713 | int LRU_UPDATE = 2; |
| 714 | int PROCESS_CHANGE = 3; |
| 715 | int caller() default NONE; |
| 716 | } |
| 717 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 718 | private final Runnable mUpdateOomAdjRunnable = new Runnable() { |
| 719 | @Override |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 720 | public void run() { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 721 | mAmInternal.updateOomAdj(); |
| 722 | } |
| 723 | }; |
| 724 | |
Charles Chen | 8d98dd2 | 2018-12-26 17:36:54 +0800 | [diff] [blame] | 725 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 726 | public ActivityTaskManagerService(Context context) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 727 | mContext = context; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 728 | mFactoryTest = FactoryTest.getMode(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 729 | mSystemThread = ActivityThread.currentActivityThread(); |
| 730 | mUiContext = mSystemThread.getSystemUiContext(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 731 | mLifecycleManager = new ClientLifecycleManager(); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 732 | mInternal = new LocalService(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 733 | GL_ES_VERSION = SystemProperties.getInt("ro.opengles.version", GL_ES_VERSION_UNDEFINED); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 734 | mWindowOrganizerController = new WindowOrganizerController(this); |
| 735 | mTaskOrganizerController = mWindowOrganizerController.mTaskOrganizerController; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 738 | public void onSystemReady() { |
| 739 | synchronized (mGlobalLock) { |
Sergey Nikolaienkov | 30c947d | 2020-04-15 19:55:48 +0200 | [diff] [blame] | 740 | final PackageManager pm = mContext.getPackageManager(); |
| 741 | mHasHeavyWeightFeature = pm.hasSystemFeature(FEATURE_CANT_SAVE_STATE); |
| 742 | mHasLeanbackFeature = pm.hasSystemFeature(FEATURE_LEANBACK); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 743 | mAssistUtils = new AssistUtils(mContext); |
| 744 | mVrController.onSystemReady(); |
| 745 | mRecentTasks.onSystemReadyLocked(); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 746 | mStackSupervisor.onSystemReady(); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 747 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 750 | public void onInitPowerManagement() { |
| 751 | synchronized (mGlobalLock) { |
| 752 | mStackSupervisor.initPowerManagement(); |
| 753 | final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 754 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
| 755 | mVoiceWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*voice*"); |
| 756 | mVoiceWakeLock.setReferenceCounted(false); |
| 757 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 760 | public void installSystemProviders() { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 761 | mFontScaleSettingObserver = new FontScaleSettingObserver(); |
| 762 | } |
| 763 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 764 | public void retrieveSettings(ContentResolver resolver) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 765 | final boolean freeformWindowManagement = |
| 766 | mContext.getPackageManager().hasSystemFeature(FEATURE_FREEFORM_WINDOW_MANAGEMENT) |
| 767 | || Settings.Global.getInt( |
| 768 | resolver, DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0; |
| 769 | |
| 770 | final boolean supportsMultiWindow = ActivityTaskManager.supportsMultiWindow(mContext); |
| 771 | final boolean supportsPictureInPicture = supportsMultiWindow && |
| 772 | mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE); |
| 773 | final boolean supportsSplitScreenMultiWindow = |
| 774 | ActivityTaskManager.supportsSplitScreenMultiWindow(mContext); |
| 775 | final boolean supportsMultiDisplay = mContext.getPackageManager() |
| 776 | .hasSystemFeature(FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 777 | final boolean forceRtl = Settings.Global.getInt(resolver, DEVELOPMENT_FORCE_RTL, 0) != 0; |
| 778 | final boolean forceResizable = Settings.Global.getInt( |
| 779 | resolver, DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 780 | final boolean sizeCompatFreeform = Settings.Global.getInt( |
| 781 | resolver, DEVELOPMENT_ENABLE_SIZECOMPAT_FREEFORM, 0) != 0; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 782 | |
| 783 | // Transfer any global setting for forcing RTL layout, into a System Property |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 784 | DisplayProperties.debug_force_rtl(forceRtl); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 785 | |
| 786 | final Configuration configuration = new Configuration(); |
| 787 | Settings.System.getConfiguration(resolver, configuration); |
| 788 | if (forceRtl) { |
| 789 | // This will take care of setting the correct layout direction flags |
| 790 | configuration.setLayoutDirection(configuration.locale); |
| 791 | } |
| 792 | |
| 793 | synchronized (mGlobalLock) { |
| 794 | mForceResizableActivities = forceResizable; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 795 | mSizeCompatFreeform = sizeCompatFreeform; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 796 | final boolean multiWindowFormEnabled = freeformWindowManagement |
| 797 | || supportsSplitScreenMultiWindow |
| 798 | || supportsPictureInPicture |
| 799 | || supportsMultiDisplay; |
| 800 | if ((supportsMultiWindow || forceResizable) && multiWindowFormEnabled) { |
| 801 | mSupportsMultiWindow = true; |
| 802 | mSupportsFreeformWindowManagement = freeformWindowManagement; |
| 803 | mSupportsSplitScreenMultiWindow = supportsSplitScreenMultiWindow; |
| 804 | mSupportsPictureInPicture = supportsPictureInPicture; |
| 805 | mSupportsMultiDisplay = supportsMultiDisplay; |
| 806 | } else { |
| 807 | mSupportsMultiWindow = false; |
| 808 | mSupportsFreeformWindowManagement = false; |
| 809 | mSupportsSplitScreenMultiWindow = false; |
| 810 | mSupportsPictureInPicture = false; |
| 811 | mSupportsMultiDisplay = false; |
| 812 | } |
Garfield Tan | b5910b4 | 2019-03-14 14:50:59 -0700 | [diff] [blame] | 813 | mWindowManager.mRoot.onSettingsRetrieved(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 814 | // This happens before any activities are started, so we can change global configuration |
| 815 | // in-place. |
| 816 | updateConfigurationLocked(configuration, null, true); |
| 817 | final Configuration globalConfig = getGlobalConfiguration(); |
| 818 | if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Initial config: " + globalConfig); |
| 819 | |
| 820 | // Load resources only after the current configuration has been set. |
| 821 | final Resources res = mContext.getResources(); |
| 822 | mThumbnailWidth = res.getDimensionPixelSize( |
| 823 | com.android.internal.R.dimen.thumbnail_width); |
| 824 | mThumbnailHeight = res.getDimensionPixelSize( |
| 825 | com.android.internal.R.dimen.thumbnail_height); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 829 | public WindowManagerGlobalLock getGlobalLock() { |
| 830 | return mGlobalLock; |
| 831 | } |
| 832 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 833 | /** For test purpose only. */ |
| 834 | @VisibleForTesting |
| 835 | public ActivityTaskManagerInternal getAtmInternal() { |
| 836 | return mInternal; |
| 837 | } |
| 838 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 839 | public void initialize(IntentFirewall intentFirewall, PendingIntentController intentController, |
| 840 | Looper looper) { |
| 841 | mH = new H(looper); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 842 | mUiHandler = new UiHandler(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 843 | mIntentFirewall = intentFirewall; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 844 | final File systemDir = SystemServiceManager.ensureSystemDir(); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 845 | mAppWarnings = createAppWarnings(mUiContext, mH, mUiHandler, systemDir); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 846 | mCompatModePackages = new CompatModePackages(this, systemDir, mH); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 847 | mPendingIntentController = intentController; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 848 | mStackSupervisor = createStackSupervisor(); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 849 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 850 | mTaskChangeNotificationController = |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 851 | new TaskChangeNotificationController(mGlobalLock, mStackSupervisor, mH); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 852 | mLockTaskController = new LockTaskController(mContext, mStackSupervisor, mH); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 853 | mActivityStartController = new ActivityStartController(this); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 854 | setRecentTasks(new RecentTasks(this, mStackSupervisor)); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 855 | mVrController = new VrController(mGlobalLock); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 856 | mKeyguardController = mStackSupervisor.getKeyguardController(); |
| 857 | } |
| 858 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 859 | public void onActivityManagerInternalAdded() { |
| 860 | synchronized (mGlobalLock) { |
| 861 | mAmInternal = LocalServices.getService(ActivityManagerInternal.class); |
| 862 | mUgmInternal = LocalServices.getService(UriGrantsManagerInternal.class); |
| 863 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 866 | int increaseConfigurationSeqLocked() { |
| 867 | mConfigurationSeq = Math.max(++mConfigurationSeq, 1); |
| 868 | return mConfigurationSeq; |
| 869 | } |
| 870 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 871 | protected ActivityStackSupervisor createStackSupervisor() { |
| 872 | final ActivityStackSupervisor supervisor = new ActivityStackSupervisor(this, mH.getLooper()); |
| 873 | supervisor.initialize(); |
| 874 | return supervisor; |
| 875 | } |
| 876 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 877 | protected AppWarnings createAppWarnings( |
| 878 | Context uiContext, Handler handler, Handler uiHandler, File systemDir) { |
| 879 | return new AppWarnings(this, uiContext, handler, uiHandler, systemDir); |
| 880 | } |
| 881 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 882 | public void setWindowManager(WindowManagerService wm) { |
| 883 | synchronized (mGlobalLock) { |
| 884 | mWindowManager = wm; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 885 | mRootWindowContainer = wm.mRoot; |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 886 | mTempConfig.setToDefaults(); |
| 887 | mTempConfig.setLocales(LocaleList.getDefault()); |
| 888 | mConfigurationSeq = mTempConfig.seq = 1; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 889 | mRootWindowContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 890 | mLockTaskController.setWindowManager(wm); |
| 891 | mStackSupervisor.setWindowManager(wm); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 892 | mRootWindowContainer.setWindowManager(wm); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 893 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 894 | } |
| 895 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 896 | public void setUsageStatsManager(UsageStatsManagerInternal usageStatsManager) { |
| 897 | synchronized (mGlobalLock) { |
| 898 | mUsageStatsInternal = usageStatsManager; |
| 899 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 902 | UserManagerService getUserManager() { |
| 903 | if (mUserManager == null) { |
| 904 | IBinder b = ServiceManager.getService(Context.USER_SERVICE); |
| 905 | mUserManager = (UserManagerService) IUserManager.Stub.asInterface(b); |
| 906 | } |
| 907 | return mUserManager; |
| 908 | } |
| 909 | |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 910 | AppOpsManager getAppOpsManager() { |
| 911 | if (mAppOpsManager == null) { |
| 912 | mAppOpsManager = mContext.getSystemService(AppOpsManager.class); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 913 | } |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 914 | return mAppOpsManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | boolean hasUserRestriction(String restriction, int userId) { |
| 918 | return getUserManager().hasUserRestriction(restriction, userId); |
| 919 | } |
| 920 | |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 921 | boolean hasSystemAlertWindowPermission(int callingUid, int callingPid, String callingPackage) { |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 922 | final int mode = getAppOpsManager().noteOpNoThrow(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, |
| 923 | callingUid, callingPackage, /* featureId */ null, ""); |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 924 | if (mode == AppOpsManager.MODE_DEFAULT) { |
| 925 | return checkPermission(Manifest.permission.SYSTEM_ALERT_WINDOW, callingPid, callingUid) |
| 926 | == PERMISSION_GRANTED; |
| 927 | } |
| 928 | return mode == AppOpsManager.MODE_ALLOWED; |
| 929 | } |
| 930 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 931 | @VisibleForTesting |
| 932 | protected void setRecentTasks(RecentTasks recentTasks) { |
| 933 | mRecentTasks = recentTasks; |
| 934 | mStackSupervisor.setRecentTasks(recentTasks); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | RecentTasks getRecentTasks() { |
| 938 | return mRecentTasks; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 939 | } |
| 940 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 941 | ClientLifecycleManager getLifecycleManager() { |
| 942 | return mLifecycleManager; |
| 943 | } |
| 944 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 945 | ActivityStartController getActivityStartController() { |
| 946 | return mActivityStartController; |
| 947 | } |
| 948 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 949 | TaskChangeNotificationController getTaskChangeNotificationController() { |
| 950 | return mTaskChangeNotificationController; |
| 951 | } |
| 952 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 953 | LockTaskController getLockTaskController() { |
| 954 | return mLockTaskController; |
| 955 | } |
| 956 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 957 | /** |
| 958 | * Return the global configuration used by the process corresponding to the input pid. This is |
| 959 | * usually the global configuration with some overrides specific to that process. |
| 960 | */ |
| 961 | Configuration getGlobalConfigurationForCallingPid() { |
| 962 | final int pid = Binder.getCallingPid(); |
Yunfan Chen | c2ff6cf | 2018-12-04 16:56:21 -0800 | [diff] [blame] | 963 | return getGlobalConfigurationForPid(pid); |
| 964 | } |
| 965 | |
| 966 | /** |
| 967 | * Return the global configuration used by the process corresponding to the given pid. |
| 968 | */ |
| 969 | Configuration getGlobalConfigurationForPid(int pid) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 970 | if (pid == MY_PID || pid < 0) { |
| 971 | return getGlobalConfiguration(); |
| 972 | } |
| 973 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 974 | final WindowProcessController app = mProcessMap.getProcess(pid); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 975 | return app != null ? app.getConfiguration() : getGlobalConfiguration(); |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | /** |
| 980 | * Return the device configuration info used by the process corresponding to the input pid. |
| 981 | * The value is consistent with the global configuration for the process. |
| 982 | */ |
| 983 | @Override |
| 984 | public ConfigurationInfo getDeviceConfigurationInfo() { |
| 985 | ConfigurationInfo config = new ConfigurationInfo(); |
| 986 | synchronized (mGlobalLock) { |
| 987 | final Configuration globalConfig = getGlobalConfigurationForCallingPid(); |
| 988 | config.reqTouchScreen = globalConfig.touchscreen; |
| 989 | config.reqKeyboardType = globalConfig.keyboard; |
| 990 | config.reqNavigation = globalConfig.navigation; |
| 991 | if (globalConfig.navigation == Configuration.NAVIGATION_DPAD |
| 992 | || globalConfig.navigation == Configuration.NAVIGATION_TRACKBALL) { |
| 993 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 994 | } |
| 995 | if (globalConfig.keyboard != Configuration.KEYBOARD_UNDEFINED |
| 996 | && globalConfig.keyboard != Configuration.KEYBOARD_NOKEYS) { |
| 997 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 998 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 999 | config.reqGlEsVersion = GL_ES_VERSION; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 1000 | } |
| 1001 | return config; |
| 1002 | } |
| 1003 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 1004 | private void start() { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1005 | LocalServices.addService(ActivityTaskManagerInternal.class, mInternal); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1008 | public static final class Lifecycle extends SystemService { |
| 1009 | private final ActivityTaskManagerService mService; |
| 1010 | |
| 1011 | public Lifecycle(Context context) { |
| 1012 | super(context); |
| 1013 | mService = new ActivityTaskManagerService(context); |
| 1014 | } |
| 1015 | |
| 1016 | @Override |
| 1017 | public void onStart() { |
| 1018 | publishBinderService(Context.ACTIVITY_TASK_SERVICE, mService); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 1019 | mService.start(); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 1022 | @Override |
| 1023 | public void onUnlockUser(int userId) { |
| 1024 | synchronized (mService.getGlobalLock()) { |
Garfield Tan | 0d407f4 | 2019-03-07 11:47:01 -0800 | [diff] [blame] | 1025 | mService.mStackSupervisor.onUserUnlocked(userId); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | @Override |
| 1030 | public void onCleanupUser(int userId) { |
| 1031 | synchronized (mService.getGlobalLock()) { |
| 1032 | mService.mStackSupervisor.mLaunchParamsPersister.onCleanupUser(userId); |
| 1033 | } |
| 1034 | } |
| 1035 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1036 | public ActivityTaskManagerService getService() { |
| 1037 | return mService; |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1042 | public final int startActivity(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1043 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1044 | String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, |
| 1045 | Bundle bOptions) { |
| 1046 | return startActivityAsUser(caller, callingPackage, callingFeatureId, intent, resolvedType, |
| 1047 | resultTo, resultWho, requestCode, startFlags, profilerInfo, bOptions, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1048 | UserHandle.getCallingUserId()); |
| 1049 | } |
| 1050 | |
| 1051 | @Override |
| 1052 | public final int startActivities(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1053 | String callingFeatureId, Intent[] intents, String[] resolvedTypes, IBinder resultTo, |
| 1054 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1055 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1056 | final String reason = "startActivities"; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1057 | enforceNotIsolatedCaller(reason); |
| 1058 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, reason); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1059 | // TODO: Switch to user app stacks here. |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 1060 | return getActivityStartController().startActivities(caller, -1, 0, -1, callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1061 | callingFeatureId, intents, resolvedTypes, resultTo, |
| 1062 | SafeActivityOptions.fromBundle(bOptions), userId, reason, |
| 1063 | null /* originatingPendingIntent */, false /* allowBackgroundActivityStart */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | @Override |
| 1067 | public int startActivityAsUser(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1068 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1069 | String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, |
| 1070 | Bundle bOptions, int userId) { |
| 1071 | return startActivityAsUser(caller, callingPackage, callingFeatureId, intent, resolvedType, |
| 1072 | resultTo, resultWho, requestCode, startFlags, profilerInfo, bOptions, userId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1073 | true /*validateIncomingUser*/); |
| 1074 | } |
| 1075 | |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1076 | private int startActivityAsUser(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1077 | @Nullable String callingFeatureId, Intent intent, String resolvedType, |
| 1078 | IBinder resultTo, String resultWho, int requestCode, int startFlags, |
| 1079 | ProfilerInfo profilerInfo, Bundle bOptions, int userId, boolean validateIncomingUser) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1080 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1081 | enforceNotIsolatedCaller("startActivityAsUser"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1082 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1083 | userId = getActivityStartController().checkTargetUser(userId, validateIncomingUser, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1084 | Binder.getCallingPid(), Binder.getCallingUid(), "startActivityAsUser"); |
| 1085 | |
| 1086 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1087 | return getActivityStartController().obtainStarter(intent, "startActivityAsUser") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1088 | .setCaller(caller) |
| 1089 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1090 | .setCallingFeatureId(callingFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1091 | .setResolvedType(resolvedType) |
| 1092 | .setResultTo(resultTo) |
| 1093 | .setResultWho(resultWho) |
| 1094 | .setRequestCode(requestCode) |
| 1095 | .setStartFlags(startFlags) |
| 1096 | .setProfilerInfo(profilerInfo) |
| 1097 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1098 | .setUserId(userId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1099 | .execute(); |
| 1100 | |
| 1101 | } |
| 1102 | |
| 1103 | @Override |
| 1104 | public int startActivityIntentSender(IApplicationThread caller, IIntentSender target, |
| 1105 | IBinder whitelistToken, Intent fillInIntent, String resolvedType, IBinder resultTo, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1106 | String resultWho, int requestCode, int flagsMask, int flagsValues, Bundle bOptions) { |
| 1107 | enforceNotIsolatedCaller("startActivityIntentSender"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1108 | // Refuse possible leaked file descriptors |
| 1109 | if (fillInIntent != null && fillInIntent.hasFileDescriptors()) { |
| 1110 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1111 | } |
| 1112 | |
| 1113 | if (!(target instanceof PendingIntentRecord)) { |
| 1114 | throw new IllegalArgumentException("Bad PendingIntent object"); |
| 1115 | } |
| 1116 | |
| 1117 | PendingIntentRecord pir = (PendingIntentRecord)target; |
| 1118 | |
| 1119 | synchronized (mGlobalLock) { |
| 1120 | // If this is coming from the currently resumed activity, it is |
| 1121 | // effectively saying that app switches are allowed at this point. |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1122 | final ActivityStack stack = getTopDisplayFocusedStack(); |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 1123 | if (stack != null && stack.mResumedActivity != null |
| 1124 | && stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1125 | mAppSwitchesAllowedTime = 0; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1126 | } |
| 1127 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1128 | return pir.sendInner(0, fillInIntent, resolvedType, whitelistToken, null, null, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1129 | resultTo, resultWho, requestCode, flagsMask, flagsValues, bOptions); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | @Override |
| 1133 | public boolean startNextMatchingActivity(IBinder callingActivity, Intent intent, |
| 1134 | Bundle bOptions) { |
| 1135 | // Refuse possible leaked file descriptors |
| 1136 | if (intent != null && intent.hasFileDescriptors()) { |
| 1137 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1138 | } |
| 1139 | SafeActivityOptions options = SafeActivityOptions.fromBundle(bOptions); |
| 1140 | |
| 1141 | synchronized (mGlobalLock) { |
| 1142 | final ActivityRecord r = ActivityRecord.isInStackLocked(callingActivity); |
| 1143 | if (r == null) { |
| 1144 | SafeActivityOptions.abort(options); |
| 1145 | return false; |
| 1146 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1147 | if (!r.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1148 | // The caller is not running... d'oh! |
| 1149 | SafeActivityOptions.abort(options); |
| 1150 | return false; |
| 1151 | } |
| 1152 | intent = new Intent(intent); |
| 1153 | // The caller is not allowed to change the data. |
| 1154 | intent.setDataAndType(r.intent.getData(), r.intent.getType()); |
| 1155 | // And we are resetting to find the next component... |
| 1156 | intent.setComponent(null); |
| 1157 | |
| 1158 | final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0); |
| 1159 | |
| 1160 | ActivityInfo aInfo = null; |
| 1161 | try { |
| 1162 | List<ResolveInfo> resolves = |
| 1163 | AppGlobals.getPackageManager().queryIntentActivities( |
| 1164 | intent, r.resolvedType, |
| 1165 | PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS, |
| 1166 | UserHandle.getCallingUserId()).getList(); |
| 1167 | |
| 1168 | // Look for the original activity in the list... |
| 1169 | final int N = resolves != null ? resolves.size() : 0; |
| 1170 | for (int i=0; i<N; i++) { |
| 1171 | ResolveInfo rInfo = resolves.get(i); |
| 1172 | if (rInfo.activityInfo.packageName.equals(r.packageName) |
| 1173 | && rInfo.activityInfo.name.equals(r.info.name)) { |
| 1174 | // We found the current one... the next matching is |
| 1175 | // after it. |
| 1176 | i++; |
| 1177 | if (i<N) { |
| 1178 | aInfo = resolves.get(i).activityInfo; |
| 1179 | } |
| 1180 | if (debug) { |
| 1181 | Slog.v(TAG, "Next matching activity: found current " + r.packageName |
| 1182 | + "/" + r.info.name); |
| 1183 | Slog.v(TAG, "Next matching activity: next is " + ((aInfo == null) |
| 1184 | ? "null" : aInfo.packageName + "/" + aInfo.name)); |
| 1185 | } |
| 1186 | break; |
| 1187 | } |
| 1188 | } |
| 1189 | } catch (RemoteException e) { |
| 1190 | } |
| 1191 | |
| 1192 | if (aInfo == null) { |
| 1193 | // Nobody who is next! |
| 1194 | SafeActivityOptions.abort(options); |
| 1195 | if (debug) Slog.d(TAG, "Next matching activity: nothing found"); |
| 1196 | return false; |
| 1197 | } |
| 1198 | |
| 1199 | intent.setComponent(new ComponentName( |
| 1200 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1201 | intent.setFlags(intent.getFlags()&~( |
| 1202 | Intent.FLAG_ACTIVITY_FORWARD_RESULT| |
| 1203 | Intent.FLAG_ACTIVITY_CLEAR_TOP| |
| 1204 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK| |
| 1205 | FLAG_ACTIVITY_NEW_TASK)); |
| 1206 | |
| 1207 | // Okay now we need to start the new activity, replacing the currently running activity. |
| 1208 | // This is a little tricky because we want to start the new one as if the current one is |
| 1209 | // finished, but not finish the current one first so that there is no flicker. |
| 1210 | // And thus... |
| 1211 | final boolean wasFinishing = r.finishing; |
| 1212 | r.finishing = true; |
| 1213 | |
| 1214 | // Propagate reply information over to the new activity. |
| 1215 | final ActivityRecord resultTo = r.resultTo; |
| 1216 | final String resultWho = r.resultWho; |
| 1217 | final int requestCode = r.requestCode; |
| 1218 | r.resultTo = null; |
| 1219 | if (resultTo != null) { |
| 1220 | resultTo.removeResultsLocked(r, resultWho, requestCode); |
| 1221 | } |
| 1222 | |
| 1223 | final long origId = Binder.clearCallingIdentity(); |
| 1224 | // TODO(b/64750076): Check if calling pid should really be -1. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1225 | final int res = getActivityStartController() |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1226 | .obtainStarter(intent, "startNextMatchingActivity") |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1227 | .setCaller(r.app.getThread()) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1228 | .setResolvedType(r.resolvedType) |
| 1229 | .setActivityInfo(aInfo) |
| 1230 | .setResultTo(resultTo != null ? resultTo.appToken : null) |
| 1231 | .setResultWho(resultWho) |
| 1232 | .setRequestCode(requestCode) |
| 1233 | .setCallingPid(-1) |
| 1234 | .setCallingUid(r.launchedFromUid) |
| 1235 | .setCallingPackage(r.launchedFromPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1236 | .setCallingFeatureId(r.launchedFromFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1237 | .setRealCallingPid(-1) |
| 1238 | .setRealCallingUid(r.launchedFromUid) |
| 1239 | .setActivityOptions(options) |
| 1240 | .execute(); |
| 1241 | Binder.restoreCallingIdentity(origId); |
| 1242 | |
| 1243 | r.finishing = wasFinishing; |
| 1244 | if (res != ActivityManager.START_SUCCESS) { |
| 1245 | return false; |
| 1246 | } |
| 1247 | return true; |
| 1248 | } |
| 1249 | } |
| 1250 | |
Galia Peycheva | ed401cc | 2020-03-19 20:28:09 +0100 | [diff] [blame] | 1251 | private void enforceCallerIsDream(String callerPackageName) { |
Galia Peycheva | 52e8922 | 2020-02-18 23:41:43 +0100 | [diff] [blame] | 1252 | final long origId = Binder.clearCallingIdentity(); |
Galia Peycheva | ed401cc | 2020-03-19 20:28:09 +0100 | [diff] [blame] | 1253 | try { |
| 1254 | if (!ActivityRecord.canLaunchDreamActivity(callerPackageName)) { |
| 1255 | throw new SecurityException("The dream activity can be started only when the device" |
| 1256 | + " is dreaming and only by the active dream package."); |
| 1257 | } |
| 1258 | } finally { |
| 1259 | Binder.restoreCallingIdentity(origId); |
Galia Peycheva | 52e8922 | 2020-02-18 23:41:43 +0100 | [diff] [blame] | 1260 | } |
Galia Peycheva | ed401cc | 2020-03-19 20:28:09 +0100 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | @Override |
| 1264 | public boolean startDreamActivity(@NonNull Intent intent) { |
| 1265 | assertPackageMatchesCallingUid(intent.getPackage()); |
| 1266 | enforceCallerIsDream(intent.getPackage()); |
Galia Peycheva | 52e8922 | 2020-02-18 23:41:43 +0100 | [diff] [blame] | 1267 | |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 1268 | final ActivityInfo a = new ActivityInfo(); |
| 1269 | a.theme = com.android.internal.R.style.Theme_Dream; |
| 1270 | a.exported = true; |
| 1271 | a.name = DreamActivity.class.getName(); |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 1272 | a.enabled = true; |
| 1273 | a.launchMode = ActivityInfo.LAUNCH_SINGLE_INSTANCE; |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 1274 | a.persistableMode = ActivityInfo.PERSIST_NEVER; |
| 1275 | a.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 1276 | a.colorMode = ActivityInfo.COLOR_MODE_DEFAULT; |
| 1277 | a.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 1278 | |
Galia Peycheva | 45f48d3 | 2020-02-20 15:39:10 +0100 | [diff] [blame] | 1279 | final ActivityOptions options = ActivityOptions.makeBasic(); |
| 1280 | options.setLaunchActivityType(ACTIVITY_TYPE_DREAM); |
| 1281 | |
Galia Peycheva | ed401cc | 2020-03-19 20:28:09 +0100 | [diff] [blame] | 1282 | synchronized (mGlobalLock) { |
| 1283 | final WindowProcessController process = mProcessMap.getProcess(Binder.getCallingPid()); |
| 1284 | |
| 1285 | a.packageName = process.mInfo.packageName; |
| 1286 | a.applicationInfo = process.mInfo; |
| 1287 | a.processName = process.mInfo.processName; |
| 1288 | a.uiOptions = process.mInfo.uiOptions; |
| 1289 | a.taskAffinity = "android:" + a.packageName + "/dream"; |
| 1290 | |
| 1291 | final int callingUid = Binder.getCallingUid(); |
| 1292 | final int callingPid = Binder.getCallingPid(); |
| 1293 | |
| 1294 | final long origId = Binder.clearCallingIdentity(); |
| 1295 | try { |
| 1296 | getActivityStartController().obtainStarter(intent, "dream") |
| 1297 | .setCallingUid(callingUid) |
| 1298 | .setCallingPid(callingPid) |
| 1299 | .setActivityInfo(a) |
| 1300 | .setActivityOptions(options.toBundle()) |
| 1301 | // To start the dream from background, we need to start it from a persistent |
| 1302 | // system process. Here we set the real calling uid to the system server uid |
| 1303 | .setRealCallingUid(Binder.getCallingUid()) |
| 1304 | .setAllowBackgroundActivityStart(true) |
| 1305 | .execute(); |
| 1306 | return true; |
| 1307 | } finally { |
| 1308 | Binder.restoreCallingIdentity(origId); |
| 1309 | } |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1314 | public final WaitResult startActivityAndWait(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1315 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1316 | String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, |
| 1317 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1318 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1319 | final WaitResult res = new WaitResult(); |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1320 | enforceNotIsolatedCaller("startActivityAndWait"); |
| 1321 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 1322 | userId, "startActivityAndWait"); |
| 1323 | // TODO: Switch to user app stacks here. |
| 1324 | getActivityStartController().obtainStarter(intent, "startActivityAndWait") |
| 1325 | .setCaller(caller) |
| 1326 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1327 | .setCallingFeatureId(callingFeatureId) |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1328 | .setResolvedType(resolvedType) |
| 1329 | .setResultTo(resultTo) |
| 1330 | .setResultWho(resultWho) |
| 1331 | .setRequestCode(requestCode) |
| 1332 | .setStartFlags(startFlags) |
| 1333 | .setActivityOptions(bOptions) |
| 1334 | .setUserId(userId) |
| 1335 | .setProfilerInfo(profilerInfo) |
| 1336 | .setWaitResult(res) |
| 1337 | .execute(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1338 | return res; |
| 1339 | } |
| 1340 | |
| 1341 | @Override |
| 1342 | public final int startActivityWithConfig(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1343 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1344 | String resultWho, int requestCode, int startFlags, Configuration config, |
| 1345 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1346 | assertPackageMatchesCallingUid(callingPackage); |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1347 | enforceNotIsolatedCaller("startActivityWithConfig"); |
| 1348 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, |
| 1349 | "startActivityWithConfig"); |
| 1350 | // TODO: Switch to user app stacks here. |
| 1351 | return getActivityStartController().obtainStarter(intent, "startActivityWithConfig") |
| 1352 | .setCaller(caller) |
| 1353 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1354 | .setCallingFeatureId(callingFeatureId) |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1355 | .setResolvedType(resolvedType) |
| 1356 | .setResultTo(resultTo) |
| 1357 | .setResultWho(resultWho) |
| 1358 | .setRequestCode(requestCode) |
| 1359 | .setStartFlags(startFlags) |
| 1360 | .setGlobalConfiguration(config) |
| 1361 | .setActivityOptions(bOptions) |
| 1362 | .setUserId(userId) |
| 1363 | .execute(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1364 | } |
| 1365 | |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 1366 | @Override |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1367 | public IBinder requestStartActivityPermissionToken(IBinder delegatorToken) { |
| 1368 | int callingUid = Binder.getCallingUid(); |
| 1369 | if (UserHandle.getAppId(callingUid) != SYSTEM_UID) { |
| 1370 | throw new SecurityException("Only the system process can request a permission token, " |
| 1371 | + "received request from uid: " + callingUid); |
| 1372 | } |
| 1373 | IBinder permissionToken = new Binder(); |
| 1374 | synchronized (mGlobalLock) { |
| 1375 | mStartActivitySources.put(permissionToken, delegatorToken); |
| 1376 | } |
| 1377 | |
| 1378 | Message expireMsg = PooledLambda.obtainMessage( |
| 1379 | ActivityTaskManagerService::expireStartAsCallerTokenMsg, this, permissionToken); |
| 1380 | mUiHandler.sendMessageDelayed(expireMsg, START_AS_CALLER_TOKEN_TIMEOUT_IMPL); |
| 1381 | |
| 1382 | Message forgetMsg = PooledLambda.obtainMessage( |
| 1383 | ActivityTaskManagerService::forgetStartAsCallerTokenMsg, this, permissionToken); |
| 1384 | mUiHandler.sendMessageDelayed(forgetMsg, START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT); |
| 1385 | |
| 1386 | return permissionToken; |
| 1387 | } |
| 1388 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1389 | @Override |
| 1390 | public final int startActivityAsCaller(IApplicationThread caller, String callingPackage, |
| 1391 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1392 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, IBinder permissionToken, |
| 1393 | boolean ignoreTargetSecurity, int userId) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1394 | // 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] | 1395 | // permission grants) as any app that may launch one of your own activities. So we only |
| 1396 | // allow this in two cases: |
| 1397 | // 1) The caller is an activity that is part of the core framework, and then only when it |
| 1398 | // is running as the system. |
| 1399 | // 2) The caller provides a valid permissionToken. Permission tokens are one-time use and |
| 1400 | // can only be requested by a system activity, which may then delegate this call to |
| 1401 | // another app. |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1402 | final ActivityRecord sourceRecord; |
| 1403 | final int targetUid; |
| 1404 | final String targetPackage; |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1405 | final String targetFeatureId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1406 | final boolean isResolver; |
| 1407 | synchronized (mGlobalLock) { |
| 1408 | if (resultTo == null) { |
| 1409 | throw new SecurityException("Must be called from an activity"); |
| 1410 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1411 | final IBinder sourceToken; |
| 1412 | if (permissionToken != null) { |
| 1413 | // To even attempt to use a permissionToken, an app must also have this signature |
| 1414 | // permission. |
| 1415 | mAmInternal.enforceCallingPermission( |
| 1416 | android.Manifest.permission.START_ACTIVITY_AS_CALLER, |
| 1417 | "startActivityAsCaller"); |
| 1418 | // If called with a permissionToken, we want the sourceRecord from the delegator |
| 1419 | // activity that requested this token. |
| 1420 | sourceToken = mStartActivitySources.remove(permissionToken); |
| 1421 | if (sourceToken == null) { |
| 1422 | // Invalid permissionToken, check if it recently expired. |
| 1423 | if (mExpiredStartAsCallerTokens.contains(permissionToken)) { |
| 1424 | throw new SecurityException("Called with expired permission token: " |
| 1425 | + permissionToken); |
| 1426 | } else { |
| 1427 | throw new SecurityException("Called with invalid permission token: " |
| 1428 | + permissionToken); |
| 1429 | } |
| 1430 | } |
| 1431 | } else { |
| 1432 | // This method was called directly by the source. |
| 1433 | sourceToken = resultTo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1434 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1435 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1436 | sourceRecord = mRootWindowContainer.isInAnyStack(sourceToken); |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1437 | if (sourceRecord == null) { |
| 1438 | throw new SecurityException("Called with bad activity token: " + sourceToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1439 | } |
| 1440 | if (sourceRecord.app == null) { |
| 1441 | throw new SecurityException("Called without a process attached to activity"); |
| 1442 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1443 | |
| 1444 | // Whether called directly or from a delegate, the source activity must be from the |
| 1445 | // android package. |
| 1446 | if (!sourceRecord.info.packageName.equals("android")) { |
| 1447 | throw new SecurityException("Must be called from an activity that is " |
| 1448 | + "declared in the android package"); |
| 1449 | } |
| 1450 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1451 | if (UserHandle.getAppId(sourceRecord.app.mUid) != SYSTEM_UID) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1452 | // This is still okay, as long as this activity is running under the |
| 1453 | // uid of the original calling activity. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1454 | if (sourceRecord.app.mUid != sourceRecord.launchedFromUid) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1455 | throw new SecurityException( |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1456 | "Calling activity in uid " + sourceRecord.app.mUid |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1457 | + " must be system uid or original calling uid " |
| 1458 | + sourceRecord.launchedFromUid); |
| 1459 | } |
| 1460 | } |
| 1461 | if (ignoreTargetSecurity) { |
| 1462 | if (intent.getComponent() == null) { |
| 1463 | throw new SecurityException( |
| 1464 | "Component must be specified with ignoreTargetSecurity"); |
| 1465 | } |
| 1466 | if (intent.getSelector() != null) { |
| 1467 | throw new SecurityException( |
| 1468 | "Selector not allowed with ignoreTargetSecurity"); |
| 1469 | } |
| 1470 | } |
| 1471 | targetUid = sourceRecord.launchedFromUid; |
| 1472 | targetPackage = sourceRecord.launchedFromPackage; |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1473 | targetFeatureId = sourceRecord.launchedFromFeatureId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1474 | isResolver = sourceRecord.isResolverOrChildActivity(); |
| 1475 | } |
| 1476 | |
| 1477 | if (userId == UserHandle.USER_NULL) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1478 | userId = UserHandle.getUserId(sourceRecord.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | // TODO: Switch to user app stacks here. |
| 1482 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1483 | return getActivityStartController().obtainStarter(intent, "startActivityAsCaller") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1484 | .setCallingUid(targetUid) |
| 1485 | .setCallingPackage(targetPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1486 | .setCallingFeatureId(targetFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1487 | .setResolvedType(resolvedType) |
| 1488 | .setResultTo(resultTo) |
| 1489 | .setResultWho(resultWho) |
| 1490 | .setRequestCode(requestCode) |
| 1491 | .setStartFlags(startFlags) |
| 1492 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1493 | .setUserId(userId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1494 | .setIgnoreTargetSecurity(ignoreTargetSecurity) |
| 1495 | .setFilterCallingUid(isResolver ? 0 /* system */ : targetUid) |
Alan Stokes | 2f4a4ed | 2019-05-08 16:56:45 +0100 | [diff] [blame] | 1496 | // The target may well be in the background, which would normally prevent it |
| 1497 | // from starting an activity. Here we definitely want the start to succeed. |
| 1498 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1499 | .execute(); |
| 1500 | } catch (SecurityException e) { |
| 1501 | // XXX need to figure out how to propagate to original app. |
| 1502 | // A SecurityException here is generally actually a fault of the original |
| 1503 | // calling activity (such as a fairly granting permissions), so propagate it |
| 1504 | // back to them. |
| 1505 | /* |
| 1506 | StringBuilder msg = new StringBuilder(); |
| 1507 | msg.append("While launching"); |
| 1508 | msg.append(intent.toString()); |
| 1509 | msg.append(": "); |
| 1510 | msg.append(e.getMessage()); |
| 1511 | */ |
| 1512 | throw e; |
| 1513 | } |
| 1514 | } |
| 1515 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1516 | int handleIncomingUser(int callingPid, int callingUid, int userId, String name) { |
| 1517 | return mAmInternal.handleIncomingUser(callingPid, callingUid, userId, false /* allowAll */, |
Jonathan Scott | 9233534 | 2019-12-17 14:46:26 +0000 | [diff] [blame] | 1518 | ALLOW_NON_FULL, name, null /* callerPackage */); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1521 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1522 | public int startVoiceActivity(String callingPackage, String callingFeatureId, int callingPid, |
| 1523 | int callingUid, Intent intent, String resolvedType, IVoiceInteractionSession session, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1524 | IVoiceInteractor interactor, int startFlags, ProfilerInfo profilerInfo, |
| 1525 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1526 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1527 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startVoiceActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1528 | if (session == null || interactor == null) { |
| 1529 | throw new NullPointerException("null session or interactor"); |
| 1530 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1531 | userId = handleIncomingUser(callingPid, callingUid, userId, "startVoiceActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1532 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1533 | return getActivityStartController().obtainStarter(intent, "startVoiceActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1534 | .setCallingUid(callingUid) |
| 1535 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1536 | .setCallingFeatureId(callingFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1537 | .setResolvedType(resolvedType) |
| 1538 | .setVoiceSession(session) |
| 1539 | .setVoiceInteractor(interactor) |
| 1540 | .setStartFlags(startFlags) |
| 1541 | .setProfilerInfo(profilerInfo) |
| 1542 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1543 | .setUserId(userId) |
Michal Karpinski | 85fa202 | 2019-02-08 12:05:09 +0000 | [diff] [blame] | 1544 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1545 | .execute(); |
| 1546 | } |
| 1547 | |
| 1548 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1549 | public int startAssistantActivity(String callingPackage, @NonNull String callingFeatureId, |
| 1550 | int callingPid, int callingUid, Intent intent, String resolvedType, Bundle bOptions, |
| 1551 | int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1552 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1553 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startAssistantActivity()"); |
| 1554 | userId = handleIncomingUser(callingPid, callingUid, userId, "startAssistantActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1555 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1556 | return getActivityStartController().obtainStarter(intent, "startAssistantActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1557 | .setCallingUid(callingUid) |
| 1558 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1559 | .setCallingFeatureId(callingFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1560 | .setResolvedType(resolvedType) |
| 1561 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1562 | .setUserId(userId) |
Michal Karpinski | 85fa202 | 2019-02-08 12:05:09 +0000 | [diff] [blame] | 1563 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1564 | .execute(); |
| 1565 | } |
| 1566 | |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1567 | /** |
| 1568 | * Start the recents activity to perform the recents animation. |
| 1569 | * |
| 1570 | * @param intent The intent to start the recents activity. |
| 1571 | * @param recentsAnimationRunner Pass {@code null} to only preload the activity. |
| 1572 | */ |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1573 | @Override |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1574 | public void startRecentsActivity(Intent intent, @Deprecated IAssistDataReceiver unused, |
| 1575 | @Nullable IRecentsAnimationRunner recentsAnimationRunner) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1576 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "startRecentsActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1577 | final int callingPid = Binder.getCallingPid(); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1578 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1579 | final long origId = Binder.clearCallingIdentity(); |
| 1580 | try { |
| 1581 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 1582 | final ComponentName recentsComponent = mRecentTasks.getRecentsComponent(); |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1583 | final String recentsFeatureId = mRecentTasks.getRecentsComponentFeatureId(); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 1584 | final int recentsUid = mRecentTasks.getRecentsComponentUid(); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1585 | final WindowProcessController caller = getProcessController(callingPid, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1586 | |
| 1587 | // Start a new recents animation |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1588 | final RecentsAnimation anim = new RecentsAnimation(this, mStackSupervisor, |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1589 | getActivityStartController(), mWindowManager, intent, recentsComponent, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1590 | recentsFeatureId, recentsUid, caller); |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1591 | if (recentsAnimationRunner == null) { |
| 1592 | anim.preloadRecentsActivity(); |
| 1593 | } else { |
| 1594 | anim.startRecentsActivity(recentsAnimationRunner); |
| 1595 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1596 | } |
| 1597 | } finally { |
| 1598 | Binder.restoreCallingIdentity(origId); |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | @Override |
| 1603 | public final int startActivityFromRecents(int taskId, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1604 | enforceCallerIsRecentsOrHasPermission(START_TASKS_FROM_RECENTS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1605 | "startActivityFromRecents()"); |
| 1606 | |
| 1607 | final int callingPid = Binder.getCallingPid(); |
| 1608 | final int callingUid = Binder.getCallingUid(); |
| 1609 | final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(bOptions); |
| 1610 | final long origId = Binder.clearCallingIdentity(); |
| 1611 | try { |
| 1612 | synchronized (mGlobalLock) { |
| 1613 | return mStackSupervisor.startActivityFromRecents(callingPid, callingUid, taskId, |
| 1614 | safeOptions); |
| 1615 | } |
| 1616 | } finally { |
| 1617 | Binder.restoreCallingIdentity(origId); |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | /** |
Andrii Kulian | 2eb84b2 | 2018-12-13 18:18:54 -0800 | [diff] [blame] | 1622 | * Public API to check if the client is allowed to start an activity on specified display. |
| 1623 | * |
| 1624 | * If the target display is private or virtual, some restrictions will apply. |
| 1625 | * |
| 1626 | * @param displayId Target display id. |
| 1627 | * @param intent Intent used to launch the activity. |
| 1628 | * @param resolvedType The MIME type of the intent. |
| 1629 | * @param userId The id of the user for whom the call is made. |
| 1630 | * @return {@code true} if a call to start an activity on the target display should succeed and |
| 1631 | * no {@link SecurityException} will be thrown, {@code false} otherwise. |
| 1632 | */ |
| 1633 | @Override |
| 1634 | public final boolean isActivityStartAllowedOnDisplay(int displayId, Intent intent, |
| 1635 | String resolvedType, int userId) { |
| 1636 | final int callingUid = Binder.getCallingUid(); |
| 1637 | final int callingPid = Binder.getCallingPid(); |
| 1638 | final long origId = Binder.clearCallingIdentity(); |
| 1639 | |
| 1640 | try { |
| 1641 | // Collect information about the target of the Intent. |
| 1642 | ActivityInfo aInfo = mStackSupervisor.resolveActivity(intent, resolvedType, |
| 1643 | 0 /* startFlags */, null /* profilerInfo */, userId, |
| 1644 | ActivityStarter.computeResolveFilterUid(callingUid, callingUid, |
| 1645 | UserHandle.USER_NULL)); |
| 1646 | aInfo = mAmInternal.getActivityInfoForUser(aInfo, userId); |
| 1647 | |
| 1648 | synchronized (mGlobalLock) { |
| 1649 | return mStackSupervisor.canPlaceEntityOnDisplay(displayId, callingPid, callingUid, |
| 1650 | aInfo); |
| 1651 | } |
| 1652 | } finally { |
| 1653 | Binder.restoreCallingIdentity(origId); |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | /** |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1658 | * This is the internal entry point for handling Activity.finish(). |
| 1659 | * |
| 1660 | * @param token The Binder token referencing the Activity we want to finish. |
| 1661 | * @param resultCode Result code, if any, from this Activity. |
| 1662 | * @param resultData Result data (Intent), if any, from this Activity. |
| 1663 | * @param finishTask Whether to finish the task associated with this Activity. |
| 1664 | * |
| 1665 | * @return Returns true if the activity successfully finished, or false if it is still running. |
| 1666 | */ |
| 1667 | @Override |
| 1668 | public final boolean finishActivity(IBinder token, int resultCode, Intent resultData, |
| 1669 | int finishTask) { |
| 1670 | // Refuse possible leaked file descriptors |
| 1671 | if (resultData != null && resultData.hasFileDescriptors()) { |
| 1672 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1673 | } |
| 1674 | |
| 1675 | synchronized (mGlobalLock) { |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 1676 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1677 | if (r == null) { |
| 1678 | return true; |
| 1679 | } |
| 1680 | // 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] | 1681 | final Task tr = r.getTask(); |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 1682 | final ActivityRecord rootR = tr.getRootActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1683 | if (rootR == null) { |
| 1684 | Slog.w(TAG, "Finishing task with all activities already finished"); |
| 1685 | } |
| 1686 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps can |
| 1687 | // finish. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1688 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1689 | return false; |
| 1690 | } |
| 1691 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1692 | // TODO: There is a dup. of this block of code in ActivityStack.navigateUpToLocked |
| 1693 | // We should consolidate. |
| 1694 | if (mController != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1695 | // Find the first activity that is not finishing. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1696 | final ActivityRecord next = |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 1697 | r.getRootTask().topRunningActivity(token, INVALID_TASK_ID); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1698 | if (next != null) { |
| 1699 | // ask watcher if this is allowed |
| 1700 | boolean resumeOK = true; |
| 1701 | try { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1702 | resumeOK = mController.activityResuming(next.packageName); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1703 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1704 | mController = null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1705 | Watchdog.getInstance().setActivityController(null); |
| 1706 | } |
| 1707 | |
| 1708 | if (!resumeOK) { |
| 1709 | Slog.i(TAG, "Not finishing activity because controller resumed"); |
| 1710 | return false; |
| 1711 | } |
| 1712 | } |
| 1713 | } |
Michal Karpinski | fc6872e | 2019-05-21 15:18:44 +0100 | [diff] [blame] | 1714 | |
| 1715 | // note down that the process has finished an activity and is in background activity |
| 1716 | // starts grace period |
| 1717 | if (r.app != null) { |
| 1718 | r.app.setLastActivityFinishTimeIfNeeded(SystemClock.uptimeMillis()); |
| 1719 | } |
| 1720 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1721 | final long origId = Binder.clearCallingIdentity(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1722 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "finishActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1723 | try { |
| 1724 | boolean res; |
| 1725 | final boolean finishWithRootActivity = |
| 1726 | finishTask == Activity.FINISH_TASK_WITH_ROOT_ACTIVITY; |
| 1727 | if (finishTask == Activity.FINISH_TASK_WITH_ACTIVITY |
| 1728 | || (finishWithRootActivity && r == rootR)) { |
| 1729 | // If requested, remove the task that is associated to this activity only if it |
| 1730 | // was the root activity in the task. The result code and data is ignored |
| 1731 | // because we don't support returning them across task boundaries. Also, to |
| 1732 | // keep backwards compatibility we remove the task from recents when finishing |
| 1733 | // task with root activity. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1734 | mStackSupervisor.removeTask(tr, false /*killProcess*/, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1735 | finishWithRootActivity, "finish-activity"); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1736 | res = true; |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 1737 | // Explicitly dismissing the activity so reset its relaunch flag. |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 1738 | r.mRelaunchReason = RELAUNCH_REASON_NONE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1739 | } else { |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 1740 | r.finishIfPossible(resultCode, resultData, "app-request", true /* oomAdj */); |
Andrii Kulian | 40eda67 | 2019-07-30 15:05:57 -0700 | [diff] [blame] | 1741 | res = r.finishing; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1742 | if (!res) { |
| 1743 | Slog.i(TAG, "Failed to finish by app-request"); |
| 1744 | } |
| 1745 | } |
| 1746 | return res; |
| 1747 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1748 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1749 | Binder.restoreCallingIdentity(origId); |
| 1750 | } |
| 1751 | } |
| 1752 | } |
| 1753 | |
| 1754 | @Override |
| 1755 | public boolean finishActivityAffinity(IBinder token) { |
| 1756 | synchronized (mGlobalLock) { |
| 1757 | final long origId = Binder.clearCallingIdentity(); |
| 1758 | try { |
| 1759 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1760 | if (r == null) { |
| 1761 | return false; |
| 1762 | } |
| 1763 | |
| 1764 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps |
| 1765 | // can finish. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1766 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1767 | return false; |
| 1768 | } |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1769 | |
| 1770 | final PooledFunction p = PooledLambda.obtainFunction( |
| 1771 | ActivityRecord::finishIfSameAffinity, r, |
| 1772 | PooledLambda.__(ActivityRecord.class)); |
| 1773 | r.getTask().forAllActivities( |
| 1774 | p, r, true /*includeBoundary*/, true /*traverseTopToBottom*/); |
| 1775 | p.recycle(); |
| 1776 | |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 1777 | return true; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1778 | } finally { |
| 1779 | Binder.restoreCallingIdentity(origId); |
| 1780 | } |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | @Override |
| 1785 | public final void activityIdle(IBinder token, Configuration config, boolean stopProfiling) { |
| 1786 | final long origId = Binder.clearCallingIdentity(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1787 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1788 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1789 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityIdle"); |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 1790 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 1791 | if (r == null) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1792 | return; |
| 1793 | } |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 1794 | mStackSupervisor.activityIdleInternal(r, false /* fromTimeout */, |
| 1795 | false /* processPausingActivities */, config); |
| 1796 | if (stopProfiling && r.hasProcess()) { |
| 1797 | r.app.clearProfilerIfNeeded(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1798 | } |
| 1799 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1800 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1801 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1802 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1803 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | @Override |
| 1807 | public final void activityResumed(IBinder token) { |
| 1808 | final long origId = Binder.clearCallingIdentity(); |
| 1809 | synchronized (mGlobalLock) { |
| 1810 | ActivityRecord.activityResumedLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1811 | } |
| 1812 | Binder.restoreCallingIdentity(origId); |
| 1813 | } |
| 1814 | |
| 1815 | @Override |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 1816 | public final void activityTopResumedStateLost() { |
| 1817 | final long origId = Binder.clearCallingIdentity(); |
| 1818 | synchronized (mGlobalLock) { |
| 1819 | mStackSupervisor.handleTopResumedStateReleased(false /* timeout */); |
| 1820 | } |
| 1821 | Binder.restoreCallingIdentity(origId); |
| 1822 | } |
| 1823 | |
| 1824 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1825 | public final void activityPaused(IBinder token) { |
| 1826 | final long origId = Binder.clearCallingIdentity(); |
| 1827 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1828 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityPaused"); |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 1829 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 1830 | if (r != null) { |
| 1831 | r.activityPaused(false); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1832 | } |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1833 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1834 | } |
| 1835 | Binder.restoreCallingIdentity(origId); |
| 1836 | } |
| 1837 | |
| 1838 | @Override |
| 1839 | public final void activityStopped(IBinder token, Bundle icicle, |
| 1840 | PersistableBundle persistentState, CharSequence description) { |
| 1841 | if (DEBUG_ALL) Slog.v(TAG, "Activity stopped: token=" + token); |
| 1842 | |
| 1843 | // Refuse possible leaked file descriptors |
| 1844 | if (icicle != null && icicle.hasFileDescriptors()) { |
| 1845 | throw new IllegalArgumentException("File descriptors passed in Bundle"); |
| 1846 | } |
| 1847 | |
| 1848 | final long origId = Binder.clearCallingIdentity(); |
| 1849 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1850 | String restartingName = null; |
| 1851 | int restartingUid = 0; |
| 1852 | final ActivityRecord r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1853 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1854 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityStopped"); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1855 | r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1856 | if (r != null) { |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1857 | if (r.attachedToProcess() |
| 1858 | && r.isState(ActivityStack.ActivityState.RESTARTING_PROCESS)) { |
| 1859 | // The activity was requested to restart from |
| 1860 | // {@link #restartActivityProcessIfVisible}. |
| 1861 | restartingName = r.app.mName; |
| 1862 | restartingUid = r.app.mUid; |
| 1863 | } |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 1864 | r.activityStopped(icicle, persistentState, description); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1865 | } |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1866 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1869 | if (restartingName != null) { |
| 1870 | // In order to let the foreground activity can be restarted with its saved state from |
| 1871 | // {@link android.app.Activity#onSaveInstanceState}, the kill operation is postponed |
| 1872 | // until the activity reports stopped with the state. And the activity record will be |
| 1873 | // kept because the record state is restarting, then the activity will be restarted |
| 1874 | // immediately if it is still the top one. |
| 1875 | mStackSupervisor.removeRestartTimeouts(r); |
| 1876 | mAmInternal.killProcess(restartingName, restartingUid, "restartActivityProcess"); |
| 1877 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1878 | mAmInternal.trimApplications(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1879 | |
| 1880 | Binder.restoreCallingIdentity(origId); |
| 1881 | } |
| 1882 | |
| 1883 | @Override |
| 1884 | public final void activityDestroyed(IBinder token) { |
| 1885 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "ACTIVITY DESTROYED: " + token); |
| 1886 | synchronized (mGlobalLock) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1887 | final long origId = Binder.clearCallingIdentity(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1888 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityDestroyed"); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1889 | try { |
| 1890 | final ActivityRecord activity = ActivityRecord.forTokenLocked(token); |
| 1891 | if (activity != null) { |
| 1892 | activity.destroyed("activityDestroyed"); |
| 1893 | } |
| 1894 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1895 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1896 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1897 | } |
| 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | @Override |
| 1902 | public final void activityRelaunched(IBinder token) { |
| 1903 | final long origId = Binder.clearCallingIdentity(); |
| 1904 | synchronized (mGlobalLock) { |
| 1905 | mStackSupervisor.activityRelaunchedLocked(token); |
| 1906 | } |
| 1907 | Binder.restoreCallingIdentity(origId); |
| 1908 | } |
| 1909 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1910 | @Override |
| 1911 | public void setRequestedOrientation(IBinder token, int requestedOrientation) { |
| 1912 | synchronized (mGlobalLock) { |
| 1913 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1914 | if (r == null) { |
| 1915 | return; |
| 1916 | } |
| 1917 | final long origId = Binder.clearCallingIdentity(); |
| 1918 | try { |
| 1919 | r.setRequestedOrientation(requestedOrientation); |
| 1920 | } finally { |
| 1921 | Binder.restoreCallingIdentity(origId); |
| 1922 | } |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | @Override |
| 1927 | public int getRequestedOrientation(IBinder token) { |
| 1928 | synchronized (mGlobalLock) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1929 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1930 | return (r != null) |
| 1931 | ? r.getRequestedOrientation() : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | @Override |
| 1936 | public void setImmersive(IBinder token, boolean immersive) { |
| 1937 | synchronized (mGlobalLock) { |
| 1938 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1939 | if (r == null) { |
| 1940 | throw new IllegalArgumentException(); |
| 1941 | } |
| 1942 | r.immersive = immersive; |
| 1943 | |
| 1944 | // update associated state if we're frontmost |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1945 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1946 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, "Frontmost changed immersion: "+ r); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1947 | applyUpdateLockStateLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1948 | } |
| 1949 | } |
| 1950 | } |
| 1951 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1952 | void applyUpdateLockStateLocked(ActivityRecord r) { |
| 1953 | // Modifications to the UpdateLock state are done on our handler, outside |
| 1954 | // the activity manager's locks. The new state is determined based on the |
| 1955 | // state *now* of the relevant activity record. The object is passed to |
| 1956 | // the handler solely for logging detail, not to be consulted/modified. |
| 1957 | final boolean nextState = r != null && r.immersive; |
| 1958 | mH.post(() -> { |
| 1959 | if (mUpdateLock.isHeld() != nextState) { |
| 1960 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, |
| 1961 | "Applying new update lock state '" + nextState + "' for " + r); |
| 1962 | if (nextState) { |
| 1963 | mUpdateLock.acquire(); |
| 1964 | } else { |
| 1965 | mUpdateLock.release(); |
| 1966 | } |
| 1967 | } |
| 1968 | }); |
| 1969 | } |
| 1970 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1971 | @Override |
| 1972 | public boolean isImmersive(IBinder token) { |
| 1973 | synchronized (mGlobalLock) { |
| 1974 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1975 | if (r == null) { |
| 1976 | throw new IllegalArgumentException(); |
| 1977 | } |
| 1978 | return r.immersive; |
| 1979 | } |
| 1980 | } |
| 1981 | |
| 1982 | @Override |
| 1983 | public boolean isTopActivityImmersive() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1984 | enforceNotIsolatedCaller("isTopActivityImmersive"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1985 | synchronized (mGlobalLock) { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 1986 | final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); |
| 1987 | if (topFocusedStack == null) { |
| 1988 | return false; |
| 1989 | } |
| 1990 | |
| 1991 | final ActivityRecord r = topFocusedStack.topRunningActivity(); |
| 1992 | return r != null && r.immersive; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1993 | } |
| 1994 | } |
| 1995 | |
| 1996 | @Override |
| 1997 | public void overridePendingTransition(IBinder token, String packageName, |
| 1998 | int enterAnim, int exitAnim) { |
| 1999 | synchronized (mGlobalLock) { |
| 2000 | ActivityRecord self = ActivityRecord.isInStackLocked(token); |
| 2001 | if (self == null) { |
| 2002 | return; |
| 2003 | } |
| 2004 | |
| 2005 | final long origId = Binder.clearCallingIdentity(); |
| 2006 | |
| 2007 | if (self.isState( |
| 2008 | ActivityStack.ActivityState.RESUMED, ActivityStack.ActivityState.PAUSING)) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2009 | self.getDisplay().mDisplayContent.mAppTransition.overridePendingAppTransition( |
Ming-Shin Lu | b6d7002 | 2020-03-27 23:51:56 +0800 | [diff] [blame] | 2010 | packageName, enterAnim, exitAnim, null, null); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | Binder.restoreCallingIdentity(origId); |
| 2014 | } |
| 2015 | } |
| 2016 | |
| 2017 | @Override |
| 2018 | public int getFrontActivityScreenCompatMode() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2019 | enforceNotIsolatedCaller("getFrontActivityScreenCompatMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2020 | synchronized (mGlobalLock) { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 2021 | final ActivityStack stack = getTopDisplayFocusedStack(); |
| 2022 | final ActivityRecord r = stack != null ? stack.topRunningActivity() : null; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2023 | if (r == null) { |
| 2024 | return ActivityManager.COMPAT_MODE_UNKNOWN; |
| 2025 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 2026 | return mCompatModePackages.computeCompatModeLocked(r.info.applicationInfo); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | @Override |
| 2031 | public void setFrontActivityScreenCompatMode(int mode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2032 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2033 | "setFrontActivityScreenCompatMode"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2034 | ApplicationInfo ai; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2035 | synchronized (mGlobalLock) { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 2036 | final ActivityStack stack = getTopDisplayFocusedStack(); |
| 2037 | final ActivityRecord r = stack != null ? stack.topRunningActivity() : null; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2038 | if (r == null) { |
| 2039 | Slog.w(TAG, "setFrontActivityScreenCompatMode failed: no top activity"); |
| 2040 | return; |
| 2041 | } |
| 2042 | ai = r.info.applicationInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 2043 | mCompatModePackages.setPackageScreenCompatModeLocked(ai, mode); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | @Override |
| 2048 | public int getLaunchedFromUid(IBinder activityToken) { |
| 2049 | ActivityRecord srec; |
| 2050 | synchronized (mGlobalLock) { |
| 2051 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 2052 | } |
| 2053 | if (srec == null) { |
| 2054 | return -1; |
| 2055 | } |
| 2056 | return srec.launchedFromUid; |
| 2057 | } |
| 2058 | |
| 2059 | @Override |
| 2060 | public String getLaunchedFromPackage(IBinder activityToken) { |
| 2061 | ActivityRecord srec; |
| 2062 | synchronized (mGlobalLock) { |
| 2063 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 2064 | } |
| 2065 | if (srec == null) { |
| 2066 | return null; |
| 2067 | } |
| 2068 | return srec.launchedFromPackage; |
| 2069 | } |
| 2070 | |
| 2071 | @Override |
| 2072 | public boolean convertFromTranslucent(IBinder token) { |
| 2073 | final long origId = Binder.clearCallingIdentity(); |
| 2074 | try { |
| 2075 | synchronized (mGlobalLock) { |
| 2076 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2077 | if (r == null) { |
| 2078 | return false; |
| 2079 | } |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 2080 | return r.setOccludesParent(true); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2081 | } |
| 2082 | } finally { |
| 2083 | Binder.restoreCallingIdentity(origId); |
| 2084 | } |
| 2085 | } |
| 2086 | |
| 2087 | @Override |
| 2088 | public boolean convertToTranslucent(IBinder token, Bundle options) { |
| 2089 | SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(options); |
| 2090 | final long origId = Binder.clearCallingIdentity(); |
| 2091 | try { |
| 2092 | synchronized (mGlobalLock) { |
| 2093 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2094 | if (r == null) { |
| 2095 | return false; |
| 2096 | } |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2097 | final ActivityRecord under = r.getTask().getActivityBelow(r); |
| 2098 | if (under != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2099 | under.returningOptions = safeOptions != null ? safeOptions.getOptions(r) : null; |
| 2100 | } |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 2101 | return r.setOccludesParent(false); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2102 | } |
| 2103 | } finally { |
| 2104 | Binder.restoreCallingIdentity(origId); |
| 2105 | } |
| 2106 | } |
| 2107 | |
| 2108 | @Override |
| 2109 | public void notifyActivityDrawn(IBinder token) { |
| 2110 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, "notifyActivityDrawn: token=" + token); |
| 2111 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2112 | ActivityRecord r = mRootWindowContainer.isInAnyStack(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2113 | if (r != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2114 | r.getRootTask().notifyActivityDrawnLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2115 | } |
| 2116 | } |
| 2117 | } |
| 2118 | |
| 2119 | @Override |
| 2120 | public void reportActivityFullyDrawn(IBinder token, boolean restoredFromBundle) { |
| 2121 | synchronized (mGlobalLock) { |
| 2122 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2123 | if (r == null) { |
| 2124 | return; |
| 2125 | } |
| 2126 | r.reportFullyDrawnLocked(restoredFromBundle); |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | @Override |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2131 | public int getDisplayId(IBinder activityToken) throws RemoteException { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2132 | synchronized (mGlobalLock) { |
| 2133 | final ActivityStack stack = ActivityRecord.getStackLocked(activityToken); |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 2134 | if (stack != null) { |
| 2135 | final int displayId = stack.getDisplayId(); |
| 2136 | return displayId != INVALID_DISPLAY ? displayId : DEFAULT_DISPLAY; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2137 | } |
| 2138 | return DEFAULT_DISPLAY; |
| 2139 | } |
| 2140 | } |
| 2141 | |
| 2142 | @Override |
| 2143 | public ActivityManager.StackInfo getFocusedStackInfo() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2144 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2145 | long ident = Binder.clearCallingIdentity(); |
| 2146 | try { |
| 2147 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2148 | ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2149 | if (focusedStack != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2150 | return mRootWindowContainer.getStackInfo(focusedStack.mTaskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2151 | } |
| 2152 | return null; |
| 2153 | } |
| 2154 | } finally { |
| 2155 | Binder.restoreCallingIdentity(ident); |
| 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | @Override |
| 2160 | public void setFocusedStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2161 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2162 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedStack: stackId=" + stackId); |
| 2163 | final long callingId = Binder.clearCallingIdentity(); |
| 2164 | try { |
| 2165 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2166 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2167 | if (stack == null) { |
| 2168 | Slog.w(TAG, "setFocusedStack: No stack with id=" + stackId); |
| 2169 | return; |
| 2170 | } |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2171 | final ActivityRecord r = stack.topRunningActivity(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2172 | if (r != null && r.moveFocusableActivityToTop("setFocusedStack")) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2173 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2174 | } |
| 2175 | } |
| 2176 | } finally { |
| 2177 | Binder.restoreCallingIdentity(callingId); |
| 2178 | } |
| 2179 | } |
| 2180 | |
| 2181 | @Override |
| 2182 | public void setFocusedTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2183 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2184 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedTask: taskId=" + taskId); |
| 2185 | final long callingId = Binder.clearCallingIdentity(); |
| 2186 | try { |
| 2187 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2188 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2189 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2190 | if (task == null) { |
| 2191 | return; |
| 2192 | } |
| 2193 | final ActivityRecord r = task.topRunningActivityLocked(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2194 | if (r != null && r.moveFocusableActivityToTop("setFocusedTask")) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2195 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2196 | } |
| 2197 | } |
| 2198 | } finally { |
| 2199 | Binder.restoreCallingIdentity(callingId); |
| 2200 | } |
| 2201 | } |
| 2202 | |
| 2203 | @Override |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2204 | public void restartActivityProcessIfVisible(IBinder activityToken) { |
| 2205 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "restartActivityProcess()"); |
| 2206 | final long callingId = Binder.clearCallingIdentity(); |
| 2207 | try { |
| 2208 | synchronized (mGlobalLock) { |
| 2209 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 2210 | if (r == null) { |
| 2211 | return; |
| 2212 | } |
| 2213 | r.restartProcessIfVisible(); |
| 2214 | } |
| 2215 | } finally { |
| 2216 | Binder.restoreCallingIdentity(callingId); |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2221 | public boolean removeTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2222 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2223 | synchronized (mGlobalLock) { |
| 2224 | final long ident = Binder.clearCallingIdentity(); |
| 2225 | try { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2226 | return mStackSupervisor.removeTaskById(taskId, true, REMOVE_FROM_RECENTS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2227 | "remove-task"); |
| 2228 | } finally { |
| 2229 | Binder.restoreCallingIdentity(ident); |
| 2230 | } |
| 2231 | } |
| 2232 | } |
| 2233 | |
| 2234 | @Override |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 2235 | public void removeAllVisibleRecentTasks() { |
| 2236 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeAllVisibleRecentTasks()"); |
| 2237 | synchronized (mGlobalLock) { |
| 2238 | final long ident = Binder.clearCallingIdentity(); |
| 2239 | try { |
Winson Chung | 42fa21f | 2019-04-02 16:23:46 -0700 | [diff] [blame] | 2240 | getRecentTasks().removeAllVisibleTasks(mAmInternal.getCurrentUserId()); |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 2241 | } finally { |
| 2242 | Binder.restoreCallingIdentity(ident); |
| 2243 | } |
| 2244 | } |
| 2245 | } |
| 2246 | |
| 2247 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2248 | public boolean shouldUpRecreateTask(IBinder token, String destAffinity) { |
| 2249 | synchronized (mGlobalLock) { |
| 2250 | final ActivityRecord srec = ActivityRecord.forTokenLocked(token); |
| 2251 | if (srec != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2252 | return srec.getRootTask().shouldUpRecreateTaskLocked(srec, destAffinity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2253 | } |
| 2254 | } |
| 2255 | return false; |
| 2256 | } |
| 2257 | |
| 2258 | @Override |
| 2259 | public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode, |
| 2260 | Intent resultData) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2261 | |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 2262 | synchronized (mGlobalLock) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2263 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2264 | if (r != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2265 | return r.getRootTask().navigateUpTo( |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2266 | r, destIntent, resultCode, resultData); |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 2267 | } |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2268 | return false; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2269 | } |
| 2270 | } |
| 2271 | |
| 2272 | /** |
| 2273 | * Attempts to move a task backwards in z-order (the order of activities within the task is |
| 2274 | * unchanged). |
| 2275 | * |
| 2276 | * There are several possible results of this call: |
| 2277 | * - if the task is locked, then we will show the lock toast |
| 2278 | * - if there is a task behind the provided task, then that task is made visible and resumed as |
| 2279 | * this task is moved to the back |
| 2280 | * - otherwise, if there are no other tasks in the stack: |
| 2281 | * - if this task is in the pinned stack, then we remove the stack completely, which will |
| 2282 | * have the effect of moving the task to the top or bottom of the fullscreen stack |
| 2283 | * (depending on whether it is visible) |
| 2284 | * - otherwise, we simply return home and hide this task |
| 2285 | * |
| 2286 | * @param token A reference to the activity we wish to move |
| 2287 | * @param nonRoot If false then this only works if the activity is the root |
| 2288 | * of a task; if true it will work for any activity in a task. |
| 2289 | * @return Returns true if the move completed, false if not. |
| 2290 | */ |
| 2291 | @Override |
| 2292 | public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2293 | enforceNotIsolatedCaller("moveActivityTaskToBack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2294 | synchronized (mGlobalLock) { |
| 2295 | final long origId = Binder.clearCallingIdentity(); |
| 2296 | try { |
| 2297 | int taskId = ActivityRecord.getTaskForActivityLocked(token, !nonRoot); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2298 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2299 | if (task != null) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2300 | return ActivityRecord.getStackLocked(token).moveTaskToBack(task); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2301 | } |
| 2302 | } finally { |
| 2303 | Binder.restoreCallingIdentity(origId); |
| 2304 | } |
| 2305 | } |
| 2306 | return false; |
| 2307 | } |
| 2308 | |
| 2309 | @Override |
| 2310 | public Rect getTaskBounds(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2311 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getTaskBounds()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2312 | long ident = Binder.clearCallingIdentity(); |
| 2313 | Rect rect = new Rect(); |
| 2314 | try { |
| 2315 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2316 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2317 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2318 | if (task == null) { |
| 2319 | Slog.w(TAG, "getTaskBounds: taskId=" + taskId + " not found"); |
| 2320 | return rect; |
| 2321 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 2322 | if (task.getParent() != null) { |
| 2323 | rect.set(task.getBounds()); |
| 2324 | } else if (task.mLastNonFullscreenBounds != null) { |
| 2325 | rect.set(task.mLastNonFullscreenBounds); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2326 | } |
| 2327 | } |
| 2328 | } finally { |
| 2329 | Binder.restoreCallingIdentity(ident); |
| 2330 | } |
| 2331 | return rect; |
| 2332 | } |
| 2333 | |
| 2334 | @Override |
| 2335 | public ActivityManager.TaskDescription getTaskDescription(int id) { |
| 2336 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2337 | enforceCallerIsRecentsOrHasPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2338 | MANAGE_ACTIVITY_STACKS, "getTaskDescription()"); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2339 | final Task tr = mRootWindowContainer.anyTaskForId(id, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2340 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2341 | if (tr != null) { |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 2342 | return tr.getTaskDescription(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2343 | } |
| 2344 | } |
| 2345 | return null; |
| 2346 | } |
| 2347 | |
| 2348 | @Override |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2349 | public boolean setTaskWindowingMode(int taskId, int windowingMode, boolean toTop) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2350 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 2351 | return setTaskWindowingModeSplitScreenPrimary(taskId, toTop); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2352 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2353 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setTaskWindowingMode()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2354 | synchronized (mGlobalLock) { |
| 2355 | final long ident = Binder.clearCallingIdentity(); |
| 2356 | try { |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2357 | if (WindowConfiguration.isSplitScreenWindowingMode(windowingMode)) { |
| 2358 | return setTaskWindowingModeSplitScreen(taskId, windowingMode, toTop); |
| 2359 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2360 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2361 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2362 | if (task == null) { |
| 2363 | Slog.w(TAG, "setTaskWindowingMode: No task for id=" + taskId); |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2364 | return false; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | if (DEBUG_STACK) Slog.d(TAG_STACK, "setTaskWindowingMode: moving task=" + taskId |
| 2368 | + " to windowingMode=" + windowingMode + " toTop=" + toTop); |
| 2369 | |
| 2370 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2371 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2372 | + " non-standard task " + taskId + " to windowing mode=" |
| 2373 | + windowingMode); |
| 2374 | } |
| 2375 | |
| 2376 | final ActivityStack stack = task.getStack(); |
| 2377 | if (toTop) { |
| 2378 | stack.moveToFront("setTaskWindowingMode", task); |
| 2379 | } |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2380 | // Convert some windowing-mode changes into root-task reparents for split-screen. |
| 2381 | if (stack.inSplitScreenWindowingMode()) { |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 2382 | stack.getDisplayArea().onSplitScreenModeDismissed(); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2383 | |
| 2384 | } else { |
| 2385 | stack.setWindowingMode(windowingMode); |
| 2386 | stack.getDisplay().ensureActivitiesVisible(null, 0, PRESERVE_WINDOWS, |
| 2387 | true /* notifyClients */); |
| 2388 | } |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2389 | return true; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2390 | } finally { |
| 2391 | Binder.restoreCallingIdentity(ident); |
| 2392 | } |
| 2393 | } |
| 2394 | } |
| 2395 | |
| 2396 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2397 | public String getCallingPackage(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2398 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2399 | ActivityRecord r = getCallingRecordLocked(token); |
| 2400 | return r != null ? r.info.packageName : null; |
| 2401 | } |
| 2402 | } |
| 2403 | |
| 2404 | @Override |
| 2405 | public ComponentName getCallingActivity(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2406 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2407 | ActivityRecord r = getCallingRecordLocked(token); |
| 2408 | return r != null ? r.intent.getComponent() : null; |
| 2409 | } |
| 2410 | } |
| 2411 | |
| 2412 | private ActivityRecord getCallingRecordLocked(IBinder token) { |
| 2413 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2414 | if (r == null) { |
| 2415 | return null; |
| 2416 | } |
| 2417 | return r.resultTo; |
| 2418 | } |
| 2419 | |
| 2420 | @Override |
| 2421 | public void unhandledBack() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2422 | mAmInternal.enforceCallingPermission(android.Manifest.permission.FORCE_BACK, "unhandledBack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2423 | |
| 2424 | synchronized (mGlobalLock) { |
| 2425 | final long origId = Binder.clearCallingIdentity(); |
| 2426 | try { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 2427 | final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); |
| 2428 | if (topFocusedStack != null) { |
| 2429 | topFocusedStack.unhandledBackLocked(); |
| 2430 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2431 | } finally { |
| 2432 | Binder.restoreCallingIdentity(origId); |
| 2433 | } |
| 2434 | } |
| 2435 | } |
| 2436 | |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2437 | @Override |
| 2438 | public void onBackPressedOnTaskRoot(IBinder token, IRequestFinishCallback callback) { |
| 2439 | synchronized (mGlobalLock) { |
| 2440 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2441 | if (r == null) { |
| 2442 | return; |
| 2443 | } |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2444 | ActivityStack stack = r.getRootTask(); |
Winson Chung | a1f869d | 2020-03-21 23:02:48 -0700 | [diff] [blame] | 2445 | final TaskOrganizerController taskOrgController = |
| 2446 | mWindowOrganizerController.mTaskOrganizerController; |
| 2447 | if (taskOrgController.handleInterceptBackPressedOnTaskRoot(stack)) { |
| 2448 | // This task is handled by a task organizer that has requested the back pressed |
| 2449 | // callback |
| 2450 | } else if (stack != null && (stack.isSingleTaskInstance())) { |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2451 | // Single-task stacks are used for activities which are presented in floating |
| 2452 | // windows above full screen activities. Instead of directly finishing the |
| 2453 | // task, a task change listener is used to notify SystemUI so the action can be |
| 2454 | // handled specially. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2455 | final Task task = r.getTask(); |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2456 | mTaskChangeNotificationController |
| 2457 | .notifyBackPressedOnTaskRoot(task.getTaskInfo()); |
| 2458 | } else { |
| 2459 | try { |
| 2460 | callback.requestFinish(); |
| 2461 | } catch (RemoteException e) { |
| 2462 | Slog.e(TAG, "Failed to invoke request finish callback", e); |
| 2463 | } |
| 2464 | } |
| 2465 | } |
| 2466 | } |
| 2467 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2468 | /** |
| 2469 | * TODO: Add mController hook |
| 2470 | */ |
| 2471 | @Override |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2472 | public void moveTaskToFront(IApplicationThread appThread, String callingPackage, int taskId, |
| 2473 | int flags, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2474 | mAmInternal.enforceCallingPermission(android.Manifest.permission.REORDER_TASKS, "moveTaskToFront()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2475 | |
| 2476 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToFront: moving taskId=" + taskId); |
| 2477 | synchronized (mGlobalLock) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2478 | moveTaskToFrontLocked(appThread, callingPackage, taskId, flags, |
| 2479 | SafeActivityOptions.fromBundle(bOptions), false /* fromRecents */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2480 | } |
| 2481 | } |
| 2482 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2483 | void moveTaskToFrontLocked(@Nullable IApplicationThread appThread, |
| 2484 | @Nullable String callingPackage, int taskId, int flags, SafeActivityOptions options, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2485 | boolean fromRecents) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2486 | final int callingPid = Binder.getCallingPid(); |
| 2487 | final int callingUid = Binder.getCallingUid(); |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 2488 | assertPackageMatchesCallingUid(callingPackage); |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2489 | if (!checkAppSwitchAllowedLocked(callingPid, callingUid, -1, -1, "Task to front")) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2490 | SafeActivityOptions.abort(options); |
| 2491 | return; |
| 2492 | } |
| 2493 | final long origId = Binder.clearCallingIdentity(); |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2494 | WindowProcessController callerApp = null; |
| 2495 | if (appThread != null) { |
| 2496 | callerApp = getProcessController(appThread); |
| 2497 | } |
| 2498 | final ActivityStarter starter = getActivityStartController().obtainStarter( |
| 2499 | null /* intent */, "moveTaskToFront"); |
| 2500 | if (starter.shouldAbortBackgroundActivityStart(callingUid, callingPid, callingPackage, -1, |
Galia Peycheva | ed401cc | 2020-03-19 20:28:09 +0100 | [diff] [blame] | 2501 | -1, callerApp, null, false, null)) { |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 2502 | if (!isBackgroundActivityStartsEnabled()) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2503 | return; |
| 2504 | } |
| 2505 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2506 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2507 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2508 | if (task == null) { |
| 2509 | Slog.d(TAG, "Could not find task for id: "+ taskId); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2510 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2511 | return; |
| 2512 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2513 | if (getLockTaskController().isLockTaskModeViolation(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2514 | Slog.e(TAG, "moveTaskToFront: Attempt to violate Lock Task Mode"); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2515 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2516 | return; |
| 2517 | } |
| 2518 | ActivityOptions realOptions = options != null |
| 2519 | ? options.getOptions(mStackSupervisor) |
| 2520 | : null; |
| 2521 | mStackSupervisor.findTaskToMoveToFront(task, flags, realOptions, "moveTaskToFront", |
| 2522 | false /* forceNonResizable */); |
| 2523 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 2524 | final ActivityRecord topActivity = task.getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2525 | if (topActivity != null) { |
| 2526 | |
| 2527 | // We are reshowing a task, use a starting window to hide the initial draw delay |
| 2528 | // so the transition can start earlier. |
| 2529 | topActivity.showStartingWindow(null /* prev */, false /* newTask */, |
| 2530 | true /* taskSwitch */, fromRecents); |
| 2531 | } |
| 2532 | } finally { |
| 2533 | Binder.restoreCallingIdentity(origId); |
| 2534 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2535 | } |
| 2536 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2537 | /** |
| 2538 | * Return true if callingUid is system, or packageName belongs to that callingUid. |
| 2539 | */ |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 2540 | private boolean isSameApp(int callingUid, @Nullable String packageName) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2541 | try { |
| 2542 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 2543 | if (packageName == null) { |
| 2544 | return false; |
| 2545 | } |
| 2546 | final int uid = AppGlobals.getPackageManager().getPackageUid(packageName, |
| 2547 | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 2548 | UserHandle.getUserId(callingUid)); |
| 2549 | return UserHandle.isSameApp(callingUid, uid); |
| 2550 | } |
| 2551 | } catch (RemoteException e) { |
| 2552 | // Should not happen |
| 2553 | } |
| 2554 | return true; |
| 2555 | } |
| 2556 | |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 2557 | /** |
| 2558 | * Checks that the provided package name matches the current calling UID, throws a security |
| 2559 | * exception if it doesn't. |
| 2560 | */ |
| 2561 | void assertPackageMatchesCallingUid(@Nullable String packageName) { |
| 2562 | final int callingUid = Binder.getCallingUid(); |
| 2563 | if (isSameApp(callingUid, packageName)) { |
| 2564 | return; |
| 2565 | } |
| 2566 | final String msg = "Permission Denial: package=" + packageName |
| 2567 | + " does not belong to uid=" + callingUid; |
| 2568 | Slog.w(TAG, msg); |
| 2569 | throw new SecurityException(msg); |
| 2570 | } |
| 2571 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2572 | boolean checkAppSwitchAllowedLocked(int sourcePid, int sourceUid, |
| 2573 | int callingPid, int callingUid, String name) { |
| 2574 | if (mAppSwitchesAllowedTime < SystemClock.uptimeMillis()) { |
| 2575 | return true; |
| 2576 | } |
| 2577 | |
| 2578 | if (getRecentTasks().isCallerRecents(sourceUid)) { |
| 2579 | return true; |
| 2580 | } |
| 2581 | |
| 2582 | int perm = checkComponentPermission(STOP_APP_SWITCHES, sourcePid, sourceUid, -1, true); |
| 2583 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2584 | return true; |
| 2585 | } |
| 2586 | if (checkAllowAppSwitchUid(sourceUid)) { |
| 2587 | return true; |
| 2588 | } |
| 2589 | |
| 2590 | // If the actual IPC caller is different from the logical source, then |
| 2591 | // also see if they are allowed to control app switches. |
| 2592 | if (callingUid != -1 && callingUid != sourceUid) { |
| 2593 | perm = checkComponentPermission(STOP_APP_SWITCHES, callingPid, callingUid, -1, true); |
| 2594 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2595 | return true; |
| 2596 | } |
| 2597 | if (checkAllowAppSwitchUid(callingUid)) { |
| 2598 | return true; |
| 2599 | } |
| 2600 | } |
| 2601 | |
| 2602 | Slog.w(TAG, name + " request from " + sourceUid + " stopped"); |
| 2603 | return false; |
| 2604 | } |
| 2605 | |
| 2606 | private boolean checkAllowAppSwitchUid(int uid) { |
| 2607 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(UserHandle.getUserId(uid)); |
| 2608 | if (types != null) { |
| 2609 | for (int i = types.size() - 1; i >= 0; i--) { |
| 2610 | if (types.valueAt(i).intValue() == uid) { |
| 2611 | return true; |
| 2612 | } |
| 2613 | } |
| 2614 | } |
| 2615 | return false; |
| 2616 | } |
| 2617 | |
| 2618 | @Override |
| 2619 | public void setActivityController(IActivityController controller, boolean imAMonkey) { |
| 2620 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER, |
| 2621 | "setActivityController()"); |
| 2622 | synchronized (mGlobalLock) { |
| 2623 | mController = controller; |
| 2624 | mControllerIsAMonkey = imAMonkey; |
| 2625 | Watchdog.getInstance().setActivityController(controller); |
| 2626 | } |
| 2627 | } |
| 2628 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 2629 | public boolean isControllerAMonkey() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2630 | synchronized (mGlobalLock) { |
| 2631 | return mController != null && mControllerIsAMonkey; |
| 2632 | } |
| 2633 | } |
| 2634 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2635 | @Override |
| 2636 | public int getTaskForActivity(IBinder token, boolean onlyRoot) { |
| 2637 | synchronized (mGlobalLock) { |
| 2638 | return ActivityRecord.getTaskForActivityLocked(token, onlyRoot); |
| 2639 | } |
| 2640 | } |
| 2641 | |
| 2642 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2643 | public List<ActivityManager.RunningTaskInfo> getTasks(int maxNum) { |
Winson Chung | e5ab017 | 2020-03-21 23:00:24 -0700 | [diff] [blame] | 2644 | return getFilteredTasks(maxNum, false /* filterForVisibleRecents */); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2645 | } |
| 2646 | |
Winson Chung | e5ab017 | 2020-03-21 23:00:24 -0700 | [diff] [blame] | 2647 | /** |
| 2648 | * @param filterOnlyVisibleRecents whether to filter the tasks based on whether they would ever |
| 2649 | * be visible in the recent task list in systemui |
| 2650 | */ |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2651 | @Override |
| 2652 | public List<ActivityManager.RunningTaskInfo> getFilteredTasks(int maxNum, |
Winson Chung | e5ab017 | 2020-03-21 23:00:24 -0700 | [diff] [blame] | 2653 | boolean filterOnlyVisibleRecents) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2654 | final int callingUid = Binder.getCallingUid(); |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 2655 | final int callingPid = Binder.getCallingPid(); |
| 2656 | final boolean crossUser = isCrossUserAllowed(callingPid, callingUid); |
Nicholas Sauer | 3f9249f | 2019-09-10 20:23:41 -0700 | [diff] [blame] | 2657 | final int[] profileIds = getUserManager().getProfileIds( |
| 2658 | UserHandle.getUserId(callingUid), true); |
| 2659 | ArraySet<Integer> callingProfileIds = new ArraySet<>(); |
| 2660 | for (int i = 0; i < profileIds.length; i++) { |
| 2661 | callingProfileIds.add(profileIds[i]); |
| 2662 | } |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2663 | ArrayList<ActivityManager.RunningTaskInfo> list = new ArrayList<>(); |
| 2664 | |
| 2665 | synchronized (mGlobalLock) { |
| 2666 | if (DEBUG_ALL) Slog.v(TAG, "getTasks: max=" + maxNum); |
| 2667 | |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 2668 | final boolean allowed = isGetTasksAllowed("getTasks", callingPid, callingUid); |
Winson Chung | e5ab017 | 2020-03-21 23:00:24 -0700 | [diff] [blame] | 2669 | mRootWindowContainer.getRunningTasks(maxNum, list, filterOnlyVisibleRecents, callingUid, |
| 2670 | allowed, crossUser, callingProfileIds); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | return list; |
| 2674 | } |
| 2675 | |
| 2676 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2677 | public final void finishSubActivity(IBinder token, String resultWho, int requestCode) { |
| 2678 | synchronized (mGlobalLock) { |
| 2679 | final long origId = Binder.clearCallingIdentity(); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2680 | try { |
| 2681 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2682 | if (r == null) return; |
| 2683 | |
| 2684 | final PooledConsumer c = PooledLambda.obtainConsumer( |
| 2685 | ActivityRecord::finishIfSubActivity, PooledLambda.__(ActivityRecord.class), |
| 2686 | r, resultWho, requestCode); |
| 2687 | // TODO: This should probably only loop over the task since you need to be in the |
| 2688 | // same task to return results. |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2689 | r.getRootTask().forAllActivities(c); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2690 | c.recycle(); |
| 2691 | |
| 2692 | updateOomAdj(); |
| 2693 | } finally { |
| 2694 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2695 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2696 | } |
| 2697 | } |
| 2698 | |
| 2699 | @Override |
| 2700 | public boolean willActivityBeVisible(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2701 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2702 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 2703 | if (stack != null) { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2704 | return stack.willActivityBeVisible(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2705 | } |
| 2706 | return false; |
| 2707 | } |
| 2708 | } |
| 2709 | |
| 2710 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2711 | public void moveTaskToStack(int taskId, int stackId, boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2712 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "moveTaskToStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2713 | synchronized (mGlobalLock) { |
| 2714 | final long ident = Binder.clearCallingIdentity(); |
| 2715 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2716 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2717 | if (task == null) { |
| 2718 | Slog.w(TAG, "moveTaskToStack: No task for id=" + taskId); |
| 2719 | return; |
| 2720 | } |
| 2721 | |
| 2722 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToStack: moving task=" + taskId |
| 2723 | + " to stackId=" + stackId + " toTop=" + toTop); |
| 2724 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2725 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2726 | if (stack == null) { |
| 2727 | throw new IllegalStateException( |
| 2728 | "moveTaskToStack: No stack for stackId=" + stackId); |
| 2729 | } |
| 2730 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 2731 | throw new IllegalArgumentException("moveTaskToStack: Attempt to move task " |
| 2732 | + taskId + " to stack " + stackId); |
| 2733 | } |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2734 | task.reparent(stack, toTop, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME, |
| 2735 | "moveTaskToStack"); |
| 2736 | } finally { |
| 2737 | Binder.restoreCallingIdentity(ident); |
| 2738 | } |
| 2739 | } |
| 2740 | } |
| 2741 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2742 | /** |
| 2743 | * Moves the specified task to the primary-split-screen stack. |
| 2744 | * |
| 2745 | * @param taskId Id of task to move. |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2746 | * @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] | 2747 | * @return Whether the task was successfully put into splitscreen. |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2748 | */ |
| 2749 | @Override |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 2750 | public boolean setTaskWindowingModeSplitScreenPrimary(int taskId, boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2751 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2752 | "setTaskWindowingModeSplitScreenPrimary()"); |
| 2753 | synchronized (mGlobalLock) { |
| 2754 | final long ident = Binder.clearCallingIdentity(); |
| 2755 | try { |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2756 | return setTaskWindowingModeSplitScreen(taskId, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, |
| 2757 | toTop); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2758 | } finally { |
| 2759 | Binder.restoreCallingIdentity(ident); |
| 2760 | } |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | /** |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2765 | * Moves the specified task into a split-screen tile. |
| 2766 | */ |
| 2767 | private boolean setTaskWindowingModeSplitScreen(int taskId, int windowingMode, boolean toTop) { |
| 2768 | if (!WindowConfiguration.isSplitScreenWindowingMode(windowingMode)) { |
| 2769 | throw new IllegalArgumentException("Calling setTaskWindowingModeSplitScreen with non" |
| 2770 | + "split-screen mode: " + windowingMode); |
| 2771 | } |
| 2772 | if (isInLockTaskMode()) { |
| 2773 | Slog.w(TAG, "setTaskWindowingModeSplitScreen: Is in lock task mode=" |
| 2774 | + getLockTaskModeState()); |
| 2775 | return false; |
| 2776 | } |
| 2777 | |
| 2778 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
| 2779 | MATCH_TASK_IN_STACKS_ONLY); |
| 2780 | if (task == null) { |
| 2781 | Slog.w(TAG, "setTaskWindowingModeSplitScreenPrimary: No task for id=" + taskId); |
| 2782 | return false; |
| 2783 | } |
| 2784 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2785 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2786 | + " non-standard task " + taskId + " to split-screen windowing mode"); |
| 2787 | } |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 2788 | if (!task.supportsSplitScreenWindowingMode()) { |
| 2789 | return false; |
| 2790 | } |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2791 | |
| 2792 | final int prevMode = task.getWindowingMode(); |
Louis Chang | cf3d145 | 2020-04-16 16:36:05 +0800 | [diff] [blame] | 2793 | if (prevMode == windowingMode) { |
| 2794 | // The task is already in split-screen and with correct windowing mode. |
| 2795 | return true; |
| 2796 | } |
| 2797 | |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2798 | moveTaskToSplitScreenPrimaryTask(task, toTop); |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 2799 | return prevMode != task.getWindowingMode(); |
| 2800 | } |
| 2801 | |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2802 | void moveTaskToSplitScreenPrimaryTask(Task task, boolean toTop) { |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 2803 | final TaskDisplayArea taskDisplayArea = task.getDisplayArea(); |
| 2804 | final ActivityStack primarySplitTask = taskDisplayArea.getRootSplitScreenPrimaryTask(); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2805 | if (primarySplitTask == null) { |
| 2806 | throw new IllegalStateException("Can't enter split without associated organized task"); |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2807 | } |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2808 | |
| 2809 | if (toTop) { |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 2810 | taskDisplayArea.positionStackAt(POSITION_TOP, primarySplitTask, |
Andrii Kulian | 9ea12da | 2020-03-27 17:16:38 -0700 | [diff] [blame] | 2811 | false /* includingParents */); |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2812 | } |
| 2813 | WindowContainerTransaction wct = new WindowContainerTransaction(); |
Wale Ogunwale | 465b1e1 | 2020-03-31 12:15:51 -0700 | [diff] [blame] | 2814 | // Clear out current windowing mode before reparenting to split taks. |
| 2815 | wct.setWindowingMode( |
| 2816 | task.getStack().mRemoteToken.toWindowContainerToken(), WINDOWING_MODE_UNDEFINED); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 2817 | wct.reparent(task.getStack().mRemoteToken.toWindowContainerToken(), |
| 2818 | primarySplitTask.mRemoteToken.toWindowContainerToken(), toTop); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 2819 | mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | /** |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2823 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 2824 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 2825 | */ |
| 2826 | @Override |
| 2827 | public void removeStacksInWindowingModes(int[] windowingModes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2828 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2829 | "removeStacksInWindowingModes()"); |
| 2830 | |
| 2831 | synchronized (mGlobalLock) { |
| 2832 | final long ident = Binder.clearCallingIdentity(); |
| 2833 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2834 | mRootWindowContainer.removeStacksInWindowingModes(windowingModes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2835 | } finally { |
| 2836 | Binder.restoreCallingIdentity(ident); |
| 2837 | } |
| 2838 | } |
| 2839 | } |
| 2840 | |
| 2841 | @Override |
| 2842 | public void removeStacksWithActivityTypes(int[] activityTypes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2843 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2844 | "removeStacksWithActivityTypes()"); |
| 2845 | |
| 2846 | synchronized (mGlobalLock) { |
| 2847 | final long ident = Binder.clearCallingIdentity(); |
| 2848 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2849 | mRootWindowContainer.removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2850 | } finally { |
| 2851 | Binder.restoreCallingIdentity(ident); |
| 2852 | } |
| 2853 | } |
| 2854 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2855 | |
| 2856 | @Override |
| 2857 | public ParceledListSlice<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, |
| 2858 | int userId) { |
| 2859 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2860 | userId = handleIncomingUser(Binder.getCallingPid(), callingUid, userId, "getRecentTasks"); |
| 2861 | final boolean allowed = isGetTasksAllowed("getRecentTasks", Binder.getCallingPid(), |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2862 | callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2863 | synchronized (mGlobalLock) { |
Winson Chung | 66b08f0 | 2020-03-03 14:32:35 -0800 | [diff] [blame] | 2864 | return mRecentTasks.getRecentTasks(maxNum, flags, allowed, userId, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2865 | } |
| 2866 | } |
| 2867 | |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 2868 | // TODO(148895075): deprecate and replace with task equivalents |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2869 | @Override |
| 2870 | public List<ActivityManager.StackInfo> getAllStackInfos() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2871 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2872 | long ident = Binder.clearCallingIdentity(); |
| 2873 | try { |
| 2874 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2875 | return mRootWindowContainer.getAllStackInfos(INVALID_DISPLAY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2876 | } |
| 2877 | } finally { |
| 2878 | Binder.restoreCallingIdentity(ident); |
| 2879 | } |
| 2880 | } |
| 2881 | |
| 2882 | @Override |
| 2883 | public ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2884 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2885 | long ident = Binder.clearCallingIdentity(); |
| 2886 | try { |
| 2887 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2888 | return mRootWindowContainer.getStackInfo(windowingMode, activityType); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2889 | } |
| 2890 | } finally { |
| 2891 | Binder.restoreCallingIdentity(ident); |
| 2892 | } |
| 2893 | } |
| 2894 | |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 2895 | // TODO(148895075): deprecate and replace with task equivalents |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2896 | @Override |
Evan Rosky | fd43969 | 2019-11-06 16:12:59 -0800 | [diff] [blame] | 2897 | public List<ActivityManager.StackInfo> getAllStackInfosOnDisplay(int displayId) { |
| 2898 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); |
| 2899 | long ident = Binder.clearCallingIdentity(); |
| 2900 | try { |
| 2901 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2902 | return mRootWindowContainer.getAllStackInfos(displayId); |
Evan Rosky | fd43969 | 2019-11-06 16:12:59 -0800 | [diff] [blame] | 2903 | } |
| 2904 | } finally { |
| 2905 | Binder.restoreCallingIdentity(ident); |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | @Override |
| 2910 | public ActivityManager.StackInfo getStackInfoOnDisplay(int windowingMode, int activityType, |
| 2911 | int displayId) { |
| 2912 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
| 2913 | long ident = Binder.clearCallingIdentity(); |
| 2914 | try { |
| 2915 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2916 | return mRootWindowContainer.getStackInfo(windowingMode, activityType, displayId); |
Evan Rosky | fd43969 | 2019-11-06 16:12:59 -0800 | [diff] [blame] | 2917 | } |
| 2918 | } finally { |
| 2919 | Binder.restoreCallingIdentity(ident); |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2924 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2925 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "cancelRecentsAnimation()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2926 | final long callingUid = Binder.getCallingUid(); |
| 2927 | final long origId = Binder.clearCallingIdentity(); |
| 2928 | try { |
| 2929 | synchronized (mGlobalLock) { |
| 2930 | // Cancel the recents animation synchronously (do not hold the WM lock) |
Wale Ogunwale | a441b92 | 2019-06-27 19:21:44 -0700 | [diff] [blame] | 2931 | mWindowManager.cancelRecentsAnimation(restoreHomeStackPosition |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2932 | ? REORDER_MOVE_TO_ORIGINAL_POSITION |
| 2933 | : REORDER_KEEP_IN_PLACE, "cancelRecentsAnimation/uid=" + callingUid); |
| 2934 | } |
| 2935 | } finally { |
| 2936 | Binder.restoreCallingIdentity(origId); |
| 2937 | } |
| 2938 | } |
| 2939 | |
| 2940 | @Override |
| 2941 | public void startLockTaskModeByToken(IBinder token) { |
| 2942 | synchronized (mGlobalLock) { |
| 2943 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2944 | if (r == null) { |
| 2945 | return; |
| 2946 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2947 | startLockTaskModeLocked(r.getTask(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2948 | } |
| 2949 | } |
| 2950 | |
| 2951 | @Override |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2952 | public void startSystemLockTaskMode(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2953 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "startSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2954 | // This makes inner call to look as if it was initiated by system. |
| 2955 | long ident = Binder.clearCallingIdentity(); |
| 2956 | try { |
| 2957 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2958 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2959 | MATCH_TASK_IN_STACKS_ONLY); |
| 2960 | if (task == null) { |
| 2961 | return; |
| 2962 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2963 | |
| 2964 | // When starting lock task mode the stack must be in front and focused |
| 2965 | task.getStack().moveToFront("startSystemLockTaskMode"); |
| 2966 | startLockTaskModeLocked(task, true /* isSystemCaller */); |
| 2967 | } |
| 2968 | } finally { |
| 2969 | Binder.restoreCallingIdentity(ident); |
| 2970 | } |
| 2971 | } |
| 2972 | |
| 2973 | @Override |
| 2974 | public void stopLockTaskModeByToken(IBinder token) { |
| 2975 | synchronized (mGlobalLock) { |
| 2976 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2977 | if (r == null) { |
| 2978 | return; |
| 2979 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2980 | stopLockTaskModeInternal(r.getTask(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | /** |
| 2985 | * This API should be called by SystemUI only when user perform certain action to dismiss |
| 2986 | * lock task mode. We should only dismiss pinned lock task mode in this case. |
| 2987 | */ |
| 2988 | @Override |
| 2989 | public void stopSystemLockTaskMode() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2990 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "stopSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2991 | stopLockTaskModeInternal(null, true /* isSystemCaller */); |
| 2992 | } |
| 2993 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2994 | private void startLockTaskModeLocked(@Nullable Task task, boolean isSystemCaller) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2995 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "startLockTaskModeLocked: " + task); |
| 2996 | if (task == null || task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) { |
| 2997 | return; |
| 2998 | } |
| 2999 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3000 | final ActivityStack stack = mRootWindowContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 3001 | if (stack == null || task != stack.getTopMostTask()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3002 | throw new IllegalArgumentException("Invalid task, not in foreground"); |
| 3003 | } |
| 3004 | |
| 3005 | // {@code isSystemCaller} is used to distinguish whether this request is initiated by the |
| 3006 | // system or a specific app. |
| 3007 | // * System-initiated requests will only start the pinned mode (screen pinning) |
| 3008 | // * App-initiated requests |
| 3009 | // - will put the device in fully locked mode (LockTask), if the app is whitelisted |
| 3010 | // - will start the pinned mode, otherwise |
| 3011 | final int callingUid = Binder.getCallingUid(); |
| 3012 | long ident = Binder.clearCallingIdentity(); |
| 3013 | try { |
| 3014 | // When a task is locked, dismiss the pinned stack if it exists |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3015 | mRootWindowContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3016 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3017 | getLockTaskController().startLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3018 | } finally { |
| 3019 | Binder.restoreCallingIdentity(ident); |
| 3020 | } |
| 3021 | } |
| 3022 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3023 | private void stopLockTaskModeInternal(@Nullable Task task, boolean isSystemCaller) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3024 | final int callingUid = Binder.getCallingUid(); |
| 3025 | long ident = Binder.clearCallingIdentity(); |
| 3026 | try { |
| 3027 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3028 | getLockTaskController().stopLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3029 | } |
| 3030 | // Launch in-call UI if a call is ongoing. This is necessary to allow stopping the lock |
| 3031 | // task and jumping straight into a call in the case of emergency call back. |
| 3032 | TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
| 3033 | if (tm != null) { |
| 3034 | tm.showInCallScreen(false); |
| 3035 | } |
| 3036 | } finally { |
| 3037 | Binder.restoreCallingIdentity(ident); |
| 3038 | } |
| 3039 | } |
| 3040 | |
| 3041 | @Override |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 3042 | public void updateLockTaskPackages(int userId, String[] packages) { |
| 3043 | final int callingUid = Binder.getCallingUid(); |
| 3044 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 3045 | mAmInternal.enforceCallingPermission(Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
| 3046 | "updateLockTaskPackages()"); |
| 3047 | } |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 3048 | synchronized (mGlobalLock) { |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 3049 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Whitelisting " + userId + ":" |
| 3050 | + Arrays.toString(packages)); |
| 3051 | getLockTaskController().updateLockTaskPackages(userId, packages); |
| 3052 | } |
| 3053 | } |
| 3054 | |
| 3055 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3056 | public boolean isInLockTaskMode() { |
| 3057 | return getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
| 3058 | } |
| 3059 | |
| 3060 | @Override |
| 3061 | public int getLockTaskModeState() { |
| 3062 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3063 | return getLockTaskController().getLockTaskModeState(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3064 | } |
| 3065 | } |
| 3066 | |
| 3067 | @Override |
| 3068 | public void setTaskDescription(IBinder token, ActivityManager.TaskDescription td) { |
| 3069 | synchronized (mGlobalLock) { |
| 3070 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3071 | if (r != null) { |
| 3072 | r.setTaskDescription(td); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3073 | } |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | @Override |
| 3078 | public Bundle getActivityOptions(IBinder token) { |
| 3079 | final long origId = Binder.clearCallingIdentity(); |
| 3080 | try { |
| 3081 | synchronized (mGlobalLock) { |
| 3082 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3083 | if (r != null) { |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 3084 | final ActivityOptions activityOptions = r.takeOptionsLocked( |
| 3085 | true /* fromClient */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3086 | return activityOptions == null ? null : activityOptions.toBundle(); |
| 3087 | } |
| 3088 | return null; |
| 3089 | } |
| 3090 | } finally { |
| 3091 | Binder.restoreCallingIdentity(origId); |
| 3092 | } |
| 3093 | } |
| 3094 | |
| 3095 | @Override |
| 3096 | public List<IBinder> getAppTasks(String callingPackage) { |
| 3097 | int callingUid = Binder.getCallingUid(); |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 3098 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3099 | long ident = Binder.clearCallingIdentity(); |
| 3100 | try { |
| 3101 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3102 | return mRecentTasks.getAppTasksList(callingUid, callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3103 | } |
| 3104 | } finally { |
| 3105 | Binder.restoreCallingIdentity(ident); |
| 3106 | } |
| 3107 | } |
| 3108 | |
| 3109 | @Override |
| 3110 | public void finishVoiceTask(IVoiceInteractionSession session) { |
| 3111 | synchronized (mGlobalLock) { |
| 3112 | final long origId = Binder.clearCallingIdentity(); |
| 3113 | try { |
| 3114 | // TODO: VI Consider treating local voice interactions and voice tasks |
| 3115 | // differently here |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3116 | mRootWindowContainer.finishVoiceTask(session); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3117 | } finally { |
| 3118 | Binder.restoreCallingIdentity(origId); |
| 3119 | } |
| 3120 | } |
| 3121 | |
| 3122 | } |
| 3123 | |
| 3124 | @Override |
| 3125 | public boolean isTopOfTask(IBinder token) { |
| 3126 | synchronized (mGlobalLock) { |
| 3127 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3128 | return r != null && r.getTask().getTopNonFinishingActivity() == r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3129 | } |
| 3130 | } |
| 3131 | |
| 3132 | @Override |
| 3133 | public void notifyLaunchTaskBehindComplete(IBinder token) { |
| 3134 | mStackSupervisor.scheduleLaunchTaskBehindComplete(token); |
| 3135 | } |
| 3136 | |
| 3137 | @Override |
| 3138 | public void notifyEnterAnimationComplete(IBinder token) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3139 | mH.post(() -> { |
| 3140 | synchronized (mGlobalLock) { |
| 3141 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3142 | if (r != null && r.attachedToProcess()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3143 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3144 | r.app.getThread().scheduleEnterAnimationComplete(r.appToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3145 | } catch (RemoteException e) { |
| 3146 | } |
| 3147 | } |
| 3148 | } |
| 3149 | |
| 3150 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | /** Called from an app when assist data is ready. */ |
| 3154 | @Override |
| 3155 | public void reportAssistContextExtras(IBinder token, Bundle extras, AssistStructure structure, |
| 3156 | AssistContent content, Uri referrer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3157 | PendingAssistExtras pae = (PendingAssistExtras) token; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3158 | synchronized (pae) { |
| 3159 | pae.result = extras; |
| 3160 | pae.structure = structure; |
| 3161 | pae.content = content; |
| 3162 | if (referrer != null) { |
| 3163 | pae.extras.putParcelable(Intent.EXTRA_REFERRER, referrer); |
| 3164 | } |
| 3165 | if (structure != null) { |
Winson Chung | 48b2565 | 2018-10-22 14:04:30 -0700 | [diff] [blame] | 3166 | // Pre-fill the task/activity component for all assist data receivers |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3167 | structure.setTaskId(pae.activity.getTask().mTaskId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3168 | structure.setActivityComponent(pae.activity.mActivityComponent); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3169 | structure.setHomeActivity(pae.isHome); |
| 3170 | } |
| 3171 | pae.haveResult = true; |
| 3172 | pae.notifyAll(); |
| 3173 | if (pae.intent == null && pae.receiver == null) { |
| 3174 | // Caller is just waiting for the result. |
| 3175 | return; |
| 3176 | } |
| 3177 | } |
| 3178 | // We are now ready to launch the assist activity. |
| 3179 | IAssistDataReceiver sendReceiver = null; |
| 3180 | Bundle sendBundle = null; |
| 3181 | synchronized (mGlobalLock) { |
| 3182 | buildAssistBundleLocked(pae, extras); |
| 3183 | boolean exists = mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3184 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3185 | if (!exists) { |
| 3186 | // Timed out. |
| 3187 | return; |
| 3188 | } |
| 3189 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3190 | if ((sendReceiver = pae.receiver) != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3191 | // Caller wants result sent back to them. |
| 3192 | sendBundle = new Bundle(); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3193 | sendBundle.putInt(ActivityTaskManagerInternal.ASSIST_TASK_ID, |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3194 | pae.activity.getTask().mTaskId); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3195 | sendBundle.putBinder(ActivityTaskManagerInternal.ASSIST_ACTIVITY_ID, |
| 3196 | pae.activity.assistToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3197 | sendBundle.putBundle(ASSIST_KEY_DATA, pae.extras); |
| 3198 | sendBundle.putParcelable(ASSIST_KEY_STRUCTURE, pae.structure); |
| 3199 | sendBundle.putParcelable(ASSIST_KEY_CONTENT, pae.content); |
| 3200 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3201 | } |
| 3202 | } |
| 3203 | if (sendReceiver != null) { |
| 3204 | try { |
| 3205 | sendReceiver.onHandleAssistData(sendBundle); |
| 3206 | } catch (RemoteException e) { |
| 3207 | } |
| 3208 | return; |
| 3209 | } |
| 3210 | |
| 3211 | final long ident = Binder.clearCallingIdentity(); |
| 3212 | try { |
| 3213 | if (TextUtils.equals(pae.intent.getAction(), |
| 3214 | android.service.voice.VoiceInteractionService.SERVICE_INTERFACE)) { |
Galia Peycheva | bffbfc3 | 2019-06-18 10:11:35 +0200 | [diff] [blame] | 3215 | // Start voice interaction through VoiceInteractionManagerService. |
| 3216 | mAssistUtils.showSessionForActiveService(sendBundle, SHOW_SOURCE_APPLICATION, |
| 3217 | null, null); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3218 | } else { |
| 3219 | pae.intent.replaceExtras(pae.extras); |
| 3220 | pae.intent.setFlags(FLAG_ACTIVITY_NEW_TASK |
| 3221 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 3222 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 3223 | mInternal.closeSystemDialogs("assist"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3224 | |
| 3225 | try { |
| 3226 | mContext.startActivityAsUser(pae.intent, new UserHandle(pae.userHandle)); |
| 3227 | } catch (ActivityNotFoundException e) { |
| 3228 | Slog.w(TAG, "No activity to handle assist action.", e); |
| 3229 | } |
| 3230 | } |
| 3231 | } finally { |
| 3232 | Binder.restoreCallingIdentity(ident); |
| 3233 | } |
| 3234 | } |
| 3235 | |
| 3236 | @Override |
| 3237 | public int addAppTask(IBinder activityToken, Intent intent, |
| 3238 | ActivityManager.TaskDescription description, Bitmap thumbnail) throws RemoteException { |
| 3239 | final int callingUid = Binder.getCallingUid(); |
| 3240 | final long callingIdent = Binder.clearCallingIdentity(); |
| 3241 | |
| 3242 | try { |
| 3243 | synchronized (mGlobalLock) { |
| 3244 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 3245 | if (r == null) { |
| 3246 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 3247 | + activityToken); |
| 3248 | } |
| 3249 | ComponentName comp = intent.getComponent(); |
| 3250 | if (comp == null) { |
| 3251 | throw new IllegalArgumentException("Intent " + intent |
| 3252 | + " must specify explicit component"); |
| 3253 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3254 | if (thumbnail.getWidth() != mThumbnailWidth |
| 3255 | || thumbnail.getHeight() != mThumbnailHeight) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3256 | throw new IllegalArgumentException("Bad thumbnail size: got " |
| 3257 | + thumbnail.getWidth() + "x" + thumbnail.getHeight() + ", require " |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3258 | + mThumbnailWidth + "x" + mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3259 | } |
| 3260 | if (intent.getSelector() != null) { |
| 3261 | intent.setSelector(null); |
| 3262 | } |
| 3263 | if (intent.getSourceBounds() != null) { |
| 3264 | intent.setSourceBounds(null); |
| 3265 | } |
| 3266 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) { |
| 3267 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) == 0) { |
| 3268 | // The caller has added this as an auto-remove task... that makes no |
| 3269 | // sense, so turn off auto-remove. |
| 3270 | intent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS); |
| 3271 | } |
| 3272 | } |
| 3273 | final ActivityInfo ainfo = AppGlobals.getPackageManager().getActivityInfo(comp, |
| 3274 | STOCK_PM_FLAGS, UserHandle.getUserId(callingUid)); |
| 3275 | if (ainfo.applicationInfo.uid != callingUid) { |
| 3276 | throw new SecurityException( |
| 3277 | "Can't add task for another application: target uid=" |
| 3278 | + ainfo.applicationInfo.uid + ", calling uid=" + callingUid); |
| 3279 | } |
| 3280 | |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 3281 | final ActivityStack stack = r.getRootTask(); |
Andrii Kulian | 86d676c | 2020-03-27 19:34:54 -0700 | [diff] [blame] | 3282 | final Task task = stack.getDisplayArea().createStack(stack.getWindowingMode(), |
| 3283 | stack.getActivityType(), !ON_TOP, ainfo, intent, |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 3284 | false /* createdByOrganizer */); |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 3285 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3286 | if (!mRecentTasks.addToBottom(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3287 | // 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] | 3288 | stack.removeChild(task, "addAppTask"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3289 | return INVALID_TASK_ID; |
| 3290 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 3291 | task.getTaskDescription().copyFrom(description); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3292 | |
| 3293 | // TODO: Send the thumbnail to WM to store it. |
| 3294 | |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 3295 | return task.mTaskId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3296 | } |
| 3297 | } finally { |
| 3298 | Binder.restoreCallingIdentity(callingIdent); |
| 3299 | } |
| 3300 | } |
| 3301 | |
| 3302 | @Override |
| 3303 | public Point getAppTaskThumbnailSize() { |
| 3304 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3305 | return new Point(mThumbnailWidth, mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3306 | } |
| 3307 | } |
| 3308 | |
| 3309 | @Override |
| 3310 | public void setTaskResizeable(int taskId, int resizeableMode) { |
| 3311 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3312 | final Task task = mRootWindowContainer.anyTaskForId( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3313 | taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 3314 | if (task == null) { |
| 3315 | Slog.w(TAG, "setTaskResizeable: taskId=" + taskId + " not found"); |
| 3316 | return; |
| 3317 | } |
| 3318 | task.setResizeMode(resizeableMode); |
| 3319 | } |
| 3320 | } |
| 3321 | |
| 3322 | @Override |
| 3323 | public void resizeTask(int taskId, Rect bounds, int resizeMode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3324 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "resizeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3325 | long ident = Binder.clearCallingIdentity(); |
| 3326 | try { |
| 3327 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3328 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 3329 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3330 | if (task == null) { |
| 3331 | Slog.w(TAG, "resizeTask: taskId=" + taskId + " not found"); |
| 3332 | return; |
| 3333 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3334 | if (!task.getWindowConfiguration().canResizeTask()) { |
| 3335 | throw new IllegalArgumentException("resizeTask not allowed on task=" + task); |
| 3336 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3337 | |
| 3338 | // Reparent the task to the right stack if necessary |
| 3339 | boolean preserveWindow = (resizeMode & RESIZE_MODE_PRESERVE_WINDOW) != 0; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3340 | |
| 3341 | // After reparenting (which only resizes the task to the stack bounds), resize the |
| 3342 | // task to the actual bounds provided |
| 3343 | task.resize(bounds, resizeMode, preserveWindow, !DEFER_RESUME); |
| 3344 | } |
| 3345 | } finally { |
| 3346 | Binder.restoreCallingIdentity(ident); |
| 3347 | } |
| 3348 | } |
| 3349 | |
| 3350 | @Override |
| 3351 | public boolean releaseActivityInstance(IBinder token) { |
| 3352 | synchronized (mGlobalLock) { |
| 3353 | final long origId = Binder.clearCallingIdentity(); |
| 3354 | try { |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 3355 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3356 | if (r == null || !r.isDestroyable()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3357 | return false; |
| 3358 | } |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 3359 | r.destroyImmediately(true /* removeFromApp */, "app-req"); |
| 3360 | return r.isState(DESTROYING, DESTROYED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3361 | } finally { |
| 3362 | Binder.restoreCallingIdentity(origId); |
| 3363 | } |
| 3364 | } |
| 3365 | } |
| 3366 | |
| 3367 | @Override |
| 3368 | public void releaseSomeActivities(IApplicationThread appInt) { |
| 3369 | synchronized (mGlobalLock) { |
| 3370 | final long origId = Binder.clearCallingIdentity(); |
| 3371 | try { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3372 | final WindowProcessController app = getProcessController(appInt); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 3373 | app.releaseSomeActivities("low-mem"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3374 | } finally { |
| 3375 | Binder.restoreCallingIdentity(origId); |
| 3376 | } |
| 3377 | } |
| 3378 | } |
| 3379 | |
| 3380 | @Override |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 3381 | public void setLockScreenShown(boolean keyguardShowing, boolean aodShowing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3382 | if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3383 | != PackageManager.PERMISSION_GRANTED) { |
| 3384 | throw new SecurityException("Requires permission " |
| 3385 | + android.Manifest.permission.DEVICE_POWER); |
| 3386 | } |
| 3387 | |
| 3388 | synchronized (mGlobalLock) { |
| 3389 | long ident = Binder.clearCallingIdentity(); |
| 3390 | if (mKeyguardShown != keyguardShowing) { |
| 3391 | mKeyguardShown = keyguardShowing; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3392 | final Message msg = PooledLambda.obtainMessage( |
| 3393 | ActivityManagerInternal::reportCurKeyguardUsageEvent, mAmInternal, |
| 3394 | keyguardShowing); |
| 3395 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3396 | } |
| 3397 | try { |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 3398 | mKeyguardController.setKeyguardShown(keyguardShowing, aodShowing); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3399 | } finally { |
| 3400 | Binder.restoreCallingIdentity(ident); |
| 3401 | } |
| 3402 | } |
| 3403 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3404 | mH.post(() -> { |
| 3405 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3406 | mScreenObservers.get(i).onKeyguardStateChanged(keyguardShowing); |
| 3407 | } |
| 3408 | }); |
| 3409 | } |
| 3410 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 3411 | public void onScreenAwakeChanged(boolean isAwake) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3412 | mH.post(() -> { |
| 3413 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3414 | mScreenObservers.get(i).onAwakeStateChanged(isAwake); |
| 3415 | } |
| 3416 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3417 | } |
| 3418 | |
| 3419 | @Override |
| 3420 | public Bitmap getTaskDescriptionIcon(String filePath, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3421 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 3422 | userId, "getTaskDescriptionIcon"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3423 | |
| 3424 | final File passedIconFile = new File(filePath); |
| 3425 | final File legitIconFile = new File(TaskPersister.getUserImagesDir(userId), |
| 3426 | passedIconFile.getName()); |
| 3427 | if (!legitIconFile.getPath().equals(filePath) |
| 3428 | || !filePath.contains(ActivityRecord.ACTIVITY_ICON_SUFFIX)) { |
| 3429 | throw new IllegalArgumentException("Bad file path: " + filePath |
| 3430 | + " passed for userId " + userId); |
| 3431 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3432 | return mRecentTasks.getTaskDescriptionIcon(filePath); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3433 | } |
| 3434 | |
| 3435 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3436 | public void removeStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3437 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "removeStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3438 | synchronized (mGlobalLock) { |
| 3439 | final long ident = Binder.clearCallingIdentity(); |
| 3440 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3441 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3442 | if (stack == null) { |
| 3443 | Slog.w(TAG, "removeStack: No stack with id=" + stackId); |
| 3444 | return; |
| 3445 | } |
| 3446 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3447 | throw new IllegalArgumentException( |
| 3448 | "Removing non-standard stack is not allowed."); |
| 3449 | } |
| 3450 | mStackSupervisor.removeStack(stack); |
| 3451 | } finally { |
| 3452 | Binder.restoreCallingIdentity(ident); |
| 3453 | } |
| 3454 | } |
| 3455 | } |
| 3456 | |
| 3457 | @Override |
| 3458 | public void moveStackToDisplay(int stackId, int displayId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3459 | mAmInternal.enforceCallingPermission(INTERNAL_SYSTEM_WINDOW, "moveStackToDisplay()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3460 | |
| 3461 | synchronized (mGlobalLock) { |
| 3462 | final long ident = Binder.clearCallingIdentity(); |
| 3463 | try { |
| 3464 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveStackToDisplay: moving stackId=" + stackId |
| 3465 | + " to displayId=" + displayId); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3466 | mRootWindowContainer.moveStackToDisplay(stackId, displayId, ON_TOP); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3467 | } finally { |
| 3468 | Binder.restoreCallingIdentity(ident); |
| 3469 | } |
| 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | @Override |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3474 | public void toggleFreeformWindowingMode(IBinder token) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3475 | synchronized (mGlobalLock) { |
| 3476 | long ident = Binder.clearCallingIdentity(); |
| 3477 | try { |
| 3478 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3479 | if (r == null) { |
| 3480 | throw new IllegalArgumentException( |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3481 | "toggleFreeformWindowingMode: No activity record matching token=" |
| 3482 | + token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 3485 | final ActivityStack stack = r.getRootTask(); |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3486 | if (stack == null) { |
| 3487 | throw new IllegalStateException("toggleFreeformWindowingMode: the activity " |
| 3488 | + "doesn't have a stack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3489 | } |
| 3490 | |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3491 | if (!stack.inFreeformWindowingMode() |
| 3492 | && stack.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) { |
| 3493 | throw new IllegalStateException("toggleFreeformWindowingMode: You can only " |
| 3494 | + "toggle between fullscreen and freeform."); |
| 3495 | } |
| 3496 | |
| 3497 | if (stack.inFreeformWindowingMode()) { |
| 3498 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Evan Rosky | 3a8d7fe | 2019-11-06 17:08:35 -0800 | [diff] [blame] | 3499 | } else if (!mSizeCompatFreeform && r.inSizeCompatMode()) { |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 3500 | throw new IllegalStateException("Size-compat windows are currently not" |
| 3501 | + "freeform-enabled"); |
Yunfan Chen | e9c1c31 | 2019-04-18 14:49:15 +0900 | [diff] [blame] | 3502 | } else if (stack.getParent().inFreeformWindowingMode()) { |
| 3503 | // If the window is on a freeform display, set it to undefined. It will be |
| 3504 | // resolved to freeform and it can adjust windowing mode when the display mode |
| 3505 | // changes in runtime. |
| 3506 | stack.setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3507 | } else { |
| 3508 | stack.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 3509 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3510 | } finally { |
| 3511 | Binder.restoreCallingIdentity(ident); |
| 3512 | } |
| 3513 | } |
| 3514 | } |
| 3515 | |
| 3516 | /** Sets the task stack listener that gets callbacks when a task stack changes. */ |
| 3517 | @Override |
| 3518 | public void registerTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3519 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3520 | "registerTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3521 | mTaskChangeNotificationController.registerTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | /** Unregister a task stack listener so that it stops receiving callbacks. */ |
| 3525 | @Override |
| 3526 | public void unregisterTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3527 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3528 | "unregisterTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3529 | mTaskChangeNotificationController.unregisterTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3530 | } |
| 3531 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3532 | @Override |
| 3533 | public boolean requestAssistContextExtras(int requestType, IAssistDataReceiver receiver, |
| 3534 | Bundle receiverExtras, IBinder activityToken, boolean focused, boolean newSessionId) { |
| 3535 | return enqueueAssistContext(requestType, null, null, receiver, receiverExtras, |
| 3536 | activityToken, focused, newSessionId, UserHandle.getCallingUserId(), null, |
| 3537 | PENDING_ASSIST_EXTRAS_LONG_TIMEOUT, 0) != null; |
| 3538 | } |
| 3539 | |
| 3540 | @Override |
| 3541 | public boolean requestAutofillData(IAssistDataReceiver receiver, Bundle receiverExtras, |
| 3542 | IBinder activityToken, int flags) { |
| 3543 | return enqueueAssistContext(ActivityManager.ASSIST_CONTEXT_AUTOFILL, null, null, |
| 3544 | receiver, receiverExtras, activityToken, true, true, UserHandle.getCallingUserId(), |
| 3545 | null, PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT, flags) != null; |
| 3546 | } |
| 3547 | |
| 3548 | @Override |
| 3549 | public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle, |
| 3550 | Bundle args) { |
| 3551 | return enqueueAssistContext(requestType, intent, hint, null, null, null, |
| 3552 | true /* focused */, true /* newSessionId */, userHandle, args, |
| 3553 | PENDING_ASSIST_EXTRAS_TIMEOUT, 0) != null; |
| 3554 | } |
| 3555 | |
| 3556 | @Override |
| 3557 | public Bundle getAssistContextExtras(int requestType) { |
| 3558 | PendingAssistExtras pae = enqueueAssistContext(requestType, null, null, null, |
| 3559 | null, null, true /* focused */, true /* newSessionId */, |
| 3560 | UserHandle.getCallingUserId(), null, PENDING_ASSIST_EXTRAS_TIMEOUT, 0); |
| 3561 | if (pae == null) { |
| 3562 | return null; |
| 3563 | } |
| 3564 | synchronized (pae) { |
| 3565 | while (!pae.haveResult) { |
| 3566 | try { |
| 3567 | pae.wait(); |
| 3568 | } catch (InterruptedException e) { |
| 3569 | } |
| 3570 | } |
| 3571 | } |
| 3572 | synchronized (mGlobalLock) { |
| 3573 | buildAssistBundleLocked(pae, pae.result); |
| 3574 | mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3575 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3576 | } |
| 3577 | return pae.extras; |
| 3578 | } |
| 3579 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3580 | /** |
| 3581 | * Binder IPC calls go through the public entry point. |
| 3582 | * This can be called with or without the global lock held. |
| 3583 | */ |
| 3584 | private static int checkCallingPermission(String permission) { |
| 3585 | return checkPermission( |
| 3586 | permission, Binder.getCallingPid(), UserHandle.getAppId(Binder.getCallingUid())); |
| 3587 | } |
| 3588 | |
| 3589 | /** This can be called with or without the global lock held. */ |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3590 | private void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3591 | if (!getRecentTasks().isCallerRecents(Binder.getCallingUid())) { |
| 3592 | mAmInternal.enforceCallingPermission(permission, func); |
| 3593 | } |
| 3594 | } |
| 3595 | |
| 3596 | @VisibleForTesting |
| 3597 | int checkGetTasksPermission(String permission, int pid, int uid) { |
| 3598 | return checkPermission(permission, pid, uid); |
| 3599 | } |
| 3600 | |
| 3601 | static int checkPermission(String permission, int pid, int uid) { |
| 3602 | if (permission == null) { |
| 3603 | return PackageManager.PERMISSION_DENIED; |
| 3604 | } |
| 3605 | return checkComponentPermission(permission, pid, uid, -1, true); |
| 3606 | } |
| 3607 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3608 | public static int checkComponentPermission(String permission, int pid, int uid, |
| 3609 | int owningUid, boolean exported) { |
| 3610 | return ActivityManagerService.checkComponentPermission( |
| 3611 | permission, pid, uid, owningUid, exported); |
| 3612 | } |
| 3613 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3614 | boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 3615 | if (getRecentTasks().isCallerRecents(callingUid)) { |
| 3616 | // Always allow the recents component to get tasks |
| 3617 | return true; |
| 3618 | } |
| 3619 | |
| 3620 | boolean allowed = checkGetTasksPermission(android.Manifest.permission.REAL_GET_TASKS, |
| 3621 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED; |
| 3622 | if (!allowed) { |
| 3623 | if (checkGetTasksPermission(android.Manifest.permission.GET_TASKS, |
| 3624 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED) { |
| 3625 | // Temporary compatibility: some existing apps on the system image may |
| 3626 | // still be requesting the old permission and not switched to the new |
| 3627 | // one; if so, we'll still allow them full access. This means we need |
| 3628 | // to see if they are holding the old permission and are a system app. |
| 3629 | try { |
| 3630 | if (AppGlobals.getPackageManager().isUidPrivileged(callingUid)) { |
| 3631 | allowed = true; |
| 3632 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3633 | + " is using old GET_TASKS but privileged; allowing"); |
| 3634 | } |
| 3635 | } catch (RemoteException e) { |
| 3636 | } |
| 3637 | } |
| 3638 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3639 | + " does not hold REAL_GET_TASKS; limiting output"); |
| 3640 | } |
| 3641 | return allowed; |
| 3642 | } |
| 3643 | |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 3644 | boolean isCrossUserAllowed(int pid, int uid) { |
| 3645 | return checkPermission(INTERACT_ACROSS_USERS, pid, uid) == PERMISSION_GRANTED |
| 3646 | || checkPermission(INTERACT_ACROSS_USERS_FULL, pid, uid) == PERMISSION_GRANTED; |
| 3647 | } |
| 3648 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3649 | private PendingAssistExtras enqueueAssistContext(int requestType, Intent intent, String hint, |
| 3650 | IAssistDataReceiver receiver, Bundle receiverExtras, IBinder activityToken, |
| 3651 | boolean focused, boolean newSessionId, int userHandle, Bundle args, long timeout, |
| 3652 | int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3653 | mAmInternal.enforceCallingPermission(android.Manifest.permission.GET_TOP_ACTIVITY_INFO, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3654 | "enqueueAssistContext()"); |
| 3655 | |
| 3656 | synchronized (mGlobalLock) { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 3657 | final ActivityStack stack = getTopDisplayFocusedStack(); |
| 3658 | ActivityRecord activity = stack != null ? stack.getTopNonFinishingActivity() : null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3659 | if (activity == null) { |
| 3660 | Slog.w(TAG, "getAssistContextExtras failed: no top activity"); |
| 3661 | return null; |
| 3662 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3663 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3664 | Slog.w(TAG, "getAssistContextExtras failed: no process for " + activity); |
| 3665 | return null; |
| 3666 | } |
| 3667 | if (focused) { |
| 3668 | if (activityToken != null) { |
| 3669 | ActivityRecord caller = ActivityRecord.forTokenLocked(activityToken); |
| 3670 | if (activity != caller) { |
| 3671 | Slog.w(TAG, "enqueueAssistContext failed: caller " + caller |
| 3672 | + " is not current top " + activity); |
| 3673 | return null; |
| 3674 | } |
| 3675 | } |
| 3676 | } else { |
| 3677 | activity = ActivityRecord.forTokenLocked(activityToken); |
| 3678 | if (activity == null) { |
| 3679 | Slog.w(TAG, "enqueueAssistContext failed: activity for token=" + activityToken |
| 3680 | + " couldn't be found"); |
| 3681 | return null; |
| 3682 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3683 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3684 | Slog.w(TAG, "enqueueAssistContext failed: no process for " + activity); |
| 3685 | return null; |
| 3686 | } |
| 3687 | } |
| 3688 | |
| 3689 | PendingAssistExtras pae; |
| 3690 | Bundle extras = new Bundle(); |
| 3691 | if (args != null) { |
| 3692 | extras.putAll(args); |
| 3693 | } |
| 3694 | extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3695 | extras.putInt(Intent.EXTRA_ASSIST_UID, activity.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3696 | |
| 3697 | pae = new PendingAssistExtras(activity, extras, intent, hint, receiver, receiverExtras, |
| 3698 | userHandle); |
| 3699 | pae.isHome = activity.isActivityTypeHome(); |
| 3700 | |
| 3701 | // Increment the sessionId if necessary |
| 3702 | if (newSessionId) { |
| 3703 | mViSessionId++; |
| 3704 | } |
| 3705 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3706 | activity.app.getThread().requestAssistContextExtras(activity.appToken, pae, |
| 3707 | requestType, mViSessionId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3708 | mPendingAssistExtras.add(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3709 | mUiHandler.postDelayed(pae, timeout); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3710 | } catch (RemoteException e) { |
| 3711 | Slog.w(TAG, "getAssistContextExtras failed: crash calling " + activity); |
| 3712 | return null; |
| 3713 | } |
| 3714 | return pae; |
| 3715 | } |
| 3716 | } |
| 3717 | |
| 3718 | private void buildAssistBundleLocked(PendingAssistExtras pae, Bundle result) { |
| 3719 | if (result != null) { |
| 3720 | pae.extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, result); |
| 3721 | } |
| 3722 | if (pae.hint != null) { |
| 3723 | pae.extras.putBoolean(pae.hint, true); |
| 3724 | } |
| 3725 | } |
| 3726 | |
| 3727 | private void pendingAssistExtrasTimedOut(PendingAssistExtras pae) { |
| 3728 | IAssistDataReceiver receiver; |
| 3729 | synchronized (mGlobalLock) { |
| 3730 | mPendingAssistExtras.remove(pae); |
| 3731 | receiver = pae.receiver; |
| 3732 | } |
| 3733 | if (receiver != null) { |
| 3734 | // Caller wants result sent back to them. |
| 3735 | Bundle sendBundle = new Bundle(); |
| 3736 | // At least return the receiver extras |
| 3737 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3738 | try { |
| 3739 | pae.receiver.onHandleAssistData(sendBundle); |
| 3740 | } catch (RemoteException e) { |
| 3741 | } |
| 3742 | } |
| 3743 | } |
| 3744 | |
| 3745 | public class PendingAssistExtras extends Binder implements Runnable { |
| 3746 | public final ActivityRecord activity; |
| 3747 | public boolean isHome; |
| 3748 | public final Bundle extras; |
| 3749 | public final Intent intent; |
| 3750 | public final String hint; |
| 3751 | public final IAssistDataReceiver receiver; |
| 3752 | public final int userHandle; |
| 3753 | public boolean haveResult = false; |
| 3754 | public Bundle result = null; |
| 3755 | public AssistStructure structure = null; |
| 3756 | public AssistContent content = null; |
| 3757 | public Bundle receiverExtras; |
| 3758 | |
| 3759 | public PendingAssistExtras(ActivityRecord _activity, Bundle _extras, Intent _intent, |
| 3760 | String _hint, IAssistDataReceiver _receiver, Bundle _receiverExtras, |
| 3761 | int _userHandle) { |
| 3762 | activity = _activity; |
| 3763 | extras = _extras; |
| 3764 | intent = _intent; |
| 3765 | hint = _hint; |
| 3766 | receiver = _receiver; |
| 3767 | receiverExtras = _receiverExtras; |
| 3768 | userHandle = _userHandle; |
| 3769 | } |
| 3770 | |
| 3771 | @Override |
| 3772 | public void run() { |
| 3773 | Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from " + activity); |
| 3774 | synchronized (this) { |
| 3775 | haveResult = true; |
| 3776 | notifyAll(); |
| 3777 | } |
| 3778 | pendingAssistExtrasTimedOut(this); |
| 3779 | } |
| 3780 | } |
| 3781 | |
| 3782 | @Override |
| 3783 | public boolean isAssistDataAllowedOnCurrentActivity() { |
| 3784 | int userId; |
| 3785 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3786 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3787 | if (focusedStack == null || focusedStack.isActivityTypeAssistant()) { |
| 3788 | return false; |
| 3789 | } |
| 3790 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3791 | final ActivityRecord activity = focusedStack.getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3792 | if (activity == null) { |
| 3793 | return false; |
| 3794 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3795 | userId = activity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3796 | } |
| 3797 | return !DevicePolicyCache.getInstance().getScreenCaptureDisabled(userId); |
| 3798 | } |
| 3799 | |
| 3800 | @Override |
| 3801 | public boolean showAssistFromActivity(IBinder token, Bundle args) { |
| 3802 | long ident = Binder.clearCallingIdentity(); |
| 3803 | try { |
| 3804 | synchronized (mGlobalLock) { |
| 3805 | ActivityRecord caller = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3806 | ActivityRecord top = getTopDisplayFocusedStack().getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3807 | if (top != caller) { |
| 3808 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3809 | + " is not current top " + top); |
| 3810 | return false; |
| 3811 | } |
| 3812 | if (!top.nowVisible) { |
| 3813 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3814 | + " is not visible"); |
| 3815 | return false; |
| 3816 | } |
| 3817 | } |
| 3818 | return mAssistUtils.showSessionForActiveService(args, SHOW_SOURCE_APPLICATION, null, |
| 3819 | token); |
| 3820 | } finally { |
| 3821 | Binder.restoreCallingIdentity(ident); |
| 3822 | } |
| 3823 | } |
| 3824 | |
| 3825 | @Override |
| 3826 | public boolean isRootVoiceInteraction(IBinder token) { |
| 3827 | synchronized (mGlobalLock) { |
| 3828 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3829 | if (r == null) { |
| 3830 | return false; |
| 3831 | } |
| 3832 | return r.rootVoiceInteraction; |
| 3833 | } |
| 3834 | } |
| 3835 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3836 | private void onLocalVoiceInteractionStartedLocked(IBinder activity, |
| 3837 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 3838 | ActivityRecord activityToCallback = ActivityRecord.forTokenLocked(activity); |
| 3839 | if (activityToCallback == null) return; |
| 3840 | activityToCallback.setVoiceSessionLocked(voiceSession); |
| 3841 | |
| 3842 | // Inform the activity |
| 3843 | try { |
| 3844 | activityToCallback.app.getThread().scheduleLocalVoiceInteractionStarted(activity, |
| 3845 | voiceInteractor); |
| 3846 | long token = Binder.clearCallingIdentity(); |
| 3847 | try { |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 3848 | startRunningVoiceLocked(voiceSession, activityToCallback.info.applicationInfo.uid); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3849 | } finally { |
| 3850 | Binder.restoreCallingIdentity(token); |
| 3851 | } |
| 3852 | // TODO: VI Should we cache the activity so that it's easier to find later |
| 3853 | // rather than scan through all the stacks and activities? |
| 3854 | } catch (RemoteException re) { |
| 3855 | activityToCallback.clearVoiceSessionLocked(); |
| 3856 | // TODO: VI Should this terminate the voice session? |
| 3857 | } |
| 3858 | } |
| 3859 | |
| 3860 | private void startRunningVoiceLocked(IVoiceInteractionSession session, int targetUid) { |
| 3861 | Slog.d(TAG, "<<< startRunningVoiceLocked()"); |
| 3862 | mVoiceWakeLock.setWorkSource(new WorkSource(targetUid)); |
| 3863 | if (mRunningVoice == null || mRunningVoice.asBinder() != session.asBinder()) { |
| 3864 | boolean wasRunningVoice = mRunningVoice != null; |
| 3865 | mRunningVoice = session; |
| 3866 | if (!wasRunningVoice) { |
| 3867 | mVoiceWakeLock.acquire(); |
| 3868 | updateSleepIfNeededLocked(); |
| 3869 | } |
| 3870 | } |
| 3871 | } |
| 3872 | |
| 3873 | void finishRunningVoiceLocked() { |
| 3874 | if (mRunningVoice != null) { |
| 3875 | mRunningVoice = null; |
| 3876 | mVoiceWakeLock.release(); |
| 3877 | updateSleepIfNeededLocked(); |
| 3878 | } |
| 3879 | } |
| 3880 | |
| 3881 | @Override |
| 3882 | public void setVoiceKeepAwake(IVoiceInteractionSession session, boolean keepAwake) { |
| 3883 | synchronized (mGlobalLock) { |
| 3884 | if (mRunningVoice != null && mRunningVoice.asBinder() == session.asBinder()) { |
| 3885 | if (keepAwake) { |
| 3886 | mVoiceWakeLock.acquire(); |
| 3887 | } else { |
| 3888 | mVoiceWakeLock.release(); |
| 3889 | } |
| 3890 | } |
| 3891 | } |
| 3892 | } |
| 3893 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3894 | @Override |
| 3895 | public ComponentName getActivityClassForToken(IBinder token) { |
| 3896 | synchronized (mGlobalLock) { |
| 3897 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3898 | if (r == null) { |
| 3899 | return null; |
| 3900 | } |
| 3901 | return r.intent.getComponent(); |
| 3902 | } |
| 3903 | } |
| 3904 | |
| 3905 | @Override |
| 3906 | public String getPackageForToken(IBinder token) { |
| 3907 | synchronized (mGlobalLock) { |
| 3908 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3909 | if (r == null) { |
| 3910 | return null; |
| 3911 | } |
| 3912 | return r.packageName; |
| 3913 | } |
| 3914 | } |
| 3915 | |
| 3916 | @Override |
| 3917 | public void showLockTaskEscapeMessage(IBinder token) { |
| 3918 | synchronized (mGlobalLock) { |
| 3919 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3920 | if (r == null) { |
| 3921 | return; |
| 3922 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3923 | getLockTaskController().showLockTaskToast(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3924 | } |
| 3925 | } |
| 3926 | |
| 3927 | @Override |
| 3928 | public void keyguardGoingAway(int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3929 | enforceNotIsolatedCaller("keyguardGoingAway"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3930 | final long token = Binder.clearCallingIdentity(); |
| 3931 | try { |
| 3932 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3933 | mKeyguardController.keyguardGoingAway(flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3934 | } |
| 3935 | } finally { |
| 3936 | Binder.restoreCallingIdentity(token); |
| 3937 | } |
| 3938 | } |
| 3939 | |
| 3940 | /** |
| 3941 | * Try to place task to provided position. The final position might be different depending on |
| 3942 | * current user and stacks state. The task will be moved to target stack if it's currently in |
| 3943 | * different stack. |
| 3944 | */ |
| 3945 | @Override |
| 3946 | public void positionTaskInStack(int taskId, int stackId, int position) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3947 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "positionTaskInStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3948 | synchronized (mGlobalLock) { |
| 3949 | long ident = Binder.clearCallingIdentity(); |
| 3950 | try { |
| 3951 | if (DEBUG_STACK) Slog.d(TAG_STACK, "positionTaskInStack: positioning task=" |
| 3952 | + taskId + " in stackId=" + stackId + " at position=" + position); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3953 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3954 | if (task == null) { |
| 3955 | throw new IllegalArgumentException("positionTaskInStack: no task for id=" |
| 3956 | + taskId); |
| 3957 | } |
| 3958 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3959 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3960 | |
| 3961 | if (stack == null) { |
| 3962 | throw new IllegalArgumentException("positionTaskInStack: no stack for id=" |
| 3963 | + stackId); |
| 3964 | } |
| 3965 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3966 | throw new IllegalArgumentException("positionTaskInStack: Attempt to change" |
| 3967 | + " the position of task " + taskId + " in/to non-standard stack"); |
| 3968 | } |
| 3969 | |
| 3970 | // TODO: Have the callers of this API call a separate reparent method if that is |
| 3971 | // what they intended to do vs. having this method also do reparenting. |
| 3972 | if (task.getStack() == stack) { |
| 3973 | // Change position in current stack. |
| 3974 | stack.positionChildAt(task, position); |
| 3975 | } else { |
| 3976 | // Reparent to new stack. |
| 3977 | task.reparent(stack, position, REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, |
| 3978 | !DEFER_RESUME, "positionTaskInStack"); |
| 3979 | } |
| 3980 | } finally { |
| 3981 | Binder.restoreCallingIdentity(ident); |
| 3982 | } |
| 3983 | } |
| 3984 | } |
| 3985 | |
| 3986 | @Override |
| 3987 | public void reportSizeConfigurations(IBinder token, int[] horizontalSizeConfiguration, |
| 3988 | int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { |
| 3989 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Report configuration: " + token + " " |
Yuichiro Hanada | e7e930b | 2019-06-06 19:07:21 +0900 | [diff] [blame] | 3990 | + Arrays.toString(horizontalSizeConfiguration) + " " |
| 3991 | + Arrays.toString(verticalSizeConfigurations)); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3992 | synchronized (mGlobalLock) { |
| 3993 | ActivityRecord record = ActivityRecord.isInStackLocked(token); |
| 3994 | if (record == null) { |
| 3995 | throw new IllegalArgumentException("reportSizeConfigurations: ActivityRecord not " |
| 3996 | + "found for: " + token); |
| 3997 | } |
| 3998 | record.setSizeConfigurations(horizontalSizeConfiguration, |
| 3999 | verticalSizeConfigurations, smallestSizeConfigurations); |
| 4000 | } |
| 4001 | } |
| 4002 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4003 | @Override |
| 4004 | public void suppressResizeConfigChanges(boolean suppress) throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4005 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "suppressResizeConfigChanges()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4006 | synchronized (mGlobalLock) { |
| 4007 | mSuppressResizeConfigChanges = suppress; |
| 4008 | } |
| 4009 | } |
| 4010 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4011 | /** |
| 4012 | * Moves the top activity in the input stackId to the pinned stack. |
| 4013 | * |
| 4014 | * @param stackId Id of stack to move the top activity to pinned stack. |
| 4015 | * @param bounds Bounds to use for pinned stack. |
| 4016 | * |
| 4017 | * @return True if the top activity of the input stack was successfully moved to the pinned |
| 4018 | * stack. |
| 4019 | */ |
| 4020 | @Override |
| 4021 | public boolean moveTopActivityToPinnedStack(int stackId, Rect bounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4022 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4023 | "moveTopActivityToPinnedStack()"); |
| 4024 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4025 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4026 | throw new IllegalStateException("moveTopActivityToPinnedStack:" |
| 4027 | + "Device doesn't support picture-in-picture mode"); |
| 4028 | } |
| 4029 | |
| 4030 | long ident = Binder.clearCallingIdentity(); |
| 4031 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4032 | return mRootWindowContainer.moveTopStackActivityToPinnedStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4033 | } finally { |
| 4034 | Binder.restoreCallingIdentity(ident); |
| 4035 | } |
| 4036 | } |
| 4037 | } |
| 4038 | |
Hongwei Wang | 5711b8f | 2019-11-15 15:44:12 -0800 | [diff] [blame] | 4039 | @VisibleForTesting |
| 4040 | boolean isInPictureInPictureMode(ActivityRecord r) { |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 4041 | return r != null |
| 4042 | && r.getRootTask() != null |
| 4043 | && r.inPinnedWindowingMode() |
Wale Ogunwale | 0db64ac | 2020-04-11 10:00:42 -0700 | [diff] [blame] | 4044 | && r.getRootTask().isInTask(r) != null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | @Override |
| 4048 | public boolean enterPictureInPictureMode(IBinder token, final PictureInPictureParams params) { |
| 4049 | final long origId = Binder.clearCallingIdentity(); |
| 4050 | try { |
| 4051 | synchronized (mGlobalLock) { |
| 4052 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 4053 | "enterPictureInPictureMode", token, params); |
| 4054 | |
| 4055 | // If the activity is already in picture in picture mode, then just return early |
| 4056 | if (isInPictureInPictureMode(r)) { |
| 4057 | return true; |
| 4058 | } |
| 4059 | |
| 4060 | // Activity supports picture-in-picture, now check that we can enter PiP at this |
| 4061 | // point, if it is |
| 4062 | if (!r.checkEnterPictureInPictureState("enterPictureInPictureMode", |
| 4063 | false /* beforeStopping */)) { |
| 4064 | return false; |
| 4065 | } |
| 4066 | |
| 4067 | final Runnable enterPipRunnable = () -> { |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4068 | synchronized (mGlobalLock) { |
Hyangseok Chae | ed0624e | 2019-11-07 10:15:46 +0900 | [diff] [blame] | 4069 | if (r.getParent() == null) { |
| 4070 | Slog.e(TAG, "Skip enterPictureInPictureMode, destroyed " + r); |
| 4071 | return; |
| 4072 | } |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4073 | // Only update the saved args from the args that are set |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 4074 | r.setPictureInPictureParams(params); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4075 | final float aspectRatio = r.pictureInPictureArgs.getAspectRatio(); |
| 4076 | final List<RemoteAction> actions = r.pictureInPictureArgs.getActions(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4077 | mRootWindowContainer.moveActivityToPinnedStack( |
Hongwei Wang | e8e3286 | 2020-04-08 13:23:45 -0700 | [diff] [blame] | 4078 | r, "enterPictureInPictureMode"); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 4079 | final ActivityStack stack = r.getRootTask(); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4080 | stack.setPictureInPictureAspectRatio(aspectRatio); |
| 4081 | stack.setPictureInPictureActions(actions); |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 4082 | MetricsLoggerWrapper.logPictureInPictureEnter(mContext, |
| 4083 | r.info.applicationInfo.uid, r.shortComponentName, |
| 4084 | r.supportsEnterPipOnTaskSwitch); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4085 | logPictureInPictureArgs(params); |
| 4086 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4087 | }; |
| 4088 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4089 | if (isKeyguardLocked()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4090 | // If the keyguard is showing or occluded, then try and dismiss it before |
| 4091 | // entering picture-in-picture (this will prompt the user to authenticate if the |
| 4092 | // device is currently locked). |
| 4093 | dismissKeyguard(token, new KeyguardDismissCallback() { |
| 4094 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4095 | public void onDismissSucceeded() { |
| 4096 | mH.post(enterPipRunnable); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4097 | } |
| 4098 | }, null /* message */); |
| 4099 | } else { |
| 4100 | // Enter picture in picture immediately otherwise |
| 4101 | enterPipRunnable.run(); |
| 4102 | } |
| 4103 | return true; |
| 4104 | } |
| 4105 | } finally { |
| 4106 | Binder.restoreCallingIdentity(origId); |
| 4107 | } |
| 4108 | } |
| 4109 | |
| 4110 | @Override |
| 4111 | public void setPictureInPictureParams(IBinder token, final PictureInPictureParams params) { |
| 4112 | final long origId = Binder.clearCallingIdentity(); |
| 4113 | try { |
| 4114 | synchronized (mGlobalLock) { |
| 4115 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 4116 | "setPictureInPictureParams", token, params); |
| 4117 | |
| 4118 | // Only update the saved args from the args that are set |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 4119 | r.setPictureInPictureParams(params); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4120 | if (r.inPinnedWindowingMode()) { |
| 4121 | // If the activity is already in picture-in-picture, update the pinned stack now |
| 4122 | // if it is not already expanding to fullscreen. Otherwise, the arguments will |
| 4123 | // be used the next time the activity enters PiP |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 4124 | final ActivityStack stack = r.getRootTask(); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 4125 | stack.setPictureInPictureAspectRatio( |
| 4126 | r.pictureInPictureArgs.getAspectRatio()); |
| 4127 | stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4128 | } |
| 4129 | logPictureInPictureArgs(params); |
| 4130 | } |
| 4131 | } finally { |
| 4132 | Binder.restoreCallingIdentity(origId); |
| 4133 | } |
| 4134 | } |
| 4135 | |
| 4136 | @Override |
| 4137 | public int getMaxNumPictureInPictureActions(IBinder token) { |
| 4138 | // Currently, this is a static constant, but later, we may change this to be dependent on |
| 4139 | // the context of the activity |
| 4140 | return 3; |
| 4141 | } |
| 4142 | |
| 4143 | private void logPictureInPictureArgs(PictureInPictureParams params) { |
| 4144 | if (params.hasSetActions()) { |
| 4145 | MetricsLogger.histogram(mContext, "tron_varz_picture_in_picture_actions_count", |
| 4146 | params.getActions().size()); |
| 4147 | } |
| 4148 | if (params.hasSetAspectRatio()) { |
| 4149 | LogMaker lm = new LogMaker(MetricsEvent.ACTION_PICTURE_IN_PICTURE_ASPECT_RATIO_CHANGED); |
| 4150 | lm.addTaggedData(MetricsEvent.PICTURE_IN_PICTURE_ASPECT_RATIO, params.getAspectRatio()); |
| 4151 | MetricsLogger.action(lm); |
| 4152 | } |
| 4153 | } |
| 4154 | |
| 4155 | /** |
| 4156 | * Checks the state of the system and the activity associated with the given {@param token} to |
| 4157 | * verify that picture-in-picture is supported for that activity. |
| 4158 | * |
| 4159 | * @return the activity record for the given {@param token} if all the checks pass. |
| 4160 | */ |
| 4161 | private ActivityRecord ensureValidPictureInPictureActivityParamsLocked(String caller, |
| 4162 | IBinder token, PictureInPictureParams params) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4163 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4164 | throw new IllegalStateException(caller |
| 4165 | + ": Device doesn't support picture-in-picture mode."); |
| 4166 | } |
| 4167 | |
| 4168 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 4169 | if (r == null) { |
| 4170 | throw new IllegalStateException(caller |
| 4171 | + ": Can't find activity for token=" + token); |
| 4172 | } |
| 4173 | |
| 4174 | if (!r.supportsPictureInPicture()) { |
| 4175 | throw new IllegalStateException(caller |
| 4176 | + ": Current activity does not support picture-in-picture."); |
| 4177 | } |
| 4178 | |
| 4179 | if (params.hasSetAspectRatio() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4180 | && !mWindowManager.isValidPictureInPictureAspectRatio( |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 4181 | r.getDisplay(), params.getAspectRatio())) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4182 | final float minAspectRatio = mContext.getResources().getFloat( |
| 4183 | com.android.internal.R.dimen.config_pictureInPictureMinAspectRatio); |
| 4184 | final float maxAspectRatio = mContext.getResources().getFloat( |
| 4185 | com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio); |
| 4186 | throw new IllegalArgumentException(String.format(caller |
| 4187 | + ": Aspect ratio is too extreme (must be between %f and %f).", |
| 4188 | minAspectRatio, maxAspectRatio)); |
| 4189 | } |
| 4190 | |
| 4191 | // Truncate the number of actions if necessary |
| 4192 | params.truncateActions(getMaxNumPictureInPictureActions(token)); |
| 4193 | |
| 4194 | return r; |
| 4195 | } |
| 4196 | |
| 4197 | @Override |
| 4198 | public IBinder getUriPermissionOwnerForActivity(IBinder activityToken) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4199 | enforceNotIsolatedCaller("getUriPermissionOwnerForActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4200 | synchronized (mGlobalLock) { |
| 4201 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 4202 | if (r == null) { |
| 4203 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 4204 | + activityToken); |
| 4205 | } |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 4206 | return r.getUriPermissionsLocked().getExternalToken(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4207 | } |
| 4208 | } |
| 4209 | |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 4210 | // TODO(b/149338177): remove when CTS no-longer requires it |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4211 | @Override |
| 4212 | public void resizeDockedStack(Rect dockedBounds, Rect tempDockedTaskBounds, |
| 4213 | Rect tempDockedTaskInsetBounds, |
| 4214 | Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4215 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeDockedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4216 | long ident = Binder.clearCallingIdentity(); |
| 4217 | try { |
| 4218 | synchronized (mGlobalLock) { |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 4219 | final TaskDisplayArea tc = mRootWindowContainer.getDefaultTaskDisplayArea(); |
| 4220 | final Task primary = tc.getRootSplitScreenPrimaryTask(); |
| 4221 | final Task secondary = tc.getTask(t -> t.mCreatedByOrganizer && t.isRootTask() |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 4222 | && t.inSplitScreenSecondaryWindowingMode()); |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 4223 | if (primary == null || secondary == null) { |
| 4224 | return; |
| 4225 | } |
| 4226 | final WindowContainerTransaction wct = new WindowContainerTransaction(); |
| 4227 | final Rect primaryRect = |
| 4228 | tempDockedTaskInsetBounds != null ? tempDockedTaskInsetBounds |
| 4229 | : (tempDockedTaskBounds != null ? tempDockedTaskBounds |
| 4230 | : dockedBounds); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 4231 | wct.setBounds(primary.mRemoteToken.toWindowContainerToken(), primaryRect); |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 4232 | Rect otherRect = tempOtherTaskInsetBounds != null ? tempOtherTaskInsetBounds |
| 4233 | : tempOtherTaskBounds; |
| 4234 | if (otherRect == null) { |
| 4235 | // Temporary estimation... again this is just for tests. |
| 4236 | otherRect = new Rect(secondary.getBounds()); |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 4237 | if (tc.getBounds().width() > tc.getBounds().height()) { |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 4238 | otherRect.left = primaryRect.right + 6; |
| 4239 | } else { |
| 4240 | otherRect.top = primaryRect.bottom + 6; |
| 4241 | } |
| 4242 | } |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 4243 | wct.setBounds(secondary.mRemoteToken.toWindowContainerToken(), otherRect); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 4244 | mWindowOrganizerController.applyTransaction(wct); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4245 | } |
| 4246 | } finally { |
| 4247 | Binder.restoreCallingIdentity(ident); |
| 4248 | } |
| 4249 | } |
| 4250 | |
| 4251 | @Override |
| 4252 | public void setSplitScreenResizing(boolean resizing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4253 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setSplitScreenResizing()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4254 | final long ident = Binder.clearCallingIdentity(); |
| 4255 | try { |
| 4256 | synchronized (mGlobalLock) { |
| 4257 | mStackSupervisor.setSplitScreenResizing(resizing); |
| 4258 | } |
| 4259 | } finally { |
| 4260 | Binder.restoreCallingIdentity(ident); |
| 4261 | } |
| 4262 | } |
| 4263 | |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 4264 | @Override |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 4265 | public IWindowOrganizerController getWindowOrganizerController() { |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 4266 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 4267 | "getWindowOrganizerController()"); |
| 4268 | return mWindowOrganizerController; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 4269 | } |
| 4270 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4271 | /** |
| 4272 | * Check that we have the features required for VR-related API calls, and throw an exception if |
| 4273 | * not. |
| 4274 | */ |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 4275 | public void enforceSystemHasVrFeature() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4276 | if (!mContext.getPackageManager().hasSystemFeature( |
| 4277 | PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE)) { |
| 4278 | throw new UnsupportedOperationException("VR mode not supported on this device!"); |
| 4279 | } |
| 4280 | } |
| 4281 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4282 | @Override |
| 4283 | public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4284 | enforceSystemHasVrFeature(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4285 | |
| 4286 | final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class); |
| 4287 | |
| 4288 | ActivityRecord r; |
| 4289 | synchronized (mGlobalLock) { |
| 4290 | r = ActivityRecord.isInStackLocked(token); |
| 4291 | } |
| 4292 | |
| 4293 | if (r == null) { |
| 4294 | throw new IllegalArgumentException(); |
| 4295 | } |
| 4296 | |
| 4297 | int err; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4298 | if ((err = vrService.hasVrPackage(packageName, r.mUserId)) != |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4299 | VrManagerInternal.NO_ERROR) { |
| 4300 | return err; |
| 4301 | } |
| 4302 | |
| 4303 | // Clear the binder calling uid since this path may call moveToTask(). |
| 4304 | final long callingId = Binder.clearCallingIdentity(); |
| 4305 | try { |
| 4306 | synchronized (mGlobalLock) { |
| 4307 | r.requestedVrComponent = (enabled) ? packageName : null; |
| 4308 | |
| 4309 | // Update associated state if this activity is currently focused |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 4310 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4311 | applyUpdateVrModeLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4312 | } |
| 4313 | return 0; |
| 4314 | } |
| 4315 | } finally { |
| 4316 | Binder.restoreCallingIdentity(callingId); |
| 4317 | } |
| 4318 | } |
| 4319 | |
| 4320 | @Override |
| 4321 | public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) { |
| 4322 | Slog.i(TAG, "Activity tried to startLocalVoiceInteraction"); |
| 4323 | synchronized (mGlobalLock) { |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 4324 | ActivityRecord activity = getTopDisplayFocusedStack().getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4325 | if (ActivityRecord.forTokenLocked(callingActivity) != activity) { |
| 4326 | throw new SecurityException("Only focused activity can call startVoiceInteraction"); |
| 4327 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4328 | if (mRunningVoice != null || activity.getTask().voiceSession != null |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4329 | || activity.voiceSession != null) { |
| 4330 | Slog.w(TAG, "Already in a voice interaction, cannot start new voice interaction"); |
| 4331 | return; |
| 4332 | } |
| 4333 | if (activity.pendingVoiceInteractionStart) { |
| 4334 | Slog.w(TAG, "Pending start of voice interaction already."); |
| 4335 | return; |
| 4336 | } |
| 4337 | activity.pendingVoiceInteractionStart = true; |
| 4338 | } |
| 4339 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4340 | .startLocalVoiceInteraction(callingActivity, options); |
| 4341 | } |
| 4342 | |
| 4343 | @Override |
| 4344 | public void stopLocalVoiceInteraction(IBinder callingActivity) { |
| 4345 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4346 | .stopLocalVoiceInteraction(callingActivity); |
| 4347 | } |
| 4348 | |
| 4349 | @Override |
| 4350 | public boolean supportsLocalVoiceInteraction() { |
| 4351 | return LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4352 | .supportsLocalVoiceInteraction(); |
| 4353 | } |
| 4354 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4355 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4356 | public boolean updateConfiguration(Configuration values) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4357 | mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateConfiguration()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4358 | |
| 4359 | synchronized (mGlobalLock) { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 4360 | if (mWindowManager == null) { |
| 4361 | Slog.w(TAG, "Skip updateConfiguration because mWindowManager isn't set"); |
| 4362 | return false; |
| 4363 | } |
| 4364 | |
| 4365 | if (values == null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4366 | // sentinel: fetch the current configuration from the window manager |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4367 | values = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4368 | } |
| 4369 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 4370 | mH.sendMessage(PooledLambda.obtainMessage( |
| 4371 | ActivityManagerInternal::updateOomLevelsForDisplay, mAmInternal, |
| 4372 | DEFAULT_DISPLAY)); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4373 | |
| 4374 | final long origId = Binder.clearCallingIdentity(); |
| 4375 | try { |
| 4376 | if (values != null) { |
| 4377 | Settings.System.clearConfiguration(values); |
| 4378 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4379 | updateConfigurationLocked(values, null, false, false /* persistent */, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4380 | UserHandle.USER_NULL, false /* deferResume */, |
| 4381 | mTmpUpdateConfigurationResult); |
| 4382 | return mTmpUpdateConfigurationResult.changes != 0; |
| 4383 | } finally { |
| 4384 | Binder.restoreCallingIdentity(origId); |
| 4385 | } |
| 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | @Override |
| 4390 | public void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback, |
| 4391 | CharSequence message) { |
| 4392 | if (message != null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4393 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4394 | Manifest.permission.SHOW_KEYGUARD_MESSAGE, "dismissKeyguard()"); |
| 4395 | } |
| 4396 | final long callingId = Binder.clearCallingIdentity(); |
| 4397 | try { |
| 4398 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4399 | mKeyguardController.dismissKeyguard(token, callback, message); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4400 | } |
| 4401 | } finally { |
| 4402 | Binder.restoreCallingIdentity(callingId); |
| 4403 | } |
| 4404 | } |
| 4405 | |
| 4406 | @Override |
| 4407 | public void cancelTaskWindowTransition(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4408 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4409 | "cancelTaskWindowTransition()"); |
| 4410 | final long ident = Binder.clearCallingIdentity(); |
| 4411 | try { |
| 4412 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4413 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4414 | MATCH_TASK_IN_STACKS_ONLY); |
| 4415 | if (task == null) { |
| 4416 | Slog.w(TAG, "cancelTaskWindowTransition: taskId=" + taskId + " not found"); |
| 4417 | return; |
| 4418 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 4419 | task.cancelTaskWindowTransition(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4420 | } |
| 4421 | } finally { |
| 4422 | Binder.restoreCallingIdentity(ident); |
| 4423 | } |
| 4424 | } |
| 4425 | |
| 4426 | @Override |
Peter Kalauskas | 4dc0460 | 2020-02-12 18:49:03 -0800 | [diff] [blame] | 4427 | public ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4428 | enforceCallerIsRecentsOrHasPermission(READ_FRAME_BUFFER, "getTaskSnapshot()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4429 | final long ident = Binder.clearCallingIdentity(); |
| 4430 | try { |
Peter Kalauskas | 4dc0460 | 2020-02-12 18:49:03 -0800 | [diff] [blame] | 4431 | return getTaskSnapshot(taskId, isLowResolution, true /* restoreFromDisk */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4432 | } finally { |
| 4433 | Binder.restoreCallingIdentity(ident); |
| 4434 | } |
| 4435 | } |
| 4436 | |
Peter Kalauskas | 4dc0460 | 2020-02-12 18:49:03 -0800 | [diff] [blame] | 4437 | private ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution, |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4438 | boolean restoreFromDisk) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4439 | final Task task; |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4440 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4441 | task = mRootWindowContainer.anyTaskForId(taskId, |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4442 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 4443 | if (task == null) { |
| 4444 | Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found"); |
| 4445 | return null; |
| 4446 | } |
| 4447 | } |
| 4448 | // 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] | 4449 | return task.getSnapshot(isLowResolution, restoreFromDisk); |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4450 | } |
| 4451 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4452 | @Override |
| 4453 | public void setDisablePreviewScreenshots(IBinder token, boolean disable) { |
| 4454 | synchronized (mGlobalLock) { |
| 4455 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4456 | if (r == null) { |
| 4457 | Slog.w(TAG, "setDisablePreviewScreenshots: Unable to find activity for token=" |
| 4458 | + token); |
| 4459 | return; |
| 4460 | } |
| 4461 | final long origId = Binder.clearCallingIdentity(); |
| 4462 | try { |
| 4463 | r.setDisablePreviewScreenshots(disable); |
| 4464 | } finally { |
| 4465 | Binder.restoreCallingIdentity(origId); |
| 4466 | } |
| 4467 | } |
| 4468 | } |
| 4469 | |
Riddle Hsu | 440f88b | 2019-11-06 22:17:35 +0800 | [diff] [blame] | 4470 | @Override |
| 4471 | public void invalidateHomeTaskSnapshot(IBinder token) { |
| 4472 | synchronized (mGlobalLock) { |
| 4473 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4474 | if (r == null || !r.isActivityTypeHome()) { |
| 4475 | return; |
| 4476 | } |
| 4477 | mWindowManager.mTaskSnapshotController.removeSnapshotCache(r.getTask().mTaskId); |
| 4478 | } |
| 4479 | } |
| 4480 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4481 | /** Return the user id of the last resumed activity. */ |
| 4482 | @Override |
| 4483 | public @UserIdInt |
| 4484 | int getLastResumedActivityUserId() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4485 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4486 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, "getLastResumedActivityUserId()"); |
| 4487 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4488 | if (mLastResumedActivity == null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4489 | return getCurrentUserId(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4490 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4491 | return mLastResumedActivity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4492 | } |
| 4493 | } |
| 4494 | |
| 4495 | @Override |
| 4496 | public void updateLockTaskFeatures(int userId, int flags) { |
| 4497 | final int callingUid = Binder.getCallingUid(); |
| 4498 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4499 | mAmInternal.enforceCallingPermission(android.Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4500 | "updateLockTaskFeatures()"); |
| 4501 | } |
| 4502 | synchronized (mGlobalLock) { |
| 4503 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Allowing features " + userId + ":0x" + |
| 4504 | Integer.toHexString(flags)); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 4505 | getLockTaskController().updateLockTaskFeatures(userId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4506 | } |
| 4507 | } |
| 4508 | |
| 4509 | @Override |
| 4510 | public void setShowWhenLocked(IBinder token, boolean showWhenLocked) { |
| 4511 | synchronized (mGlobalLock) { |
| 4512 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4513 | if (r == null) { |
| 4514 | return; |
| 4515 | } |
| 4516 | final long origId = Binder.clearCallingIdentity(); |
| 4517 | try { |
| 4518 | r.setShowWhenLocked(showWhenLocked); |
| 4519 | } finally { |
| 4520 | Binder.restoreCallingIdentity(origId); |
| 4521 | } |
| 4522 | } |
| 4523 | } |
| 4524 | |
| 4525 | @Override |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 4526 | public void setInheritShowWhenLocked(IBinder token, boolean inheritShowWhenLocked) { |
| 4527 | synchronized (mGlobalLock) { |
| 4528 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4529 | if (r == null) { |
| 4530 | return; |
| 4531 | } |
| 4532 | final long origId = Binder.clearCallingIdentity(); |
| 4533 | try { |
| 4534 | r.setInheritShowWhenLocked(inheritShowWhenLocked); |
| 4535 | } finally { |
| 4536 | Binder.restoreCallingIdentity(origId); |
| 4537 | } |
| 4538 | } |
| 4539 | } |
| 4540 | |
| 4541 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4542 | public void setTurnScreenOn(IBinder token, boolean turnScreenOn) { |
| 4543 | synchronized (mGlobalLock) { |
| 4544 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4545 | if (r == null) { |
| 4546 | return; |
| 4547 | } |
| 4548 | final long origId = Binder.clearCallingIdentity(); |
| 4549 | try { |
| 4550 | r.setTurnScreenOn(turnScreenOn); |
| 4551 | } finally { |
| 4552 | Binder.restoreCallingIdentity(origId); |
| 4553 | } |
| 4554 | } |
| 4555 | } |
| 4556 | |
| 4557 | @Override |
| 4558 | public void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4559 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4560 | "registerRemoteAnimations"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4561 | definition.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4562 | synchronized (mGlobalLock) { |
| 4563 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4564 | if (r == null) { |
| 4565 | return; |
| 4566 | } |
| 4567 | final long origId = Binder.clearCallingIdentity(); |
| 4568 | try { |
| 4569 | r.registerRemoteAnimations(definition); |
| 4570 | } finally { |
| 4571 | Binder.restoreCallingIdentity(origId); |
| 4572 | } |
| 4573 | } |
| 4574 | } |
| 4575 | |
| 4576 | @Override |
Winson Chung | 10fc25d | 2019-12-10 14:13:56 -0800 | [diff] [blame] | 4577 | public void unregisterRemoteAnimations(IBinder token) { |
| 4578 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
| 4579 | "unregisterRemoteAnimations"); |
| 4580 | synchronized (mGlobalLock) { |
| 4581 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4582 | if (r == null) { |
| 4583 | return; |
| 4584 | } |
| 4585 | final long origId = Binder.clearCallingIdentity(); |
| 4586 | try { |
| 4587 | r.unregisterRemoteAnimations(); |
| 4588 | } finally { |
| 4589 | Binder.restoreCallingIdentity(origId); |
| 4590 | } |
| 4591 | } |
| 4592 | } |
| 4593 | |
| 4594 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4595 | public void registerRemoteAnimationForNextActivityStart(String packageName, |
| 4596 | RemoteAnimationAdapter adapter) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4597 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4598 | "registerRemoteAnimationForNextActivityStart"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4599 | adapter.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4600 | synchronized (mGlobalLock) { |
| 4601 | final long origId = Binder.clearCallingIdentity(); |
| 4602 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4603 | getActivityStartController().registerRemoteAnimationForNextActivityStart( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4604 | packageName, adapter); |
| 4605 | } finally { |
| 4606 | Binder.restoreCallingIdentity(origId); |
| 4607 | } |
| 4608 | } |
| 4609 | } |
| 4610 | |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4611 | @Override |
| 4612 | public void registerRemoteAnimationsForDisplay(int displayId, |
| 4613 | RemoteAnimationDefinition definition) { |
| 4614 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
| 4615 | "registerRemoteAnimations"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4616 | definition.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4617 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4618 | final DisplayContent display = mRootWindowContainer.getDisplayContent(displayId); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4619 | if (display == null) { |
| 4620 | Slog.e(TAG, "Couldn't find display with id: " + displayId); |
| 4621 | return; |
| 4622 | } |
| 4623 | final long origId = Binder.clearCallingIdentity(); |
| 4624 | try { |
| 4625 | display.mDisplayContent.registerRemoteAnimations(definition); |
| 4626 | } finally { |
| 4627 | Binder.restoreCallingIdentity(origId); |
| 4628 | } |
| 4629 | } |
| 4630 | } |
| 4631 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4632 | /** @see android.app.ActivityManager#alwaysShowUnsupportedCompileSdkWarning */ |
| 4633 | @Override |
| 4634 | public void alwaysShowUnsupportedCompileSdkWarning(ComponentName activity) { |
| 4635 | synchronized (mGlobalLock) { |
| 4636 | final long origId = Binder.clearCallingIdentity(); |
| 4637 | try { |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 4638 | mAppWarnings.alwaysShowUnsupportedCompileSdkWarning(activity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4639 | } finally { |
| 4640 | Binder.restoreCallingIdentity(origId); |
| 4641 | } |
| 4642 | } |
| 4643 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 4644 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4645 | @Override |
| 4646 | public void setVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4647 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4648 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4649 | final int pid = Binder.getCallingPid(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 4650 | final WindowProcessController wpc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4651 | mVrController.setVrThreadLocked(tid, pid, wpc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4652 | } |
| 4653 | } |
| 4654 | |
| 4655 | @Override |
| 4656 | public void setPersistentVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4657 | if (checkCallingPermission(Manifest.permission.RESTRICTED_VR_ACCESS) |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4658 | != PERMISSION_GRANTED) { |
| 4659 | final String msg = "Permission Denial: setPersistentVrThread() from pid=" |
| 4660 | + Binder.getCallingPid() |
| 4661 | + ", uid=" + Binder.getCallingUid() |
| 4662 | + " requires " + Manifest.permission.RESTRICTED_VR_ACCESS; |
| 4663 | Slog.w(TAG, msg); |
| 4664 | throw new SecurityException(msg); |
| 4665 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4666 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4667 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4668 | final int pid = Binder.getCallingPid(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 4669 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4670 | mVrController.setPersistentVrThreadLocked(tid, pid, proc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4671 | } |
| 4672 | } |
| 4673 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4674 | @Override |
| 4675 | public void stopAppSwitches() { |
| 4676 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "stopAppSwitches"); |
| 4677 | synchronized (mGlobalLock) { |
| 4678 | mAppSwitchesAllowedTime = SystemClock.uptimeMillis() + APP_SWITCH_DELAY_TIME; |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 4679 | mLastStopAppSwitchesTime = SystemClock.uptimeMillis(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4680 | mDidAppSwitch = false; |
| 4681 | getActivityStartController().schedulePendingActivityLaunches(APP_SWITCH_DELAY_TIME); |
| 4682 | } |
| 4683 | } |
| 4684 | |
| 4685 | @Override |
| 4686 | public void resumeAppSwitches() { |
| 4687 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "resumeAppSwitches"); |
| 4688 | synchronized (mGlobalLock) { |
| 4689 | // Note that we don't execute any pending app switches... we will |
| 4690 | // let those wait until either the timeout, or the next start |
| 4691 | // activity request. |
| 4692 | mAppSwitchesAllowedTime = 0; |
| 4693 | } |
| 4694 | } |
| 4695 | |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 4696 | long getLastStopAppSwitchesTime() { |
| 4697 | return mLastStopAppSwitchesTime; |
| 4698 | } |
| 4699 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4700 | void onStartActivitySetDidAppSwitch() { |
| 4701 | if (mDidAppSwitch) { |
| 4702 | // This is the second allowed switch since we stopped switches, so now just generally |
| 4703 | // allow switches. Use case: |
| 4704 | // - user presses home (switches disabled, switch to home, mDidAppSwitch now true); |
| 4705 | // - user taps a home icon (coming from home so allowed, we hit here and now allow |
| 4706 | // anyone to switch again). |
| 4707 | mAppSwitchesAllowedTime = 0; |
| 4708 | } else { |
| 4709 | mDidAppSwitch = true; |
| 4710 | } |
| 4711 | } |
| 4712 | |
| 4713 | /** @return whether the system should disable UI modes incompatible with VR mode. */ |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4714 | boolean shouldDisableNonVrUiLocked() { |
| 4715 | return mVrController.shouldDisableNonVrUiLocked(); |
| 4716 | } |
| 4717 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4718 | private void applyUpdateVrModeLocked(ActivityRecord r) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4719 | // 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] | 4720 | // 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] | 4721 | if (r.requestedVrComponent != null && r.getDisplayId() != DEFAULT_DISPLAY) { |
Wale Ogunwale | b8e6b63 | 2019-06-28 15:19:25 +0000 | [diff] [blame] | 4722 | Slog.i(TAG, "Moving " + r.shortComponentName + " from display " + r.getDisplayId() |
| 4723 | + " to main display for VR"); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4724 | mRootWindowContainer.moveStackToDisplay( |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 4725 | r.getRootTaskId(), DEFAULT_DISPLAY, true /* toTop */); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4726 | } |
| 4727 | mH.post(() -> { |
| 4728 | if (!mVrController.onVrModeChanged(r)) { |
| 4729 | return; |
| 4730 | } |
| 4731 | synchronized (mGlobalLock) { |
| 4732 | final boolean disableNonVrUi = mVrController.shouldDisableNonVrUiLocked(); |
| 4733 | mWindowManager.disableNonVrUi(disableNonVrUi); |
| 4734 | if (disableNonVrUi) { |
| 4735 | // If we are in a VR mode where Picture-in-Picture mode is unsupported, |
| 4736 | // then remove the pinned stack. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4737 | mRootWindowContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4738 | } |
| 4739 | } |
| 4740 | }); |
| 4741 | } |
| 4742 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4743 | @Override |
| 4744 | public int getPackageScreenCompatMode(String packageName) { |
| 4745 | enforceNotIsolatedCaller("getPackageScreenCompatMode"); |
| 4746 | synchronized (mGlobalLock) { |
| 4747 | return mCompatModePackages.getPackageScreenCompatModeLocked(packageName); |
| 4748 | } |
| 4749 | } |
| 4750 | |
| 4751 | @Override |
| 4752 | public void setPackageScreenCompatMode(String packageName, int mode) { |
| 4753 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4754 | "setPackageScreenCompatMode"); |
| 4755 | synchronized (mGlobalLock) { |
| 4756 | mCompatModePackages.setPackageScreenCompatModeLocked(packageName, mode); |
| 4757 | } |
| 4758 | } |
| 4759 | |
| 4760 | @Override |
| 4761 | public boolean getPackageAskScreenCompat(String packageName) { |
| 4762 | enforceNotIsolatedCaller("getPackageAskScreenCompat"); |
| 4763 | synchronized (mGlobalLock) { |
| 4764 | return mCompatModePackages.getPackageAskCompatModeLocked(packageName); |
| 4765 | } |
| 4766 | } |
| 4767 | |
| 4768 | @Override |
| 4769 | public void setPackageAskScreenCompat(String packageName, boolean ask) { |
| 4770 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4771 | "setPackageAskScreenCompat"); |
| 4772 | synchronized (mGlobalLock) { |
| 4773 | mCompatModePackages.setPackageAskCompatModeLocked(packageName, ask); |
| 4774 | } |
| 4775 | } |
| 4776 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 4777 | public static String relaunchReasonToString(int relaunchReason) { |
| 4778 | switch (relaunchReason) { |
| 4779 | case RELAUNCH_REASON_WINDOWING_MODE_RESIZE: |
| 4780 | return "window_resize"; |
| 4781 | case RELAUNCH_REASON_FREE_RESIZE: |
| 4782 | return "free_resize"; |
| 4783 | default: |
| 4784 | return null; |
| 4785 | } |
| 4786 | } |
| 4787 | |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4788 | ActivityStack getTopDisplayFocusedStack() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4789 | return mRootWindowContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4790 | } |
| 4791 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4792 | /** Pokes the task persister. */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4793 | void notifyTaskPersisterLocked(Task task, boolean flush) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4794 | mRecentTasks.notifyTaskPersisterLocked(task, flush); |
| 4795 | } |
| 4796 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4797 | boolean isKeyguardLocked() { |
| 4798 | return mKeyguardController.isKeyguardLocked(); |
| 4799 | } |
| 4800 | |
Garfield Tan | 0154863 | 2018-11-27 10:15:48 -0800 | [diff] [blame] | 4801 | /** |
| 4802 | * Clears launch params for the given package. |
| 4803 | * @param packageNames the names of the packages of which the launch params are to be cleared |
| 4804 | */ |
| 4805 | @Override |
| 4806 | public void clearLaunchParamsForPackages(List<String> packageNames) { |
| 4807 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4808 | "clearLaunchParamsForPackages"); |
| 4809 | synchronized (mGlobalLock) { |
| 4810 | for (int i = 0; i < packageNames.size(); ++i) { |
| 4811 | mStackSupervisor.mLaunchParamsPersister.removeRecordForPackage(packageNames.get(i)); |
| 4812 | } |
| 4813 | } |
| 4814 | } |
| 4815 | |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 4816 | /** |
| 4817 | * Makes the display with the given id a single task instance display. I.e the display can only |
| 4818 | * contain one task. |
| 4819 | */ |
| 4820 | @Override |
| 4821 | public void setDisplayToSingleTaskInstance(int displayId) { |
| 4822 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4823 | "setDisplayToSingleTaskInstance"); |
| 4824 | final long origId = Binder.clearCallingIdentity(); |
| 4825 | try { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 4826 | final DisplayContent display = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4827 | mRootWindowContainer.getDisplayContentOrCreate(displayId); |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 4828 | if (display != null) { |
| 4829 | display.setDisplayToSingleTaskInstance(); |
| 4830 | } |
| 4831 | } finally { |
| 4832 | Binder.restoreCallingIdentity(origId); |
| 4833 | } |
| 4834 | } |
| 4835 | |
jorgegil@google.com | 06bc323 | 2019-10-31 14:51:22 -0700 | [diff] [blame] | 4836 | /** |
| 4837 | * Requests that an activity should enter picture-in-picture mode if possible. |
| 4838 | */ |
| 4839 | @Override |
| 4840 | public void requestPictureInPictureMode(IBinder token) throws RemoteException { |
| 4841 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4842 | "requestPictureInPictureMode"); |
| 4843 | final long origId = Binder.clearCallingIdentity(); |
| 4844 | try { |
| 4845 | synchronized (mGlobalLock) { |
| 4846 | final ActivityRecord activity = ActivityRecord.forTokenLocked(token); |
| 4847 | if (activity == null) { |
| 4848 | return; |
| 4849 | } |
| 4850 | |
| 4851 | final boolean canEnterPictureInPicture = activity.checkEnterPictureInPictureState( |
| 4852 | "requestPictureInPictureMode", /* beforeStopping */ false); |
| 4853 | if (!canEnterPictureInPicture) { |
| 4854 | throw new IllegalStateException( |
| 4855 | "Requested PIP on an activity that doesn't support it"); |
| 4856 | } |
| 4857 | |
| 4858 | try { |
| 4859 | final ClientTransaction transaction = ClientTransaction.obtain( |
| 4860 | activity.app.getThread(), |
| 4861 | activity.token); |
| 4862 | transaction.addCallback(EnterPipRequestedItem.obtain()); |
| 4863 | getLifecycleManager().scheduleTransaction(transaction); |
| 4864 | } catch (Exception e) { |
| 4865 | Slog.w(TAG, "Failed to send enter pip requested item: " |
| 4866 | + activity.intent.getComponent(), e); |
| 4867 | } |
| 4868 | } |
| 4869 | } finally { |
| 4870 | Binder.restoreCallingIdentity(origId); |
| 4871 | } |
| 4872 | } |
| 4873 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4874 | void dumpLastANRLocked(PrintWriter pw) { |
| 4875 | pw.println("ACTIVITY MANAGER LAST ANR (dumpsys activity lastanr)"); |
| 4876 | if (mLastANRState == null) { |
| 4877 | pw.println(" <no ANR has occurred since boot>"); |
| 4878 | } else { |
| 4879 | pw.println(mLastANRState); |
| 4880 | } |
| 4881 | } |
| 4882 | |
| 4883 | void dumpLastANRTracesLocked(PrintWriter pw) { |
| 4884 | pw.println("ACTIVITY MANAGER LAST ANR TRACES (dumpsys activity lastanr-traces)"); |
| 4885 | |
| 4886 | final File[] files = new File(ANR_TRACE_DIR).listFiles(); |
| 4887 | if (ArrayUtils.isEmpty(files)) { |
| 4888 | pw.println(" <no ANR has occurred since boot>"); |
| 4889 | return; |
| 4890 | } |
| 4891 | // Find the latest file. |
| 4892 | File latest = null; |
| 4893 | for (File f : files) { |
| 4894 | if ((latest == null) || (latest.lastModified() < f.lastModified())) { |
| 4895 | latest = f; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4896 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4897 | } |
| 4898 | pw.print("File: "); |
| 4899 | pw.print(latest.getName()); |
| 4900 | pw.println(); |
| 4901 | try (BufferedReader in = new BufferedReader(new FileReader(latest))) { |
| 4902 | String line; |
| 4903 | while ((line = in.readLine()) != null) { |
| 4904 | pw.println(line); |
| 4905 | } |
| 4906 | } catch (IOException e) { |
| 4907 | pw.print("Unable to read: "); |
| 4908 | pw.print(e); |
| 4909 | pw.println(); |
| 4910 | } |
| 4911 | } |
| 4912 | |
| 4913 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4914 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 4915 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage, |
| 4916 | "ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)"); |
| 4917 | } |
| 4918 | |
| 4919 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4920 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage, String header) { |
| 4921 | pw.println(header); |
| 4922 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4923 | boolean printedAnything = mRootWindowContainer.dumpActivities(fd, pw, dumpAll, dumpClient, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4924 | dumpPackage); |
| 4925 | boolean needSep = printedAnything; |
| 4926 | |
| 4927 | boolean printed = ActivityStackSupervisor.printThisActivity(pw, |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4928 | mRootWindowContainer.getTopResumedActivity(), dumpPackage, needSep, |
Dianne Hackborn | 9106f2a | 2020-04-30 16:23:20 -0700 | [diff] [blame] | 4929 | " ResumedActivity: ", null); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4930 | if (printed) { |
| 4931 | printedAnything = true; |
| 4932 | needSep = false; |
| 4933 | } |
| 4934 | |
| 4935 | if (dumpPackage == null) { |
| 4936 | if (needSep) { |
| 4937 | pw.println(); |
| 4938 | } |
| 4939 | printedAnything = true; |
| 4940 | mStackSupervisor.dump(pw, " "); |
Winson Chung | 268eccb | 2020-03-26 13:43:44 -0700 | [diff] [blame] | 4941 | mTaskOrganizerController.dump(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | if (!printedAnything) { |
| 4945 | pw.println(" (nothing)"); |
| 4946 | } |
| 4947 | } |
| 4948 | |
| 4949 | void dumpActivityContainersLocked(PrintWriter pw) { |
Jeff Chang | de32273 | 2019-07-12 12:16:23 +0800 | [diff] [blame] | 4950 | pw.println("ACTIVITY MANAGER CONTAINERS (dumpsys activity containers)"); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4951 | mRootWindowContainer.dumpChildrenNames(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4952 | pw.println(" "); |
| 4953 | } |
| 4954 | |
| 4955 | void dumpActivityStarterLocked(PrintWriter pw, String dumpPackage) { |
| 4956 | pw.println("ACTIVITY MANAGER STARTER (dumpsys activity starter)"); |
| 4957 | getActivityStartController().dump(pw, "", dumpPackage); |
| 4958 | } |
| 4959 | |
| 4960 | /** |
| 4961 | * There are three things that cmd can be: |
| 4962 | * - a flattened component name that matches an existing activity |
| 4963 | * - the cmd arg isn't the flattened component name of an existing activity: |
| 4964 | * dump all activity whose component contains the cmd as a substring |
| 4965 | * - A hex number of the ActivityRecord object instance. |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 4966 | * <p> |
| 4967 | * The caller should not hold lock when calling this method because it will wait for the |
| 4968 | * activities to complete the dump. |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4969 | * |
| 4970 | * @param dumpVisibleStacksOnly dump activity with {@param name} only if in a visible stack |
| 4971 | * @param dumpFocusedStackOnly dump activity with {@param name} only if in the focused stack |
| 4972 | */ |
| 4973 | protected boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, String[] args, |
| 4974 | int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, boolean dumpFocusedStackOnly) { |
| 4975 | ArrayList<ActivityRecord> activities; |
| 4976 | |
| 4977 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4978 | activities = mRootWindowContainer.getDumpActivities(name, dumpVisibleStacksOnly, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4979 | dumpFocusedStackOnly); |
| 4980 | } |
| 4981 | |
| 4982 | if (activities.size() <= 0) { |
| 4983 | return false; |
| 4984 | } |
| 4985 | |
| 4986 | String[] newArgs = new String[args.length - opti]; |
| 4987 | System.arraycopy(args, opti, newArgs, 0, args.length - opti); |
| 4988 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4989 | Task lastTask = null; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4990 | boolean needSep = false; |
| 4991 | for (int i = activities.size() - 1; i >= 0; i--) { |
| 4992 | ActivityRecord r = activities.get(i); |
| 4993 | if (needSep) { |
| 4994 | pw.println(); |
| 4995 | } |
| 4996 | needSep = true; |
| 4997 | synchronized (mGlobalLock) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4998 | final Task task = r.getTask(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4999 | if (lastTask != task) { |
| 5000 | lastTask = task; |
| 5001 | pw.print("TASK "); pw.print(lastTask.affinity); |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 5002 | pw.print(" id="); pw.print(lastTask.mTaskId); |
| 5003 | pw.print(" userId="); pw.println(lastTask.mUserId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5004 | if (dumpAll) { |
| 5005 | lastTask.dump(pw, " "); |
| 5006 | } |
| 5007 | } |
| 5008 | } |
| 5009 | dumpActivity(" ", fd, pw, activities.get(i), newArgs, dumpAll); |
| 5010 | } |
| 5011 | return true; |
| 5012 | } |
| 5013 | |
| 5014 | /** |
| 5015 | * Invokes IApplicationThread.dumpActivity() on the thread of the specified activity if |
| 5016 | * there is a thread associated with the activity. |
| 5017 | */ |
| 5018 | private void dumpActivity(String prefix, FileDescriptor fd, PrintWriter pw, |
| 5019 | final ActivityRecord r, String[] args, boolean dumpAll) { |
| 5020 | String innerPrefix = prefix + " "; |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5021 | IApplicationThread appThread = null; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5022 | synchronized (mGlobalLock) { |
| 5023 | pw.print(prefix); pw.print("ACTIVITY "); pw.print(r.shortComponentName); |
| 5024 | pw.print(" "); pw.print(Integer.toHexString(System.identityHashCode(r))); |
| 5025 | pw.print(" pid="); |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5026 | if (r.hasProcess()) { |
| 5027 | pw.println(r.app.getPid()); |
| 5028 | appThread = r.app.getThread(); |
| 5029 | } else { |
| 5030 | pw.println("(not running)"); |
| 5031 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5032 | if (dumpAll) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5033 | r.dump(pw, innerPrefix, true /* dumpAll */); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5034 | } |
| 5035 | } |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5036 | if (appThread != null) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5037 | // flush anything that is already in the PrintWriter since the thread is going |
| 5038 | // to write to the file descriptor directly |
| 5039 | pw.flush(); |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5040 | try (TransferPipe tp = new TransferPipe()) { |
| 5041 | appThread.dumpActivity(tp.getWriteFd(), r.appToken, innerPrefix, args); |
| 5042 | tp.go(fd); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5043 | } catch (IOException e) { |
| 5044 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 5045 | } catch (RemoteException e) { |
| 5046 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 5047 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5048 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5049 | } |
| 5050 | |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 5051 | private void writeSleepStateToProto(ProtoOutputStream proto, int wakeFullness, |
| 5052 | boolean testPssMode) { |
| 5053 | final long sleepToken = proto.start(ActivityManagerServiceDumpProcessesProto.SLEEP_STATUS); |
| 5054 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.WAKEFULNESS, |
| 5055 | PowerManagerInternal.wakefulnessToProtoEnum(wakeFullness)); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5056 | for (ActivityTaskManagerInternal.SleepToken st : mRootWindowContainer.mSleepTokens) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5057 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEP_TOKENS, |
| 5058 | st.toString()); |
| 5059 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5060 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEPING, mSleeping); |
| 5061 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SHUTTING_DOWN, |
| 5062 | mShuttingDown); |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 5063 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.TEST_PSS_MODE, |
| 5064 | testPssMode); |
| 5065 | proto.end(sleepToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5066 | } |
| 5067 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5068 | int getCurrentUserId() { |
| 5069 | return mAmInternal.getCurrentUserId(); |
| 5070 | } |
| 5071 | |
| 5072 | private void enforceNotIsolatedCaller(String caller) { |
| 5073 | if (UserHandle.isIsolated(Binder.getCallingUid())) { |
| 5074 | throw new SecurityException("Isolated process not allowed to call " + caller); |
| 5075 | } |
| 5076 | } |
| 5077 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5078 | public Configuration getConfiguration() { |
| 5079 | Configuration ci; |
| 5080 | synchronized(mGlobalLock) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 5081 | ci = new Configuration(getGlobalConfigurationForCallingPid()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5082 | ci.userSetLocale = false; |
| 5083 | } |
| 5084 | return ci; |
| 5085 | } |
| 5086 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5087 | /** |
| 5088 | * Current global configuration information. Contains general settings for the entire system, |
| 5089 | * also corresponds to the merged configuration of the default display. |
| 5090 | */ |
| 5091 | Configuration getGlobalConfiguration() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5092 | // Return default configuration before mRootWindowContainer initialized, which happens |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 5093 | // while initializing process record for system, see {@link |
| 5094 | // ActivityManagerService#setSystemProcess}. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5095 | return mRootWindowContainer != null ? mRootWindowContainer.getConfiguration() |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 5096 | : new Configuration(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5097 | } |
| 5098 | |
| 5099 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5100 | boolean initLocale) { |
| 5101 | return updateConfigurationLocked(values, starting, initLocale, false /* deferResume */); |
| 5102 | } |
| 5103 | |
| 5104 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5105 | boolean initLocale, boolean deferResume) { |
| 5106 | // pass UserHandle.USER_NULL as userId because we don't persist configuration for any user |
| 5107 | return updateConfigurationLocked(values, starting, initLocale, false /* persistent */, |
| 5108 | UserHandle.USER_NULL, deferResume); |
| 5109 | } |
| 5110 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 5111 | public void updatePersistentConfiguration(Configuration values, @UserIdInt int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5112 | final long origId = Binder.clearCallingIdentity(); |
| 5113 | try { |
| 5114 | synchronized (mGlobalLock) { |
| 5115 | updateConfigurationLocked(values, null, false, true, userId, |
| 5116 | false /* deferResume */); |
| 5117 | } |
| 5118 | } finally { |
| 5119 | Binder.restoreCallingIdentity(origId); |
| 5120 | } |
| 5121 | } |
| 5122 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5123 | private boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5124 | boolean initLocale, boolean persistent, int userId, boolean deferResume) { |
| 5125 | return updateConfigurationLocked(values, starting, initLocale, persistent, userId, |
| 5126 | deferResume, null /* result */); |
| 5127 | } |
| 5128 | |
| 5129 | /** |
| 5130 | * Do either or both things: (1) change the current configuration, and (2) |
| 5131 | * make sure the given activity is running with the (now) current |
| 5132 | * configuration. Returns true if the activity has been left running, or |
| 5133 | * false if <var>starting</var> is being destroyed to match the new |
| 5134 | * configuration. |
| 5135 | * |
| 5136 | * @param userId is only used when persistent parameter is set to true to persist configuration |
| 5137 | * for that particular user |
| 5138 | */ |
| 5139 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5140 | boolean initLocale, boolean persistent, int userId, boolean deferResume, |
| 5141 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 5142 | int changes = 0; |
| 5143 | boolean kept = true; |
| 5144 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5145 | deferWindowLayout(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5146 | try { |
| 5147 | if (values != null) { |
| 5148 | changes = updateGlobalConfigurationLocked(values, initLocale, persistent, userId, |
| 5149 | deferResume); |
| 5150 | } |
| 5151 | |
| 5152 | kept = ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 5153 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5154 | continueWindowLayout(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5155 | } |
| 5156 | |
| 5157 | if (result != null) { |
| 5158 | result.changes = changes; |
| 5159 | result.activityRelaunched = !kept; |
| 5160 | } |
| 5161 | return kept; |
| 5162 | } |
| 5163 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5164 | /** Update default (global) configuration and notify listeners about changes. */ |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5165 | int updateGlobalConfigurationLocked(@NonNull Configuration values, boolean initLocale, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5166 | boolean persistent, int userId, boolean deferResume) { |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5167 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5168 | final DisplayContent defaultDisplay = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5169 | mRootWindowContainer.getDisplayContent(DEFAULT_DISPLAY); |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5170 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5171 | mTempConfig.setTo(getGlobalConfiguration()); |
| 5172 | final int changes = mTempConfig.updateFrom(values); |
| 5173 | if (changes == 0) { |
| 5174 | // Since calling to Activity.setRequestedOrientation leads to freezing the window with |
| 5175 | // setting WindowManagerService.mWaitingForConfig to true, it is important that we call |
| 5176 | // performDisplayOverrideConfigUpdate in order to send the new display configuration |
| 5177 | // (even if there are no actual changes) to unfreeze the window. |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5178 | defaultDisplay.performDisplayOverrideConfigUpdate(values, deferResume); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5179 | return 0; |
| 5180 | } |
| 5181 | |
| 5182 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.i(TAG_CONFIGURATION, |
| 5183 | "Updating global configuration to: " + values); |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5184 | writeConfigurationChanged(changes); |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 5185 | FrameworkStatsLog.write(FrameworkStatsLog.RESOURCE_CONFIGURATION_CHANGED, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5186 | values.colorMode, |
| 5187 | values.densityDpi, |
| 5188 | values.fontScale, |
| 5189 | values.hardKeyboardHidden, |
| 5190 | values.keyboard, |
| 5191 | values.keyboardHidden, |
| 5192 | values.mcc, |
| 5193 | values.mnc, |
| 5194 | values.navigation, |
| 5195 | values.navigationHidden, |
| 5196 | values.orientation, |
| 5197 | values.screenHeightDp, |
| 5198 | values.screenLayout, |
| 5199 | values.screenWidthDp, |
| 5200 | values.smallestScreenWidthDp, |
| 5201 | values.touchscreen, |
| 5202 | values.uiMode); |
| 5203 | |
| 5204 | |
| 5205 | if (!initLocale && !values.getLocales().isEmpty() && values.userSetLocale) { |
| 5206 | final LocaleList locales = values.getLocales(); |
| 5207 | int bestLocaleIndex = 0; |
| 5208 | if (locales.size() > 1) { |
| 5209 | if (mSupportedSystemLocales == null) { |
| 5210 | mSupportedSystemLocales = Resources.getSystem().getAssets().getLocales(); |
| 5211 | } |
| 5212 | bestLocaleIndex = Math.max(0, locales.getFirstMatchIndex(mSupportedSystemLocales)); |
| 5213 | } |
| 5214 | SystemProperties.set("persist.sys.locale", |
| 5215 | locales.get(bestLocaleIndex).toLanguageTag()); |
| 5216 | LocaleList.setDefault(locales, bestLocaleIndex); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5217 | |
| 5218 | final Message m = PooledLambda.obtainMessage( |
| 5219 | ActivityTaskManagerService::sendLocaleToMountDaemonMsg, this, |
| 5220 | locales.get(bestLocaleIndex)); |
| 5221 | mH.sendMessage(m); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5222 | } |
| 5223 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 5224 | mTempConfig.seq = increaseConfigurationSeqLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5225 | |
| 5226 | // Update stored global config and notify everyone about the change. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5227 | mRootWindowContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5228 | |
| 5229 | Slog.i(TAG, "Config changes=" + Integer.toHexString(changes) + " " + mTempConfig); |
| 5230 | // TODO(multi-display): Update UsageEvents#Event to include displayId. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5231 | mUsageStatsInternal.reportConfigurationChange(mTempConfig, mAmInternal.getCurrentUserId()); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5232 | |
| 5233 | // 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] | 5234 | updateShouldShowDialogsLocked(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5235 | |
| 5236 | AttributeCache ac = AttributeCache.instance(); |
| 5237 | if (ac != null) { |
| 5238 | ac.updateConfiguration(mTempConfig); |
| 5239 | } |
| 5240 | |
| 5241 | // Make sure all resources in our process are updated right now, so that anyone who is going |
| 5242 | // to retrieve resource values after we return will be sure to get the new ones. This is |
| 5243 | // especially important during boot, where the first config change needs to guarantee all |
| 5244 | // resources have that config before following boot code is executed. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5245 | mSystemThread.applyConfigurationToResources(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5246 | |
| 5247 | // We need another copy of global config because we're scheduling some calls instead of |
| 5248 | // running them in place. We need to be sure that object we send will be handled unchanged. |
| 5249 | final Configuration configCopy = new Configuration(mTempConfig); |
| 5250 | if (persistent && Settings.System.hasInterestingConfigurationChanges(changes)) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5251 | final Message msg = PooledLambda.obtainMessage( |
| 5252 | ActivityTaskManagerService::sendPutConfigurationForUserMsg, |
| 5253 | this, userId, configCopy); |
| 5254 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5255 | } |
| 5256 | |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 5257 | SparseArray<WindowProcessController> pidMap = mProcessMap.getPidMap(); |
| 5258 | for (int i = pidMap.size() - 1; i >= 0; i--) { |
| 5259 | final int pid = pidMap.keyAt(i); |
| 5260 | final WindowProcessController app = pidMap.get(pid); |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 5261 | if (DEBUG_CONFIGURATION) { |
| 5262 | Slog.v(TAG_CONFIGURATION, "Update process config of " |
| 5263 | + app.mName + " to new config " + configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5264 | } |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 5265 | app.onConfigurationChanged(configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5266 | } |
| 5267 | |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 5268 | final Message msg = PooledLambda.obtainMessage( |
| 5269 | ActivityManagerInternal::broadcastGlobalConfigurationChanged, |
| 5270 | mAmInternal, changes, initLocale); |
| 5271 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5272 | |
| 5273 | // Override configuration of the default display duplicates global config, so we need to |
| 5274 | // update it also. This will also notify WindowManager about changes. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5275 | defaultDisplay.performDisplayOverrideConfigUpdate(mRootWindowContainer.getConfiguration(), |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5276 | deferResume); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5277 | |
| 5278 | return changes; |
| 5279 | } |
| 5280 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5281 | /** @see WindowSurfacePlacer#deferLayout */ |
| 5282 | void deferWindowLayout() { |
| 5283 | if (!mWindowManager.mWindowPlacerLocked.isLayoutDeferred()) { |
| 5284 | // Reset the reasons at the first entrance because we only care about the changes in the |
| 5285 | // deferred scope. |
| 5286 | mLayoutReasons = 0; |
| 5287 | } |
| 5288 | |
| 5289 | mWindowManager.mWindowPlacerLocked.deferLayout(); |
| 5290 | } |
| 5291 | |
| 5292 | /** @see WindowSurfacePlacer#continueLayout */ |
| 5293 | void continueWindowLayout() { |
| 5294 | mWindowManager.mWindowPlacerLocked.continueLayout(mLayoutReasons != 0); |
| 5295 | if (DEBUG_ALL && !mWindowManager.mWindowPlacerLocked.isLayoutDeferred()) { |
| 5296 | Slog.i(TAG, "continueWindowLayout reason=" + mLayoutReasons); |
| 5297 | } |
| 5298 | } |
| 5299 | |
| 5300 | /** |
| 5301 | * If a reason is added between {@link #deferWindowLayout} and {@link #continueWindowLayout}, |
| 5302 | * it will make sure {@link WindowSurfacePlacer#performSurfacePlacement} is called when the last |
| 5303 | * defer count is gone. |
| 5304 | */ |
| 5305 | void addWindowLayoutReasons(@LayoutReason int reasons) { |
| 5306 | mLayoutReasons |= reasons; |
| 5307 | } |
| 5308 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5309 | private void updateEventDispatchingLocked(boolean booted) { |
| 5310 | mWindowManager.setEventDispatching(booted && !mShuttingDown); |
| 5311 | } |
| 5312 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5313 | private void sendPutConfigurationForUserMsg(int userId, Configuration config) { |
| 5314 | final ContentResolver resolver = mContext.getContentResolver(); |
| 5315 | Settings.System.putConfigurationForUser(resolver, config, userId); |
| 5316 | } |
| 5317 | |
| 5318 | private void sendLocaleToMountDaemonMsg(Locale l) { |
| 5319 | try { |
| 5320 | IBinder service = ServiceManager.getService("mount"); |
| 5321 | IStorageManager storageManager = IStorageManager.Stub.asInterface(service); |
| 5322 | Log.d(TAG, "Storing locale " + l.toLanguageTag() + " for decryption UI"); |
| 5323 | storageManager.setField(StorageManager.SYSTEM_LOCALE_KEY, l.toLanguageTag()); |
| 5324 | } catch (RemoteException e) { |
| 5325 | Log.e(TAG, "Error storing locale for decryption UI", e); |
| 5326 | } |
| 5327 | } |
| 5328 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5329 | private void expireStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5330 | mStartActivitySources.remove(permissionToken); |
| 5331 | mExpiredStartAsCallerTokens.add(permissionToken); |
| 5332 | } |
| 5333 | |
| 5334 | private void forgetStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5335 | mExpiredStartAsCallerTokens.remove(permissionToken); |
| 5336 | } |
| 5337 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5338 | boolean isActivityStartsLoggingEnabled() { |
| 5339 | return mAmInternal.isActivityStartsLoggingEnabled(); |
| 5340 | } |
| 5341 | |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 5342 | boolean isBackgroundActivityStartsEnabled() { |
| 5343 | return mAmInternal.isBackgroundActivityStartsEnabled(); |
| 5344 | } |
| 5345 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5346 | void enableScreenAfterBoot(boolean booted) { |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5347 | writeBootProgressEnableScreen(SystemClock.uptimeMillis()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5348 | mWindowManager.enableScreenAfterBoot(); |
| 5349 | |
| 5350 | synchronized (mGlobalLock) { |
| 5351 | updateEventDispatchingLocked(booted); |
| 5352 | } |
| 5353 | } |
| 5354 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5355 | static long getInputDispatchingTimeoutLocked(ActivityRecord r) { |
| 5356 | if (r == null || !r.hasProcess()) { |
| 5357 | return KEY_DISPATCHING_TIMEOUT_MS; |
| 5358 | } |
| 5359 | return getInputDispatchingTimeoutLocked(r.app); |
| 5360 | } |
| 5361 | |
| 5362 | private static long getInputDispatchingTimeoutLocked(WindowProcessController r) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 5363 | return r != null ? r.getInputDispatchingTimeout() : KEY_DISPATCHING_TIMEOUT_MS; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5364 | } |
| 5365 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5366 | /** |
| 5367 | * Decide based on the configuration whether we should show the ANR, |
| 5368 | * crash, etc dialogs. The idea is that if there is no affordance to |
| 5369 | * press the on-screen buttons, or the user experience would be more |
| 5370 | * greatly impacted than the crash itself, we shouldn't show the dialog. |
| 5371 | * |
| 5372 | * A thought: SystemUI might also want to get told about this, the Power |
| 5373 | * dialog / global actions also might want different behaviors. |
| 5374 | */ |
| 5375 | private void updateShouldShowDialogsLocked(Configuration config) { |
| 5376 | final boolean inputMethodExists = !(config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 5377 | && config.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH |
| 5378 | && config.navigation == Configuration.NAVIGATION_NONAV); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5379 | final boolean hideDialogsSet = Settings.Global.getInt(mContext.getContentResolver(), |
| 5380 | HIDE_ERROR_DIALOGS, 0) != 0; |
Yuncheol Heo | 5d9b271 | 2020-04-16 17:31:32 -0700 | [diff] [blame] | 5381 | mShowDialogs = inputMethodExists |
| 5382 | && ActivityTaskManager.currentUiModeSupportsErrorDialogs(mContext) |
| 5383 | && !hideDialogsSet; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5384 | } |
| 5385 | |
| 5386 | private void updateFontScaleIfNeeded(@UserIdInt int userId) { |
| 5387 | final float scaleFactor = Settings.System.getFloatForUser(mContext.getContentResolver(), |
| 5388 | FONT_SCALE, 1.0f, userId); |
| 5389 | |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 5390 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5391 | if (getGlobalConfiguration().fontScale == scaleFactor) { |
| 5392 | return; |
| 5393 | } |
| 5394 | |
| 5395 | final Configuration configuration |
| 5396 | = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
| 5397 | configuration.fontScale = scaleFactor; |
| 5398 | updatePersistentConfiguration(configuration, userId); |
| 5399 | } |
| 5400 | } |
| 5401 | |
| 5402 | // Actually is sleeping or shutting down or whatever else in the future |
| 5403 | // is an inactive state. |
| 5404 | boolean isSleepingOrShuttingDownLocked() { |
| 5405 | return isSleepingLocked() || mShuttingDown; |
| 5406 | } |
| 5407 | |
| 5408 | boolean isSleepingLocked() { |
| 5409 | return mSleeping; |
| 5410 | } |
| 5411 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5412 | /** Update AMS states when an activity is resumed. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5413 | void setResumedActivityUncheckLocked(ActivityRecord r, String reason) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5414 | final Task task = r.getTask(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5415 | if (task.isActivityTypeStandard()) { |
| 5416 | if (mCurAppTimeTracker != r.appTimeTracker) { |
| 5417 | // We are switching app tracking. Complete the current one. |
| 5418 | if (mCurAppTimeTracker != null) { |
| 5419 | mCurAppTimeTracker.stop(); |
| 5420 | mH.obtainMessage( |
| 5421 | REPORT_TIME_TRACKER_MSG, mCurAppTimeTracker).sendToTarget(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5422 | mRootWindowContainer.clearOtherAppTimeTrackers(r.appTimeTracker); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5423 | mCurAppTimeTracker = null; |
| 5424 | } |
| 5425 | if (r.appTimeTracker != null) { |
| 5426 | mCurAppTimeTracker = r.appTimeTracker; |
| 5427 | startTimeTrackingFocusedActivityLocked(); |
| 5428 | } |
| 5429 | } else { |
| 5430 | startTimeTrackingFocusedActivityLocked(); |
| 5431 | } |
| 5432 | } else { |
| 5433 | r.appTimeTracker = null; |
| 5434 | } |
| 5435 | // TODO: VI Maybe r.task.voiceInteractor || r.voiceInteractor != null |
| 5436 | // TODO: Probably not, because we don't want to resume voice on switching |
| 5437 | // back to this activity |
| 5438 | if (task.voiceInteractor != null) { |
| 5439 | startRunningVoiceLocked(task.voiceSession, r.info.applicationInfo.uid); |
| 5440 | } else { |
| 5441 | finishRunningVoiceLocked(); |
| 5442 | |
| 5443 | if (mLastResumedActivity != null) { |
| 5444 | final IVoiceInteractionSession session; |
| 5445 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5446 | final Task lastResumedActivityTask = mLastResumedActivity.getTask(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5447 | if (lastResumedActivityTask != null |
| 5448 | && lastResumedActivityTask.voiceSession != null) { |
| 5449 | session = lastResumedActivityTask.voiceSession; |
| 5450 | } else { |
| 5451 | session = mLastResumedActivity.voiceSession; |
| 5452 | } |
| 5453 | |
| 5454 | if (session != null) { |
| 5455 | // We had been in a voice interaction session, but now focused has |
| 5456 | // move to something different. Just finish the session, we can't |
| 5457 | // return to it and retain the proper state and synchronization with |
| 5458 | // the voice interaction service. |
| 5459 | finishVoiceTask(session); |
| 5460 | } |
| 5461 | } |
| 5462 | } |
| 5463 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5464 | if (mLastResumedActivity != null && r.mUserId != mLastResumedActivity.mUserId) { |
| 5465 | mAmInternal.sendForegroundProfileChanged(r.mUserId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5466 | } |
Bogyun Son | bfb64dc | 2019-12-09 17:50:24 +0900 | [diff] [blame] | 5467 | final Task prevTask = mLastResumedActivity != null ? mLastResumedActivity.getTask() : null; |
| 5468 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5469 | updateResumedAppTrace(r); |
| 5470 | mLastResumedActivity = r; |
| 5471 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 5472 | r.getDisplay().setFocusedApp(r, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5473 | |
Bogyun Son | bfb64dc | 2019-12-09 17:50:24 +0900 | [diff] [blame] | 5474 | if (prevTask == null || task != prevTask) { |
| 5475 | if (prevTask != null) { |
| 5476 | mTaskChangeNotificationController.notifyTaskFocusChanged(prevTask.mTaskId, false); |
| 5477 | } |
| 5478 | mTaskChangeNotificationController.notifyTaskFocusChanged(task.mTaskId, true); |
| 5479 | } |
| 5480 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5481 | applyUpdateLockStateLocked(r); |
| 5482 | applyUpdateVrModeLocked(r); |
| 5483 | |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5484 | EventLogTags.writeWmSetResumedActivity( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5485 | r == null ? -1 : r.mUserId, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5486 | r == null ? "NULL" : r.shortComponentName, |
| 5487 | reason); |
| 5488 | } |
| 5489 | |
| 5490 | ActivityTaskManagerInternal.SleepToken acquireSleepToken(String tag, int displayId) { |
| 5491 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5492 | final ActivityTaskManagerInternal.SleepToken token = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5493 | mRootWindowContainer.createSleepToken(tag, displayId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5494 | updateSleepIfNeededLocked(); |
| 5495 | return token; |
| 5496 | } |
| 5497 | } |
| 5498 | |
| 5499 | void updateSleepIfNeededLocked() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5500 | final boolean shouldSleep = !mRootWindowContainer.hasAwakeDisplay(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5501 | final boolean wasSleeping = mSleeping; |
| 5502 | boolean updateOomAdj = false; |
| 5503 | |
| 5504 | if (!shouldSleep) { |
| 5505 | // If wasSleeping is true, we need to wake up activity manager state from when |
| 5506 | // we started sleeping. In either case, we need to apply the sleep tokens, which |
| 5507 | // will wake up stacks or put them to sleep as appropriate. |
| 5508 | if (wasSleeping) { |
| 5509 | mSleeping = false; |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 5510 | FrameworkStatsLog.write(FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5511 | FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__AWAKE); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5512 | startTimeTrackingFocusedActivityLocked(); |
| 5513 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
Varun Shah | 98694fb | 2019-04-11 09:28:27 -0700 | [diff] [blame] | 5514 | Slog.d(TAG, "Top Process State changed to PROCESS_STATE_TOP"); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5515 | mStackSupervisor.comeOutOfSleepIfNeededLocked(); |
| 5516 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5517 | mRootWindowContainer.applySleepTokens(true /* applyToStacks */); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5518 | if (wasSleeping) { |
| 5519 | updateOomAdj = true; |
| 5520 | } |
| 5521 | } else if (!mSleeping && shouldSleep) { |
| 5522 | mSleeping = true; |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 5523 | FrameworkStatsLog.write(FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5524 | FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__ASLEEP); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5525 | if (mCurAppTimeTracker != null) { |
| 5526 | mCurAppTimeTracker.stop(); |
| 5527 | } |
| 5528 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP_SLEEPING; |
Varun Shah | 98694fb | 2019-04-11 09:28:27 -0700 | [diff] [blame] | 5529 | Slog.d(TAG, "Top Process State changed to PROCESS_STATE_TOP_SLEEPING"); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5530 | mStackSupervisor.goingToSleepLocked(); |
| 5531 | updateResumedAppTrace(null /* resumed */); |
| 5532 | updateOomAdj = true; |
| 5533 | } |
| 5534 | if (updateOomAdj) { |
wilsonshih | 8d096d2 | 2019-08-01 17:46:14 +0800 | [diff] [blame] | 5535 | updateOomAdj(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5536 | } |
| 5537 | } |
| 5538 | |
| 5539 | void updateOomAdj() { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 5540 | mH.removeCallbacks(mUpdateOomAdjRunnable); |
| 5541 | mH.post(mUpdateOomAdjRunnable); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5542 | } |
| 5543 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5544 | void updateCpuStats() { |
| 5545 | mH.post(mAmInternal::updateCpuStats); |
| 5546 | } |
| 5547 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5548 | void updateBatteryStats(ActivityRecord component, boolean resumed) { |
| 5549 | final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::updateBatteryStats, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5550 | mAmInternal, component.mActivityComponent, component.app.mUid, component.mUserId, |
| 5551 | resumed); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5552 | mH.sendMessage(m); |
| 5553 | } |
| 5554 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5555 | void updateActivityUsageStats(ActivityRecord activity, int event) { |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5556 | ComponentName taskRoot = null; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5557 | final Task task = activity.getTask(); |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5558 | if (task != null) { |
| 5559 | final ActivityRecord rootActivity = task.getRootActivity(); |
| 5560 | if (rootActivity != null) { |
| 5561 | taskRoot = rootActivity.mActivityComponent; |
| 5562 | } |
| 5563 | } |
| 5564 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5565 | final Message m = PooledLambda.obtainMessage( |
| 5566 | ActivityManagerInternal::updateActivityUsageStats, mAmInternal, |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5567 | activity.mActivityComponent, activity.mUserId, event, activity.appToken, taskRoot); |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5568 | mH.sendMessage(m); |
| 5569 | } |
| 5570 | |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5571 | void startProcessAsync(ActivityRecord activity, boolean knownToBeDead, boolean isTop, |
| 5572 | String hostingType) { |
| 5573 | try { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5574 | if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) { |
| 5575 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "dispatchingStartProcess:" |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5576 | + activity.processName); |
| 5577 | } |
| 5578 | // Post message to start process to avoid possible deadlock of calling into AMS with the |
| 5579 | // ATMS lock held. |
| 5580 | final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::startProcess, |
| 5581 | mAmInternal, activity.processName, activity.info.applicationInfo, knownToBeDead, |
| 5582 | isTop, hostingType, activity.intent.getComponent()); |
| 5583 | mH.sendMessage(m); |
| 5584 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5585 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5586 | } |
| 5587 | } |
| 5588 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5589 | void setBooting(boolean booting) { |
| 5590 | mAmInternal.setBooting(booting); |
| 5591 | } |
| 5592 | |
| 5593 | boolean isBooting() { |
| 5594 | return mAmInternal.isBooting(); |
| 5595 | } |
| 5596 | |
| 5597 | void setBooted(boolean booted) { |
| 5598 | mAmInternal.setBooted(booted); |
| 5599 | } |
| 5600 | |
| 5601 | boolean isBooted() { |
| 5602 | return mAmInternal.isBooted(); |
| 5603 | } |
| 5604 | |
| 5605 | void postFinishBooting(boolean finishBooting, boolean enableScreen) { |
| 5606 | mH.post(() -> { |
| 5607 | if (finishBooting) { |
| 5608 | mAmInternal.finishBooting(); |
| 5609 | } |
| 5610 | if (enableScreen) { |
| 5611 | mInternal.enableScreenAfterBoot(isBooted()); |
| 5612 | } |
| 5613 | }); |
| 5614 | } |
| 5615 | |
| 5616 | void setHeavyWeightProcess(ActivityRecord root) { |
| 5617 | mHeavyWeightProcess = root.app; |
| 5618 | final Message m = PooledLambda.obtainMessage( |
| 5619 | ActivityTaskManagerService::postHeavyWeightProcessNotification, this, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5620 | root.app, root.intent, root.mUserId); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5621 | mH.sendMessage(m); |
| 5622 | } |
| 5623 | |
| 5624 | void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
| 5625 | if (mHeavyWeightProcess == null || mHeavyWeightProcess != proc) { |
| 5626 | return; |
| 5627 | } |
| 5628 | |
| 5629 | mHeavyWeightProcess = null; |
| 5630 | final Message m = PooledLambda.obtainMessage( |
| 5631 | ActivityTaskManagerService::cancelHeavyWeightProcessNotification, this, |
| 5632 | proc.mUserId); |
| 5633 | mH.sendMessage(m); |
| 5634 | } |
| 5635 | |
| 5636 | private void cancelHeavyWeightProcessNotification(int userId) { |
| 5637 | final INotificationManager inm = NotificationManager.getService(); |
| 5638 | if (inm == null) { |
| 5639 | return; |
| 5640 | } |
| 5641 | try { |
Julia Reynolds | e4a47dd | 2019-06-07 13:40:59 -0400 | [diff] [blame] | 5642 | inm.cancelNotificationWithTag("android", "android", null, |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5643 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, userId); |
| 5644 | } catch (RuntimeException e) { |
| 5645 | Slog.w(TAG, "Error canceling notification for service", e); |
| 5646 | } catch (RemoteException e) { |
| 5647 | } |
| 5648 | |
| 5649 | } |
| 5650 | |
| 5651 | private void postHeavyWeightProcessNotification( |
| 5652 | WindowProcessController proc, Intent intent, int userId) { |
| 5653 | if (proc == null) { |
| 5654 | return; |
| 5655 | } |
| 5656 | |
| 5657 | final INotificationManager inm = NotificationManager.getService(); |
| 5658 | if (inm == null) { |
| 5659 | return; |
| 5660 | } |
| 5661 | |
| 5662 | try { |
| 5663 | Context context = mContext.createPackageContext(proc.mInfo.packageName, 0); |
| 5664 | String text = mContext.getString(R.string.heavy_weight_notification, |
| 5665 | context.getApplicationInfo().loadLabel(context.getPackageManager())); |
| 5666 | Notification notification = |
| 5667 | new Notification.Builder(context, |
| 5668 | SystemNotificationChannels.HEAVY_WEIGHT_APP) |
| 5669 | .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) |
| 5670 | .setWhen(0) |
| 5671 | .setOngoing(true) |
| 5672 | .setTicker(text) |
| 5673 | .setColor(mContext.getColor( |
| 5674 | com.android.internal.R.color.system_notification_accent_color)) |
| 5675 | .setContentTitle(text) |
| 5676 | .setContentText( |
| 5677 | mContext.getText(R.string.heavy_weight_notification_detail)) |
| 5678 | .setContentIntent(PendingIntent.getActivityAsUser(mContext, 0, |
| 5679 | intent, PendingIntent.FLAG_CANCEL_CURRENT, null, |
| 5680 | new UserHandle(userId))) |
| 5681 | .build(); |
| 5682 | try { |
| 5683 | inm.enqueueNotificationWithTag("android", "android", null, |
| 5684 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, notification, userId); |
| 5685 | } catch (RuntimeException e) { |
| 5686 | Slog.w(TAG, "Error showing notification for heavy-weight app", e); |
| 5687 | } catch (RemoteException e) { |
| 5688 | } |
| 5689 | } catch (PackageManager.NameNotFoundException e) { |
| 5690 | Slog.w(TAG, "Unable to create context for heavy notification", e); |
| 5691 | } |
| 5692 | |
| 5693 | } |
| 5694 | |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 5695 | IIntentSender getIntentSenderLocked(int type, String packageName, String featureId, |
| 5696 | int callingUid, int userId, IBinder token, String resultWho, int requestCode, |
| 5697 | Intent[] intents, String[] resolvedTypes, int flags, Bundle bOptions) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5698 | |
| 5699 | ActivityRecord activity = null; |
| 5700 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5701 | activity = ActivityRecord.isInStackLocked(token); |
| 5702 | if (activity == null) { |
| 5703 | Slog.w(TAG, "Failed createPendingResult: activity " + token + " not in any stack"); |
| 5704 | return null; |
| 5705 | } |
| 5706 | if (activity.finishing) { |
| 5707 | Slog.w(TAG, "Failed createPendingResult: activity " + activity + " is finishing"); |
| 5708 | return null; |
| 5709 | } |
| 5710 | } |
| 5711 | |
| 5712 | final PendingIntentRecord rec = mPendingIntentController.getIntentSender(type, packageName, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 5713 | featureId, callingUid, userId, token, resultWho, requestCode, intents, |
| 5714 | resolvedTypes, flags, bOptions); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5715 | final boolean noCreate = (flags & PendingIntent.FLAG_NO_CREATE) != 0; |
| 5716 | if (noCreate) { |
| 5717 | return rec; |
| 5718 | } |
| 5719 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5720 | if (activity.pendingResults == null) { |
| 5721 | activity.pendingResults = new HashSet<>(); |
| 5722 | } |
| 5723 | activity.pendingResults.add(rec.ref); |
| 5724 | } |
| 5725 | return rec; |
| 5726 | } |
| 5727 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 5728 | // 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] | 5729 | private void startTimeTrackingFocusedActivityLocked() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5730 | final ActivityRecord resumedActivity = mRootWindowContainer.getTopResumedActivity(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5731 | if (!mSleeping && mCurAppTimeTracker != null && resumedActivity != null) { |
| 5732 | mCurAppTimeTracker.start(resumedActivity.packageName); |
| 5733 | } |
| 5734 | } |
| 5735 | |
| 5736 | private void updateResumedAppTrace(@Nullable ActivityRecord resumed) { |
| 5737 | if (mTracedResumedActivity != null) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5738 | Trace.asyncTraceEnd(TRACE_TAG_WINDOW_MANAGER, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5739 | constructResumedTraceName(mTracedResumedActivity.packageName), 0); |
| 5740 | } |
| 5741 | if (resumed != null) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5742 | Trace.asyncTraceBegin(TRACE_TAG_WINDOW_MANAGER, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5743 | constructResumedTraceName(resumed.packageName), 0); |
| 5744 | } |
| 5745 | mTracedResumedActivity = resumed; |
| 5746 | } |
| 5747 | |
| 5748 | private String constructResumedTraceName(String packageName) { |
| 5749 | return "focused app: " + packageName; |
| 5750 | } |
| 5751 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5752 | /** Applies latest configuration and/or visibility updates if needed. */ |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5753 | boolean ensureConfigAndVisibilityAfterUpdate(ActivityRecord starting, int changes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5754 | boolean kept = true; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5755 | final ActivityStack mainStack = mRootWindowContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5756 | // mainStack is null during startup. |
| 5757 | if (mainStack != null) { |
| 5758 | if (changes != 0 && starting == null) { |
| 5759 | // If the configuration changed, and the caller is not already |
| 5760 | // in the process of starting an activity, then find the top |
| 5761 | // activity to check if its configuration needs to change. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 5762 | starting = mainStack.topRunningActivity(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5763 | } |
| 5764 | |
| 5765 | if (starting != null) { |
| 5766 | kept = starting.ensureActivityConfiguration(changes, |
| 5767 | false /* preserveWindow */); |
| 5768 | // And we need to make sure at this point that all other activities |
| 5769 | // are made visible with the correct configuration. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5770 | mRootWindowContainer.ensureActivitiesVisible(starting, changes, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5771 | !PRESERVE_WINDOWS); |
| 5772 | } |
| 5773 | } |
| 5774 | |
| 5775 | return kept; |
| 5776 | } |
| 5777 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5778 | void scheduleAppGcsLocked() { |
| 5779 | mH.post(() -> mAmInternal.scheduleAppGcs()); |
| 5780 | } |
| 5781 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5782 | CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) { |
| 5783 | return mCompatModePackages.compatibilityInfoForPackageLocked(ai); |
| 5784 | } |
| 5785 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5786 | /** |
| 5787 | * Returns the PackageManager. Used by classes hosted by {@link ActivityTaskManagerService}. The |
| 5788 | * PackageManager could be unavailable at construction time and therefore needs to be accessed |
| 5789 | * on demand. |
| 5790 | */ |
| 5791 | IPackageManager getPackageManager() { |
| 5792 | return AppGlobals.getPackageManager(); |
| 5793 | } |
| 5794 | |
| 5795 | PackageManagerInternal getPackageManagerInternalLocked() { |
| 5796 | if (mPmInternal == null) { |
| 5797 | mPmInternal = LocalServices.getService(PackageManagerInternal.class); |
| 5798 | } |
| 5799 | return mPmInternal; |
| 5800 | } |
| 5801 | |
Darryl L Johnson | a098222 | 2020-02-18 18:21:51 -0800 | [diff] [blame] | 5802 | ComponentName getSysUiServiceComponentLocked() { |
| 5803 | if (mSysUiServiceComponent == null) { |
| 5804 | final PackageManagerInternal pm = getPackageManagerInternalLocked(); |
| 5805 | mSysUiServiceComponent = pm.getSystemUiServiceComponent(); |
| 5806 | } |
| 5807 | return mSysUiServiceComponent; |
| 5808 | } |
| 5809 | |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 5810 | PermissionPolicyInternal getPermissionPolicyInternal() { |
| 5811 | if (mPermissionPolicyInternal == null) { |
| 5812 | mPermissionPolicyInternal = LocalServices.getService(PermissionPolicyInternal.class); |
| 5813 | } |
| 5814 | return mPermissionPolicyInternal; |
| 5815 | } |
| 5816 | |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 5817 | AppWarnings getAppWarningsLocked() { |
| 5818 | return mAppWarnings; |
| 5819 | } |
| 5820 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5821 | Intent getHomeIntent() { |
| 5822 | Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null); |
| 5823 | intent.setComponent(mTopComponent); |
| 5824 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5825 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5826 | intent.addCategory(Intent.CATEGORY_HOME); |
| 5827 | } |
| 5828 | return intent; |
| 5829 | } |
| 5830 | |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5831 | /** |
| 5832 | * Return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} to resolve secondary home |
| 5833 | * activities. |
| 5834 | * |
Chilun | 939b05c | 2020-02-19 14:50:59 +0800 | [diff] [blame] | 5835 | * @param preferredPackage Specify a preferred package name, otherwise use the package name |
| 5836 | * defined in config_secondaryHomePackage. |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5837 | * @return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} |
| 5838 | */ |
| 5839 | Intent getSecondaryHomeIntent(String preferredPackage) { |
| 5840 | 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] | 5841 | final boolean useSystemProvidedLauncher = mContext.getResources().getBoolean( |
| 5842 | com.android.internal.R.bool.config_useSystemProvidedLauncherForSecondary); |
| 5843 | if (preferredPackage == null || useSystemProvidedLauncher) { |
Chilun | 939b05c | 2020-02-19 14:50:59 +0800 | [diff] [blame] | 5844 | // Using the package name stored in config if no preferred package name or forced. |
| 5845 | final String secondaryHomePackage = mContext.getResources().getString( |
| 5846 | com.android.internal.R.string.config_secondaryHomePackage); |
| 5847 | intent.setPackage(secondaryHomePackage); |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5848 | } else { |
| 5849 | intent.setPackage(preferredPackage); |
| 5850 | } |
| 5851 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5852 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5853 | intent.addCategory(Intent.CATEGORY_SECONDARY_HOME); |
| 5854 | } |
| 5855 | return intent; |
| 5856 | } |
| 5857 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5858 | ApplicationInfo getAppInfoForUser(ApplicationInfo info, int userId) { |
| 5859 | if (info == null) return null; |
| 5860 | ApplicationInfo newInfo = new ApplicationInfo(info); |
| 5861 | newInfo.initForUser(userId); |
| 5862 | return newInfo; |
| 5863 | } |
| 5864 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 5865 | WindowProcessController getProcessController(String processName, int uid) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5866 | if (uid == SYSTEM_UID) { |
| 5867 | // The system gets to run in any process. If there are multiple processes with the same |
| 5868 | // uid, just pick the first (this should never happen). |
| 5869 | final SparseArray<WindowProcessController> procs = |
| 5870 | mProcessNames.getMap().get(processName); |
| 5871 | if (procs == null) return null; |
| 5872 | final int procCount = procs.size(); |
| 5873 | for (int i = 0; i < procCount; i++) { |
| 5874 | final int procUid = procs.keyAt(i); |
| 5875 | if (UserHandle.isApp(procUid) || !UserHandle.isSameUser(procUid, uid)) { |
| 5876 | // Don't use an app process or different user process for system component. |
| 5877 | continue; |
| 5878 | } |
| 5879 | return procs.valueAt(i); |
| 5880 | } |
| 5881 | } |
| 5882 | |
| 5883 | return mProcessNames.get(processName, uid); |
| 5884 | } |
| 5885 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5886 | WindowProcessController getProcessController(IApplicationThread thread) { |
| 5887 | if (thread == null) { |
| 5888 | return null; |
| 5889 | } |
| 5890 | |
| 5891 | final IBinder threadBinder = thread.asBinder(); |
| 5892 | final ArrayMap<String, SparseArray<WindowProcessController>> pmap = mProcessNames.getMap(); |
| 5893 | for (int i = pmap.size()-1; i >= 0; i--) { |
| 5894 | final SparseArray<WindowProcessController> procs = pmap.valueAt(i); |
| 5895 | for (int j = procs.size() - 1; j >= 0; j--) { |
| 5896 | final WindowProcessController proc = procs.valueAt(j); |
| 5897 | if (proc.hasThread() && proc.getThread().asBinder() == threadBinder) { |
| 5898 | return proc; |
| 5899 | } |
| 5900 | } |
| 5901 | } |
| 5902 | |
| 5903 | return null; |
| 5904 | } |
| 5905 | |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 5906 | WindowProcessController getProcessController(int pid, int uid) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 5907 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Yunfan Chen | 8546b21 | 2019-04-01 15:34:44 +0900 | [diff] [blame] | 5908 | if (proc == null) return null; |
| 5909 | if (UserHandle.isApp(uid) && proc.mUid == uid) { |
| 5910 | return proc; |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 5911 | } |
| 5912 | return null; |
| 5913 | } |
| 5914 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 5915 | int getUidState(int uid) { |
| 5916 | return mActiveUids.getUidState(uid); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 5917 | } |
| 5918 | |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 5919 | boolean isUidForeground(int uid) { |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 5920 | // A uid is considered to be foreground if it has a visible non-toast window. |
| 5921 | return mWindowManager.mRoot.isAnyNonToastWindowVisibleForUid(uid); |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 5922 | } |
| 5923 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 5924 | boolean isDeviceOwner(int uid) { |
| 5925 | return uid >= 0 && mDeviceOwnerUid == uid; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 5926 | } |
| 5927 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 5928 | void setDeviceOwnerUid(int uid) { |
| 5929 | mDeviceOwnerUid = uid; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 5930 | } |
| 5931 | |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 5932 | /** |
| 5933 | * @return whitelist tag for a uid from mPendingTempWhitelist, null if not currently on |
| 5934 | * the whitelist |
| 5935 | */ |
| 5936 | String getPendingTempWhitelistTagForUidLocked(int uid) { |
| 5937 | return mPendingTempWhitelist.get(uid); |
| 5938 | } |
| 5939 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5940 | void logAppTooSlow(WindowProcessController app, long startTime, String msg) { |
| 5941 | if (true || Build.IS_USER) { |
| 5942 | return; |
| 5943 | } |
| 5944 | |
| 5945 | StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 5946 | StrictMode.allowThreadDiskWrites(); |
| 5947 | try { |
| 5948 | File tracesDir = new File("/data/anr"); |
| 5949 | File tracesFile = null; |
| 5950 | try { |
| 5951 | tracesFile = File.createTempFile("app_slow", null, tracesDir); |
| 5952 | |
| 5953 | StringBuilder sb = new StringBuilder(); |
Neil Fuller | 9774681 | 2019-08-19 14:20:50 +0100 | [diff] [blame] | 5954 | String timeString = |
| 5955 | TimeMigrationUtils.formatMillisWithFixedFormat(System.currentTimeMillis()); |
| 5956 | sb.append(timeString); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5957 | sb.append(": "); |
| 5958 | TimeUtils.formatDuration(SystemClock.uptimeMillis()-startTime, sb); |
| 5959 | sb.append(" since "); |
| 5960 | sb.append(msg); |
| 5961 | FileOutputStream fos = new FileOutputStream(tracesFile); |
| 5962 | fos.write(sb.toString().getBytes()); |
| 5963 | if (app == null) { |
| 5964 | fos.write("\n*** No application process!".getBytes()); |
| 5965 | } |
| 5966 | fos.close(); |
| 5967 | FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1); // -rw-rw-rw- |
| 5968 | } catch (IOException e) { |
| 5969 | Slog.w(TAG, "Unable to prepare slow app traces file: " + tracesFile, e); |
| 5970 | return; |
| 5971 | } |
| 5972 | |
| 5973 | if (app != null && app.getPid() > 0) { |
| 5974 | ArrayList<Integer> firstPids = new ArrayList<Integer>(); |
| 5975 | firstPids.add(app.getPid()); |
| 5976 | dumpStackTraces(tracesFile.getAbsolutePath(), firstPids, null, null); |
| 5977 | } |
| 5978 | |
| 5979 | File lastTracesFile = null; |
| 5980 | File curTracesFile = null; |
| 5981 | for (int i=9; i>=0; i--) { |
| 5982 | String name = String.format(Locale.US, "slow%02d.txt", i); |
| 5983 | curTracesFile = new File(tracesDir, name); |
| 5984 | if (curTracesFile.exists()) { |
| 5985 | if (lastTracesFile != null) { |
| 5986 | curTracesFile.renameTo(lastTracesFile); |
| 5987 | } else { |
| 5988 | curTracesFile.delete(); |
| 5989 | } |
| 5990 | } |
| 5991 | lastTracesFile = curTracesFile; |
| 5992 | } |
| 5993 | tracesFile.renameTo(curTracesFile); |
| 5994 | } finally { |
| 5995 | StrictMode.setThreadPolicy(oldPolicy); |
| 5996 | } |
| 5997 | } |
| 5998 | |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 5999 | boolean isAssociatedCompanionApp(int userId, int uid) { |
| 6000 | final Set<Integer> allUids = mCompanionAppUidsMap.get(userId); |
| 6001 | if (allUids == null) { |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 6002 | return false; |
| 6003 | } |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 6004 | return allUids.contains(uid); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 6005 | } |
| 6006 | |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 6007 | void notifySingleTaskDisplayEmpty(int displayId) { |
| 6008 | mTaskChangeNotificationController.notifySingleTaskDisplayEmpty(displayId); |
| 6009 | } |
| 6010 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6011 | final class H extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6012 | static final int REPORT_TIME_TRACKER_MSG = 1; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 6013 | |
| 6014 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 6015 | static final int FIRST_ACTIVITY_STACK_MSG = 100; |
| 6016 | static final int FIRST_SUPERVISOR_STACK_MSG = 200; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6017 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 6018 | H(Looper looper) { |
| 6019 | super(looper); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6020 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6021 | |
| 6022 | @Override |
| 6023 | public void handleMessage(Message msg) { |
| 6024 | switch (msg.what) { |
| 6025 | case REPORT_TIME_TRACKER_MSG: { |
| 6026 | AppTimeTracker tracker = (AppTimeTracker) msg.obj; |
| 6027 | tracker.deliverResult(mContext); |
| 6028 | } break; |
| 6029 | } |
| 6030 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6031 | } |
| 6032 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6033 | final class UiHandler extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6034 | static final int DISMISS_DIALOG_UI_MSG = 1; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6035 | |
| 6036 | public UiHandler() { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 6037 | super(UiThread.get().getLooper(), null, true); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6038 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6039 | |
| 6040 | @Override |
| 6041 | public void handleMessage(Message msg) { |
| 6042 | switch (msg.what) { |
| 6043 | case DISMISS_DIALOG_UI_MSG: { |
| 6044 | final Dialog d = (Dialog) msg.obj; |
| 6045 | d.dismiss(); |
| 6046 | break; |
| 6047 | } |
| 6048 | } |
| 6049 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6050 | } |
| 6051 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6052 | final class LocalService extends ActivityTaskManagerInternal { |
| 6053 | @Override |
| 6054 | public SleepToken acquireSleepToken(String tag, int displayId) { |
Daulet Zhanguzin | c6c641f | 2020-01-02 17:18:30 +0000 | [diff] [blame] | 6055 | Objects.requireNonNull(tag); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6056 | return ActivityTaskManagerService.this.acquireSleepToken(tag, displayId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6057 | } |
| 6058 | |
| 6059 | @Override |
| 6060 | public ComponentName getHomeActivityForUser(int userId) { |
| 6061 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6062 | final ActivityRecord homeActivity = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6063 | mRootWindowContainer.getDefaultDisplayHomeActivityForUser(userId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 6064 | return homeActivity == null ? null : homeActivity.mActivityComponent; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6065 | } |
| 6066 | } |
| 6067 | |
| 6068 | @Override |
| 6069 | public void onLocalVoiceInteractionStarted(IBinder activity, |
| 6070 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 6071 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6072 | onLocalVoiceInteractionStartedLocked(activity, voiceSession, voiceInteractor); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6073 | } |
| 6074 | } |
| 6075 | |
| 6076 | @Override |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 6077 | public void notifySingleTaskDisplayDrawn(int displayId) { |
| 6078 | mTaskChangeNotificationController.notifySingleTaskDisplayDrawn(displayId); |
| 6079 | } |
| 6080 | |
| 6081 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6082 | public void notifyAppTransitionFinished() { |
| 6083 | synchronized (mGlobalLock) { |
| 6084 | mStackSupervisor.notifyAppTransitionDone(); |
| 6085 | } |
| 6086 | } |
| 6087 | |
| 6088 | @Override |
| 6089 | public void notifyAppTransitionCancelled() { |
| 6090 | synchronized (mGlobalLock) { |
| 6091 | mStackSupervisor.notifyAppTransitionDone(); |
| 6092 | } |
| 6093 | } |
| 6094 | |
| 6095 | @Override |
| 6096 | public List<IBinder> getTopVisibleActivities() { |
| 6097 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6098 | return mRootWindowContainer.getTopVisibleActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6099 | } |
| 6100 | } |
| 6101 | |
| 6102 | @Override |
Bernardo Rufino | e6cb310 | 2020-03-06 20:33:11 +0000 | [diff] [blame] | 6103 | public boolean hasResumedActivity(int uid) { |
| 6104 | synchronized (mGlobalLock) { |
| 6105 | final ArraySet<WindowProcessController> processes = mProcessMap.getProcesses(uid); |
| 6106 | for (int i = 0, n = processes.size(); i < n; i++) { |
| 6107 | final WindowProcessController process = processes.valueAt(i); |
| 6108 | if (process.hasResumedActivity()) { |
| 6109 | return true; |
| 6110 | } |
| 6111 | } |
| 6112 | } |
| 6113 | return false; |
| 6114 | } |
| 6115 | |
| 6116 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6117 | public int startActivitiesAsPackage(String packageName, @Nullable String featureId, |
| 6118 | int userId, Intent[] intents, Bundle bOptions) { |
Daulet Zhanguzin | c6c641f | 2020-01-02 17:18:30 +0000 | [diff] [blame] | 6119 | Objects.requireNonNull(intents, "intents"); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6120 | final String[] resolvedTypes = new String[intents.length]; |
| 6121 | |
| 6122 | // UID of the package on user userId. |
| 6123 | // "= 0" is needed because otherwise catch(RemoteException) would make it look like |
| 6124 | // packageUid may not be initialized. |
| 6125 | int packageUid = 0; |
| 6126 | final long ident = Binder.clearCallingIdentity(); |
| 6127 | |
| 6128 | try { |
| 6129 | for (int i = 0; i < intents.length; i++) { |
| 6130 | resolvedTypes[i] = |
| 6131 | intents[i].resolveTypeIfNeeded(mContext.getContentResolver()); |
| 6132 | } |
| 6133 | |
| 6134 | packageUid = AppGlobals.getPackageManager().getPackageUid( |
| 6135 | packageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId); |
| 6136 | } catch (RemoteException e) { |
| 6137 | // Shouldn't happen. |
| 6138 | } finally { |
| 6139 | Binder.restoreCallingIdentity(ident); |
| 6140 | } |
| 6141 | |
Riddle Hsu | 591bf61 | 2019-02-14 17:55:31 +0800 | [diff] [blame] | 6142 | return getActivityStartController().startActivitiesInPackage( |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6143 | packageUid, packageName, featureId, |
Riddle Hsu | 591bf61 | 2019-02-14 17:55:31 +0800 | [diff] [blame] | 6144 | intents, resolvedTypes, null /* resultTo */, |
| 6145 | SafeActivityOptions.fromBundle(bOptions), userId, |
| 6146 | false /* validateIncomingUser */, null /* originatingPendingIntent */, |
| 6147 | false /* allowBackgroundActivityStart */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | @Override |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6151 | public int startActivitiesInPackage(int uid, int realCallingPid, int realCallingUid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6152 | String callingPackage, @Nullable String callingFeatureId, Intent[] intents, |
| 6153 | String[] resolvedTypes, IBinder resultTo, SafeActivityOptions options, int userId, |
| 6154 | boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6155 | boolean allowBackgroundActivityStart) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 6156 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6157 | synchronized (mGlobalLock) { |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6158 | return getActivityStartController().startActivitiesInPackage(uid, realCallingPid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6159 | realCallingUid, callingPackage, callingFeatureId, intents, resolvedTypes, |
| 6160 | resultTo, options, userId, validateIncomingUser, originatingPendingIntent, |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6161 | allowBackgroundActivityStart); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6162 | } |
| 6163 | } |
| 6164 | |
| 6165 | @Override |
| 6166 | public int startActivityInPackage(int uid, int realCallingPid, int realCallingUid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6167 | String callingPackage, @Nullable String callingFeatureId, Intent intent, |
| 6168 | String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 6169 | int startFlags, SafeActivityOptions options, int userId, Task inTask, String reason, |
| 6170 | boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6171 | boolean allowBackgroundActivityStart) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 6172 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6173 | synchronized (mGlobalLock) { |
| 6174 | return getActivityStartController().startActivityInPackage(uid, realCallingPid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6175 | realCallingUid, callingPackage, callingFeatureId, intent, resolvedType, |
| 6176 | resultTo, resultWho, requestCode, startFlags, options, userId, inTask, |
| 6177 | reason, validateIncomingUser, originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6178 | allowBackgroundActivityStart); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6179 | } |
| 6180 | } |
| 6181 | |
| 6182 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6183 | public int startActivityAsUser(IApplicationThread caller, String callerPackage, |
Alex Kershaw | 16406c3 | 2020-02-17 12:28:53 +0000 | [diff] [blame] | 6184 | @Nullable String callerFeatureId, Intent intent, @Nullable IBinder resultTo, |
| 6185 | int startFlags, Bundle options, int userId) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6186 | return ActivityTaskManagerService.this.startActivityAsUser( |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6187 | caller, callerPackage, callerFeatureId, intent, |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6188 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Alex Kershaw | 16406c3 | 2020-02-17 12:28:53 +0000 | [diff] [blame] | 6189 | resultTo, null, 0, startFlags, null, options, userId, |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6190 | false /*validateIncomingUser*/); |
| 6191 | } |
| 6192 | |
| 6193 | @Override |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 6194 | public void notifyKeyguardFlagsChanged(@Nullable Runnable callback, int displayId) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6195 | synchronized (mGlobalLock) { |
| 6196 | |
| 6197 | // We might change the visibilities here, so prepare an empty app transition which |
| 6198 | // might be overridden later if we actually change visibilities. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6199 | final DisplayContent displayContent = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6200 | mRootWindowContainer.getDisplayContent(displayId); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6201 | if (displayContent == null) { |
lumark | 52ea28e | 2018-11-09 17:30:47 +0800 | [diff] [blame] | 6202 | return; |
| 6203 | } |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6204 | final DisplayContent dc = displayContent.mDisplayContent; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6205 | final boolean wasTransitionSet = |
| 6206 | dc.mAppTransition.getAppTransition() != TRANSIT_NONE; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6207 | if (!wasTransitionSet) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6208 | dc.prepareAppTransition(TRANSIT_NONE, false /* alwaysKeepCurrent */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6209 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6210 | mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6211 | |
| 6212 | // If there was a transition set already we don't want to interfere with it as we |
| 6213 | // might be starting it too early. |
| 6214 | if (!wasTransitionSet) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6215 | dc.executeAppTransition(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6216 | } |
| 6217 | } |
| 6218 | if (callback != null) { |
| 6219 | callback.run(); |
| 6220 | } |
| 6221 | } |
| 6222 | |
| 6223 | @Override |
| 6224 | public void notifyKeyguardTrustedChanged() { |
| 6225 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6226 | if (mKeyguardController.isKeyguardShowing(DEFAULT_DISPLAY)) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6227 | mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6228 | } |
| 6229 | } |
| 6230 | } |
| 6231 | |
| 6232 | /** |
| 6233 | * Called after virtual display Id is updated by |
| 6234 | * {@link com.android.server.vr.Vr2dDisplay} with a specific |
| 6235 | * {@param vrVr2dDisplayId}. |
| 6236 | */ |
| 6237 | @Override |
| 6238 | public void setVr2dDisplayId(int vr2dDisplayId) { |
| 6239 | if (DEBUG_STACK) Slog.d(TAG, "setVr2dDisplayId called for: " + vr2dDisplayId); |
| 6240 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6241 | mVr2dDisplayId = vr2dDisplayId; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6242 | } |
| 6243 | } |
| 6244 | |
| 6245 | @Override |
| 6246 | public void setFocusedActivity(IBinder token) { |
| 6247 | synchronized (mGlobalLock) { |
| 6248 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 6249 | if (r == null) { |
| 6250 | throw new IllegalArgumentException( |
| 6251 | "setFocusedActivity: No activity record matching token=" + token); |
| 6252 | } |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 6253 | if (r.moveFocusableActivityToTop("setFocusedActivity")) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6254 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6255 | } |
| 6256 | } |
| 6257 | } |
| 6258 | |
| 6259 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6260 | public void registerScreenObserver(ScreenObserver observer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6261 | mScreenObservers.add(observer); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6262 | } |
| 6263 | |
| 6264 | @Override |
| 6265 | public boolean isCallerRecents(int callingUid) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 6266 | return getRecentTasks().isCallerRecents(callingUid); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6267 | } |
| 6268 | |
| 6269 | @Override |
| 6270 | public boolean isRecentsComponentHomeActivity(int userId) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 6271 | return getRecentTasks().isRecentsComponentHomeActivity(userId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6272 | } |
| 6273 | |
| 6274 | @Override |
| 6275 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
| 6276 | ActivityTaskManagerService.this.cancelRecentsAnimation(restoreHomeStackPosition); |
| 6277 | } |
| 6278 | |
| 6279 | @Override |
| 6280 | public void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6281 | ActivityTaskManagerService.this.enforceCallerIsRecentsOrHasPermission(permission, func); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6282 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6283 | |
| 6284 | @Override |
| 6285 | public void notifyActiveVoiceInteractionServiceChanged(ComponentName component) { |
| 6286 | synchronized (mGlobalLock) { |
| 6287 | mActiveVoiceInteractionServiceComponent = component; |
| 6288 | } |
| 6289 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6290 | |
| 6291 | @Override |
Galia Peycheva | 480275a | 2020-03-18 17:33:42 +0100 | [diff] [blame] | 6292 | public void notifyDreamStateChanged(boolean dreaming) { |
| 6293 | synchronized (mGlobalLock) { |
| 6294 | mDreaming = dreaming; |
| 6295 | } |
| 6296 | } |
| 6297 | |
| 6298 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6299 | public void setAllowAppSwitches(@NonNull String type, int uid, int userId) { |
| 6300 | if (!mAmInternal.isUserRunning(userId, ActivityManager.FLAG_OR_STOPPED)) { |
| 6301 | return; |
| 6302 | } |
| 6303 | synchronized (mGlobalLock) { |
| 6304 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(userId); |
| 6305 | if (types == null) { |
| 6306 | if (uid < 0) { |
| 6307 | return; |
| 6308 | } |
| 6309 | types = new ArrayMap<>(); |
| 6310 | mAllowAppSwitchUids.put(userId, types); |
| 6311 | } |
| 6312 | if (uid < 0) { |
| 6313 | types.remove(type); |
| 6314 | } else { |
| 6315 | types.put(type, uid); |
| 6316 | } |
| 6317 | } |
| 6318 | } |
| 6319 | |
| 6320 | @Override |
| 6321 | public void onUserStopped(int userId) { |
| 6322 | synchronized (mGlobalLock) { |
| 6323 | getRecentTasks().unloadUserDataFromMemoryLocked(userId); |
| 6324 | mAllowAppSwitchUids.remove(userId); |
| 6325 | } |
| 6326 | } |
| 6327 | |
| 6328 | @Override |
| 6329 | public boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 6330 | synchronized (mGlobalLock) { |
| 6331 | return ActivityTaskManagerService.this.isGetTasksAllowed( |
| 6332 | caller, callingPid, callingUid); |
| 6333 | } |
| 6334 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6335 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6336 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6337 | @Override |
| 6338 | public void onProcessAdded(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6339 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6340 | mProcessNames.put(proc.mName, proc.mUid, proc); |
| 6341 | } |
| 6342 | } |
| 6343 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6344 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6345 | @Override |
| 6346 | public void onProcessRemoved(String name, int uid) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6347 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6348 | mProcessNames.remove(name, uid); |
| 6349 | } |
| 6350 | } |
| 6351 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6352 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6353 | @Override |
| 6354 | public void onCleanUpApplicationRecord(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6355 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6356 | if (proc == mHomeProcess) { |
| 6357 | mHomeProcess = null; |
| 6358 | } |
| 6359 | if (proc == mPreviousProcess) { |
| 6360 | mPreviousProcess = null; |
| 6361 | } |
| 6362 | } |
| 6363 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6364 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6365 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6366 | @Override |
| 6367 | public int getTopProcessState() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6368 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6369 | return mTopProcessState; |
| 6370 | } |
| 6371 | } |
| 6372 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6373 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6374 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6375 | public boolean isHeavyWeightProcess(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6376 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6377 | return proc == mHeavyWeightProcess; |
| 6378 | } |
| 6379 | } |
| 6380 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6381 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6382 | @Override |
| 6383 | public void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6384 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6385 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals(proc); |
| 6386 | } |
| 6387 | } |
| 6388 | |
| 6389 | @Override |
| 6390 | public void finishHeavyWeightApp() { |
| 6391 | synchronized (mGlobalLock) { |
Sudheer Shanka | ee1da27 | 2018-10-20 20:11:44 -0700 | [diff] [blame] | 6392 | if (mHeavyWeightProcess != null) { |
| 6393 | mHeavyWeightProcess.finishActivities(); |
| 6394 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6395 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals( |
| 6396 | mHeavyWeightProcess); |
| 6397 | } |
| 6398 | } |
| 6399 | |
Galia Peycheva | 480275a | 2020-03-18 17:33:42 +0100 | [diff] [blame] | 6400 | @Override |
| 6401 | public boolean isDreaming() { |
| 6402 | synchronized (mGlobalLock) { |
| 6403 | return mDreaming; |
| 6404 | } |
| 6405 | } |
| 6406 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6407 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6408 | @Override |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6409 | public boolean isSleeping() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6410 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6411 | return isSleepingLocked(); |
| 6412 | } |
| 6413 | } |
| 6414 | |
| 6415 | @Override |
| 6416 | public boolean isShuttingDown() { |
| 6417 | synchronized (mGlobalLock) { |
| 6418 | return mShuttingDown; |
| 6419 | } |
| 6420 | } |
| 6421 | |
| 6422 | @Override |
| 6423 | public boolean shuttingDown(boolean booted, int timeout) { |
| 6424 | synchronized (mGlobalLock) { |
| 6425 | mShuttingDown = true; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6426 | mRootWindowContainer.prepareForShutdown(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6427 | updateEventDispatchingLocked(booted); |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 6428 | notifyTaskPersisterLocked(null, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6429 | return mStackSupervisor.shutdownLocked(timeout); |
| 6430 | } |
| 6431 | } |
| 6432 | |
| 6433 | @Override |
| 6434 | public void enableScreenAfterBoot(boolean booted) { |
| 6435 | synchronized (mGlobalLock) { |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 6436 | writeBootProgressEnableScreen(SystemClock.uptimeMillis()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6437 | mWindowManager.enableScreenAfterBoot(); |
| 6438 | updateEventDispatchingLocked(booted); |
| 6439 | } |
| 6440 | } |
| 6441 | |
| 6442 | @Override |
| 6443 | public boolean showStrictModeViolationDialog() { |
| 6444 | synchronized (mGlobalLock) { |
| 6445 | return mShowDialogs && !mSleeping && !mShuttingDown; |
| 6446 | } |
| 6447 | } |
| 6448 | |
| 6449 | @Override |
| 6450 | public void showSystemReadyErrorDialogsIfNeeded() { |
| 6451 | synchronized (mGlobalLock) { |
| 6452 | try { |
| 6453 | if (AppGlobals.getPackageManager().hasSystemUidErrors()) { |
| 6454 | Slog.e(TAG, "UIDs on the system are inconsistent, you need to wipe your" |
| 6455 | + " data partition or your device will be unstable."); |
| 6456 | mUiHandler.post(() -> { |
| 6457 | if (mShowDialogs) { |
| 6458 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6459 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6460 | d.setCancelable(false); |
| 6461 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6462 | d.setMessage(mUiContext.getText(R.string.system_error_wipe_data)); |
| 6463 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6464 | mUiContext.getText(R.string.ok), |
| 6465 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6466 | d.show(); |
| 6467 | } |
| 6468 | }); |
| 6469 | } |
| 6470 | } catch (RemoteException e) { |
| 6471 | } |
| 6472 | |
| 6473 | if (!Build.isBuildConsistent()) { |
| 6474 | Slog.e(TAG, "Build fingerprint is not consistent, warning user"); |
| 6475 | mUiHandler.post(() -> { |
| 6476 | if (mShowDialogs) { |
| 6477 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6478 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6479 | d.setCancelable(false); |
| 6480 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6481 | d.setMessage(mUiContext.getText(R.string.system_error_manufacturer)); |
| 6482 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6483 | mUiContext.getText(R.string.ok), |
| 6484 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6485 | d.show(); |
| 6486 | } |
| 6487 | }); |
| 6488 | } |
| 6489 | } |
| 6490 | } |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6491 | |
| 6492 | @Override |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6493 | public void onProcessMapped(int pid, WindowProcessController proc) { |
| 6494 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6495 | mProcessMap.put(pid, proc); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6496 | } |
| 6497 | } |
| 6498 | |
| 6499 | @Override |
| 6500 | public void onProcessUnMapped(int pid) { |
| 6501 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6502 | mProcessMap.remove(pid); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6503 | } |
| 6504 | } |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6505 | |
| 6506 | @Override |
| 6507 | public void onPackageDataCleared(String name) { |
| 6508 | synchronized (mGlobalLock) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6509 | mCompatModePackages.handlePackageDataClearedLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6510 | mAppWarnings.onPackageDataCleared(name); |
| 6511 | } |
| 6512 | } |
| 6513 | |
| 6514 | @Override |
| 6515 | public void onPackageUninstalled(String name) { |
| 6516 | synchronized (mGlobalLock) { |
| 6517 | mAppWarnings.onPackageUninstalled(name); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6518 | mCompatModePackages.handlePackageUninstalledLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6519 | } |
| 6520 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6521 | |
| 6522 | @Override |
| 6523 | public void onPackageAdded(String name, boolean replacing) { |
| 6524 | synchronized (mGlobalLock) { |
| 6525 | mCompatModePackages.handlePackageAddedLocked(name, replacing); |
| 6526 | } |
| 6527 | } |
| 6528 | |
| 6529 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6530 | public void onPackageReplaced(ApplicationInfo aInfo) { |
| 6531 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6532 | mRootWindowContainer.updateActivityApplicationInfo(aInfo); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6533 | } |
| 6534 | } |
| 6535 | |
| 6536 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6537 | public CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai) { |
| 6538 | synchronized (mGlobalLock) { |
| 6539 | return compatibilityInfoForPackageLocked(ai); |
| 6540 | } |
| 6541 | } |
| 6542 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6543 | /** |
| 6544 | * Set the corresponding display information for the process global configuration. To be |
| 6545 | * called when we need to show IME on a different display. |
| 6546 | * |
| 6547 | * @param pid The process id associated with the IME window. |
| 6548 | * @param displayId The ID of the display showing the IME. |
| 6549 | */ |
| 6550 | @Override |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6551 | public void onImeWindowSetOnDisplay(final int pid, final int displayId) { |
lumark | 4897353 | 2019-04-12 20:18:15 +0800 | [diff] [blame] | 6552 | // Don't update process-level configuration for Multi-Client IME process since other |
| 6553 | // IMEs on other displays will also receive this configuration change due to IME |
| 6554 | // services use the same application config/context. |
| 6555 | if (InputMethodSystemProperty.MULTI_CLIENT_IME_ENABLED) return; |
lumark | 5df4951 | 2019-04-02 14:56:46 +0800 | [diff] [blame] | 6556 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6557 | if (pid == MY_PID || pid < 0) { |
| 6558 | if (DEBUG_CONFIGURATION) { |
| 6559 | Slog.w(TAG, |
| 6560 | "Trying to update display configuration for system/invalid process."); |
| 6561 | } |
| 6562 | return; |
| 6563 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6564 | synchronized (mGlobalLock) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6565 | final DisplayContent displayContent = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6566 | mRootWindowContainer.getDisplayContent(displayId); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6567 | if (displayContent == null) { |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6568 | // Call might come when display is not yet added or has been removed. |
| 6569 | if (DEBUG_CONFIGURATION) { |
| 6570 | Slog.w(TAG, "Trying to update display configuration for non-existing " |
| 6571 | + "displayId=" + displayId); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6572 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6573 | return; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6574 | } |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6575 | final WindowProcessController process = mProcessMap.getProcess(pid); |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6576 | if (process == null) { |
| 6577 | if (DEBUG_CONFIGURATION) { |
| 6578 | Slog.w(TAG, "Trying to update display configuration for invalid " |
| 6579 | + "process, pid=" + pid); |
| 6580 | } |
| 6581 | return; |
| 6582 | } |
Andrii Kulian | fa23a9e | 2019-10-10 15:15:36 -0700 | [diff] [blame] | 6583 | process.registerDisplayConfigurationListener(displayContent); |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6584 | } |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6585 | } |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6586 | |
| 6587 | @Override |
| 6588 | public void sendActivityResult(int callingUid, IBinder activityToken, String resultWho, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 6589 | int requestCode, int resultCode, Intent data) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6590 | synchronized (mGlobalLock) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 6591 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 6592 | if (r != null && r.getRootTask() != null) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 6593 | r.sendResult(callingUid, resultWho, requestCode, resultCode, data); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6594 | } |
| 6595 | } |
| 6596 | } |
| 6597 | |
| 6598 | @Override |
| 6599 | public void clearPendingResultForActivity(IBinder activityToken, |
| 6600 | WeakReference<PendingIntentRecord> pir) { |
| 6601 | synchronized (mGlobalLock) { |
| 6602 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 6603 | if (r != null && r.pendingResults != null) { |
| 6604 | r.pendingResults.remove(pir); |
| 6605 | } |
| 6606 | } |
| 6607 | } |
| 6608 | |
| 6609 | @Override |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6610 | public ActivityTokens getTopActivityForTask(int taskId) { |
| 6611 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6612 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 6613 | if (task == null) { |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6614 | Slog.w(TAG, "getApplicationThreadForTopActivity failed:" |
| 6615 | + " Requested task not found"); |
| 6616 | return null; |
| 6617 | } |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 6618 | final ActivityRecord activity = task.getTopNonFinishingActivity(); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6619 | if (activity == null) { |
| 6620 | Slog.w(TAG, "getApplicationThreadForTopActivity failed:" |
| 6621 | + " Requested activity not found"); |
| 6622 | return null; |
| 6623 | } |
| 6624 | if (!activity.attachedToProcess()) { |
| 6625 | Slog.w(TAG, "getApplicationThreadForTopActivity failed: No process for " |
| 6626 | + activity); |
| 6627 | return null; |
| 6628 | } |
| 6629 | return new ActivityTokens(activity.appToken, activity.assistToken, |
| 6630 | activity.app.getThread()); |
| 6631 | } |
| 6632 | } |
| 6633 | |
| 6634 | @Override |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6635 | public IIntentSender getIntentSender(int type, String packageName, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6636 | @Nullable String featureId, int callingUid, int userId, IBinder token, |
| 6637 | String resultWho, int requestCode, Intent[] intents, String[] resolvedTypes, |
| 6638 | int flags, Bundle bOptions) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6639 | synchronized (mGlobalLock) { |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6640 | return getIntentSenderLocked(type, packageName, featureId, callingUid, userId, |
| 6641 | token, resultWho, requestCode, intents, resolvedTypes, flags, bOptions); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6642 | } |
| 6643 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 6644 | |
| 6645 | @Override |
| 6646 | public ActivityServiceConnectionsHolder getServiceConnectionsHolder(IBinder token) { |
| 6647 | synchronized (mGlobalLock) { |
| 6648 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 6649 | if (r == null) { |
| 6650 | return null; |
| 6651 | } |
| 6652 | if (r.mServiceConnectionsHolder == null) { |
| 6653 | r.mServiceConnectionsHolder = new ActivityServiceConnectionsHolder( |
| 6654 | ActivityTaskManagerService.this, r); |
| 6655 | } |
| 6656 | |
| 6657 | return r.mServiceConnectionsHolder; |
| 6658 | } |
| 6659 | } |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6660 | |
| 6661 | @Override |
| 6662 | public Intent getHomeIntent() { |
| 6663 | synchronized (mGlobalLock) { |
| 6664 | return ActivityTaskManagerService.this.getHomeIntent(); |
| 6665 | } |
| 6666 | } |
| 6667 | |
| 6668 | @Override |
| 6669 | public boolean startHomeActivity(int userId, String reason) { |
| 6670 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6671 | return mRootWindowContainer.startHomeOnDisplay(userId, reason, DEFAULT_DISPLAY); |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6672 | } |
| 6673 | } |
| 6674 | |
| 6675 | @Override |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 6676 | public boolean startHomeOnDisplay(int userId, String reason, int displayId, |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 6677 | boolean allowInstrumenting, boolean fromHomeKey) { |
Chilun | 5fd5654 | 2019-03-21 19:51:37 +0800 | [diff] [blame] | 6678 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6679 | return mRootWindowContainer.startHomeOnDisplay(userId, reason, displayId, |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 6680 | allowInstrumenting, fromHomeKey); |
Chilun | 5fd5654 | 2019-03-21 19:51:37 +0800 | [diff] [blame] | 6681 | } |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 6682 | } |
| 6683 | |
| 6684 | @Override |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6685 | public boolean startHomeOnAllDisplays(int userId, String reason) { |
| 6686 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6687 | return mRootWindowContainer.startHomeOnAllDisplays(userId, reason); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6688 | } |
| 6689 | } |
| 6690 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6691 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6692 | @Override |
| 6693 | public boolean isFactoryTestProcess(WindowProcessController wpc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6694 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6695 | if (mFactoryTest == FACTORY_TEST_OFF) { |
| 6696 | return false; |
| 6697 | } |
| 6698 | if (mFactoryTest == FACTORY_TEST_LOW_LEVEL && mTopComponent != null |
| 6699 | && wpc.mName.equals(mTopComponent.getPackageName())) { |
| 6700 | return true; |
| 6701 | } |
| 6702 | return mFactoryTest == FACTORY_TEST_HIGH_LEVEL |
| 6703 | && (wpc.mInfo.flags & FLAG_FACTORY_TEST) != 0; |
| 6704 | } |
| 6705 | } |
| 6706 | |
| 6707 | @Override |
| 6708 | public void updateTopComponentForFactoryTest() { |
| 6709 | synchronized (mGlobalLock) { |
| 6710 | if (mFactoryTest != FACTORY_TEST_LOW_LEVEL) { |
| 6711 | return; |
| 6712 | } |
| 6713 | final ResolveInfo ri = mContext.getPackageManager() |
| 6714 | .resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST), STOCK_PM_FLAGS); |
| 6715 | final CharSequence errorMsg; |
| 6716 | if (ri != null) { |
| 6717 | final ActivityInfo ai = ri.activityInfo; |
| 6718 | final ApplicationInfo app = ai.applicationInfo; |
| 6719 | if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 6720 | mTopAction = Intent.ACTION_FACTORY_TEST; |
| 6721 | mTopData = null; |
| 6722 | mTopComponent = new ComponentName(app.packageName, ai.name); |
| 6723 | errorMsg = null; |
| 6724 | } else { |
| 6725 | errorMsg = mContext.getResources().getText( |
| 6726 | com.android.internal.R.string.factorytest_not_system); |
| 6727 | } |
| 6728 | } else { |
| 6729 | errorMsg = mContext.getResources().getText( |
| 6730 | com.android.internal.R.string.factorytest_no_action); |
| 6731 | } |
| 6732 | if (errorMsg == null) { |
| 6733 | return; |
| 6734 | } |
| 6735 | |
| 6736 | mTopAction = null; |
| 6737 | mTopData = null; |
| 6738 | mTopComponent = null; |
| 6739 | mUiHandler.post(() -> { |
| 6740 | Dialog d = new FactoryErrorDialog(mUiContext, errorMsg); |
| 6741 | d.show(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 6742 | mAmInternal.ensureBootCompleted(); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6743 | }); |
| 6744 | } |
| 6745 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6746 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6747 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6748 | @Override |
| 6749 | public void handleAppDied(WindowProcessController wpc, boolean restarting, |
| 6750 | Runnable finishInstrumentationCallback) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6751 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6752 | // Remove this application's activities from active lists. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6753 | boolean hasVisibleActivities = mRootWindowContainer.handleAppDied(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6754 | |
| 6755 | wpc.clearRecentTasks(); |
| 6756 | wpc.clearActivities(); |
| 6757 | |
| 6758 | if (wpc.isInstrumenting()) { |
| 6759 | finishInstrumentationCallback.run(); |
| 6760 | } |
| 6761 | |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6762 | if (!restarting && hasVisibleActivities) { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 6763 | deferWindowLayout(); |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6764 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6765 | if (!mRootWindowContainer.resumeFocusedStacksTopActivities()) { |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6766 | // If there was nothing to resume, and we are not already restarting |
| 6767 | // this process, but there is a visible activity that is hosted by the |
| 6768 | // process...then make sure all visible activities are running, taking |
| 6769 | // care of restarting this process. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6770 | mRootWindowContainer.ensureActivitiesVisible(null, 0, |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6771 | !PRESERVE_WINDOWS); |
| 6772 | } |
| 6773 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 6774 | continueWindowLayout(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6775 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6776 | } |
| 6777 | } |
| 6778 | } |
| 6779 | |
| 6780 | @Override |
| 6781 | public void closeSystemDialogs(String reason) { |
| 6782 | enforceNotIsolatedCaller("closeSystemDialogs"); |
| 6783 | |
| 6784 | final int pid = Binder.getCallingPid(); |
| 6785 | final int uid = Binder.getCallingUid(); |
| 6786 | final long origId = Binder.clearCallingIdentity(); |
| 6787 | try { |
| 6788 | synchronized (mGlobalLock) { |
| 6789 | // Only allow this from foreground processes, so that background |
| 6790 | // applications can't abuse it to prevent system UI from being shown. |
| 6791 | if (uid >= FIRST_APPLICATION_UID) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6792 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6793 | if (!proc.isPerceptible()) { |
| 6794 | Slog.w(TAG, "Ignoring closeSystemDialogs " + reason |
| 6795 | + " from background process " + proc); |
| 6796 | return; |
| 6797 | } |
| 6798 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6799 | mWindowManager.closeSystemDialogs(reason); |
| 6800 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6801 | mRootWindowContainer.closeSystemDialogs(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6802 | } |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 6803 | // Call into AM outside the synchronized block. |
| 6804 | mAmInternal.broadcastCloseSystemDialogs(reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6805 | } finally { |
| 6806 | Binder.restoreCallingIdentity(origId); |
| 6807 | } |
| 6808 | } |
| 6809 | |
| 6810 | @Override |
| 6811 | public void cleanupDisabledPackageComponents( |
| 6812 | String packageName, Set<String> disabledClasses, int userId, boolean booted) { |
| 6813 | synchronized (mGlobalLock) { |
| 6814 | // Clean-up disabled activities. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6815 | if (mRootWindowContainer.finishDisabledPackageActivities( |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6816 | packageName, disabledClasses, true, false, userId) && booted) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6817 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 6818 | mStackSupervisor.scheduleIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6819 | } |
| 6820 | |
| 6821 | // Clean-up disabled tasks |
| 6822 | getRecentTasks().cleanupDisabledPackageTasksLocked( |
| 6823 | packageName, disabledClasses, userId); |
| 6824 | } |
| 6825 | } |
| 6826 | |
| 6827 | @Override |
| 6828 | public boolean onForceStopPackage(String packageName, boolean doit, boolean evenPersistent, |
| 6829 | int userId) { |
| 6830 | synchronized (mGlobalLock) { |
| 6831 | |
| 6832 | boolean didSomething = |
| 6833 | getActivityStartController().clearPendingActivityLaunches(packageName); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6834 | didSomething |= mRootWindowContainer.finishDisabledPackageActivities(packageName, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6835 | null, doit, evenPersistent, userId); |
| 6836 | return didSomething; |
| 6837 | } |
| 6838 | } |
| 6839 | |
| 6840 | @Override |
| 6841 | public void resumeTopActivities(boolean scheduleIdle) { |
| 6842 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6843 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6844 | if (scheduleIdle) { |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 6845 | mStackSupervisor.scheduleIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6846 | } |
| 6847 | } |
| 6848 | } |
| 6849 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6850 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6851 | @Override |
| 6852 | public void preBindApplication(WindowProcessController wpc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6853 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6854 | mStackSupervisor.getActivityMetricsLogger().notifyBindApplication(wpc.mInfo); |
| 6855 | } |
| 6856 | } |
| 6857 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6858 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6859 | @Override |
| 6860 | public boolean attachApplication(WindowProcessController wpc) throws RemoteException { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6861 | synchronized (mGlobalLockWithoutBoost) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 6862 | if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) { |
| 6863 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "attachApplication:" + wpc.mName); |
| 6864 | } |
| 6865 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6866 | return mRootWindowContainer.attachApplication(wpc); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 6867 | } finally { |
| 6868 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 6869 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6870 | } |
| 6871 | } |
| 6872 | |
| 6873 | @Override |
| 6874 | public void notifyLockedProfile(@UserIdInt int userId, int currentUserId) { |
| 6875 | try { |
| 6876 | if (!AppGlobals.getPackageManager().isUidPrivileged(Binder.getCallingUid())) { |
| 6877 | throw new SecurityException("Only privileged app can call notifyLockedProfile"); |
| 6878 | } |
| 6879 | } catch (RemoteException ex) { |
| 6880 | throw new SecurityException("Fail to check is caller a privileged app", ex); |
| 6881 | } |
| 6882 | |
| 6883 | synchronized (mGlobalLock) { |
| 6884 | final long ident = Binder.clearCallingIdentity(); |
| 6885 | try { |
| 6886 | if (mAmInternal.shouldConfirmCredentials(userId)) { |
| 6887 | if (mKeyguardController.isKeyguardLocked()) { |
| 6888 | // Showing launcher to avoid user entering credential twice. |
| 6889 | startHomeActivity(currentUserId, "notifyLockedProfile"); |
| 6890 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6891 | mRootWindowContainer.lockAllProfileTasks(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6892 | } |
| 6893 | } finally { |
| 6894 | Binder.restoreCallingIdentity(ident); |
| 6895 | } |
| 6896 | } |
| 6897 | } |
| 6898 | |
| 6899 | @Override |
| 6900 | public void startConfirmDeviceCredentialIntent(Intent intent, Bundle options) { |
| 6901 | mAmInternal.enforceCallingPermission( |
| 6902 | MANAGE_ACTIVITY_STACKS, "startConfirmDeviceCredentialIntent"); |
| 6903 | |
| 6904 | synchronized (mGlobalLock) { |
| 6905 | final long ident = Binder.clearCallingIdentity(); |
| 6906 | try { |
Pavel Grafov | c0fe0a0 | 2019-05-13 18:19:33 +0100 | [diff] [blame] | 6907 | intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 6908 | final ActivityOptions activityOptions = options != null |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6909 | ? new ActivityOptions(options) : ActivityOptions.makeBasic(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6910 | mContext.startActivityAsUser(intent, activityOptions.toBundle(), |
| 6911 | UserHandle.CURRENT); |
| 6912 | } finally { |
| 6913 | Binder.restoreCallingIdentity(ident); |
| 6914 | } |
| 6915 | } |
| 6916 | } |
| 6917 | |
| 6918 | @Override |
| 6919 | public void writeActivitiesToProto(ProtoOutputStream proto) { |
| 6920 | synchronized (mGlobalLock) { |
| 6921 | // The output proto of "activity --proto activities" |
Wale Ogunwale | f342f06 | 2020-01-27 07:34:13 -0800 | [diff] [blame] | 6922 | mRootWindowContainer.dumpDebug( |
| 6923 | proto, ROOT_WINDOW_CONTAINER, WindowTraceLogLevel.ALL); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6924 | } |
| 6925 | } |
| 6926 | |
| 6927 | @Override |
| 6928 | public void saveANRState(String reason) { |
| 6929 | synchronized (mGlobalLock) { |
| 6930 | final StringWriter sw = new StringWriter(); |
| 6931 | final PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
| 6932 | pw.println(" ANR time: " + DateFormat.getDateTimeInstance().format(new Date())); |
| 6933 | if (reason != null) { |
| 6934 | pw.println(" Reason: " + reason); |
| 6935 | } |
| 6936 | pw.println(); |
| 6937 | getActivityStartController().dump(pw, " ", null); |
| 6938 | pw.println(); |
| 6939 | pw.println("-------------------------------------------------------------------------------"); |
| 6940 | dumpActivitiesLocked(null /* fd */, pw, null /* args */, 0 /* opti */, |
| 6941 | true /* dumpAll */, false /* dumpClient */, null /* dumpPackage */, |
| 6942 | "" /* header */); |
| 6943 | pw.println(); |
| 6944 | pw.close(); |
| 6945 | |
| 6946 | mLastANRState = sw.toString(); |
| 6947 | } |
| 6948 | } |
| 6949 | |
| 6950 | @Override |
| 6951 | public void clearSavedANRState() { |
| 6952 | synchronized (mGlobalLock) { |
| 6953 | mLastANRState = null; |
| 6954 | } |
| 6955 | } |
| 6956 | |
| 6957 | @Override |
| 6958 | public void dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args, int opti, |
| 6959 | boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 6960 | synchronized (mGlobalLock) { |
| 6961 | if (DUMP_ACTIVITIES_CMD.equals(cmd) || DUMP_ACTIVITIES_SHORT_CMD.equals(cmd)) { |
| 6962 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage); |
| 6963 | } else if (DUMP_LASTANR_CMD.equals(cmd)) { |
| 6964 | dumpLastANRLocked(pw); |
| 6965 | } else if (DUMP_LASTANR_TRACES_CMD.equals(cmd)) { |
| 6966 | dumpLastANRTracesLocked(pw); |
| 6967 | } else if (DUMP_STARTER_CMD.equals(cmd)) { |
| 6968 | dumpActivityStarterLocked(pw, dumpPackage); |
| 6969 | } else if (DUMP_CONTAINERS_CMD.equals(cmd)) { |
| 6970 | dumpActivityContainersLocked(pw); |
| 6971 | } else if (DUMP_RECENTS_CMD.equals(cmd) || DUMP_RECENTS_SHORT_CMD.equals(cmd)) { |
| 6972 | if (getRecentTasks() != null) { |
| 6973 | getRecentTasks().dump(pw, dumpAll, dumpPackage); |
| 6974 | } |
| 6975 | } |
| 6976 | } |
| 6977 | } |
| 6978 | |
| 6979 | @Override |
| 6980 | public boolean dumpForProcesses(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 6981 | String dumpPackage, int dumpAppId, boolean needSep, boolean testPssMode, |
| 6982 | int wakefulness) { |
| 6983 | synchronized (mGlobalLock) { |
| 6984 | if (mHomeProcess != null && (dumpPackage == null |
| 6985 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
| 6986 | if (needSep) { |
| 6987 | pw.println(); |
| 6988 | needSep = false; |
| 6989 | } |
| 6990 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 6991 | } |
| 6992 | if (mPreviousProcess != null && (dumpPackage == null |
| 6993 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 6994 | if (needSep) { |
| 6995 | pw.println(); |
| 6996 | needSep = false; |
| 6997 | } |
| 6998 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 6999 | } |
| 7000 | if (dumpAll && (mPreviousProcess == null || dumpPackage == null |
| 7001 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 7002 | StringBuilder sb = new StringBuilder(128); |
| 7003 | sb.append(" mPreviousProcessVisibleTime: "); |
| 7004 | TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb); |
| 7005 | pw.println(sb); |
| 7006 | } |
| 7007 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 7008 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
| 7009 | if (needSep) { |
| 7010 | pw.println(); |
| 7011 | needSep = false; |
| 7012 | } |
| 7013 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 7014 | } |
| 7015 | if (dumpPackage == null) { |
| 7016 | pw.println(" mGlobalConfiguration: " + getGlobalConfiguration()); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7017 | mRootWindowContainer.dumpDisplayConfigs(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7018 | } |
| 7019 | if (dumpAll) { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 7020 | final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); |
| 7021 | if (dumpPackage == null && topFocusedStack != null) { |
| 7022 | pw.println(" mConfigWillChange: " + topFocusedStack.mConfigWillChange); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7023 | } |
| 7024 | if (mCompatModePackages.getPackages().size() > 0) { |
| 7025 | boolean printed = false; |
| 7026 | for (Map.Entry<String, Integer> entry |
| 7027 | : mCompatModePackages.getPackages().entrySet()) { |
| 7028 | String pkg = entry.getKey(); |
| 7029 | int mode = entry.getValue(); |
| 7030 | if (dumpPackage != null && !dumpPackage.equals(pkg)) { |
| 7031 | continue; |
| 7032 | } |
| 7033 | if (!printed) { |
| 7034 | pw.println(" mScreenCompatPackages:"); |
| 7035 | printed = true; |
| 7036 | } |
| 7037 | pw.println(" " + pkg + ": " + mode); |
| 7038 | } |
| 7039 | } |
| 7040 | } |
| 7041 | |
| 7042 | if (dumpPackage == null) { |
| 7043 | pw.println(" mWakefulness=" |
| 7044 | + PowerManagerInternal.wakefulnessToString(wakefulness)); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7045 | pw.println(" mSleepTokens=" + mRootWindowContainer.mSleepTokens); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7046 | if (mRunningVoice != null) { |
| 7047 | pw.println(" mRunningVoice=" + mRunningVoice); |
| 7048 | pw.println(" mVoiceWakeLock" + mVoiceWakeLock); |
| 7049 | } |
| 7050 | pw.println(" mSleeping=" + mSleeping); |
| 7051 | pw.println(" mShuttingDown=" + mShuttingDown + " mTestPssMode=" + testPssMode); |
| 7052 | pw.println(" mVrController=" + mVrController); |
| 7053 | } |
| 7054 | if (mCurAppTimeTracker != null) { |
| 7055 | mCurAppTimeTracker.dumpWithHeader(pw, " ", true); |
| 7056 | } |
| 7057 | if (mAllowAppSwitchUids.size() > 0) { |
| 7058 | boolean printed = false; |
| 7059 | for (int i = 0; i < mAllowAppSwitchUids.size(); i++) { |
| 7060 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.valueAt(i); |
| 7061 | for (int j = 0; j < types.size(); j++) { |
| 7062 | if (dumpPackage == null || |
| 7063 | UserHandle.getAppId(types.valueAt(j).intValue()) == dumpAppId) { |
| 7064 | if (needSep) { |
| 7065 | pw.println(); |
| 7066 | needSep = false; |
| 7067 | } |
| 7068 | if (!printed) { |
| 7069 | pw.println(" mAllowAppSwitchUids:"); |
| 7070 | printed = true; |
| 7071 | } |
| 7072 | pw.print(" User "); |
| 7073 | pw.print(mAllowAppSwitchUids.keyAt(i)); |
| 7074 | pw.print(": Type "); |
| 7075 | pw.print(types.keyAt(j)); |
| 7076 | pw.print(" = "); |
| 7077 | UserHandle.formatUid(pw, types.valueAt(j).intValue()); |
| 7078 | pw.println(); |
| 7079 | } |
| 7080 | } |
| 7081 | } |
| 7082 | } |
| 7083 | if (dumpPackage == null) { |
| 7084 | if (mController != null) { |
| 7085 | pw.println(" mController=" + mController |
| 7086 | + " mControllerIsAMonkey=" + mControllerIsAMonkey); |
| 7087 | } |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 7088 | pw.println(" mGoingToSleepWakeLock=" + mStackSupervisor.mGoingToSleepWakeLock); |
| 7089 | pw.println(" mLaunchingActivityWakeLock=" |
| 7090 | + mStackSupervisor.mLaunchingActivityWakeLock); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7091 | } |
| 7092 | |
| 7093 | return needSep; |
| 7094 | } |
| 7095 | } |
| 7096 | |
| 7097 | @Override |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7098 | public void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage, |
| 7099 | int wakeFullness, boolean testPssMode) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7100 | synchronized (mGlobalLock) { |
| 7101 | if (dumpPackage == null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7102 | getGlobalConfiguration().dumpDebug(proto, GLOBAL_CONFIGURATION); |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 7103 | final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); |
| 7104 | if (topFocusedStack != null) { |
| 7105 | proto.write(CONFIG_WILL_CHANGE, topFocusedStack.mConfigWillChange); |
| 7106 | } |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7107 | writeSleepStateToProto(proto, wakeFullness, testPssMode); |
| 7108 | if (mRunningVoice != null) { |
| 7109 | final long vrToken = proto.start( |
| 7110 | ActivityManagerServiceDumpProcessesProto.RUNNING_VOICE); |
| 7111 | proto.write(ActivityManagerServiceDumpProcessesProto.Voice.SESSION, |
| 7112 | mRunningVoice.toString()); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7113 | mVoiceWakeLock.dumpDebug( |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7114 | proto, ActivityManagerServiceDumpProcessesProto.Voice.WAKELOCK); |
| 7115 | proto.end(vrToken); |
| 7116 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7117 | mVrController.dumpDebug(proto, |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7118 | ActivityManagerServiceDumpProcessesProto.VR_CONTROLLER); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7119 | if (mController != null) { |
| 7120 | final long token = proto.start(CONTROLLER); |
Wally Yau | 0eb29f6 | 2020-01-08 10:16:43 -0800 | [diff] [blame] | 7121 | proto.write(ActivityManagerServiceDumpProcessesProto.Controller.CONTROLLER, |
| 7122 | mController.toString()); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7123 | proto.write(IS_A_MONKEY, mControllerIsAMonkey); |
| 7124 | proto.end(token); |
| 7125 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7126 | mStackSupervisor.mGoingToSleepWakeLock.dumpDebug(proto, GOING_TO_SLEEP); |
| 7127 | mStackSupervisor.mLaunchingActivityWakeLock.dumpDebug(proto, |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 7128 | LAUNCHING_ACTIVITY); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7129 | } |
| 7130 | |
| 7131 | if (mHomeProcess != null && (dumpPackage == null |
| 7132 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7133 | mHomeProcess.dumpDebug(proto, HOME_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7134 | } |
| 7135 | |
| 7136 | if (mPreviousProcess != null && (dumpPackage == null |
| 7137 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7138 | mPreviousProcess.dumpDebug(proto, PREVIOUS_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7139 | proto.write(PREVIOUS_PROC_VISIBLE_TIME_MS, mPreviousProcessVisibleTime); |
| 7140 | } |
| 7141 | |
| 7142 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 7143 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7144 | mHeavyWeightProcess.dumpDebug(proto, HEAVY_WEIGHT_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7145 | } |
| 7146 | |
| 7147 | for (Map.Entry<String, Integer> entry |
| 7148 | : mCompatModePackages.getPackages().entrySet()) { |
| 7149 | String pkg = entry.getKey(); |
| 7150 | int mode = entry.getValue(); |
| 7151 | if (dumpPackage == null || dumpPackage.equals(pkg)) { |
| 7152 | long compatToken = proto.start(SCREEN_COMPAT_PACKAGES); |
| 7153 | proto.write(PACKAGE, pkg); |
| 7154 | proto.write(MODE, mode); |
| 7155 | proto.end(compatToken); |
| 7156 | } |
| 7157 | } |
| 7158 | |
| 7159 | if (mCurAppTimeTracker != null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7160 | mCurAppTimeTracker.dumpDebug(proto, CURRENT_TRACKER, true); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7161 | } |
| 7162 | |
| 7163 | } |
| 7164 | } |
| 7165 | |
| 7166 | @Override |
| 7167 | public boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, |
| 7168 | String[] args, int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, |
| 7169 | boolean dumpFocusedStackOnly) { |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 7170 | return ActivityTaskManagerService.this.dumpActivity(fd, pw, name, args, opti, dumpAll, |
| 7171 | dumpVisibleStacksOnly, dumpFocusedStackOnly); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7172 | } |
| 7173 | |
| 7174 | @Override |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 7175 | public void dumpForOom(PrintWriter pw) { |
| 7176 | synchronized (mGlobalLock) { |
| 7177 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 7178 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 7179 | if (mHeavyWeightProcess != null) { |
| 7180 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 7181 | } |
| 7182 | } |
| 7183 | } |
| 7184 | |
| 7185 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7186 | public boolean canGcNow() { |
| 7187 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7188 | return isSleeping() || mRootWindowContainer.allResumedActivitiesIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7189 | } |
| 7190 | } |
| 7191 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7192 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7193 | @Override |
| 7194 | public WindowProcessController getTopApp() { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7195 | synchronized (mGlobalLockWithoutBoost) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7196 | if (mRootWindowContainer == null) { |
| 7197 | // Return null if mRootWindowContainer not yet initialize, while update |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 7198 | // oomadj after AMS created. |
| 7199 | return null; |
| 7200 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7201 | final ActivityRecord top = mRootWindowContainer.getTopResumedActivity(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7202 | return top != null ? top.app : null; |
| 7203 | } |
| 7204 | } |
| 7205 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7206 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7207 | @Override |
| 7208 | public void rankTaskLayersIfNeeded() { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7209 | synchronized (mGlobalLockWithoutBoost) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7210 | if (mRootWindowContainer != null) { |
| 7211 | mRootWindowContainer.rankTaskLayersIfNeeded(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7212 | } |
| 7213 | } |
| 7214 | } |
| 7215 | |
| 7216 | @Override |
| 7217 | public void scheduleDestroyAllActivities(String reason) { |
| 7218 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7219 | mRootWindowContainer.scheduleDestroyAllActivities(reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7220 | } |
| 7221 | } |
| 7222 | |
| 7223 | @Override |
| 7224 | public void removeUser(int userId) { |
| 7225 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7226 | mRootWindowContainer.removeUser(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7227 | } |
| 7228 | } |
| 7229 | |
| 7230 | @Override |
| 7231 | public boolean switchUser(int userId, UserState userState) { |
| 7232 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7233 | return mRootWindowContainer.switchUser(userId, userState); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7234 | } |
| 7235 | } |
| 7236 | |
| 7237 | @Override |
| 7238 | public void onHandleAppCrash(WindowProcessController wpc) { |
| 7239 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7240 | mRootWindowContainer.handleAppCrash(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7241 | } |
| 7242 | } |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 7243 | |
| 7244 | @Override |
| 7245 | public int finishTopCrashedActivities(WindowProcessController crashedApp, String reason) { |
| 7246 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7247 | return mRootWindowContainer.finishTopCrashedActivities(crashedApp, reason); |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 7248 | } |
| 7249 | } |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7250 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7251 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7252 | @Override |
| 7253 | public void onUidActive(int uid, int procState) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7254 | mActiveUids.onUidActive(uid, procState); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7255 | } |
| 7256 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7257 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7258 | @Override |
| 7259 | public void onUidInactive(int uid) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7260 | mActiveUids.onUidInactive(uid); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7261 | } |
| 7262 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7263 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7264 | @Override |
| 7265 | public void onActiveUidsCleared() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7266 | mActiveUids.onActiveUidsCleared(); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7267 | } |
| 7268 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7269 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7270 | @Override |
| 7271 | public void onUidProcStateChanged(int uid, int procState) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7272 | mActiveUids.onUidProcStateChanged(uid, procState); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7273 | } |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7274 | |
| 7275 | @Override |
| 7276 | public void onUidAddedToPendingTempWhitelist(int uid, String tag) { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7277 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7278 | mPendingTempWhitelist.put(uid, tag); |
| 7279 | } |
| 7280 | } |
| 7281 | |
| 7282 | @Override |
| 7283 | public void onUidRemovedFromPendingTempWhitelist(int uid) { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7284 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7285 | mPendingTempWhitelist.remove(uid); |
| 7286 | } |
| 7287 | } |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 7288 | |
| 7289 | @Override |
| 7290 | public boolean handleAppCrashInActivityController(String processName, int pid, |
| 7291 | String shortMsg, String longMsg, long timeMillis, String stackTrace, |
| 7292 | Runnable killCrashingAppCallback) { |
| 7293 | synchronized (mGlobalLock) { |
| 7294 | if (mController == null) { |
| 7295 | return false; |
| 7296 | } |
| 7297 | |
| 7298 | try { |
| 7299 | if (!mController.appCrashed(processName, pid, shortMsg, longMsg, timeMillis, |
| 7300 | stackTrace)) { |
| 7301 | killCrashingAppCallback.run(); |
| 7302 | return true; |
| 7303 | } |
| 7304 | } catch (RemoteException e) { |
| 7305 | mController = null; |
| 7306 | Watchdog.getInstance().setActivityController(null); |
| 7307 | } |
| 7308 | return false; |
| 7309 | } |
| 7310 | } |
Wale Ogunwale | d7889f5 | 2018-10-25 11:03:20 -0700 | [diff] [blame] | 7311 | |
| 7312 | @Override |
| 7313 | public void removeRecentTasksByPackageName(String packageName, int userId) { |
| 7314 | synchronized (mGlobalLock) { |
| 7315 | mRecentTasks.removeTasksByPackageName(packageName, userId); |
| 7316 | } |
| 7317 | } |
| 7318 | |
| 7319 | @Override |
| 7320 | public void cleanupRecentTasksForUser(int userId) { |
| 7321 | synchronized (mGlobalLock) { |
| 7322 | mRecentTasks.cleanupLocked(userId); |
| 7323 | } |
| 7324 | } |
| 7325 | |
| 7326 | @Override |
| 7327 | public void loadRecentTasksForUser(int userId) { |
| 7328 | synchronized (mGlobalLock) { |
| 7329 | mRecentTasks.loadUserRecentsLocked(userId); |
| 7330 | } |
| 7331 | } |
| 7332 | |
| 7333 | @Override |
| 7334 | public void onPackagesSuspendedChanged(String[] packages, boolean suspended, int userId) { |
| 7335 | synchronized (mGlobalLock) { |
| 7336 | mRecentTasks.onPackagesSuspendedChanged(packages, suspended, userId); |
| 7337 | } |
| 7338 | } |
| 7339 | |
| 7340 | @Override |
| 7341 | public void flushRecentTasks() { |
| 7342 | mRecentTasks.flush(); |
| 7343 | } |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 7344 | |
| 7345 | @Override |
| 7346 | public WindowProcessController getHomeProcess() { |
| 7347 | synchronized (mGlobalLock) { |
| 7348 | return mHomeProcess; |
| 7349 | } |
| 7350 | } |
| 7351 | |
| 7352 | @Override |
| 7353 | public WindowProcessController getPreviousProcess() { |
| 7354 | synchronized (mGlobalLock) { |
| 7355 | return mPreviousProcess; |
| 7356 | } |
| 7357 | } |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 7358 | |
| 7359 | @Override |
| 7360 | public void clearLockedTasks(String reason) { |
| 7361 | synchronized (mGlobalLock) { |
| 7362 | getLockTaskController().clearLockedTasks(reason); |
| 7363 | } |
| 7364 | } |
| 7365 | |
| 7366 | @Override |
| 7367 | public void updateUserConfiguration() { |
| 7368 | synchronized (mGlobalLock) { |
| 7369 | final Configuration configuration = new Configuration(getGlobalConfiguration()); |
| 7370 | final int currentUserId = mAmInternal.getCurrentUserId(); |
| 7371 | Settings.System.adjustConfigurationForUser(mContext.getContentResolver(), |
| 7372 | configuration, currentUserId, Settings.System.canWrite(mContext)); |
| 7373 | updateConfigurationLocked(configuration, null /* starting */, |
| 7374 | false /* initLocale */, false /* persistent */, currentUserId, |
| 7375 | false /* deferResume */); |
| 7376 | } |
| 7377 | } |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 7378 | |
| 7379 | @Override |
| 7380 | public boolean canShowErrorDialogs() { |
| 7381 | synchronized (mGlobalLock) { |
| 7382 | return mShowDialogs && !mSleeping && !mShuttingDown |
| 7383 | && !mKeyguardController.isKeyguardOrAodShowing(DEFAULT_DISPLAY) |
| 7384 | && !hasUserRestriction(UserManager.DISALLOW_SYSTEM_ERROR_DIALOGS, |
| 7385 | mAmInternal.getCurrentUserId()) |
| 7386 | && !(UserManager.isDeviceInDemoMode(mContext) |
| 7387 | && mAmInternal.getCurrentUser().isDemo()); |
| 7388 | } |
| 7389 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 7390 | |
| 7391 | @Override |
| 7392 | public void setProfileApp(String profileApp) { |
| 7393 | synchronized (mGlobalLock) { |
| 7394 | mProfileApp = profileApp; |
| 7395 | } |
| 7396 | } |
| 7397 | |
| 7398 | @Override |
| 7399 | public void setProfileProc(WindowProcessController wpc) { |
| 7400 | synchronized (mGlobalLock) { |
| 7401 | mProfileProc = wpc; |
| 7402 | } |
| 7403 | } |
| 7404 | |
| 7405 | @Override |
| 7406 | public void setProfilerInfo(ProfilerInfo profilerInfo) { |
| 7407 | synchronized (mGlobalLock) { |
| 7408 | mProfilerInfo = profilerInfo; |
| 7409 | } |
| 7410 | } |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 7411 | |
| 7412 | @Override |
| 7413 | public ActivityMetricsLaunchObserverRegistry getLaunchObserverRegistry() { |
| 7414 | synchronized (mGlobalLock) { |
| 7415 | return mStackSupervisor.getActivityMetricsLogger().getLaunchObserverRegistry(); |
| 7416 | } |
| 7417 | } |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 7418 | |
| 7419 | @Override |
Zak Cohen | 84b4318 | 2020-03-09 14:36:01 -0700 | [diff] [blame] | 7420 | public ActivityManager.TaskSnapshot getTaskSnapshotBlocking( |
| 7421 | int taskId, boolean isLowResolution) { |
Peter Kalauskas | 4dc0460 | 2020-02-12 18:49:03 -0800 | [diff] [blame] | 7422 | return ActivityTaskManagerService.this.getTaskSnapshot(taskId, isLowResolution, |
Zak Cohen | 84b4318 | 2020-03-09 14:36:01 -0700 | [diff] [blame] | 7423 | true /* restoreFromDisk */); |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 7424 | } |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 7425 | |
| 7426 | @Override |
| 7427 | public boolean isUidForeground(int uid) { |
| 7428 | synchronized (mGlobalLock) { |
| 7429 | return ActivityTaskManagerService.this.isUidForeground(uid); |
| 7430 | } |
| 7431 | } |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7432 | |
| 7433 | @Override |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 7434 | public void setDeviceOwnerUid(int uid) { |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7435 | synchronized (mGlobalLock) { |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 7436 | ActivityTaskManagerService.this.setDeviceOwnerUid(uid); |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7437 | } |
| 7438 | } |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7439 | |
| 7440 | @Override |
| 7441 | public void setCompanionAppPackages(int userId, Set<String> companionAppPackages) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7442 | // Translate package names into UIDs |
| 7443 | final Set<Integer> result = new HashSet<>(); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7444 | for (String pkg : companionAppPackages) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7445 | final int uid = getPackageManagerInternalLocked().getPackageUid(pkg, 0, userId); |
| 7446 | if (uid >= 0) { |
| 7447 | result.add(uid); |
| 7448 | } |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7449 | } |
| 7450 | synchronized (mGlobalLock) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7451 | mCompanionAppUidsMap.put(userId, result); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7452 | } |
| 7453 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 7454 | } |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 7455 | } |