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; |
| 45 | import static android.content.pm.PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 46 | import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 47 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 48 | import static android.os.FactoryTest.FACTORY_TEST_HIGH_LEVEL; |
| 49 | import static android.os.FactoryTest.FACTORY_TEST_LOW_LEVEL; |
| 50 | import static android.os.FactoryTest.FACTORY_TEST_OFF; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 51 | import static android.os.Process.FIRST_APPLICATION_UID; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 52 | import static android.os.Process.SYSTEM_UID; |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 53 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 54 | import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 55 | import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_SIZECOMPAT_FREEFORM; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 56 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES; |
| 57 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RTL; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 58 | import static android.provider.Settings.Global.HIDE_ERROR_DIALOGS; |
| 59 | import static android.provider.Settings.System.FONT_SCALE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 60 | import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_APPLICATION; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 61 | import static android.text.format.DateUtils.MINUTE_IN_MILLIS; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 62 | import static android.view.Display.DEFAULT_DISPLAY; |
| 63 | import static android.view.Display.INVALID_DISPLAY; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 64 | import static android.view.WindowManager.TRANSIT_NONE; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 65 | |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 66 | import static com.android.server.am.ActivityManagerService.ANR_TRACE_DIR; |
| 67 | import static com.android.server.am.ActivityManagerService.MY_PID; |
| 68 | import static com.android.server.am.ActivityManagerService.STOCK_PM_FLAGS; |
| 69 | import static com.android.server.am.ActivityManagerService.dumpStackTraces; |
Wale Ogunwale | f342f06 | 2020-01-27 07:34:13 -0800 | [diff] [blame] | 70 | import static com.android.server.am.ActivityManagerServiceDumpActivitiesProto.ROOT_WINDOW_CONTAINER; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 71 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CONFIG_WILL_CHANGE; |
| 72 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CONTROLLER; |
| 73 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CURRENT_TRACKER; |
| 74 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.Controller.IS_A_MONKEY; |
| 75 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.GLOBAL_CONFIGURATION; |
| 76 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.GOING_TO_SLEEP; |
| 77 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HEAVY_WEIGHT_PROC; |
| 78 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HOME_PROC; |
| 79 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.LAUNCHING_ACTIVITY; |
| 80 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 81 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC_VISIBLE_TIME_MS; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 82 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.SCREEN_COMPAT_PACKAGES; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 83 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.MODE; |
| 84 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.PACKAGE; |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 85 | import static com.android.server.am.EventLogTags.writeBootProgressEnableScreen; |
| 86 | import static com.android.server.am.EventLogTags.writeConfigurationChanged; |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 87 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; |
| 88 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 89 | import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 90 | import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; |
| 91 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
| 92 | import static com.android.server.wm.ActivityStackSupervisor.REMOVE_FROM_RECENTS; |
| 93 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL; |
| 94 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONFIGURATION; |
| 95 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_FOCUS; |
| 96 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_IMMERSIVE; |
| 97 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_LOCKTASK; |
| 98 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STACK; |
| 99 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; |
| 100 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 101 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_VISIBILITY; |
| 102 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFIGURATION; |
| 103 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_FOCUS; |
| 104 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_IMMERSIVE; |
| 105 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_LOCKTASK; |
| 106 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; |
| 107 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; |
| 108 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_VISIBILITY; |
| 109 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 110 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 111 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_CONTENT; |
| 112 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_DATA; |
| 113 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_RECEIVER_EXTRAS; |
| 114 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_STRUCTURE; |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 115 | import static com.android.server.wm.ActivityTaskManagerService.H.REPORT_TIME_TRACKER_MSG; |
| 116 | import static com.android.server.wm.ActivityTaskManagerService.UiHandler.DISMISS_DIALOG_UI_MSG; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 117 | import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; |
| 118 | import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 119 | import static com.android.server.wm.RootWindowContainer.MATCH_TASK_IN_STACKS_ONLY; |
| 120 | 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] | 121 | import static com.android.server.wm.Task.LOCK_TASK_AUTH_DONT_LOCK; |
| 122 | import static com.android.server.wm.Task.REPARENT_KEEP_STACK_AT_FRONT; |
| 123 | import static com.android.server.wm.Task.REPARENT_LEAVE_STACK_IN_PLACE; |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 124 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 125 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 126 | import android.Manifest; |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 127 | import android.annotation.IntDef; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 128 | import android.annotation.NonNull; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 129 | import android.annotation.Nullable; |
| 130 | import android.annotation.UserIdInt; |
| 131 | import android.app.Activity; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 132 | import android.app.ActivityManager; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 133 | import android.app.ActivityManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 134 | import android.app.ActivityOptions; |
| 135 | import android.app.ActivityTaskManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 136 | import android.app.ActivityThread; |
| 137 | import android.app.AlertDialog; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 138 | import android.app.AppGlobals; |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 139 | import android.app.AppOpsManager; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 140 | import android.app.Dialog; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 141 | import android.app.IActivityController; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 142 | import android.app.IActivityTaskManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 143 | import android.app.IApplicationThread; |
| 144 | import android.app.IAssistDataReceiver; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 145 | import android.app.INotificationManager; |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 146 | import android.app.IRequestFinishCallback; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 147 | import android.app.ITaskStackListener; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 148 | import android.app.Notification; |
| 149 | import android.app.NotificationManager; |
| 150 | import android.app.PendingIntent; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 151 | import android.app.PictureInPictureParams; |
| 152 | import android.app.ProfilerInfo; |
| 153 | import android.app.RemoteAction; |
| 154 | import android.app.WaitResult; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 155 | import android.app.WindowConfiguration; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 156 | import android.app.admin.DevicePolicyCache; |
| 157 | import android.app.assist.AssistContent; |
| 158 | import android.app.assist.AssistStructure; |
jorgegil@google.com | 06bc323 | 2019-10-31 14:51:22 -0700 | [diff] [blame] | 159 | import android.app.servertransaction.ClientTransaction; |
| 160 | import android.app.servertransaction.EnterPipRequestedItem; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 161 | import android.app.usage.UsageStatsManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 162 | import android.content.ActivityNotFoundException; |
| 163 | import android.content.ComponentName; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 164 | import android.content.ContentResolver; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 165 | import android.content.Context; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 166 | import android.content.DialogInterface; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 167 | import android.content.IIntentSender; |
| 168 | import android.content.Intent; |
| 169 | import android.content.pm.ActivityInfo; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 170 | import android.content.pm.ApplicationInfo; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 171 | import android.content.pm.ConfigurationInfo; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 172 | import android.content.pm.IPackageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 173 | import android.content.pm.PackageManager; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 174 | import android.content.pm.PackageManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 175 | import android.content.pm.ParceledListSlice; |
| 176 | import android.content.pm.ResolveInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 177 | import android.content.res.CompatibilityInfo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 178 | import android.content.res.Configuration; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 179 | import android.content.res.Resources; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 180 | import android.database.ContentObserver; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 181 | import android.graphics.Bitmap; |
| 182 | import android.graphics.Point; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 183 | import android.graphics.Rect; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 184 | import android.metrics.LogMaker; |
| 185 | import android.net.Uri; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 186 | import android.os.Binder; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 187 | import android.os.Build; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 188 | import android.os.Bundle; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 189 | import android.os.FactoryTest; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 190 | import android.os.FileUtils; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 191 | import android.os.Handler; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 192 | import android.os.IBinder; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 193 | import android.os.IUserManager; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 194 | import android.os.LocaleList; |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 195 | import android.os.Looper; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 196 | import android.os.Message; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 197 | import android.os.PersistableBundle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 198 | import android.os.PowerManager; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 199 | import android.os.PowerManagerInternal; |
Marvin Ramin | 830d4e3 | 2019-03-12 13:16:58 +0100 | [diff] [blame] | 200 | import android.os.Process; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 201 | import android.os.RemoteException; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 202 | import android.os.ServiceManager; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 203 | import android.os.StrictMode; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 204 | import android.os.SystemClock; |
| 205 | import android.os.SystemProperties; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 206 | import android.os.Trace; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 207 | import android.os.UpdateLock; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 208 | import android.os.UserHandle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 209 | import android.os.UserManager; |
| 210 | import android.os.WorkSource; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 211 | import android.os.storage.IStorageManager; |
| 212 | import android.os.storage.StorageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 213 | import android.provider.Settings; |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 214 | import android.service.dreams.DreamActivity; |
Galia Peycheva | 52e8922 | 2020-02-18 23:41:43 +0100 | [diff] [blame] | 215 | import android.service.dreams.DreamManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 216 | import android.service.voice.IVoiceInteractionSession; |
| 217 | import android.service.voice.VoiceInteractionManagerInternal; |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 218 | import android.sysprop.DisplayProperties; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 219 | import android.telecom.TelecomManager; |
| 220 | import android.text.TextUtils; |
Neil Fuller | 9774681 | 2019-08-19 14:20:50 +0100 | [diff] [blame] | 221 | import android.text.format.TimeMigrationUtils; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 222 | import android.util.ArrayMap; |
Nicholas Sauer | 3f9249f | 2019-09-10 20:23:41 -0700 | [diff] [blame] | 223 | import android.util.ArraySet; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 224 | import android.util.Log; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 225 | import android.util.Slog; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 226 | import android.util.SparseArray; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 227 | import android.util.TimeUtils; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 228 | import android.util.proto.ProtoOutputStream; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 229 | import android.view.IRecentsAnimationRunner; |
| 230 | import android.view.RemoteAnimationAdapter; |
| 231 | import android.view.RemoteAnimationDefinition; |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 232 | import android.view.WindowManager; |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 233 | import android.window.IWindowOrganizerController; |
Wale Ogunwale | 5794658 | 2020-03-21 14:29:07 -0700 | [diff] [blame] | 234 | import android.window.WindowContainerTransaction; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 235 | |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 236 | import com.android.internal.R; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 237 | import com.android.internal.annotations.VisibleForTesting; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 238 | import com.android.internal.app.AssistUtils; |
| 239 | import com.android.internal.app.IVoiceInteractor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 240 | import com.android.internal.app.ProcessMap; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 241 | import com.android.internal.logging.MetricsLogger; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 242 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 243 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
| 244 | import com.android.internal.notification.SystemNotificationChannels; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 245 | import com.android.internal.os.TransferPipe; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 246 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 247 | import com.android.internal.policy.IKeyguardDismissCallback; |
| 248 | import com.android.internal.policy.KeyguardDismissCallback; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 249 | import com.android.internal.util.ArrayUtils; |
| 250 | import com.android.internal.util.FastPrintWriter; |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 251 | import com.android.internal.util.FrameworkStatsLog; |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 252 | import com.android.internal.util.function.pooled.PooledConsumer; |
| 253 | import com.android.internal.util.function.pooled.PooledFunction; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 254 | import com.android.internal.util.function.pooled.PooledLambda; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 255 | import com.android.server.AttributeCache; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 256 | import com.android.server.LocalServices; |
| 257 | import com.android.server.SystemService; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 258 | import com.android.server.SystemServiceManager; |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 259 | import com.android.server.UiThread; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 260 | import com.android.server.Watchdog; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 261 | import com.android.server.am.ActivityManagerService; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 262 | import com.android.server.am.ActivityManagerServiceDumpProcessesProto; |
| 263 | import com.android.server.am.AppTimeTracker; |
| 264 | import com.android.server.am.BaseErrorDialog; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 265 | import com.android.server.am.PendingIntentController; |
| 266 | import com.android.server.am.PendingIntentRecord; |
| 267 | import com.android.server.am.UserState; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 268 | import com.android.server.firewall.IntentFirewall; |
Tarandeep Singh | 07b318b | 2019-07-17 11:12:04 -0700 | [diff] [blame] | 269 | import com.android.server.inputmethod.InputMethodSystemProperty; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 270 | import com.android.server.pm.UserManagerService; |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 271 | import com.android.server.policy.PermissionPolicyInternal; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 272 | import com.android.server.uri.UriGrantsManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 273 | import com.android.server.vr.VrManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 274 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 275 | import java.io.BufferedReader; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 276 | import java.io.File; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 277 | import java.io.FileDescriptor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 278 | import java.io.FileOutputStream; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 279 | import java.io.FileReader; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 280 | import java.io.IOException; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 281 | import java.io.PrintWriter; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 282 | import java.io.StringWriter; |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 283 | import java.lang.annotation.ElementType; |
| 284 | import java.lang.annotation.Retention; |
| 285 | import java.lang.annotation.RetentionPolicy; |
| 286 | import java.lang.annotation.Target; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 287 | import java.lang.ref.WeakReference; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 288 | import java.text.DateFormat; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 289 | import java.util.ArrayList; |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 290 | import java.util.Arrays; |
Jeff Sharkey | 8b0cff7 | 2020-03-09 15:49:01 -0600 | [diff] [blame] | 291 | import java.util.Collection; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 292 | import java.util.Date; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 293 | import java.util.HashMap; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 294 | import java.util.HashSet; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 295 | import java.util.List; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 296 | import java.util.Locale; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 297 | import java.util.Map; |
Daulet Zhanguzin | c6c641f | 2020-01-02 17:18:30 +0000 | [diff] [blame] | 298 | import java.util.Objects; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 299 | import java.util.Set; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 300 | |
| 301 | /** |
| 302 | * System service for managing activities and their containers (task, stacks, displays,... ). |
| 303 | * |
| 304 | * {@hide} |
| 305 | */ |
| 306 | public class ActivityTaskManagerService extends IActivityTaskManager.Stub { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 307 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityTaskManagerService" : TAG_ATM; |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 308 | static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 309 | static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 310 | private static final String TAG_IMMERSIVE = TAG + POSTFIX_IMMERSIVE; |
| 311 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
| 312 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
| 313 | private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 314 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 315 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 316 | // How long we wait until we timeout on key dispatching. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 317 | public static final int KEY_DISPATCHING_TIMEOUT_MS = 5 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 318 | // How long we wait until we timeout on key dispatching during instrumentation. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 319 | static final int INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT_MS = 60 * 1000; |
Michal Karpinski | fc6872e | 2019-05-21 15:18:44 +0100 | [diff] [blame] | 320 | // How long we permit background activity starts after an activity in the process |
| 321 | // started or finished. |
| 322 | static final long ACTIVITY_BG_START_GRACE_PERIOD_MS = 10 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 323 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 324 | /** Used to indicate that an app transition should be animated. */ |
| 325 | static final boolean ANIMATE = true; |
| 326 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 327 | /** Hardware-reported OpenGLES version. */ |
| 328 | final int GL_ES_VERSION; |
| 329 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 330 | public static final String DUMP_ACTIVITIES_CMD = "activities" ; |
| 331 | public static final String DUMP_ACTIVITIES_SHORT_CMD = "a" ; |
| 332 | public static final String DUMP_LASTANR_CMD = "lastanr" ; |
| 333 | public static final String DUMP_LASTANR_TRACES_CMD = "lastanr-traces" ; |
| 334 | public static final String DUMP_STARTER_CMD = "starter" ; |
| 335 | public static final String DUMP_CONTAINERS_CMD = "containers" ; |
| 336 | public static final String DUMP_RECENTS_CMD = "recents" ; |
| 337 | public static final String DUMP_RECENTS_SHORT_CMD = "r" ; |
| 338 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 339 | /** This activity is not being relaunched, or being relaunched for a non-resize reason. */ |
| 340 | public static final int RELAUNCH_REASON_NONE = 0; |
| 341 | /** This activity is being relaunched due to windowing mode change. */ |
| 342 | public static final int RELAUNCH_REASON_WINDOWING_MODE_RESIZE = 1; |
| 343 | /** This activity is being relaunched due to a free-resize operation. */ |
| 344 | public static final int RELAUNCH_REASON_FREE_RESIZE = 2; |
| 345 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 346 | Context mContext; |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 347 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 348 | /** |
| 349 | * This Context is themable and meant for UI display (AlertDialogs, etc.). The theme can |
| 350 | * change at runtime. Use mContext for non-UI purposes. |
| 351 | */ |
| 352 | final Context mUiContext; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 353 | final ActivityThread mSystemThread; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 354 | H mH; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 355 | UiHandler mUiHandler; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 356 | ActivityManagerInternal mAmInternal; |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 357 | UriGrantsManagerInternal mUgmInternal; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 358 | private PackageManagerInternal mPmInternal; |
Darryl L Johnson | a098222 | 2020-02-18 18:21:51 -0800 | [diff] [blame] | 359 | /** The cached sys ui service component name from package manager. */ |
| 360 | private ComponentName mSysUiServiceComponent; |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 361 | private PermissionPolicyInternal mPermissionPolicyInternal; |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 362 | @VisibleForTesting |
| 363 | final ActivityTaskManagerInternal mInternal; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 364 | PowerManagerInternal mPowerManagerInternal; |
| 365 | private UsageStatsManagerInternal mUsageStatsInternal; |
| 366 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 367 | PendingIntentController mPendingIntentController; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 368 | IntentFirewall mIntentFirewall; |
| 369 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 370 | /* Global service lock used by the package the owns this service. */ |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 371 | final WindowManagerGlobalLock mGlobalLock = new WindowManagerGlobalLock(); |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 372 | /** |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 373 | * 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] | 374 | * locked-region-code-injection does't recognize it. It is used to skip wrapping priority |
| 375 | * booster for places that are already in the scope of another booster (e.g. computing oom-adj). |
| 376 | * |
| 377 | * @see WindowManagerThreadPriorityBooster |
| 378 | */ |
| 379 | final Object mGlobalLockWithoutBoost = mGlobalLock; |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 380 | ActivityStackSupervisor mStackSupervisor; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 381 | RootWindowContainer mRootWindowContainer; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 382 | WindowManagerService mWindowManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 383 | private UserManagerService mUserManager; |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 384 | private AppOpsManager mAppOpsManager; |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 385 | /** All active uids in the system. */ |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 386 | private final MirrorActiveUids mActiveUids = new MirrorActiveUids(); |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 387 | private final SparseArray<String> mPendingTempWhitelist = new SparseArray<>(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 388 | /** All processes currently running that might have a window organized by name. */ |
| 389 | final ProcessMap<WindowProcessController> mProcessNames = new ProcessMap<>(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 390 | /** All processes we currently have running mapped by pid and uid */ |
| 391 | final WindowProcessControllerMap mProcessMap = new WindowProcessControllerMap(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 392 | /** This is the process holding what we currently consider to be the "home" activity. */ |
| 393 | WindowProcessController mHomeProcess; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 394 | /** The currently running heavy-weight process, if any. */ |
| 395 | WindowProcessController mHeavyWeightProcess = null; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 396 | boolean mHasHeavyWeightFeature; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 397 | /** |
| 398 | * This is the process holding the activity the user last visited that is in a different process |
| 399 | * from the one they are currently in. |
| 400 | */ |
| 401 | WindowProcessController mPreviousProcess; |
| 402 | /** The time at which the previous process was last visible. */ |
| 403 | long mPreviousProcessVisibleTime; |
| 404 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 405 | /** List of intents that were used to start the most recent tasks. */ |
| 406 | private RecentTasks mRecentTasks; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 407 | /** State of external calls telling us if the device is awake or asleep. */ |
| 408 | private boolean mKeyguardShown = false; |
| 409 | |
| 410 | // Wrapper around VoiceInteractionServiceManager |
| 411 | private AssistUtils mAssistUtils; |
| 412 | |
| 413 | // VoiceInteraction session ID that changes for each new request except when |
| 414 | // being called for multi-window assist in a single session. |
| 415 | private int mViSessionId = 1000; |
| 416 | |
| 417 | // How long to wait in getAssistContextExtras for the activity and foreground services |
| 418 | // to respond with the result. |
| 419 | private static final int PENDING_ASSIST_EXTRAS_TIMEOUT = 500; |
| 420 | |
| 421 | // How long top wait when going through the modern assist (which doesn't need to block |
| 422 | // on getting this result before starting to launch its UI). |
| 423 | private static final int PENDING_ASSIST_EXTRAS_LONG_TIMEOUT = 2000; |
| 424 | |
| 425 | // How long to wait in getAutofillAssistStructure() for the activity to respond with the result. |
| 426 | private static final int PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT = 2000; |
| 427 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 428 | // Permission tokens are used to temporarily granted a trusted app the ability to call |
| 429 | // #startActivityAsCaller. A client is expected to dump its token after this time has elapsed, |
| 430 | // showing any appropriate error messages to the user. |
| 431 | private static final long START_AS_CALLER_TOKEN_TIMEOUT = |
| 432 | 10 * MINUTE_IN_MILLIS; |
| 433 | |
| 434 | // How long before the service actually expires a token. This is slightly longer than |
| 435 | // START_AS_CALLER_TOKEN_TIMEOUT, to provide a buffer so clients will rarely encounter the |
| 436 | // expiration exception. |
| 437 | private static final long START_AS_CALLER_TOKEN_TIMEOUT_IMPL = |
| 438 | START_AS_CALLER_TOKEN_TIMEOUT + 2 * 1000; |
| 439 | |
| 440 | // How long the service will remember expired tokens, for the purpose of providing error |
| 441 | // messaging when a client uses an expired token. |
| 442 | private static final long START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT = |
| 443 | START_AS_CALLER_TOKEN_TIMEOUT_IMPL + 20 * MINUTE_IN_MILLIS; |
| 444 | |
| 445 | // Activity tokens of system activities that are delegating their call to |
| 446 | // #startActivityByCaller, keyed by the permissionToken granted to the delegate. |
| 447 | final HashMap<IBinder, IBinder> mStartActivitySources = new HashMap<>(); |
| 448 | |
| 449 | // Permission tokens that have expired, but we remember for error reporting. |
| 450 | final ArrayList<IBinder> mExpiredStartAsCallerTokens = new ArrayList<>(); |
| 451 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 452 | private final ArrayList<PendingAssistExtras> mPendingAssistExtras = new ArrayList<>(); |
| 453 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 454 | // Keeps track of the active voice interaction service component, notified from |
| 455 | // VoiceInteractionManagerService |
| 456 | ComponentName mActiveVoiceInteractionServiceComponent; |
| 457 | |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 458 | // A map userId and all its companion app uids |
| 459 | private final Map<Integer, Set<Integer>> mCompanionAppUidsMap = new ArrayMap<>(); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 460 | |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 461 | VrController mVrController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 462 | KeyguardController mKeyguardController; |
| 463 | private final ClientLifecycleManager mLifecycleManager; |
| 464 | private TaskChangeNotificationController mTaskChangeNotificationController; |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 465 | /** The controller for all operations related to locktask. */ |
| 466 | private LockTaskController mLockTaskController; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 467 | private ActivityStartController mActivityStartController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 468 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 469 | boolean mSuppressResizeConfigChanges; |
| 470 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 471 | final UpdateConfigurationResult mTmpUpdateConfigurationResult = |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 472 | new UpdateConfigurationResult(); |
| 473 | |
| 474 | static final class UpdateConfigurationResult { |
| 475 | // Configuration changes that were updated. |
| 476 | int changes; |
| 477 | // If the activity was relaunched to match the new configuration. |
| 478 | boolean activityRelaunched; |
| 479 | |
| 480 | void reset() { |
| 481 | changes = 0; |
| 482 | activityRelaunched = false; |
| 483 | } |
| 484 | } |
| 485 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 486 | /** Current sequencing integer of the configuration, for skipping old configurations. */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 487 | private int mConfigurationSeq; |
| 488 | // To cache the list of supported system locales |
| 489 | private String[] mSupportedSystemLocales = null; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 490 | |
| 491 | /** |
| 492 | * Temp object used when global and/or display override configuration is updated. It is also |
| 493 | * sent to outer world instead of {@link #getGlobalConfiguration} because we don't trust |
| 494 | * anyone... |
| 495 | */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 496 | private Configuration mTempConfig = new Configuration(); |
| 497 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 498 | /** Temporary to avoid allocations. */ |
| 499 | final StringBuilder mStringBuilder = new StringBuilder(256); |
| 500 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 501 | // Amount of time after a call to stopAppSwitches() during which we will |
| 502 | // prevent further untrusted switches from happening. |
| 503 | private static final long APP_SWITCH_DELAY_TIME = 5 * 1000; |
| 504 | |
| 505 | /** |
| 506 | * The time at which we will allow normal application switches again, |
| 507 | * after a call to {@link #stopAppSwitches()}. |
| 508 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 509 | private long mAppSwitchesAllowedTime; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 510 | /** |
| 511 | * This is set to true after the first switch after mAppSwitchesAllowedTime |
| 512 | * is set; any switches after that will clear the time. |
| 513 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 514 | private boolean mDidAppSwitch; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 515 | |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 516 | /** |
| 517 | * Last stop app switches time, apps finished before this time cannot start background activity |
| 518 | * even if they are in grace period. |
| 519 | */ |
| 520 | private long mLastStopAppSwitchesTime; |
| 521 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 522 | IActivityController mController = null; |
| 523 | boolean mControllerIsAMonkey = false; |
| 524 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 525 | final int mFactoryTest; |
| 526 | |
| 527 | /** Used to control how we initialize the service. */ |
| 528 | ComponentName mTopComponent; |
| 529 | String mTopAction = Intent.ACTION_MAIN; |
| 530 | String mTopData; |
| 531 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 532 | /** Profiling app information. */ |
| 533 | String mProfileApp = null; |
| 534 | WindowProcessController mProfileProc = null; |
| 535 | ProfilerInfo mProfilerInfo = null; |
| 536 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 537 | /** |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 538 | * Dump of the activity state at the time of the last ANR. Cleared after |
| 539 | * {@link WindowManagerService#LAST_ANR_LIFETIME_DURATION_MSECS} |
| 540 | */ |
| 541 | String mLastANRState; |
| 542 | |
| 543 | /** |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 544 | * Used to retain an update lock when the foreground activity is in |
| 545 | * immersive mode. |
| 546 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 547 | private final UpdateLock mUpdateLock = new UpdateLock("immersive"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 548 | |
| 549 | /** |
| 550 | * Packages that are being allowed to perform unrestricted app switches. Mapping is |
| 551 | * User -> Type -> uid. |
| 552 | */ |
| 553 | final SparseArray<ArrayMap<String, Integer>> mAllowAppSwitchUids = new SparseArray<>(); |
| 554 | |
| 555 | /** The dimensions of the thumbnails in the Recents UI. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 556 | private int mThumbnailWidth; |
| 557 | private int mThumbnailHeight; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 558 | |
| 559 | /** |
| 560 | * Flag that indicates if multi-window is enabled. |
| 561 | * |
| 562 | * For any particular form of multi-window to be enabled, generic multi-window must be enabled |
| 563 | * in {@link com.android.internal.R.bool#config_supportsMultiWindow} config or |
| 564 | * {@link Settings.Global#DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES} development option set. |
| 565 | * At least one of the forms of multi-window must be enabled in order for this flag to be |
| 566 | * initialized to 'true'. |
| 567 | * |
| 568 | * @see #mSupportsSplitScreenMultiWindow |
| 569 | * @see #mSupportsFreeformWindowManagement |
| 570 | * @see #mSupportsPictureInPicture |
| 571 | * @see #mSupportsMultiDisplay |
| 572 | */ |
| 573 | boolean mSupportsMultiWindow; |
| 574 | boolean mSupportsSplitScreenMultiWindow; |
| 575 | boolean mSupportsFreeformWindowManagement; |
| 576 | boolean mSupportsPictureInPicture; |
| 577 | boolean mSupportsMultiDisplay; |
| 578 | boolean mForceResizableActivities; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 579 | boolean mSizeCompatFreeform; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 580 | |
| 581 | final List<ActivityTaskManagerInternal.ScreenObserver> mScreenObservers = new ArrayList<>(); |
| 582 | |
| 583 | // VR Vr2d Display Id. |
| 584 | int mVr2dDisplayId = INVALID_DISPLAY; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 585 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 586 | /** |
| 587 | * Set while we are wanting to sleep, to prevent any |
| 588 | * activities from being started/resumed. |
| 589 | * |
| 590 | * TODO(b/33594039): Clarify the actual state transitions represented by mSleeping. |
| 591 | * |
| 592 | * Currently mSleeping is set to true when transitioning into the sleep state, and remains true |
| 593 | * while in the sleep state until there is a pending transition out of sleep, in which case |
| 594 | * mSleeping is set to false, and remains false while awake. |
| 595 | * |
| 596 | * Whether mSleeping can quickly toggled between true/false without the device actually |
| 597 | * display changing states is undefined. |
| 598 | */ |
| 599 | private boolean mSleeping = false; |
| 600 | |
| 601 | /** |
Galia Peycheva | 480275a | 2020-03-18 17:33:42 +0100 | [diff] [blame^] | 602 | * The mDreaming state is set by the {@link DreamManagerService} when it receives a request to |
| 603 | * start/stop the dream. It is set to true shortly before the {@link DreamService} is started. |
| 604 | * It is set to false after the {@link DreamService} is stopped. |
| 605 | */ |
| 606 | private boolean mDreaming = false; |
| 607 | |
| 608 | /** |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 609 | * The process state used for processes that are running the top activities. |
| 610 | * This changes between TOP and TOP_SLEEPING to following mSleeping. |
| 611 | */ |
| 612 | int mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
| 613 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 614 | @Retention(RetentionPolicy.SOURCE) |
| 615 | @IntDef({ |
| 616 | LAYOUT_REASON_CONFIG_CHANGED, |
| 617 | LAYOUT_REASON_VISIBILITY_CHANGED, |
| 618 | }) |
| 619 | @interface LayoutReason {} |
| 620 | static final int LAYOUT_REASON_CONFIG_CHANGED = 0x1; |
| 621 | static final int LAYOUT_REASON_VISIBILITY_CHANGED = 0x2; |
| 622 | |
| 623 | /** The reasons to perform surface placement. */ |
| 624 | @LayoutReason |
| 625 | private int mLayoutReasons; |
| 626 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 627 | // Whether we should show our dialogs (ANR, crash, etc) or just perform their default action |
| 628 | // automatically. Important for devices without direct input devices. |
| 629 | private boolean mShowDialogs = true; |
| 630 | |
| 631 | /** Set if we are shutting down the system, similar to sleeping. */ |
| 632 | boolean mShuttingDown = false; |
| 633 | |
| 634 | /** |
| 635 | * We want to hold a wake lock while running a voice interaction session, since |
| 636 | * this may happen with the screen off and we need to keep the CPU running to |
| 637 | * be able to continue to interact with the user. |
| 638 | */ |
| 639 | PowerManager.WakeLock mVoiceWakeLock; |
| 640 | |
| 641 | /** |
| 642 | * Set while we are running a voice interaction. This overrides sleeping while it is active. |
| 643 | */ |
| 644 | IVoiceInteractionSession mRunningVoice; |
| 645 | |
| 646 | /** |
| 647 | * The last resumed activity. This is identical to the current resumed activity most |
| 648 | * of the time but could be different when we're pausing one activity before we resume |
| 649 | * another activity. |
| 650 | */ |
| 651 | ActivityRecord mLastResumedActivity; |
| 652 | |
| 653 | /** |
| 654 | * The activity that is currently being traced as the active resumed activity. |
| 655 | * |
| 656 | * @see #updateResumedAppTrace |
| 657 | */ |
| 658 | private @Nullable ActivityRecord mTracedResumedActivity; |
| 659 | |
| 660 | /** If non-null, we are tracking the time the user spends in the currently focused app. */ |
| 661 | AppTimeTracker mCurAppTimeTracker; |
| 662 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 663 | AppWarnings mAppWarnings; |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 664 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 665 | /** |
| 666 | * Packages that the user has asked to have run in screen size |
| 667 | * compatibility mode instead of filling the screen. |
| 668 | */ |
| 669 | CompatModePackages mCompatModePackages; |
| 670 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 671 | private FontScaleSettingObserver mFontScaleSettingObserver; |
| 672 | |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 673 | WindowOrganizerController mWindowOrganizerController; |
| 674 | TaskOrganizerController mTaskOrganizerController; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 675 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 676 | private int mDeviceOwnerUid = Process.INVALID_UID; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 677 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 678 | private final class FontScaleSettingObserver extends ContentObserver { |
| 679 | private final Uri mFontScaleUri = Settings.System.getUriFor(FONT_SCALE); |
| 680 | private final Uri mHideErrorDialogsUri = Settings.Global.getUriFor(HIDE_ERROR_DIALOGS); |
| 681 | |
| 682 | public FontScaleSettingObserver() { |
| 683 | super(mH); |
| 684 | final ContentResolver resolver = mContext.getContentResolver(); |
| 685 | resolver.registerContentObserver(mFontScaleUri, false, this, UserHandle.USER_ALL); |
| 686 | resolver.registerContentObserver(mHideErrorDialogsUri, false, this, |
| 687 | UserHandle.USER_ALL); |
| 688 | } |
| 689 | |
| 690 | @Override |
Jeff Sharkey | 8b0cff7 | 2020-03-09 15:49:01 -0600 | [diff] [blame] | 691 | public void onChange(boolean selfChange, Collection<Uri> uris, int flags, |
Riddle Hsu | 9c024d1 | 2020-03-09 16:10:07 +0800 | [diff] [blame] | 692 | @UserIdInt int userId) { |
| 693 | for (Uri uri : uris) { |
| 694 | if (mFontScaleUri.equals(uri)) { |
| 695 | updateFontScaleIfNeeded(userId); |
| 696 | } else if (mHideErrorDialogsUri.equals(uri)) { |
| 697 | synchronized (mGlobalLock) { |
| 698 | updateShouldShowDialogsLocked(getGlobalConfiguration()); |
| 699 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | } |
| 703 | } |
| 704 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 705 | /** Indicates that the method may be invoked frequently or is sensitive to performance. */ |
| 706 | @Target(ElementType.METHOD) |
| 707 | @Retention(RetentionPolicy.SOURCE) |
| 708 | @interface HotPath { |
| 709 | int NONE = 0; |
| 710 | int OOM_ADJUSTMENT = 1; |
| 711 | int LRU_UPDATE = 2; |
| 712 | int PROCESS_CHANGE = 3; |
| 713 | int caller() default NONE; |
| 714 | } |
| 715 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 716 | private final Runnable mUpdateOomAdjRunnable = new Runnable() { |
| 717 | @Override |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 718 | public void run() { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 719 | mAmInternal.updateOomAdj(); |
| 720 | } |
| 721 | }; |
| 722 | |
Charles Chen | 8d98dd2 | 2018-12-26 17:36:54 +0800 | [diff] [blame] | 723 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 724 | public ActivityTaskManagerService(Context context) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 725 | mContext = context; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 726 | mFactoryTest = FactoryTest.getMode(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 727 | mSystemThread = ActivityThread.currentActivityThread(); |
| 728 | mUiContext = mSystemThread.getSystemUiContext(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 729 | mLifecycleManager = new ClientLifecycleManager(); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 730 | mInternal = new LocalService(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 731 | GL_ES_VERSION = SystemProperties.getInt("ro.opengles.version", GL_ES_VERSION_UNDEFINED); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 732 | mWindowOrganizerController = new WindowOrganizerController(this); |
| 733 | mTaskOrganizerController = mWindowOrganizerController.mTaskOrganizerController; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 734 | } |
| 735 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 736 | public void onSystemReady() { |
| 737 | synchronized (mGlobalLock) { |
| 738 | mHasHeavyWeightFeature = mContext.getPackageManager().hasSystemFeature( |
| 739 | PackageManager.FEATURE_CANT_SAVE_STATE); |
| 740 | mAssistUtils = new AssistUtils(mContext); |
| 741 | mVrController.onSystemReady(); |
| 742 | mRecentTasks.onSystemReadyLocked(); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 743 | mStackSupervisor.onSystemReady(); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 744 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 747 | public void onInitPowerManagement() { |
| 748 | synchronized (mGlobalLock) { |
| 749 | mStackSupervisor.initPowerManagement(); |
| 750 | final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 751 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
| 752 | mVoiceWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*voice*"); |
| 753 | mVoiceWakeLock.setReferenceCounted(false); |
| 754 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 755 | } |
| 756 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 757 | public void installSystemProviders() { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 758 | mFontScaleSettingObserver = new FontScaleSettingObserver(); |
| 759 | } |
| 760 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 761 | public void retrieveSettings(ContentResolver resolver) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 762 | final boolean freeformWindowManagement = |
| 763 | mContext.getPackageManager().hasSystemFeature(FEATURE_FREEFORM_WINDOW_MANAGEMENT) |
| 764 | || Settings.Global.getInt( |
| 765 | resolver, DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0; |
| 766 | |
| 767 | final boolean supportsMultiWindow = ActivityTaskManager.supportsMultiWindow(mContext); |
| 768 | final boolean supportsPictureInPicture = supportsMultiWindow && |
| 769 | mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE); |
| 770 | final boolean supportsSplitScreenMultiWindow = |
| 771 | ActivityTaskManager.supportsSplitScreenMultiWindow(mContext); |
| 772 | final boolean supportsMultiDisplay = mContext.getPackageManager() |
| 773 | .hasSystemFeature(FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 774 | final boolean forceRtl = Settings.Global.getInt(resolver, DEVELOPMENT_FORCE_RTL, 0) != 0; |
| 775 | final boolean forceResizable = Settings.Global.getInt( |
| 776 | resolver, DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 777 | final boolean sizeCompatFreeform = Settings.Global.getInt( |
| 778 | resolver, DEVELOPMENT_ENABLE_SIZECOMPAT_FREEFORM, 0) != 0; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 779 | |
| 780 | // Transfer any global setting for forcing RTL layout, into a System Property |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 781 | DisplayProperties.debug_force_rtl(forceRtl); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 782 | |
| 783 | final Configuration configuration = new Configuration(); |
| 784 | Settings.System.getConfiguration(resolver, configuration); |
| 785 | if (forceRtl) { |
| 786 | // This will take care of setting the correct layout direction flags |
| 787 | configuration.setLayoutDirection(configuration.locale); |
| 788 | } |
| 789 | |
| 790 | synchronized (mGlobalLock) { |
| 791 | mForceResizableActivities = forceResizable; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 792 | mSizeCompatFreeform = sizeCompatFreeform; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 793 | final boolean multiWindowFormEnabled = freeformWindowManagement |
| 794 | || supportsSplitScreenMultiWindow |
| 795 | || supportsPictureInPicture |
| 796 | || supportsMultiDisplay; |
| 797 | if ((supportsMultiWindow || forceResizable) && multiWindowFormEnabled) { |
| 798 | mSupportsMultiWindow = true; |
| 799 | mSupportsFreeformWindowManagement = freeformWindowManagement; |
| 800 | mSupportsSplitScreenMultiWindow = supportsSplitScreenMultiWindow; |
| 801 | mSupportsPictureInPicture = supportsPictureInPicture; |
| 802 | mSupportsMultiDisplay = supportsMultiDisplay; |
| 803 | } else { |
| 804 | mSupportsMultiWindow = false; |
| 805 | mSupportsFreeformWindowManagement = false; |
| 806 | mSupportsSplitScreenMultiWindow = false; |
| 807 | mSupportsPictureInPicture = false; |
| 808 | mSupportsMultiDisplay = false; |
| 809 | } |
Garfield Tan | b5910b4 | 2019-03-14 14:50:59 -0700 | [diff] [blame] | 810 | mWindowManager.mRoot.onSettingsRetrieved(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 811 | // This happens before any activities are started, so we can change global configuration |
| 812 | // in-place. |
| 813 | updateConfigurationLocked(configuration, null, true); |
| 814 | final Configuration globalConfig = getGlobalConfiguration(); |
| 815 | if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Initial config: " + globalConfig); |
| 816 | |
| 817 | // Load resources only after the current configuration has been set. |
| 818 | final Resources res = mContext.getResources(); |
| 819 | mThumbnailWidth = res.getDimensionPixelSize( |
| 820 | com.android.internal.R.dimen.thumbnail_width); |
| 821 | mThumbnailHeight = res.getDimensionPixelSize( |
| 822 | com.android.internal.R.dimen.thumbnail_height); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 826 | public WindowManagerGlobalLock getGlobalLock() { |
| 827 | return mGlobalLock; |
| 828 | } |
| 829 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 830 | /** For test purpose only. */ |
| 831 | @VisibleForTesting |
| 832 | public ActivityTaskManagerInternal getAtmInternal() { |
| 833 | return mInternal; |
| 834 | } |
| 835 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 836 | public void initialize(IntentFirewall intentFirewall, PendingIntentController intentController, |
| 837 | Looper looper) { |
| 838 | mH = new H(looper); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 839 | mUiHandler = new UiHandler(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 840 | mIntentFirewall = intentFirewall; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 841 | final File systemDir = SystemServiceManager.ensureSystemDir(); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 842 | mAppWarnings = createAppWarnings(mUiContext, mH, mUiHandler, systemDir); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 843 | mCompatModePackages = new CompatModePackages(this, systemDir, mH); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 844 | mPendingIntentController = intentController; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 845 | mStackSupervisor = createStackSupervisor(); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 846 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 847 | mTaskChangeNotificationController = |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 848 | new TaskChangeNotificationController(mGlobalLock, mStackSupervisor, mH); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 849 | mLockTaskController = new LockTaskController(mContext, mStackSupervisor, mH); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 850 | mActivityStartController = new ActivityStartController(this); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 851 | setRecentTasks(new RecentTasks(this, mStackSupervisor)); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 852 | mVrController = new VrController(mGlobalLock); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 853 | mKeyguardController = mStackSupervisor.getKeyguardController(); |
| 854 | } |
| 855 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 856 | public void onActivityManagerInternalAdded() { |
| 857 | synchronized (mGlobalLock) { |
| 858 | mAmInternal = LocalServices.getService(ActivityManagerInternal.class); |
| 859 | mUgmInternal = LocalServices.getService(UriGrantsManagerInternal.class); |
| 860 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 863 | int increaseConfigurationSeqLocked() { |
| 864 | mConfigurationSeq = Math.max(++mConfigurationSeq, 1); |
| 865 | return mConfigurationSeq; |
| 866 | } |
| 867 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 868 | protected ActivityStackSupervisor createStackSupervisor() { |
| 869 | final ActivityStackSupervisor supervisor = new ActivityStackSupervisor(this, mH.getLooper()); |
| 870 | supervisor.initialize(); |
| 871 | return supervisor; |
| 872 | } |
| 873 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 874 | protected AppWarnings createAppWarnings( |
| 875 | Context uiContext, Handler handler, Handler uiHandler, File systemDir) { |
| 876 | return new AppWarnings(this, uiContext, handler, uiHandler, systemDir); |
| 877 | } |
| 878 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 879 | public void setWindowManager(WindowManagerService wm) { |
| 880 | synchronized (mGlobalLock) { |
| 881 | mWindowManager = wm; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 882 | mRootWindowContainer = wm.mRoot; |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 883 | mTempConfig.setToDefaults(); |
| 884 | mTempConfig.setLocales(LocaleList.getDefault()); |
| 885 | mConfigurationSeq = mTempConfig.seq = 1; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 886 | mRootWindowContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 887 | mLockTaskController.setWindowManager(wm); |
| 888 | mStackSupervisor.setWindowManager(wm); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 889 | mRootWindowContainer.setWindowManager(wm); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 890 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 891 | } |
| 892 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 893 | public void setUsageStatsManager(UsageStatsManagerInternal usageStatsManager) { |
| 894 | synchronized (mGlobalLock) { |
| 895 | mUsageStatsInternal = usageStatsManager; |
| 896 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 899 | UserManagerService getUserManager() { |
| 900 | if (mUserManager == null) { |
| 901 | IBinder b = ServiceManager.getService(Context.USER_SERVICE); |
| 902 | mUserManager = (UserManagerService) IUserManager.Stub.asInterface(b); |
| 903 | } |
| 904 | return mUserManager; |
| 905 | } |
| 906 | |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 907 | AppOpsManager getAppOpsManager() { |
| 908 | if (mAppOpsManager == null) { |
| 909 | mAppOpsManager = mContext.getSystemService(AppOpsManager.class); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 910 | } |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 911 | return mAppOpsManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | boolean hasUserRestriction(String restriction, int userId) { |
| 915 | return getUserManager().hasUserRestriction(restriction, userId); |
| 916 | } |
| 917 | |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 918 | boolean hasSystemAlertWindowPermission(int callingUid, int callingPid, String callingPackage) { |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 919 | final int mode = getAppOpsManager().noteOpNoThrow(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, |
| 920 | callingUid, callingPackage, /* featureId */ null, ""); |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 921 | if (mode == AppOpsManager.MODE_DEFAULT) { |
| 922 | return checkPermission(Manifest.permission.SYSTEM_ALERT_WINDOW, callingPid, callingUid) |
| 923 | == PERMISSION_GRANTED; |
| 924 | } |
| 925 | return mode == AppOpsManager.MODE_ALLOWED; |
| 926 | } |
| 927 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 928 | @VisibleForTesting |
| 929 | protected void setRecentTasks(RecentTasks recentTasks) { |
| 930 | mRecentTasks = recentTasks; |
| 931 | mStackSupervisor.setRecentTasks(recentTasks); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | RecentTasks getRecentTasks() { |
| 935 | return mRecentTasks; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 936 | } |
| 937 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 938 | ClientLifecycleManager getLifecycleManager() { |
| 939 | return mLifecycleManager; |
| 940 | } |
| 941 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 942 | ActivityStartController getActivityStartController() { |
| 943 | return mActivityStartController; |
| 944 | } |
| 945 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 946 | TaskChangeNotificationController getTaskChangeNotificationController() { |
| 947 | return mTaskChangeNotificationController; |
| 948 | } |
| 949 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 950 | LockTaskController getLockTaskController() { |
| 951 | return mLockTaskController; |
| 952 | } |
| 953 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 954 | /** |
| 955 | * Return the global configuration used by the process corresponding to the input pid. This is |
| 956 | * usually the global configuration with some overrides specific to that process. |
| 957 | */ |
| 958 | Configuration getGlobalConfigurationForCallingPid() { |
| 959 | final int pid = Binder.getCallingPid(); |
Yunfan Chen | c2ff6cf | 2018-12-04 16:56:21 -0800 | [diff] [blame] | 960 | return getGlobalConfigurationForPid(pid); |
| 961 | } |
| 962 | |
| 963 | /** |
| 964 | * Return the global configuration used by the process corresponding to the given pid. |
| 965 | */ |
| 966 | Configuration getGlobalConfigurationForPid(int pid) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 967 | if (pid == MY_PID || pid < 0) { |
| 968 | return getGlobalConfiguration(); |
| 969 | } |
| 970 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 971 | final WindowProcessController app = mProcessMap.getProcess(pid); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 972 | return app != null ? app.getConfiguration() : getGlobalConfiguration(); |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | /** |
| 977 | * Return the device configuration info used by the process corresponding to the input pid. |
| 978 | * The value is consistent with the global configuration for the process. |
| 979 | */ |
| 980 | @Override |
| 981 | public ConfigurationInfo getDeviceConfigurationInfo() { |
| 982 | ConfigurationInfo config = new ConfigurationInfo(); |
| 983 | synchronized (mGlobalLock) { |
| 984 | final Configuration globalConfig = getGlobalConfigurationForCallingPid(); |
| 985 | config.reqTouchScreen = globalConfig.touchscreen; |
| 986 | config.reqKeyboardType = globalConfig.keyboard; |
| 987 | config.reqNavigation = globalConfig.navigation; |
| 988 | if (globalConfig.navigation == Configuration.NAVIGATION_DPAD |
| 989 | || globalConfig.navigation == Configuration.NAVIGATION_TRACKBALL) { |
| 990 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 991 | } |
| 992 | if (globalConfig.keyboard != Configuration.KEYBOARD_UNDEFINED |
| 993 | && globalConfig.keyboard != Configuration.KEYBOARD_NOKEYS) { |
| 994 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 995 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 996 | config.reqGlEsVersion = GL_ES_VERSION; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 997 | } |
| 998 | return config; |
| 999 | } |
| 1000 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 1001 | private void start() { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1002 | LocalServices.addService(ActivityTaskManagerInternal.class, mInternal); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1005 | public static final class Lifecycle extends SystemService { |
| 1006 | private final ActivityTaskManagerService mService; |
| 1007 | |
| 1008 | public Lifecycle(Context context) { |
| 1009 | super(context); |
| 1010 | mService = new ActivityTaskManagerService(context); |
| 1011 | } |
| 1012 | |
| 1013 | @Override |
| 1014 | public void onStart() { |
| 1015 | publishBinderService(Context.ACTIVITY_TASK_SERVICE, mService); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 1016 | mService.start(); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 1019 | @Override |
| 1020 | public void onUnlockUser(int userId) { |
| 1021 | synchronized (mService.getGlobalLock()) { |
Garfield Tan | 0d407f4 | 2019-03-07 11:47:01 -0800 | [diff] [blame] | 1022 | mService.mStackSupervisor.onUserUnlocked(userId); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | @Override |
| 1027 | public void onCleanupUser(int userId) { |
| 1028 | synchronized (mService.getGlobalLock()) { |
| 1029 | mService.mStackSupervisor.mLaunchParamsPersister.onCleanupUser(userId); |
| 1030 | } |
| 1031 | } |
| 1032 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1033 | public ActivityTaskManagerService getService() { |
| 1034 | return mService; |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1039 | public final int startActivity(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1040 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1041 | String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, |
| 1042 | Bundle bOptions) { |
| 1043 | return startActivityAsUser(caller, callingPackage, callingFeatureId, intent, resolvedType, |
| 1044 | resultTo, resultWho, requestCode, startFlags, profilerInfo, bOptions, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1045 | UserHandle.getCallingUserId()); |
| 1046 | } |
| 1047 | |
| 1048 | @Override |
| 1049 | public final int startActivities(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1050 | String callingFeatureId, Intent[] intents, String[] resolvedTypes, IBinder resultTo, |
| 1051 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1052 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1053 | final String reason = "startActivities"; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1054 | enforceNotIsolatedCaller(reason); |
| 1055 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, reason); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1056 | // TODO: Switch to user app stacks here. |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 1057 | return getActivityStartController().startActivities(caller, -1, 0, -1, callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1058 | callingFeatureId, intents, resolvedTypes, resultTo, |
| 1059 | SafeActivityOptions.fromBundle(bOptions), userId, reason, |
| 1060 | null /* originatingPendingIntent */, false /* allowBackgroundActivityStart */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | @Override |
| 1064 | public int startActivityAsUser(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1065 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1066 | String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, |
| 1067 | Bundle bOptions, int userId) { |
| 1068 | return startActivityAsUser(caller, callingPackage, callingFeatureId, intent, resolvedType, |
| 1069 | resultTo, resultWho, requestCode, startFlags, profilerInfo, bOptions, userId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1070 | true /*validateIncomingUser*/); |
| 1071 | } |
| 1072 | |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1073 | private int startActivityAsUser(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1074 | @Nullable String callingFeatureId, Intent intent, String resolvedType, |
| 1075 | IBinder resultTo, String resultWho, int requestCode, int startFlags, |
| 1076 | ProfilerInfo profilerInfo, Bundle bOptions, int userId, boolean validateIncomingUser) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1077 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1078 | enforceNotIsolatedCaller("startActivityAsUser"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1079 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1080 | userId = getActivityStartController().checkTargetUser(userId, validateIncomingUser, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1081 | Binder.getCallingPid(), Binder.getCallingUid(), "startActivityAsUser"); |
| 1082 | |
| 1083 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1084 | return getActivityStartController().obtainStarter(intent, "startActivityAsUser") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1085 | .setCaller(caller) |
| 1086 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1087 | .setCallingFeatureId(callingFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1088 | .setResolvedType(resolvedType) |
| 1089 | .setResultTo(resultTo) |
| 1090 | .setResultWho(resultWho) |
| 1091 | .setRequestCode(requestCode) |
| 1092 | .setStartFlags(startFlags) |
| 1093 | .setProfilerInfo(profilerInfo) |
| 1094 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1095 | .setUserId(userId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1096 | .execute(); |
| 1097 | |
| 1098 | } |
| 1099 | |
| 1100 | @Override |
| 1101 | public int startActivityIntentSender(IApplicationThread caller, IIntentSender target, |
| 1102 | IBinder whitelistToken, Intent fillInIntent, String resolvedType, IBinder resultTo, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1103 | String resultWho, int requestCode, int flagsMask, int flagsValues, Bundle bOptions) { |
| 1104 | enforceNotIsolatedCaller("startActivityIntentSender"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1105 | // Refuse possible leaked file descriptors |
| 1106 | if (fillInIntent != null && fillInIntent.hasFileDescriptors()) { |
| 1107 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1108 | } |
| 1109 | |
| 1110 | if (!(target instanceof PendingIntentRecord)) { |
| 1111 | throw new IllegalArgumentException("Bad PendingIntent object"); |
| 1112 | } |
| 1113 | |
| 1114 | PendingIntentRecord pir = (PendingIntentRecord)target; |
| 1115 | |
| 1116 | synchronized (mGlobalLock) { |
| 1117 | // If this is coming from the currently resumed activity, it is |
| 1118 | // effectively saying that app switches are allowed at this point. |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1119 | final ActivityStack stack = getTopDisplayFocusedStack(); |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 1120 | if (stack != null && stack.mResumedActivity != null |
| 1121 | && stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1122 | mAppSwitchesAllowedTime = 0; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1123 | } |
| 1124 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1125 | return pir.sendInner(0, fillInIntent, resolvedType, whitelistToken, null, null, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1126 | resultTo, resultWho, requestCode, flagsMask, flagsValues, bOptions); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | @Override |
| 1130 | public boolean startNextMatchingActivity(IBinder callingActivity, Intent intent, |
| 1131 | Bundle bOptions) { |
| 1132 | // Refuse possible leaked file descriptors |
| 1133 | if (intent != null && intent.hasFileDescriptors()) { |
| 1134 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1135 | } |
| 1136 | SafeActivityOptions options = SafeActivityOptions.fromBundle(bOptions); |
| 1137 | |
| 1138 | synchronized (mGlobalLock) { |
| 1139 | final ActivityRecord r = ActivityRecord.isInStackLocked(callingActivity); |
| 1140 | if (r == null) { |
| 1141 | SafeActivityOptions.abort(options); |
| 1142 | return false; |
| 1143 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1144 | if (!r.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1145 | // The caller is not running... d'oh! |
| 1146 | SafeActivityOptions.abort(options); |
| 1147 | return false; |
| 1148 | } |
| 1149 | intent = new Intent(intent); |
| 1150 | // The caller is not allowed to change the data. |
| 1151 | intent.setDataAndType(r.intent.getData(), r.intent.getType()); |
| 1152 | // And we are resetting to find the next component... |
| 1153 | intent.setComponent(null); |
| 1154 | |
| 1155 | final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0); |
| 1156 | |
| 1157 | ActivityInfo aInfo = null; |
| 1158 | try { |
| 1159 | List<ResolveInfo> resolves = |
| 1160 | AppGlobals.getPackageManager().queryIntentActivities( |
| 1161 | intent, r.resolvedType, |
| 1162 | PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS, |
| 1163 | UserHandle.getCallingUserId()).getList(); |
| 1164 | |
| 1165 | // Look for the original activity in the list... |
| 1166 | final int N = resolves != null ? resolves.size() : 0; |
| 1167 | for (int i=0; i<N; i++) { |
| 1168 | ResolveInfo rInfo = resolves.get(i); |
| 1169 | if (rInfo.activityInfo.packageName.equals(r.packageName) |
| 1170 | && rInfo.activityInfo.name.equals(r.info.name)) { |
| 1171 | // We found the current one... the next matching is |
| 1172 | // after it. |
| 1173 | i++; |
| 1174 | if (i<N) { |
| 1175 | aInfo = resolves.get(i).activityInfo; |
| 1176 | } |
| 1177 | if (debug) { |
| 1178 | Slog.v(TAG, "Next matching activity: found current " + r.packageName |
| 1179 | + "/" + r.info.name); |
| 1180 | Slog.v(TAG, "Next matching activity: next is " + ((aInfo == null) |
| 1181 | ? "null" : aInfo.packageName + "/" + aInfo.name)); |
| 1182 | } |
| 1183 | break; |
| 1184 | } |
| 1185 | } |
| 1186 | } catch (RemoteException e) { |
| 1187 | } |
| 1188 | |
| 1189 | if (aInfo == null) { |
| 1190 | // Nobody who is next! |
| 1191 | SafeActivityOptions.abort(options); |
| 1192 | if (debug) Slog.d(TAG, "Next matching activity: nothing found"); |
| 1193 | return false; |
| 1194 | } |
| 1195 | |
| 1196 | intent.setComponent(new ComponentName( |
| 1197 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1198 | intent.setFlags(intent.getFlags()&~( |
| 1199 | Intent.FLAG_ACTIVITY_FORWARD_RESULT| |
| 1200 | Intent.FLAG_ACTIVITY_CLEAR_TOP| |
| 1201 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK| |
| 1202 | FLAG_ACTIVITY_NEW_TASK)); |
| 1203 | |
| 1204 | // Okay now we need to start the new activity, replacing the currently running activity. |
| 1205 | // This is a little tricky because we want to start the new one as if the current one is |
| 1206 | // finished, but not finish the current one first so that there is no flicker. |
| 1207 | // And thus... |
| 1208 | final boolean wasFinishing = r.finishing; |
| 1209 | r.finishing = true; |
| 1210 | |
| 1211 | // Propagate reply information over to the new activity. |
| 1212 | final ActivityRecord resultTo = r.resultTo; |
| 1213 | final String resultWho = r.resultWho; |
| 1214 | final int requestCode = r.requestCode; |
| 1215 | r.resultTo = null; |
| 1216 | if (resultTo != null) { |
| 1217 | resultTo.removeResultsLocked(r, resultWho, requestCode); |
| 1218 | } |
| 1219 | |
| 1220 | final long origId = Binder.clearCallingIdentity(); |
| 1221 | // TODO(b/64750076): Check if calling pid should really be -1. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1222 | final int res = getActivityStartController() |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1223 | .obtainStarter(intent, "startNextMatchingActivity") |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1224 | .setCaller(r.app.getThread()) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1225 | .setResolvedType(r.resolvedType) |
| 1226 | .setActivityInfo(aInfo) |
| 1227 | .setResultTo(resultTo != null ? resultTo.appToken : null) |
| 1228 | .setResultWho(resultWho) |
| 1229 | .setRequestCode(requestCode) |
| 1230 | .setCallingPid(-1) |
| 1231 | .setCallingUid(r.launchedFromUid) |
| 1232 | .setCallingPackage(r.launchedFromPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1233 | .setCallingFeatureId(r.launchedFromFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1234 | .setRealCallingPid(-1) |
| 1235 | .setRealCallingUid(r.launchedFromUid) |
| 1236 | .setActivityOptions(options) |
| 1237 | .execute(); |
| 1238 | Binder.restoreCallingIdentity(origId); |
| 1239 | |
| 1240 | r.finishing = wasFinishing; |
| 1241 | if (res != ActivityManager.START_SUCCESS) { |
| 1242 | return false; |
| 1243 | } |
| 1244 | return true; |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | @Override |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 1249 | public boolean startDreamActivity(Intent intent) { |
Galia Peycheva | 52e8922 | 2020-02-18 23:41:43 +0100 | [diff] [blame] | 1250 | final WindowProcessController process = mProcessMap.getProcess(Binder.getCallingPid()); |
| 1251 | final long origId = Binder.clearCallingIdentity(); |
| 1252 | |
| 1253 | // The dream activity is only called for non-doze dreams. |
| 1254 | final ComponentName currentDream = LocalServices.getService(DreamManagerInternal.class) |
| 1255 | .getActiveDreamComponent(/* doze= */ false); |
| 1256 | |
| 1257 | if (currentDream == null || currentDream.getPackageName() == null |
| 1258 | || !currentDream.getPackageName().equals(process.mInfo.packageName)) { |
| 1259 | Slog.e(TAG, "Calling package is not the current dream package. " |
| 1260 | + "Aborting startDreamActivity..."); |
| 1261 | return false; |
| 1262 | } |
| 1263 | |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 1264 | final ActivityInfo a = new ActivityInfo(); |
| 1265 | a.theme = com.android.internal.R.style.Theme_Dream; |
| 1266 | a.exported = true; |
| 1267 | a.name = DreamActivity.class.getName(); |
| 1268 | |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 1269 | |
| 1270 | a.packageName = process.mInfo.packageName; |
| 1271 | a.applicationInfo = process.mInfo; |
| 1272 | a.processName = process.mInfo.processName; |
| 1273 | a.uiOptions = process.mInfo.uiOptions; |
| 1274 | a.taskAffinity = "android:" + a.packageName + "/dream"; |
| 1275 | a.enabled = true; |
| 1276 | a.launchMode = ActivityInfo.LAUNCH_SINGLE_INSTANCE; |
| 1277 | |
| 1278 | a.persistableMode = ActivityInfo.PERSIST_NEVER; |
| 1279 | a.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 1280 | a.colorMode = ActivityInfo.COLOR_MODE_DEFAULT; |
| 1281 | a.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 1282 | |
Galia Peycheva | 45f48d3 | 2020-02-20 15:39:10 +0100 | [diff] [blame] | 1283 | final ActivityOptions options = ActivityOptions.makeBasic(); |
| 1284 | options.setLaunchActivityType(ACTIVITY_TYPE_DREAM); |
| 1285 | |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 1286 | try { |
| 1287 | getActivityStartController().obtainStarter(intent, "dream") |
| 1288 | .setActivityInfo(a) |
Galia Peycheva | 45f48d3 | 2020-02-20 15:39:10 +0100 | [diff] [blame] | 1289 | .setActivityOptions(options.toBundle()) |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 1290 | .setIsDream(true) |
| 1291 | .execute(); |
| 1292 | return true; |
| 1293 | } finally { |
| 1294 | Binder.restoreCallingIdentity(origId); |
| 1295 | } |
| 1296 | } |
| 1297 | |
| 1298 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1299 | public final WaitResult startActivityAndWait(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1300 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1301 | String resultWho, int requestCode, int startFlags, ProfilerInfo profilerInfo, |
| 1302 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1303 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1304 | final WaitResult res = new WaitResult(); |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1305 | enforceNotIsolatedCaller("startActivityAndWait"); |
| 1306 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 1307 | userId, "startActivityAndWait"); |
| 1308 | // TODO: Switch to user app stacks here. |
| 1309 | getActivityStartController().obtainStarter(intent, "startActivityAndWait") |
| 1310 | .setCaller(caller) |
| 1311 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1312 | .setCallingFeatureId(callingFeatureId) |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1313 | .setResolvedType(resolvedType) |
| 1314 | .setResultTo(resultTo) |
| 1315 | .setResultWho(resultWho) |
| 1316 | .setRequestCode(requestCode) |
| 1317 | .setStartFlags(startFlags) |
| 1318 | .setActivityOptions(bOptions) |
| 1319 | .setUserId(userId) |
| 1320 | .setProfilerInfo(profilerInfo) |
| 1321 | .setWaitResult(res) |
| 1322 | .execute(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1323 | return res; |
| 1324 | } |
| 1325 | |
| 1326 | @Override |
| 1327 | public final int startActivityWithConfig(IApplicationThread caller, String callingPackage, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1328 | String callingFeatureId, Intent intent, String resolvedType, IBinder resultTo, |
| 1329 | String resultWho, int requestCode, int startFlags, Configuration config, |
| 1330 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1331 | assertPackageMatchesCallingUid(callingPackage); |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1332 | enforceNotIsolatedCaller("startActivityWithConfig"); |
| 1333 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, |
| 1334 | "startActivityWithConfig"); |
| 1335 | // TODO: Switch to user app stacks here. |
| 1336 | return getActivityStartController().obtainStarter(intent, "startActivityWithConfig") |
| 1337 | .setCaller(caller) |
| 1338 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1339 | .setCallingFeatureId(callingFeatureId) |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1340 | .setResolvedType(resolvedType) |
| 1341 | .setResultTo(resultTo) |
| 1342 | .setResultWho(resultWho) |
| 1343 | .setRequestCode(requestCode) |
| 1344 | .setStartFlags(startFlags) |
| 1345 | .setGlobalConfiguration(config) |
| 1346 | .setActivityOptions(bOptions) |
| 1347 | .setUserId(userId) |
| 1348 | .execute(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 1351 | @Override |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1352 | public IBinder requestStartActivityPermissionToken(IBinder delegatorToken) { |
| 1353 | int callingUid = Binder.getCallingUid(); |
| 1354 | if (UserHandle.getAppId(callingUid) != SYSTEM_UID) { |
| 1355 | throw new SecurityException("Only the system process can request a permission token, " |
| 1356 | + "received request from uid: " + callingUid); |
| 1357 | } |
| 1358 | IBinder permissionToken = new Binder(); |
| 1359 | synchronized (mGlobalLock) { |
| 1360 | mStartActivitySources.put(permissionToken, delegatorToken); |
| 1361 | } |
| 1362 | |
| 1363 | Message expireMsg = PooledLambda.obtainMessage( |
| 1364 | ActivityTaskManagerService::expireStartAsCallerTokenMsg, this, permissionToken); |
| 1365 | mUiHandler.sendMessageDelayed(expireMsg, START_AS_CALLER_TOKEN_TIMEOUT_IMPL); |
| 1366 | |
| 1367 | Message forgetMsg = PooledLambda.obtainMessage( |
| 1368 | ActivityTaskManagerService::forgetStartAsCallerTokenMsg, this, permissionToken); |
| 1369 | mUiHandler.sendMessageDelayed(forgetMsg, START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT); |
| 1370 | |
| 1371 | return permissionToken; |
| 1372 | } |
| 1373 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1374 | @Override |
| 1375 | public final int startActivityAsCaller(IApplicationThread caller, String callingPackage, |
| 1376 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1377 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, IBinder permissionToken, |
| 1378 | boolean ignoreTargetSecurity, int userId) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1379 | // 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] | 1380 | // permission grants) as any app that may launch one of your own activities. So we only |
| 1381 | // allow this in two cases: |
| 1382 | // 1) The caller is an activity that is part of the core framework, and then only when it |
| 1383 | // is running as the system. |
| 1384 | // 2) The caller provides a valid permissionToken. Permission tokens are one-time use and |
| 1385 | // can only be requested by a system activity, which may then delegate this call to |
| 1386 | // another app. |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1387 | final ActivityRecord sourceRecord; |
| 1388 | final int targetUid; |
| 1389 | final String targetPackage; |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1390 | final String targetFeatureId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1391 | final boolean isResolver; |
| 1392 | synchronized (mGlobalLock) { |
| 1393 | if (resultTo == null) { |
| 1394 | throw new SecurityException("Must be called from an activity"); |
| 1395 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1396 | final IBinder sourceToken; |
| 1397 | if (permissionToken != null) { |
| 1398 | // To even attempt to use a permissionToken, an app must also have this signature |
| 1399 | // permission. |
| 1400 | mAmInternal.enforceCallingPermission( |
| 1401 | android.Manifest.permission.START_ACTIVITY_AS_CALLER, |
| 1402 | "startActivityAsCaller"); |
| 1403 | // If called with a permissionToken, we want the sourceRecord from the delegator |
| 1404 | // activity that requested this token. |
| 1405 | sourceToken = mStartActivitySources.remove(permissionToken); |
| 1406 | if (sourceToken == null) { |
| 1407 | // Invalid permissionToken, check if it recently expired. |
| 1408 | if (mExpiredStartAsCallerTokens.contains(permissionToken)) { |
| 1409 | throw new SecurityException("Called with expired permission token: " |
| 1410 | + permissionToken); |
| 1411 | } else { |
| 1412 | throw new SecurityException("Called with invalid permission token: " |
| 1413 | + permissionToken); |
| 1414 | } |
| 1415 | } |
| 1416 | } else { |
| 1417 | // This method was called directly by the source. |
| 1418 | sourceToken = resultTo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1419 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1420 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 1421 | sourceRecord = mRootWindowContainer.isInAnyStack(sourceToken); |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1422 | if (sourceRecord == null) { |
| 1423 | throw new SecurityException("Called with bad activity token: " + sourceToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1424 | } |
| 1425 | if (sourceRecord.app == null) { |
| 1426 | throw new SecurityException("Called without a process attached to activity"); |
| 1427 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1428 | |
| 1429 | // Whether called directly or from a delegate, the source activity must be from the |
| 1430 | // android package. |
| 1431 | if (!sourceRecord.info.packageName.equals("android")) { |
| 1432 | throw new SecurityException("Must be called from an activity that is " |
| 1433 | + "declared in the android package"); |
| 1434 | } |
| 1435 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1436 | if (UserHandle.getAppId(sourceRecord.app.mUid) != SYSTEM_UID) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1437 | // This is still okay, as long as this activity is running under the |
| 1438 | // uid of the original calling activity. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1439 | if (sourceRecord.app.mUid != sourceRecord.launchedFromUid) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1440 | throw new SecurityException( |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1441 | "Calling activity in uid " + sourceRecord.app.mUid |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1442 | + " must be system uid or original calling uid " |
| 1443 | + sourceRecord.launchedFromUid); |
| 1444 | } |
| 1445 | } |
| 1446 | if (ignoreTargetSecurity) { |
| 1447 | if (intent.getComponent() == null) { |
| 1448 | throw new SecurityException( |
| 1449 | "Component must be specified with ignoreTargetSecurity"); |
| 1450 | } |
| 1451 | if (intent.getSelector() != null) { |
| 1452 | throw new SecurityException( |
| 1453 | "Selector not allowed with ignoreTargetSecurity"); |
| 1454 | } |
| 1455 | } |
| 1456 | targetUid = sourceRecord.launchedFromUid; |
| 1457 | targetPackage = sourceRecord.launchedFromPackage; |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1458 | targetFeatureId = sourceRecord.launchedFromFeatureId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1459 | isResolver = sourceRecord.isResolverOrChildActivity(); |
| 1460 | } |
| 1461 | |
| 1462 | if (userId == UserHandle.USER_NULL) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1463 | userId = UserHandle.getUserId(sourceRecord.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | // TODO: Switch to user app stacks here. |
| 1467 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1468 | return getActivityStartController().obtainStarter(intent, "startActivityAsCaller") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1469 | .setCallingUid(targetUid) |
| 1470 | .setCallingPackage(targetPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1471 | .setCallingFeatureId(targetFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1472 | .setResolvedType(resolvedType) |
| 1473 | .setResultTo(resultTo) |
| 1474 | .setResultWho(resultWho) |
| 1475 | .setRequestCode(requestCode) |
| 1476 | .setStartFlags(startFlags) |
| 1477 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1478 | .setUserId(userId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1479 | .setIgnoreTargetSecurity(ignoreTargetSecurity) |
| 1480 | .setFilterCallingUid(isResolver ? 0 /* system */ : targetUid) |
Alan Stokes | 2f4a4ed | 2019-05-08 16:56:45 +0100 | [diff] [blame] | 1481 | // The target may well be in the background, which would normally prevent it |
| 1482 | // from starting an activity. Here we definitely want the start to succeed. |
| 1483 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1484 | .execute(); |
| 1485 | } catch (SecurityException e) { |
| 1486 | // XXX need to figure out how to propagate to original app. |
| 1487 | // A SecurityException here is generally actually a fault of the original |
| 1488 | // calling activity (such as a fairly granting permissions), so propagate it |
| 1489 | // back to them. |
| 1490 | /* |
| 1491 | StringBuilder msg = new StringBuilder(); |
| 1492 | msg.append("While launching"); |
| 1493 | msg.append(intent.toString()); |
| 1494 | msg.append(": "); |
| 1495 | msg.append(e.getMessage()); |
| 1496 | */ |
| 1497 | throw e; |
| 1498 | } |
| 1499 | } |
| 1500 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1501 | int handleIncomingUser(int callingPid, int callingUid, int userId, String name) { |
| 1502 | return mAmInternal.handleIncomingUser(callingPid, callingUid, userId, false /* allowAll */, |
Jonathan Scott | 9233534 | 2019-12-17 14:46:26 +0000 | [diff] [blame] | 1503 | ALLOW_NON_FULL, name, null /* callerPackage */); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1506 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1507 | public int startVoiceActivity(String callingPackage, String callingFeatureId, int callingPid, |
| 1508 | int callingUid, Intent intent, String resolvedType, IVoiceInteractionSession session, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1509 | IVoiceInteractor interactor, int startFlags, ProfilerInfo profilerInfo, |
| 1510 | Bundle bOptions, int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1511 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1512 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startVoiceActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1513 | if (session == null || interactor == null) { |
| 1514 | throw new NullPointerException("null session or interactor"); |
| 1515 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1516 | userId = handleIncomingUser(callingPid, callingUid, userId, "startVoiceActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1517 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1518 | return getActivityStartController().obtainStarter(intent, "startVoiceActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1519 | .setCallingUid(callingUid) |
| 1520 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1521 | .setCallingFeatureId(callingFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1522 | .setResolvedType(resolvedType) |
| 1523 | .setVoiceSession(session) |
| 1524 | .setVoiceInteractor(interactor) |
| 1525 | .setStartFlags(startFlags) |
| 1526 | .setProfilerInfo(profilerInfo) |
| 1527 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1528 | .setUserId(userId) |
Michal Karpinski | 85fa202 | 2019-02-08 12:05:09 +0000 | [diff] [blame] | 1529 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1530 | .execute(); |
| 1531 | } |
| 1532 | |
| 1533 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1534 | public int startAssistantActivity(String callingPackage, @NonNull String callingFeatureId, |
| 1535 | int callingPid, int callingUid, Intent intent, String resolvedType, Bundle bOptions, |
| 1536 | int userId) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 1537 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1538 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startAssistantActivity()"); |
| 1539 | userId = handleIncomingUser(callingPid, callingUid, userId, "startAssistantActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1540 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1541 | return getActivityStartController().obtainStarter(intent, "startAssistantActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1542 | .setCallingUid(callingUid) |
| 1543 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1544 | .setCallingFeatureId(callingFeatureId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1545 | .setResolvedType(resolvedType) |
| 1546 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1547 | .setUserId(userId) |
Michal Karpinski | 85fa202 | 2019-02-08 12:05:09 +0000 | [diff] [blame] | 1548 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1549 | .execute(); |
| 1550 | } |
| 1551 | |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1552 | /** |
| 1553 | * Start the recents activity to perform the recents animation. |
| 1554 | * |
| 1555 | * @param intent The intent to start the recents activity. |
| 1556 | * @param recentsAnimationRunner Pass {@code null} to only preload the activity. |
| 1557 | */ |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1558 | @Override |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1559 | public void startRecentsActivity(Intent intent, @Deprecated IAssistDataReceiver unused, |
| 1560 | @Nullable IRecentsAnimationRunner recentsAnimationRunner) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1561 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "startRecentsActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1562 | final int callingPid = Binder.getCallingPid(); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1563 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1564 | final long origId = Binder.clearCallingIdentity(); |
| 1565 | try { |
| 1566 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 1567 | final ComponentName recentsComponent = mRecentTasks.getRecentsComponent(); |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1568 | final String recentsFeatureId = mRecentTasks.getRecentsComponentFeatureId(); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 1569 | final int recentsUid = mRecentTasks.getRecentsComponentUid(); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1570 | final WindowProcessController caller = getProcessController(callingPid, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1571 | |
| 1572 | // Start a new recents animation |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1573 | final RecentsAnimation anim = new RecentsAnimation(this, mStackSupervisor, |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1574 | getActivityStartController(), mWindowManager, intent, recentsComponent, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 1575 | recentsFeatureId, recentsUid, caller); |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1576 | if (recentsAnimationRunner == null) { |
| 1577 | anim.preloadRecentsActivity(); |
| 1578 | } else { |
| 1579 | anim.startRecentsActivity(recentsAnimationRunner); |
| 1580 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1581 | } |
| 1582 | } finally { |
| 1583 | Binder.restoreCallingIdentity(origId); |
| 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | @Override |
| 1588 | public final int startActivityFromRecents(int taskId, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1589 | enforceCallerIsRecentsOrHasPermission(START_TASKS_FROM_RECENTS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1590 | "startActivityFromRecents()"); |
| 1591 | |
| 1592 | final int callingPid = Binder.getCallingPid(); |
| 1593 | final int callingUid = Binder.getCallingUid(); |
| 1594 | final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(bOptions); |
| 1595 | final long origId = Binder.clearCallingIdentity(); |
| 1596 | try { |
| 1597 | synchronized (mGlobalLock) { |
| 1598 | return mStackSupervisor.startActivityFromRecents(callingPid, callingUid, taskId, |
| 1599 | safeOptions); |
| 1600 | } |
| 1601 | } finally { |
| 1602 | Binder.restoreCallingIdentity(origId); |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | /** |
Andrii Kulian | 2eb84b2 | 2018-12-13 18:18:54 -0800 | [diff] [blame] | 1607 | * Public API to check if the client is allowed to start an activity on specified display. |
| 1608 | * |
| 1609 | * If the target display is private or virtual, some restrictions will apply. |
| 1610 | * |
| 1611 | * @param displayId Target display id. |
| 1612 | * @param intent Intent used to launch the activity. |
| 1613 | * @param resolvedType The MIME type of the intent. |
| 1614 | * @param userId The id of the user for whom the call is made. |
| 1615 | * @return {@code true} if a call to start an activity on the target display should succeed and |
| 1616 | * no {@link SecurityException} will be thrown, {@code false} otherwise. |
| 1617 | */ |
| 1618 | @Override |
| 1619 | public final boolean isActivityStartAllowedOnDisplay(int displayId, Intent intent, |
| 1620 | String resolvedType, int userId) { |
| 1621 | final int callingUid = Binder.getCallingUid(); |
| 1622 | final int callingPid = Binder.getCallingPid(); |
| 1623 | final long origId = Binder.clearCallingIdentity(); |
| 1624 | |
| 1625 | try { |
| 1626 | // Collect information about the target of the Intent. |
| 1627 | ActivityInfo aInfo = mStackSupervisor.resolveActivity(intent, resolvedType, |
| 1628 | 0 /* startFlags */, null /* profilerInfo */, userId, |
| 1629 | ActivityStarter.computeResolveFilterUid(callingUid, callingUid, |
| 1630 | UserHandle.USER_NULL)); |
| 1631 | aInfo = mAmInternal.getActivityInfoForUser(aInfo, userId); |
| 1632 | |
| 1633 | synchronized (mGlobalLock) { |
| 1634 | return mStackSupervisor.canPlaceEntityOnDisplay(displayId, callingPid, callingUid, |
| 1635 | aInfo); |
| 1636 | } |
| 1637 | } finally { |
| 1638 | Binder.restoreCallingIdentity(origId); |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | /** |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1643 | * This is the internal entry point for handling Activity.finish(). |
| 1644 | * |
| 1645 | * @param token The Binder token referencing the Activity we want to finish. |
| 1646 | * @param resultCode Result code, if any, from this Activity. |
| 1647 | * @param resultData Result data (Intent), if any, from this Activity. |
| 1648 | * @param finishTask Whether to finish the task associated with this Activity. |
| 1649 | * |
| 1650 | * @return Returns true if the activity successfully finished, or false if it is still running. |
| 1651 | */ |
| 1652 | @Override |
| 1653 | public final boolean finishActivity(IBinder token, int resultCode, Intent resultData, |
| 1654 | int finishTask) { |
| 1655 | // Refuse possible leaked file descriptors |
| 1656 | if (resultData != null && resultData.hasFileDescriptors()) { |
| 1657 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1658 | } |
| 1659 | |
| 1660 | synchronized (mGlobalLock) { |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 1661 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1662 | if (r == null) { |
| 1663 | return true; |
| 1664 | } |
| 1665 | // 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] | 1666 | final Task tr = r.getTask(); |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 1667 | final ActivityRecord rootR = tr.getRootActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1668 | if (rootR == null) { |
| 1669 | Slog.w(TAG, "Finishing task with all activities already finished"); |
| 1670 | } |
| 1671 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps can |
| 1672 | // finish. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1673 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1674 | return false; |
| 1675 | } |
| 1676 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1677 | // TODO: There is a dup. of this block of code in ActivityStack.navigateUpToLocked |
| 1678 | // We should consolidate. |
| 1679 | if (mController != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1680 | // Find the first activity that is not finishing. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1681 | final ActivityRecord next = |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 1682 | r.getRootTask().topRunningActivity(token, INVALID_TASK_ID); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1683 | if (next != null) { |
| 1684 | // ask watcher if this is allowed |
| 1685 | boolean resumeOK = true; |
| 1686 | try { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1687 | resumeOK = mController.activityResuming(next.packageName); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1688 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1689 | mController = null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1690 | Watchdog.getInstance().setActivityController(null); |
| 1691 | } |
| 1692 | |
| 1693 | if (!resumeOK) { |
| 1694 | Slog.i(TAG, "Not finishing activity because controller resumed"); |
| 1695 | return false; |
| 1696 | } |
| 1697 | } |
| 1698 | } |
Michal Karpinski | fc6872e | 2019-05-21 15:18:44 +0100 | [diff] [blame] | 1699 | |
| 1700 | // note down that the process has finished an activity and is in background activity |
| 1701 | // starts grace period |
| 1702 | if (r.app != null) { |
| 1703 | r.app.setLastActivityFinishTimeIfNeeded(SystemClock.uptimeMillis()); |
| 1704 | } |
| 1705 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1706 | final long origId = Binder.clearCallingIdentity(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1707 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "finishActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1708 | try { |
| 1709 | boolean res; |
| 1710 | final boolean finishWithRootActivity = |
| 1711 | finishTask == Activity.FINISH_TASK_WITH_ROOT_ACTIVITY; |
| 1712 | if (finishTask == Activity.FINISH_TASK_WITH_ACTIVITY |
| 1713 | || (finishWithRootActivity && r == rootR)) { |
| 1714 | // If requested, remove the task that is associated to this activity only if it |
| 1715 | // was the root activity in the task. The result code and data is ignored |
| 1716 | // because we don't support returning them across task boundaries. Also, to |
| 1717 | // keep backwards compatibility we remove the task from recents when finishing |
| 1718 | // task with root activity. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1719 | mStackSupervisor.removeTask(tr, false /*killProcess*/, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1720 | finishWithRootActivity, "finish-activity"); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1721 | res = true; |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 1722 | // Explicitly dismissing the activity so reset its relaunch flag. |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 1723 | r.mRelaunchReason = RELAUNCH_REASON_NONE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1724 | } else { |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 1725 | r.finishIfPossible(resultCode, resultData, "app-request", true /* oomAdj */); |
Andrii Kulian | 40eda67 | 2019-07-30 15:05:57 -0700 | [diff] [blame] | 1726 | res = r.finishing; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1727 | if (!res) { |
| 1728 | Slog.i(TAG, "Failed to finish by app-request"); |
| 1729 | } |
| 1730 | } |
| 1731 | return res; |
| 1732 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1733 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1734 | Binder.restoreCallingIdentity(origId); |
| 1735 | } |
| 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | @Override |
| 1740 | public boolean finishActivityAffinity(IBinder token) { |
| 1741 | synchronized (mGlobalLock) { |
| 1742 | final long origId = Binder.clearCallingIdentity(); |
| 1743 | try { |
| 1744 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1745 | if (r == null) { |
| 1746 | return false; |
| 1747 | } |
| 1748 | |
| 1749 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps |
| 1750 | // can finish. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1751 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1752 | return false; |
| 1753 | } |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1754 | |
| 1755 | final PooledFunction p = PooledLambda.obtainFunction( |
| 1756 | ActivityRecord::finishIfSameAffinity, r, |
| 1757 | PooledLambda.__(ActivityRecord.class)); |
| 1758 | r.getTask().forAllActivities( |
| 1759 | p, r, true /*includeBoundary*/, true /*traverseTopToBottom*/); |
| 1760 | p.recycle(); |
| 1761 | |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 1762 | return true; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1763 | } finally { |
| 1764 | Binder.restoreCallingIdentity(origId); |
| 1765 | } |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | @Override |
| 1770 | public final void activityIdle(IBinder token, Configuration config, boolean stopProfiling) { |
| 1771 | final long origId = Binder.clearCallingIdentity(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1772 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1773 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1774 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityIdle"); |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 1775 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 1776 | if (r == null) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1777 | return; |
| 1778 | } |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 1779 | mStackSupervisor.activityIdleInternal(r, false /* fromTimeout */, |
| 1780 | false /* processPausingActivities */, config); |
| 1781 | if (stopProfiling && r.hasProcess()) { |
| 1782 | r.app.clearProfilerIfNeeded(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1783 | } |
| 1784 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1785 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1786 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1787 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1788 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | @Override |
| 1792 | public final void activityResumed(IBinder token) { |
| 1793 | final long origId = Binder.clearCallingIdentity(); |
| 1794 | synchronized (mGlobalLock) { |
| 1795 | ActivityRecord.activityResumedLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1796 | } |
| 1797 | Binder.restoreCallingIdentity(origId); |
| 1798 | } |
| 1799 | |
| 1800 | @Override |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 1801 | public final void activityTopResumedStateLost() { |
| 1802 | final long origId = Binder.clearCallingIdentity(); |
| 1803 | synchronized (mGlobalLock) { |
| 1804 | mStackSupervisor.handleTopResumedStateReleased(false /* timeout */); |
| 1805 | } |
| 1806 | Binder.restoreCallingIdentity(origId); |
| 1807 | } |
| 1808 | |
| 1809 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1810 | public final void activityPaused(IBinder token) { |
| 1811 | final long origId = Binder.clearCallingIdentity(); |
| 1812 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1813 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityPaused"); |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 1814 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 1815 | if (r != null) { |
| 1816 | r.activityPaused(false); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1817 | } |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1818 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1819 | } |
| 1820 | Binder.restoreCallingIdentity(origId); |
| 1821 | } |
| 1822 | |
| 1823 | @Override |
| 1824 | public final void activityStopped(IBinder token, Bundle icicle, |
| 1825 | PersistableBundle persistentState, CharSequence description) { |
| 1826 | if (DEBUG_ALL) Slog.v(TAG, "Activity stopped: token=" + token); |
| 1827 | |
| 1828 | // Refuse possible leaked file descriptors |
| 1829 | if (icicle != null && icicle.hasFileDescriptors()) { |
| 1830 | throw new IllegalArgumentException("File descriptors passed in Bundle"); |
| 1831 | } |
| 1832 | |
| 1833 | final long origId = Binder.clearCallingIdentity(); |
| 1834 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1835 | String restartingName = null; |
| 1836 | int restartingUid = 0; |
| 1837 | final ActivityRecord r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1838 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1839 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityStopped"); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1840 | r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1841 | if (r != null) { |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1842 | if (r.attachedToProcess() |
| 1843 | && r.isState(ActivityStack.ActivityState.RESTARTING_PROCESS)) { |
| 1844 | // The activity was requested to restart from |
| 1845 | // {@link #restartActivityProcessIfVisible}. |
| 1846 | restartingName = r.app.mName; |
| 1847 | restartingUid = r.app.mUid; |
| 1848 | } |
Wale Ogunwale | 196db71 | 2019-12-27 15:35:39 +0000 | [diff] [blame] | 1849 | r.activityStopped(icicle, persistentState, description); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1850 | } |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1851 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1854 | if (restartingName != null) { |
| 1855 | // In order to let the foreground activity can be restarted with its saved state from |
| 1856 | // {@link android.app.Activity#onSaveInstanceState}, the kill operation is postponed |
| 1857 | // until the activity reports stopped with the state. And the activity record will be |
| 1858 | // kept because the record state is restarting, then the activity will be restarted |
| 1859 | // immediately if it is still the top one. |
| 1860 | mStackSupervisor.removeRestartTimeouts(r); |
| 1861 | mAmInternal.killProcess(restartingName, restartingUid, "restartActivityProcess"); |
| 1862 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1863 | mAmInternal.trimApplications(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1864 | |
| 1865 | Binder.restoreCallingIdentity(origId); |
| 1866 | } |
| 1867 | |
| 1868 | @Override |
| 1869 | public final void activityDestroyed(IBinder token) { |
| 1870 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "ACTIVITY DESTROYED: " + token); |
| 1871 | synchronized (mGlobalLock) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1872 | final long origId = Binder.clearCallingIdentity(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1873 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityDestroyed"); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1874 | try { |
| 1875 | final ActivityRecord activity = ActivityRecord.forTokenLocked(token); |
| 1876 | if (activity != null) { |
| 1877 | activity.destroyed("activityDestroyed"); |
| 1878 | } |
| 1879 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1880 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1881 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1882 | } |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | @Override |
| 1887 | public final void activityRelaunched(IBinder token) { |
| 1888 | final long origId = Binder.clearCallingIdentity(); |
| 1889 | synchronized (mGlobalLock) { |
| 1890 | mStackSupervisor.activityRelaunchedLocked(token); |
| 1891 | } |
| 1892 | Binder.restoreCallingIdentity(origId); |
| 1893 | } |
| 1894 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1895 | @Override |
| 1896 | public void setRequestedOrientation(IBinder token, int requestedOrientation) { |
| 1897 | synchronized (mGlobalLock) { |
| 1898 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1899 | if (r == null) { |
| 1900 | return; |
| 1901 | } |
| 1902 | final long origId = Binder.clearCallingIdentity(); |
| 1903 | try { |
| 1904 | r.setRequestedOrientation(requestedOrientation); |
| 1905 | } finally { |
| 1906 | Binder.restoreCallingIdentity(origId); |
| 1907 | } |
| 1908 | } |
| 1909 | } |
| 1910 | |
| 1911 | @Override |
| 1912 | public int getRequestedOrientation(IBinder token) { |
| 1913 | synchronized (mGlobalLock) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1914 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1915 | return (r != null) |
| 1916 | ? r.getRequestedOrientation() : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1917 | } |
| 1918 | } |
| 1919 | |
| 1920 | @Override |
| 1921 | public void setImmersive(IBinder token, boolean immersive) { |
| 1922 | synchronized (mGlobalLock) { |
| 1923 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1924 | if (r == null) { |
| 1925 | throw new IllegalArgumentException(); |
| 1926 | } |
| 1927 | r.immersive = immersive; |
| 1928 | |
| 1929 | // update associated state if we're frontmost |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1930 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1931 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, "Frontmost changed immersion: "+ r); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1932 | applyUpdateLockStateLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1933 | } |
| 1934 | } |
| 1935 | } |
| 1936 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1937 | void applyUpdateLockStateLocked(ActivityRecord r) { |
| 1938 | // Modifications to the UpdateLock state are done on our handler, outside |
| 1939 | // the activity manager's locks. The new state is determined based on the |
| 1940 | // state *now* of the relevant activity record. The object is passed to |
| 1941 | // the handler solely for logging detail, not to be consulted/modified. |
| 1942 | final boolean nextState = r != null && r.immersive; |
| 1943 | mH.post(() -> { |
| 1944 | if (mUpdateLock.isHeld() != nextState) { |
| 1945 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, |
| 1946 | "Applying new update lock state '" + nextState + "' for " + r); |
| 1947 | if (nextState) { |
| 1948 | mUpdateLock.acquire(); |
| 1949 | } else { |
| 1950 | mUpdateLock.release(); |
| 1951 | } |
| 1952 | } |
| 1953 | }); |
| 1954 | } |
| 1955 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1956 | @Override |
| 1957 | public boolean isImmersive(IBinder token) { |
| 1958 | synchronized (mGlobalLock) { |
| 1959 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1960 | if (r == null) { |
| 1961 | throw new IllegalArgumentException(); |
| 1962 | } |
| 1963 | return r.immersive; |
| 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | @Override |
| 1968 | public boolean isTopActivityImmersive() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1969 | enforceNotIsolatedCaller("isTopActivityImmersive"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1970 | synchronized (mGlobalLock) { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 1971 | final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); |
| 1972 | if (topFocusedStack == null) { |
| 1973 | return false; |
| 1974 | } |
| 1975 | |
| 1976 | final ActivityRecord r = topFocusedStack.topRunningActivity(); |
| 1977 | return r != null && r.immersive; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | @Override |
| 1982 | public void overridePendingTransition(IBinder token, String packageName, |
| 1983 | int enterAnim, int exitAnim) { |
| 1984 | synchronized (mGlobalLock) { |
| 1985 | ActivityRecord self = ActivityRecord.isInStackLocked(token); |
| 1986 | if (self == null) { |
| 1987 | return; |
| 1988 | } |
| 1989 | |
| 1990 | final long origId = Binder.clearCallingIdentity(); |
| 1991 | |
| 1992 | if (self.isState( |
| 1993 | ActivityStack.ActivityState.RESUMED, ActivityStack.ActivityState.PAUSING)) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1994 | self.getDisplay().mDisplayContent.mAppTransition.overridePendingAppTransition( |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1995 | packageName, enterAnim, exitAnim, null); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | Binder.restoreCallingIdentity(origId); |
| 1999 | } |
| 2000 | } |
| 2001 | |
| 2002 | @Override |
| 2003 | public int getFrontActivityScreenCompatMode() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2004 | enforceNotIsolatedCaller("getFrontActivityScreenCompatMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2005 | synchronized (mGlobalLock) { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 2006 | final ActivityStack stack = getTopDisplayFocusedStack(); |
| 2007 | final ActivityRecord r = stack != null ? stack.topRunningActivity() : null; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2008 | if (r == null) { |
| 2009 | return ActivityManager.COMPAT_MODE_UNKNOWN; |
| 2010 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 2011 | return mCompatModePackages.computeCompatModeLocked(r.info.applicationInfo); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | @Override |
| 2016 | public void setFrontActivityScreenCompatMode(int mode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2017 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2018 | "setFrontActivityScreenCompatMode"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2019 | ApplicationInfo ai; |
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 | Slog.w(TAG, "setFrontActivityScreenCompatMode failed: no top activity"); |
| 2025 | return; |
| 2026 | } |
| 2027 | ai = r.info.applicationInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 2028 | mCompatModePackages.setPackageScreenCompatModeLocked(ai, mode); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2029 | } |
| 2030 | } |
| 2031 | |
| 2032 | @Override |
| 2033 | public int getLaunchedFromUid(IBinder activityToken) { |
| 2034 | ActivityRecord srec; |
| 2035 | synchronized (mGlobalLock) { |
| 2036 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 2037 | } |
| 2038 | if (srec == null) { |
| 2039 | return -1; |
| 2040 | } |
| 2041 | return srec.launchedFromUid; |
| 2042 | } |
| 2043 | |
| 2044 | @Override |
| 2045 | public String getLaunchedFromPackage(IBinder activityToken) { |
| 2046 | ActivityRecord srec; |
| 2047 | synchronized (mGlobalLock) { |
| 2048 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 2049 | } |
| 2050 | if (srec == null) { |
| 2051 | return null; |
| 2052 | } |
| 2053 | return srec.launchedFromPackage; |
| 2054 | } |
| 2055 | |
| 2056 | @Override |
| 2057 | public boolean convertFromTranslucent(IBinder token) { |
| 2058 | final long origId = Binder.clearCallingIdentity(); |
| 2059 | try { |
| 2060 | synchronized (mGlobalLock) { |
| 2061 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2062 | if (r == null) { |
| 2063 | return false; |
| 2064 | } |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 2065 | return r.setOccludesParent(true); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2066 | } |
| 2067 | } finally { |
| 2068 | Binder.restoreCallingIdentity(origId); |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | @Override |
| 2073 | public boolean convertToTranslucent(IBinder token, Bundle options) { |
| 2074 | SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(options); |
| 2075 | final long origId = Binder.clearCallingIdentity(); |
| 2076 | try { |
| 2077 | synchronized (mGlobalLock) { |
| 2078 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2079 | if (r == null) { |
| 2080 | return false; |
| 2081 | } |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2082 | final ActivityRecord under = r.getTask().getActivityBelow(r); |
| 2083 | if (under != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2084 | under.returningOptions = safeOptions != null ? safeOptions.getOptions(r) : null; |
| 2085 | } |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 2086 | return r.setOccludesParent(false); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2087 | } |
| 2088 | } finally { |
| 2089 | Binder.restoreCallingIdentity(origId); |
| 2090 | } |
| 2091 | } |
| 2092 | |
| 2093 | @Override |
| 2094 | public void notifyActivityDrawn(IBinder token) { |
| 2095 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, "notifyActivityDrawn: token=" + token); |
| 2096 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2097 | ActivityRecord r = mRootWindowContainer.isInAnyStack(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2098 | if (r != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2099 | r.getRootTask().notifyActivityDrawnLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2100 | } |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | @Override |
| 2105 | public void reportActivityFullyDrawn(IBinder token, boolean restoredFromBundle) { |
| 2106 | synchronized (mGlobalLock) { |
| 2107 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2108 | if (r == null) { |
| 2109 | return; |
| 2110 | } |
| 2111 | r.reportFullyDrawnLocked(restoredFromBundle); |
| 2112 | } |
| 2113 | } |
| 2114 | |
| 2115 | @Override |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2116 | public int getDisplayId(IBinder activityToken) throws RemoteException { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2117 | synchronized (mGlobalLock) { |
| 2118 | final ActivityStack stack = ActivityRecord.getStackLocked(activityToken); |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 2119 | if (stack != null) { |
| 2120 | final int displayId = stack.getDisplayId(); |
| 2121 | return displayId != INVALID_DISPLAY ? displayId : DEFAULT_DISPLAY; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2122 | } |
| 2123 | return DEFAULT_DISPLAY; |
| 2124 | } |
| 2125 | } |
| 2126 | |
| 2127 | @Override |
| 2128 | public ActivityManager.StackInfo getFocusedStackInfo() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2129 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2130 | long ident = Binder.clearCallingIdentity(); |
| 2131 | try { |
| 2132 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2133 | ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2134 | if (focusedStack != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2135 | return mRootWindowContainer.getStackInfo(focusedStack.mTaskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2136 | } |
| 2137 | return null; |
| 2138 | } |
| 2139 | } finally { |
| 2140 | Binder.restoreCallingIdentity(ident); |
| 2141 | } |
| 2142 | } |
| 2143 | |
| 2144 | @Override |
| 2145 | public void setFocusedStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2146 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2147 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedStack: stackId=" + stackId); |
| 2148 | final long callingId = Binder.clearCallingIdentity(); |
| 2149 | try { |
| 2150 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2151 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2152 | if (stack == null) { |
| 2153 | Slog.w(TAG, "setFocusedStack: No stack with id=" + stackId); |
| 2154 | return; |
| 2155 | } |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2156 | final ActivityRecord r = stack.topRunningActivity(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2157 | if (r != null && r.moveFocusableActivityToTop("setFocusedStack")) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2158 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2159 | } |
| 2160 | } |
| 2161 | } finally { |
| 2162 | Binder.restoreCallingIdentity(callingId); |
| 2163 | } |
| 2164 | } |
| 2165 | |
| 2166 | @Override |
| 2167 | public void setFocusedTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2168 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2169 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedTask: taskId=" + taskId); |
| 2170 | final long callingId = Binder.clearCallingIdentity(); |
| 2171 | try { |
| 2172 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2173 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2174 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2175 | if (task == null) { |
| 2176 | return; |
| 2177 | } |
| 2178 | final ActivityRecord r = task.topRunningActivityLocked(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2179 | if (r != null && r.moveFocusableActivityToTop("setFocusedTask")) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2180 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2181 | } |
| 2182 | } |
| 2183 | } finally { |
| 2184 | Binder.restoreCallingIdentity(callingId); |
| 2185 | } |
| 2186 | } |
| 2187 | |
| 2188 | @Override |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2189 | public void restartActivityProcessIfVisible(IBinder activityToken) { |
| 2190 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "restartActivityProcess()"); |
| 2191 | final long callingId = Binder.clearCallingIdentity(); |
| 2192 | try { |
| 2193 | synchronized (mGlobalLock) { |
| 2194 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 2195 | if (r == null) { |
| 2196 | return; |
| 2197 | } |
| 2198 | r.restartProcessIfVisible(); |
| 2199 | } |
| 2200 | } finally { |
| 2201 | Binder.restoreCallingIdentity(callingId); |
| 2202 | } |
| 2203 | } |
| 2204 | |
| 2205 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2206 | public boolean removeTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2207 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2208 | synchronized (mGlobalLock) { |
| 2209 | final long ident = Binder.clearCallingIdentity(); |
| 2210 | try { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2211 | return mStackSupervisor.removeTaskById(taskId, true, REMOVE_FROM_RECENTS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2212 | "remove-task"); |
| 2213 | } finally { |
| 2214 | Binder.restoreCallingIdentity(ident); |
| 2215 | } |
| 2216 | } |
| 2217 | } |
| 2218 | |
| 2219 | @Override |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 2220 | public void removeAllVisibleRecentTasks() { |
| 2221 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeAllVisibleRecentTasks()"); |
| 2222 | synchronized (mGlobalLock) { |
| 2223 | final long ident = Binder.clearCallingIdentity(); |
| 2224 | try { |
Winson Chung | 42fa21f | 2019-04-02 16:23:46 -0700 | [diff] [blame] | 2225 | getRecentTasks().removeAllVisibleTasks(mAmInternal.getCurrentUserId()); |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 2226 | } finally { |
| 2227 | Binder.restoreCallingIdentity(ident); |
| 2228 | } |
| 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2233 | public boolean shouldUpRecreateTask(IBinder token, String destAffinity) { |
| 2234 | synchronized (mGlobalLock) { |
| 2235 | final ActivityRecord srec = ActivityRecord.forTokenLocked(token); |
| 2236 | if (srec != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2237 | return srec.getRootTask().shouldUpRecreateTaskLocked(srec, destAffinity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2238 | } |
| 2239 | } |
| 2240 | return false; |
| 2241 | } |
| 2242 | |
| 2243 | @Override |
| 2244 | public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode, |
| 2245 | Intent resultData) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2246 | |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 2247 | synchronized (mGlobalLock) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2248 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2249 | if (r != null) { |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2250 | return r.getRootTask().navigateUpTo( |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2251 | r, destIntent, resultCode, resultData); |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 2252 | } |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2253 | return false; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2254 | } |
| 2255 | } |
| 2256 | |
| 2257 | /** |
| 2258 | * Attempts to move a task backwards in z-order (the order of activities within the task is |
| 2259 | * unchanged). |
| 2260 | * |
| 2261 | * There are several possible results of this call: |
| 2262 | * - if the task is locked, then we will show the lock toast |
| 2263 | * - if there is a task behind the provided task, then that task is made visible and resumed as |
| 2264 | * this task is moved to the back |
| 2265 | * - otherwise, if there are no other tasks in the stack: |
| 2266 | * - if this task is in the pinned stack, then we remove the stack completely, which will |
| 2267 | * have the effect of moving the task to the top or bottom of the fullscreen stack |
| 2268 | * (depending on whether it is visible) |
| 2269 | * - otherwise, we simply return home and hide this task |
| 2270 | * |
| 2271 | * @param token A reference to the activity we wish to move |
| 2272 | * @param nonRoot If false then this only works if the activity is the root |
| 2273 | * of a task; if true it will work for any activity in a task. |
| 2274 | * @return Returns true if the move completed, false if not. |
| 2275 | */ |
| 2276 | @Override |
| 2277 | public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2278 | enforceNotIsolatedCaller("moveActivityTaskToBack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2279 | synchronized (mGlobalLock) { |
| 2280 | final long origId = Binder.clearCallingIdentity(); |
| 2281 | try { |
| 2282 | int taskId = ActivityRecord.getTaskForActivityLocked(token, !nonRoot); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2283 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2284 | if (task != null) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2285 | return ActivityRecord.getStackLocked(token).moveTaskToBack(task); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2286 | } |
| 2287 | } finally { |
| 2288 | Binder.restoreCallingIdentity(origId); |
| 2289 | } |
| 2290 | } |
| 2291 | return false; |
| 2292 | } |
| 2293 | |
| 2294 | @Override |
| 2295 | public Rect getTaskBounds(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2296 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getTaskBounds()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2297 | long ident = Binder.clearCallingIdentity(); |
| 2298 | Rect rect = new Rect(); |
| 2299 | try { |
| 2300 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2301 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2302 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2303 | if (task == null) { |
| 2304 | Slog.w(TAG, "getTaskBounds: taskId=" + taskId + " not found"); |
| 2305 | return rect; |
| 2306 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 2307 | if (task.getParent() != null) { |
| 2308 | rect.set(task.getBounds()); |
| 2309 | } else if (task.mLastNonFullscreenBounds != null) { |
| 2310 | rect.set(task.mLastNonFullscreenBounds); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2311 | } |
| 2312 | } |
| 2313 | } finally { |
| 2314 | Binder.restoreCallingIdentity(ident); |
| 2315 | } |
| 2316 | return rect; |
| 2317 | } |
| 2318 | |
| 2319 | @Override |
| 2320 | public ActivityManager.TaskDescription getTaskDescription(int id) { |
| 2321 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2322 | enforceCallerIsRecentsOrHasPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2323 | MANAGE_ACTIVITY_STACKS, "getTaskDescription()"); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2324 | final Task tr = mRootWindowContainer.anyTaskForId(id, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2325 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2326 | if (tr != null) { |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 2327 | return tr.getTaskDescription(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2328 | } |
| 2329 | } |
| 2330 | return null; |
| 2331 | } |
| 2332 | |
| 2333 | @Override |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2334 | public boolean setTaskWindowingMode(int taskId, int windowingMode, boolean toTop) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2335 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 2336 | return setTaskWindowingModeSplitScreenPrimary(taskId, toTop); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2337 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2338 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setTaskWindowingMode()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2339 | synchronized (mGlobalLock) { |
| 2340 | final long ident = Binder.clearCallingIdentity(); |
| 2341 | try { |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2342 | if (WindowConfiguration.isSplitScreenWindowingMode(windowingMode)) { |
| 2343 | return setTaskWindowingModeSplitScreen(taskId, windowingMode, toTop); |
| 2344 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2345 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2346 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2347 | if (task == null) { |
| 2348 | Slog.w(TAG, "setTaskWindowingMode: No task for id=" + taskId); |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2349 | return false; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | if (DEBUG_STACK) Slog.d(TAG_STACK, "setTaskWindowingMode: moving task=" + taskId |
| 2353 | + " to windowingMode=" + windowingMode + " toTop=" + toTop); |
| 2354 | |
| 2355 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2356 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2357 | + " non-standard task " + taskId + " to windowing mode=" |
| 2358 | + windowingMode); |
| 2359 | } |
| 2360 | |
| 2361 | final ActivityStack stack = task.getStack(); |
| 2362 | if (toTop) { |
| 2363 | stack.moveToFront("setTaskWindowingMode", task); |
| 2364 | } |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2365 | // Convert some windowing-mode changes into root-task reparents for split-screen. |
| 2366 | if (stack.inSplitScreenWindowingMode()) { |
Andrii Kulian | 9ea12da | 2020-03-27 17:16:38 -0700 | [diff] [blame] | 2367 | stack.getDisplay().mTaskContainers.onSplitScreenModeDismissed(); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2368 | |
| 2369 | } else { |
| 2370 | stack.setWindowingMode(windowingMode); |
| 2371 | stack.getDisplay().ensureActivitiesVisible(null, 0, PRESERVE_WINDOWS, |
| 2372 | true /* notifyClients */); |
| 2373 | } |
Winson Chung | 7ccc681 | 2020-01-23 16:15:10 -0800 | [diff] [blame] | 2374 | return true; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2375 | } finally { |
| 2376 | Binder.restoreCallingIdentity(ident); |
| 2377 | } |
| 2378 | } |
| 2379 | } |
| 2380 | |
| 2381 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2382 | public String getCallingPackage(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2383 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2384 | ActivityRecord r = getCallingRecordLocked(token); |
| 2385 | return r != null ? r.info.packageName : null; |
| 2386 | } |
| 2387 | } |
| 2388 | |
| 2389 | @Override |
| 2390 | public ComponentName getCallingActivity(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2391 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2392 | ActivityRecord r = getCallingRecordLocked(token); |
| 2393 | return r != null ? r.intent.getComponent() : null; |
| 2394 | } |
| 2395 | } |
| 2396 | |
| 2397 | private ActivityRecord getCallingRecordLocked(IBinder token) { |
| 2398 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2399 | if (r == null) { |
| 2400 | return null; |
| 2401 | } |
| 2402 | return r.resultTo; |
| 2403 | } |
| 2404 | |
| 2405 | @Override |
| 2406 | public void unhandledBack() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2407 | mAmInternal.enforceCallingPermission(android.Manifest.permission.FORCE_BACK, "unhandledBack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2408 | |
| 2409 | synchronized (mGlobalLock) { |
| 2410 | final long origId = Binder.clearCallingIdentity(); |
| 2411 | try { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 2412 | final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); |
| 2413 | if (topFocusedStack != null) { |
| 2414 | topFocusedStack.unhandledBackLocked(); |
| 2415 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2416 | } finally { |
| 2417 | Binder.restoreCallingIdentity(origId); |
| 2418 | } |
| 2419 | } |
| 2420 | } |
| 2421 | |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2422 | @Override |
| 2423 | public void onBackPressedOnTaskRoot(IBinder token, IRequestFinishCallback callback) { |
| 2424 | synchronized (mGlobalLock) { |
| 2425 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2426 | if (r == null) { |
| 2427 | return; |
| 2428 | } |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2429 | ActivityStack stack = r.getRootTask(); |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2430 | if (stack != null && stack.isSingleTaskInstance()) { |
| 2431 | // Single-task stacks are used for activities which are presented in floating |
| 2432 | // windows above full screen activities. Instead of directly finishing the |
| 2433 | // task, a task change listener is used to notify SystemUI so the action can be |
| 2434 | // handled specially. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2435 | final Task task = r.getTask(); |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2436 | mTaskChangeNotificationController |
| 2437 | .notifyBackPressedOnTaskRoot(task.getTaskInfo()); |
| 2438 | } else { |
| 2439 | try { |
| 2440 | callback.requestFinish(); |
| 2441 | } catch (RemoteException e) { |
| 2442 | Slog.e(TAG, "Failed to invoke request finish callback", e); |
| 2443 | } |
| 2444 | } |
| 2445 | } |
| 2446 | } |
| 2447 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2448 | /** |
| 2449 | * TODO: Add mController hook |
| 2450 | */ |
| 2451 | @Override |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2452 | public void moveTaskToFront(IApplicationThread appThread, String callingPackage, int taskId, |
| 2453 | int flags, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2454 | mAmInternal.enforceCallingPermission(android.Manifest.permission.REORDER_TASKS, "moveTaskToFront()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2455 | |
| 2456 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToFront: moving taskId=" + taskId); |
| 2457 | synchronized (mGlobalLock) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2458 | moveTaskToFrontLocked(appThread, callingPackage, taskId, flags, |
| 2459 | SafeActivityOptions.fromBundle(bOptions), false /* fromRecents */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2460 | } |
| 2461 | } |
| 2462 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2463 | void moveTaskToFrontLocked(@Nullable IApplicationThread appThread, |
| 2464 | @Nullable String callingPackage, int taskId, int flags, SafeActivityOptions options, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2465 | boolean fromRecents) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2466 | final int callingPid = Binder.getCallingPid(); |
| 2467 | final int callingUid = Binder.getCallingUid(); |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 2468 | assertPackageMatchesCallingUid(callingPackage); |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2469 | if (!checkAppSwitchAllowedLocked(callingPid, callingUid, -1, -1, "Task to front")) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2470 | SafeActivityOptions.abort(options); |
| 2471 | return; |
| 2472 | } |
| 2473 | final long origId = Binder.clearCallingIdentity(); |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2474 | WindowProcessController callerApp = null; |
| 2475 | if (appThread != null) { |
| 2476 | callerApp = getProcessController(appThread); |
| 2477 | } |
| 2478 | final ActivityStarter starter = getActivityStartController().obtainStarter( |
| 2479 | null /* intent */, "moveTaskToFront"); |
| 2480 | if (starter.shouldAbortBackgroundActivityStart(callingUid, callingPid, callingPackage, -1, |
Galia Peycheva | 6861e91 | 2019-08-21 10:20:23 +0200 | [diff] [blame] | 2481 | -1, callerApp, null, false, false, null)) { |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 2482 | if (!isBackgroundActivityStartsEnabled()) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2483 | return; |
| 2484 | } |
| 2485 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2486 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2487 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2488 | if (task == null) { |
| 2489 | Slog.d(TAG, "Could not find task for id: "+ taskId); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2490 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2491 | return; |
| 2492 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2493 | if (getLockTaskController().isLockTaskModeViolation(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2494 | Slog.e(TAG, "moveTaskToFront: Attempt to violate Lock Task Mode"); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2495 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2496 | return; |
| 2497 | } |
| 2498 | ActivityOptions realOptions = options != null |
| 2499 | ? options.getOptions(mStackSupervisor) |
| 2500 | : null; |
| 2501 | mStackSupervisor.findTaskToMoveToFront(task, flags, realOptions, "moveTaskToFront", |
| 2502 | false /* forceNonResizable */); |
| 2503 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 2504 | final ActivityRecord topActivity = task.getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2505 | if (topActivity != null) { |
| 2506 | |
| 2507 | // We are reshowing a task, use a starting window to hide the initial draw delay |
| 2508 | // so the transition can start earlier. |
| 2509 | topActivity.showStartingWindow(null /* prev */, false /* newTask */, |
| 2510 | true /* taskSwitch */, fromRecents); |
| 2511 | } |
| 2512 | } finally { |
| 2513 | Binder.restoreCallingIdentity(origId); |
| 2514 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2515 | } |
| 2516 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2517 | /** |
| 2518 | * Return true if callingUid is system, or packageName belongs to that callingUid. |
| 2519 | */ |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 2520 | private boolean isSameApp(int callingUid, @Nullable String packageName) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2521 | try { |
| 2522 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 2523 | if (packageName == null) { |
| 2524 | return false; |
| 2525 | } |
| 2526 | final int uid = AppGlobals.getPackageManager().getPackageUid(packageName, |
| 2527 | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 2528 | UserHandle.getUserId(callingUid)); |
| 2529 | return UserHandle.isSameApp(callingUid, uid); |
| 2530 | } |
| 2531 | } catch (RemoteException e) { |
| 2532 | // Should not happen |
| 2533 | } |
| 2534 | return true; |
| 2535 | } |
| 2536 | |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 2537 | /** |
| 2538 | * Checks that the provided package name matches the current calling UID, throws a security |
| 2539 | * exception if it doesn't. |
| 2540 | */ |
| 2541 | void assertPackageMatchesCallingUid(@Nullable String packageName) { |
| 2542 | final int callingUid = Binder.getCallingUid(); |
| 2543 | if (isSameApp(callingUid, packageName)) { |
| 2544 | return; |
| 2545 | } |
| 2546 | final String msg = "Permission Denial: package=" + packageName |
| 2547 | + " does not belong to uid=" + callingUid; |
| 2548 | Slog.w(TAG, msg); |
| 2549 | throw new SecurityException(msg); |
| 2550 | } |
| 2551 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2552 | boolean checkAppSwitchAllowedLocked(int sourcePid, int sourceUid, |
| 2553 | int callingPid, int callingUid, String name) { |
| 2554 | if (mAppSwitchesAllowedTime < SystemClock.uptimeMillis()) { |
| 2555 | return true; |
| 2556 | } |
| 2557 | |
| 2558 | if (getRecentTasks().isCallerRecents(sourceUid)) { |
| 2559 | return true; |
| 2560 | } |
| 2561 | |
| 2562 | int perm = checkComponentPermission(STOP_APP_SWITCHES, sourcePid, sourceUid, -1, true); |
| 2563 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2564 | return true; |
| 2565 | } |
| 2566 | if (checkAllowAppSwitchUid(sourceUid)) { |
| 2567 | return true; |
| 2568 | } |
| 2569 | |
| 2570 | // If the actual IPC caller is different from the logical source, then |
| 2571 | // also see if they are allowed to control app switches. |
| 2572 | if (callingUid != -1 && callingUid != sourceUid) { |
| 2573 | perm = checkComponentPermission(STOP_APP_SWITCHES, callingPid, callingUid, -1, true); |
| 2574 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2575 | return true; |
| 2576 | } |
| 2577 | if (checkAllowAppSwitchUid(callingUid)) { |
| 2578 | return true; |
| 2579 | } |
| 2580 | } |
| 2581 | |
| 2582 | Slog.w(TAG, name + " request from " + sourceUid + " stopped"); |
| 2583 | return false; |
| 2584 | } |
| 2585 | |
| 2586 | private boolean checkAllowAppSwitchUid(int uid) { |
| 2587 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(UserHandle.getUserId(uid)); |
| 2588 | if (types != null) { |
| 2589 | for (int i = types.size() - 1; i >= 0; i--) { |
| 2590 | if (types.valueAt(i).intValue() == uid) { |
| 2591 | return true; |
| 2592 | } |
| 2593 | } |
| 2594 | } |
| 2595 | return false; |
| 2596 | } |
| 2597 | |
| 2598 | @Override |
| 2599 | public void setActivityController(IActivityController controller, boolean imAMonkey) { |
| 2600 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER, |
| 2601 | "setActivityController()"); |
| 2602 | synchronized (mGlobalLock) { |
| 2603 | mController = controller; |
| 2604 | mControllerIsAMonkey = imAMonkey; |
| 2605 | Watchdog.getInstance().setActivityController(controller); |
| 2606 | } |
| 2607 | } |
| 2608 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 2609 | public boolean isControllerAMonkey() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2610 | synchronized (mGlobalLock) { |
| 2611 | return mController != null && mControllerIsAMonkey; |
| 2612 | } |
| 2613 | } |
| 2614 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2615 | @Override |
| 2616 | public int getTaskForActivity(IBinder token, boolean onlyRoot) { |
| 2617 | synchronized (mGlobalLock) { |
| 2618 | return ActivityRecord.getTaskForActivityLocked(token, onlyRoot); |
| 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2623 | public List<ActivityManager.RunningTaskInfo> getTasks(int maxNum) { |
Winson Chung | e5ab017 | 2020-03-21 23:00:24 -0700 | [diff] [blame] | 2624 | return getFilteredTasks(maxNum, false /* filterForVisibleRecents */); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2625 | } |
| 2626 | |
Winson Chung | e5ab017 | 2020-03-21 23:00:24 -0700 | [diff] [blame] | 2627 | /** |
| 2628 | * @param filterOnlyVisibleRecents whether to filter the tasks based on whether they would ever |
| 2629 | * be visible in the recent task list in systemui |
| 2630 | */ |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2631 | @Override |
| 2632 | public List<ActivityManager.RunningTaskInfo> getFilteredTasks(int maxNum, |
Winson Chung | e5ab017 | 2020-03-21 23:00:24 -0700 | [diff] [blame] | 2633 | boolean filterOnlyVisibleRecents) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2634 | final int callingUid = Binder.getCallingUid(); |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 2635 | final int callingPid = Binder.getCallingPid(); |
| 2636 | final boolean crossUser = isCrossUserAllowed(callingPid, callingUid); |
Nicholas Sauer | 3f9249f | 2019-09-10 20:23:41 -0700 | [diff] [blame] | 2637 | final int[] profileIds = getUserManager().getProfileIds( |
| 2638 | UserHandle.getUserId(callingUid), true); |
| 2639 | ArraySet<Integer> callingProfileIds = new ArraySet<>(); |
| 2640 | for (int i = 0; i < profileIds.length; i++) { |
| 2641 | callingProfileIds.add(profileIds[i]); |
| 2642 | } |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2643 | ArrayList<ActivityManager.RunningTaskInfo> list = new ArrayList<>(); |
| 2644 | |
| 2645 | synchronized (mGlobalLock) { |
| 2646 | if (DEBUG_ALL) Slog.v(TAG, "getTasks: max=" + maxNum); |
| 2647 | |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 2648 | final boolean allowed = isGetTasksAllowed("getTasks", callingPid, callingUid); |
Winson Chung | e5ab017 | 2020-03-21 23:00:24 -0700 | [diff] [blame] | 2649 | mRootWindowContainer.getRunningTasks(maxNum, list, filterOnlyVisibleRecents, callingUid, |
| 2650 | allowed, crossUser, callingProfileIds); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | return list; |
| 2654 | } |
| 2655 | |
| 2656 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2657 | public final void finishSubActivity(IBinder token, String resultWho, int requestCode) { |
| 2658 | synchronized (mGlobalLock) { |
| 2659 | final long origId = Binder.clearCallingIdentity(); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2660 | try { |
| 2661 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2662 | if (r == null) return; |
| 2663 | |
| 2664 | final PooledConsumer c = PooledLambda.obtainConsumer( |
| 2665 | ActivityRecord::finishIfSubActivity, PooledLambda.__(ActivityRecord.class), |
| 2666 | r, resultWho, requestCode); |
| 2667 | // TODO: This should probably only loop over the task since you need to be in the |
| 2668 | // same task to return results. |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 2669 | r.getRootTask().forAllActivities(c); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2670 | c.recycle(); |
| 2671 | |
| 2672 | updateOomAdj(); |
| 2673 | } finally { |
| 2674 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2675 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2676 | } |
| 2677 | } |
| 2678 | |
| 2679 | @Override |
| 2680 | public boolean willActivityBeVisible(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2681 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2682 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 2683 | if (stack != null) { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2684 | return stack.willActivityBeVisible(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2685 | } |
| 2686 | return false; |
| 2687 | } |
| 2688 | } |
| 2689 | |
| 2690 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2691 | public void moveTaskToStack(int taskId, int stackId, boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2692 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "moveTaskToStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2693 | synchronized (mGlobalLock) { |
| 2694 | final long ident = Binder.clearCallingIdentity(); |
| 2695 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2696 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2697 | if (task == null) { |
| 2698 | Slog.w(TAG, "moveTaskToStack: No task for id=" + taskId); |
| 2699 | return; |
| 2700 | } |
| 2701 | |
| 2702 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToStack: moving task=" + taskId |
| 2703 | + " to stackId=" + stackId + " toTop=" + toTop); |
| 2704 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2705 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2706 | if (stack == null) { |
| 2707 | throw new IllegalStateException( |
| 2708 | "moveTaskToStack: No stack for stackId=" + stackId); |
| 2709 | } |
| 2710 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 2711 | throw new IllegalArgumentException("moveTaskToStack: Attempt to move task " |
| 2712 | + taskId + " to stack " + stackId); |
| 2713 | } |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2714 | task.reparent(stack, toTop, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME, |
| 2715 | "moveTaskToStack"); |
| 2716 | } finally { |
| 2717 | Binder.restoreCallingIdentity(ident); |
| 2718 | } |
| 2719 | } |
| 2720 | } |
| 2721 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2722 | /** |
| 2723 | * Moves the specified task to the primary-split-screen stack. |
| 2724 | * |
| 2725 | * @param taskId Id of task to move. |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2726 | * @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] | 2727 | * @return Whether the task was successfully put into splitscreen. |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2728 | */ |
| 2729 | @Override |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 2730 | public boolean setTaskWindowingModeSplitScreenPrimary(int taskId, boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2731 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2732 | "setTaskWindowingModeSplitScreenPrimary()"); |
| 2733 | synchronized (mGlobalLock) { |
| 2734 | final long ident = Binder.clearCallingIdentity(); |
| 2735 | try { |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2736 | return setTaskWindowingModeSplitScreen(taskId, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, |
| 2737 | toTop); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2738 | } finally { |
| 2739 | Binder.restoreCallingIdentity(ident); |
| 2740 | } |
| 2741 | } |
| 2742 | } |
| 2743 | |
| 2744 | /** |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2745 | * Moves the specified task into a split-screen tile. |
| 2746 | */ |
| 2747 | private boolean setTaskWindowingModeSplitScreen(int taskId, int windowingMode, boolean toTop) { |
| 2748 | if (!WindowConfiguration.isSplitScreenWindowingMode(windowingMode)) { |
| 2749 | throw new IllegalArgumentException("Calling setTaskWindowingModeSplitScreen with non" |
| 2750 | + "split-screen mode: " + windowingMode); |
| 2751 | } |
| 2752 | if (isInLockTaskMode()) { |
| 2753 | Slog.w(TAG, "setTaskWindowingModeSplitScreen: Is in lock task mode=" |
| 2754 | + getLockTaskModeState()); |
| 2755 | return false; |
| 2756 | } |
| 2757 | |
| 2758 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
| 2759 | MATCH_TASK_IN_STACKS_ONLY); |
| 2760 | if (task == null) { |
| 2761 | Slog.w(TAG, "setTaskWindowingModeSplitScreenPrimary: No task for id=" + taskId); |
| 2762 | return false; |
| 2763 | } |
| 2764 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2765 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2766 | + " non-standard task " + taskId + " to split-screen windowing mode"); |
| 2767 | } |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 2768 | if (!task.supportsSplitScreenWindowingMode()) { |
| 2769 | return false; |
| 2770 | } |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2771 | |
| 2772 | final int prevMode = task.getWindowingMode(); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2773 | moveTaskToSplitScreenPrimaryTask(task, toTop); |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 2774 | return prevMode != task.getWindowingMode(); |
| 2775 | } |
| 2776 | |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2777 | void moveTaskToSplitScreenPrimaryTask(Task task, boolean toTop) { |
| 2778 | final DisplayContent display = task.getDisplayContent(); |
| 2779 | final ActivityStack primarySplitTask = display.getRootSplitScreenPrimaryTask(); |
| 2780 | if (primarySplitTask == null) { |
| 2781 | throw new IllegalStateException("Can't enter split without associated organized task"); |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2782 | } |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2783 | |
| 2784 | if (toTop) { |
Andrii Kulian | 9ea12da | 2020-03-27 17:16:38 -0700 | [diff] [blame] | 2785 | display.mTaskContainers.positionStackAt(POSITION_TOP, primarySplitTask, |
| 2786 | false /* includingParents */); |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2787 | } |
| 2788 | WindowContainerTransaction wct = new WindowContainerTransaction(); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 2789 | wct.reparent(task.getStack().mRemoteToken, primarySplitTask.mRemoteToken, toTop); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 2790 | mWindowOrganizerController.applyTransaction(wct); |
Evan Rosky | af9f27c | 2020-02-18 18:58:35 +0000 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | /** |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2794 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 2795 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 2796 | */ |
| 2797 | @Override |
| 2798 | public void removeStacksInWindowingModes(int[] windowingModes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2799 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2800 | "removeStacksInWindowingModes()"); |
| 2801 | |
| 2802 | synchronized (mGlobalLock) { |
| 2803 | final long ident = Binder.clearCallingIdentity(); |
| 2804 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2805 | mRootWindowContainer.removeStacksInWindowingModes(windowingModes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2806 | } finally { |
| 2807 | Binder.restoreCallingIdentity(ident); |
| 2808 | } |
| 2809 | } |
| 2810 | } |
| 2811 | |
| 2812 | @Override |
| 2813 | public void removeStacksWithActivityTypes(int[] activityTypes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2814 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2815 | "removeStacksWithActivityTypes()"); |
| 2816 | |
| 2817 | synchronized (mGlobalLock) { |
| 2818 | final long ident = Binder.clearCallingIdentity(); |
| 2819 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2820 | mRootWindowContainer.removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2821 | } finally { |
| 2822 | Binder.restoreCallingIdentity(ident); |
| 2823 | } |
| 2824 | } |
| 2825 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2826 | |
| 2827 | @Override |
| 2828 | public ParceledListSlice<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, |
| 2829 | int userId) { |
| 2830 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2831 | userId = handleIncomingUser(Binder.getCallingPid(), callingUid, userId, "getRecentTasks"); |
| 2832 | final boolean allowed = isGetTasksAllowed("getRecentTasks", Binder.getCallingPid(), |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2833 | callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2834 | synchronized (mGlobalLock) { |
Winson Chung | 66b08f0 | 2020-03-03 14:32:35 -0800 | [diff] [blame] | 2835 | return mRecentTasks.getRecentTasks(maxNum, flags, allowed, userId, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2836 | } |
| 2837 | } |
| 2838 | |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 2839 | // TODO(148895075): deprecate and replace with task equivalents |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2840 | @Override |
| 2841 | public List<ActivityManager.StackInfo> getAllStackInfos() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2842 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2843 | long ident = Binder.clearCallingIdentity(); |
| 2844 | try { |
| 2845 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2846 | return mRootWindowContainer.getAllStackInfos(INVALID_DISPLAY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2847 | } |
| 2848 | } finally { |
| 2849 | Binder.restoreCallingIdentity(ident); |
| 2850 | } |
| 2851 | } |
| 2852 | |
| 2853 | @Override |
| 2854 | public ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2855 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2856 | long ident = Binder.clearCallingIdentity(); |
| 2857 | try { |
| 2858 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2859 | return mRootWindowContainer.getStackInfo(windowingMode, activityType); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2860 | } |
| 2861 | } finally { |
| 2862 | Binder.restoreCallingIdentity(ident); |
| 2863 | } |
| 2864 | } |
| 2865 | |
Evan Rosky | 29d4a0a | 2020-02-04 16:40:44 -0800 | [diff] [blame] | 2866 | // TODO(148895075): deprecate and replace with task equivalents |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2867 | @Override |
Evan Rosky | fd43969 | 2019-11-06 16:12:59 -0800 | [diff] [blame] | 2868 | public List<ActivityManager.StackInfo> getAllStackInfosOnDisplay(int displayId) { |
| 2869 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); |
| 2870 | long ident = Binder.clearCallingIdentity(); |
| 2871 | try { |
| 2872 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2873 | return mRootWindowContainer.getAllStackInfos(displayId); |
Evan Rosky | fd43969 | 2019-11-06 16:12:59 -0800 | [diff] [blame] | 2874 | } |
| 2875 | } finally { |
| 2876 | Binder.restoreCallingIdentity(ident); |
| 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | @Override |
| 2881 | public ActivityManager.StackInfo getStackInfoOnDisplay(int windowingMode, int activityType, |
| 2882 | int displayId) { |
| 2883 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
| 2884 | long ident = Binder.clearCallingIdentity(); |
| 2885 | try { |
| 2886 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2887 | return mRootWindowContainer.getStackInfo(windowingMode, activityType, displayId); |
Evan Rosky | fd43969 | 2019-11-06 16:12:59 -0800 | [diff] [blame] | 2888 | } |
| 2889 | } finally { |
| 2890 | Binder.restoreCallingIdentity(ident); |
| 2891 | } |
| 2892 | } |
| 2893 | |
| 2894 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2895 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2896 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "cancelRecentsAnimation()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2897 | final long callingUid = Binder.getCallingUid(); |
| 2898 | final long origId = Binder.clearCallingIdentity(); |
| 2899 | try { |
| 2900 | synchronized (mGlobalLock) { |
| 2901 | // Cancel the recents animation synchronously (do not hold the WM lock) |
Wale Ogunwale | a441b92 | 2019-06-27 19:21:44 -0700 | [diff] [blame] | 2902 | mWindowManager.cancelRecentsAnimation(restoreHomeStackPosition |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2903 | ? REORDER_MOVE_TO_ORIGINAL_POSITION |
| 2904 | : REORDER_KEEP_IN_PLACE, "cancelRecentsAnimation/uid=" + callingUid); |
| 2905 | } |
| 2906 | } finally { |
| 2907 | Binder.restoreCallingIdentity(origId); |
| 2908 | } |
| 2909 | } |
| 2910 | |
| 2911 | @Override |
| 2912 | public void startLockTaskModeByToken(IBinder token) { |
| 2913 | synchronized (mGlobalLock) { |
| 2914 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2915 | if (r == null) { |
| 2916 | return; |
| 2917 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2918 | startLockTaskModeLocked(r.getTask(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2919 | } |
| 2920 | } |
| 2921 | |
| 2922 | @Override |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2923 | public void startSystemLockTaskMode(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2924 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "startSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2925 | // This makes inner call to look as if it was initiated by system. |
| 2926 | long ident = Binder.clearCallingIdentity(); |
| 2927 | try { |
| 2928 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2929 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2930 | MATCH_TASK_IN_STACKS_ONLY); |
| 2931 | if (task == null) { |
| 2932 | return; |
| 2933 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2934 | |
| 2935 | // When starting lock task mode the stack must be in front and focused |
| 2936 | task.getStack().moveToFront("startSystemLockTaskMode"); |
| 2937 | startLockTaskModeLocked(task, true /* isSystemCaller */); |
| 2938 | } |
| 2939 | } finally { |
| 2940 | Binder.restoreCallingIdentity(ident); |
| 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | @Override |
| 2945 | public void stopLockTaskModeByToken(IBinder token) { |
| 2946 | synchronized (mGlobalLock) { |
| 2947 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2948 | if (r == null) { |
| 2949 | return; |
| 2950 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2951 | stopLockTaskModeInternal(r.getTask(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2952 | } |
| 2953 | } |
| 2954 | |
| 2955 | /** |
| 2956 | * This API should be called by SystemUI only when user perform certain action to dismiss |
| 2957 | * lock task mode. We should only dismiss pinned lock task mode in this case. |
| 2958 | */ |
| 2959 | @Override |
| 2960 | public void stopSystemLockTaskMode() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2961 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "stopSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2962 | stopLockTaskModeInternal(null, true /* isSystemCaller */); |
| 2963 | } |
| 2964 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2965 | private void startLockTaskModeLocked(@Nullable Task task, boolean isSystemCaller) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2966 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "startLockTaskModeLocked: " + task); |
| 2967 | if (task == null || task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) { |
| 2968 | return; |
| 2969 | } |
| 2970 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2971 | final ActivityStack stack = mRootWindowContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2972 | if (stack == null || task != stack.getTopMostTask()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2973 | throw new IllegalArgumentException("Invalid task, not in foreground"); |
| 2974 | } |
| 2975 | |
| 2976 | // {@code isSystemCaller} is used to distinguish whether this request is initiated by the |
| 2977 | // system or a specific app. |
| 2978 | // * System-initiated requests will only start the pinned mode (screen pinning) |
| 2979 | // * App-initiated requests |
| 2980 | // - will put the device in fully locked mode (LockTask), if the app is whitelisted |
| 2981 | // - will start the pinned mode, otherwise |
| 2982 | final int callingUid = Binder.getCallingUid(); |
| 2983 | long ident = Binder.clearCallingIdentity(); |
| 2984 | try { |
| 2985 | // When a task is locked, dismiss the pinned stack if it exists |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 2986 | mRootWindowContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2987 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2988 | getLockTaskController().startLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2989 | } finally { |
| 2990 | Binder.restoreCallingIdentity(ident); |
| 2991 | } |
| 2992 | } |
| 2993 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2994 | private void stopLockTaskModeInternal(@Nullable Task task, boolean isSystemCaller) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2995 | final int callingUid = Binder.getCallingUid(); |
| 2996 | long ident = Binder.clearCallingIdentity(); |
| 2997 | try { |
| 2998 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2999 | getLockTaskController().stopLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3000 | } |
| 3001 | // Launch in-call UI if a call is ongoing. This is necessary to allow stopping the lock |
| 3002 | // task and jumping straight into a call in the case of emergency call back. |
| 3003 | TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
| 3004 | if (tm != null) { |
| 3005 | tm.showInCallScreen(false); |
| 3006 | } |
| 3007 | } finally { |
| 3008 | Binder.restoreCallingIdentity(ident); |
| 3009 | } |
| 3010 | } |
| 3011 | |
| 3012 | @Override |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 3013 | public void updateLockTaskPackages(int userId, String[] packages) { |
| 3014 | final int callingUid = Binder.getCallingUid(); |
| 3015 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 3016 | mAmInternal.enforceCallingPermission(Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
| 3017 | "updateLockTaskPackages()"); |
| 3018 | } |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 3019 | synchronized (mGlobalLock) { |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 3020 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Whitelisting " + userId + ":" |
| 3021 | + Arrays.toString(packages)); |
| 3022 | getLockTaskController().updateLockTaskPackages(userId, packages); |
| 3023 | } |
| 3024 | } |
| 3025 | |
| 3026 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3027 | public boolean isInLockTaskMode() { |
| 3028 | return getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
| 3029 | } |
| 3030 | |
| 3031 | @Override |
| 3032 | public int getLockTaskModeState() { |
| 3033 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3034 | return getLockTaskController().getLockTaskModeState(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | @Override |
| 3039 | public void setTaskDescription(IBinder token, ActivityManager.TaskDescription td) { |
| 3040 | synchronized (mGlobalLock) { |
| 3041 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3042 | if (r != null) { |
| 3043 | r.setTaskDescription(td); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3044 | final Task task = r.getTask(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3045 | task.updateTaskDescription(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3046 | } |
| 3047 | } |
| 3048 | } |
| 3049 | |
| 3050 | @Override |
| 3051 | public Bundle getActivityOptions(IBinder token) { |
| 3052 | final long origId = Binder.clearCallingIdentity(); |
| 3053 | try { |
| 3054 | synchronized (mGlobalLock) { |
| 3055 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3056 | if (r != null) { |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 3057 | final ActivityOptions activityOptions = r.takeOptionsLocked( |
| 3058 | true /* fromClient */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3059 | return activityOptions == null ? null : activityOptions.toBundle(); |
| 3060 | } |
| 3061 | return null; |
| 3062 | } |
| 3063 | } finally { |
| 3064 | Binder.restoreCallingIdentity(origId); |
| 3065 | } |
| 3066 | } |
| 3067 | |
| 3068 | @Override |
| 3069 | public List<IBinder> getAppTasks(String callingPackage) { |
| 3070 | int callingUid = Binder.getCallingUid(); |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 3071 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3072 | long ident = Binder.clearCallingIdentity(); |
| 3073 | try { |
| 3074 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3075 | return mRecentTasks.getAppTasksList(callingUid, callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3076 | } |
| 3077 | } finally { |
| 3078 | Binder.restoreCallingIdentity(ident); |
| 3079 | } |
| 3080 | } |
| 3081 | |
| 3082 | @Override |
| 3083 | public void finishVoiceTask(IVoiceInteractionSession session) { |
| 3084 | synchronized (mGlobalLock) { |
| 3085 | final long origId = Binder.clearCallingIdentity(); |
| 3086 | try { |
| 3087 | // TODO: VI Consider treating local voice interactions and voice tasks |
| 3088 | // differently here |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3089 | mRootWindowContainer.finishVoiceTask(session); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3090 | } finally { |
| 3091 | Binder.restoreCallingIdentity(origId); |
| 3092 | } |
| 3093 | } |
| 3094 | |
| 3095 | } |
| 3096 | |
| 3097 | @Override |
| 3098 | public boolean isTopOfTask(IBinder token) { |
| 3099 | synchronized (mGlobalLock) { |
| 3100 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3101 | return r != null && r.getTask().getTopNonFinishingActivity() == r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3102 | } |
| 3103 | } |
| 3104 | |
| 3105 | @Override |
| 3106 | public void notifyLaunchTaskBehindComplete(IBinder token) { |
| 3107 | mStackSupervisor.scheduleLaunchTaskBehindComplete(token); |
| 3108 | } |
| 3109 | |
| 3110 | @Override |
| 3111 | public void notifyEnterAnimationComplete(IBinder token) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3112 | mH.post(() -> { |
| 3113 | synchronized (mGlobalLock) { |
| 3114 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3115 | if (r != null && r.attachedToProcess()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3116 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3117 | r.app.getThread().scheduleEnterAnimationComplete(r.appToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3118 | } catch (RemoteException e) { |
| 3119 | } |
| 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | /** Called from an app when assist data is ready. */ |
| 3127 | @Override |
| 3128 | public void reportAssistContextExtras(IBinder token, Bundle extras, AssistStructure structure, |
| 3129 | AssistContent content, Uri referrer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3130 | PendingAssistExtras pae = (PendingAssistExtras) token; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3131 | synchronized (pae) { |
| 3132 | pae.result = extras; |
| 3133 | pae.structure = structure; |
| 3134 | pae.content = content; |
| 3135 | if (referrer != null) { |
| 3136 | pae.extras.putParcelable(Intent.EXTRA_REFERRER, referrer); |
| 3137 | } |
| 3138 | if (structure != null) { |
Winson Chung | 48b2565 | 2018-10-22 14:04:30 -0700 | [diff] [blame] | 3139 | // Pre-fill the task/activity component for all assist data receivers |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3140 | structure.setTaskId(pae.activity.getTask().mTaskId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3141 | structure.setActivityComponent(pae.activity.mActivityComponent); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3142 | structure.setHomeActivity(pae.isHome); |
| 3143 | } |
| 3144 | pae.haveResult = true; |
| 3145 | pae.notifyAll(); |
| 3146 | if (pae.intent == null && pae.receiver == null) { |
| 3147 | // Caller is just waiting for the result. |
| 3148 | return; |
| 3149 | } |
| 3150 | } |
| 3151 | // We are now ready to launch the assist activity. |
| 3152 | IAssistDataReceiver sendReceiver = null; |
| 3153 | Bundle sendBundle = null; |
| 3154 | synchronized (mGlobalLock) { |
| 3155 | buildAssistBundleLocked(pae, extras); |
| 3156 | boolean exists = mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3157 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3158 | if (!exists) { |
| 3159 | // Timed out. |
| 3160 | return; |
| 3161 | } |
| 3162 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3163 | if ((sendReceiver = pae.receiver) != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3164 | // Caller wants result sent back to them. |
| 3165 | sendBundle = new Bundle(); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3166 | sendBundle.putInt(ActivityTaskManagerInternal.ASSIST_TASK_ID, |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3167 | pae.activity.getTask().mTaskId); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3168 | sendBundle.putBinder(ActivityTaskManagerInternal.ASSIST_ACTIVITY_ID, |
| 3169 | pae.activity.assistToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3170 | sendBundle.putBundle(ASSIST_KEY_DATA, pae.extras); |
| 3171 | sendBundle.putParcelable(ASSIST_KEY_STRUCTURE, pae.structure); |
| 3172 | sendBundle.putParcelable(ASSIST_KEY_CONTENT, pae.content); |
| 3173 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3174 | } |
| 3175 | } |
| 3176 | if (sendReceiver != null) { |
| 3177 | try { |
| 3178 | sendReceiver.onHandleAssistData(sendBundle); |
| 3179 | } catch (RemoteException e) { |
| 3180 | } |
| 3181 | return; |
| 3182 | } |
| 3183 | |
| 3184 | final long ident = Binder.clearCallingIdentity(); |
| 3185 | try { |
| 3186 | if (TextUtils.equals(pae.intent.getAction(), |
| 3187 | android.service.voice.VoiceInteractionService.SERVICE_INTERFACE)) { |
Galia Peycheva | bffbfc3 | 2019-06-18 10:11:35 +0200 | [diff] [blame] | 3188 | // Start voice interaction through VoiceInteractionManagerService. |
| 3189 | mAssistUtils.showSessionForActiveService(sendBundle, SHOW_SOURCE_APPLICATION, |
| 3190 | null, null); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3191 | } else { |
| 3192 | pae.intent.replaceExtras(pae.extras); |
| 3193 | pae.intent.setFlags(FLAG_ACTIVITY_NEW_TASK |
| 3194 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 3195 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 3196 | mInternal.closeSystemDialogs("assist"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3197 | |
| 3198 | try { |
| 3199 | mContext.startActivityAsUser(pae.intent, new UserHandle(pae.userHandle)); |
| 3200 | } catch (ActivityNotFoundException e) { |
| 3201 | Slog.w(TAG, "No activity to handle assist action.", e); |
| 3202 | } |
| 3203 | } |
| 3204 | } finally { |
| 3205 | Binder.restoreCallingIdentity(ident); |
| 3206 | } |
| 3207 | } |
| 3208 | |
| 3209 | @Override |
| 3210 | public int addAppTask(IBinder activityToken, Intent intent, |
| 3211 | ActivityManager.TaskDescription description, Bitmap thumbnail) throws RemoteException { |
| 3212 | final int callingUid = Binder.getCallingUid(); |
| 3213 | final long callingIdent = Binder.clearCallingIdentity(); |
| 3214 | |
| 3215 | try { |
| 3216 | synchronized (mGlobalLock) { |
| 3217 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 3218 | if (r == null) { |
| 3219 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 3220 | + activityToken); |
| 3221 | } |
| 3222 | ComponentName comp = intent.getComponent(); |
| 3223 | if (comp == null) { |
| 3224 | throw new IllegalArgumentException("Intent " + intent |
| 3225 | + " must specify explicit component"); |
| 3226 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3227 | if (thumbnail.getWidth() != mThumbnailWidth |
| 3228 | || thumbnail.getHeight() != mThumbnailHeight) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3229 | throw new IllegalArgumentException("Bad thumbnail size: got " |
| 3230 | + thumbnail.getWidth() + "x" + thumbnail.getHeight() + ", require " |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3231 | + mThumbnailWidth + "x" + mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3232 | } |
| 3233 | if (intent.getSelector() != null) { |
| 3234 | intent.setSelector(null); |
| 3235 | } |
| 3236 | if (intent.getSourceBounds() != null) { |
| 3237 | intent.setSourceBounds(null); |
| 3238 | } |
| 3239 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) { |
| 3240 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) == 0) { |
| 3241 | // The caller has added this as an auto-remove task... that makes no |
| 3242 | // sense, so turn off auto-remove. |
| 3243 | intent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS); |
| 3244 | } |
| 3245 | } |
| 3246 | final ActivityInfo ainfo = AppGlobals.getPackageManager().getActivityInfo(comp, |
| 3247 | STOCK_PM_FLAGS, UserHandle.getUserId(callingUid)); |
| 3248 | if (ainfo.applicationInfo.uid != callingUid) { |
| 3249 | throw new SecurityException( |
| 3250 | "Can't add task for another application: target uid=" |
| 3251 | + ainfo.applicationInfo.uid + ", calling uid=" + callingUid); |
| 3252 | } |
| 3253 | |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 3254 | final ActivityStack stack = r.getRootTask(); |
Andrii Kulian | 9ea12da | 2020-03-27 17:16:38 -0700 | [diff] [blame] | 3255 | final Task task = stack.getDisplay().mTaskContainers.createStack( |
| 3256 | stack.getWindowingMode(), stack.getActivityType(), !ON_TOP, ainfo, intent, |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 3257 | false /* createdByOrganizer */); |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 3258 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3259 | if (!mRecentTasks.addToBottom(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3260 | // 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] | 3261 | stack.removeChild(task, "addAppTask"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3262 | return INVALID_TASK_ID; |
| 3263 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 3264 | task.getTaskDescription().copyFrom(description); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3265 | |
| 3266 | // TODO: Send the thumbnail to WM to store it. |
| 3267 | |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 3268 | return task.mTaskId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3269 | } |
| 3270 | } finally { |
| 3271 | Binder.restoreCallingIdentity(callingIdent); |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | @Override |
| 3276 | public Point getAppTaskThumbnailSize() { |
| 3277 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3278 | return new Point(mThumbnailWidth, mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3279 | } |
| 3280 | } |
| 3281 | |
| 3282 | @Override |
| 3283 | public void setTaskResizeable(int taskId, int resizeableMode) { |
| 3284 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3285 | final Task task = mRootWindowContainer.anyTaskForId( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3286 | taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 3287 | if (task == null) { |
| 3288 | Slog.w(TAG, "setTaskResizeable: taskId=" + taskId + " not found"); |
| 3289 | return; |
| 3290 | } |
| 3291 | task.setResizeMode(resizeableMode); |
| 3292 | } |
| 3293 | } |
| 3294 | |
| 3295 | @Override |
| 3296 | public void resizeTask(int taskId, Rect bounds, int resizeMode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3297 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "resizeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3298 | long ident = Binder.clearCallingIdentity(); |
| 3299 | try { |
| 3300 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3301 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 3302 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3303 | if (task == null) { |
| 3304 | Slog.w(TAG, "resizeTask: taskId=" + taskId + " not found"); |
| 3305 | return; |
| 3306 | } |
| 3307 | // Place the task in the right stack if it isn't there already based on |
| 3308 | // the requested bounds. |
| 3309 | // The stack transition logic is: |
| 3310 | // - a null bounds on a freeform task moves that task to fullscreen |
| 3311 | // - a non-null bounds on a non-freeform (fullscreen OR docked) task moves |
| 3312 | // that task to freeform |
| 3313 | // - otherwise the task is not moved |
| 3314 | ActivityStack stack = task.getStack(); |
| 3315 | if (!task.getWindowConfiguration().canResizeTask()) { |
| 3316 | throw new IllegalArgumentException("resizeTask not allowed on task=" + task); |
| 3317 | } |
| 3318 | if (bounds == null && stack.getWindowingMode() == WINDOWING_MODE_FREEFORM) { |
Andrii Kulian | 9ea12da | 2020-03-27 17:16:38 -0700 | [diff] [blame] | 3319 | stack = stack.getDisplay().mTaskContainers.getOrCreateStack( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3320 | WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), ON_TOP); |
| 3321 | } else if (bounds != null && stack.getWindowingMode() != WINDOWING_MODE_FREEFORM) { |
Andrii Kulian | 9ea12da | 2020-03-27 17:16:38 -0700 | [diff] [blame] | 3322 | stack = stack.getDisplay().mTaskContainers.getOrCreateStack( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3323 | WINDOWING_MODE_FREEFORM, stack.getActivityType(), ON_TOP); |
| 3324 | } |
| 3325 | |
| 3326 | // Reparent the task to the right stack if necessary |
| 3327 | boolean preserveWindow = (resizeMode & RESIZE_MODE_PRESERVE_WINDOW) != 0; |
| 3328 | if (stack != task.getStack()) { |
| 3329 | // Defer resume until the task is resized below |
| 3330 | task.reparent(stack, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, |
| 3331 | DEFER_RESUME, "resizeTask"); |
| 3332 | preserveWindow = false; |
| 3333 | } |
| 3334 | |
| 3335 | // After reparenting (which only resizes the task to the stack bounds), resize the |
| 3336 | // task to the actual bounds provided |
| 3337 | task.resize(bounds, resizeMode, preserveWindow, !DEFER_RESUME); |
| 3338 | } |
| 3339 | } finally { |
| 3340 | Binder.restoreCallingIdentity(ident); |
| 3341 | } |
| 3342 | } |
| 3343 | |
| 3344 | @Override |
| 3345 | public boolean releaseActivityInstance(IBinder token) { |
| 3346 | synchronized (mGlobalLock) { |
| 3347 | final long origId = Binder.clearCallingIdentity(); |
| 3348 | try { |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 3349 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3350 | if (r == null || !r.isDestroyable()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3351 | return false; |
| 3352 | } |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 3353 | r.destroyImmediately(true /* removeFromApp */, "app-req"); |
| 3354 | return r.isState(DESTROYING, DESTROYED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3355 | } finally { |
| 3356 | Binder.restoreCallingIdentity(origId); |
| 3357 | } |
| 3358 | } |
| 3359 | } |
| 3360 | |
| 3361 | @Override |
| 3362 | public void releaseSomeActivities(IApplicationThread appInt) { |
| 3363 | synchronized (mGlobalLock) { |
| 3364 | final long origId = Binder.clearCallingIdentity(); |
| 3365 | try { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3366 | final WindowProcessController app = getProcessController(appInt); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 3367 | app.releaseSomeActivities("low-mem"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3368 | } finally { |
| 3369 | Binder.restoreCallingIdentity(origId); |
| 3370 | } |
| 3371 | } |
| 3372 | } |
| 3373 | |
| 3374 | @Override |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 3375 | public void setLockScreenShown(boolean keyguardShowing, boolean aodShowing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3376 | if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3377 | != PackageManager.PERMISSION_GRANTED) { |
| 3378 | throw new SecurityException("Requires permission " |
| 3379 | + android.Manifest.permission.DEVICE_POWER); |
| 3380 | } |
| 3381 | |
| 3382 | synchronized (mGlobalLock) { |
| 3383 | long ident = Binder.clearCallingIdentity(); |
| 3384 | if (mKeyguardShown != keyguardShowing) { |
| 3385 | mKeyguardShown = keyguardShowing; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3386 | final Message msg = PooledLambda.obtainMessage( |
| 3387 | ActivityManagerInternal::reportCurKeyguardUsageEvent, mAmInternal, |
| 3388 | keyguardShowing); |
| 3389 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3390 | } |
| 3391 | try { |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 3392 | mKeyguardController.setKeyguardShown(keyguardShowing, aodShowing); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3393 | } finally { |
| 3394 | Binder.restoreCallingIdentity(ident); |
| 3395 | } |
| 3396 | } |
| 3397 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3398 | mH.post(() -> { |
| 3399 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3400 | mScreenObservers.get(i).onKeyguardStateChanged(keyguardShowing); |
| 3401 | } |
| 3402 | }); |
| 3403 | } |
| 3404 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 3405 | public void onScreenAwakeChanged(boolean isAwake) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3406 | mH.post(() -> { |
| 3407 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3408 | mScreenObservers.get(i).onAwakeStateChanged(isAwake); |
| 3409 | } |
| 3410 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3411 | } |
| 3412 | |
| 3413 | @Override |
| 3414 | public Bitmap getTaskDescriptionIcon(String filePath, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3415 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 3416 | userId, "getTaskDescriptionIcon"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3417 | |
| 3418 | final File passedIconFile = new File(filePath); |
| 3419 | final File legitIconFile = new File(TaskPersister.getUserImagesDir(userId), |
| 3420 | passedIconFile.getName()); |
| 3421 | if (!legitIconFile.getPath().equals(filePath) |
| 3422 | || !filePath.contains(ActivityRecord.ACTIVITY_ICON_SUFFIX)) { |
| 3423 | throw new IllegalArgumentException("Bad file path: " + filePath |
| 3424 | + " passed for userId " + userId); |
| 3425 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3426 | return mRecentTasks.getTaskDescriptionIcon(filePath); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3427 | } |
| 3428 | |
| 3429 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3430 | public void removeStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3431 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "removeStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3432 | synchronized (mGlobalLock) { |
| 3433 | final long ident = Binder.clearCallingIdentity(); |
| 3434 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3435 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3436 | if (stack == null) { |
| 3437 | Slog.w(TAG, "removeStack: No stack with id=" + stackId); |
| 3438 | return; |
| 3439 | } |
| 3440 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3441 | throw new IllegalArgumentException( |
| 3442 | "Removing non-standard stack is not allowed."); |
| 3443 | } |
| 3444 | mStackSupervisor.removeStack(stack); |
| 3445 | } finally { |
| 3446 | Binder.restoreCallingIdentity(ident); |
| 3447 | } |
| 3448 | } |
| 3449 | } |
| 3450 | |
| 3451 | @Override |
| 3452 | public void moveStackToDisplay(int stackId, int displayId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3453 | mAmInternal.enforceCallingPermission(INTERNAL_SYSTEM_WINDOW, "moveStackToDisplay()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3454 | |
| 3455 | synchronized (mGlobalLock) { |
| 3456 | final long ident = Binder.clearCallingIdentity(); |
| 3457 | try { |
| 3458 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveStackToDisplay: moving stackId=" + stackId |
| 3459 | + " to displayId=" + displayId); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3460 | mRootWindowContainer.moveStackToDisplay(stackId, displayId, ON_TOP); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3461 | } finally { |
| 3462 | Binder.restoreCallingIdentity(ident); |
| 3463 | } |
| 3464 | } |
| 3465 | } |
| 3466 | |
| 3467 | @Override |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3468 | public void toggleFreeformWindowingMode(IBinder token) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3469 | synchronized (mGlobalLock) { |
| 3470 | long ident = Binder.clearCallingIdentity(); |
| 3471 | try { |
| 3472 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3473 | if (r == null) { |
| 3474 | throw new IllegalArgumentException( |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3475 | "toggleFreeformWindowingMode: No activity record matching token=" |
| 3476 | + token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3477 | } |
| 3478 | |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 3479 | final ActivityStack stack = r.getRootTask(); |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3480 | if (stack == null) { |
| 3481 | throw new IllegalStateException("toggleFreeformWindowingMode: the activity " |
| 3482 | + "doesn't have a stack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3485 | if (!stack.inFreeformWindowingMode() |
| 3486 | && stack.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) { |
| 3487 | throw new IllegalStateException("toggleFreeformWindowingMode: You can only " |
| 3488 | + "toggle between fullscreen and freeform."); |
| 3489 | } |
| 3490 | |
| 3491 | if (stack.inFreeformWindowingMode()) { |
| 3492 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Evan Rosky | 3a8d7fe | 2019-11-06 17:08:35 -0800 | [diff] [blame] | 3493 | } else if (!mSizeCompatFreeform && r.inSizeCompatMode()) { |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 3494 | throw new IllegalStateException("Size-compat windows are currently not" |
| 3495 | + "freeform-enabled"); |
Yunfan Chen | e9c1c31 | 2019-04-18 14:49:15 +0900 | [diff] [blame] | 3496 | } else if (stack.getParent().inFreeformWindowingMode()) { |
| 3497 | // If the window is on a freeform display, set it to undefined. It will be |
| 3498 | // resolved to freeform and it can adjust windowing mode when the display mode |
| 3499 | // changes in runtime. |
| 3500 | stack.setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3501 | } else { |
| 3502 | stack.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 3503 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3504 | } finally { |
| 3505 | Binder.restoreCallingIdentity(ident); |
| 3506 | } |
| 3507 | } |
| 3508 | } |
| 3509 | |
| 3510 | /** Sets the task stack listener that gets callbacks when a task stack changes. */ |
| 3511 | @Override |
| 3512 | public void registerTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3513 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3514 | "registerTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3515 | mTaskChangeNotificationController.registerTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | /** Unregister a task stack listener so that it stops receiving callbacks. */ |
| 3519 | @Override |
| 3520 | public void unregisterTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3521 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3522 | "unregisterTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3523 | mTaskChangeNotificationController.unregisterTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3524 | } |
| 3525 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3526 | @Override |
| 3527 | public boolean requestAssistContextExtras(int requestType, IAssistDataReceiver receiver, |
| 3528 | Bundle receiverExtras, IBinder activityToken, boolean focused, boolean newSessionId) { |
| 3529 | return enqueueAssistContext(requestType, null, null, receiver, receiverExtras, |
| 3530 | activityToken, focused, newSessionId, UserHandle.getCallingUserId(), null, |
| 3531 | PENDING_ASSIST_EXTRAS_LONG_TIMEOUT, 0) != null; |
| 3532 | } |
| 3533 | |
| 3534 | @Override |
| 3535 | public boolean requestAutofillData(IAssistDataReceiver receiver, Bundle receiverExtras, |
| 3536 | IBinder activityToken, int flags) { |
| 3537 | return enqueueAssistContext(ActivityManager.ASSIST_CONTEXT_AUTOFILL, null, null, |
| 3538 | receiver, receiverExtras, activityToken, true, true, UserHandle.getCallingUserId(), |
| 3539 | null, PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT, flags) != null; |
| 3540 | } |
| 3541 | |
| 3542 | @Override |
| 3543 | public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle, |
| 3544 | Bundle args) { |
| 3545 | return enqueueAssistContext(requestType, intent, hint, null, null, null, |
| 3546 | true /* focused */, true /* newSessionId */, userHandle, args, |
| 3547 | PENDING_ASSIST_EXTRAS_TIMEOUT, 0) != null; |
| 3548 | } |
| 3549 | |
| 3550 | @Override |
| 3551 | public Bundle getAssistContextExtras(int requestType) { |
| 3552 | PendingAssistExtras pae = enqueueAssistContext(requestType, null, null, null, |
| 3553 | null, null, true /* focused */, true /* newSessionId */, |
| 3554 | UserHandle.getCallingUserId(), null, PENDING_ASSIST_EXTRAS_TIMEOUT, 0); |
| 3555 | if (pae == null) { |
| 3556 | return null; |
| 3557 | } |
| 3558 | synchronized (pae) { |
| 3559 | while (!pae.haveResult) { |
| 3560 | try { |
| 3561 | pae.wait(); |
| 3562 | } catch (InterruptedException e) { |
| 3563 | } |
| 3564 | } |
| 3565 | } |
| 3566 | synchronized (mGlobalLock) { |
| 3567 | buildAssistBundleLocked(pae, pae.result); |
| 3568 | mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3569 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3570 | } |
| 3571 | return pae.extras; |
| 3572 | } |
| 3573 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3574 | /** |
| 3575 | * Binder IPC calls go through the public entry point. |
| 3576 | * This can be called with or without the global lock held. |
| 3577 | */ |
| 3578 | private static int checkCallingPermission(String permission) { |
| 3579 | return checkPermission( |
| 3580 | permission, Binder.getCallingPid(), UserHandle.getAppId(Binder.getCallingUid())); |
| 3581 | } |
| 3582 | |
| 3583 | /** This can be called with or without the global lock held. */ |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3584 | private void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3585 | if (!getRecentTasks().isCallerRecents(Binder.getCallingUid())) { |
| 3586 | mAmInternal.enforceCallingPermission(permission, func); |
| 3587 | } |
| 3588 | } |
| 3589 | |
| 3590 | @VisibleForTesting |
| 3591 | int checkGetTasksPermission(String permission, int pid, int uid) { |
| 3592 | return checkPermission(permission, pid, uid); |
| 3593 | } |
| 3594 | |
| 3595 | static int checkPermission(String permission, int pid, int uid) { |
| 3596 | if (permission == null) { |
| 3597 | return PackageManager.PERMISSION_DENIED; |
| 3598 | } |
| 3599 | return checkComponentPermission(permission, pid, uid, -1, true); |
| 3600 | } |
| 3601 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3602 | public static int checkComponentPermission(String permission, int pid, int uid, |
| 3603 | int owningUid, boolean exported) { |
| 3604 | return ActivityManagerService.checkComponentPermission( |
| 3605 | permission, pid, uid, owningUid, exported); |
| 3606 | } |
| 3607 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3608 | boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 3609 | if (getRecentTasks().isCallerRecents(callingUid)) { |
| 3610 | // Always allow the recents component to get tasks |
| 3611 | return true; |
| 3612 | } |
| 3613 | |
| 3614 | boolean allowed = checkGetTasksPermission(android.Manifest.permission.REAL_GET_TASKS, |
| 3615 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED; |
| 3616 | if (!allowed) { |
| 3617 | if (checkGetTasksPermission(android.Manifest.permission.GET_TASKS, |
| 3618 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED) { |
| 3619 | // Temporary compatibility: some existing apps on the system image may |
| 3620 | // still be requesting the old permission and not switched to the new |
| 3621 | // one; if so, we'll still allow them full access. This means we need |
| 3622 | // to see if they are holding the old permission and are a system app. |
| 3623 | try { |
| 3624 | if (AppGlobals.getPackageManager().isUidPrivileged(callingUid)) { |
| 3625 | allowed = true; |
| 3626 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3627 | + " is using old GET_TASKS but privileged; allowing"); |
| 3628 | } |
| 3629 | } catch (RemoteException e) { |
| 3630 | } |
| 3631 | } |
| 3632 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3633 | + " does not hold REAL_GET_TASKS; limiting output"); |
| 3634 | } |
| 3635 | return allowed; |
| 3636 | } |
| 3637 | |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 3638 | boolean isCrossUserAllowed(int pid, int uid) { |
| 3639 | return checkPermission(INTERACT_ACROSS_USERS, pid, uid) == PERMISSION_GRANTED |
| 3640 | || checkPermission(INTERACT_ACROSS_USERS_FULL, pid, uid) == PERMISSION_GRANTED; |
| 3641 | } |
| 3642 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3643 | private PendingAssistExtras enqueueAssistContext(int requestType, Intent intent, String hint, |
| 3644 | IAssistDataReceiver receiver, Bundle receiverExtras, IBinder activityToken, |
| 3645 | boolean focused, boolean newSessionId, int userHandle, Bundle args, long timeout, |
| 3646 | int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3647 | mAmInternal.enforceCallingPermission(android.Manifest.permission.GET_TOP_ACTIVITY_INFO, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3648 | "enqueueAssistContext()"); |
| 3649 | |
| 3650 | synchronized (mGlobalLock) { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 3651 | final ActivityStack stack = getTopDisplayFocusedStack(); |
| 3652 | ActivityRecord activity = stack != null ? stack.getTopNonFinishingActivity() : null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3653 | if (activity == null) { |
| 3654 | Slog.w(TAG, "getAssistContextExtras failed: no top activity"); |
| 3655 | return null; |
| 3656 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3657 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3658 | Slog.w(TAG, "getAssistContextExtras failed: no process for " + activity); |
| 3659 | return null; |
| 3660 | } |
| 3661 | if (focused) { |
| 3662 | if (activityToken != null) { |
| 3663 | ActivityRecord caller = ActivityRecord.forTokenLocked(activityToken); |
| 3664 | if (activity != caller) { |
| 3665 | Slog.w(TAG, "enqueueAssistContext failed: caller " + caller |
| 3666 | + " is not current top " + activity); |
| 3667 | return null; |
| 3668 | } |
| 3669 | } |
| 3670 | } else { |
| 3671 | activity = ActivityRecord.forTokenLocked(activityToken); |
| 3672 | if (activity == null) { |
| 3673 | Slog.w(TAG, "enqueueAssistContext failed: activity for token=" + activityToken |
| 3674 | + " couldn't be found"); |
| 3675 | return null; |
| 3676 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3677 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3678 | Slog.w(TAG, "enqueueAssistContext failed: no process for " + activity); |
| 3679 | return null; |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | PendingAssistExtras pae; |
| 3684 | Bundle extras = new Bundle(); |
| 3685 | if (args != null) { |
| 3686 | extras.putAll(args); |
| 3687 | } |
| 3688 | extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3689 | extras.putInt(Intent.EXTRA_ASSIST_UID, activity.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3690 | |
| 3691 | pae = new PendingAssistExtras(activity, extras, intent, hint, receiver, receiverExtras, |
| 3692 | userHandle); |
| 3693 | pae.isHome = activity.isActivityTypeHome(); |
| 3694 | |
| 3695 | // Increment the sessionId if necessary |
| 3696 | if (newSessionId) { |
| 3697 | mViSessionId++; |
| 3698 | } |
| 3699 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3700 | activity.app.getThread().requestAssistContextExtras(activity.appToken, pae, |
| 3701 | requestType, mViSessionId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3702 | mPendingAssistExtras.add(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3703 | mUiHandler.postDelayed(pae, timeout); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3704 | } catch (RemoteException e) { |
| 3705 | Slog.w(TAG, "getAssistContextExtras failed: crash calling " + activity); |
| 3706 | return null; |
| 3707 | } |
| 3708 | return pae; |
| 3709 | } |
| 3710 | } |
| 3711 | |
| 3712 | private void buildAssistBundleLocked(PendingAssistExtras pae, Bundle result) { |
| 3713 | if (result != null) { |
| 3714 | pae.extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, result); |
| 3715 | } |
| 3716 | if (pae.hint != null) { |
| 3717 | pae.extras.putBoolean(pae.hint, true); |
| 3718 | } |
| 3719 | } |
| 3720 | |
| 3721 | private void pendingAssistExtrasTimedOut(PendingAssistExtras pae) { |
| 3722 | IAssistDataReceiver receiver; |
| 3723 | synchronized (mGlobalLock) { |
| 3724 | mPendingAssistExtras.remove(pae); |
| 3725 | receiver = pae.receiver; |
| 3726 | } |
| 3727 | if (receiver != null) { |
| 3728 | // Caller wants result sent back to them. |
| 3729 | Bundle sendBundle = new Bundle(); |
| 3730 | // At least return the receiver extras |
| 3731 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3732 | try { |
| 3733 | pae.receiver.onHandleAssistData(sendBundle); |
| 3734 | } catch (RemoteException e) { |
| 3735 | } |
| 3736 | } |
| 3737 | } |
| 3738 | |
| 3739 | public class PendingAssistExtras extends Binder implements Runnable { |
| 3740 | public final ActivityRecord activity; |
| 3741 | public boolean isHome; |
| 3742 | public final Bundle extras; |
| 3743 | public final Intent intent; |
| 3744 | public final String hint; |
| 3745 | public final IAssistDataReceiver receiver; |
| 3746 | public final int userHandle; |
| 3747 | public boolean haveResult = false; |
| 3748 | public Bundle result = null; |
| 3749 | public AssistStructure structure = null; |
| 3750 | public AssistContent content = null; |
| 3751 | public Bundle receiverExtras; |
| 3752 | |
| 3753 | public PendingAssistExtras(ActivityRecord _activity, Bundle _extras, Intent _intent, |
| 3754 | String _hint, IAssistDataReceiver _receiver, Bundle _receiverExtras, |
| 3755 | int _userHandle) { |
| 3756 | activity = _activity; |
| 3757 | extras = _extras; |
| 3758 | intent = _intent; |
| 3759 | hint = _hint; |
| 3760 | receiver = _receiver; |
| 3761 | receiverExtras = _receiverExtras; |
| 3762 | userHandle = _userHandle; |
| 3763 | } |
| 3764 | |
| 3765 | @Override |
| 3766 | public void run() { |
| 3767 | Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from " + activity); |
| 3768 | synchronized (this) { |
| 3769 | haveResult = true; |
| 3770 | notifyAll(); |
| 3771 | } |
| 3772 | pendingAssistExtrasTimedOut(this); |
| 3773 | } |
| 3774 | } |
| 3775 | |
| 3776 | @Override |
| 3777 | public boolean isAssistDataAllowedOnCurrentActivity() { |
| 3778 | int userId; |
| 3779 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3780 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3781 | if (focusedStack == null || focusedStack.isActivityTypeAssistant()) { |
| 3782 | return false; |
| 3783 | } |
| 3784 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3785 | final ActivityRecord activity = focusedStack.getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3786 | if (activity == null) { |
| 3787 | return false; |
| 3788 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3789 | userId = activity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3790 | } |
| 3791 | return !DevicePolicyCache.getInstance().getScreenCaptureDisabled(userId); |
| 3792 | } |
| 3793 | |
| 3794 | @Override |
| 3795 | public boolean showAssistFromActivity(IBinder token, Bundle args) { |
| 3796 | long ident = Binder.clearCallingIdentity(); |
| 3797 | try { |
| 3798 | synchronized (mGlobalLock) { |
| 3799 | ActivityRecord caller = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3800 | ActivityRecord top = getTopDisplayFocusedStack().getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3801 | if (top != caller) { |
| 3802 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3803 | + " is not current top " + top); |
| 3804 | return false; |
| 3805 | } |
| 3806 | if (!top.nowVisible) { |
| 3807 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3808 | + " is not visible"); |
| 3809 | return false; |
| 3810 | } |
| 3811 | } |
| 3812 | return mAssistUtils.showSessionForActiveService(args, SHOW_SOURCE_APPLICATION, null, |
| 3813 | token); |
| 3814 | } finally { |
| 3815 | Binder.restoreCallingIdentity(ident); |
| 3816 | } |
| 3817 | } |
| 3818 | |
| 3819 | @Override |
| 3820 | public boolean isRootVoiceInteraction(IBinder token) { |
| 3821 | synchronized (mGlobalLock) { |
| 3822 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3823 | if (r == null) { |
| 3824 | return false; |
| 3825 | } |
| 3826 | return r.rootVoiceInteraction; |
| 3827 | } |
| 3828 | } |
| 3829 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3830 | private void onLocalVoiceInteractionStartedLocked(IBinder activity, |
| 3831 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 3832 | ActivityRecord activityToCallback = ActivityRecord.forTokenLocked(activity); |
| 3833 | if (activityToCallback == null) return; |
| 3834 | activityToCallback.setVoiceSessionLocked(voiceSession); |
| 3835 | |
| 3836 | // Inform the activity |
| 3837 | try { |
| 3838 | activityToCallback.app.getThread().scheduleLocalVoiceInteractionStarted(activity, |
| 3839 | voiceInteractor); |
| 3840 | long token = Binder.clearCallingIdentity(); |
| 3841 | try { |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 3842 | startRunningVoiceLocked(voiceSession, activityToCallback.info.applicationInfo.uid); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3843 | } finally { |
| 3844 | Binder.restoreCallingIdentity(token); |
| 3845 | } |
| 3846 | // TODO: VI Should we cache the activity so that it's easier to find later |
| 3847 | // rather than scan through all the stacks and activities? |
| 3848 | } catch (RemoteException re) { |
| 3849 | activityToCallback.clearVoiceSessionLocked(); |
| 3850 | // TODO: VI Should this terminate the voice session? |
| 3851 | } |
| 3852 | } |
| 3853 | |
| 3854 | private void startRunningVoiceLocked(IVoiceInteractionSession session, int targetUid) { |
| 3855 | Slog.d(TAG, "<<< startRunningVoiceLocked()"); |
| 3856 | mVoiceWakeLock.setWorkSource(new WorkSource(targetUid)); |
| 3857 | if (mRunningVoice == null || mRunningVoice.asBinder() != session.asBinder()) { |
| 3858 | boolean wasRunningVoice = mRunningVoice != null; |
| 3859 | mRunningVoice = session; |
| 3860 | if (!wasRunningVoice) { |
| 3861 | mVoiceWakeLock.acquire(); |
| 3862 | updateSleepIfNeededLocked(); |
| 3863 | } |
| 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | void finishRunningVoiceLocked() { |
| 3868 | if (mRunningVoice != null) { |
| 3869 | mRunningVoice = null; |
| 3870 | mVoiceWakeLock.release(); |
| 3871 | updateSleepIfNeededLocked(); |
| 3872 | } |
| 3873 | } |
| 3874 | |
| 3875 | @Override |
| 3876 | public void setVoiceKeepAwake(IVoiceInteractionSession session, boolean keepAwake) { |
| 3877 | synchronized (mGlobalLock) { |
| 3878 | if (mRunningVoice != null && mRunningVoice.asBinder() == session.asBinder()) { |
| 3879 | if (keepAwake) { |
| 3880 | mVoiceWakeLock.acquire(); |
| 3881 | } else { |
| 3882 | mVoiceWakeLock.release(); |
| 3883 | } |
| 3884 | } |
| 3885 | } |
| 3886 | } |
| 3887 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3888 | @Override |
| 3889 | public ComponentName getActivityClassForToken(IBinder token) { |
| 3890 | synchronized (mGlobalLock) { |
| 3891 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3892 | if (r == null) { |
| 3893 | return null; |
| 3894 | } |
| 3895 | return r.intent.getComponent(); |
| 3896 | } |
| 3897 | } |
| 3898 | |
| 3899 | @Override |
| 3900 | public String getPackageForToken(IBinder token) { |
| 3901 | synchronized (mGlobalLock) { |
| 3902 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3903 | if (r == null) { |
| 3904 | return null; |
| 3905 | } |
| 3906 | return r.packageName; |
| 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | @Override |
| 3911 | public void showLockTaskEscapeMessage(IBinder token) { |
| 3912 | synchronized (mGlobalLock) { |
| 3913 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3914 | if (r == null) { |
| 3915 | return; |
| 3916 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3917 | getLockTaskController().showLockTaskToast(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3918 | } |
| 3919 | } |
| 3920 | |
| 3921 | @Override |
| 3922 | public void keyguardGoingAway(int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3923 | enforceNotIsolatedCaller("keyguardGoingAway"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3924 | final long token = Binder.clearCallingIdentity(); |
| 3925 | try { |
| 3926 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3927 | mKeyguardController.keyguardGoingAway(flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3928 | } |
| 3929 | } finally { |
| 3930 | Binder.restoreCallingIdentity(token); |
| 3931 | } |
| 3932 | } |
| 3933 | |
| 3934 | /** |
| 3935 | * Try to place task to provided position. The final position might be different depending on |
| 3936 | * current user and stacks state. The task will be moved to target stack if it's currently in |
| 3937 | * different stack. |
| 3938 | */ |
| 3939 | @Override |
| 3940 | public void positionTaskInStack(int taskId, int stackId, int position) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3941 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "positionTaskInStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3942 | synchronized (mGlobalLock) { |
| 3943 | long ident = Binder.clearCallingIdentity(); |
| 3944 | try { |
| 3945 | if (DEBUG_STACK) Slog.d(TAG_STACK, "positionTaskInStack: positioning task=" |
| 3946 | + taskId + " in stackId=" + stackId + " at position=" + position); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3947 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3948 | if (task == null) { |
| 3949 | throw new IllegalArgumentException("positionTaskInStack: no task for id=" |
| 3950 | + taskId); |
| 3951 | } |
| 3952 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 3953 | final ActivityStack stack = mRootWindowContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3954 | |
| 3955 | if (stack == null) { |
| 3956 | throw new IllegalArgumentException("positionTaskInStack: no stack for id=" |
| 3957 | + stackId); |
| 3958 | } |
| 3959 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3960 | throw new IllegalArgumentException("positionTaskInStack: Attempt to change" |
| 3961 | + " the position of task " + taskId + " in/to non-standard stack"); |
| 3962 | } |
| 3963 | |
| 3964 | // TODO: Have the callers of this API call a separate reparent method if that is |
| 3965 | // what they intended to do vs. having this method also do reparenting. |
| 3966 | if (task.getStack() == stack) { |
| 3967 | // Change position in current stack. |
| 3968 | stack.positionChildAt(task, position); |
| 3969 | } else { |
| 3970 | // Reparent to new stack. |
| 3971 | task.reparent(stack, position, REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, |
| 3972 | !DEFER_RESUME, "positionTaskInStack"); |
| 3973 | } |
| 3974 | } finally { |
| 3975 | Binder.restoreCallingIdentity(ident); |
| 3976 | } |
| 3977 | } |
| 3978 | } |
| 3979 | |
| 3980 | @Override |
| 3981 | public void reportSizeConfigurations(IBinder token, int[] horizontalSizeConfiguration, |
| 3982 | int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { |
| 3983 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Report configuration: " + token + " " |
Yuichiro Hanada | e7e930b | 2019-06-06 19:07:21 +0900 | [diff] [blame] | 3984 | + Arrays.toString(horizontalSizeConfiguration) + " " |
| 3985 | + Arrays.toString(verticalSizeConfigurations)); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3986 | synchronized (mGlobalLock) { |
| 3987 | ActivityRecord record = ActivityRecord.isInStackLocked(token); |
| 3988 | if (record == null) { |
| 3989 | throw new IllegalArgumentException("reportSizeConfigurations: ActivityRecord not " |
| 3990 | + "found for: " + token); |
| 3991 | } |
| 3992 | record.setSizeConfigurations(horizontalSizeConfiguration, |
| 3993 | verticalSizeConfigurations, smallestSizeConfigurations); |
| 3994 | } |
| 3995 | } |
| 3996 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3997 | @Override |
| 3998 | public void suppressResizeConfigChanges(boolean suppress) throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3999 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "suppressResizeConfigChanges()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4000 | synchronized (mGlobalLock) { |
| 4001 | mSuppressResizeConfigChanges = suppress; |
| 4002 | } |
| 4003 | } |
| 4004 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4005 | @Override |
| 4006 | // TODO: API should just be about changing windowing modes... |
| 4007 | public void moveTasksToFullscreenStack(int fromStackId, boolean onTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4008 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4009 | "moveTasksToFullscreenStack()"); |
| 4010 | synchronized (mGlobalLock) { |
| 4011 | final long origId = Binder.clearCallingIdentity(); |
| 4012 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4013 | final ActivityStack stack = mRootWindowContainer.getStack(fromStackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4014 | if (stack != null){ |
| 4015 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 4016 | throw new IllegalArgumentException( |
| 4017 | "You can't move tasks from non-standard stacks."); |
| 4018 | } |
| 4019 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, onTop); |
| 4020 | } |
| 4021 | } finally { |
| 4022 | Binder.restoreCallingIdentity(origId); |
| 4023 | } |
| 4024 | } |
| 4025 | } |
| 4026 | |
| 4027 | /** |
| 4028 | * Moves the top activity in the input stackId to the pinned stack. |
| 4029 | * |
| 4030 | * @param stackId Id of stack to move the top activity to pinned stack. |
| 4031 | * @param bounds Bounds to use for pinned stack. |
| 4032 | * |
| 4033 | * @return True if the top activity of the input stack was successfully moved to the pinned |
| 4034 | * stack. |
| 4035 | */ |
| 4036 | @Override |
| 4037 | public boolean moveTopActivityToPinnedStack(int stackId, Rect bounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4038 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4039 | "moveTopActivityToPinnedStack()"); |
| 4040 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4041 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4042 | throw new IllegalStateException("moveTopActivityToPinnedStack:" |
| 4043 | + "Device doesn't support picture-in-picture mode"); |
| 4044 | } |
| 4045 | |
| 4046 | long ident = Binder.clearCallingIdentity(); |
| 4047 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4048 | return mRootWindowContainer.moveTopStackActivityToPinnedStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4049 | } finally { |
| 4050 | Binder.restoreCallingIdentity(ident); |
| 4051 | } |
| 4052 | } |
| 4053 | } |
| 4054 | |
| 4055 | @Override |
| 4056 | public boolean isInMultiWindowMode(IBinder token) { |
| 4057 | final long origId = Binder.clearCallingIdentity(); |
| 4058 | try { |
| 4059 | synchronized (mGlobalLock) { |
| 4060 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4061 | if (r == null) { |
| 4062 | return false; |
| 4063 | } |
| 4064 | // An activity is consider to be in multi-window mode if its task isn't fullscreen. |
| 4065 | return r.inMultiWindowMode(); |
| 4066 | } |
| 4067 | } finally { |
| 4068 | Binder.restoreCallingIdentity(origId); |
| 4069 | } |
| 4070 | } |
| 4071 | |
| 4072 | @Override |
| 4073 | public boolean isInPictureInPictureMode(IBinder token) { |
| 4074 | final long origId = Binder.clearCallingIdentity(); |
| 4075 | try { |
| 4076 | synchronized (mGlobalLock) { |
| 4077 | return isInPictureInPictureMode(ActivityRecord.forTokenLocked(token)); |
| 4078 | } |
| 4079 | } finally { |
| 4080 | Binder.restoreCallingIdentity(origId); |
| 4081 | } |
| 4082 | } |
| 4083 | |
| 4084 | private boolean isInPictureInPictureMode(ActivityRecord r) { |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 4085 | return r != null |
| 4086 | && r.getRootTask() != null |
| 4087 | && r.inPinnedWindowingMode() |
| 4088 | && r.getRootTask().isInStackLocked(r) != null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4089 | } |
| 4090 | |
| 4091 | @Override |
| 4092 | public boolean enterPictureInPictureMode(IBinder token, final PictureInPictureParams params) { |
| 4093 | final long origId = Binder.clearCallingIdentity(); |
| 4094 | try { |
| 4095 | synchronized (mGlobalLock) { |
| 4096 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 4097 | "enterPictureInPictureMode", token, params); |
| 4098 | |
| 4099 | // If the activity is already in picture in picture mode, then just return early |
| 4100 | if (isInPictureInPictureMode(r)) { |
| 4101 | return true; |
| 4102 | } |
| 4103 | |
| 4104 | // Activity supports picture-in-picture, now check that we can enter PiP at this |
| 4105 | // point, if it is |
| 4106 | if (!r.checkEnterPictureInPictureState("enterPictureInPictureMode", |
| 4107 | false /* beforeStopping */)) { |
| 4108 | return false; |
| 4109 | } |
| 4110 | |
| 4111 | final Runnable enterPipRunnable = () -> { |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4112 | synchronized (mGlobalLock) { |
Hyangseok Chae | ed0624e | 2019-11-07 10:15:46 +0900 | [diff] [blame] | 4113 | if (r.getParent() == null) { |
| 4114 | Slog.e(TAG, "Skip enterPictureInPictureMode, destroyed " + r); |
| 4115 | return; |
| 4116 | } |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4117 | // Only update the saved args from the args that are set |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 4118 | r.setPictureInPictureParams(params); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4119 | final float aspectRatio = r.pictureInPictureArgs.getAspectRatio(); |
| 4120 | final List<RemoteAction> actions = r.pictureInPictureArgs.getActions(); |
| 4121 | // Adjust the source bounds by the insets for the transition down |
| 4122 | final Rect sourceBounds = new Rect( |
| 4123 | r.pictureInPictureArgs.getSourceRectHint()); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4124 | mRootWindowContainer.moveActivityToPinnedStack( |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4125 | r, sourceBounds, aspectRatio, "enterPictureInPictureMode"); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 4126 | final ActivityStack stack = r.getRootTask(); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4127 | stack.setPictureInPictureAspectRatio(aspectRatio); |
| 4128 | stack.setPictureInPictureActions(actions); |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 4129 | MetricsLoggerWrapper.logPictureInPictureEnter(mContext, |
| 4130 | r.info.applicationInfo.uid, r.shortComponentName, |
| 4131 | r.supportsEnterPipOnTaskSwitch); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4132 | logPictureInPictureArgs(params); |
| 4133 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4134 | }; |
| 4135 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4136 | if (isKeyguardLocked()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4137 | // If the keyguard is showing or occluded, then try and dismiss it before |
| 4138 | // entering picture-in-picture (this will prompt the user to authenticate if the |
| 4139 | // device is currently locked). |
| 4140 | dismissKeyguard(token, new KeyguardDismissCallback() { |
| 4141 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4142 | public void onDismissSucceeded() { |
| 4143 | mH.post(enterPipRunnable); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4144 | } |
| 4145 | }, null /* message */); |
| 4146 | } else { |
| 4147 | // Enter picture in picture immediately otherwise |
| 4148 | enterPipRunnable.run(); |
| 4149 | } |
| 4150 | return true; |
| 4151 | } |
| 4152 | } finally { |
| 4153 | Binder.restoreCallingIdentity(origId); |
| 4154 | } |
| 4155 | } |
| 4156 | |
| 4157 | @Override |
| 4158 | public void setPictureInPictureParams(IBinder token, final PictureInPictureParams params) { |
| 4159 | final long origId = Binder.clearCallingIdentity(); |
| 4160 | try { |
| 4161 | synchronized (mGlobalLock) { |
| 4162 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 4163 | "setPictureInPictureParams", token, params); |
| 4164 | |
| 4165 | // Only update the saved args from the args that are set |
Robert Carr | f6690d1 | 2020-02-04 14:16:21 -0800 | [diff] [blame] | 4166 | r.setPictureInPictureParams(params); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4167 | if (r.inPinnedWindowingMode()) { |
| 4168 | // If the activity is already in picture-in-picture, update the pinned stack now |
| 4169 | // if it is not already expanding to fullscreen. Otherwise, the arguments will |
| 4170 | // be used the next time the activity enters PiP |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 4171 | final ActivityStack stack = r.getRootTask(); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 4172 | stack.setPictureInPictureAspectRatio( |
| 4173 | r.pictureInPictureArgs.getAspectRatio()); |
| 4174 | stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4175 | } |
| 4176 | logPictureInPictureArgs(params); |
| 4177 | } |
| 4178 | } finally { |
| 4179 | Binder.restoreCallingIdentity(origId); |
| 4180 | } |
| 4181 | } |
| 4182 | |
| 4183 | @Override |
| 4184 | public int getMaxNumPictureInPictureActions(IBinder token) { |
| 4185 | // Currently, this is a static constant, but later, we may change this to be dependent on |
| 4186 | // the context of the activity |
| 4187 | return 3; |
| 4188 | } |
| 4189 | |
| 4190 | private void logPictureInPictureArgs(PictureInPictureParams params) { |
| 4191 | if (params.hasSetActions()) { |
| 4192 | MetricsLogger.histogram(mContext, "tron_varz_picture_in_picture_actions_count", |
| 4193 | params.getActions().size()); |
| 4194 | } |
| 4195 | if (params.hasSetAspectRatio()) { |
| 4196 | LogMaker lm = new LogMaker(MetricsEvent.ACTION_PICTURE_IN_PICTURE_ASPECT_RATIO_CHANGED); |
| 4197 | lm.addTaggedData(MetricsEvent.PICTURE_IN_PICTURE_ASPECT_RATIO, params.getAspectRatio()); |
| 4198 | MetricsLogger.action(lm); |
| 4199 | } |
| 4200 | } |
| 4201 | |
| 4202 | /** |
| 4203 | * Checks the state of the system and the activity associated with the given {@param token} to |
| 4204 | * verify that picture-in-picture is supported for that activity. |
| 4205 | * |
| 4206 | * @return the activity record for the given {@param token} if all the checks pass. |
| 4207 | */ |
| 4208 | private ActivityRecord ensureValidPictureInPictureActivityParamsLocked(String caller, |
| 4209 | IBinder token, PictureInPictureParams params) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4210 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4211 | throw new IllegalStateException(caller |
| 4212 | + ": Device doesn't support picture-in-picture mode."); |
| 4213 | } |
| 4214 | |
| 4215 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 4216 | if (r == null) { |
| 4217 | throw new IllegalStateException(caller |
| 4218 | + ": Can't find activity for token=" + token); |
| 4219 | } |
| 4220 | |
| 4221 | if (!r.supportsPictureInPicture()) { |
| 4222 | throw new IllegalStateException(caller |
| 4223 | + ": Current activity does not support picture-in-picture."); |
| 4224 | } |
| 4225 | |
| 4226 | if (params.hasSetAspectRatio() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4227 | && !mWindowManager.isValidPictureInPictureAspectRatio( |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 4228 | r.getDisplay(), params.getAspectRatio())) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4229 | final float minAspectRatio = mContext.getResources().getFloat( |
| 4230 | com.android.internal.R.dimen.config_pictureInPictureMinAspectRatio); |
| 4231 | final float maxAspectRatio = mContext.getResources().getFloat( |
| 4232 | com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio); |
| 4233 | throw new IllegalArgumentException(String.format(caller |
| 4234 | + ": Aspect ratio is too extreme (must be between %f and %f).", |
| 4235 | minAspectRatio, maxAspectRatio)); |
| 4236 | } |
| 4237 | |
| 4238 | // Truncate the number of actions if necessary |
| 4239 | params.truncateActions(getMaxNumPictureInPictureActions(token)); |
| 4240 | |
| 4241 | return r; |
| 4242 | } |
| 4243 | |
| 4244 | @Override |
| 4245 | public IBinder getUriPermissionOwnerForActivity(IBinder activityToken) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4246 | enforceNotIsolatedCaller("getUriPermissionOwnerForActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4247 | synchronized (mGlobalLock) { |
| 4248 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 4249 | if (r == null) { |
| 4250 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 4251 | + activityToken); |
| 4252 | } |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 4253 | return r.getUriPermissionsLocked().getExternalToken(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4254 | } |
| 4255 | } |
| 4256 | |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 4257 | // TODO(b/149338177): remove when CTS no-longer requires it |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4258 | @Override |
| 4259 | public void resizeDockedStack(Rect dockedBounds, Rect tempDockedTaskBounds, |
| 4260 | Rect tempDockedTaskInsetBounds, |
| 4261 | Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4262 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeDockedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4263 | long ident = Binder.clearCallingIdentity(); |
| 4264 | try { |
| 4265 | synchronized (mGlobalLock) { |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 4266 | final DisplayContent dc = mRootWindowContainer.getDefaultDisplay(); |
Louis Chang | a009c76 | 2020-02-26 11:21:31 +0800 | [diff] [blame] | 4267 | final Task primary = dc.getRootSplitScreenPrimaryTask(); |
| 4268 | final Task secondary = dc.getTask(t -> t.mCreatedByOrganizer && t.isRootTask() |
| 4269 | && t.inSplitScreenSecondaryWindowingMode()); |
Evan Rosky | 73a7fe9 | 2019-11-18 18:28:01 -0800 | [diff] [blame] | 4270 | if (primary == null || secondary == null) { |
| 4271 | return; |
| 4272 | } |
| 4273 | final WindowContainerTransaction wct = new WindowContainerTransaction(); |
| 4274 | final Rect primaryRect = |
| 4275 | tempDockedTaskInsetBounds != null ? tempDockedTaskInsetBounds |
| 4276 | : (tempDockedTaskBounds != null ? tempDockedTaskBounds |
| 4277 | : dockedBounds); |
| 4278 | wct.setBounds(primary.mRemoteToken, primaryRect); |
| 4279 | Rect otherRect = tempOtherTaskInsetBounds != null ? tempOtherTaskInsetBounds |
| 4280 | : tempOtherTaskBounds; |
| 4281 | if (otherRect == null) { |
| 4282 | // Temporary estimation... again this is just for tests. |
| 4283 | otherRect = new Rect(secondary.getBounds()); |
| 4284 | if (dc.getBounds().width() > dc.getBounds().height()) { |
| 4285 | otherRect.left = primaryRect.right + 6; |
| 4286 | } else { |
| 4287 | otherRect.top = primaryRect.bottom + 6; |
| 4288 | } |
| 4289 | } |
| 4290 | wct.setBounds(secondary.mRemoteToken, otherRect); |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 4291 | mWindowOrganizerController.applyTransaction(wct); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4292 | } |
| 4293 | } finally { |
| 4294 | Binder.restoreCallingIdentity(ident); |
| 4295 | } |
| 4296 | } |
| 4297 | |
| 4298 | @Override |
| 4299 | public void setSplitScreenResizing(boolean resizing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4300 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setSplitScreenResizing()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4301 | final long ident = Binder.clearCallingIdentity(); |
| 4302 | try { |
| 4303 | synchronized (mGlobalLock) { |
| 4304 | mStackSupervisor.setSplitScreenResizing(resizing); |
| 4305 | } |
| 4306 | } finally { |
| 4307 | Binder.restoreCallingIdentity(ident); |
| 4308 | } |
| 4309 | } |
| 4310 | |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 4311 | @Override |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 4312 | public IWindowOrganizerController getWindowOrganizerController() { |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 4313 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 568f9f41 | 2020-03-21 22:27:35 -0700 | [diff] [blame] | 4314 | "getWindowOrganizerController()"); |
| 4315 | return mWindowOrganizerController; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 4316 | } |
| 4317 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4318 | /** |
| 4319 | * Check that we have the features required for VR-related API calls, and throw an exception if |
| 4320 | * not. |
| 4321 | */ |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 4322 | public void enforceSystemHasVrFeature() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4323 | if (!mContext.getPackageManager().hasSystemFeature( |
| 4324 | PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE)) { |
| 4325 | throw new UnsupportedOperationException("VR mode not supported on this device!"); |
| 4326 | } |
| 4327 | } |
| 4328 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4329 | @Override |
| 4330 | public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4331 | enforceSystemHasVrFeature(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4332 | |
| 4333 | final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class); |
| 4334 | |
| 4335 | ActivityRecord r; |
| 4336 | synchronized (mGlobalLock) { |
| 4337 | r = ActivityRecord.isInStackLocked(token); |
| 4338 | } |
| 4339 | |
| 4340 | if (r == null) { |
| 4341 | throw new IllegalArgumentException(); |
| 4342 | } |
| 4343 | |
| 4344 | int err; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4345 | if ((err = vrService.hasVrPackage(packageName, r.mUserId)) != |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4346 | VrManagerInternal.NO_ERROR) { |
| 4347 | return err; |
| 4348 | } |
| 4349 | |
| 4350 | // Clear the binder calling uid since this path may call moveToTask(). |
| 4351 | final long callingId = Binder.clearCallingIdentity(); |
| 4352 | try { |
| 4353 | synchronized (mGlobalLock) { |
| 4354 | r.requestedVrComponent = (enabled) ? packageName : null; |
| 4355 | |
| 4356 | // Update associated state if this activity is currently focused |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 4357 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4358 | applyUpdateVrModeLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4359 | } |
| 4360 | return 0; |
| 4361 | } |
| 4362 | } finally { |
| 4363 | Binder.restoreCallingIdentity(callingId); |
| 4364 | } |
| 4365 | } |
| 4366 | |
| 4367 | @Override |
| 4368 | public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) { |
| 4369 | Slog.i(TAG, "Activity tried to startLocalVoiceInteraction"); |
| 4370 | synchronized (mGlobalLock) { |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 4371 | ActivityRecord activity = getTopDisplayFocusedStack().getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4372 | if (ActivityRecord.forTokenLocked(callingActivity) != activity) { |
| 4373 | throw new SecurityException("Only focused activity can call startVoiceInteraction"); |
| 4374 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4375 | if (mRunningVoice != null || activity.getTask().voiceSession != null |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4376 | || activity.voiceSession != null) { |
| 4377 | Slog.w(TAG, "Already in a voice interaction, cannot start new voice interaction"); |
| 4378 | return; |
| 4379 | } |
| 4380 | if (activity.pendingVoiceInteractionStart) { |
| 4381 | Slog.w(TAG, "Pending start of voice interaction already."); |
| 4382 | return; |
| 4383 | } |
| 4384 | activity.pendingVoiceInteractionStart = true; |
| 4385 | } |
| 4386 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4387 | .startLocalVoiceInteraction(callingActivity, options); |
| 4388 | } |
| 4389 | |
| 4390 | @Override |
| 4391 | public void stopLocalVoiceInteraction(IBinder callingActivity) { |
| 4392 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4393 | .stopLocalVoiceInteraction(callingActivity); |
| 4394 | } |
| 4395 | |
| 4396 | @Override |
| 4397 | public boolean supportsLocalVoiceInteraction() { |
| 4398 | return LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4399 | .supportsLocalVoiceInteraction(); |
| 4400 | } |
| 4401 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4402 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4403 | public boolean updateConfiguration(Configuration values) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4404 | mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateConfiguration()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4405 | |
| 4406 | synchronized (mGlobalLock) { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 4407 | if (mWindowManager == null) { |
| 4408 | Slog.w(TAG, "Skip updateConfiguration because mWindowManager isn't set"); |
| 4409 | return false; |
| 4410 | } |
| 4411 | |
| 4412 | if (values == null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4413 | // sentinel: fetch the current configuration from the window manager |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4414 | values = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4415 | } |
| 4416 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 4417 | mH.sendMessage(PooledLambda.obtainMessage( |
| 4418 | ActivityManagerInternal::updateOomLevelsForDisplay, mAmInternal, |
| 4419 | DEFAULT_DISPLAY)); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4420 | |
| 4421 | final long origId = Binder.clearCallingIdentity(); |
| 4422 | try { |
| 4423 | if (values != null) { |
| 4424 | Settings.System.clearConfiguration(values); |
| 4425 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4426 | updateConfigurationLocked(values, null, false, false /* persistent */, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4427 | UserHandle.USER_NULL, false /* deferResume */, |
| 4428 | mTmpUpdateConfigurationResult); |
| 4429 | return mTmpUpdateConfigurationResult.changes != 0; |
| 4430 | } finally { |
| 4431 | Binder.restoreCallingIdentity(origId); |
| 4432 | } |
| 4433 | } |
| 4434 | } |
| 4435 | |
| 4436 | @Override |
| 4437 | public void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback, |
| 4438 | CharSequence message) { |
| 4439 | if (message != null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4440 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4441 | Manifest.permission.SHOW_KEYGUARD_MESSAGE, "dismissKeyguard()"); |
| 4442 | } |
| 4443 | final long callingId = Binder.clearCallingIdentity(); |
| 4444 | try { |
| 4445 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4446 | mKeyguardController.dismissKeyguard(token, callback, message); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4447 | } |
| 4448 | } finally { |
| 4449 | Binder.restoreCallingIdentity(callingId); |
| 4450 | } |
| 4451 | } |
| 4452 | |
| 4453 | @Override |
| 4454 | public void cancelTaskWindowTransition(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4455 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4456 | "cancelTaskWindowTransition()"); |
| 4457 | final long ident = Binder.clearCallingIdentity(); |
| 4458 | try { |
| 4459 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4460 | final Task task = mRootWindowContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4461 | MATCH_TASK_IN_STACKS_ONLY); |
| 4462 | if (task == null) { |
| 4463 | Slog.w(TAG, "cancelTaskWindowTransition: taskId=" + taskId + " not found"); |
| 4464 | return; |
| 4465 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 4466 | task.cancelTaskWindowTransition(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4467 | } |
| 4468 | } finally { |
| 4469 | Binder.restoreCallingIdentity(ident); |
| 4470 | } |
| 4471 | } |
| 4472 | |
| 4473 | @Override |
Peter Kalauskas | 4dc0460 | 2020-02-12 18:49:03 -0800 | [diff] [blame] | 4474 | public ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4475 | enforceCallerIsRecentsOrHasPermission(READ_FRAME_BUFFER, "getTaskSnapshot()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4476 | final long ident = Binder.clearCallingIdentity(); |
| 4477 | try { |
Peter Kalauskas | 4dc0460 | 2020-02-12 18:49:03 -0800 | [diff] [blame] | 4478 | return getTaskSnapshot(taskId, isLowResolution, true /* restoreFromDisk */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4479 | } finally { |
| 4480 | Binder.restoreCallingIdentity(ident); |
| 4481 | } |
| 4482 | } |
| 4483 | |
Peter Kalauskas | 4dc0460 | 2020-02-12 18:49:03 -0800 | [diff] [blame] | 4484 | private ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution, |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4485 | boolean restoreFromDisk) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4486 | final Task task; |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4487 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4488 | task = mRootWindowContainer.anyTaskForId(taskId, |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4489 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 4490 | if (task == null) { |
| 4491 | Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found"); |
| 4492 | return null; |
| 4493 | } |
| 4494 | } |
| 4495 | // 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] | 4496 | return task.getSnapshot(isLowResolution, restoreFromDisk); |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4497 | } |
| 4498 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4499 | @Override |
| 4500 | public void setDisablePreviewScreenshots(IBinder token, boolean disable) { |
| 4501 | synchronized (mGlobalLock) { |
| 4502 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4503 | if (r == null) { |
| 4504 | Slog.w(TAG, "setDisablePreviewScreenshots: Unable to find activity for token=" |
| 4505 | + token); |
| 4506 | return; |
| 4507 | } |
| 4508 | final long origId = Binder.clearCallingIdentity(); |
| 4509 | try { |
| 4510 | r.setDisablePreviewScreenshots(disable); |
| 4511 | } finally { |
| 4512 | Binder.restoreCallingIdentity(origId); |
| 4513 | } |
| 4514 | } |
| 4515 | } |
| 4516 | |
Riddle Hsu | 440f88b | 2019-11-06 22:17:35 +0800 | [diff] [blame] | 4517 | @Override |
| 4518 | public void invalidateHomeTaskSnapshot(IBinder token) { |
| 4519 | synchronized (mGlobalLock) { |
| 4520 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4521 | if (r == null || !r.isActivityTypeHome()) { |
| 4522 | return; |
| 4523 | } |
| 4524 | mWindowManager.mTaskSnapshotController.removeSnapshotCache(r.getTask().mTaskId); |
| 4525 | } |
| 4526 | } |
| 4527 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4528 | /** Return the user id of the last resumed activity. */ |
| 4529 | @Override |
| 4530 | public @UserIdInt |
| 4531 | int getLastResumedActivityUserId() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4532 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4533 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, "getLastResumedActivityUserId()"); |
| 4534 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4535 | if (mLastResumedActivity == null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4536 | return getCurrentUserId(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4537 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4538 | return mLastResumedActivity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4539 | } |
| 4540 | } |
| 4541 | |
| 4542 | @Override |
| 4543 | public void updateLockTaskFeatures(int userId, int flags) { |
| 4544 | final int callingUid = Binder.getCallingUid(); |
| 4545 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4546 | mAmInternal.enforceCallingPermission(android.Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4547 | "updateLockTaskFeatures()"); |
| 4548 | } |
| 4549 | synchronized (mGlobalLock) { |
| 4550 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Allowing features " + userId + ":0x" + |
| 4551 | Integer.toHexString(flags)); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 4552 | getLockTaskController().updateLockTaskFeatures(userId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4553 | } |
| 4554 | } |
| 4555 | |
| 4556 | @Override |
| 4557 | public void setShowWhenLocked(IBinder token, boolean showWhenLocked) { |
| 4558 | synchronized (mGlobalLock) { |
| 4559 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4560 | if (r == null) { |
| 4561 | return; |
| 4562 | } |
| 4563 | final long origId = Binder.clearCallingIdentity(); |
| 4564 | try { |
| 4565 | r.setShowWhenLocked(showWhenLocked); |
| 4566 | } finally { |
| 4567 | Binder.restoreCallingIdentity(origId); |
| 4568 | } |
| 4569 | } |
| 4570 | } |
| 4571 | |
| 4572 | @Override |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 4573 | public void setInheritShowWhenLocked(IBinder token, boolean inheritShowWhenLocked) { |
| 4574 | synchronized (mGlobalLock) { |
| 4575 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4576 | if (r == null) { |
| 4577 | return; |
| 4578 | } |
| 4579 | final long origId = Binder.clearCallingIdentity(); |
| 4580 | try { |
| 4581 | r.setInheritShowWhenLocked(inheritShowWhenLocked); |
| 4582 | } finally { |
| 4583 | Binder.restoreCallingIdentity(origId); |
| 4584 | } |
| 4585 | } |
| 4586 | } |
| 4587 | |
| 4588 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4589 | public void setTurnScreenOn(IBinder token, boolean turnScreenOn) { |
| 4590 | synchronized (mGlobalLock) { |
| 4591 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4592 | if (r == null) { |
| 4593 | return; |
| 4594 | } |
| 4595 | final long origId = Binder.clearCallingIdentity(); |
| 4596 | try { |
| 4597 | r.setTurnScreenOn(turnScreenOn); |
| 4598 | } finally { |
| 4599 | Binder.restoreCallingIdentity(origId); |
| 4600 | } |
| 4601 | } |
| 4602 | } |
| 4603 | |
| 4604 | @Override |
| 4605 | public void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4606 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4607 | "registerRemoteAnimations"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4608 | definition.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4609 | synchronized (mGlobalLock) { |
| 4610 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4611 | if (r == null) { |
| 4612 | return; |
| 4613 | } |
| 4614 | final long origId = Binder.clearCallingIdentity(); |
| 4615 | try { |
| 4616 | r.registerRemoteAnimations(definition); |
| 4617 | } finally { |
| 4618 | Binder.restoreCallingIdentity(origId); |
| 4619 | } |
| 4620 | } |
| 4621 | } |
| 4622 | |
| 4623 | @Override |
Winson Chung | 10fc25d | 2019-12-10 14:13:56 -0800 | [diff] [blame] | 4624 | public void unregisterRemoteAnimations(IBinder token) { |
| 4625 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
| 4626 | "unregisterRemoteAnimations"); |
| 4627 | synchronized (mGlobalLock) { |
| 4628 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4629 | if (r == null) { |
| 4630 | return; |
| 4631 | } |
| 4632 | final long origId = Binder.clearCallingIdentity(); |
| 4633 | try { |
| 4634 | r.unregisterRemoteAnimations(); |
| 4635 | } finally { |
| 4636 | Binder.restoreCallingIdentity(origId); |
| 4637 | } |
| 4638 | } |
| 4639 | } |
| 4640 | |
| 4641 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4642 | public void registerRemoteAnimationForNextActivityStart(String packageName, |
| 4643 | RemoteAnimationAdapter adapter) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4644 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4645 | "registerRemoteAnimationForNextActivityStart"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4646 | adapter.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4647 | synchronized (mGlobalLock) { |
| 4648 | final long origId = Binder.clearCallingIdentity(); |
| 4649 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4650 | getActivityStartController().registerRemoteAnimationForNextActivityStart( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4651 | packageName, adapter); |
| 4652 | } finally { |
| 4653 | Binder.restoreCallingIdentity(origId); |
| 4654 | } |
| 4655 | } |
| 4656 | } |
| 4657 | |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4658 | @Override |
| 4659 | public void registerRemoteAnimationsForDisplay(int displayId, |
| 4660 | RemoteAnimationDefinition definition) { |
| 4661 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
| 4662 | "registerRemoteAnimations"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4663 | definition.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4664 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4665 | final DisplayContent display = mRootWindowContainer.getDisplayContent(displayId); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4666 | if (display == null) { |
| 4667 | Slog.e(TAG, "Couldn't find display with id: " + displayId); |
| 4668 | return; |
| 4669 | } |
| 4670 | final long origId = Binder.clearCallingIdentity(); |
| 4671 | try { |
| 4672 | display.mDisplayContent.registerRemoteAnimations(definition); |
| 4673 | } finally { |
| 4674 | Binder.restoreCallingIdentity(origId); |
| 4675 | } |
| 4676 | } |
| 4677 | } |
| 4678 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4679 | /** @see android.app.ActivityManager#alwaysShowUnsupportedCompileSdkWarning */ |
| 4680 | @Override |
| 4681 | public void alwaysShowUnsupportedCompileSdkWarning(ComponentName activity) { |
| 4682 | synchronized (mGlobalLock) { |
| 4683 | final long origId = Binder.clearCallingIdentity(); |
| 4684 | try { |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 4685 | mAppWarnings.alwaysShowUnsupportedCompileSdkWarning(activity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4686 | } finally { |
| 4687 | Binder.restoreCallingIdentity(origId); |
| 4688 | } |
| 4689 | } |
| 4690 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 4691 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4692 | @Override |
| 4693 | public void setVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4694 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4695 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4696 | final int pid = Binder.getCallingPid(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 4697 | final WindowProcessController wpc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4698 | mVrController.setVrThreadLocked(tid, pid, wpc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4699 | } |
| 4700 | } |
| 4701 | |
| 4702 | @Override |
| 4703 | public void setPersistentVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4704 | if (checkCallingPermission(Manifest.permission.RESTRICTED_VR_ACCESS) |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4705 | != PERMISSION_GRANTED) { |
| 4706 | final String msg = "Permission Denial: setPersistentVrThread() from pid=" |
| 4707 | + Binder.getCallingPid() |
| 4708 | + ", uid=" + Binder.getCallingUid() |
| 4709 | + " requires " + Manifest.permission.RESTRICTED_VR_ACCESS; |
| 4710 | Slog.w(TAG, msg); |
| 4711 | throw new SecurityException(msg); |
| 4712 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4713 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4714 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4715 | final int pid = Binder.getCallingPid(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 4716 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4717 | mVrController.setPersistentVrThreadLocked(tid, pid, proc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4718 | } |
| 4719 | } |
| 4720 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4721 | @Override |
| 4722 | public void stopAppSwitches() { |
| 4723 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "stopAppSwitches"); |
| 4724 | synchronized (mGlobalLock) { |
| 4725 | mAppSwitchesAllowedTime = SystemClock.uptimeMillis() + APP_SWITCH_DELAY_TIME; |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 4726 | mLastStopAppSwitchesTime = SystemClock.uptimeMillis(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4727 | mDidAppSwitch = false; |
| 4728 | getActivityStartController().schedulePendingActivityLaunches(APP_SWITCH_DELAY_TIME); |
| 4729 | } |
| 4730 | } |
| 4731 | |
| 4732 | @Override |
| 4733 | public void resumeAppSwitches() { |
| 4734 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "resumeAppSwitches"); |
| 4735 | synchronized (mGlobalLock) { |
| 4736 | // Note that we don't execute any pending app switches... we will |
| 4737 | // let those wait until either the timeout, or the next start |
| 4738 | // activity request. |
| 4739 | mAppSwitchesAllowedTime = 0; |
| 4740 | } |
| 4741 | } |
| 4742 | |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 4743 | long getLastStopAppSwitchesTime() { |
| 4744 | return mLastStopAppSwitchesTime; |
| 4745 | } |
| 4746 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4747 | void onStartActivitySetDidAppSwitch() { |
| 4748 | if (mDidAppSwitch) { |
| 4749 | // This is the second allowed switch since we stopped switches, so now just generally |
| 4750 | // allow switches. Use case: |
| 4751 | // - user presses home (switches disabled, switch to home, mDidAppSwitch now true); |
| 4752 | // - user taps a home icon (coming from home so allowed, we hit here and now allow |
| 4753 | // anyone to switch again). |
| 4754 | mAppSwitchesAllowedTime = 0; |
| 4755 | } else { |
| 4756 | mDidAppSwitch = true; |
| 4757 | } |
| 4758 | } |
| 4759 | |
| 4760 | /** @return whether the system should disable UI modes incompatible with VR mode. */ |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4761 | boolean shouldDisableNonVrUiLocked() { |
| 4762 | return mVrController.shouldDisableNonVrUiLocked(); |
| 4763 | } |
| 4764 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4765 | private void applyUpdateVrModeLocked(ActivityRecord r) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4766 | // 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] | 4767 | // 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] | 4768 | if (r.requestedVrComponent != null && r.getDisplayId() != DEFAULT_DISPLAY) { |
Wale Ogunwale | b8e6b63 | 2019-06-28 15:19:25 +0000 | [diff] [blame] | 4769 | Slog.i(TAG, "Moving " + r.shortComponentName + " from display " + r.getDisplayId() |
| 4770 | + " to main display for VR"); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4771 | mRootWindowContainer.moveStackToDisplay( |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 4772 | r.getRootTaskId(), DEFAULT_DISPLAY, true /* toTop */); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4773 | } |
| 4774 | mH.post(() -> { |
| 4775 | if (!mVrController.onVrModeChanged(r)) { |
| 4776 | return; |
| 4777 | } |
| 4778 | synchronized (mGlobalLock) { |
| 4779 | final boolean disableNonVrUi = mVrController.shouldDisableNonVrUiLocked(); |
| 4780 | mWindowManager.disableNonVrUi(disableNonVrUi); |
| 4781 | if (disableNonVrUi) { |
| 4782 | // If we are in a VR mode where Picture-in-Picture mode is unsupported, |
| 4783 | // then remove the pinned stack. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4784 | mRootWindowContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4785 | } |
| 4786 | } |
| 4787 | }); |
| 4788 | } |
| 4789 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4790 | @Override |
| 4791 | public int getPackageScreenCompatMode(String packageName) { |
| 4792 | enforceNotIsolatedCaller("getPackageScreenCompatMode"); |
| 4793 | synchronized (mGlobalLock) { |
| 4794 | return mCompatModePackages.getPackageScreenCompatModeLocked(packageName); |
| 4795 | } |
| 4796 | } |
| 4797 | |
| 4798 | @Override |
| 4799 | public void setPackageScreenCompatMode(String packageName, int mode) { |
| 4800 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4801 | "setPackageScreenCompatMode"); |
| 4802 | synchronized (mGlobalLock) { |
| 4803 | mCompatModePackages.setPackageScreenCompatModeLocked(packageName, mode); |
| 4804 | } |
| 4805 | } |
| 4806 | |
| 4807 | @Override |
| 4808 | public boolean getPackageAskScreenCompat(String packageName) { |
| 4809 | enforceNotIsolatedCaller("getPackageAskScreenCompat"); |
| 4810 | synchronized (mGlobalLock) { |
| 4811 | return mCompatModePackages.getPackageAskCompatModeLocked(packageName); |
| 4812 | } |
| 4813 | } |
| 4814 | |
| 4815 | @Override |
| 4816 | public void setPackageAskScreenCompat(String packageName, boolean ask) { |
| 4817 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4818 | "setPackageAskScreenCompat"); |
| 4819 | synchronized (mGlobalLock) { |
| 4820 | mCompatModePackages.setPackageAskCompatModeLocked(packageName, ask); |
| 4821 | } |
| 4822 | } |
| 4823 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 4824 | public static String relaunchReasonToString(int relaunchReason) { |
| 4825 | switch (relaunchReason) { |
| 4826 | case RELAUNCH_REASON_WINDOWING_MODE_RESIZE: |
| 4827 | return "window_resize"; |
| 4828 | case RELAUNCH_REASON_FREE_RESIZE: |
| 4829 | return "free_resize"; |
| 4830 | default: |
| 4831 | return null; |
| 4832 | } |
| 4833 | } |
| 4834 | |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4835 | ActivityStack getTopDisplayFocusedStack() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4836 | return mRootWindowContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4837 | } |
| 4838 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4839 | /** Pokes the task persister. */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4840 | void notifyTaskPersisterLocked(Task task, boolean flush) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4841 | mRecentTasks.notifyTaskPersisterLocked(task, flush); |
| 4842 | } |
| 4843 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4844 | boolean isKeyguardLocked() { |
| 4845 | return mKeyguardController.isKeyguardLocked(); |
| 4846 | } |
| 4847 | |
Garfield Tan | 0154863 | 2018-11-27 10:15:48 -0800 | [diff] [blame] | 4848 | /** |
| 4849 | * Clears launch params for the given package. |
| 4850 | * @param packageNames the names of the packages of which the launch params are to be cleared |
| 4851 | */ |
| 4852 | @Override |
| 4853 | public void clearLaunchParamsForPackages(List<String> packageNames) { |
| 4854 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4855 | "clearLaunchParamsForPackages"); |
| 4856 | synchronized (mGlobalLock) { |
| 4857 | for (int i = 0; i < packageNames.size(); ++i) { |
| 4858 | mStackSupervisor.mLaunchParamsPersister.removeRecordForPackage(packageNames.get(i)); |
| 4859 | } |
| 4860 | } |
| 4861 | } |
| 4862 | |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 4863 | /** |
| 4864 | * Makes the display with the given id a single task instance display. I.e the display can only |
| 4865 | * contain one task. |
| 4866 | */ |
| 4867 | @Override |
| 4868 | public void setDisplayToSingleTaskInstance(int displayId) { |
| 4869 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4870 | "setDisplayToSingleTaskInstance"); |
| 4871 | final long origId = Binder.clearCallingIdentity(); |
| 4872 | try { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 4873 | final DisplayContent display = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4874 | mRootWindowContainer.getDisplayContentOrCreate(displayId); |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 4875 | if (display != null) { |
| 4876 | display.setDisplayToSingleTaskInstance(); |
| 4877 | } |
| 4878 | } finally { |
| 4879 | Binder.restoreCallingIdentity(origId); |
| 4880 | } |
| 4881 | } |
| 4882 | |
jorgegil@google.com | 06bc323 | 2019-10-31 14:51:22 -0700 | [diff] [blame] | 4883 | /** |
| 4884 | * Requests that an activity should enter picture-in-picture mode if possible. |
| 4885 | */ |
| 4886 | @Override |
| 4887 | public void requestPictureInPictureMode(IBinder token) throws RemoteException { |
| 4888 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4889 | "requestPictureInPictureMode"); |
| 4890 | final long origId = Binder.clearCallingIdentity(); |
| 4891 | try { |
| 4892 | synchronized (mGlobalLock) { |
| 4893 | final ActivityRecord activity = ActivityRecord.forTokenLocked(token); |
| 4894 | if (activity == null) { |
| 4895 | return; |
| 4896 | } |
| 4897 | |
| 4898 | final boolean canEnterPictureInPicture = activity.checkEnterPictureInPictureState( |
| 4899 | "requestPictureInPictureMode", /* beforeStopping */ false); |
| 4900 | if (!canEnterPictureInPicture) { |
| 4901 | throw new IllegalStateException( |
| 4902 | "Requested PIP on an activity that doesn't support it"); |
| 4903 | } |
| 4904 | |
| 4905 | try { |
| 4906 | final ClientTransaction transaction = ClientTransaction.obtain( |
| 4907 | activity.app.getThread(), |
| 4908 | activity.token); |
| 4909 | transaction.addCallback(EnterPipRequestedItem.obtain()); |
| 4910 | getLifecycleManager().scheduleTransaction(transaction); |
| 4911 | } catch (Exception e) { |
| 4912 | Slog.w(TAG, "Failed to send enter pip requested item: " |
| 4913 | + activity.intent.getComponent(), e); |
| 4914 | } |
| 4915 | } |
| 4916 | } finally { |
| 4917 | Binder.restoreCallingIdentity(origId); |
| 4918 | } |
| 4919 | } |
| 4920 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4921 | void dumpLastANRLocked(PrintWriter pw) { |
| 4922 | pw.println("ACTIVITY MANAGER LAST ANR (dumpsys activity lastanr)"); |
| 4923 | if (mLastANRState == null) { |
| 4924 | pw.println(" <no ANR has occurred since boot>"); |
| 4925 | } else { |
| 4926 | pw.println(mLastANRState); |
| 4927 | } |
| 4928 | } |
| 4929 | |
| 4930 | void dumpLastANRTracesLocked(PrintWriter pw) { |
| 4931 | pw.println("ACTIVITY MANAGER LAST ANR TRACES (dumpsys activity lastanr-traces)"); |
| 4932 | |
| 4933 | final File[] files = new File(ANR_TRACE_DIR).listFiles(); |
| 4934 | if (ArrayUtils.isEmpty(files)) { |
| 4935 | pw.println(" <no ANR has occurred since boot>"); |
| 4936 | return; |
| 4937 | } |
| 4938 | // Find the latest file. |
| 4939 | File latest = null; |
| 4940 | for (File f : files) { |
| 4941 | if ((latest == null) || (latest.lastModified() < f.lastModified())) { |
| 4942 | latest = f; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4943 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4944 | } |
| 4945 | pw.print("File: "); |
| 4946 | pw.print(latest.getName()); |
| 4947 | pw.println(); |
| 4948 | try (BufferedReader in = new BufferedReader(new FileReader(latest))) { |
| 4949 | String line; |
| 4950 | while ((line = in.readLine()) != null) { |
| 4951 | pw.println(line); |
| 4952 | } |
| 4953 | } catch (IOException e) { |
| 4954 | pw.print("Unable to read: "); |
| 4955 | pw.print(e); |
| 4956 | pw.println(); |
| 4957 | } |
| 4958 | } |
| 4959 | |
| 4960 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4961 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 4962 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage, |
| 4963 | "ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)"); |
| 4964 | } |
| 4965 | |
| 4966 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4967 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage, String header) { |
| 4968 | pw.println(header); |
| 4969 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4970 | boolean printedAnything = mRootWindowContainer.dumpActivities(fd, pw, dumpAll, dumpClient, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4971 | dumpPackage); |
| 4972 | boolean needSep = printedAnything; |
| 4973 | |
| 4974 | boolean printed = ActivityStackSupervisor.printThisActivity(pw, |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4975 | mRootWindowContainer.getTopResumedActivity(), dumpPackage, needSep, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4976 | " ResumedActivity: "); |
| 4977 | if (printed) { |
| 4978 | printedAnything = true; |
| 4979 | needSep = false; |
| 4980 | } |
| 4981 | |
| 4982 | if (dumpPackage == null) { |
| 4983 | if (needSep) { |
| 4984 | pw.println(); |
| 4985 | } |
| 4986 | printedAnything = true; |
| 4987 | mStackSupervisor.dump(pw, " "); |
| 4988 | } |
| 4989 | |
| 4990 | if (!printedAnything) { |
| 4991 | pw.println(" (nothing)"); |
| 4992 | } |
| 4993 | } |
| 4994 | |
| 4995 | void dumpActivityContainersLocked(PrintWriter pw) { |
Jeff Chang | de32273 | 2019-07-12 12:16:23 +0800 | [diff] [blame] | 4996 | pw.println("ACTIVITY MANAGER CONTAINERS (dumpsys activity containers)"); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 4997 | mRootWindowContainer.dumpChildrenNames(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4998 | pw.println(" "); |
| 4999 | } |
| 5000 | |
| 5001 | void dumpActivityStarterLocked(PrintWriter pw, String dumpPackage) { |
| 5002 | pw.println("ACTIVITY MANAGER STARTER (dumpsys activity starter)"); |
| 5003 | getActivityStartController().dump(pw, "", dumpPackage); |
| 5004 | } |
| 5005 | |
| 5006 | /** |
| 5007 | * There are three things that cmd can be: |
| 5008 | * - a flattened component name that matches an existing activity |
| 5009 | * - the cmd arg isn't the flattened component name of an existing activity: |
| 5010 | * dump all activity whose component contains the cmd as a substring |
| 5011 | * - A hex number of the ActivityRecord object instance. |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5012 | * <p> |
| 5013 | * The caller should not hold lock when calling this method because it will wait for the |
| 5014 | * activities to complete the dump. |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5015 | * |
| 5016 | * @param dumpVisibleStacksOnly dump activity with {@param name} only if in a visible stack |
| 5017 | * @param dumpFocusedStackOnly dump activity with {@param name} only if in the focused stack |
| 5018 | */ |
| 5019 | protected boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, String[] args, |
| 5020 | int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, boolean dumpFocusedStackOnly) { |
| 5021 | ArrayList<ActivityRecord> activities; |
| 5022 | |
| 5023 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5024 | activities = mRootWindowContainer.getDumpActivities(name, dumpVisibleStacksOnly, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5025 | dumpFocusedStackOnly); |
| 5026 | } |
| 5027 | |
| 5028 | if (activities.size() <= 0) { |
| 5029 | return false; |
| 5030 | } |
| 5031 | |
| 5032 | String[] newArgs = new String[args.length - opti]; |
| 5033 | System.arraycopy(args, opti, newArgs, 0, args.length - opti); |
| 5034 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5035 | Task lastTask = null; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5036 | boolean needSep = false; |
| 5037 | for (int i = activities.size() - 1; i >= 0; i--) { |
| 5038 | ActivityRecord r = activities.get(i); |
| 5039 | if (needSep) { |
| 5040 | pw.println(); |
| 5041 | } |
| 5042 | needSep = true; |
| 5043 | synchronized (mGlobalLock) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5044 | final Task task = r.getTask(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5045 | if (lastTask != task) { |
| 5046 | lastTask = task; |
| 5047 | pw.print("TASK "); pw.print(lastTask.affinity); |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 5048 | pw.print(" id="); pw.print(lastTask.mTaskId); |
| 5049 | pw.print(" userId="); pw.println(lastTask.mUserId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5050 | if (dumpAll) { |
| 5051 | lastTask.dump(pw, " "); |
| 5052 | } |
| 5053 | } |
| 5054 | } |
| 5055 | dumpActivity(" ", fd, pw, activities.get(i), newArgs, dumpAll); |
| 5056 | } |
| 5057 | return true; |
| 5058 | } |
| 5059 | |
| 5060 | /** |
| 5061 | * Invokes IApplicationThread.dumpActivity() on the thread of the specified activity if |
| 5062 | * there is a thread associated with the activity. |
| 5063 | */ |
| 5064 | private void dumpActivity(String prefix, FileDescriptor fd, PrintWriter pw, |
| 5065 | final ActivityRecord r, String[] args, boolean dumpAll) { |
| 5066 | String innerPrefix = prefix + " "; |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5067 | IApplicationThread appThread = null; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5068 | synchronized (mGlobalLock) { |
| 5069 | pw.print(prefix); pw.print("ACTIVITY "); pw.print(r.shortComponentName); |
| 5070 | pw.print(" "); pw.print(Integer.toHexString(System.identityHashCode(r))); |
| 5071 | pw.print(" pid="); |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5072 | if (r.hasProcess()) { |
| 5073 | pw.println(r.app.getPid()); |
| 5074 | appThread = r.app.getThread(); |
| 5075 | } else { |
| 5076 | pw.println("(not running)"); |
| 5077 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5078 | if (dumpAll) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5079 | r.dump(pw, innerPrefix, true /* dumpAll */); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5080 | } |
| 5081 | } |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5082 | if (appThread != null) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5083 | // flush anything that is already in the PrintWriter since the thread is going |
| 5084 | // to write to the file descriptor directly |
| 5085 | pw.flush(); |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5086 | try (TransferPipe tp = new TransferPipe()) { |
| 5087 | appThread.dumpActivity(tp.getWriteFd(), r.appToken, innerPrefix, args); |
| 5088 | tp.go(fd); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5089 | } catch (IOException e) { |
| 5090 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 5091 | } catch (RemoteException e) { |
| 5092 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 5093 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5094 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5095 | } |
| 5096 | |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 5097 | private void writeSleepStateToProto(ProtoOutputStream proto, int wakeFullness, |
| 5098 | boolean testPssMode) { |
| 5099 | final long sleepToken = proto.start(ActivityManagerServiceDumpProcessesProto.SLEEP_STATUS); |
| 5100 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.WAKEFULNESS, |
| 5101 | PowerManagerInternal.wakefulnessToProtoEnum(wakeFullness)); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5102 | for (ActivityTaskManagerInternal.SleepToken st : mRootWindowContainer.mSleepTokens) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5103 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEP_TOKENS, |
| 5104 | st.toString()); |
| 5105 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5106 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEPING, mSleeping); |
| 5107 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SHUTTING_DOWN, |
| 5108 | mShuttingDown); |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 5109 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.TEST_PSS_MODE, |
| 5110 | testPssMode); |
| 5111 | proto.end(sleepToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5112 | } |
| 5113 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5114 | int getCurrentUserId() { |
| 5115 | return mAmInternal.getCurrentUserId(); |
| 5116 | } |
| 5117 | |
| 5118 | private void enforceNotIsolatedCaller(String caller) { |
| 5119 | if (UserHandle.isIsolated(Binder.getCallingUid())) { |
| 5120 | throw new SecurityException("Isolated process not allowed to call " + caller); |
| 5121 | } |
| 5122 | } |
| 5123 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5124 | public Configuration getConfiguration() { |
| 5125 | Configuration ci; |
| 5126 | synchronized(mGlobalLock) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 5127 | ci = new Configuration(getGlobalConfigurationForCallingPid()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5128 | ci.userSetLocale = false; |
| 5129 | } |
| 5130 | return ci; |
| 5131 | } |
| 5132 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5133 | /** |
| 5134 | * Current global configuration information. Contains general settings for the entire system, |
| 5135 | * also corresponds to the merged configuration of the default display. |
| 5136 | */ |
| 5137 | Configuration getGlobalConfiguration() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5138 | // Return default configuration before mRootWindowContainer initialized, which happens |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 5139 | // while initializing process record for system, see {@link |
| 5140 | // ActivityManagerService#setSystemProcess}. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5141 | return mRootWindowContainer != null ? mRootWindowContainer.getConfiguration() |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 5142 | : new Configuration(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5143 | } |
| 5144 | |
| 5145 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5146 | boolean initLocale) { |
| 5147 | return updateConfigurationLocked(values, starting, initLocale, false /* deferResume */); |
| 5148 | } |
| 5149 | |
| 5150 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5151 | boolean initLocale, boolean deferResume) { |
| 5152 | // pass UserHandle.USER_NULL as userId because we don't persist configuration for any user |
| 5153 | return updateConfigurationLocked(values, starting, initLocale, false /* persistent */, |
| 5154 | UserHandle.USER_NULL, deferResume); |
| 5155 | } |
| 5156 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 5157 | public void updatePersistentConfiguration(Configuration values, @UserIdInt int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5158 | final long origId = Binder.clearCallingIdentity(); |
| 5159 | try { |
| 5160 | synchronized (mGlobalLock) { |
| 5161 | updateConfigurationLocked(values, null, false, true, userId, |
| 5162 | false /* deferResume */); |
| 5163 | } |
| 5164 | } finally { |
| 5165 | Binder.restoreCallingIdentity(origId); |
| 5166 | } |
| 5167 | } |
| 5168 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5169 | private boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5170 | boolean initLocale, boolean persistent, int userId, boolean deferResume) { |
| 5171 | return updateConfigurationLocked(values, starting, initLocale, persistent, userId, |
| 5172 | deferResume, null /* result */); |
| 5173 | } |
| 5174 | |
| 5175 | /** |
| 5176 | * Do either or both things: (1) change the current configuration, and (2) |
| 5177 | * make sure the given activity is running with the (now) current |
| 5178 | * configuration. Returns true if the activity has been left running, or |
| 5179 | * false if <var>starting</var> is being destroyed to match the new |
| 5180 | * configuration. |
| 5181 | * |
| 5182 | * @param userId is only used when persistent parameter is set to true to persist configuration |
| 5183 | * for that particular user |
| 5184 | */ |
| 5185 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5186 | boolean initLocale, boolean persistent, int userId, boolean deferResume, |
| 5187 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 5188 | int changes = 0; |
| 5189 | boolean kept = true; |
| 5190 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5191 | deferWindowLayout(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5192 | try { |
| 5193 | if (values != null) { |
| 5194 | changes = updateGlobalConfigurationLocked(values, initLocale, persistent, userId, |
| 5195 | deferResume); |
| 5196 | } |
| 5197 | |
| 5198 | kept = ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 5199 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5200 | continueWindowLayout(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5201 | } |
| 5202 | |
| 5203 | if (result != null) { |
| 5204 | result.changes = changes; |
| 5205 | result.activityRelaunched = !kept; |
| 5206 | } |
| 5207 | return kept; |
| 5208 | } |
| 5209 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5210 | /** Update default (global) configuration and notify listeners about changes. */ |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5211 | int updateGlobalConfigurationLocked(@NonNull Configuration values, boolean initLocale, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5212 | boolean persistent, int userId, boolean deferResume) { |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5213 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5214 | final DisplayContent defaultDisplay = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5215 | mRootWindowContainer.getDisplayContent(DEFAULT_DISPLAY); |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5216 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5217 | mTempConfig.setTo(getGlobalConfiguration()); |
| 5218 | final int changes = mTempConfig.updateFrom(values); |
| 5219 | if (changes == 0) { |
| 5220 | // Since calling to Activity.setRequestedOrientation leads to freezing the window with |
| 5221 | // setting WindowManagerService.mWaitingForConfig to true, it is important that we call |
| 5222 | // performDisplayOverrideConfigUpdate in order to send the new display configuration |
| 5223 | // (even if there are no actual changes) to unfreeze the window. |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5224 | defaultDisplay.performDisplayOverrideConfigUpdate(values, deferResume); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5225 | return 0; |
| 5226 | } |
| 5227 | |
| 5228 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.i(TAG_CONFIGURATION, |
| 5229 | "Updating global configuration to: " + values); |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5230 | writeConfigurationChanged(changes); |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 5231 | FrameworkStatsLog.write(FrameworkStatsLog.RESOURCE_CONFIGURATION_CHANGED, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5232 | values.colorMode, |
| 5233 | values.densityDpi, |
| 5234 | values.fontScale, |
| 5235 | values.hardKeyboardHidden, |
| 5236 | values.keyboard, |
| 5237 | values.keyboardHidden, |
| 5238 | values.mcc, |
| 5239 | values.mnc, |
| 5240 | values.navigation, |
| 5241 | values.navigationHidden, |
| 5242 | values.orientation, |
| 5243 | values.screenHeightDp, |
| 5244 | values.screenLayout, |
| 5245 | values.screenWidthDp, |
| 5246 | values.smallestScreenWidthDp, |
| 5247 | values.touchscreen, |
| 5248 | values.uiMode); |
| 5249 | |
| 5250 | |
| 5251 | if (!initLocale && !values.getLocales().isEmpty() && values.userSetLocale) { |
| 5252 | final LocaleList locales = values.getLocales(); |
| 5253 | int bestLocaleIndex = 0; |
| 5254 | if (locales.size() > 1) { |
| 5255 | if (mSupportedSystemLocales == null) { |
| 5256 | mSupportedSystemLocales = Resources.getSystem().getAssets().getLocales(); |
| 5257 | } |
| 5258 | bestLocaleIndex = Math.max(0, locales.getFirstMatchIndex(mSupportedSystemLocales)); |
| 5259 | } |
| 5260 | SystemProperties.set("persist.sys.locale", |
| 5261 | locales.get(bestLocaleIndex).toLanguageTag()); |
| 5262 | LocaleList.setDefault(locales, bestLocaleIndex); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5263 | |
| 5264 | final Message m = PooledLambda.obtainMessage( |
| 5265 | ActivityTaskManagerService::sendLocaleToMountDaemonMsg, this, |
| 5266 | locales.get(bestLocaleIndex)); |
| 5267 | mH.sendMessage(m); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5268 | } |
| 5269 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 5270 | mTempConfig.seq = increaseConfigurationSeqLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5271 | |
| 5272 | // Update stored global config and notify everyone about the change. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5273 | mRootWindowContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5274 | |
| 5275 | Slog.i(TAG, "Config changes=" + Integer.toHexString(changes) + " " + mTempConfig); |
| 5276 | // TODO(multi-display): Update UsageEvents#Event to include displayId. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5277 | mUsageStatsInternal.reportConfigurationChange(mTempConfig, mAmInternal.getCurrentUserId()); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5278 | |
| 5279 | // 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] | 5280 | updateShouldShowDialogsLocked(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5281 | |
| 5282 | AttributeCache ac = AttributeCache.instance(); |
| 5283 | if (ac != null) { |
| 5284 | ac.updateConfiguration(mTempConfig); |
| 5285 | } |
| 5286 | |
| 5287 | // Make sure all resources in our process are updated right now, so that anyone who is going |
| 5288 | // to retrieve resource values after we return will be sure to get the new ones. This is |
| 5289 | // especially important during boot, where the first config change needs to guarantee all |
| 5290 | // resources have that config before following boot code is executed. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5291 | mSystemThread.applyConfigurationToResources(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5292 | |
| 5293 | // We need another copy of global config because we're scheduling some calls instead of |
| 5294 | // running them in place. We need to be sure that object we send will be handled unchanged. |
| 5295 | final Configuration configCopy = new Configuration(mTempConfig); |
| 5296 | if (persistent && Settings.System.hasInterestingConfigurationChanges(changes)) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5297 | final Message msg = PooledLambda.obtainMessage( |
| 5298 | ActivityTaskManagerService::sendPutConfigurationForUserMsg, |
| 5299 | this, userId, configCopy); |
| 5300 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5301 | } |
| 5302 | |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 5303 | SparseArray<WindowProcessController> pidMap = mProcessMap.getPidMap(); |
| 5304 | for (int i = pidMap.size() - 1; i >= 0; i--) { |
| 5305 | final int pid = pidMap.keyAt(i); |
| 5306 | final WindowProcessController app = pidMap.get(pid); |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 5307 | if (DEBUG_CONFIGURATION) { |
| 5308 | Slog.v(TAG_CONFIGURATION, "Update process config of " |
| 5309 | + app.mName + " to new config " + configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5310 | } |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 5311 | app.onConfigurationChanged(configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5312 | } |
| 5313 | |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 5314 | final Message msg = PooledLambda.obtainMessage( |
| 5315 | ActivityManagerInternal::broadcastGlobalConfigurationChanged, |
| 5316 | mAmInternal, changes, initLocale); |
| 5317 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5318 | |
| 5319 | // Override configuration of the default display duplicates global config, so we need to |
| 5320 | // update it also. This will also notify WindowManager about changes. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5321 | defaultDisplay.performDisplayOverrideConfigUpdate(mRootWindowContainer.getConfiguration(), |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5322 | deferResume); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5323 | |
| 5324 | return changes; |
| 5325 | } |
| 5326 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5327 | /** @see WindowSurfacePlacer#deferLayout */ |
| 5328 | void deferWindowLayout() { |
| 5329 | if (!mWindowManager.mWindowPlacerLocked.isLayoutDeferred()) { |
| 5330 | // Reset the reasons at the first entrance because we only care about the changes in the |
| 5331 | // deferred scope. |
| 5332 | mLayoutReasons = 0; |
| 5333 | } |
| 5334 | |
| 5335 | mWindowManager.mWindowPlacerLocked.deferLayout(); |
| 5336 | } |
| 5337 | |
| 5338 | /** @see WindowSurfacePlacer#continueLayout */ |
| 5339 | void continueWindowLayout() { |
| 5340 | mWindowManager.mWindowPlacerLocked.continueLayout(mLayoutReasons != 0); |
| 5341 | if (DEBUG_ALL && !mWindowManager.mWindowPlacerLocked.isLayoutDeferred()) { |
| 5342 | Slog.i(TAG, "continueWindowLayout reason=" + mLayoutReasons); |
| 5343 | } |
| 5344 | } |
| 5345 | |
| 5346 | /** |
| 5347 | * If a reason is added between {@link #deferWindowLayout} and {@link #continueWindowLayout}, |
| 5348 | * it will make sure {@link WindowSurfacePlacer#performSurfacePlacement} is called when the last |
| 5349 | * defer count is gone. |
| 5350 | */ |
| 5351 | void addWindowLayoutReasons(@LayoutReason int reasons) { |
| 5352 | mLayoutReasons |= reasons; |
| 5353 | } |
| 5354 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5355 | private void updateEventDispatchingLocked(boolean booted) { |
| 5356 | mWindowManager.setEventDispatching(booted && !mShuttingDown); |
| 5357 | } |
| 5358 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5359 | private void sendPutConfigurationForUserMsg(int userId, Configuration config) { |
| 5360 | final ContentResolver resolver = mContext.getContentResolver(); |
| 5361 | Settings.System.putConfigurationForUser(resolver, config, userId); |
| 5362 | } |
| 5363 | |
| 5364 | private void sendLocaleToMountDaemonMsg(Locale l) { |
| 5365 | try { |
| 5366 | IBinder service = ServiceManager.getService("mount"); |
| 5367 | IStorageManager storageManager = IStorageManager.Stub.asInterface(service); |
| 5368 | Log.d(TAG, "Storing locale " + l.toLanguageTag() + " for decryption UI"); |
| 5369 | storageManager.setField(StorageManager.SYSTEM_LOCALE_KEY, l.toLanguageTag()); |
| 5370 | } catch (RemoteException e) { |
| 5371 | Log.e(TAG, "Error storing locale for decryption UI", e); |
| 5372 | } |
| 5373 | } |
| 5374 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5375 | private void expireStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5376 | mStartActivitySources.remove(permissionToken); |
| 5377 | mExpiredStartAsCallerTokens.add(permissionToken); |
| 5378 | } |
| 5379 | |
| 5380 | private void forgetStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5381 | mExpiredStartAsCallerTokens.remove(permissionToken); |
| 5382 | } |
| 5383 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5384 | boolean isActivityStartsLoggingEnabled() { |
| 5385 | return mAmInternal.isActivityStartsLoggingEnabled(); |
| 5386 | } |
| 5387 | |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 5388 | boolean isBackgroundActivityStartsEnabled() { |
| 5389 | return mAmInternal.isBackgroundActivityStartsEnabled(); |
| 5390 | } |
| 5391 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5392 | void enableScreenAfterBoot(boolean booted) { |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5393 | writeBootProgressEnableScreen(SystemClock.uptimeMillis()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5394 | mWindowManager.enableScreenAfterBoot(); |
| 5395 | |
| 5396 | synchronized (mGlobalLock) { |
| 5397 | updateEventDispatchingLocked(booted); |
| 5398 | } |
| 5399 | } |
| 5400 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5401 | static long getInputDispatchingTimeoutLocked(ActivityRecord r) { |
| 5402 | if (r == null || !r.hasProcess()) { |
| 5403 | return KEY_DISPATCHING_TIMEOUT_MS; |
| 5404 | } |
| 5405 | return getInputDispatchingTimeoutLocked(r.app); |
| 5406 | } |
| 5407 | |
| 5408 | private static long getInputDispatchingTimeoutLocked(WindowProcessController r) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 5409 | return r != null ? r.getInputDispatchingTimeout() : KEY_DISPATCHING_TIMEOUT_MS; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5410 | } |
| 5411 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5412 | /** |
| 5413 | * Decide based on the configuration whether we should show the ANR, |
| 5414 | * crash, etc dialogs. The idea is that if there is no affordance to |
| 5415 | * press the on-screen buttons, or the user experience would be more |
| 5416 | * greatly impacted than the crash itself, we shouldn't show the dialog. |
| 5417 | * |
| 5418 | * A thought: SystemUI might also want to get told about this, the Power |
| 5419 | * dialog / global actions also might want different behaviors. |
| 5420 | */ |
| 5421 | private void updateShouldShowDialogsLocked(Configuration config) { |
| 5422 | final boolean inputMethodExists = !(config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 5423 | && config.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH |
| 5424 | && config.navigation == Configuration.NAVIGATION_NONAV); |
| 5425 | int modeType = config.uiMode & Configuration.UI_MODE_TYPE_MASK; |
| 5426 | final boolean uiModeSupportsDialogs = (modeType != Configuration.UI_MODE_TYPE_CAR |
| 5427 | && !(modeType == Configuration.UI_MODE_TYPE_WATCH && Build.IS_USER) |
| 5428 | && modeType != Configuration.UI_MODE_TYPE_TELEVISION |
| 5429 | && modeType != Configuration.UI_MODE_TYPE_VR_HEADSET); |
| 5430 | final boolean hideDialogsSet = Settings.Global.getInt(mContext.getContentResolver(), |
| 5431 | HIDE_ERROR_DIALOGS, 0) != 0; |
| 5432 | mShowDialogs = inputMethodExists && uiModeSupportsDialogs && !hideDialogsSet; |
| 5433 | } |
| 5434 | |
| 5435 | private void updateFontScaleIfNeeded(@UserIdInt int userId) { |
| 5436 | final float scaleFactor = Settings.System.getFloatForUser(mContext.getContentResolver(), |
| 5437 | FONT_SCALE, 1.0f, userId); |
| 5438 | |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 5439 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5440 | if (getGlobalConfiguration().fontScale == scaleFactor) { |
| 5441 | return; |
| 5442 | } |
| 5443 | |
| 5444 | final Configuration configuration |
| 5445 | = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
| 5446 | configuration.fontScale = scaleFactor; |
| 5447 | updatePersistentConfiguration(configuration, userId); |
| 5448 | } |
| 5449 | } |
| 5450 | |
| 5451 | // Actually is sleeping or shutting down or whatever else in the future |
| 5452 | // is an inactive state. |
| 5453 | boolean isSleepingOrShuttingDownLocked() { |
| 5454 | return isSleepingLocked() || mShuttingDown; |
| 5455 | } |
| 5456 | |
| 5457 | boolean isSleepingLocked() { |
| 5458 | return mSleeping; |
| 5459 | } |
| 5460 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5461 | /** Update AMS states when an activity is resumed. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5462 | void setResumedActivityUncheckLocked(ActivityRecord r, String reason) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5463 | final Task task = r.getTask(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5464 | if (task.isActivityTypeStandard()) { |
| 5465 | if (mCurAppTimeTracker != r.appTimeTracker) { |
| 5466 | // We are switching app tracking. Complete the current one. |
| 5467 | if (mCurAppTimeTracker != null) { |
| 5468 | mCurAppTimeTracker.stop(); |
| 5469 | mH.obtainMessage( |
| 5470 | REPORT_TIME_TRACKER_MSG, mCurAppTimeTracker).sendToTarget(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5471 | mRootWindowContainer.clearOtherAppTimeTrackers(r.appTimeTracker); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5472 | mCurAppTimeTracker = null; |
| 5473 | } |
| 5474 | if (r.appTimeTracker != null) { |
| 5475 | mCurAppTimeTracker = r.appTimeTracker; |
| 5476 | startTimeTrackingFocusedActivityLocked(); |
| 5477 | } |
| 5478 | } else { |
| 5479 | startTimeTrackingFocusedActivityLocked(); |
| 5480 | } |
| 5481 | } else { |
| 5482 | r.appTimeTracker = null; |
| 5483 | } |
| 5484 | // TODO: VI Maybe r.task.voiceInteractor || r.voiceInteractor != null |
| 5485 | // TODO: Probably not, because we don't want to resume voice on switching |
| 5486 | // back to this activity |
| 5487 | if (task.voiceInteractor != null) { |
| 5488 | startRunningVoiceLocked(task.voiceSession, r.info.applicationInfo.uid); |
| 5489 | } else { |
| 5490 | finishRunningVoiceLocked(); |
| 5491 | |
| 5492 | if (mLastResumedActivity != null) { |
| 5493 | final IVoiceInteractionSession session; |
| 5494 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5495 | final Task lastResumedActivityTask = mLastResumedActivity.getTask(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5496 | if (lastResumedActivityTask != null |
| 5497 | && lastResumedActivityTask.voiceSession != null) { |
| 5498 | session = lastResumedActivityTask.voiceSession; |
| 5499 | } else { |
| 5500 | session = mLastResumedActivity.voiceSession; |
| 5501 | } |
| 5502 | |
| 5503 | if (session != null) { |
| 5504 | // We had been in a voice interaction session, but now focused has |
| 5505 | // move to something different. Just finish the session, we can't |
| 5506 | // return to it and retain the proper state and synchronization with |
| 5507 | // the voice interaction service. |
| 5508 | finishVoiceTask(session); |
| 5509 | } |
| 5510 | } |
| 5511 | } |
| 5512 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5513 | if (mLastResumedActivity != null && r.mUserId != mLastResumedActivity.mUserId) { |
| 5514 | mAmInternal.sendForegroundProfileChanged(r.mUserId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5515 | } |
Bogyun Son | bfb64dc | 2019-12-09 17:50:24 +0900 | [diff] [blame] | 5516 | final Task prevTask = mLastResumedActivity != null ? mLastResumedActivity.getTask() : null; |
| 5517 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5518 | updateResumedAppTrace(r); |
| 5519 | mLastResumedActivity = r; |
| 5520 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 5521 | r.getDisplay().setFocusedApp(r, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5522 | |
Bogyun Son | bfb64dc | 2019-12-09 17:50:24 +0900 | [diff] [blame] | 5523 | if (prevTask == null || task != prevTask) { |
| 5524 | if (prevTask != null) { |
| 5525 | mTaskChangeNotificationController.notifyTaskFocusChanged(prevTask.mTaskId, false); |
| 5526 | } |
| 5527 | mTaskChangeNotificationController.notifyTaskFocusChanged(task.mTaskId, true); |
| 5528 | } |
| 5529 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5530 | applyUpdateLockStateLocked(r); |
| 5531 | applyUpdateVrModeLocked(r); |
| 5532 | |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5533 | EventLogTags.writeWmSetResumedActivity( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5534 | r == null ? -1 : r.mUserId, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5535 | r == null ? "NULL" : r.shortComponentName, |
| 5536 | reason); |
| 5537 | } |
| 5538 | |
| 5539 | ActivityTaskManagerInternal.SleepToken acquireSleepToken(String tag, int displayId) { |
| 5540 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5541 | final ActivityTaskManagerInternal.SleepToken token = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5542 | mRootWindowContainer.createSleepToken(tag, displayId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5543 | updateSleepIfNeededLocked(); |
| 5544 | return token; |
| 5545 | } |
| 5546 | } |
| 5547 | |
| 5548 | void updateSleepIfNeededLocked() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5549 | final boolean shouldSleep = !mRootWindowContainer.hasAwakeDisplay(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5550 | final boolean wasSleeping = mSleeping; |
| 5551 | boolean updateOomAdj = false; |
| 5552 | |
| 5553 | if (!shouldSleep) { |
| 5554 | // If wasSleeping is true, we need to wake up activity manager state from when |
| 5555 | // we started sleeping. In either case, we need to apply the sleep tokens, which |
| 5556 | // will wake up stacks or put them to sleep as appropriate. |
| 5557 | if (wasSleeping) { |
| 5558 | mSleeping = false; |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 5559 | FrameworkStatsLog.write(FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5560 | FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__AWAKE); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5561 | startTimeTrackingFocusedActivityLocked(); |
| 5562 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
Varun Shah | 98694fb | 2019-04-11 09:28:27 -0700 | [diff] [blame] | 5563 | Slog.d(TAG, "Top Process State changed to PROCESS_STATE_TOP"); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5564 | mStackSupervisor.comeOutOfSleepIfNeededLocked(); |
| 5565 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5566 | mRootWindowContainer.applySleepTokens(true /* applyToStacks */); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5567 | if (wasSleeping) { |
| 5568 | updateOomAdj = true; |
| 5569 | } |
| 5570 | } else if (!mSleeping && shouldSleep) { |
| 5571 | mSleeping = true; |
Muhammad Qureshi | 759f92f | 2020-01-28 10:41:55 -0800 | [diff] [blame] | 5572 | FrameworkStatsLog.write(FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5573 | FrameworkStatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__ASLEEP); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5574 | if (mCurAppTimeTracker != null) { |
| 5575 | mCurAppTimeTracker.stop(); |
| 5576 | } |
| 5577 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP_SLEEPING; |
Varun Shah | 98694fb | 2019-04-11 09:28:27 -0700 | [diff] [blame] | 5578 | Slog.d(TAG, "Top Process State changed to PROCESS_STATE_TOP_SLEEPING"); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5579 | mStackSupervisor.goingToSleepLocked(); |
| 5580 | updateResumedAppTrace(null /* resumed */); |
| 5581 | updateOomAdj = true; |
| 5582 | } |
| 5583 | if (updateOomAdj) { |
wilsonshih | 8d096d2 | 2019-08-01 17:46:14 +0800 | [diff] [blame] | 5584 | updateOomAdj(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5585 | } |
| 5586 | } |
| 5587 | |
| 5588 | void updateOomAdj() { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 5589 | mH.removeCallbacks(mUpdateOomAdjRunnable); |
| 5590 | mH.post(mUpdateOomAdjRunnable); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5591 | } |
| 5592 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5593 | void updateCpuStats() { |
| 5594 | mH.post(mAmInternal::updateCpuStats); |
| 5595 | } |
| 5596 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5597 | void updateBatteryStats(ActivityRecord component, boolean resumed) { |
| 5598 | final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::updateBatteryStats, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5599 | mAmInternal, component.mActivityComponent, component.app.mUid, component.mUserId, |
| 5600 | resumed); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5601 | mH.sendMessage(m); |
| 5602 | } |
| 5603 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5604 | void updateActivityUsageStats(ActivityRecord activity, int event) { |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5605 | ComponentName taskRoot = null; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5606 | final Task task = activity.getTask(); |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5607 | if (task != null) { |
| 5608 | final ActivityRecord rootActivity = task.getRootActivity(); |
| 5609 | if (rootActivity != null) { |
| 5610 | taskRoot = rootActivity.mActivityComponent; |
| 5611 | } |
| 5612 | } |
| 5613 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5614 | final Message m = PooledLambda.obtainMessage( |
| 5615 | ActivityManagerInternal::updateActivityUsageStats, mAmInternal, |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5616 | activity.mActivityComponent, activity.mUserId, event, activity.appToken, taskRoot); |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5617 | mH.sendMessage(m); |
| 5618 | } |
| 5619 | |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5620 | void startProcessAsync(ActivityRecord activity, boolean knownToBeDead, boolean isTop, |
| 5621 | String hostingType) { |
| 5622 | try { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5623 | if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) { |
| 5624 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "dispatchingStartProcess:" |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5625 | + activity.processName); |
| 5626 | } |
| 5627 | // Post message to start process to avoid possible deadlock of calling into AMS with the |
| 5628 | // ATMS lock held. |
| 5629 | final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::startProcess, |
| 5630 | mAmInternal, activity.processName, activity.info.applicationInfo, knownToBeDead, |
| 5631 | isTop, hostingType, activity.intent.getComponent()); |
| 5632 | mH.sendMessage(m); |
| 5633 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5634 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5635 | } |
| 5636 | } |
| 5637 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5638 | void setBooting(boolean booting) { |
| 5639 | mAmInternal.setBooting(booting); |
| 5640 | } |
| 5641 | |
| 5642 | boolean isBooting() { |
| 5643 | return mAmInternal.isBooting(); |
| 5644 | } |
| 5645 | |
| 5646 | void setBooted(boolean booted) { |
| 5647 | mAmInternal.setBooted(booted); |
| 5648 | } |
| 5649 | |
| 5650 | boolean isBooted() { |
| 5651 | return mAmInternal.isBooted(); |
| 5652 | } |
| 5653 | |
| 5654 | void postFinishBooting(boolean finishBooting, boolean enableScreen) { |
| 5655 | mH.post(() -> { |
| 5656 | if (finishBooting) { |
| 5657 | mAmInternal.finishBooting(); |
| 5658 | } |
| 5659 | if (enableScreen) { |
| 5660 | mInternal.enableScreenAfterBoot(isBooted()); |
| 5661 | } |
| 5662 | }); |
| 5663 | } |
| 5664 | |
| 5665 | void setHeavyWeightProcess(ActivityRecord root) { |
| 5666 | mHeavyWeightProcess = root.app; |
| 5667 | final Message m = PooledLambda.obtainMessage( |
| 5668 | ActivityTaskManagerService::postHeavyWeightProcessNotification, this, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5669 | root.app, root.intent, root.mUserId); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5670 | mH.sendMessage(m); |
| 5671 | } |
| 5672 | |
| 5673 | void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
| 5674 | if (mHeavyWeightProcess == null || mHeavyWeightProcess != proc) { |
| 5675 | return; |
| 5676 | } |
| 5677 | |
| 5678 | mHeavyWeightProcess = null; |
| 5679 | final Message m = PooledLambda.obtainMessage( |
| 5680 | ActivityTaskManagerService::cancelHeavyWeightProcessNotification, this, |
| 5681 | proc.mUserId); |
| 5682 | mH.sendMessage(m); |
| 5683 | } |
| 5684 | |
| 5685 | private void cancelHeavyWeightProcessNotification(int userId) { |
| 5686 | final INotificationManager inm = NotificationManager.getService(); |
| 5687 | if (inm == null) { |
| 5688 | return; |
| 5689 | } |
| 5690 | try { |
Julia Reynolds | e4a47dd | 2019-06-07 13:40:59 -0400 | [diff] [blame] | 5691 | inm.cancelNotificationWithTag("android", "android", null, |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5692 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, userId); |
| 5693 | } catch (RuntimeException e) { |
| 5694 | Slog.w(TAG, "Error canceling notification for service", e); |
| 5695 | } catch (RemoteException e) { |
| 5696 | } |
| 5697 | |
| 5698 | } |
| 5699 | |
| 5700 | private void postHeavyWeightProcessNotification( |
| 5701 | WindowProcessController proc, Intent intent, int userId) { |
| 5702 | if (proc == null) { |
| 5703 | return; |
| 5704 | } |
| 5705 | |
| 5706 | final INotificationManager inm = NotificationManager.getService(); |
| 5707 | if (inm == null) { |
| 5708 | return; |
| 5709 | } |
| 5710 | |
| 5711 | try { |
| 5712 | Context context = mContext.createPackageContext(proc.mInfo.packageName, 0); |
| 5713 | String text = mContext.getString(R.string.heavy_weight_notification, |
| 5714 | context.getApplicationInfo().loadLabel(context.getPackageManager())); |
| 5715 | Notification notification = |
| 5716 | new Notification.Builder(context, |
| 5717 | SystemNotificationChannels.HEAVY_WEIGHT_APP) |
| 5718 | .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) |
| 5719 | .setWhen(0) |
| 5720 | .setOngoing(true) |
| 5721 | .setTicker(text) |
| 5722 | .setColor(mContext.getColor( |
| 5723 | com.android.internal.R.color.system_notification_accent_color)) |
| 5724 | .setContentTitle(text) |
| 5725 | .setContentText( |
| 5726 | mContext.getText(R.string.heavy_weight_notification_detail)) |
| 5727 | .setContentIntent(PendingIntent.getActivityAsUser(mContext, 0, |
| 5728 | intent, PendingIntent.FLAG_CANCEL_CURRENT, null, |
| 5729 | new UserHandle(userId))) |
| 5730 | .build(); |
| 5731 | try { |
| 5732 | inm.enqueueNotificationWithTag("android", "android", null, |
| 5733 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, notification, userId); |
| 5734 | } catch (RuntimeException e) { |
| 5735 | Slog.w(TAG, "Error showing notification for heavy-weight app", e); |
| 5736 | } catch (RemoteException e) { |
| 5737 | } |
| 5738 | } catch (PackageManager.NameNotFoundException e) { |
| 5739 | Slog.w(TAG, "Unable to create context for heavy notification", e); |
| 5740 | } |
| 5741 | |
| 5742 | } |
| 5743 | |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 5744 | IIntentSender getIntentSenderLocked(int type, String packageName, String featureId, |
| 5745 | int callingUid, int userId, IBinder token, String resultWho, int requestCode, |
| 5746 | Intent[] intents, String[] resolvedTypes, int flags, Bundle bOptions) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5747 | |
| 5748 | ActivityRecord activity = null; |
| 5749 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5750 | activity = ActivityRecord.isInStackLocked(token); |
| 5751 | if (activity == null) { |
| 5752 | Slog.w(TAG, "Failed createPendingResult: activity " + token + " not in any stack"); |
| 5753 | return null; |
| 5754 | } |
| 5755 | if (activity.finishing) { |
| 5756 | Slog.w(TAG, "Failed createPendingResult: activity " + activity + " is finishing"); |
| 5757 | return null; |
| 5758 | } |
| 5759 | } |
| 5760 | |
| 5761 | final PendingIntentRecord rec = mPendingIntentController.getIntentSender(type, packageName, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 5762 | featureId, callingUid, userId, token, resultWho, requestCode, intents, |
| 5763 | resolvedTypes, flags, bOptions); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5764 | final boolean noCreate = (flags & PendingIntent.FLAG_NO_CREATE) != 0; |
| 5765 | if (noCreate) { |
| 5766 | return rec; |
| 5767 | } |
| 5768 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5769 | if (activity.pendingResults == null) { |
| 5770 | activity.pendingResults = new HashSet<>(); |
| 5771 | } |
| 5772 | activity.pendingResults.add(rec.ref); |
| 5773 | } |
| 5774 | return rec; |
| 5775 | } |
| 5776 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 5777 | // 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] | 5778 | private void startTimeTrackingFocusedActivityLocked() { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5779 | final ActivityRecord resumedActivity = mRootWindowContainer.getTopResumedActivity(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5780 | if (!mSleeping && mCurAppTimeTracker != null && resumedActivity != null) { |
| 5781 | mCurAppTimeTracker.start(resumedActivity.packageName); |
| 5782 | } |
| 5783 | } |
| 5784 | |
| 5785 | private void updateResumedAppTrace(@Nullable ActivityRecord resumed) { |
| 5786 | if (mTracedResumedActivity != null) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5787 | Trace.asyncTraceEnd(TRACE_TAG_WINDOW_MANAGER, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5788 | constructResumedTraceName(mTracedResumedActivity.packageName), 0); |
| 5789 | } |
| 5790 | if (resumed != null) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5791 | Trace.asyncTraceBegin(TRACE_TAG_WINDOW_MANAGER, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5792 | constructResumedTraceName(resumed.packageName), 0); |
| 5793 | } |
| 5794 | mTracedResumedActivity = resumed; |
| 5795 | } |
| 5796 | |
| 5797 | private String constructResumedTraceName(String packageName) { |
| 5798 | return "focused app: " + packageName; |
| 5799 | } |
| 5800 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5801 | /** Applies latest configuration and/or visibility updates if needed. */ |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5802 | boolean ensureConfigAndVisibilityAfterUpdate(ActivityRecord starting, int changes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5803 | boolean kept = true; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5804 | final ActivityStack mainStack = mRootWindowContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5805 | // mainStack is null during startup. |
| 5806 | if (mainStack != null) { |
| 5807 | if (changes != 0 && starting == null) { |
| 5808 | // If the configuration changed, and the caller is not already |
| 5809 | // in the process of starting an activity, then find the top |
| 5810 | // activity to check if its configuration needs to change. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 5811 | starting = mainStack.topRunningActivity(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5812 | } |
| 5813 | |
| 5814 | if (starting != null) { |
| 5815 | kept = starting.ensureActivityConfiguration(changes, |
| 5816 | false /* preserveWindow */); |
| 5817 | // And we need to make sure at this point that all other activities |
| 5818 | // are made visible with the correct configuration. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 5819 | mRootWindowContainer.ensureActivitiesVisible(starting, changes, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5820 | !PRESERVE_WINDOWS); |
| 5821 | } |
| 5822 | } |
| 5823 | |
| 5824 | return kept; |
| 5825 | } |
| 5826 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5827 | void scheduleAppGcsLocked() { |
| 5828 | mH.post(() -> mAmInternal.scheduleAppGcs()); |
| 5829 | } |
| 5830 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5831 | CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) { |
| 5832 | return mCompatModePackages.compatibilityInfoForPackageLocked(ai); |
| 5833 | } |
| 5834 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5835 | /** |
| 5836 | * Returns the PackageManager. Used by classes hosted by {@link ActivityTaskManagerService}. The |
| 5837 | * PackageManager could be unavailable at construction time and therefore needs to be accessed |
| 5838 | * on demand. |
| 5839 | */ |
| 5840 | IPackageManager getPackageManager() { |
| 5841 | return AppGlobals.getPackageManager(); |
| 5842 | } |
| 5843 | |
| 5844 | PackageManagerInternal getPackageManagerInternalLocked() { |
| 5845 | if (mPmInternal == null) { |
| 5846 | mPmInternal = LocalServices.getService(PackageManagerInternal.class); |
| 5847 | } |
| 5848 | return mPmInternal; |
| 5849 | } |
| 5850 | |
Darryl L Johnson | a098222 | 2020-02-18 18:21:51 -0800 | [diff] [blame] | 5851 | ComponentName getSysUiServiceComponentLocked() { |
| 5852 | if (mSysUiServiceComponent == null) { |
| 5853 | final PackageManagerInternal pm = getPackageManagerInternalLocked(); |
| 5854 | mSysUiServiceComponent = pm.getSystemUiServiceComponent(); |
| 5855 | } |
| 5856 | return mSysUiServiceComponent; |
| 5857 | } |
| 5858 | |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 5859 | PermissionPolicyInternal getPermissionPolicyInternal() { |
| 5860 | if (mPermissionPolicyInternal == null) { |
| 5861 | mPermissionPolicyInternal = LocalServices.getService(PermissionPolicyInternal.class); |
| 5862 | } |
| 5863 | return mPermissionPolicyInternal; |
| 5864 | } |
| 5865 | |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 5866 | AppWarnings getAppWarningsLocked() { |
| 5867 | return mAppWarnings; |
| 5868 | } |
| 5869 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5870 | Intent getHomeIntent() { |
| 5871 | Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null); |
| 5872 | intent.setComponent(mTopComponent); |
| 5873 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5874 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5875 | intent.addCategory(Intent.CATEGORY_HOME); |
| 5876 | } |
| 5877 | return intent; |
| 5878 | } |
| 5879 | |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5880 | /** |
| 5881 | * Return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} to resolve secondary home |
| 5882 | * activities. |
| 5883 | * |
Chilun | 939b05c | 2020-02-19 14:50:59 +0800 | [diff] [blame] | 5884 | * @param preferredPackage Specify a preferred package name, otherwise use the package name |
| 5885 | * defined in config_secondaryHomePackage. |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5886 | * @return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} |
| 5887 | */ |
| 5888 | Intent getSecondaryHomeIntent(String preferredPackage) { |
| 5889 | 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] | 5890 | final boolean useSystemProvidedLauncher = mContext.getResources().getBoolean( |
| 5891 | com.android.internal.R.bool.config_useSystemProvidedLauncherForSecondary); |
| 5892 | if (preferredPackage == null || useSystemProvidedLauncher) { |
Chilun | 939b05c | 2020-02-19 14:50:59 +0800 | [diff] [blame] | 5893 | // Using the package name stored in config if no preferred package name or forced. |
| 5894 | final String secondaryHomePackage = mContext.getResources().getString( |
| 5895 | com.android.internal.R.string.config_secondaryHomePackage); |
| 5896 | intent.setPackage(secondaryHomePackage); |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5897 | } else { |
| 5898 | intent.setPackage(preferredPackage); |
| 5899 | } |
| 5900 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5901 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5902 | intent.addCategory(Intent.CATEGORY_SECONDARY_HOME); |
| 5903 | } |
| 5904 | return intent; |
| 5905 | } |
| 5906 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5907 | ApplicationInfo getAppInfoForUser(ApplicationInfo info, int userId) { |
| 5908 | if (info == null) return null; |
| 5909 | ApplicationInfo newInfo = new ApplicationInfo(info); |
| 5910 | newInfo.initForUser(userId); |
| 5911 | return newInfo; |
| 5912 | } |
| 5913 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 5914 | WindowProcessController getProcessController(String processName, int uid) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5915 | if (uid == SYSTEM_UID) { |
| 5916 | // The system gets to run in any process. If there are multiple processes with the same |
| 5917 | // uid, just pick the first (this should never happen). |
| 5918 | final SparseArray<WindowProcessController> procs = |
| 5919 | mProcessNames.getMap().get(processName); |
| 5920 | if (procs == null) return null; |
| 5921 | final int procCount = procs.size(); |
| 5922 | for (int i = 0; i < procCount; i++) { |
| 5923 | final int procUid = procs.keyAt(i); |
| 5924 | if (UserHandle.isApp(procUid) || !UserHandle.isSameUser(procUid, uid)) { |
| 5925 | // Don't use an app process or different user process for system component. |
| 5926 | continue; |
| 5927 | } |
| 5928 | return procs.valueAt(i); |
| 5929 | } |
| 5930 | } |
| 5931 | |
| 5932 | return mProcessNames.get(processName, uid); |
| 5933 | } |
| 5934 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5935 | WindowProcessController getProcessController(IApplicationThread thread) { |
| 5936 | if (thread == null) { |
| 5937 | return null; |
| 5938 | } |
| 5939 | |
| 5940 | final IBinder threadBinder = thread.asBinder(); |
| 5941 | final ArrayMap<String, SparseArray<WindowProcessController>> pmap = mProcessNames.getMap(); |
| 5942 | for (int i = pmap.size()-1; i >= 0; i--) { |
| 5943 | final SparseArray<WindowProcessController> procs = pmap.valueAt(i); |
| 5944 | for (int j = procs.size() - 1; j >= 0; j--) { |
| 5945 | final WindowProcessController proc = procs.valueAt(j); |
| 5946 | if (proc.hasThread() && proc.getThread().asBinder() == threadBinder) { |
| 5947 | return proc; |
| 5948 | } |
| 5949 | } |
| 5950 | } |
| 5951 | |
| 5952 | return null; |
| 5953 | } |
| 5954 | |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 5955 | WindowProcessController getProcessController(int pid, int uid) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 5956 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Yunfan Chen | 8546b21 | 2019-04-01 15:34:44 +0900 | [diff] [blame] | 5957 | if (proc == null) return null; |
| 5958 | if (UserHandle.isApp(uid) && proc.mUid == uid) { |
| 5959 | return proc; |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 5960 | } |
| 5961 | return null; |
| 5962 | } |
| 5963 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 5964 | int getUidState(int uid) { |
| 5965 | return mActiveUids.getUidState(uid); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 5966 | } |
| 5967 | |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 5968 | boolean isUidForeground(int uid) { |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 5969 | // A uid is considered to be foreground if it has a visible non-toast window. |
| 5970 | return mWindowManager.mRoot.isAnyNonToastWindowVisibleForUid(uid); |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 5971 | } |
| 5972 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 5973 | boolean isDeviceOwner(int uid) { |
| 5974 | return uid >= 0 && mDeviceOwnerUid == uid; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 5975 | } |
| 5976 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 5977 | void setDeviceOwnerUid(int uid) { |
| 5978 | mDeviceOwnerUid = uid; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 5979 | } |
| 5980 | |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 5981 | /** |
| 5982 | * @return whitelist tag for a uid from mPendingTempWhitelist, null if not currently on |
| 5983 | * the whitelist |
| 5984 | */ |
| 5985 | String getPendingTempWhitelistTagForUidLocked(int uid) { |
| 5986 | return mPendingTempWhitelist.get(uid); |
| 5987 | } |
| 5988 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5989 | void logAppTooSlow(WindowProcessController app, long startTime, String msg) { |
| 5990 | if (true || Build.IS_USER) { |
| 5991 | return; |
| 5992 | } |
| 5993 | |
| 5994 | StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 5995 | StrictMode.allowThreadDiskWrites(); |
| 5996 | try { |
| 5997 | File tracesDir = new File("/data/anr"); |
| 5998 | File tracesFile = null; |
| 5999 | try { |
| 6000 | tracesFile = File.createTempFile("app_slow", null, tracesDir); |
| 6001 | |
| 6002 | StringBuilder sb = new StringBuilder(); |
Neil Fuller | 9774681 | 2019-08-19 14:20:50 +0100 | [diff] [blame] | 6003 | String timeString = |
| 6004 | TimeMigrationUtils.formatMillisWithFixedFormat(System.currentTimeMillis()); |
| 6005 | sb.append(timeString); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6006 | sb.append(": "); |
| 6007 | TimeUtils.formatDuration(SystemClock.uptimeMillis()-startTime, sb); |
| 6008 | sb.append(" since "); |
| 6009 | sb.append(msg); |
| 6010 | FileOutputStream fos = new FileOutputStream(tracesFile); |
| 6011 | fos.write(sb.toString().getBytes()); |
| 6012 | if (app == null) { |
| 6013 | fos.write("\n*** No application process!".getBytes()); |
| 6014 | } |
| 6015 | fos.close(); |
| 6016 | FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1); // -rw-rw-rw- |
| 6017 | } catch (IOException e) { |
| 6018 | Slog.w(TAG, "Unable to prepare slow app traces file: " + tracesFile, e); |
| 6019 | return; |
| 6020 | } |
| 6021 | |
| 6022 | if (app != null && app.getPid() > 0) { |
| 6023 | ArrayList<Integer> firstPids = new ArrayList<Integer>(); |
| 6024 | firstPids.add(app.getPid()); |
| 6025 | dumpStackTraces(tracesFile.getAbsolutePath(), firstPids, null, null); |
| 6026 | } |
| 6027 | |
| 6028 | File lastTracesFile = null; |
| 6029 | File curTracesFile = null; |
| 6030 | for (int i=9; i>=0; i--) { |
| 6031 | String name = String.format(Locale.US, "slow%02d.txt", i); |
| 6032 | curTracesFile = new File(tracesDir, name); |
| 6033 | if (curTracesFile.exists()) { |
| 6034 | if (lastTracesFile != null) { |
| 6035 | curTracesFile.renameTo(lastTracesFile); |
| 6036 | } else { |
| 6037 | curTracesFile.delete(); |
| 6038 | } |
| 6039 | } |
| 6040 | lastTracesFile = curTracesFile; |
| 6041 | } |
| 6042 | tracesFile.renameTo(curTracesFile); |
| 6043 | } finally { |
| 6044 | StrictMode.setThreadPolicy(oldPolicy); |
| 6045 | } |
| 6046 | } |
| 6047 | |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 6048 | boolean isAssociatedCompanionApp(int userId, int uid) { |
| 6049 | final Set<Integer> allUids = mCompanionAppUidsMap.get(userId); |
| 6050 | if (allUids == null) { |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 6051 | return false; |
| 6052 | } |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 6053 | return allUids.contains(uid); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 6054 | } |
| 6055 | |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 6056 | void notifySingleTaskDisplayEmpty(int displayId) { |
| 6057 | mTaskChangeNotificationController.notifySingleTaskDisplayEmpty(displayId); |
| 6058 | } |
| 6059 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6060 | final class H extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6061 | static final int REPORT_TIME_TRACKER_MSG = 1; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 6062 | |
| 6063 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 6064 | static final int FIRST_ACTIVITY_STACK_MSG = 100; |
| 6065 | static final int FIRST_SUPERVISOR_STACK_MSG = 200; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6066 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 6067 | H(Looper looper) { |
| 6068 | super(looper); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6069 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6070 | |
| 6071 | @Override |
| 6072 | public void handleMessage(Message msg) { |
| 6073 | switch (msg.what) { |
| 6074 | case REPORT_TIME_TRACKER_MSG: { |
| 6075 | AppTimeTracker tracker = (AppTimeTracker) msg.obj; |
| 6076 | tracker.deliverResult(mContext); |
| 6077 | } break; |
| 6078 | } |
| 6079 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6080 | } |
| 6081 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6082 | final class UiHandler extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6083 | static final int DISMISS_DIALOG_UI_MSG = 1; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6084 | |
| 6085 | public UiHandler() { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 6086 | super(UiThread.get().getLooper(), null, true); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6087 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6088 | |
| 6089 | @Override |
| 6090 | public void handleMessage(Message msg) { |
| 6091 | switch (msg.what) { |
| 6092 | case DISMISS_DIALOG_UI_MSG: { |
| 6093 | final Dialog d = (Dialog) msg.obj; |
| 6094 | d.dismiss(); |
| 6095 | break; |
| 6096 | } |
| 6097 | } |
| 6098 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6099 | } |
| 6100 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6101 | final class LocalService extends ActivityTaskManagerInternal { |
| 6102 | @Override |
| 6103 | public SleepToken acquireSleepToken(String tag, int displayId) { |
Daulet Zhanguzin | c6c641f | 2020-01-02 17:18:30 +0000 | [diff] [blame] | 6104 | Objects.requireNonNull(tag); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6105 | return ActivityTaskManagerService.this.acquireSleepToken(tag, displayId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6106 | } |
| 6107 | |
| 6108 | @Override |
| 6109 | public ComponentName getHomeActivityForUser(int userId) { |
| 6110 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6111 | final ActivityRecord homeActivity = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6112 | mRootWindowContainer.getDefaultDisplayHomeActivityForUser(userId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 6113 | return homeActivity == null ? null : homeActivity.mActivityComponent; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6114 | } |
| 6115 | } |
| 6116 | |
| 6117 | @Override |
| 6118 | public void onLocalVoiceInteractionStarted(IBinder activity, |
| 6119 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 6120 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6121 | onLocalVoiceInteractionStartedLocked(activity, voiceSession, voiceInteractor); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6122 | } |
| 6123 | } |
| 6124 | |
| 6125 | @Override |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 6126 | public void notifySingleTaskDisplayDrawn(int displayId) { |
| 6127 | mTaskChangeNotificationController.notifySingleTaskDisplayDrawn(displayId); |
| 6128 | } |
| 6129 | |
| 6130 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6131 | public void notifyAppTransitionFinished() { |
| 6132 | synchronized (mGlobalLock) { |
| 6133 | mStackSupervisor.notifyAppTransitionDone(); |
| 6134 | } |
| 6135 | } |
| 6136 | |
| 6137 | @Override |
| 6138 | public void notifyAppTransitionCancelled() { |
| 6139 | synchronized (mGlobalLock) { |
| 6140 | mStackSupervisor.notifyAppTransitionDone(); |
| 6141 | } |
| 6142 | } |
| 6143 | |
| 6144 | @Override |
| 6145 | public List<IBinder> getTopVisibleActivities() { |
| 6146 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6147 | return mRootWindowContainer.getTopVisibleActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6148 | } |
| 6149 | } |
| 6150 | |
| 6151 | @Override |
Bernardo Rufino | e6cb310 | 2020-03-06 20:33:11 +0000 | [diff] [blame] | 6152 | public boolean hasResumedActivity(int uid) { |
| 6153 | synchronized (mGlobalLock) { |
| 6154 | final ArraySet<WindowProcessController> processes = mProcessMap.getProcesses(uid); |
| 6155 | for (int i = 0, n = processes.size(); i < n; i++) { |
| 6156 | final WindowProcessController process = processes.valueAt(i); |
| 6157 | if (process.hasResumedActivity()) { |
| 6158 | return true; |
| 6159 | } |
| 6160 | } |
| 6161 | } |
| 6162 | return false; |
| 6163 | } |
| 6164 | |
| 6165 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6166 | public int startActivitiesAsPackage(String packageName, @Nullable String featureId, |
| 6167 | int userId, Intent[] intents, Bundle bOptions) { |
Daulet Zhanguzin | c6c641f | 2020-01-02 17:18:30 +0000 | [diff] [blame] | 6168 | Objects.requireNonNull(intents, "intents"); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6169 | final String[] resolvedTypes = new String[intents.length]; |
| 6170 | |
| 6171 | // UID of the package on user userId. |
| 6172 | // "= 0" is needed because otherwise catch(RemoteException) would make it look like |
| 6173 | // packageUid may not be initialized. |
| 6174 | int packageUid = 0; |
| 6175 | final long ident = Binder.clearCallingIdentity(); |
| 6176 | |
| 6177 | try { |
| 6178 | for (int i = 0; i < intents.length; i++) { |
| 6179 | resolvedTypes[i] = |
| 6180 | intents[i].resolveTypeIfNeeded(mContext.getContentResolver()); |
| 6181 | } |
| 6182 | |
| 6183 | packageUid = AppGlobals.getPackageManager().getPackageUid( |
| 6184 | packageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId); |
| 6185 | } catch (RemoteException e) { |
| 6186 | // Shouldn't happen. |
| 6187 | } finally { |
| 6188 | Binder.restoreCallingIdentity(ident); |
| 6189 | } |
| 6190 | |
Riddle Hsu | 591bf61 | 2019-02-14 17:55:31 +0800 | [diff] [blame] | 6191 | return getActivityStartController().startActivitiesInPackage( |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6192 | packageUid, packageName, featureId, |
Riddle Hsu | 591bf61 | 2019-02-14 17:55:31 +0800 | [diff] [blame] | 6193 | intents, resolvedTypes, null /* resultTo */, |
| 6194 | SafeActivityOptions.fromBundle(bOptions), userId, |
| 6195 | false /* validateIncomingUser */, null /* originatingPendingIntent */, |
| 6196 | false /* allowBackgroundActivityStart */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | @Override |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6200 | public int startActivitiesInPackage(int uid, int realCallingPid, int realCallingUid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6201 | String callingPackage, @Nullable String callingFeatureId, Intent[] intents, |
| 6202 | String[] resolvedTypes, IBinder resultTo, SafeActivityOptions options, int userId, |
| 6203 | boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6204 | boolean allowBackgroundActivityStart) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 6205 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6206 | synchronized (mGlobalLock) { |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6207 | return getActivityStartController().startActivitiesInPackage(uid, realCallingPid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6208 | realCallingUid, callingPackage, callingFeatureId, intents, resolvedTypes, |
| 6209 | resultTo, options, userId, validateIncomingUser, originatingPendingIntent, |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6210 | allowBackgroundActivityStart); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6211 | } |
| 6212 | } |
| 6213 | |
| 6214 | @Override |
| 6215 | public int startActivityInPackage(int uid, int realCallingPid, int realCallingUid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6216 | String callingPackage, @Nullable String callingFeatureId, Intent intent, |
| 6217 | String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 6218 | int startFlags, SafeActivityOptions options, int userId, Task inTask, String reason, |
| 6219 | boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6220 | boolean allowBackgroundActivityStart) { |
Andrii Kulian | f9e5c9f | 2019-07-16 11:24:45 -0700 | [diff] [blame] | 6221 | assertPackageMatchesCallingUid(callingPackage); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6222 | synchronized (mGlobalLock) { |
| 6223 | return getActivityStartController().startActivityInPackage(uid, realCallingPid, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6224 | realCallingUid, callingPackage, callingFeatureId, intent, resolvedType, |
| 6225 | resultTo, resultWho, requestCode, startFlags, options, userId, inTask, |
| 6226 | reason, validateIncomingUser, originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6227 | allowBackgroundActivityStart); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6228 | } |
| 6229 | } |
| 6230 | |
| 6231 | @Override |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6232 | public int startActivityAsUser(IApplicationThread caller, String callerPackage, |
Alex Kershaw | 16406c3 | 2020-02-17 12:28:53 +0000 | [diff] [blame] | 6233 | @Nullable String callerFeatureId, Intent intent, @Nullable IBinder resultTo, |
| 6234 | int startFlags, Bundle options, int userId) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6235 | return ActivityTaskManagerService.this.startActivityAsUser( |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6236 | caller, callerPackage, callerFeatureId, intent, |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6237 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Alex Kershaw | 16406c3 | 2020-02-17 12:28:53 +0000 | [diff] [blame] | 6238 | resultTo, null, 0, startFlags, null, options, userId, |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6239 | false /*validateIncomingUser*/); |
| 6240 | } |
| 6241 | |
| 6242 | @Override |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 6243 | public void notifyKeyguardFlagsChanged(@Nullable Runnable callback, int displayId) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6244 | synchronized (mGlobalLock) { |
| 6245 | |
| 6246 | // We might change the visibilities here, so prepare an empty app transition which |
| 6247 | // might be overridden later if we actually change visibilities. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6248 | final DisplayContent displayContent = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6249 | mRootWindowContainer.getDisplayContent(displayId); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6250 | if (displayContent == null) { |
lumark | 52ea28e | 2018-11-09 17:30:47 +0800 | [diff] [blame] | 6251 | return; |
| 6252 | } |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6253 | final DisplayContent dc = displayContent.mDisplayContent; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6254 | final boolean wasTransitionSet = |
| 6255 | dc.mAppTransition.getAppTransition() != TRANSIT_NONE; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6256 | if (!wasTransitionSet) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6257 | dc.prepareAppTransition(TRANSIT_NONE, false /* alwaysKeepCurrent */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6258 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6259 | mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6260 | |
| 6261 | // If there was a transition set already we don't want to interfere with it as we |
| 6262 | // might be starting it too early. |
| 6263 | if (!wasTransitionSet) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6264 | dc.executeAppTransition(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6265 | } |
| 6266 | } |
| 6267 | if (callback != null) { |
| 6268 | callback.run(); |
| 6269 | } |
| 6270 | } |
| 6271 | |
| 6272 | @Override |
| 6273 | public void notifyKeyguardTrustedChanged() { |
| 6274 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6275 | if (mKeyguardController.isKeyguardShowing(DEFAULT_DISPLAY)) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6276 | mRootWindowContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6277 | } |
| 6278 | } |
| 6279 | } |
| 6280 | |
| 6281 | /** |
| 6282 | * Called after virtual display Id is updated by |
| 6283 | * {@link com.android.server.vr.Vr2dDisplay} with a specific |
| 6284 | * {@param vrVr2dDisplayId}. |
| 6285 | */ |
| 6286 | @Override |
| 6287 | public void setVr2dDisplayId(int vr2dDisplayId) { |
| 6288 | if (DEBUG_STACK) Slog.d(TAG, "setVr2dDisplayId called for: " + vr2dDisplayId); |
| 6289 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6290 | mVr2dDisplayId = vr2dDisplayId; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6291 | } |
| 6292 | } |
| 6293 | |
| 6294 | @Override |
| 6295 | public void setFocusedActivity(IBinder token) { |
| 6296 | synchronized (mGlobalLock) { |
| 6297 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 6298 | if (r == null) { |
| 6299 | throw new IllegalArgumentException( |
| 6300 | "setFocusedActivity: No activity record matching token=" + token); |
| 6301 | } |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 6302 | if (r.moveFocusableActivityToTop("setFocusedActivity")) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6303 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6304 | } |
| 6305 | } |
| 6306 | } |
| 6307 | |
| 6308 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6309 | public void registerScreenObserver(ScreenObserver observer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6310 | mScreenObservers.add(observer); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6311 | } |
| 6312 | |
| 6313 | @Override |
| 6314 | public boolean isCallerRecents(int callingUid) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 6315 | return getRecentTasks().isCallerRecents(callingUid); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6316 | } |
| 6317 | |
| 6318 | @Override |
| 6319 | public boolean isRecentsComponentHomeActivity(int userId) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 6320 | return getRecentTasks().isRecentsComponentHomeActivity(userId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6321 | } |
| 6322 | |
| 6323 | @Override |
| 6324 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
| 6325 | ActivityTaskManagerService.this.cancelRecentsAnimation(restoreHomeStackPosition); |
| 6326 | } |
| 6327 | |
| 6328 | @Override |
| 6329 | public void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6330 | ActivityTaskManagerService.this.enforceCallerIsRecentsOrHasPermission(permission, func); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6331 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6332 | |
| 6333 | @Override |
| 6334 | public void notifyActiveVoiceInteractionServiceChanged(ComponentName component) { |
| 6335 | synchronized (mGlobalLock) { |
| 6336 | mActiveVoiceInteractionServiceComponent = component; |
| 6337 | } |
| 6338 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6339 | |
| 6340 | @Override |
Galia Peycheva | 480275a | 2020-03-18 17:33:42 +0100 | [diff] [blame^] | 6341 | public void notifyDreamStateChanged(boolean dreaming) { |
| 6342 | synchronized (mGlobalLock) { |
| 6343 | mDreaming = dreaming; |
| 6344 | } |
| 6345 | } |
| 6346 | |
| 6347 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6348 | public void setAllowAppSwitches(@NonNull String type, int uid, int userId) { |
| 6349 | if (!mAmInternal.isUserRunning(userId, ActivityManager.FLAG_OR_STOPPED)) { |
| 6350 | return; |
| 6351 | } |
| 6352 | synchronized (mGlobalLock) { |
| 6353 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(userId); |
| 6354 | if (types == null) { |
| 6355 | if (uid < 0) { |
| 6356 | return; |
| 6357 | } |
| 6358 | types = new ArrayMap<>(); |
| 6359 | mAllowAppSwitchUids.put(userId, types); |
| 6360 | } |
| 6361 | if (uid < 0) { |
| 6362 | types.remove(type); |
| 6363 | } else { |
| 6364 | types.put(type, uid); |
| 6365 | } |
| 6366 | } |
| 6367 | } |
| 6368 | |
| 6369 | @Override |
| 6370 | public void onUserStopped(int userId) { |
| 6371 | synchronized (mGlobalLock) { |
| 6372 | getRecentTasks().unloadUserDataFromMemoryLocked(userId); |
| 6373 | mAllowAppSwitchUids.remove(userId); |
| 6374 | } |
| 6375 | } |
| 6376 | |
| 6377 | @Override |
| 6378 | public boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 6379 | synchronized (mGlobalLock) { |
| 6380 | return ActivityTaskManagerService.this.isGetTasksAllowed( |
| 6381 | caller, callingPid, callingUid); |
| 6382 | } |
| 6383 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6384 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6385 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6386 | @Override |
| 6387 | public void onProcessAdded(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6388 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6389 | mProcessNames.put(proc.mName, proc.mUid, proc); |
| 6390 | } |
| 6391 | } |
| 6392 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6393 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6394 | @Override |
| 6395 | public void onProcessRemoved(String name, int uid) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6396 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6397 | mProcessNames.remove(name, uid); |
| 6398 | } |
| 6399 | } |
| 6400 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6401 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6402 | @Override |
| 6403 | public void onCleanUpApplicationRecord(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6404 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6405 | if (proc == mHomeProcess) { |
| 6406 | mHomeProcess = null; |
| 6407 | } |
| 6408 | if (proc == mPreviousProcess) { |
| 6409 | mPreviousProcess = null; |
| 6410 | } |
| 6411 | } |
| 6412 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6413 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6414 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6415 | @Override |
| 6416 | public int getTopProcessState() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6417 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6418 | return mTopProcessState; |
| 6419 | } |
| 6420 | } |
| 6421 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6422 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6423 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6424 | public boolean isHeavyWeightProcess(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6425 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6426 | return proc == mHeavyWeightProcess; |
| 6427 | } |
| 6428 | } |
| 6429 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6430 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6431 | @Override |
| 6432 | public void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6433 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6434 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals(proc); |
| 6435 | } |
| 6436 | } |
| 6437 | |
| 6438 | @Override |
| 6439 | public void finishHeavyWeightApp() { |
| 6440 | synchronized (mGlobalLock) { |
Sudheer Shanka | ee1da27 | 2018-10-20 20:11:44 -0700 | [diff] [blame] | 6441 | if (mHeavyWeightProcess != null) { |
| 6442 | mHeavyWeightProcess.finishActivities(); |
| 6443 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6444 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals( |
| 6445 | mHeavyWeightProcess); |
| 6446 | } |
| 6447 | } |
| 6448 | |
Galia Peycheva | 480275a | 2020-03-18 17:33:42 +0100 | [diff] [blame^] | 6449 | @Override |
| 6450 | public boolean isDreaming() { |
| 6451 | synchronized (mGlobalLock) { |
| 6452 | return mDreaming; |
| 6453 | } |
| 6454 | } |
| 6455 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6456 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6457 | @Override |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6458 | public boolean isSleeping() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6459 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6460 | return isSleepingLocked(); |
| 6461 | } |
| 6462 | } |
| 6463 | |
| 6464 | @Override |
| 6465 | public boolean isShuttingDown() { |
| 6466 | synchronized (mGlobalLock) { |
| 6467 | return mShuttingDown; |
| 6468 | } |
| 6469 | } |
| 6470 | |
| 6471 | @Override |
| 6472 | public boolean shuttingDown(boolean booted, int timeout) { |
| 6473 | synchronized (mGlobalLock) { |
| 6474 | mShuttingDown = true; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6475 | mRootWindowContainer.prepareForShutdown(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6476 | updateEventDispatchingLocked(booted); |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 6477 | notifyTaskPersisterLocked(null, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6478 | return mStackSupervisor.shutdownLocked(timeout); |
| 6479 | } |
| 6480 | } |
| 6481 | |
| 6482 | @Override |
| 6483 | public void enableScreenAfterBoot(boolean booted) { |
| 6484 | synchronized (mGlobalLock) { |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 6485 | writeBootProgressEnableScreen(SystemClock.uptimeMillis()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6486 | mWindowManager.enableScreenAfterBoot(); |
| 6487 | updateEventDispatchingLocked(booted); |
| 6488 | } |
| 6489 | } |
| 6490 | |
| 6491 | @Override |
| 6492 | public boolean showStrictModeViolationDialog() { |
| 6493 | synchronized (mGlobalLock) { |
| 6494 | return mShowDialogs && !mSleeping && !mShuttingDown; |
| 6495 | } |
| 6496 | } |
| 6497 | |
| 6498 | @Override |
| 6499 | public void showSystemReadyErrorDialogsIfNeeded() { |
| 6500 | synchronized (mGlobalLock) { |
| 6501 | try { |
| 6502 | if (AppGlobals.getPackageManager().hasSystemUidErrors()) { |
| 6503 | Slog.e(TAG, "UIDs on the system are inconsistent, you need to wipe your" |
| 6504 | + " data partition or your device will be unstable."); |
| 6505 | mUiHandler.post(() -> { |
| 6506 | if (mShowDialogs) { |
| 6507 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6508 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6509 | d.setCancelable(false); |
| 6510 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6511 | d.setMessage(mUiContext.getText(R.string.system_error_wipe_data)); |
| 6512 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6513 | mUiContext.getText(R.string.ok), |
| 6514 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6515 | d.show(); |
| 6516 | } |
| 6517 | }); |
| 6518 | } |
| 6519 | } catch (RemoteException e) { |
| 6520 | } |
| 6521 | |
| 6522 | if (!Build.isBuildConsistent()) { |
| 6523 | Slog.e(TAG, "Build fingerprint is not consistent, warning user"); |
| 6524 | mUiHandler.post(() -> { |
| 6525 | if (mShowDialogs) { |
| 6526 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6527 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6528 | d.setCancelable(false); |
| 6529 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6530 | d.setMessage(mUiContext.getText(R.string.system_error_manufacturer)); |
| 6531 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6532 | mUiContext.getText(R.string.ok), |
| 6533 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6534 | d.show(); |
| 6535 | } |
| 6536 | }); |
| 6537 | } |
| 6538 | } |
| 6539 | } |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6540 | |
| 6541 | @Override |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6542 | public void onProcessMapped(int pid, WindowProcessController proc) { |
| 6543 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6544 | mProcessMap.put(pid, proc); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6545 | } |
| 6546 | } |
| 6547 | |
| 6548 | @Override |
| 6549 | public void onProcessUnMapped(int pid) { |
| 6550 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6551 | mProcessMap.remove(pid); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6552 | } |
| 6553 | } |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6554 | |
| 6555 | @Override |
| 6556 | public void onPackageDataCleared(String name) { |
| 6557 | synchronized (mGlobalLock) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6558 | mCompatModePackages.handlePackageDataClearedLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6559 | mAppWarnings.onPackageDataCleared(name); |
| 6560 | } |
| 6561 | } |
| 6562 | |
| 6563 | @Override |
| 6564 | public void onPackageUninstalled(String name) { |
| 6565 | synchronized (mGlobalLock) { |
| 6566 | mAppWarnings.onPackageUninstalled(name); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6567 | mCompatModePackages.handlePackageUninstalledLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6568 | } |
| 6569 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6570 | |
| 6571 | @Override |
| 6572 | public void onPackageAdded(String name, boolean replacing) { |
| 6573 | synchronized (mGlobalLock) { |
| 6574 | mCompatModePackages.handlePackageAddedLocked(name, replacing); |
| 6575 | } |
| 6576 | } |
| 6577 | |
| 6578 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6579 | public void onPackageReplaced(ApplicationInfo aInfo) { |
| 6580 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6581 | mRootWindowContainer.updateActivityApplicationInfo(aInfo); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6582 | } |
| 6583 | } |
| 6584 | |
| 6585 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6586 | public CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai) { |
| 6587 | synchronized (mGlobalLock) { |
| 6588 | return compatibilityInfoForPackageLocked(ai); |
| 6589 | } |
| 6590 | } |
| 6591 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6592 | /** |
| 6593 | * Set the corresponding display information for the process global configuration. To be |
| 6594 | * called when we need to show IME on a different display. |
| 6595 | * |
| 6596 | * @param pid The process id associated with the IME window. |
| 6597 | * @param displayId The ID of the display showing the IME. |
| 6598 | */ |
| 6599 | @Override |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6600 | public void onImeWindowSetOnDisplay(final int pid, final int displayId) { |
lumark | 4897353 | 2019-04-12 20:18:15 +0800 | [diff] [blame] | 6601 | // Don't update process-level configuration for Multi-Client IME process since other |
| 6602 | // IMEs on other displays will also receive this configuration change due to IME |
| 6603 | // services use the same application config/context. |
| 6604 | if (InputMethodSystemProperty.MULTI_CLIENT_IME_ENABLED) return; |
lumark | 5df4951 | 2019-04-02 14:56:46 +0800 | [diff] [blame] | 6605 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6606 | if (pid == MY_PID || pid < 0) { |
| 6607 | if (DEBUG_CONFIGURATION) { |
| 6608 | Slog.w(TAG, |
| 6609 | "Trying to update display configuration for system/invalid process."); |
| 6610 | } |
| 6611 | return; |
| 6612 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6613 | synchronized (mGlobalLock) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6614 | final DisplayContent displayContent = |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6615 | mRootWindowContainer.getDisplayContent(displayId); |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6616 | if (displayContent == null) { |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6617 | // Call might come when display is not yet added or has been removed. |
| 6618 | if (DEBUG_CONFIGURATION) { |
| 6619 | Slog.w(TAG, "Trying to update display configuration for non-existing " |
| 6620 | + "displayId=" + displayId); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6621 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6622 | return; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6623 | } |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6624 | final WindowProcessController process = mProcessMap.getProcess(pid); |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6625 | if (process == null) { |
| 6626 | if (DEBUG_CONFIGURATION) { |
| 6627 | Slog.w(TAG, "Trying to update display configuration for invalid " |
| 6628 | + "process, pid=" + pid); |
| 6629 | } |
| 6630 | return; |
| 6631 | } |
lumark | ddc77fb | 2019-06-27 22:22:23 +0800 | [diff] [blame] | 6632 | process.mIsImeProcess = true; |
Andrii Kulian | fa23a9e | 2019-10-10 15:15:36 -0700 | [diff] [blame] | 6633 | process.registerDisplayConfigurationListener(displayContent); |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6634 | } |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6635 | } |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6636 | |
| 6637 | @Override |
| 6638 | public void sendActivityResult(int callingUid, IBinder activityToken, String resultWho, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 6639 | int requestCode, int resultCode, Intent data) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6640 | synchronized (mGlobalLock) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 6641 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
Wale Ogunwale | 1ebcd8e | 2020-01-21 11:27:03 -0800 | [diff] [blame] | 6642 | if (r != null && r.getRootTask() != null) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 6643 | r.sendResult(callingUid, resultWho, requestCode, resultCode, data); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6644 | } |
| 6645 | } |
| 6646 | } |
| 6647 | |
| 6648 | @Override |
| 6649 | public void clearPendingResultForActivity(IBinder activityToken, |
| 6650 | WeakReference<PendingIntentRecord> pir) { |
| 6651 | synchronized (mGlobalLock) { |
| 6652 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 6653 | if (r != null && r.pendingResults != null) { |
| 6654 | r.pendingResults.remove(pir); |
| 6655 | } |
| 6656 | } |
| 6657 | } |
| 6658 | |
| 6659 | @Override |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6660 | public ActivityTokens getTopActivityForTask(int taskId) { |
| 6661 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6662 | final Task task = mRootWindowContainer.anyTaskForId(taskId); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 6663 | if (task == null) { |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6664 | Slog.w(TAG, "getApplicationThreadForTopActivity failed:" |
| 6665 | + " Requested task not found"); |
| 6666 | return null; |
| 6667 | } |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 6668 | final ActivityRecord activity = task.getTopNonFinishingActivity(); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6669 | if (activity == null) { |
| 6670 | Slog.w(TAG, "getApplicationThreadForTopActivity failed:" |
| 6671 | + " Requested activity not found"); |
| 6672 | return null; |
| 6673 | } |
| 6674 | if (!activity.attachedToProcess()) { |
| 6675 | Slog.w(TAG, "getApplicationThreadForTopActivity failed: No process for " |
| 6676 | + activity); |
| 6677 | return null; |
| 6678 | } |
| 6679 | return new ActivityTokens(activity.appToken, activity.assistToken, |
| 6680 | activity.app.getThread()); |
| 6681 | } |
| 6682 | } |
| 6683 | |
| 6684 | @Override |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6685 | public IIntentSender getIntentSender(int type, String packageName, |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6686 | @Nullable String featureId, int callingUid, int userId, IBinder token, |
| 6687 | String resultWho, int requestCode, Intent[] intents, String[] resolvedTypes, |
| 6688 | int flags, Bundle bOptions) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6689 | synchronized (mGlobalLock) { |
Philip P. Moltmann | ee29509 | 2020-02-10 08:46:26 -0800 | [diff] [blame] | 6690 | return getIntentSenderLocked(type, packageName, featureId, callingUid, userId, |
| 6691 | token, resultWho, requestCode, intents, resolvedTypes, flags, bOptions); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6692 | } |
| 6693 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 6694 | |
| 6695 | @Override |
| 6696 | public ActivityServiceConnectionsHolder getServiceConnectionsHolder(IBinder token) { |
| 6697 | synchronized (mGlobalLock) { |
| 6698 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 6699 | if (r == null) { |
| 6700 | return null; |
| 6701 | } |
| 6702 | if (r.mServiceConnectionsHolder == null) { |
| 6703 | r.mServiceConnectionsHolder = new ActivityServiceConnectionsHolder( |
| 6704 | ActivityTaskManagerService.this, r); |
| 6705 | } |
| 6706 | |
| 6707 | return r.mServiceConnectionsHolder; |
| 6708 | } |
| 6709 | } |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6710 | |
| 6711 | @Override |
| 6712 | public Intent getHomeIntent() { |
| 6713 | synchronized (mGlobalLock) { |
| 6714 | return ActivityTaskManagerService.this.getHomeIntent(); |
| 6715 | } |
| 6716 | } |
| 6717 | |
| 6718 | @Override |
| 6719 | public boolean startHomeActivity(int userId, String reason) { |
| 6720 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6721 | return mRootWindowContainer.startHomeOnDisplay(userId, reason, DEFAULT_DISPLAY); |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6722 | } |
| 6723 | } |
| 6724 | |
| 6725 | @Override |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 6726 | public boolean startHomeOnDisplay(int userId, String reason, int displayId, |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 6727 | boolean allowInstrumenting, boolean fromHomeKey) { |
Chilun | 5fd5654 | 2019-03-21 19:51:37 +0800 | [diff] [blame] | 6728 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6729 | return mRootWindowContainer.startHomeOnDisplay(userId, reason, displayId, |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 6730 | allowInstrumenting, fromHomeKey); |
Chilun | 5fd5654 | 2019-03-21 19:51:37 +0800 | [diff] [blame] | 6731 | } |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 6732 | } |
| 6733 | |
| 6734 | @Override |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6735 | public boolean startHomeOnAllDisplays(int userId, String reason) { |
| 6736 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6737 | return mRootWindowContainer.startHomeOnAllDisplays(userId, reason); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6738 | } |
| 6739 | } |
| 6740 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6741 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6742 | @Override |
| 6743 | public boolean isFactoryTestProcess(WindowProcessController wpc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6744 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6745 | if (mFactoryTest == FACTORY_TEST_OFF) { |
| 6746 | return false; |
| 6747 | } |
| 6748 | if (mFactoryTest == FACTORY_TEST_LOW_LEVEL && mTopComponent != null |
| 6749 | && wpc.mName.equals(mTopComponent.getPackageName())) { |
| 6750 | return true; |
| 6751 | } |
| 6752 | return mFactoryTest == FACTORY_TEST_HIGH_LEVEL |
| 6753 | && (wpc.mInfo.flags & FLAG_FACTORY_TEST) != 0; |
| 6754 | } |
| 6755 | } |
| 6756 | |
| 6757 | @Override |
| 6758 | public void updateTopComponentForFactoryTest() { |
| 6759 | synchronized (mGlobalLock) { |
| 6760 | if (mFactoryTest != FACTORY_TEST_LOW_LEVEL) { |
| 6761 | return; |
| 6762 | } |
| 6763 | final ResolveInfo ri = mContext.getPackageManager() |
| 6764 | .resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST), STOCK_PM_FLAGS); |
| 6765 | final CharSequence errorMsg; |
| 6766 | if (ri != null) { |
| 6767 | final ActivityInfo ai = ri.activityInfo; |
| 6768 | final ApplicationInfo app = ai.applicationInfo; |
| 6769 | if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 6770 | mTopAction = Intent.ACTION_FACTORY_TEST; |
| 6771 | mTopData = null; |
| 6772 | mTopComponent = new ComponentName(app.packageName, ai.name); |
| 6773 | errorMsg = null; |
| 6774 | } else { |
| 6775 | errorMsg = mContext.getResources().getText( |
| 6776 | com.android.internal.R.string.factorytest_not_system); |
| 6777 | } |
| 6778 | } else { |
| 6779 | errorMsg = mContext.getResources().getText( |
| 6780 | com.android.internal.R.string.factorytest_no_action); |
| 6781 | } |
| 6782 | if (errorMsg == null) { |
| 6783 | return; |
| 6784 | } |
| 6785 | |
| 6786 | mTopAction = null; |
| 6787 | mTopData = null; |
| 6788 | mTopComponent = null; |
| 6789 | mUiHandler.post(() -> { |
| 6790 | Dialog d = new FactoryErrorDialog(mUiContext, errorMsg); |
| 6791 | d.show(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 6792 | mAmInternal.ensureBootCompleted(); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6793 | }); |
| 6794 | } |
| 6795 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6796 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6797 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6798 | @Override |
| 6799 | public void handleAppDied(WindowProcessController wpc, boolean restarting, |
| 6800 | Runnable finishInstrumentationCallback) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6801 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6802 | // Remove this application's activities from active lists. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6803 | boolean hasVisibleActivities = mRootWindowContainer.handleAppDied(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6804 | |
| 6805 | wpc.clearRecentTasks(); |
| 6806 | wpc.clearActivities(); |
| 6807 | |
| 6808 | if (wpc.isInstrumenting()) { |
| 6809 | finishInstrumentationCallback.run(); |
| 6810 | } |
| 6811 | |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6812 | if (!restarting && hasVisibleActivities) { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 6813 | deferWindowLayout(); |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6814 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6815 | if (!mRootWindowContainer.resumeFocusedStacksTopActivities()) { |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6816 | // If there was nothing to resume, and we are not already restarting |
| 6817 | // this process, but there is a visible activity that is hosted by the |
| 6818 | // process...then make sure all visible activities are running, taking |
| 6819 | // care of restarting this process. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6820 | mRootWindowContainer.ensureActivitiesVisible(null, 0, |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6821 | !PRESERVE_WINDOWS); |
| 6822 | } |
| 6823 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 6824 | continueWindowLayout(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6825 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6826 | } |
| 6827 | } |
| 6828 | } |
| 6829 | |
| 6830 | @Override |
| 6831 | public void closeSystemDialogs(String reason) { |
| 6832 | enforceNotIsolatedCaller("closeSystemDialogs"); |
| 6833 | |
| 6834 | final int pid = Binder.getCallingPid(); |
| 6835 | final int uid = Binder.getCallingUid(); |
| 6836 | final long origId = Binder.clearCallingIdentity(); |
| 6837 | try { |
| 6838 | synchronized (mGlobalLock) { |
| 6839 | // Only allow this from foreground processes, so that background |
| 6840 | // applications can't abuse it to prevent system UI from being shown. |
| 6841 | if (uid >= FIRST_APPLICATION_UID) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6842 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6843 | if (!proc.isPerceptible()) { |
| 6844 | Slog.w(TAG, "Ignoring closeSystemDialogs " + reason |
| 6845 | + " from background process " + proc); |
| 6846 | return; |
| 6847 | } |
| 6848 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6849 | mWindowManager.closeSystemDialogs(reason); |
| 6850 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6851 | mRootWindowContainer.closeSystemDialogs(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6852 | } |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 6853 | // Call into AM outside the synchronized block. |
| 6854 | mAmInternal.broadcastCloseSystemDialogs(reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6855 | } finally { |
| 6856 | Binder.restoreCallingIdentity(origId); |
| 6857 | } |
| 6858 | } |
| 6859 | |
| 6860 | @Override |
| 6861 | public void cleanupDisabledPackageComponents( |
| 6862 | String packageName, Set<String> disabledClasses, int userId, boolean booted) { |
| 6863 | synchronized (mGlobalLock) { |
| 6864 | // Clean-up disabled activities. |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6865 | if (mRootWindowContainer.finishDisabledPackageActivities( |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6866 | packageName, disabledClasses, true, false, userId) && booted) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6867 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 6868 | mStackSupervisor.scheduleIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6869 | } |
| 6870 | |
| 6871 | // Clean-up disabled tasks |
| 6872 | getRecentTasks().cleanupDisabledPackageTasksLocked( |
| 6873 | packageName, disabledClasses, userId); |
| 6874 | } |
| 6875 | } |
| 6876 | |
| 6877 | @Override |
| 6878 | public boolean onForceStopPackage(String packageName, boolean doit, boolean evenPersistent, |
| 6879 | int userId) { |
| 6880 | synchronized (mGlobalLock) { |
| 6881 | |
| 6882 | boolean didSomething = |
| 6883 | getActivityStartController().clearPendingActivityLaunches(packageName); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6884 | didSomething |= mRootWindowContainer.finishDisabledPackageActivities(packageName, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6885 | null, doit, evenPersistent, userId); |
| 6886 | return didSomething; |
| 6887 | } |
| 6888 | } |
| 6889 | |
| 6890 | @Override |
| 6891 | public void resumeTopActivities(boolean scheduleIdle) { |
| 6892 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6893 | mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6894 | if (scheduleIdle) { |
Riddle Hsu | fc8ab26 | 2019-12-31 15:31:24 +0800 | [diff] [blame] | 6895 | mStackSupervisor.scheduleIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6896 | } |
| 6897 | } |
| 6898 | } |
| 6899 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6900 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6901 | @Override |
| 6902 | public void preBindApplication(WindowProcessController wpc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6903 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6904 | mStackSupervisor.getActivityMetricsLogger().notifyBindApplication(wpc.mInfo); |
| 6905 | } |
| 6906 | } |
| 6907 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6908 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6909 | @Override |
| 6910 | public boolean attachApplication(WindowProcessController wpc) throws RemoteException { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6911 | synchronized (mGlobalLockWithoutBoost) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 6912 | if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) { |
| 6913 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "attachApplication:" + wpc.mName); |
| 6914 | } |
| 6915 | try { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6916 | return mRootWindowContainer.attachApplication(wpc); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 6917 | } finally { |
| 6918 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 6919 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6920 | } |
| 6921 | } |
| 6922 | |
| 6923 | @Override |
| 6924 | public void notifyLockedProfile(@UserIdInt int userId, int currentUserId) { |
| 6925 | try { |
| 6926 | if (!AppGlobals.getPackageManager().isUidPrivileged(Binder.getCallingUid())) { |
| 6927 | throw new SecurityException("Only privileged app can call notifyLockedProfile"); |
| 6928 | } |
| 6929 | } catch (RemoteException ex) { |
| 6930 | throw new SecurityException("Fail to check is caller a privileged app", ex); |
| 6931 | } |
| 6932 | |
| 6933 | synchronized (mGlobalLock) { |
| 6934 | final long ident = Binder.clearCallingIdentity(); |
| 6935 | try { |
| 6936 | if (mAmInternal.shouldConfirmCredentials(userId)) { |
| 6937 | if (mKeyguardController.isKeyguardLocked()) { |
| 6938 | // Showing launcher to avoid user entering credential twice. |
| 6939 | startHomeActivity(currentUserId, "notifyLockedProfile"); |
| 6940 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 6941 | mRootWindowContainer.lockAllProfileTasks(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6942 | } |
| 6943 | } finally { |
| 6944 | Binder.restoreCallingIdentity(ident); |
| 6945 | } |
| 6946 | } |
| 6947 | } |
| 6948 | |
| 6949 | @Override |
| 6950 | public void startConfirmDeviceCredentialIntent(Intent intent, Bundle options) { |
| 6951 | mAmInternal.enforceCallingPermission( |
| 6952 | MANAGE_ACTIVITY_STACKS, "startConfirmDeviceCredentialIntent"); |
| 6953 | |
| 6954 | synchronized (mGlobalLock) { |
| 6955 | final long ident = Binder.clearCallingIdentity(); |
| 6956 | try { |
Pavel Grafov | c0fe0a0 | 2019-05-13 18:19:33 +0100 | [diff] [blame] | 6957 | intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 6958 | final ActivityOptions activityOptions = options != null |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6959 | ? new ActivityOptions(options) : ActivityOptions.makeBasic(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6960 | mContext.startActivityAsUser(intent, activityOptions.toBundle(), |
| 6961 | UserHandle.CURRENT); |
| 6962 | } finally { |
| 6963 | Binder.restoreCallingIdentity(ident); |
| 6964 | } |
| 6965 | } |
| 6966 | } |
| 6967 | |
| 6968 | @Override |
| 6969 | public void writeActivitiesToProto(ProtoOutputStream proto) { |
| 6970 | synchronized (mGlobalLock) { |
| 6971 | // The output proto of "activity --proto activities" |
Wale Ogunwale | f342f06 | 2020-01-27 07:34:13 -0800 | [diff] [blame] | 6972 | mRootWindowContainer.dumpDebug( |
| 6973 | proto, ROOT_WINDOW_CONTAINER, WindowTraceLogLevel.ALL); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6974 | } |
| 6975 | } |
| 6976 | |
| 6977 | @Override |
| 6978 | public void saveANRState(String reason) { |
| 6979 | synchronized (mGlobalLock) { |
| 6980 | final StringWriter sw = new StringWriter(); |
| 6981 | final PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
| 6982 | pw.println(" ANR time: " + DateFormat.getDateTimeInstance().format(new Date())); |
| 6983 | if (reason != null) { |
| 6984 | pw.println(" Reason: " + reason); |
| 6985 | } |
| 6986 | pw.println(); |
| 6987 | getActivityStartController().dump(pw, " ", null); |
| 6988 | pw.println(); |
| 6989 | pw.println("-------------------------------------------------------------------------------"); |
| 6990 | dumpActivitiesLocked(null /* fd */, pw, null /* args */, 0 /* opti */, |
| 6991 | true /* dumpAll */, false /* dumpClient */, null /* dumpPackage */, |
| 6992 | "" /* header */); |
| 6993 | pw.println(); |
| 6994 | pw.close(); |
| 6995 | |
| 6996 | mLastANRState = sw.toString(); |
| 6997 | } |
| 6998 | } |
| 6999 | |
| 7000 | @Override |
| 7001 | public void clearSavedANRState() { |
| 7002 | synchronized (mGlobalLock) { |
| 7003 | mLastANRState = null; |
| 7004 | } |
| 7005 | } |
| 7006 | |
| 7007 | @Override |
| 7008 | public void dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args, int opti, |
| 7009 | boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 7010 | synchronized (mGlobalLock) { |
| 7011 | if (DUMP_ACTIVITIES_CMD.equals(cmd) || DUMP_ACTIVITIES_SHORT_CMD.equals(cmd)) { |
| 7012 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage); |
| 7013 | } else if (DUMP_LASTANR_CMD.equals(cmd)) { |
| 7014 | dumpLastANRLocked(pw); |
| 7015 | } else if (DUMP_LASTANR_TRACES_CMD.equals(cmd)) { |
| 7016 | dumpLastANRTracesLocked(pw); |
| 7017 | } else if (DUMP_STARTER_CMD.equals(cmd)) { |
| 7018 | dumpActivityStarterLocked(pw, dumpPackage); |
| 7019 | } else if (DUMP_CONTAINERS_CMD.equals(cmd)) { |
| 7020 | dumpActivityContainersLocked(pw); |
| 7021 | } else if (DUMP_RECENTS_CMD.equals(cmd) || DUMP_RECENTS_SHORT_CMD.equals(cmd)) { |
| 7022 | if (getRecentTasks() != null) { |
| 7023 | getRecentTasks().dump(pw, dumpAll, dumpPackage); |
| 7024 | } |
| 7025 | } |
| 7026 | } |
| 7027 | } |
| 7028 | |
| 7029 | @Override |
| 7030 | public boolean dumpForProcesses(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 7031 | String dumpPackage, int dumpAppId, boolean needSep, boolean testPssMode, |
| 7032 | int wakefulness) { |
| 7033 | synchronized (mGlobalLock) { |
| 7034 | if (mHomeProcess != null && (dumpPackage == null |
| 7035 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
| 7036 | if (needSep) { |
| 7037 | pw.println(); |
| 7038 | needSep = false; |
| 7039 | } |
| 7040 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 7041 | } |
| 7042 | if (mPreviousProcess != null && (dumpPackage == null |
| 7043 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 7044 | if (needSep) { |
| 7045 | pw.println(); |
| 7046 | needSep = false; |
| 7047 | } |
| 7048 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 7049 | } |
| 7050 | if (dumpAll && (mPreviousProcess == null || dumpPackage == null |
| 7051 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 7052 | StringBuilder sb = new StringBuilder(128); |
| 7053 | sb.append(" mPreviousProcessVisibleTime: "); |
| 7054 | TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb); |
| 7055 | pw.println(sb); |
| 7056 | } |
| 7057 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 7058 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
| 7059 | if (needSep) { |
| 7060 | pw.println(); |
| 7061 | needSep = false; |
| 7062 | } |
| 7063 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 7064 | } |
| 7065 | if (dumpPackage == null) { |
| 7066 | pw.println(" mGlobalConfiguration: " + getGlobalConfiguration()); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7067 | mRootWindowContainer.dumpDisplayConfigs(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7068 | } |
| 7069 | if (dumpAll) { |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 7070 | final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); |
| 7071 | if (dumpPackage == null && topFocusedStack != null) { |
| 7072 | pw.println(" mConfigWillChange: " + topFocusedStack.mConfigWillChange); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7073 | } |
| 7074 | if (mCompatModePackages.getPackages().size() > 0) { |
| 7075 | boolean printed = false; |
| 7076 | for (Map.Entry<String, Integer> entry |
| 7077 | : mCompatModePackages.getPackages().entrySet()) { |
| 7078 | String pkg = entry.getKey(); |
| 7079 | int mode = entry.getValue(); |
| 7080 | if (dumpPackage != null && !dumpPackage.equals(pkg)) { |
| 7081 | continue; |
| 7082 | } |
| 7083 | if (!printed) { |
| 7084 | pw.println(" mScreenCompatPackages:"); |
| 7085 | printed = true; |
| 7086 | } |
| 7087 | pw.println(" " + pkg + ": " + mode); |
| 7088 | } |
| 7089 | } |
| 7090 | } |
| 7091 | |
| 7092 | if (dumpPackage == null) { |
| 7093 | pw.println(" mWakefulness=" |
| 7094 | + PowerManagerInternal.wakefulnessToString(wakefulness)); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7095 | pw.println(" mSleepTokens=" + mRootWindowContainer.mSleepTokens); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7096 | if (mRunningVoice != null) { |
| 7097 | pw.println(" mRunningVoice=" + mRunningVoice); |
| 7098 | pw.println(" mVoiceWakeLock" + mVoiceWakeLock); |
| 7099 | } |
| 7100 | pw.println(" mSleeping=" + mSleeping); |
| 7101 | pw.println(" mShuttingDown=" + mShuttingDown + " mTestPssMode=" + testPssMode); |
| 7102 | pw.println(" mVrController=" + mVrController); |
| 7103 | } |
| 7104 | if (mCurAppTimeTracker != null) { |
| 7105 | mCurAppTimeTracker.dumpWithHeader(pw, " ", true); |
| 7106 | } |
| 7107 | if (mAllowAppSwitchUids.size() > 0) { |
| 7108 | boolean printed = false; |
| 7109 | for (int i = 0; i < mAllowAppSwitchUids.size(); i++) { |
| 7110 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.valueAt(i); |
| 7111 | for (int j = 0; j < types.size(); j++) { |
| 7112 | if (dumpPackage == null || |
| 7113 | UserHandle.getAppId(types.valueAt(j).intValue()) == dumpAppId) { |
| 7114 | if (needSep) { |
| 7115 | pw.println(); |
| 7116 | needSep = false; |
| 7117 | } |
| 7118 | if (!printed) { |
| 7119 | pw.println(" mAllowAppSwitchUids:"); |
| 7120 | printed = true; |
| 7121 | } |
| 7122 | pw.print(" User "); |
| 7123 | pw.print(mAllowAppSwitchUids.keyAt(i)); |
| 7124 | pw.print(": Type "); |
| 7125 | pw.print(types.keyAt(j)); |
| 7126 | pw.print(" = "); |
| 7127 | UserHandle.formatUid(pw, types.valueAt(j).intValue()); |
| 7128 | pw.println(); |
| 7129 | } |
| 7130 | } |
| 7131 | } |
| 7132 | } |
| 7133 | if (dumpPackage == null) { |
| 7134 | if (mController != null) { |
| 7135 | pw.println(" mController=" + mController |
| 7136 | + " mControllerIsAMonkey=" + mControllerIsAMonkey); |
| 7137 | } |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 7138 | pw.println(" mGoingToSleepWakeLock=" + mStackSupervisor.mGoingToSleepWakeLock); |
| 7139 | pw.println(" mLaunchingActivityWakeLock=" |
| 7140 | + mStackSupervisor.mLaunchingActivityWakeLock); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7141 | } |
| 7142 | |
| 7143 | return needSep; |
| 7144 | } |
| 7145 | } |
| 7146 | |
| 7147 | @Override |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7148 | public void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage, |
| 7149 | int wakeFullness, boolean testPssMode) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7150 | synchronized (mGlobalLock) { |
| 7151 | if (dumpPackage == null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7152 | getGlobalConfiguration().dumpDebug(proto, GLOBAL_CONFIGURATION); |
Darryl L Johnson | 1e3885c | 2020-02-27 17:38:13 -0800 | [diff] [blame] | 7153 | final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); |
| 7154 | if (topFocusedStack != null) { |
| 7155 | proto.write(CONFIG_WILL_CHANGE, topFocusedStack.mConfigWillChange); |
| 7156 | } |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7157 | writeSleepStateToProto(proto, wakeFullness, testPssMode); |
| 7158 | if (mRunningVoice != null) { |
| 7159 | final long vrToken = proto.start( |
| 7160 | ActivityManagerServiceDumpProcessesProto.RUNNING_VOICE); |
| 7161 | proto.write(ActivityManagerServiceDumpProcessesProto.Voice.SESSION, |
| 7162 | mRunningVoice.toString()); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7163 | mVoiceWakeLock.dumpDebug( |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7164 | proto, ActivityManagerServiceDumpProcessesProto.Voice.WAKELOCK); |
| 7165 | proto.end(vrToken); |
| 7166 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7167 | mVrController.dumpDebug(proto, |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7168 | ActivityManagerServiceDumpProcessesProto.VR_CONTROLLER); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7169 | if (mController != null) { |
| 7170 | final long token = proto.start(CONTROLLER); |
Wally Yau | 0eb29f6 | 2020-01-08 10:16:43 -0800 | [diff] [blame] | 7171 | proto.write(ActivityManagerServiceDumpProcessesProto.Controller.CONTROLLER, |
| 7172 | mController.toString()); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7173 | proto.write(IS_A_MONKEY, mControllerIsAMonkey); |
| 7174 | proto.end(token); |
| 7175 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7176 | mStackSupervisor.mGoingToSleepWakeLock.dumpDebug(proto, GOING_TO_SLEEP); |
| 7177 | mStackSupervisor.mLaunchingActivityWakeLock.dumpDebug(proto, |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 7178 | LAUNCHING_ACTIVITY); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7179 | } |
| 7180 | |
| 7181 | if (mHomeProcess != null && (dumpPackage == null |
| 7182 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7183 | mHomeProcess.dumpDebug(proto, HOME_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7184 | } |
| 7185 | |
| 7186 | if (mPreviousProcess != null && (dumpPackage == null |
| 7187 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7188 | mPreviousProcess.dumpDebug(proto, PREVIOUS_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7189 | proto.write(PREVIOUS_PROC_VISIBLE_TIME_MS, mPreviousProcessVisibleTime); |
| 7190 | } |
| 7191 | |
| 7192 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 7193 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7194 | mHeavyWeightProcess.dumpDebug(proto, HEAVY_WEIGHT_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7195 | } |
| 7196 | |
| 7197 | for (Map.Entry<String, Integer> entry |
| 7198 | : mCompatModePackages.getPackages().entrySet()) { |
| 7199 | String pkg = entry.getKey(); |
| 7200 | int mode = entry.getValue(); |
| 7201 | if (dumpPackage == null || dumpPackage.equals(pkg)) { |
| 7202 | long compatToken = proto.start(SCREEN_COMPAT_PACKAGES); |
| 7203 | proto.write(PACKAGE, pkg); |
| 7204 | proto.write(MODE, mode); |
| 7205 | proto.end(compatToken); |
| 7206 | } |
| 7207 | } |
| 7208 | |
| 7209 | if (mCurAppTimeTracker != null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7210 | mCurAppTimeTracker.dumpDebug(proto, CURRENT_TRACKER, true); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7211 | } |
| 7212 | |
| 7213 | } |
| 7214 | } |
| 7215 | |
| 7216 | @Override |
| 7217 | public boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, |
| 7218 | String[] args, int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, |
| 7219 | boolean dumpFocusedStackOnly) { |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 7220 | return ActivityTaskManagerService.this.dumpActivity(fd, pw, name, args, opti, dumpAll, |
| 7221 | dumpVisibleStacksOnly, dumpFocusedStackOnly); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7222 | } |
| 7223 | |
| 7224 | @Override |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 7225 | public void dumpForOom(PrintWriter pw) { |
| 7226 | synchronized (mGlobalLock) { |
| 7227 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 7228 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 7229 | if (mHeavyWeightProcess != null) { |
| 7230 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 7231 | } |
| 7232 | } |
| 7233 | } |
| 7234 | |
| 7235 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7236 | public boolean canGcNow() { |
| 7237 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7238 | return isSleeping() || mRootWindowContainer.allResumedActivitiesIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7239 | } |
| 7240 | } |
| 7241 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7242 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7243 | @Override |
| 7244 | public WindowProcessController getTopApp() { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7245 | synchronized (mGlobalLockWithoutBoost) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7246 | if (mRootWindowContainer == null) { |
| 7247 | // Return null if mRootWindowContainer not yet initialize, while update |
Louis Chang | 3ff72a8 | 2019-12-17 12:12:59 +0800 | [diff] [blame] | 7248 | // oomadj after AMS created. |
| 7249 | return null; |
| 7250 | } |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7251 | final ActivityRecord top = mRootWindowContainer.getTopResumedActivity(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7252 | return top != null ? top.app : null; |
| 7253 | } |
| 7254 | } |
| 7255 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7256 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7257 | @Override |
| 7258 | public void rankTaskLayersIfNeeded() { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7259 | synchronized (mGlobalLockWithoutBoost) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7260 | if (mRootWindowContainer != null) { |
| 7261 | mRootWindowContainer.rankTaskLayersIfNeeded(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7262 | } |
| 7263 | } |
| 7264 | } |
| 7265 | |
| 7266 | @Override |
| 7267 | public void scheduleDestroyAllActivities(String reason) { |
| 7268 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7269 | mRootWindowContainer.scheduleDestroyAllActivities(reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7270 | } |
| 7271 | } |
| 7272 | |
| 7273 | @Override |
| 7274 | public void removeUser(int userId) { |
| 7275 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7276 | mRootWindowContainer.removeUser(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7277 | } |
| 7278 | } |
| 7279 | |
| 7280 | @Override |
| 7281 | public boolean switchUser(int userId, UserState userState) { |
| 7282 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7283 | return mRootWindowContainer.switchUser(userId, userState); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7284 | } |
| 7285 | } |
| 7286 | |
| 7287 | @Override |
| 7288 | public void onHandleAppCrash(WindowProcessController wpc) { |
| 7289 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7290 | mRootWindowContainer.handleAppCrash(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7291 | } |
| 7292 | } |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 7293 | |
| 7294 | @Override |
| 7295 | public int finishTopCrashedActivities(WindowProcessController crashedApp, String reason) { |
| 7296 | synchronized (mGlobalLock) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 7297 | return mRootWindowContainer.finishTopCrashedActivities(crashedApp, reason); |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 7298 | } |
| 7299 | } |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7300 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7301 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7302 | @Override |
| 7303 | public void onUidActive(int uid, int procState) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7304 | mActiveUids.onUidActive(uid, procState); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7305 | } |
| 7306 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7307 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7308 | @Override |
| 7309 | public void onUidInactive(int uid) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7310 | mActiveUids.onUidInactive(uid); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7311 | } |
| 7312 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7313 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7314 | @Override |
| 7315 | public void onActiveUidsCleared() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7316 | mActiveUids.onActiveUidsCleared(); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7317 | } |
| 7318 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7319 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7320 | @Override |
| 7321 | public void onUidProcStateChanged(int uid, int procState) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7322 | mActiveUids.onUidProcStateChanged(uid, procState); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7323 | } |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7324 | |
| 7325 | @Override |
| 7326 | public void onUidAddedToPendingTempWhitelist(int uid, String tag) { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7327 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7328 | mPendingTempWhitelist.put(uid, tag); |
| 7329 | } |
| 7330 | } |
| 7331 | |
| 7332 | @Override |
| 7333 | public void onUidRemovedFromPendingTempWhitelist(int uid) { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7334 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7335 | mPendingTempWhitelist.remove(uid); |
| 7336 | } |
| 7337 | } |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 7338 | |
| 7339 | @Override |
| 7340 | public boolean handleAppCrashInActivityController(String processName, int pid, |
| 7341 | String shortMsg, String longMsg, long timeMillis, String stackTrace, |
| 7342 | Runnable killCrashingAppCallback) { |
| 7343 | synchronized (mGlobalLock) { |
| 7344 | if (mController == null) { |
| 7345 | return false; |
| 7346 | } |
| 7347 | |
| 7348 | try { |
| 7349 | if (!mController.appCrashed(processName, pid, shortMsg, longMsg, timeMillis, |
| 7350 | stackTrace)) { |
| 7351 | killCrashingAppCallback.run(); |
| 7352 | return true; |
| 7353 | } |
| 7354 | } catch (RemoteException e) { |
| 7355 | mController = null; |
| 7356 | Watchdog.getInstance().setActivityController(null); |
| 7357 | } |
| 7358 | return false; |
| 7359 | } |
| 7360 | } |
Wale Ogunwale | d7889f5 | 2018-10-25 11:03:20 -0700 | [diff] [blame] | 7361 | |
| 7362 | @Override |
| 7363 | public void removeRecentTasksByPackageName(String packageName, int userId) { |
| 7364 | synchronized (mGlobalLock) { |
| 7365 | mRecentTasks.removeTasksByPackageName(packageName, userId); |
| 7366 | } |
| 7367 | } |
| 7368 | |
| 7369 | @Override |
| 7370 | public void cleanupRecentTasksForUser(int userId) { |
| 7371 | synchronized (mGlobalLock) { |
| 7372 | mRecentTasks.cleanupLocked(userId); |
| 7373 | } |
| 7374 | } |
| 7375 | |
| 7376 | @Override |
| 7377 | public void loadRecentTasksForUser(int userId) { |
| 7378 | synchronized (mGlobalLock) { |
| 7379 | mRecentTasks.loadUserRecentsLocked(userId); |
| 7380 | } |
| 7381 | } |
| 7382 | |
| 7383 | @Override |
| 7384 | public void onPackagesSuspendedChanged(String[] packages, boolean suspended, int userId) { |
| 7385 | synchronized (mGlobalLock) { |
| 7386 | mRecentTasks.onPackagesSuspendedChanged(packages, suspended, userId); |
| 7387 | } |
| 7388 | } |
| 7389 | |
| 7390 | @Override |
| 7391 | public void flushRecentTasks() { |
| 7392 | mRecentTasks.flush(); |
| 7393 | } |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 7394 | |
| 7395 | @Override |
| 7396 | public WindowProcessController getHomeProcess() { |
| 7397 | synchronized (mGlobalLock) { |
| 7398 | return mHomeProcess; |
| 7399 | } |
| 7400 | } |
| 7401 | |
| 7402 | @Override |
| 7403 | public WindowProcessController getPreviousProcess() { |
| 7404 | synchronized (mGlobalLock) { |
| 7405 | return mPreviousProcess; |
| 7406 | } |
| 7407 | } |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 7408 | |
| 7409 | @Override |
| 7410 | public void clearLockedTasks(String reason) { |
| 7411 | synchronized (mGlobalLock) { |
| 7412 | getLockTaskController().clearLockedTasks(reason); |
| 7413 | } |
| 7414 | } |
| 7415 | |
| 7416 | @Override |
| 7417 | public void updateUserConfiguration() { |
| 7418 | synchronized (mGlobalLock) { |
| 7419 | final Configuration configuration = new Configuration(getGlobalConfiguration()); |
| 7420 | final int currentUserId = mAmInternal.getCurrentUserId(); |
| 7421 | Settings.System.adjustConfigurationForUser(mContext.getContentResolver(), |
| 7422 | configuration, currentUserId, Settings.System.canWrite(mContext)); |
| 7423 | updateConfigurationLocked(configuration, null /* starting */, |
| 7424 | false /* initLocale */, false /* persistent */, currentUserId, |
| 7425 | false /* deferResume */); |
| 7426 | } |
| 7427 | } |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 7428 | |
| 7429 | @Override |
| 7430 | public boolean canShowErrorDialogs() { |
| 7431 | synchronized (mGlobalLock) { |
| 7432 | return mShowDialogs && !mSleeping && !mShuttingDown |
| 7433 | && !mKeyguardController.isKeyguardOrAodShowing(DEFAULT_DISPLAY) |
| 7434 | && !hasUserRestriction(UserManager.DISALLOW_SYSTEM_ERROR_DIALOGS, |
| 7435 | mAmInternal.getCurrentUserId()) |
| 7436 | && !(UserManager.isDeviceInDemoMode(mContext) |
| 7437 | && mAmInternal.getCurrentUser().isDemo()); |
| 7438 | } |
| 7439 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 7440 | |
| 7441 | @Override |
| 7442 | public void setProfileApp(String profileApp) { |
| 7443 | synchronized (mGlobalLock) { |
| 7444 | mProfileApp = profileApp; |
| 7445 | } |
| 7446 | } |
| 7447 | |
| 7448 | @Override |
| 7449 | public void setProfileProc(WindowProcessController wpc) { |
| 7450 | synchronized (mGlobalLock) { |
| 7451 | mProfileProc = wpc; |
| 7452 | } |
| 7453 | } |
| 7454 | |
| 7455 | @Override |
| 7456 | public void setProfilerInfo(ProfilerInfo profilerInfo) { |
| 7457 | synchronized (mGlobalLock) { |
| 7458 | mProfilerInfo = profilerInfo; |
| 7459 | } |
| 7460 | } |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 7461 | |
| 7462 | @Override |
| 7463 | public ActivityMetricsLaunchObserverRegistry getLaunchObserverRegistry() { |
| 7464 | synchronized (mGlobalLock) { |
| 7465 | return mStackSupervisor.getActivityMetricsLogger().getLaunchObserverRegistry(); |
| 7466 | } |
| 7467 | } |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 7468 | |
| 7469 | @Override |
Zak Cohen | 84b4318 | 2020-03-09 14:36:01 -0700 | [diff] [blame] | 7470 | public ActivityManager.TaskSnapshot getTaskSnapshotBlocking( |
| 7471 | int taskId, boolean isLowResolution) { |
Peter Kalauskas | 4dc0460 | 2020-02-12 18:49:03 -0800 | [diff] [blame] | 7472 | return ActivityTaskManagerService.this.getTaskSnapshot(taskId, isLowResolution, |
Zak Cohen | 84b4318 | 2020-03-09 14:36:01 -0700 | [diff] [blame] | 7473 | true /* restoreFromDisk */); |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 7474 | } |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 7475 | |
| 7476 | @Override |
| 7477 | public boolean isUidForeground(int uid) { |
| 7478 | synchronized (mGlobalLock) { |
| 7479 | return ActivityTaskManagerService.this.isUidForeground(uid); |
| 7480 | } |
| 7481 | } |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7482 | |
| 7483 | @Override |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 7484 | public void setDeviceOwnerUid(int uid) { |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7485 | synchronized (mGlobalLock) { |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 7486 | ActivityTaskManagerService.this.setDeviceOwnerUid(uid); |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7487 | } |
| 7488 | } |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7489 | |
| 7490 | @Override |
| 7491 | public void setCompanionAppPackages(int userId, Set<String> companionAppPackages) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7492 | // Translate package names into UIDs |
| 7493 | final Set<Integer> result = new HashSet<>(); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7494 | for (String pkg : companionAppPackages) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7495 | final int uid = getPackageManagerInternalLocked().getPackageUid(pkg, 0, userId); |
| 7496 | if (uid >= 0) { |
| 7497 | result.add(uid); |
| 7498 | } |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7499 | } |
| 7500 | synchronized (mGlobalLock) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7501 | mCompanionAppUidsMap.put(userId, result); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7502 | } |
| 7503 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 7504 | } |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 7505 | } |