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; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 31 | import static android.app.ActivityManagerInternal.ALLOW_FULL_ONLY; |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 32 | import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 33 | import static android.app.ActivityTaskManager.RESIZE_MODE_PRESERVE_WINDOW; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 34 | import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT; |
| 35 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 36 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 37 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 38 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 39 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 40 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 41 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 42 | import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 43 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 44 | import static android.content.pm.ApplicationInfo.FLAG_FACTORY_TEST; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 45 | import static android.content.pm.ConfigurationInfo.GL_ES_VERSION_UNDEFINED; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 46 | import static android.content.pm.PackageManager.FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS; |
| 47 | import static android.content.pm.PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 48 | import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 49 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 50 | import static android.os.FactoryTest.FACTORY_TEST_HIGH_LEVEL; |
| 51 | import static android.os.FactoryTest.FACTORY_TEST_LOW_LEVEL; |
| 52 | import static android.os.FactoryTest.FACTORY_TEST_OFF; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 53 | import static android.os.Process.FIRST_APPLICATION_UID; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 54 | import static android.os.Process.SYSTEM_UID; |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 55 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 56 | import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 57 | import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_SIZECOMPAT_FREEFORM; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 58 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES; |
| 59 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RTL; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 60 | import static android.provider.Settings.Global.HIDE_ERROR_DIALOGS; |
| 61 | import static android.provider.Settings.System.FONT_SCALE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 62 | import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_APPLICATION; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 63 | import static android.text.format.DateUtils.MINUTE_IN_MILLIS; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 64 | import static android.view.Display.DEFAULT_DISPLAY; |
| 65 | import static android.view.Display.INVALID_DISPLAY; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 66 | import static android.view.WindowManager.TRANSIT_NONE; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 67 | |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 68 | import static com.android.server.am.ActivityManagerService.ANR_TRACE_DIR; |
| 69 | import static com.android.server.am.ActivityManagerService.MY_PID; |
| 70 | import static com.android.server.am.ActivityManagerService.STOCK_PM_FLAGS; |
| 71 | import static com.android.server.am.ActivityManagerService.dumpStackTraces; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 72 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CONFIG_WILL_CHANGE; |
| 73 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CONTROLLER; |
| 74 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CURRENT_TRACKER; |
| 75 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.Controller.IS_A_MONKEY; |
| 76 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.GLOBAL_CONFIGURATION; |
| 77 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.GOING_TO_SLEEP; |
| 78 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HEAVY_WEIGHT_PROC; |
| 79 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HOME_PROC; |
| 80 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.LAUNCHING_ACTIVITY; |
| 81 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 82 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC_VISIBLE_TIME_MS; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 83 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.SCREEN_COMPAT_PACKAGES; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 84 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.MODE; |
| 85 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.PACKAGE; |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 86 | import static com.android.server.am.EventLogTags.writeBootProgressEnableScreen; |
| 87 | import static com.android.server.am.EventLogTags.writeConfigurationChanged; |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 88 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; |
| 89 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 90 | import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 91 | import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; |
| 92 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
| 93 | import static com.android.server.wm.ActivityStackSupervisor.REMOVE_FROM_RECENTS; |
| 94 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL; |
| 95 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONFIGURATION; |
| 96 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_FOCUS; |
| 97 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_IMMERSIVE; |
| 98 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_LOCKTASK; |
| 99 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STACK; |
| 100 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; |
| 101 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 102 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_VISIBILITY; |
| 103 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFIGURATION; |
| 104 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_FOCUS; |
| 105 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_IMMERSIVE; |
| 106 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_LOCKTASK; |
| 107 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; |
| 108 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; |
| 109 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_VISIBILITY; |
| 110 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 111 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 112 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_CONTENT; |
| 113 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_DATA; |
| 114 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_RECEIVER_EXTRAS; |
| 115 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_STRUCTURE; |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 116 | import static com.android.server.wm.ActivityTaskManagerService.H.REPORT_TIME_TRACKER_MSG; |
| 117 | import static com.android.server.wm.ActivityTaskManagerService.UiHandler.DISMISS_DIALOG_UI_MSG; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 118 | import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; |
| 119 | import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 120 | import static com.android.server.wm.RootActivityContainer.MATCH_TASK_IN_STACKS_ONLY; |
| 121 | import static com.android.server.wm.RootActivityContainer.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 122 | import static com.android.server.wm.Task.LOCK_TASK_AUTH_DONT_LOCK; |
| 123 | import static com.android.server.wm.Task.REPARENT_KEEP_STACK_AT_FRONT; |
| 124 | import static com.android.server.wm.Task.REPARENT_LEAVE_STACK_IN_PLACE; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 125 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 126 | import android.Manifest; |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 127 | import android.annotation.IntDef; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 128 | import android.annotation.NonNull; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 129 | import android.annotation.Nullable; |
| 130 | import android.annotation.UserIdInt; |
| 131 | import android.app.Activity; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 132 | import android.app.ActivityManager; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 133 | import android.app.ActivityManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 134 | import android.app.ActivityOptions; |
| 135 | import android.app.ActivityTaskManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 136 | import android.app.ActivityThread; |
| 137 | import android.app.AlertDialog; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 138 | import android.app.AppGlobals; |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 139 | import android.app.AppOpsManager; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 140 | import android.app.Dialog; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 141 | import android.app.IActivityController; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 142 | import android.app.IActivityTaskManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 143 | import android.app.IApplicationThread; |
| 144 | import android.app.IAssistDataReceiver; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 145 | import android.app.INotificationManager; |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 146 | import android.app.IRequestFinishCallback; |
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; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 159 | import android.app.usage.UsageStatsManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 160 | import android.content.ActivityNotFoundException; |
| 161 | import android.content.ComponentName; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 162 | import android.content.ContentResolver; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 163 | import android.content.Context; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 164 | import android.content.DialogInterface; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 165 | import android.content.IIntentSender; |
| 166 | import android.content.Intent; |
| 167 | import android.content.pm.ActivityInfo; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 168 | import android.content.pm.ApplicationInfo; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 169 | import android.content.pm.ConfigurationInfo; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 170 | import android.content.pm.IPackageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 171 | import android.content.pm.PackageManager; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 172 | import android.content.pm.PackageManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 173 | import android.content.pm.ParceledListSlice; |
| 174 | import android.content.pm.ResolveInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 175 | import android.content.res.CompatibilityInfo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 176 | import android.content.res.Configuration; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 177 | import android.content.res.Resources; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 178 | import android.database.ContentObserver; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 179 | import android.graphics.Bitmap; |
| 180 | import android.graphics.Point; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 181 | import android.graphics.Rect; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 182 | import android.metrics.LogMaker; |
| 183 | import android.net.Uri; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 184 | import android.os.Binder; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 185 | import android.os.Build; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 186 | import android.os.Bundle; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 187 | import android.os.FactoryTest; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 188 | import android.os.FileUtils; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 189 | import android.os.Handler; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 190 | import android.os.IBinder; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 191 | import android.os.IUserManager; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 192 | import android.os.LocaleList; |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 193 | import android.os.Looper; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 194 | import android.os.Message; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 195 | import android.os.PersistableBundle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 196 | import android.os.PowerManager; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 197 | import android.os.PowerManagerInternal; |
Marvin Ramin | 830d4e3 | 2019-03-12 13:16:58 +0100 | [diff] [blame] | 198 | import android.os.Process; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 199 | import android.os.RemoteException; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 200 | import android.os.ServiceManager; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 201 | import android.os.StrictMode; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 202 | import android.os.SystemClock; |
| 203 | import android.os.SystemProperties; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 204 | import android.os.Trace; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 205 | import android.os.UpdateLock; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 206 | import android.os.UserHandle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 207 | import android.os.UserManager; |
| 208 | import android.os.WorkSource; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 209 | import android.os.storage.IStorageManager; |
| 210 | import android.os.storage.StorageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 211 | import android.provider.Settings; |
| 212 | import android.service.voice.IVoiceInteractionSession; |
| 213 | import android.service.voice.VoiceInteractionManagerInternal; |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 214 | import android.sysprop.DisplayProperties; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 215 | import android.telecom.TelecomManager; |
| 216 | import android.text.TextUtils; |
Neil Fuller | 9774681 | 2019-08-19 14:20:50 +0100 | [diff] [blame] | 217 | import android.text.format.TimeMigrationUtils; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 218 | import android.util.ArrayMap; |
Nicholas Sauer | 3f9249f | 2019-09-10 20:23:41 -0700 | [diff] [blame] | 219 | import android.util.ArraySet; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 220 | import android.util.Log; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 221 | import android.util.Slog; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 222 | import android.util.SparseArray; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 223 | import android.util.StatsLog; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 224 | import android.util.TimeUtils; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 225 | import android.util.proto.ProtoOutputStream; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 226 | import android.view.IRecentsAnimationRunner; |
| 227 | import android.view.RemoteAnimationAdapter; |
| 228 | import android.view.RemoteAnimationDefinition; |
Evan Rosky | ddedfd4 | 2019-10-04 13:38:38 -0700 | [diff] [blame] | 229 | import android.view.WindowContainerTransaction; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 230 | import android.view.WindowManager; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 231 | |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 232 | import com.android.internal.R; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 233 | import com.android.internal.annotations.VisibleForTesting; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 234 | import com.android.internal.app.AssistUtils; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 235 | import com.android.internal.app.IAppOpsService; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 236 | import com.android.internal.app.IVoiceInteractor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 237 | import com.android.internal.app.ProcessMap; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 238 | import com.android.internal.logging.MetricsLogger; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 239 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 240 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
| 241 | import com.android.internal.notification.SystemNotificationChannels; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 242 | import com.android.internal.os.TransferPipe; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 243 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 244 | import com.android.internal.policy.IKeyguardDismissCallback; |
| 245 | import com.android.internal.policy.KeyguardDismissCallback; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 246 | import com.android.internal.util.ArrayUtils; |
| 247 | import com.android.internal.util.FastPrintWriter; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 248 | import com.android.internal.util.Preconditions; |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 249 | import com.android.internal.util.function.pooled.PooledConsumer; |
| 250 | import com.android.internal.util.function.pooled.PooledFunction; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 251 | import com.android.internal.util.function.pooled.PooledLambda; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 252 | import com.android.server.AttributeCache; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 253 | import com.android.server.LocalServices; |
| 254 | import com.android.server.SystemService; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 255 | import com.android.server.SystemServiceManager; |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 256 | import com.android.server.UiThread; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 257 | import com.android.server.Watchdog; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 258 | import com.android.server.am.ActivityManagerService; |
| 259 | import com.android.server.am.ActivityManagerServiceDumpActivitiesProto; |
| 260 | import com.android.server.am.ActivityManagerServiceDumpProcessesProto; |
| 261 | import com.android.server.am.AppTimeTracker; |
| 262 | import com.android.server.am.BaseErrorDialog; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 263 | import com.android.server.am.PendingIntentController; |
| 264 | import com.android.server.am.PendingIntentRecord; |
| 265 | import com.android.server.am.UserState; |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 266 | import com.android.server.appop.AppOpsService; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 267 | import com.android.server.firewall.IntentFirewall; |
Tarandeep Singh | 07b318b | 2019-07-17 11:12:04 -0700 | [diff] [blame] | 268 | import com.android.server.inputmethod.InputMethodSystemProperty; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 269 | import com.android.server.pm.UserManagerService; |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 270 | import com.android.server.policy.PermissionPolicyInternal; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 271 | import com.android.server.uri.UriGrantsManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 272 | import com.android.server.vr.VrManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 273 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 274 | import java.io.BufferedReader; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 275 | import java.io.File; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 276 | import java.io.FileDescriptor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 277 | import java.io.FileOutputStream; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 278 | import java.io.FileReader; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 279 | import java.io.IOException; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 280 | import java.io.PrintWriter; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 281 | import java.io.StringWriter; |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 282 | import java.lang.annotation.ElementType; |
| 283 | import java.lang.annotation.Retention; |
| 284 | import java.lang.annotation.RetentionPolicy; |
| 285 | import java.lang.annotation.Target; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 286 | import java.lang.ref.WeakReference; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 287 | import java.text.DateFormat; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 288 | import java.util.ArrayList; |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 289 | import java.util.Arrays; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 290 | import java.util.Date; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 291 | import java.util.HashMap; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 292 | import java.util.HashSet; |
Evan Rosky | ddedfd4 | 2019-10-04 13:38:38 -0700 | [diff] [blame] | 293 | import java.util.Iterator; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 294 | import java.util.List; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 295 | import java.util.Locale; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 296 | import java.util.Map; |
| 297 | import java.util.Set; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 298 | |
| 299 | /** |
| 300 | * System service for managing activities and their containers (task, stacks, displays,... ). |
| 301 | * |
| 302 | * {@hide} |
| 303 | */ |
| 304 | public class ActivityTaskManagerService extends IActivityTaskManager.Stub { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 305 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityTaskManagerService" : TAG_ATM; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 306 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 307 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 308 | private static final String TAG_IMMERSIVE = TAG + POSTFIX_IMMERSIVE; |
| 309 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
| 310 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
| 311 | private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 312 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 313 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 314 | // How long we wait until we timeout on key dispatching. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 315 | public static final int KEY_DISPATCHING_TIMEOUT_MS = 5 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 316 | // How long we wait until we timeout on key dispatching during instrumentation. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 317 | static final int INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT_MS = 60 * 1000; |
Michal Karpinski | fc6872e | 2019-05-21 15:18:44 +0100 | [diff] [blame] | 318 | // How long we permit background activity starts after an activity in the process |
| 319 | // started or finished. |
| 320 | static final long ACTIVITY_BG_START_GRACE_PERIOD_MS = 10 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 321 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 322 | /** Used to indicate that an app transition should be animated. */ |
| 323 | static final boolean ANIMATE = true; |
| 324 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 325 | /** Hardware-reported OpenGLES version. */ |
| 326 | final int GL_ES_VERSION; |
| 327 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 328 | public static final String DUMP_ACTIVITIES_CMD = "activities" ; |
| 329 | public static final String DUMP_ACTIVITIES_SHORT_CMD = "a" ; |
| 330 | public static final String DUMP_LASTANR_CMD = "lastanr" ; |
| 331 | public static final String DUMP_LASTANR_TRACES_CMD = "lastanr-traces" ; |
| 332 | public static final String DUMP_STARTER_CMD = "starter" ; |
| 333 | public static final String DUMP_CONTAINERS_CMD = "containers" ; |
| 334 | public static final String DUMP_RECENTS_CMD = "recents" ; |
| 335 | public static final String DUMP_RECENTS_SHORT_CMD = "r" ; |
| 336 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 337 | /** This activity is not being relaunched, or being relaunched for a non-resize reason. */ |
| 338 | public static final int RELAUNCH_REASON_NONE = 0; |
| 339 | /** This activity is being relaunched due to windowing mode change. */ |
| 340 | public static final int RELAUNCH_REASON_WINDOWING_MODE_RESIZE = 1; |
| 341 | /** This activity is being relaunched due to a free-resize operation. */ |
| 342 | public static final int RELAUNCH_REASON_FREE_RESIZE = 2; |
| 343 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 344 | Context mContext; |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 345 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 346 | /** |
| 347 | * This Context is themable and meant for UI display (AlertDialogs, etc.). The theme can |
| 348 | * change at runtime. Use mContext for non-UI purposes. |
| 349 | */ |
| 350 | final Context mUiContext; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 351 | final ActivityThread mSystemThread; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 352 | H mH; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 353 | UiHandler mUiHandler; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 354 | ActivityManagerInternal mAmInternal; |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 355 | UriGrantsManagerInternal mUgmInternal; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 356 | private PackageManagerInternal mPmInternal; |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 357 | private PermissionPolicyInternal mPermissionPolicyInternal; |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 358 | @VisibleForTesting |
| 359 | final ActivityTaskManagerInternal mInternal; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 360 | PowerManagerInternal mPowerManagerInternal; |
| 361 | private UsageStatsManagerInternal mUsageStatsInternal; |
| 362 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 363 | PendingIntentController mPendingIntentController; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 364 | IntentFirewall mIntentFirewall; |
| 365 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 366 | /* Global service lock used by the package the owns this service. */ |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 367 | final WindowManagerGlobalLock mGlobalLock = new WindowManagerGlobalLock(); |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 368 | /** |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 369 | * 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] | 370 | * locked-region-code-injection does't recognize it. It is used to skip wrapping priority |
| 371 | * booster for places that are already in the scope of another booster (e.g. computing oom-adj). |
| 372 | * |
| 373 | * @see WindowManagerThreadPriorityBooster |
| 374 | */ |
| 375 | final Object mGlobalLockWithoutBoost = mGlobalLock; |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 376 | ActivityStackSupervisor mStackSupervisor; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 377 | RootActivityContainer mRootActivityContainer; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 378 | WindowManagerService mWindowManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 379 | private UserManagerService mUserManager; |
| 380 | private AppOpsService mAppOpsService; |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 381 | /** All active uids in the system. */ |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 382 | private final MirrorActiveUids mActiveUids = new MirrorActiveUids(); |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 383 | private final SparseArray<String> mPendingTempWhitelist = new SparseArray<>(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 384 | /** All processes currently running that might have a window organized by name. */ |
| 385 | final ProcessMap<WindowProcessController> mProcessNames = new ProcessMap<>(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 386 | /** All processes we currently have running mapped by pid and uid */ |
| 387 | final WindowProcessControllerMap mProcessMap = new WindowProcessControllerMap(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 388 | /** This is the process holding what we currently consider to be the "home" activity. */ |
| 389 | WindowProcessController mHomeProcess; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 390 | /** The currently running heavy-weight process, if any. */ |
| 391 | WindowProcessController mHeavyWeightProcess = null; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 392 | boolean mHasHeavyWeightFeature; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 393 | /** |
| 394 | * This is the process holding the activity the user last visited that is in a different process |
| 395 | * from the one they are currently in. |
| 396 | */ |
| 397 | WindowProcessController mPreviousProcess; |
| 398 | /** The time at which the previous process was last visible. */ |
| 399 | long mPreviousProcessVisibleTime; |
| 400 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 401 | /** List of intents that were used to start the most recent tasks. */ |
| 402 | private RecentTasks mRecentTasks; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 403 | /** State of external calls telling us if the device is awake or asleep. */ |
| 404 | private boolean mKeyguardShown = false; |
| 405 | |
| 406 | // Wrapper around VoiceInteractionServiceManager |
| 407 | private AssistUtils mAssistUtils; |
| 408 | |
| 409 | // VoiceInteraction session ID that changes for each new request except when |
| 410 | // being called for multi-window assist in a single session. |
| 411 | private int mViSessionId = 1000; |
| 412 | |
| 413 | // How long to wait in getAssistContextExtras for the activity and foreground services |
| 414 | // to respond with the result. |
| 415 | private static final int PENDING_ASSIST_EXTRAS_TIMEOUT = 500; |
| 416 | |
| 417 | // How long top wait when going through the modern assist (which doesn't need to block |
| 418 | // on getting this result before starting to launch its UI). |
| 419 | private static final int PENDING_ASSIST_EXTRAS_LONG_TIMEOUT = 2000; |
| 420 | |
| 421 | // How long to wait in getAutofillAssistStructure() for the activity to respond with the result. |
| 422 | private static final int PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT = 2000; |
| 423 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 424 | // Permission tokens are used to temporarily granted a trusted app the ability to call |
| 425 | // #startActivityAsCaller. A client is expected to dump its token after this time has elapsed, |
| 426 | // showing any appropriate error messages to the user. |
| 427 | private static final long START_AS_CALLER_TOKEN_TIMEOUT = |
| 428 | 10 * MINUTE_IN_MILLIS; |
| 429 | |
| 430 | // How long before the service actually expires a token. This is slightly longer than |
| 431 | // START_AS_CALLER_TOKEN_TIMEOUT, to provide a buffer so clients will rarely encounter the |
| 432 | // expiration exception. |
| 433 | private static final long START_AS_CALLER_TOKEN_TIMEOUT_IMPL = |
| 434 | START_AS_CALLER_TOKEN_TIMEOUT + 2 * 1000; |
| 435 | |
| 436 | // How long the service will remember expired tokens, for the purpose of providing error |
| 437 | // messaging when a client uses an expired token. |
| 438 | private static final long START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT = |
| 439 | START_AS_CALLER_TOKEN_TIMEOUT_IMPL + 20 * MINUTE_IN_MILLIS; |
| 440 | |
| 441 | // Activity tokens of system activities that are delegating their call to |
| 442 | // #startActivityByCaller, keyed by the permissionToken granted to the delegate. |
| 443 | final HashMap<IBinder, IBinder> mStartActivitySources = new HashMap<>(); |
| 444 | |
| 445 | // Permission tokens that have expired, but we remember for error reporting. |
| 446 | final ArrayList<IBinder> mExpiredStartAsCallerTokens = new ArrayList<>(); |
| 447 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 448 | private final ArrayList<PendingAssistExtras> mPendingAssistExtras = new ArrayList<>(); |
| 449 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 450 | // Keeps track of the active voice interaction service component, notified from |
| 451 | // VoiceInteractionManagerService |
| 452 | ComponentName mActiveVoiceInteractionServiceComponent; |
| 453 | |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 454 | // A map userId and all its companion app uids |
| 455 | private final Map<Integer, Set<Integer>> mCompanionAppUidsMap = new ArrayMap<>(); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 456 | |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 457 | VrController mVrController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 458 | KeyguardController mKeyguardController; |
| 459 | private final ClientLifecycleManager mLifecycleManager; |
| 460 | private TaskChangeNotificationController mTaskChangeNotificationController; |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 461 | /** The controller for all operations related to locktask. */ |
| 462 | private LockTaskController mLockTaskController; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 463 | private ActivityStartController mActivityStartController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 464 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 465 | boolean mSuppressResizeConfigChanges; |
| 466 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 467 | final UpdateConfigurationResult mTmpUpdateConfigurationResult = |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 468 | new UpdateConfigurationResult(); |
| 469 | |
| 470 | static final class UpdateConfigurationResult { |
| 471 | // Configuration changes that were updated. |
| 472 | int changes; |
| 473 | // If the activity was relaunched to match the new configuration. |
| 474 | boolean activityRelaunched; |
| 475 | |
| 476 | void reset() { |
| 477 | changes = 0; |
| 478 | activityRelaunched = false; |
| 479 | } |
| 480 | } |
| 481 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 482 | /** Current sequencing integer of the configuration, for skipping old configurations. */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 483 | private int mConfigurationSeq; |
| 484 | // To cache the list of supported system locales |
| 485 | private String[] mSupportedSystemLocales = null; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 486 | |
| 487 | /** |
| 488 | * Temp object used when global and/or display override configuration is updated. It is also |
| 489 | * sent to outer world instead of {@link #getGlobalConfiguration} because we don't trust |
| 490 | * anyone... |
| 491 | */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 492 | private Configuration mTempConfig = new Configuration(); |
| 493 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 494 | /** Temporary to avoid allocations. */ |
| 495 | final StringBuilder mStringBuilder = new StringBuilder(256); |
| 496 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 497 | // Amount of time after a call to stopAppSwitches() during which we will |
| 498 | // prevent further untrusted switches from happening. |
| 499 | private static final long APP_SWITCH_DELAY_TIME = 5 * 1000; |
| 500 | |
| 501 | /** |
| 502 | * The time at which we will allow normal application switches again, |
| 503 | * after a call to {@link #stopAppSwitches()}. |
| 504 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 505 | private long mAppSwitchesAllowedTime; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 506 | /** |
| 507 | * This is set to true after the first switch after mAppSwitchesAllowedTime |
| 508 | * is set; any switches after that will clear the time. |
| 509 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 510 | private boolean mDidAppSwitch; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 511 | |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 512 | /** |
| 513 | * Last stop app switches time, apps finished before this time cannot start background activity |
| 514 | * even if they are in grace period. |
| 515 | */ |
| 516 | private long mLastStopAppSwitchesTime; |
| 517 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 518 | IActivityController mController = null; |
| 519 | boolean mControllerIsAMonkey = false; |
| 520 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 521 | final int mFactoryTest; |
| 522 | |
| 523 | /** Used to control how we initialize the service. */ |
| 524 | ComponentName mTopComponent; |
| 525 | String mTopAction = Intent.ACTION_MAIN; |
| 526 | String mTopData; |
| 527 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 528 | /** Profiling app information. */ |
| 529 | String mProfileApp = null; |
| 530 | WindowProcessController mProfileProc = null; |
| 531 | ProfilerInfo mProfilerInfo = null; |
| 532 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 533 | /** |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 534 | * Dump of the activity state at the time of the last ANR. Cleared after |
| 535 | * {@link WindowManagerService#LAST_ANR_LIFETIME_DURATION_MSECS} |
| 536 | */ |
| 537 | String mLastANRState; |
| 538 | |
| 539 | /** |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 540 | * Used to retain an update lock when the foreground activity is in |
| 541 | * immersive mode. |
| 542 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 543 | private final UpdateLock mUpdateLock = new UpdateLock("immersive"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 544 | |
| 545 | /** |
| 546 | * Packages that are being allowed to perform unrestricted app switches. Mapping is |
| 547 | * User -> Type -> uid. |
| 548 | */ |
| 549 | final SparseArray<ArrayMap<String, Integer>> mAllowAppSwitchUids = new SparseArray<>(); |
| 550 | |
| 551 | /** The dimensions of the thumbnails in the Recents UI. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 552 | private int mThumbnailWidth; |
| 553 | private int mThumbnailHeight; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 554 | |
| 555 | /** |
| 556 | * Flag that indicates if multi-window is enabled. |
| 557 | * |
| 558 | * For any particular form of multi-window to be enabled, generic multi-window must be enabled |
| 559 | * in {@link com.android.internal.R.bool#config_supportsMultiWindow} config or |
| 560 | * {@link Settings.Global#DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES} development option set. |
| 561 | * At least one of the forms of multi-window must be enabled in order for this flag to be |
| 562 | * initialized to 'true'. |
| 563 | * |
| 564 | * @see #mSupportsSplitScreenMultiWindow |
| 565 | * @see #mSupportsFreeformWindowManagement |
| 566 | * @see #mSupportsPictureInPicture |
| 567 | * @see #mSupportsMultiDisplay |
| 568 | */ |
| 569 | boolean mSupportsMultiWindow; |
| 570 | boolean mSupportsSplitScreenMultiWindow; |
| 571 | boolean mSupportsFreeformWindowManagement; |
| 572 | boolean mSupportsPictureInPicture; |
| 573 | boolean mSupportsMultiDisplay; |
| 574 | boolean mForceResizableActivities; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 575 | boolean mSizeCompatFreeform; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 576 | |
| 577 | final List<ActivityTaskManagerInternal.ScreenObserver> mScreenObservers = new ArrayList<>(); |
| 578 | |
| 579 | // VR Vr2d Display Id. |
| 580 | int mVr2dDisplayId = INVALID_DISPLAY; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 581 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 582 | /** |
| 583 | * Set while we are wanting to sleep, to prevent any |
| 584 | * activities from being started/resumed. |
| 585 | * |
| 586 | * TODO(b/33594039): Clarify the actual state transitions represented by mSleeping. |
| 587 | * |
| 588 | * Currently mSleeping is set to true when transitioning into the sleep state, and remains true |
| 589 | * while in the sleep state until there is a pending transition out of sleep, in which case |
| 590 | * mSleeping is set to false, and remains false while awake. |
| 591 | * |
| 592 | * Whether mSleeping can quickly toggled between true/false without the device actually |
| 593 | * display changing states is undefined. |
| 594 | */ |
| 595 | private boolean mSleeping = false; |
| 596 | |
| 597 | /** |
| 598 | * The process state used for processes that are running the top activities. |
| 599 | * This changes between TOP and TOP_SLEEPING to following mSleeping. |
| 600 | */ |
| 601 | int mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
| 602 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 603 | @Retention(RetentionPolicy.SOURCE) |
| 604 | @IntDef({ |
| 605 | LAYOUT_REASON_CONFIG_CHANGED, |
| 606 | LAYOUT_REASON_VISIBILITY_CHANGED, |
| 607 | }) |
| 608 | @interface LayoutReason {} |
| 609 | static final int LAYOUT_REASON_CONFIG_CHANGED = 0x1; |
| 610 | static final int LAYOUT_REASON_VISIBILITY_CHANGED = 0x2; |
| 611 | |
| 612 | /** The reasons to perform surface placement. */ |
| 613 | @LayoutReason |
| 614 | private int mLayoutReasons; |
| 615 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 616 | // Whether we should show our dialogs (ANR, crash, etc) or just perform their default action |
| 617 | // automatically. Important for devices without direct input devices. |
| 618 | private boolean mShowDialogs = true; |
| 619 | |
| 620 | /** Set if we are shutting down the system, similar to sleeping. */ |
| 621 | boolean mShuttingDown = false; |
| 622 | |
| 623 | /** |
| 624 | * We want to hold a wake lock while running a voice interaction session, since |
| 625 | * this may happen with the screen off and we need to keep the CPU running to |
| 626 | * be able to continue to interact with the user. |
| 627 | */ |
| 628 | PowerManager.WakeLock mVoiceWakeLock; |
| 629 | |
| 630 | /** |
| 631 | * Set while we are running a voice interaction. This overrides sleeping while it is active. |
| 632 | */ |
| 633 | IVoiceInteractionSession mRunningVoice; |
| 634 | |
| 635 | /** |
| 636 | * The last resumed activity. This is identical to the current resumed activity most |
| 637 | * of the time but could be different when we're pausing one activity before we resume |
| 638 | * another activity. |
| 639 | */ |
| 640 | ActivityRecord mLastResumedActivity; |
| 641 | |
| 642 | /** |
| 643 | * The activity that is currently being traced as the active resumed activity. |
| 644 | * |
| 645 | * @see #updateResumedAppTrace |
| 646 | */ |
| 647 | private @Nullable ActivityRecord mTracedResumedActivity; |
| 648 | |
| 649 | /** If non-null, we are tracking the time the user spends in the currently focused app. */ |
| 650 | AppTimeTracker mCurAppTimeTracker; |
| 651 | |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 652 | AppWarnings mAppWarnings; |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 653 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 654 | /** |
| 655 | * Packages that the user has asked to have run in screen size |
| 656 | * compatibility mode instead of filling the screen. |
| 657 | */ |
| 658 | CompatModePackages mCompatModePackages; |
| 659 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 660 | private FontScaleSettingObserver mFontScaleSettingObserver; |
| 661 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 662 | private int mDeviceOwnerUid = Process.INVALID_UID; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 663 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 664 | private final class FontScaleSettingObserver extends ContentObserver { |
| 665 | private final Uri mFontScaleUri = Settings.System.getUriFor(FONT_SCALE); |
| 666 | private final Uri mHideErrorDialogsUri = Settings.Global.getUriFor(HIDE_ERROR_DIALOGS); |
| 667 | |
| 668 | public FontScaleSettingObserver() { |
| 669 | super(mH); |
| 670 | final ContentResolver resolver = mContext.getContentResolver(); |
| 671 | resolver.registerContentObserver(mFontScaleUri, false, this, UserHandle.USER_ALL); |
| 672 | resolver.registerContentObserver(mHideErrorDialogsUri, false, this, |
| 673 | UserHandle.USER_ALL); |
| 674 | } |
| 675 | |
| 676 | @Override |
| 677 | public void onChange(boolean selfChange, Uri uri, @UserIdInt int userId) { |
| 678 | if (mFontScaleUri.equals(uri)) { |
| 679 | updateFontScaleIfNeeded(userId); |
| 680 | } else if (mHideErrorDialogsUri.equals(uri)) { |
| 681 | synchronized (mGlobalLock) { |
| 682 | updateShouldShowDialogsLocked(getGlobalConfiguration()); |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | } |
| 687 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 688 | /** Indicates that the method may be invoked frequently or is sensitive to performance. */ |
| 689 | @Target(ElementType.METHOD) |
| 690 | @Retention(RetentionPolicy.SOURCE) |
| 691 | @interface HotPath { |
| 692 | int NONE = 0; |
| 693 | int OOM_ADJUSTMENT = 1; |
| 694 | int LRU_UPDATE = 2; |
| 695 | int PROCESS_CHANGE = 3; |
| 696 | int caller() default NONE; |
| 697 | } |
| 698 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 699 | private final Runnable mUpdateOomAdjRunnable = new Runnable() { |
| 700 | @Override |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 701 | public void run() { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 702 | mAmInternal.updateOomAdj(); |
| 703 | } |
| 704 | }; |
| 705 | |
Charles Chen | 8d98dd2 | 2018-12-26 17:36:54 +0800 | [diff] [blame] | 706 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 707 | public ActivityTaskManagerService(Context context) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 708 | mContext = context; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 709 | mFactoryTest = FactoryTest.getMode(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 710 | mSystemThread = ActivityThread.currentActivityThread(); |
| 711 | mUiContext = mSystemThread.getSystemUiContext(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 712 | mLifecycleManager = new ClientLifecycleManager(); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 713 | mInternal = new LocalService(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 714 | GL_ES_VERSION = SystemProperties.getInt("ro.opengles.version", GL_ES_VERSION_UNDEFINED); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 717 | public void onSystemReady() { |
| 718 | synchronized (mGlobalLock) { |
| 719 | mHasHeavyWeightFeature = mContext.getPackageManager().hasSystemFeature( |
| 720 | PackageManager.FEATURE_CANT_SAVE_STATE); |
| 721 | mAssistUtils = new AssistUtils(mContext); |
| 722 | mVrController.onSystemReady(); |
| 723 | mRecentTasks.onSystemReadyLocked(); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 724 | mStackSupervisor.onSystemReady(); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 725 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 728 | public void onInitPowerManagement() { |
| 729 | synchronized (mGlobalLock) { |
| 730 | mStackSupervisor.initPowerManagement(); |
| 731 | final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 732 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
| 733 | mVoiceWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*voice*"); |
| 734 | mVoiceWakeLock.setReferenceCounted(false); |
| 735 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 738 | public void installSystemProviders() { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 739 | mFontScaleSettingObserver = new FontScaleSettingObserver(); |
| 740 | } |
| 741 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 742 | public void retrieveSettings(ContentResolver resolver) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 743 | final boolean freeformWindowManagement = |
| 744 | mContext.getPackageManager().hasSystemFeature(FEATURE_FREEFORM_WINDOW_MANAGEMENT) |
| 745 | || Settings.Global.getInt( |
| 746 | resolver, DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0; |
| 747 | |
| 748 | final boolean supportsMultiWindow = ActivityTaskManager.supportsMultiWindow(mContext); |
| 749 | final boolean supportsPictureInPicture = supportsMultiWindow && |
| 750 | mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE); |
| 751 | final boolean supportsSplitScreenMultiWindow = |
| 752 | ActivityTaskManager.supportsSplitScreenMultiWindow(mContext); |
| 753 | final boolean supportsMultiDisplay = mContext.getPackageManager() |
| 754 | .hasSystemFeature(FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 755 | final boolean forceRtl = Settings.Global.getInt(resolver, DEVELOPMENT_FORCE_RTL, 0) != 0; |
| 756 | final boolean forceResizable = Settings.Global.getInt( |
| 757 | resolver, DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 758 | final boolean sizeCompatFreeform = Settings.Global.getInt( |
| 759 | resolver, DEVELOPMENT_ENABLE_SIZECOMPAT_FREEFORM, 0) != 0; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 760 | |
| 761 | // Transfer any global setting for forcing RTL layout, into a System Property |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 762 | DisplayProperties.debug_force_rtl(forceRtl); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 763 | |
| 764 | final Configuration configuration = new Configuration(); |
| 765 | Settings.System.getConfiguration(resolver, configuration); |
| 766 | if (forceRtl) { |
| 767 | // This will take care of setting the correct layout direction flags |
| 768 | configuration.setLayoutDirection(configuration.locale); |
| 769 | } |
| 770 | |
| 771 | synchronized (mGlobalLock) { |
| 772 | mForceResizableActivities = forceResizable; |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 773 | mSizeCompatFreeform = sizeCompatFreeform; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 774 | final boolean multiWindowFormEnabled = freeformWindowManagement |
| 775 | || supportsSplitScreenMultiWindow |
| 776 | || supportsPictureInPicture |
| 777 | || supportsMultiDisplay; |
| 778 | if ((supportsMultiWindow || forceResizable) && multiWindowFormEnabled) { |
| 779 | mSupportsMultiWindow = true; |
| 780 | mSupportsFreeformWindowManagement = freeformWindowManagement; |
| 781 | mSupportsSplitScreenMultiWindow = supportsSplitScreenMultiWindow; |
| 782 | mSupportsPictureInPicture = supportsPictureInPicture; |
| 783 | mSupportsMultiDisplay = supportsMultiDisplay; |
| 784 | } else { |
| 785 | mSupportsMultiWindow = false; |
| 786 | mSupportsFreeformWindowManagement = false; |
| 787 | mSupportsSplitScreenMultiWindow = false; |
| 788 | mSupportsPictureInPicture = false; |
| 789 | mSupportsMultiDisplay = false; |
| 790 | } |
Garfield Tan | b5910b4 | 2019-03-14 14:50:59 -0700 | [diff] [blame] | 791 | mWindowManager.mRoot.onSettingsRetrieved(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 792 | // This happens before any activities are started, so we can change global configuration |
| 793 | // in-place. |
| 794 | updateConfigurationLocked(configuration, null, true); |
| 795 | final Configuration globalConfig = getGlobalConfiguration(); |
| 796 | if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Initial config: " + globalConfig); |
| 797 | |
| 798 | // Load resources only after the current configuration has been set. |
| 799 | final Resources res = mContext.getResources(); |
| 800 | mThumbnailWidth = res.getDimensionPixelSize( |
| 801 | com.android.internal.R.dimen.thumbnail_width); |
| 802 | mThumbnailHeight = res.getDimensionPixelSize( |
| 803 | com.android.internal.R.dimen.thumbnail_height); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 807 | public WindowManagerGlobalLock getGlobalLock() { |
| 808 | return mGlobalLock; |
| 809 | } |
| 810 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 811 | /** For test purpose only. */ |
| 812 | @VisibleForTesting |
| 813 | public ActivityTaskManagerInternal getAtmInternal() { |
| 814 | return mInternal; |
| 815 | } |
| 816 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 817 | public void initialize(IntentFirewall intentFirewall, PendingIntentController intentController, |
| 818 | Looper looper) { |
| 819 | mH = new H(looper); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 820 | mUiHandler = new UiHandler(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 821 | mIntentFirewall = intentFirewall; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 822 | final File systemDir = SystemServiceManager.ensureSystemDir(); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 823 | mAppWarnings = createAppWarnings(mUiContext, mH, mUiHandler, systemDir); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 824 | mCompatModePackages = new CompatModePackages(this, systemDir, mH); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 825 | mPendingIntentController = intentController; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 826 | |
| 827 | mTempConfig.setToDefaults(); |
| 828 | mTempConfig.setLocales(LocaleList.getDefault()); |
| 829 | mConfigurationSeq = mTempConfig.seq = 1; |
| 830 | mStackSupervisor = createStackSupervisor(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 831 | mRootActivityContainer = new RootActivityContainer(this); |
| 832 | mRootActivityContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 833 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 834 | mTaskChangeNotificationController = |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 835 | new TaskChangeNotificationController(mGlobalLock, mStackSupervisor, mH); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 836 | mLockTaskController = new LockTaskController(mContext, mStackSupervisor, mH); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 837 | mActivityStartController = new ActivityStartController(this); |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 838 | setRecentTasks(new RecentTasks(this, mStackSupervisor)); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 839 | mVrController = new VrController(mGlobalLock); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 840 | mKeyguardController = mStackSupervisor.getKeyguardController(); |
| 841 | } |
| 842 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 843 | public void onActivityManagerInternalAdded() { |
| 844 | synchronized (mGlobalLock) { |
| 845 | mAmInternal = LocalServices.getService(ActivityManagerInternal.class); |
| 846 | mUgmInternal = LocalServices.getService(UriGrantsManagerInternal.class); |
| 847 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 848 | } |
| 849 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 850 | int increaseConfigurationSeqLocked() { |
| 851 | mConfigurationSeq = Math.max(++mConfigurationSeq, 1); |
| 852 | return mConfigurationSeq; |
| 853 | } |
| 854 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 855 | protected ActivityStackSupervisor createStackSupervisor() { |
| 856 | final ActivityStackSupervisor supervisor = new ActivityStackSupervisor(this, mH.getLooper()); |
| 857 | supervisor.initialize(); |
| 858 | return supervisor; |
| 859 | } |
| 860 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 861 | protected AppWarnings createAppWarnings( |
| 862 | Context uiContext, Handler handler, Handler uiHandler, File systemDir) { |
| 863 | return new AppWarnings(this, uiContext, handler, uiHandler, systemDir); |
| 864 | } |
| 865 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 866 | public void setWindowManager(WindowManagerService wm) { |
| 867 | synchronized (mGlobalLock) { |
| 868 | mWindowManager = wm; |
| 869 | mLockTaskController.setWindowManager(wm); |
| 870 | mStackSupervisor.setWindowManager(wm); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 871 | mRootActivityContainer.setWindowManager(wm); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 872 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 875 | public void setUsageStatsManager(UsageStatsManagerInternal usageStatsManager) { |
| 876 | synchronized (mGlobalLock) { |
| 877 | mUsageStatsInternal = usageStatsManager; |
| 878 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 881 | UserManagerService getUserManager() { |
| 882 | if (mUserManager == null) { |
| 883 | IBinder b = ServiceManager.getService(Context.USER_SERVICE); |
| 884 | mUserManager = (UserManagerService) IUserManager.Stub.asInterface(b); |
| 885 | } |
| 886 | return mUserManager; |
| 887 | } |
| 888 | |
| 889 | AppOpsService getAppOpsService() { |
| 890 | if (mAppOpsService == null) { |
| 891 | IBinder b = ServiceManager.getService(Context.APP_OPS_SERVICE); |
| 892 | mAppOpsService = (AppOpsService) IAppOpsService.Stub.asInterface(b); |
| 893 | } |
| 894 | return mAppOpsService; |
| 895 | } |
| 896 | |
| 897 | boolean hasUserRestriction(String restriction, int userId) { |
| 898 | return getUserManager().hasUserRestriction(restriction, userId); |
| 899 | } |
| 900 | |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 901 | boolean hasSystemAlertWindowPermission(int callingUid, int callingPid, String callingPackage) { |
| 902 | final int mode = getAppOpsService().noteOperation(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 903 | callingUid, callingPackage, /* featureId */ null); |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 904 | if (mode == AppOpsManager.MODE_DEFAULT) { |
| 905 | return checkPermission(Manifest.permission.SYSTEM_ALERT_WINDOW, callingPid, callingUid) |
| 906 | == PERMISSION_GRANTED; |
| 907 | } |
| 908 | return mode == AppOpsManager.MODE_ALLOWED; |
| 909 | } |
| 910 | |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 911 | @VisibleForTesting |
| 912 | protected void setRecentTasks(RecentTasks recentTasks) { |
| 913 | mRecentTasks = recentTasks; |
| 914 | mStackSupervisor.setRecentTasks(recentTasks); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | RecentTasks getRecentTasks() { |
| 918 | return mRecentTasks; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 921 | ClientLifecycleManager getLifecycleManager() { |
| 922 | return mLifecycleManager; |
| 923 | } |
| 924 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 925 | ActivityStartController getActivityStartController() { |
| 926 | return mActivityStartController; |
| 927 | } |
| 928 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 929 | TaskChangeNotificationController getTaskChangeNotificationController() { |
| 930 | return mTaskChangeNotificationController; |
| 931 | } |
| 932 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 933 | LockTaskController getLockTaskController() { |
| 934 | return mLockTaskController; |
| 935 | } |
| 936 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 937 | /** |
| 938 | * Return the global configuration used by the process corresponding to the input pid. This is |
| 939 | * usually the global configuration with some overrides specific to that process. |
| 940 | */ |
| 941 | Configuration getGlobalConfigurationForCallingPid() { |
| 942 | final int pid = Binder.getCallingPid(); |
Yunfan Chen | c2ff6cf | 2018-12-04 16:56:21 -0800 | [diff] [blame] | 943 | return getGlobalConfigurationForPid(pid); |
| 944 | } |
| 945 | |
| 946 | /** |
| 947 | * Return the global configuration used by the process corresponding to the given pid. |
| 948 | */ |
| 949 | Configuration getGlobalConfigurationForPid(int pid) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 950 | if (pid == MY_PID || pid < 0) { |
| 951 | return getGlobalConfiguration(); |
| 952 | } |
| 953 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 954 | final WindowProcessController app = mProcessMap.getProcess(pid); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 955 | return app != null ? app.getConfiguration() : getGlobalConfiguration(); |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | /** |
| 960 | * Return the device configuration info used by the process corresponding to the input pid. |
| 961 | * The value is consistent with the global configuration for the process. |
| 962 | */ |
| 963 | @Override |
| 964 | public ConfigurationInfo getDeviceConfigurationInfo() { |
| 965 | ConfigurationInfo config = new ConfigurationInfo(); |
| 966 | synchronized (mGlobalLock) { |
| 967 | final Configuration globalConfig = getGlobalConfigurationForCallingPid(); |
| 968 | config.reqTouchScreen = globalConfig.touchscreen; |
| 969 | config.reqKeyboardType = globalConfig.keyboard; |
| 970 | config.reqNavigation = globalConfig.navigation; |
| 971 | if (globalConfig.navigation == Configuration.NAVIGATION_DPAD |
| 972 | || globalConfig.navigation == Configuration.NAVIGATION_TRACKBALL) { |
| 973 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 974 | } |
| 975 | if (globalConfig.keyboard != Configuration.KEYBOARD_UNDEFINED |
| 976 | && globalConfig.keyboard != Configuration.KEYBOARD_NOKEYS) { |
| 977 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 978 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 979 | config.reqGlEsVersion = GL_ES_VERSION; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 980 | } |
| 981 | return config; |
| 982 | } |
| 983 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 984 | private void start() { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 985 | LocalServices.addService(ActivityTaskManagerInternal.class, mInternal); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 986 | } |
| 987 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 988 | public static final class Lifecycle extends SystemService { |
| 989 | private final ActivityTaskManagerService mService; |
| 990 | |
| 991 | public Lifecycle(Context context) { |
| 992 | super(context); |
| 993 | mService = new ActivityTaskManagerService(context); |
| 994 | } |
| 995 | |
| 996 | @Override |
| 997 | public void onStart() { |
| 998 | publishBinderService(Context.ACTIVITY_TASK_SERVICE, mService); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 999 | mService.start(); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 1002 | @Override |
| 1003 | public void onUnlockUser(int userId) { |
| 1004 | synchronized (mService.getGlobalLock()) { |
Garfield Tan | 0d407f4 | 2019-03-07 11:47:01 -0800 | [diff] [blame] | 1005 | mService.mStackSupervisor.onUserUnlocked(userId); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | @Override |
| 1010 | public void onCleanupUser(int userId) { |
| 1011 | synchronized (mService.getGlobalLock()) { |
| 1012 | mService.mStackSupervisor.mLaunchParamsPersister.onCleanupUser(userId); |
| 1013 | } |
| 1014 | } |
| 1015 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1016 | public ActivityTaskManagerService getService() { |
| 1017 | return mService; |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1022 | public final int startActivity(IApplicationThread caller, String callingPackage, |
| 1023 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1024 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions) { |
| 1025 | return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo, |
| 1026 | resultWho, requestCode, startFlags, profilerInfo, bOptions, |
| 1027 | UserHandle.getCallingUserId()); |
| 1028 | } |
| 1029 | |
| 1030 | @Override |
| 1031 | public final int startActivities(IApplicationThread caller, String callingPackage, |
| 1032 | Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle bOptions, |
| 1033 | int userId) { |
| 1034 | final String reason = "startActivities"; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1035 | enforceNotIsolatedCaller(reason); |
| 1036 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, reason); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1037 | // TODO: Switch to user app stacks here. |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 1038 | return getActivityStartController().startActivities(caller, -1, 0, -1, callingPackage, |
| 1039 | intents, resolvedTypes, resultTo, SafeActivityOptions.fromBundle(bOptions), userId, |
| 1040 | reason, null /* originatingPendingIntent */, |
| 1041 | false /* allowBackgroundActivityStart */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | @Override |
| 1045 | public int startActivityAsUser(IApplicationThread caller, String callingPackage, |
| 1046 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1047 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId) { |
| 1048 | return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo, |
| 1049 | resultWho, requestCode, startFlags, profilerInfo, bOptions, userId, |
| 1050 | true /*validateIncomingUser*/); |
| 1051 | } |
| 1052 | |
Andrii Kulian | a8ccae4 | 2019-07-24 18:35:22 +0000 | [diff] [blame] | 1053 | int startActivityAsUser(IApplicationThread caller, String callingPackage, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1054 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1055 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId, |
| 1056 | boolean validateIncomingUser) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1057 | enforceNotIsolatedCaller("startActivityAsUser"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1058 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1059 | userId = getActivityStartController().checkTargetUser(userId, validateIncomingUser, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1060 | Binder.getCallingPid(), Binder.getCallingUid(), "startActivityAsUser"); |
| 1061 | |
| 1062 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1063 | return getActivityStartController().obtainStarter(intent, "startActivityAsUser") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1064 | .setCaller(caller) |
| 1065 | .setCallingPackage(callingPackage) |
| 1066 | .setResolvedType(resolvedType) |
| 1067 | .setResultTo(resultTo) |
| 1068 | .setResultWho(resultWho) |
| 1069 | .setRequestCode(requestCode) |
| 1070 | .setStartFlags(startFlags) |
| 1071 | .setProfilerInfo(profilerInfo) |
| 1072 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1073 | .setUserId(userId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1074 | .execute(); |
| 1075 | |
| 1076 | } |
| 1077 | |
| 1078 | @Override |
| 1079 | public int startActivityIntentSender(IApplicationThread caller, IIntentSender target, |
| 1080 | IBinder whitelistToken, Intent fillInIntent, String resolvedType, IBinder resultTo, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1081 | String resultWho, int requestCode, int flagsMask, int flagsValues, Bundle bOptions) { |
| 1082 | enforceNotIsolatedCaller("startActivityIntentSender"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1083 | // Refuse possible leaked file descriptors |
| 1084 | if (fillInIntent != null && fillInIntent.hasFileDescriptors()) { |
| 1085 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1086 | } |
| 1087 | |
| 1088 | if (!(target instanceof PendingIntentRecord)) { |
| 1089 | throw new IllegalArgumentException("Bad PendingIntent object"); |
| 1090 | } |
| 1091 | |
| 1092 | PendingIntentRecord pir = (PendingIntentRecord)target; |
| 1093 | |
| 1094 | synchronized (mGlobalLock) { |
| 1095 | // If this is coming from the currently resumed activity, it is |
| 1096 | // effectively saying that app switches are allowed at this point. |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1097 | final ActivityStack stack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1098 | if (stack.mResumedActivity != null && |
| 1099 | stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1100 | mAppSwitchesAllowedTime = 0; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1101 | } |
| 1102 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1103 | return pir.sendInner(0, fillInIntent, resolvedType, whitelistToken, null, null, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1104 | resultTo, resultWho, requestCode, flagsMask, flagsValues, bOptions); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | @Override |
| 1108 | public boolean startNextMatchingActivity(IBinder callingActivity, Intent intent, |
| 1109 | Bundle bOptions) { |
| 1110 | // Refuse possible leaked file descriptors |
| 1111 | if (intent != null && intent.hasFileDescriptors()) { |
| 1112 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1113 | } |
| 1114 | SafeActivityOptions options = SafeActivityOptions.fromBundle(bOptions); |
| 1115 | |
| 1116 | synchronized (mGlobalLock) { |
| 1117 | final ActivityRecord r = ActivityRecord.isInStackLocked(callingActivity); |
| 1118 | if (r == null) { |
| 1119 | SafeActivityOptions.abort(options); |
| 1120 | return false; |
| 1121 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1122 | if (!r.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1123 | // The caller is not running... d'oh! |
| 1124 | SafeActivityOptions.abort(options); |
| 1125 | return false; |
| 1126 | } |
| 1127 | intent = new Intent(intent); |
| 1128 | // The caller is not allowed to change the data. |
| 1129 | intent.setDataAndType(r.intent.getData(), r.intent.getType()); |
| 1130 | // And we are resetting to find the next component... |
| 1131 | intent.setComponent(null); |
| 1132 | |
| 1133 | final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0); |
| 1134 | |
| 1135 | ActivityInfo aInfo = null; |
| 1136 | try { |
| 1137 | List<ResolveInfo> resolves = |
| 1138 | AppGlobals.getPackageManager().queryIntentActivities( |
| 1139 | intent, r.resolvedType, |
| 1140 | PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS, |
| 1141 | UserHandle.getCallingUserId()).getList(); |
| 1142 | |
| 1143 | // Look for the original activity in the list... |
| 1144 | final int N = resolves != null ? resolves.size() : 0; |
| 1145 | for (int i=0; i<N; i++) { |
| 1146 | ResolveInfo rInfo = resolves.get(i); |
| 1147 | if (rInfo.activityInfo.packageName.equals(r.packageName) |
| 1148 | && rInfo.activityInfo.name.equals(r.info.name)) { |
| 1149 | // We found the current one... the next matching is |
| 1150 | // after it. |
| 1151 | i++; |
| 1152 | if (i<N) { |
| 1153 | aInfo = resolves.get(i).activityInfo; |
| 1154 | } |
| 1155 | if (debug) { |
| 1156 | Slog.v(TAG, "Next matching activity: found current " + r.packageName |
| 1157 | + "/" + r.info.name); |
| 1158 | Slog.v(TAG, "Next matching activity: next is " + ((aInfo == null) |
| 1159 | ? "null" : aInfo.packageName + "/" + aInfo.name)); |
| 1160 | } |
| 1161 | break; |
| 1162 | } |
| 1163 | } |
| 1164 | } catch (RemoteException e) { |
| 1165 | } |
| 1166 | |
| 1167 | if (aInfo == null) { |
| 1168 | // Nobody who is next! |
| 1169 | SafeActivityOptions.abort(options); |
| 1170 | if (debug) Slog.d(TAG, "Next matching activity: nothing found"); |
| 1171 | return false; |
| 1172 | } |
| 1173 | |
| 1174 | intent.setComponent(new ComponentName( |
| 1175 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1176 | intent.setFlags(intent.getFlags()&~( |
| 1177 | Intent.FLAG_ACTIVITY_FORWARD_RESULT| |
| 1178 | Intent.FLAG_ACTIVITY_CLEAR_TOP| |
| 1179 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK| |
| 1180 | FLAG_ACTIVITY_NEW_TASK)); |
| 1181 | |
| 1182 | // Okay now we need to start the new activity, replacing the currently running activity. |
| 1183 | // This is a little tricky because we want to start the new one as if the current one is |
| 1184 | // finished, but not finish the current one first so that there is no flicker. |
| 1185 | // And thus... |
| 1186 | final boolean wasFinishing = r.finishing; |
| 1187 | r.finishing = true; |
| 1188 | |
| 1189 | // Propagate reply information over to the new activity. |
| 1190 | final ActivityRecord resultTo = r.resultTo; |
| 1191 | final String resultWho = r.resultWho; |
| 1192 | final int requestCode = r.requestCode; |
| 1193 | r.resultTo = null; |
| 1194 | if (resultTo != null) { |
| 1195 | resultTo.removeResultsLocked(r, resultWho, requestCode); |
| 1196 | } |
| 1197 | |
| 1198 | final long origId = Binder.clearCallingIdentity(); |
| 1199 | // TODO(b/64750076): Check if calling pid should really be -1. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1200 | final int res = getActivityStartController() |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1201 | .obtainStarter(intent, "startNextMatchingActivity") |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1202 | .setCaller(r.app.getThread()) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1203 | .setResolvedType(r.resolvedType) |
| 1204 | .setActivityInfo(aInfo) |
| 1205 | .setResultTo(resultTo != null ? resultTo.appToken : null) |
| 1206 | .setResultWho(resultWho) |
| 1207 | .setRequestCode(requestCode) |
| 1208 | .setCallingPid(-1) |
| 1209 | .setCallingUid(r.launchedFromUid) |
| 1210 | .setCallingPackage(r.launchedFromPackage) |
| 1211 | .setRealCallingPid(-1) |
| 1212 | .setRealCallingUid(r.launchedFromUid) |
| 1213 | .setActivityOptions(options) |
| 1214 | .execute(); |
| 1215 | Binder.restoreCallingIdentity(origId); |
| 1216 | |
| 1217 | r.finishing = wasFinishing; |
| 1218 | if (res != ActivityManager.START_SUCCESS) { |
| 1219 | return false; |
| 1220 | } |
| 1221 | return true; |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | @Override |
| 1226 | public final WaitResult startActivityAndWait(IApplicationThread caller, String callingPackage, |
| 1227 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1228 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId) { |
| 1229 | final WaitResult res = new WaitResult(); |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1230 | enforceNotIsolatedCaller("startActivityAndWait"); |
| 1231 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 1232 | userId, "startActivityAndWait"); |
| 1233 | // TODO: Switch to user app stacks here. |
| 1234 | getActivityStartController().obtainStarter(intent, "startActivityAndWait") |
| 1235 | .setCaller(caller) |
| 1236 | .setCallingPackage(callingPackage) |
| 1237 | .setResolvedType(resolvedType) |
| 1238 | .setResultTo(resultTo) |
| 1239 | .setResultWho(resultWho) |
| 1240 | .setRequestCode(requestCode) |
| 1241 | .setStartFlags(startFlags) |
| 1242 | .setActivityOptions(bOptions) |
| 1243 | .setUserId(userId) |
| 1244 | .setProfilerInfo(profilerInfo) |
| 1245 | .setWaitResult(res) |
| 1246 | .execute(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1247 | return res; |
| 1248 | } |
| 1249 | |
| 1250 | @Override |
| 1251 | public final int startActivityWithConfig(IApplicationThread caller, String callingPackage, |
| 1252 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1253 | int startFlags, Configuration config, Bundle bOptions, int userId) { |
Riddle Hsu | fd66d4d | 2019-11-14 10:35:55 +0800 | [diff] [blame] | 1254 | enforceNotIsolatedCaller("startActivityWithConfig"); |
| 1255 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, |
| 1256 | "startActivityWithConfig"); |
| 1257 | // TODO: Switch to user app stacks here. |
| 1258 | return getActivityStartController().obtainStarter(intent, "startActivityWithConfig") |
| 1259 | .setCaller(caller) |
| 1260 | .setCallingPackage(callingPackage) |
| 1261 | .setResolvedType(resolvedType) |
| 1262 | .setResultTo(resultTo) |
| 1263 | .setResultWho(resultWho) |
| 1264 | .setRequestCode(requestCode) |
| 1265 | .setStartFlags(startFlags) |
| 1266 | .setGlobalConfiguration(config) |
| 1267 | .setActivityOptions(bOptions) |
| 1268 | .setUserId(userId) |
| 1269 | .execute(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1270 | } |
| 1271 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1272 | |
| 1273 | @Override |
| 1274 | public IBinder requestStartActivityPermissionToken(IBinder delegatorToken) { |
| 1275 | int callingUid = Binder.getCallingUid(); |
| 1276 | if (UserHandle.getAppId(callingUid) != SYSTEM_UID) { |
| 1277 | throw new SecurityException("Only the system process can request a permission token, " |
| 1278 | + "received request from uid: " + callingUid); |
| 1279 | } |
| 1280 | IBinder permissionToken = new Binder(); |
| 1281 | synchronized (mGlobalLock) { |
| 1282 | mStartActivitySources.put(permissionToken, delegatorToken); |
| 1283 | } |
| 1284 | |
| 1285 | Message expireMsg = PooledLambda.obtainMessage( |
| 1286 | ActivityTaskManagerService::expireStartAsCallerTokenMsg, this, permissionToken); |
| 1287 | mUiHandler.sendMessageDelayed(expireMsg, START_AS_CALLER_TOKEN_TIMEOUT_IMPL); |
| 1288 | |
| 1289 | Message forgetMsg = PooledLambda.obtainMessage( |
| 1290 | ActivityTaskManagerService::forgetStartAsCallerTokenMsg, this, permissionToken); |
| 1291 | mUiHandler.sendMessageDelayed(forgetMsg, START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT); |
| 1292 | |
| 1293 | return permissionToken; |
| 1294 | } |
| 1295 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1296 | @Override |
| 1297 | public final int startActivityAsCaller(IApplicationThread caller, String callingPackage, |
| 1298 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1299 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, IBinder permissionToken, |
| 1300 | boolean ignoreTargetSecurity, int userId) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1301 | // 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] | 1302 | // permission grants) as any app that may launch one of your own activities. So we only |
| 1303 | // allow this in two cases: |
| 1304 | // 1) The caller is an activity that is part of the core framework, and then only when it |
| 1305 | // is running as the system. |
| 1306 | // 2) The caller provides a valid permissionToken. Permission tokens are one-time use and |
| 1307 | // can only be requested by a system activity, which may then delegate this call to |
| 1308 | // another app. |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1309 | final ActivityRecord sourceRecord; |
| 1310 | final int targetUid; |
| 1311 | final String targetPackage; |
| 1312 | final boolean isResolver; |
| 1313 | synchronized (mGlobalLock) { |
| 1314 | if (resultTo == null) { |
| 1315 | throw new SecurityException("Must be called from an activity"); |
| 1316 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1317 | final IBinder sourceToken; |
| 1318 | if (permissionToken != null) { |
| 1319 | // To even attempt to use a permissionToken, an app must also have this signature |
| 1320 | // permission. |
| 1321 | mAmInternal.enforceCallingPermission( |
| 1322 | android.Manifest.permission.START_ACTIVITY_AS_CALLER, |
| 1323 | "startActivityAsCaller"); |
| 1324 | // If called with a permissionToken, we want the sourceRecord from the delegator |
| 1325 | // activity that requested this token. |
| 1326 | sourceToken = mStartActivitySources.remove(permissionToken); |
| 1327 | if (sourceToken == null) { |
| 1328 | // Invalid permissionToken, check if it recently expired. |
| 1329 | if (mExpiredStartAsCallerTokens.contains(permissionToken)) { |
| 1330 | throw new SecurityException("Called with expired permission token: " |
| 1331 | + permissionToken); |
| 1332 | } else { |
| 1333 | throw new SecurityException("Called with invalid permission token: " |
| 1334 | + permissionToken); |
| 1335 | } |
| 1336 | } |
| 1337 | } else { |
| 1338 | // This method was called directly by the source. |
| 1339 | sourceToken = resultTo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1340 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1341 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1342 | sourceRecord = mRootActivityContainer.isInAnyStack(sourceToken); |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1343 | if (sourceRecord == null) { |
| 1344 | throw new SecurityException("Called with bad activity token: " + sourceToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1345 | } |
| 1346 | if (sourceRecord.app == null) { |
| 1347 | throw new SecurityException("Called without a process attached to activity"); |
| 1348 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1349 | |
| 1350 | // Whether called directly or from a delegate, the source activity must be from the |
| 1351 | // android package. |
| 1352 | if (!sourceRecord.info.packageName.equals("android")) { |
| 1353 | throw new SecurityException("Must be called from an activity that is " |
| 1354 | + "declared in the android package"); |
| 1355 | } |
| 1356 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1357 | if (UserHandle.getAppId(sourceRecord.app.mUid) != SYSTEM_UID) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1358 | // This is still okay, as long as this activity is running under the |
| 1359 | // uid of the original calling activity. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1360 | if (sourceRecord.app.mUid != sourceRecord.launchedFromUid) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1361 | throw new SecurityException( |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1362 | "Calling activity in uid " + sourceRecord.app.mUid |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1363 | + " must be system uid or original calling uid " |
| 1364 | + sourceRecord.launchedFromUid); |
| 1365 | } |
| 1366 | } |
| 1367 | if (ignoreTargetSecurity) { |
| 1368 | if (intent.getComponent() == null) { |
| 1369 | throw new SecurityException( |
| 1370 | "Component must be specified with ignoreTargetSecurity"); |
| 1371 | } |
| 1372 | if (intent.getSelector() != null) { |
| 1373 | throw new SecurityException( |
| 1374 | "Selector not allowed with ignoreTargetSecurity"); |
| 1375 | } |
| 1376 | } |
| 1377 | targetUid = sourceRecord.launchedFromUid; |
| 1378 | targetPackage = sourceRecord.launchedFromPackage; |
| 1379 | isResolver = sourceRecord.isResolverOrChildActivity(); |
| 1380 | } |
| 1381 | |
| 1382 | if (userId == UserHandle.USER_NULL) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1383 | userId = UserHandle.getUserId(sourceRecord.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | // TODO: Switch to user app stacks here. |
| 1387 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1388 | return getActivityStartController().obtainStarter(intent, "startActivityAsCaller") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1389 | .setCallingUid(targetUid) |
| 1390 | .setCallingPackage(targetPackage) |
| 1391 | .setResolvedType(resolvedType) |
| 1392 | .setResultTo(resultTo) |
| 1393 | .setResultWho(resultWho) |
| 1394 | .setRequestCode(requestCode) |
| 1395 | .setStartFlags(startFlags) |
| 1396 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1397 | .setUserId(userId) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1398 | .setIgnoreTargetSecurity(ignoreTargetSecurity) |
| 1399 | .setFilterCallingUid(isResolver ? 0 /* system */ : targetUid) |
Alan Stokes | 2f4a4ed | 2019-05-08 16:56:45 +0100 | [diff] [blame] | 1400 | // The target may well be in the background, which would normally prevent it |
| 1401 | // from starting an activity. Here we definitely want the start to succeed. |
| 1402 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1403 | .execute(); |
| 1404 | } catch (SecurityException e) { |
| 1405 | // XXX need to figure out how to propagate to original app. |
| 1406 | // A SecurityException here is generally actually a fault of the original |
| 1407 | // calling activity (such as a fairly granting permissions), so propagate it |
| 1408 | // back to them. |
| 1409 | /* |
| 1410 | StringBuilder msg = new StringBuilder(); |
| 1411 | msg.append("While launching"); |
| 1412 | msg.append(intent.toString()); |
| 1413 | msg.append(": "); |
| 1414 | msg.append(e.getMessage()); |
| 1415 | */ |
| 1416 | throw e; |
| 1417 | } |
| 1418 | } |
| 1419 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1420 | int handleIncomingUser(int callingPid, int callingUid, int userId, String name) { |
| 1421 | return mAmInternal.handleIncomingUser(callingPid, callingUid, userId, false /* allowAll */, |
| 1422 | ALLOW_FULL_ONLY, name, null /* callerPackage */); |
| 1423 | } |
| 1424 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1425 | @Override |
| 1426 | public int startVoiceActivity(String callingPackage, int callingPid, int callingUid, |
| 1427 | Intent intent, String resolvedType, IVoiceInteractionSession session, |
| 1428 | IVoiceInteractor interactor, int startFlags, ProfilerInfo profilerInfo, |
| 1429 | Bundle bOptions, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1430 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startVoiceActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1431 | if (session == null || interactor == null) { |
| 1432 | throw new NullPointerException("null session or interactor"); |
| 1433 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1434 | userId = handleIncomingUser(callingPid, callingUid, userId, "startVoiceActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1435 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1436 | return getActivityStartController().obtainStarter(intent, "startVoiceActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1437 | .setCallingUid(callingUid) |
| 1438 | .setCallingPackage(callingPackage) |
| 1439 | .setResolvedType(resolvedType) |
| 1440 | .setVoiceSession(session) |
| 1441 | .setVoiceInteractor(interactor) |
| 1442 | .setStartFlags(startFlags) |
| 1443 | .setProfilerInfo(profilerInfo) |
| 1444 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1445 | .setUserId(userId) |
Michal Karpinski | 85fa202 | 2019-02-08 12:05:09 +0000 | [diff] [blame] | 1446 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1447 | .execute(); |
| 1448 | } |
| 1449 | |
| 1450 | @Override |
| 1451 | public int startAssistantActivity(String callingPackage, int callingPid, int callingUid, |
| 1452 | Intent intent, String resolvedType, Bundle bOptions, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1453 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startAssistantActivity()"); |
| 1454 | userId = handleIncomingUser(callingPid, callingUid, userId, "startAssistantActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1455 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1456 | return getActivityStartController().obtainStarter(intent, "startAssistantActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1457 | .setCallingUid(callingUid) |
| 1458 | .setCallingPackage(callingPackage) |
| 1459 | .setResolvedType(resolvedType) |
| 1460 | .setActivityOptions(bOptions) |
Louis Chang | 54fbb05 | 2019-10-16 17:10:17 +0800 | [diff] [blame] | 1461 | .setUserId(userId) |
Michal Karpinski | 85fa202 | 2019-02-08 12:05:09 +0000 | [diff] [blame] | 1462 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1463 | .execute(); |
| 1464 | } |
| 1465 | |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1466 | /** |
| 1467 | * Start the recents activity to perform the recents animation. |
| 1468 | * |
| 1469 | * @param intent The intent to start the recents activity. |
| 1470 | * @param recentsAnimationRunner Pass {@code null} to only preload the activity. |
| 1471 | */ |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1472 | @Override |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1473 | public void startRecentsActivity(Intent intent, @Deprecated IAssistDataReceiver unused, |
| 1474 | @Nullable IRecentsAnimationRunner recentsAnimationRunner) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1475 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "startRecentsActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1476 | final int callingPid = Binder.getCallingPid(); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1477 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1478 | final long origId = Binder.clearCallingIdentity(); |
| 1479 | try { |
| 1480 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 1481 | final ComponentName recentsComponent = mRecentTasks.getRecentsComponent(); |
| 1482 | final int recentsUid = mRecentTasks.getRecentsComponentUid(); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1483 | final WindowProcessController caller = getProcessController(callingPid, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1484 | |
| 1485 | // Start a new recents animation |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1486 | final RecentsAnimation anim = new RecentsAnimation(this, mStackSupervisor, |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1487 | getActivityStartController(), mWindowManager, intent, recentsComponent, |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1488 | recentsUid, caller); |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1489 | if (recentsAnimationRunner == null) { |
| 1490 | anim.preloadRecentsActivity(); |
| 1491 | } else { |
| 1492 | anim.startRecentsActivity(recentsAnimationRunner); |
| 1493 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1494 | } |
| 1495 | } finally { |
| 1496 | Binder.restoreCallingIdentity(origId); |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | @Override |
| 1501 | public final int startActivityFromRecents(int taskId, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1502 | enforceCallerIsRecentsOrHasPermission(START_TASKS_FROM_RECENTS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1503 | "startActivityFromRecents()"); |
| 1504 | |
| 1505 | final int callingPid = Binder.getCallingPid(); |
| 1506 | final int callingUid = Binder.getCallingUid(); |
| 1507 | final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(bOptions); |
| 1508 | final long origId = Binder.clearCallingIdentity(); |
| 1509 | try { |
| 1510 | synchronized (mGlobalLock) { |
| 1511 | return mStackSupervisor.startActivityFromRecents(callingPid, callingUid, taskId, |
| 1512 | safeOptions); |
| 1513 | } |
| 1514 | } finally { |
| 1515 | Binder.restoreCallingIdentity(origId); |
| 1516 | } |
| 1517 | } |
| 1518 | |
| 1519 | /** |
Andrii Kulian | 2eb84b2 | 2018-12-13 18:18:54 -0800 | [diff] [blame] | 1520 | * Public API to check if the client is allowed to start an activity on specified display. |
| 1521 | * |
| 1522 | * If the target display is private or virtual, some restrictions will apply. |
| 1523 | * |
| 1524 | * @param displayId Target display id. |
| 1525 | * @param intent Intent used to launch the activity. |
| 1526 | * @param resolvedType The MIME type of the intent. |
| 1527 | * @param userId The id of the user for whom the call is made. |
| 1528 | * @return {@code true} if a call to start an activity on the target display should succeed and |
| 1529 | * no {@link SecurityException} will be thrown, {@code false} otherwise. |
| 1530 | */ |
| 1531 | @Override |
| 1532 | public final boolean isActivityStartAllowedOnDisplay(int displayId, Intent intent, |
| 1533 | String resolvedType, int userId) { |
| 1534 | final int callingUid = Binder.getCallingUid(); |
| 1535 | final int callingPid = Binder.getCallingPid(); |
| 1536 | final long origId = Binder.clearCallingIdentity(); |
| 1537 | |
| 1538 | try { |
| 1539 | // Collect information about the target of the Intent. |
| 1540 | ActivityInfo aInfo = mStackSupervisor.resolveActivity(intent, resolvedType, |
| 1541 | 0 /* startFlags */, null /* profilerInfo */, userId, |
| 1542 | ActivityStarter.computeResolveFilterUid(callingUid, callingUid, |
| 1543 | UserHandle.USER_NULL)); |
| 1544 | aInfo = mAmInternal.getActivityInfoForUser(aInfo, userId); |
| 1545 | |
| 1546 | synchronized (mGlobalLock) { |
| 1547 | return mStackSupervisor.canPlaceEntityOnDisplay(displayId, callingPid, callingUid, |
| 1548 | aInfo); |
| 1549 | } |
| 1550 | } finally { |
| 1551 | Binder.restoreCallingIdentity(origId); |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | /** |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1556 | * This is the internal entry point for handling Activity.finish(). |
| 1557 | * |
| 1558 | * @param token The Binder token referencing the Activity we want to finish. |
| 1559 | * @param resultCode Result code, if any, from this Activity. |
| 1560 | * @param resultData Result data (Intent), if any, from this Activity. |
| 1561 | * @param finishTask Whether to finish the task associated with this Activity. |
| 1562 | * |
| 1563 | * @return Returns true if the activity successfully finished, or false if it is still running. |
| 1564 | */ |
| 1565 | @Override |
| 1566 | public final boolean finishActivity(IBinder token, int resultCode, Intent resultData, |
| 1567 | int finishTask) { |
| 1568 | // Refuse possible leaked file descriptors |
| 1569 | if (resultData != null && resultData.hasFileDescriptors()) { |
| 1570 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1571 | } |
| 1572 | |
| 1573 | synchronized (mGlobalLock) { |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 1574 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1575 | if (r == null) { |
| 1576 | return true; |
| 1577 | } |
| 1578 | // 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] | 1579 | final Task tr = r.getTask(); |
Andrii Kulian | 057a651 | 2019-07-15 16:15:51 -0700 | [diff] [blame] | 1580 | final ActivityRecord rootR = tr.getRootActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1581 | if (rootR == null) { |
| 1582 | Slog.w(TAG, "Finishing task with all activities already finished"); |
| 1583 | } |
| 1584 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps can |
| 1585 | // finish. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1586 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1587 | return false; |
| 1588 | } |
| 1589 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1590 | // TODO: There is a dup. of this block of code in ActivityStack.navigateUpToLocked |
| 1591 | // We should consolidate. |
| 1592 | if (mController != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1593 | // Find the first activity that is not finishing. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1594 | final ActivityRecord next = |
| 1595 | r.getActivityStack().topRunningActivity(token, INVALID_TASK_ID); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1596 | if (next != null) { |
| 1597 | // ask watcher if this is allowed |
| 1598 | boolean resumeOK = true; |
| 1599 | try { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1600 | resumeOK = mController.activityResuming(next.packageName); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1601 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1602 | mController = null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1603 | Watchdog.getInstance().setActivityController(null); |
| 1604 | } |
| 1605 | |
| 1606 | if (!resumeOK) { |
| 1607 | Slog.i(TAG, "Not finishing activity because controller resumed"); |
| 1608 | return false; |
| 1609 | } |
| 1610 | } |
| 1611 | } |
Michal Karpinski | fc6872e | 2019-05-21 15:18:44 +0100 | [diff] [blame] | 1612 | |
| 1613 | // note down that the process has finished an activity and is in background activity |
| 1614 | // starts grace period |
| 1615 | if (r.app != null) { |
| 1616 | r.app.setLastActivityFinishTimeIfNeeded(SystemClock.uptimeMillis()); |
| 1617 | } |
| 1618 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1619 | final long origId = Binder.clearCallingIdentity(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1620 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "finishActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1621 | try { |
| 1622 | boolean res; |
| 1623 | final boolean finishWithRootActivity = |
| 1624 | finishTask == Activity.FINISH_TASK_WITH_ROOT_ACTIVITY; |
| 1625 | if (finishTask == Activity.FINISH_TASK_WITH_ACTIVITY |
| 1626 | || (finishWithRootActivity && r == rootR)) { |
| 1627 | // If requested, remove the task that is associated to this activity only if it |
| 1628 | // was the root activity in the task. The result code and data is ignored |
| 1629 | // because we don't support returning them across task boundaries. Also, to |
| 1630 | // keep backwards compatibility we remove the task from recents when finishing |
| 1631 | // task with root activity. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1632 | mStackSupervisor.removeTask(tr, false /*killProcess*/, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1633 | finishWithRootActivity, "finish-activity"); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1634 | res = true; |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 1635 | // Explicitly dismissing the activity so reset its relaunch flag. |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 1636 | r.mRelaunchReason = RELAUNCH_REASON_NONE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1637 | } else { |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 1638 | r.finishIfPossible(resultCode, resultData, "app-request", true /* oomAdj */); |
Andrii Kulian | 40eda67 | 2019-07-30 15:05:57 -0700 | [diff] [blame] | 1639 | res = r.finishing; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1640 | if (!res) { |
| 1641 | Slog.i(TAG, "Failed to finish by app-request"); |
| 1642 | } |
| 1643 | } |
| 1644 | return res; |
| 1645 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1646 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1647 | Binder.restoreCallingIdentity(origId); |
| 1648 | } |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | @Override |
| 1653 | public boolean finishActivityAffinity(IBinder token) { |
| 1654 | synchronized (mGlobalLock) { |
| 1655 | final long origId = Binder.clearCallingIdentity(); |
| 1656 | try { |
| 1657 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1658 | if (r == null) { |
| 1659 | return false; |
| 1660 | } |
| 1661 | |
| 1662 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps |
| 1663 | // can finish. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1664 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1665 | return false; |
| 1666 | } |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1667 | |
| 1668 | final PooledFunction p = PooledLambda.obtainFunction( |
| 1669 | ActivityRecord::finishIfSameAffinity, r, |
| 1670 | PooledLambda.__(ActivityRecord.class)); |
| 1671 | r.getTask().forAllActivities( |
| 1672 | p, r, true /*includeBoundary*/, true /*traverseTopToBottom*/); |
| 1673 | p.recycle(); |
| 1674 | |
Andrii Kulian | de93eff | 2019-07-12 12:21:27 -0700 | [diff] [blame] | 1675 | return true; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1676 | } finally { |
| 1677 | Binder.restoreCallingIdentity(origId); |
| 1678 | } |
| 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | @Override |
| 1683 | public final void activityIdle(IBinder token, Configuration config, boolean stopProfiling) { |
| 1684 | final long origId = Binder.clearCallingIdentity(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1685 | try { |
| 1686 | WindowProcessController proc = null; |
| 1687 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1688 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityIdle"); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1689 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 1690 | if (stack == null) { |
| 1691 | return; |
| 1692 | } |
| 1693 | final ActivityRecord r = mStackSupervisor.activityIdleInternalLocked(token, |
| 1694 | false /* fromTimeout */, false /* processPausingActivities */, config); |
| 1695 | if (r != null) { |
| 1696 | proc = r.app; |
| 1697 | } |
| 1698 | if (stopProfiling && proc != null) { |
| 1699 | proc.clearProfilerIfNeeded(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1700 | } |
| 1701 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1702 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1703 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1704 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1705 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | @Override |
| 1709 | public final void activityResumed(IBinder token) { |
| 1710 | final long origId = Binder.clearCallingIdentity(); |
| 1711 | synchronized (mGlobalLock) { |
| 1712 | ActivityRecord.activityResumedLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1713 | } |
| 1714 | Binder.restoreCallingIdentity(origId); |
| 1715 | } |
| 1716 | |
| 1717 | @Override |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 1718 | public final void activityTopResumedStateLost() { |
| 1719 | final long origId = Binder.clearCallingIdentity(); |
| 1720 | synchronized (mGlobalLock) { |
| 1721 | mStackSupervisor.handleTopResumedStateReleased(false /* timeout */); |
| 1722 | } |
| 1723 | Binder.restoreCallingIdentity(origId); |
| 1724 | } |
| 1725 | |
| 1726 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1727 | public final void activityPaused(IBinder token) { |
| 1728 | final long origId = Binder.clearCallingIdentity(); |
| 1729 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1730 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityPaused"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1731 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 1732 | if (stack != null) { |
| 1733 | stack.activityPausedLocked(token, false); |
| 1734 | } |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1735 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1736 | } |
| 1737 | Binder.restoreCallingIdentity(origId); |
| 1738 | } |
| 1739 | |
| 1740 | @Override |
| 1741 | public final void activityStopped(IBinder token, Bundle icicle, |
| 1742 | PersistableBundle persistentState, CharSequence description) { |
| 1743 | if (DEBUG_ALL) Slog.v(TAG, "Activity stopped: token=" + token); |
| 1744 | |
| 1745 | // Refuse possible leaked file descriptors |
| 1746 | if (icicle != null && icicle.hasFileDescriptors()) { |
| 1747 | throw new IllegalArgumentException("File descriptors passed in Bundle"); |
| 1748 | } |
| 1749 | |
| 1750 | final long origId = Binder.clearCallingIdentity(); |
| 1751 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1752 | String restartingName = null; |
| 1753 | int restartingUid = 0; |
| 1754 | final ActivityRecord r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1755 | synchronized (mGlobalLock) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1756 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityStopped"); |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1757 | r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1758 | if (r != null) { |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1759 | if (r.attachedToProcess() |
| 1760 | && r.isState(ActivityStack.ActivityState.RESTARTING_PROCESS)) { |
| 1761 | // The activity was requested to restart from |
| 1762 | // {@link #restartActivityProcessIfVisible}. |
| 1763 | restartingName = r.app.mName; |
| 1764 | restartingUid = r.app.mUid; |
| 1765 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1766 | r.activityStoppedLocked(icicle, persistentState, description); |
| 1767 | } |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1768 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1771 | if (restartingName != null) { |
| 1772 | // In order to let the foreground activity can be restarted with its saved state from |
| 1773 | // {@link android.app.Activity#onSaveInstanceState}, the kill operation is postponed |
| 1774 | // until the activity reports stopped with the state. And the activity record will be |
| 1775 | // kept because the record state is restarting, then the activity will be restarted |
| 1776 | // immediately if it is still the top one. |
| 1777 | mStackSupervisor.removeRestartTimeouts(r); |
| 1778 | mAmInternal.killProcess(restartingName, restartingUid, "restartActivityProcess"); |
| 1779 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1780 | mAmInternal.trimApplications(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1781 | |
| 1782 | Binder.restoreCallingIdentity(origId); |
| 1783 | } |
| 1784 | |
| 1785 | @Override |
| 1786 | public final void activityDestroyed(IBinder token) { |
| 1787 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "ACTIVITY DESTROYED: " + token); |
| 1788 | synchronized (mGlobalLock) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1789 | final long origId = Binder.clearCallingIdentity(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1790 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "activityDestroyed"); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1791 | try { |
| 1792 | final ActivityRecord activity = ActivityRecord.forTokenLocked(token); |
| 1793 | if (activity != null) { |
| 1794 | activity.destroyed("activityDestroyed"); |
| 1795 | } |
| 1796 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1797 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1798 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1799 | } |
| 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | @Override |
| 1804 | public final void activityRelaunched(IBinder token) { |
| 1805 | final long origId = Binder.clearCallingIdentity(); |
| 1806 | synchronized (mGlobalLock) { |
| 1807 | mStackSupervisor.activityRelaunchedLocked(token); |
| 1808 | } |
| 1809 | Binder.restoreCallingIdentity(origId); |
| 1810 | } |
| 1811 | |
| 1812 | public final void activitySlept(IBinder token) { |
| 1813 | if (DEBUG_ALL) Slog.v(TAG, "Activity slept: token=" + token); |
| 1814 | |
| 1815 | final long origId = Binder.clearCallingIdentity(); |
| 1816 | |
| 1817 | synchronized (mGlobalLock) { |
| 1818 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1819 | if (r != null) { |
| 1820 | mStackSupervisor.activitySleptLocked(r); |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | Binder.restoreCallingIdentity(origId); |
| 1825 | } |
| 1826 | |
| 1827 | @Override |
| 1828 | public void setRequestedOrientation(IBinder token, int requestedOrientation) { |
| 1829 | synchronized (mGlobalLock) { |
| 1830 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1831 | if (r == null) { |
| 1832 | return; |
| 1833 | } |
| 1834 | final long origId = Binder.clearCallingIdentity(); |
| 1835 | try { |
| 1836 | r.setRequestedOrientation(requestedOrientation); |
| 1837 | } finally { |
| 1838 | Binder.restoreCallingIdentity(origId); |
| 1839 | } |
| 1840 | } |
| 1841 | } |
| 1842 | |
| 1843 | @Override |
| 1844 | public int getRequestedOrientation(IBinder token) { |
| 1845 | synchronized (mGlobalLock) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1846 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1847 | return (r != null) |
| 1848 | ? r.getRequestedOrientation() : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1849 | } |
| 1850 | } |
| 1851 | |
| 1852 | @Override |
| 1853 | public void setImmersive(IBinder token, boolean immersive) { |
| 1854 | synchronized (mGlobalLock) { |
| 1855 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1856 | if (r == null) { |
| 1857 | throw new IllegalArgumentException(); |
| 1858 | } |
| 1859 | r.immersive = immersive; |
| 1860 | |
| 1861 | // update associated state if we're frontmost |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1862 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1863 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, "Frontmost changed immersion: "+ r); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1864 | applyUpdateLockStateLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1865 | } |
| 1866 | } |
| 1867 | } |
| 1868 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1869 | void applyUpdateLockStateLocked(ActivityRecord r) { |
| 1870 | // Modifications to the UpdateLock state are done on our handler, outside |
| 1871 | // the activity manager's locks. The new state is determined based on the |
| 1872 | // state *now* of the relevant activity record. The object is passed to |
| 1873 | // the handler solely for logging detail, not to be consulted/modified. |
| 1874 | final boolean nextState = r != null && r.immersive; |
| 1875 | mH.post(() -> { |
| 1876 | if (mUpdateLock.isHeld() != nextState) { |
| 1877 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, |
| 1878 | "Applying new update lock state '" + nextState + "' for " + r); |
| 1879 | if (nextState) { |
| 1880 | mUpdateLock.acquire(); |
| 1881 | } else { |
| 1882 | mUpdateLock.release(); |
| 1883 | } |
| 1884 | } |
| 1885 | }); |
| 1886 | } |
| 1887 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1888 | @Override |
| 1889 | public boolean isImmersive(IBinder token) { |
| 1890 | synchronized (mGlobalLock) { |
| 1891 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1892 | if (r == null) { |
| 1893 | throw new IllegalArgumentException(); |
| 1894 | } |
| 1895 | return r.immersive; |
| 1896 | } |
| 1897 | } |
| 1898 | |
| 1899 | @Override |
| 1900 | public boolean isTopActivityImmersive() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1901 | enforceNotIsolatedCaller("isTopActivityImmersive"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1902 | synchronized (mGlobalLock) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1903 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1904 | return (r != null) ? r.immersive : false; |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | @Override |
| 1909 | public void overridePendingTransition(IBinder token, String packageName, |
| 1910 | int enterAnim, int exitAnim) { |
| 1911 | synchronized (mGlobalLock) { |
| 1912 | ActivityRecord self = ActivityRecord.isInStackLocked(token); |
| 1913 | if (self == null) { |
| 1914 | return; |
| 1915 | } |
| 1916 | |
| 1917 | final long origId = Binder.clearCallingIdentity(); |
| 1918 | |
| 1919 | if (self.isState( |
| 1920 | ActivityStack.ActivityState.RESUMED, ActivityStack.ActivityState.PAUSING)) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1921 | self.getDisplay().mDisplayContent.mAppTransition.overridePendingAppTransition( |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1922 | packageName, enterAnim, exitAnim, null); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | Binder.restoreCallingIdentity(origId); |
| 1926 | } |
| 1927 | } |
| 1928 | |
| 1929 | @Override |
| 1930 | public int getFrontActivityScreenCompatMode() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1931 | enforceNotIsolatedCaller("getFrontActivityScreenCompatMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1932 | synchronized (mGlobalLock) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1933 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivity(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1934 | if (r == null) { |
| 1935 | return ActivityManager.COMPAT_MODE_UNKNOWN; |
| 1936 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1937 | return mCompatModePackages.computeCompatModeLocked(r.info.applicationInfo); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1938 | } |
| 1939 | } |
| 1940 | |
| 1941 | @Override |
| 1942 | public void setFrontActivityScreenCompatMode(int mode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1943 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1944 | "setFrontActivityScreenCompatMode"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1945 | ApplicationInfo ai; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1946 | synchronized (mGlobalLock) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1947 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivity(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1948 | if (r == null) { |
| 1949 | Slog.w(TAG, "setFrontActivityScreenCompatMode failed: no top activity"); |
| 1950 | return; |
| 1951 | } |
| 1952 | ai = r.info.applicationInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1953 | mCompatModePackages.setPackageScreenCompatModeLocked(ai, mode); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1954 | } |
| 1955 | } |
| 1956 | |
| 1957 | @Override |
| 1958 | public int getLaunchedFromUid(IBinder activityToken) { |
| 1959 | ActivityRecord srec; |
| 1960 | synchronized (mGlobalLock) { |
| 1961 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 1962 | } |
| 1963 | if (srec == null) { |
| 1964 | return -1; |
| 1965 | } |
| 1966 | return srec.launchedFromUid; |
| 1967 | } |
| 1968 | |
| 1969 | @Override |
| 1970 | public String getLaunchedFromPackage(IBinder activityToken) { |
| 1971 | ActivityRecord srec; |
| 1972 | synchronized (mGlobalLock) { |
| 1973 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 1974 | } |
| 1975 | if (srec == null) { |
| 1976 | return null; |
| 1977 | } |
| 1978 | return srec.launchedFromPackage; |
| 1979 | } |
| 1980 | |
| 1981 | @Override |
| 1982 | public boolean convertFromTranslucent(IBinder token) { |
| 1983 | final long origId = Binder.clearCallingIdentity(); |
| 1984 | try { |
| 1985 | synchronized (mGlobalLock) { |
| 1986 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1987 | if (r == null) { |
| 1988 | return false; |
| 1989 | } |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 1990 | return r.setOccludesParent(true); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1991 | } |
| 1992 | } finally { |
| 1993 | Binder.restoreCallingIdentity(origId); |
| 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | @Override |
| 1998 | public boolean convertToTranslucent(IBinder token, Bundle options) { |
| 1999 | SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(options); |
| 2000 | final long origId = Binder.clearCallingIdentity(); |
| 2001 | try { |
| 2002 | synchronized (mGlobalLock) { |
| 2003 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2004 | if (r == null) { |
| 2005 | return false; |
| 2006 | } |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2007 | final ActivityRecord under = r.getTask().getActivityBelow(r); |
| 2008 | if (under != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2009 | under.returningOptions = safeOptions != null ? safeOptions.getOptions(r) : null; |
| 2010 | } |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 2011 | return r.setOccludesParent(false); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2012 | } |
| 2013 | } finally { |
| 2014 | Binder.restoreCallingIdentity(origId); |
| 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | @Override |
| 2019 | public void notifyActivityDrawn(IBinder token) { |
| 2020 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, "notifyActivityDrawn: token=" + token); |
| 2021 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2022 | ActivityRecord r = mRootActivityContainer.isInAnyStack(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2023 | if (r != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2024 | r.getActivityStack().notifyActivityDrawnLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2025 | } |
| 2026 | } |
| 2027 | } |
| 2028 | |
| 2029 | @Override |
| 2030 | public void reportActivityFullyDrawn(IBinder token, boolean restoredFromBundle) { |
| 2031 | synchronized (mGlobalLock) { |
| 2032 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2033 | if (r == null) { |
| 2034 | return; |
| 2035 | } |
| 2036 | r.reportFullyDrawnLocked(restoredFromBundle); |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | @Override |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 2041 | public int getDisplayId(IBinder activityToken) throws RemoteException { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2042 | synchronized (mGlobalLock) { |
| 2043 | final ActivityStack stack = ActivityRecord.getStackLocked(activityToken); |
| 2044 | if (stack != null && stack.mDisplayId != INVALID_DISPLAY) { |
| 2045 | return stack.mDisplayId; |
| 2046 | } |
| 2047 | return DEFAULT_DISPLAY; |
| 2048 | } |
| 2049 | } |
| 2050 | |
| 2051 | @Override |
| 2052 | public ActivityManager.StackInfo getFocusedStackInfo() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2053 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2054 | long ident = Binder.clearCallingIdentity(); |
| 2055 | try { |
| 2056 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2057 | ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2058 | if (focusedStack != null) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2059 | return mRootActivityContainer.getStackInfo(focusedStack.mStackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2060 | } |
| 2061 | return null; |
| 2062 | } |
| 2063 | } finally { |
| 2064 | Binder.restoreCallingIdentity(ident); |
| 2065 | } |
| 2066 | } |
| 2067 | |
| 2068 | @Override |
| 2069 | public void setFocusedStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2070 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2071 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedStack: stackId=" + stackId); |
| 2072 | final long callingId = Binder.clearCallingIdentity(); |
| 2073 | try { |
| 2074 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2075 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2076 | if (stack == null) { |
| 2077 | Slog.w(TAG, "setFocusedStack: No stack with id=" + stackId); |
| 2078 | return; |
| 2079 | } |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2080 | final ActivityRecord r = stack.topRunningActivity(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2081 | if (r != null && r.moveFocusableActivityToTop("setFocusedStack")) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2082 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2083 | } |
| 2084 | } |
| 2085 | } finally { |
| 2086 | Binder.restoreCallingIdentity(callingId); |
| 2087 | } |
| 2088 | } |
| 2089 | |
| 2090 | @Override |
| 2091 | public void setFocusedTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2092 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2093 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedTask: taskId=" + taskId); |
| 2094 | final long callingId = Binder.clearCallingIdentity(); |
| 2095 | try { |
| 2096 | synchronized (mGlobalLock) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2097 | final Task task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2098 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2099 | if (task == null) { |
| 2100 | return; |
| 2101 | } |
| 2102 | final ActivityRecord r = task.topRunningActivityLocked(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2103 | if (r != null && r.moveFocusableActivityToTop("setFocusedTask")) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2104 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2105 | } |
| 2106 | } |
| 2107 | } finally { |
| 2108 | Binder.restoreCallingIdentity(callingId); |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | @Override |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2113 | public void restartActivityProcessIfVisible(IBinder activityToken) { |
| 2114 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "restartActivityProcess()"); |
| 2115 | final long callingId = Binder.clearCallingIdentity(); |
| 2116 | try { |
| 2117 | synchronized (mGlobalLock) { |
| 2118 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 2119 | if (r == null) { |
| 2120 | return; |
| 2121 | } |
| 2122 | r.restartProcessIfVisible(); |
| 2123 | } |
| 2124 | } finally { |
| 2125 | Binder.restoreCallingIdentity(callingId); |
| 2126 | } |
| 2127 | } |
| 2128 | |
| 2129 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2130 | public boolean removeTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2131 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2132 | synchronized (mGlobalLock) { |
| 2133 | final long ident = Binder.clearCallingIdentity(); |
| 2134 | try { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2135 | return mStackSupervisor.removeTaskById(taskId, true, REMOVE_FROM_RECENTS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2136 | "remove-task"); |
| 2137 | } finally { |
| 2138 | Binder.restoreCallingIdentity(ident); |
| 2139 | } |
| 2140 | } |
| 2141 | } |
| 2142 | |
| 2143 | @Override |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 2144 | public void removeAllVisibleRecentTasks() { |
| 2145 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeAllVisibleRecentTasks()"); |
| 2146 | synchronized (mGlobalLock) { |
| 2147 | final long ident = Binder.clearCallingIdentity(); |
| 2148 | try { |
Winson Chung | 42fa21f | 2019-04-02 16:23:46 -0700 | [diff] [blame] | 2149 | getRecentTasks().removeAllVisibleTasks(mAmInternal.getCurrentUserId()); |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 2150 | } finally { |
| 2151 | Binder.restoreCallingIdentity(ident); |
| 2152 | } |
| 2153 | } |
| 2154 | } |
| 2155 | |
| 2156 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2157 | public boolean shouldUpRecreateTask(IBinder token, String destAffinity) { |
| 2158 | synchronized (mGlobalLock) { |
| 2159 | final ActivityRecord srec = ActivityRecord.forTokenLocked(token); |
| 2160 | if (srec != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2161 | return srec.getActivityStack().shouldUpRecreateTaskLocked(srec, destAffinity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2162 | } |
| 2163 | } |
| 2164 | return false; |
| 2165 | } |
| 2166 | |
| 2167 | @Override |
| 2168 | public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode, |
| 2169 | Intent resultData) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2170 | |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 2171 | synchronized (mGlobalLock) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2172 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2173 | if (r != null) { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2174 | return r.getActivityStack().navigateUpTo( |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2175 | r, destIntent, resultCode, resultData); |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 2176 | } |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2177 | return false; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2178 | } |
| 2179 | } |
| 2180 | |
| 2181 | /** |
| 2182 | * Attempts to move a task backwards in z-order (the order of activities within the task is |
| 2183 | * unchanged). |
| 2184 | * |
| 2185 | * There are several possible results of this call: |
| 2186 | * - if the task is locked, then we will show the lock toast |
| 2187 | * - if there is a task behind the provided task, then that task is made visible and resumed as |
| 2188 | * this task is moved to the back |
| 2189 | * - otherwise, if there are no other tasks in the stack: |
| 2190 | * - if this task is in the pinned stack, then we remove the stack completely, which will |
| 2191 | * have the effect of moving the task to the top or bottom of the fullscreen stack |
| 2192 | * (depending on whether it is visible) |
| 2193 | * - otherwise, we simply return home and hide this task |
| 2194 | * |
| 2195 | * @param token A reference to the activity we wish to move |
| 2196 | * @param nonRoot If false then this only works if the activity is the root |
| 2197 | * of a task; if true it will work for any activity in a task. |
| 2198 | * @return Returns true if the move completed, false if not. |
| 2199 | */ |
| 2200 | @Override |
| 2201 | public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2202 | enforceNotIsolatedCaller("moveActivityTaskToBack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2203 | synchronized (mGlobalLock) { |
| 2204 | final long origId = Binder.clearCallingIdentity(); |
| 2205 | try { |
| 2206 | int taskId = ActivityRecord.getTaskForActivityLocked(token, !nonRoot); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2207 | final Task task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2208 | if (task != null) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2209 | return ActivityRecord.getStackLocked(token).moveTaskToBack(task); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2210 | } |
| 2211 | } finally { |
| 2212 | Binder.restoreCallingIdentity(origId); |
| 2213 | } |
| 2214 | } |
| 2215 | return false; |
| 2216 | } |
| 2217 | |
| 2218 | @Override |
| 2219 | public Rect getTaskBounds(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2220 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getTaskBounds()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2221 | long ident = Binder.clearCallingIdentity(); |
| 2222 | Rect rect = new Rect(); |
| 2223 | try { |
| 2224 | synchronized (mGlobalLock) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2225 | final Task task = mRootActivityContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2226 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2227 | if (task == null) { |
| 2228 | Slog.w(TAG, "getTaskBounds: taskId=" + taskId + " not found"); |
| 2229 | return rect; |
| 2230 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 2231 | if (task.getParent() != null) { |
| 2232 | rect.set(task.getBounds()); |
| 2233 | } else if (task.mLastNonFullscreenBounds != null) { |
| 2234 | rect.set(task.mLastNonFullscreenBounds); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2235 | } |
| 2236 | } |
| 2237 | } finally { |
| 2238 | Binder.restoreCallingIdentity(ident); |
| 2239 | } |
| 2240 | return rect; |
| 2241 | } |
| 2242 | |
| 2243 | @Override |
| 2244 | public ActivityManager.TaskDescription getTaskDescription(int id) { |
| 2245 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2246 | enforceCallerIsRecentsOrHasPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2247 | MANAGE_ACTIVITY_STACKS, "getTaskDescription()"); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2248 | final Task tr = mRootActivityContainer.anyTaskForId(id, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2249 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2250 | if (tr != null) { |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 2251 | return tr.getTaskDescription(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2252 | } |
| 2253 | } |
| 2254 | return null; |
| 2255 | } |
| 2256 | |
| 2257 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2258 | public void setTaskWindowingMode(int taskId, int windowingMode, boolean toTop) { |
| 2259 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 2260 | setTaskWindowingModeSplitScreenPrimary(taskId, SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, |
| 2261 | toTop, ANIMATE, null /* initialBounds */, true /* showRecents */); |
| 2262 | return; |
| 2263 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2264 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setTaskWindowingMode()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2265 | synchronized (mGlobalLock) { |
| 2266 | final long ident = Binder.clearCallingIdentity(); |
| 2267 | try { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2268 | final Task task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2269 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2270 | if (task == null) { |
| 2271 | Slog.w(TAG, "setTaskWindowingMode: No task for id=" + taskId); |
| 2272 | return; |
| 2273 | } |
| 2274 | |
| 2275 | if (DEBUG_STACK) Slog.d(TAG_STACK, "setTaskWindowingMode: moving task=" + taskId |
| 2276 | + " to windowingMode=" + windowingMode + " toTop=" + toTop); |
| 2277 | |
| 2278 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2279 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2280 | + " non-standard task " + taskId + " to windowing mode=" |
| 2281 | + windowingMode); |
| 2282 | } |
| 2283 | |
| 2284 | final ActivityStack stack = task.getStack(); |
| 2285 | if (toTop) { |
| 2286 | stack.moveToFront("setTaskWindowingMode", task); |
| 2287 | } |
| 2288 | stack.setWindowingMode(windowingMode); |
| 2289 | } finally { |
| 2290 | Binder.restoreCallingIdentity(ident); |
| 2291 | } |
| 2292 | } |
| 2293 | } |
| 2294 | |
| 2295 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2296 | public String getCallingPackage(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2297 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2298 | ActivityRecord r = getCallingRecordLocked(token); |
| 2299 | return r != null ? r.info.packageName : null; |
| 2300 | } |
| 2301 | } |
| 2302 | |
| 2303 | @Override |
| 2304 | public ComponentName getCallingActivity(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2305 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2306 | ActivityRecord r = getCallingRecordLocked(token); |
| 2307 | return r != null ? r.intent.getComponent() : null; |
| 2308 | } |
| 2309 | } |
| 2310 | |
| 2311 | private ActivityRecord getCallingRecordLocked(IBinder token) { |
| 2312 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2313 | if (r == null) { |
| 2314 | return null; |
| 2315 | } |
| 2316 | return r.resultTo; |
| 2317 | } |
| 2318 | |
| 2319 | @Override |
| 2320 | public void unhandledBack() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2321 | mAmInternal.enforceCallingPermission(android.Manifest.permission.FORCE_BACK, "unhandledBack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2322 | |
| 2323 | synchronized (mGlobalLock) { |
| 2324 | final long origId = Binder.clearCallingIdentity(); |
| 2325 | try { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2326 | getTopDisplayFocusedStack().unhandledBackLocked(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2327 | } finally { |
| 2328 | Binder.restoreCallingIdentity(origId); |
| 2329 | } |
| 2330 | } |
| 2331 | } |
| 2332 | |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2333 | @Override |
| 2334 | public void onBackPressedOnTaskRoot(IBinder token, IRequestFinishCallback callback) { |
| 2335 | synchronized (mGlobalLock) { |
| 2336 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2337 | if (r == null) { |
| 2338 | return; |
| 2339 | } |
| 2340 | ActivityStack stack = r.getActivityStack(); |
| 2341 | if (stack != null && stack.isSingleTaskInstance()) { |
| 2342 | // Single-task stacks are used for activities which are presented in floating |
| 2343 | // windows above full screen activities. Instead of directly finishing the |
| 2344 | // task, a task change listener is used to notify SystemUI so the action can be |
| 2345 | // handled specially. |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2346 | final Task task = r.getTask(); |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2347 | mTaskChangeNotificationController |
| 2348 | .notifyBackPressedOnTaskRoot(task.getTaskInfo()); |
| 2349 | } else { |
| 2350 | try { |
| 2351 | callback.requestFinish(); |
| 2352 | } catch (RemoteException e) { |
| 2353 | Slog.e(TAG, "Failed to invoke request finish callback", e); |
| 2354 | } |
| 2355 | } |
| 2356 | } |
| 2357 | } |
| 2358 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2359 | /** |
| 2360 | * TODO: Add mController hook |
| 2361 | */ |
| 2362 | @Override |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2363 | public void moveTaskToFront(IApplicationThread appThread, String callingPackage, int taskId, |
| 2364 | int flags, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2365 | mAmInternal.enforceCallingPermission(android.Manifest.permission.REORDER_TASKS, "moveTaskToFront()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2366 | |
| 2367 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToFront: moving taskId=" + taskId); |
| 2368 | synchronized (mGlobalLock) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2369 | moveTaskToFrontLocked(appThread, callingPackage, taskId, flags, |
| 2370 | SafeActivityOptions.fromBundle(bOptions), false /* fromRecents */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2371 | } |
| 2372 | } |
| 2373 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2374 | void moveTaskToFrontLocked(@Nullable IApplicationThread appThread, |
| 2375 | @Nullable String callingPackage, int taskId, int flags, SafeActivityOptions options, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2376 | boolean fromRecents) { |
Andrii Kulian | a8ccae4 | 2019-07-24 18:35:22 +0000 | [diff] [blame] | 2377 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2378 | final int callingPid = Binder.getCallingPid(); |
| 2379 | final int callingUid = Binder.getCallingUid(); |
Andrii Kulian | a8ccae4 | 2019-07-24 18:35:22 +0000 | [diff] [blame] | 2380 | if (!isSameApp(callingUid, callingPackage)) { |
| 2381 | String msg = "Permission Denial: moveTaskToFrontLocked() from pid=" |
| 2382 | + Binder.getCallingPid() + " as package " + callingPackage; |
| 2383 | Slog.w(TAG, msg); |
| 2384 | throw new SecurityException(msg); |
| 2385 | } |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2386 | if (!checkAppSwitchAllowedLocked(callingPid, callingUid, -1, -1, "Task to front")) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2387 | SafeActivityOptions.abort(options); |
| 2388 | return; |
| 2389 | } |
| 2390 | final long origId = Binder.clearCallingIdentity(); |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2391 | WindowProcessController callerApp = null; |
| 2392 | if (appThread != null) { |
| 2393 | callerApp = getProcessController(appThread); |
| 2394 | } |
| 2395 | final ActivityStarter starter = getActivityStartController().obtainStarter( |
| 2396 | null /* intent */, "moveTaskToFront"); |
| 2397 | if (starter.shouldAbortBackgroundActivityStart(callingUid, callingPid, callingPackage, -1, |
| 2398 | -1, callerApp, null, false, null)) { |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 2399 | if (!isBackgroundActivityStartsEnabled()) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2400 | return; |
| 2401 | } |
| 2402 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2403 | try { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2404 | final Task task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2405 | if (task == null) { |
| 2406 | Slog.d(TAG, "Could not find task for id: "+ taskId); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2407 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2408 | return; |
| 2409 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2410 | if (getLockTaskController().isLockTaskModeViolation(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2411 | Slog.e(TAG, "moveTaskToFront: Attempt to violate Lock Task Mode"); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2412 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2413 | return; |
| 2414 | } |
| 2415 | ActivityOptions realOptions = options != null |
| 2416 | ? options.getOptions(mStackSupervisor) |
| 2417 | : null; |
| 2418 | mStackSupervisor.findTaskToMoveToFront(task, flags, realOptions, "moveTaskToFront", |
| 2419 | false /* forceNonResizable */); |
| 2420 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 2421 | final ActivityRecord topActivity = task.getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2422 | if (topActivity != null) { |
| 2423 | |
| 2424 | // We are reshowing a task, use a starting window to hide the initial draw delay |
| 2425 | // so the transition can start earlier. |
| 2426 | topActivity.showStartingWindow(null /* prev */, false /* newTask */, |
| 2427 | true /* taskSwitch */, fromRecents); |
| 2428 | } |
| 2429 | } finally { |
| 2430 | Binder.restoreCallingIdentity(origId); |
| 2431 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2432 | } |
| 2433 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2434 | /** |
| 2435 | * Return true if callingUid is system, or packageName belongs to that callingUid. |
| 2436 | */ |
Andrii Kulian | a8ccae4 | 2019-07-24 18:35:22 +0000 | [diff] [blame] | 2437 | boolean isSameApp(int callingUid, @Nullable String packageName) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2438 | try { |
| 2439 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 2440 | if (packageName == null) { |
| 2441 | return false; |
| 2442 | } |
| 2443 | final int uid = AppGlobals.getPackageManager().getPackageUid(packageName, |
| 2444 | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 2445 | UserHandle.getUserId(callingUid)); |
| 2446 | return UserHandle.isSameApp(callingUid, uid); |
| 2447 | } |
| 2448 | } catch (RemoteException e) { |
| 2449 | // Should not happen |
| 2450 | } |
| 2451 | return true; |
| 2452 | } |
| 2453 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2454 | boolean checkAppSwitchAllowedLocked(int sourcePid, int sourceUid, |
| 2455 | int callingPid, int callingUid, String name) { |
| 2456 | if (mAppSwitchesAllowedTime < SystemClock.uptimeMillis()) { |
| 2457 | return true; |
| 2458 | } |
| 2459 | |
| 2460 | if (getRecentTasks().isCallerRecents(sourceUid)) { |
| 2461 | return true; |
| 2462 | } |
| 2463 | |
| 2464 | int perm = checkComponentPermission(STOP_APP_SWITCHES, sourcePid, sourceUid, -1, true); |
| 2465 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2466 | return true; |
| 2467 | } |
| 2468 | if (checkAllowAppSwitchUid(sourceUid)) { |
| 2469 | return true; |
| 2470 | } |
| 2471 | |
| 2472 | // If the actual IPC caller is different from the logical source, then |
| 2473 | // also see if they are allowed to control app switches. |
| 2474 | if (callingUid != -1 && callingUid != sourceUid) { |
| 2475 | perm = checkComponentPermission(STOP_APP_SWITCHES, callingPid, callingUid, -1, true); |
| 2476 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2477 | return true; |
| 2478 | } |
| 2479 | if (checkAllowAppSwitchUid(callingUid)) { |
| 2480 | return true; |
| 2481 | } |
| 2482 | } |
| 2483 | |
| 2484 | Slog.w(TAG, name + " request from " + sourceUid + " stopped"); |
| 2485 | return false; |
| 2486 | } |
| 2487 | |
| 2488 | private boolean checkAllowAppSwitchUid(int uid) { |
| 2489 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(UserHandle.getUserId(uid)); |
| 2490 | if (types != null) { |
| 2491 | for (int i = types.size() - 1; i >= 0; i--) { |
| 2492 | if (types.valueAt(i).intValue() == uid) { |
| 2493 | return true; |
| 2494 | } |
| 2495 | } |
| 2496 | } |
| 2497 | return false; |
| 2498 | } |
| 2499 | |
| 2500 | @Override |
| 2501 | public void setActivityController(IActivityController controller, boolean imAMonkey) { |
| 2502 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER, |
| 2503 | "setActivityController()"); |
| 2504 | synchronized (mGlobalLock) { |
| 2505 | mController = controller; |
| 2506 | mControllerIsAMonkey = imAMonkey; |
| 2507 | Watchdog.getInstance().setActivityController(controller); |
| 2508 | } |
| 2509 | } |
| 2510 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 2511 | public boolean isControllerAMonkey() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2512 | synchronized (mGlobalLock) { |
| 2513 | return mController != null && mControllerIsAMonkey; |
| 2514 | } |
| 2515 | } |
| 2516 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2517 | @Override |
| 2518 | public int getTaskForActivity(IBinder token, boolean onlyRoot) { |
| 2519 | synchronized (mGlobalLock) { |
| 2520 | return ActivityRecord.getTaskForActivityLocked(token, onlyRoot); |
| 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2525 | public List<ActivityManager.RunningTaskInfo> getTasks(int maxNum) { |
| 2526 | return getFilteredTasks(maxNum, ACTIVITY_TYPE_UNDEFINED, WINDOWING_MODE_UNDEFINED); |
| 2527 | } |
| 2528 | |
| 2529 | @Override |
| 2530 | public List<ActivityManager.RunningTaskInfo> getFilteredTasks(int maxNum, |
| 2531 | @WindowConfiguration.ActivityType int ignoreActivityType, |
| 2532 | @WindowConfiguration.WindowingMode int ignoreWindowingMode) { |
| 2533 | final int callingUid = Binder.getCallingUid(); |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 2534 | final int callingPid = Binder.getCallingPid(); |
| 2535 | final boolean crossUser = isCrossUserAllowed(callingPid, callingUid); |
Nicholas Sauer | 3f9249f | 2019-09-10 20:23:41 -0700 | [diff] [blame] | 2536 | final int[] profileIds = getUserManager().getProfileIds( |
| 2537 | UserHandle.getUserId(callingUid), true); |
| 2538 | ArraySet<Integer> callingProfileIds = new ArraySet<>(); |
| 2539 | for (int i = 0; i < profileIds.length; i++) { |
| 2540 | callingProfileIds.add(profileIds[i]); |
| 2541 | } |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2542 | ArrayList<ActivityManager.RunningTaskInfo> list = new ArrayList<>(); |
| 2543 | |
| 2544 | synchronized (mGlobalLock) { |
| 2545 | if (DEBUG_ALL) Slog.v(TAG, "getTasks: max=" + maxNum); |
| 2546 | |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 2547 | final boolean allowed = isGetTasksAllowed("getTasks", callingPid, callingUid); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2548 | mRootActivityContainer.getRunningTasks(maxNum, list, ignoreActivityType, |
Nicholas Sauer | 3f9249f | 2019-09-10 20:23:41 -0700 | [diff] [blame] | 2549 | ignoreWindowingMode, callingUid, allowed, crossUser, callingProfileIds); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | return list; |
| 2553 | } |
| 2554 | |
| 2555 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2556 | public final void finishSubActivity(IBinder token, String resultWho, int requestCode) { |
| 2557 | synchronized (mGlobalLock) { |
| 2558 | final long origId = Binder.clearCallingIdentity(); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2559 | try { |
| 2560 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2561 | if (r == null) return; |
| 2562 | |
| 2563 | final PooledConsumer c = PooledLambda.obtainConsumer( |
| 2564 | ActivityRecord::finishIfSubActivity, PooledLambda.__(ActivityRecord.class), |
| 2565 | r, resultWho, requestCode); |
| 2566 | // TODO: This should probably only loop over the task since you need to be in the |
| 2567 | // same task to return results. |
| 2568 | r.getActivityStack().forAllActivities(c); |
| 2569 | c.recycle(); |
| 2570 | |
| 2571 | updateOomAdj(); |
| 2572 | } finally { |
| 2573 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2574 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2575 | } |
| 2576 | } |
| 2577 | |
| 2578 | @Override |
| 2579 | public boolean willActivityBeVisible(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2580 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2581 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 2582 | if (stack != null) { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 2583 | return stack.willActivityBeVisible(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2584 | } |
| 2585 | return false; |
| 2586 | } |
| 2587 | } |
| 2588 | |
| 2589 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2590 | public void moveTaskToStack(int taskId, int stackId, boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2591 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "moveTaskToStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2592 | synchronized (mGlobalLock) { |
| 2593 | final long ident = Binder.clearCallingIdentity(); |
| 2594 | try { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2595 | final Task task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2596 | if (task == null) { |
| 2597 | Slog.w(TAG, "moveTaskToStack: No task for id=" + taskId); |
| 2598 | return; |
| 2599 | } |
| 2600 | |
| 2601 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToStack: moving task=" + taskId |
| 2602 | + " to stackId=" + stackId + " toTop=" + toTop); |
| 2603 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2604 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2605 | if (stack == null) { |
| 2606 | throw new IllegalStateException( |
| 2607 | "moveTaskToStack: No stack for stackId=" + stackId); |
| 2608 | } |
| 2609 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 2610 | throw new IllegalArgumentException("moveTaskToStack: Attempt to move task " |
| 2611 | + taskId + " to stack " + stackId); |
| 2612 | } |
| 2613 | if (stack.inSplitScreenPrimaryWindowingMode()) { |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 2614 | mWindowManager.setDockedStackCreateStateLocked( |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2615 | SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */); |
| 2616 | } |
| 2617 | task.reparent(stack, toTop, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME, |
| 2618 | "moveTaskToStack"); |
| 2619 | } finally { |
| 2620 | Binder.restoreCallingIdentity(ident); |
| 2621 | } |
| 2622 | } |
| 2623 | } |
| 2624 | |
| 2625 | @Override |
Evan Rosky | dbe2ce5 | 2019-07-18 11:13:17 -0700 | [diff] [blame] | 2626 | public void animateResizePinnedStack(int stackId, Rect destBounds, int animationDuration) { |
| 2627 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "animateResizePinnedStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2628 | |
| 2629 | final long ident = Binder.clearCallingIdentity(); |
| 2630 | try { |
| 2631 | synchronized (mGlobalLock) { |
Evan Rosky | dbe2ce5 | 2019-07-18 11:13:17 -0700 | [diff] [blame] | 2632 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
| 2633 | if (stack == null) { |
| 2634 | Slog.w(TAG, "resizeStack: stackId " + stackId + " not found."); |
| 2635 | return; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2636 | } |
Evan Rosky | dbe2ce5 | 2019-07-18 11:13:17 -0700 | [diff] [blame] | 2637 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 2638 | throw new IllegalArgumentException("Stack: " + stackId |
| 2639 | + " doesn't support animated resize."); |
| 2640 | } |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2641 | stack.animateResizePinnedStack(destBounds, null /* sourceHintBounds */, |
Evan Rosky | dbe2ce5 | 2019-07-18 11:13:17 -0700 | [diff] [blame] | 2642 | animationDuration, false /* fromFullscreen */); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2643 | } |
| 2644 | } finally { |
| 2645 | Binder.restoreCallingIdentity(ident); |
| 2646 | } |
| 2647 | } |
| 2648 | |
wilsonshih | 5c4cf52 | 2019-01-25 09:03:47 +0800 | [diff] [blame] | 2649 | @Override |
| 2650 | public void offsetPinnedStackBounds(int stackId, Rect compareBounds, int xOffset, int yOffset, |
| 2651 | int animationDuration) { |
| 2652 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "offsetPinnedStackBounds()"); |
| 2653 | |
| 2654 | final long ident = Binder.clearCallingIdentity(); |
| 2655 | try { |
| 2656 | synchronized (mGlobalLock) { |
| 2657 | if (xOffset == 0 && yOffset == 0) { |
| 2658 | return; |
| 2659 | } |
| 2660 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
| 2661 | if (stack == null) { |
| 2662 | Slog.w(TAG, "offsetPinnedStackBounds: stackId " + stackId + " not found."); |
| 2663 | return; |
| 2664 | } |
| 2665 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 2666 | throw new IllegalArgumentException("Stack: " + stackId |
| 2667 | + " doesn't support animated resize."); |
| 2668 | } |
| 2669 | final Rect destBounds = new Rect(); |
| 2670 | stack.getAnimationOrCurrentBounds(destBounds); |
wilsonshih | a6e408c | 2019-02-19 17:30:03 +0800 | [diff] [blame] | 2671 | if (destBounds.isEmpty() || !destBounds.equals(compareBounds)) { |
wilsonshih | 5c4cf52 | 2019-01-25 09:03:47 +0800 | [diff] [blame] | 2672 | Slog.w(TAG, "The current stack bounds does not matched! It may be obsolete."); |
| 2673 | return; |
| 2674 | } |
| 2675 | destBounds.offset(xOffset, yOffset); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2676 | stack.animateResizePinnedStack(destBounds, null /* sourceHintBounds */, |
wilsonshih | 5c4cf52 | 2019-01-25 09:03:47 +0800 | [diff] [blame] | 2677 | animationDuration, false /* fromFullscreen */); |
| 2678 | } |
| 2679 | } finally { |
| 2680 | Binder.restoreCallingIdentity(ident); |
| 2681 | } |
| 2682 | } |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2683 | /** |
| 2684 | * Moves the specified task to the primary-split-screen stack. |
| 2685 | * |
| 2686 | * @param taskId Id of task to move. |
| 2687 | * @param createMode The mode the primary split screen stack should be created in if it doesn't |
| 2688 | * exist already. See |
| 2689 | * {@link android.app.ActivityTaskManager#SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT} |
| 2690 | * and |
| 2691 | * {@link android.app.ActivityTaskManager#SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT} |
| 2692 | * @param toTop If the task and stack should be moved to the top. |
| 2693 | * @param animate Whether we should play an animation for the moving the task. |
| 2694 | * @param initialBounds If the primary stack gets created, it will use these bounds for the |
| 2695 | * stack. Pass {@code null} to use default bounds. |
| 2696 | * @param showRecents If the recents activity should be shown on the other side of the task |
| 2697 | * going into split-screen mode. |
| 2698 | */ |
| 2699 | @Override |
| 2700 | public boolean setTaskWindowingModeSplitScreenPrimary(int taskId, int createMode, |
| 2701 | boolean toTop, boolean animate, Rect initialBounds, boolean showRecents) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2702 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2703 | "setTaskWindowingModeSplitScreenPrimary()"); |
| 2704 | synchronized (mGlobalLock) { |
| 2705 | final long ident = Binder.clearCallingIdentity(); |
| 2706 | try { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2707 | final Task task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2708 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2709 | if (task == null) { |
| 2710 | Slog.w(TAG, "setTaskWindowingModeSplitScreenPrimary: No task for id=" + taskId); |
| 2711 | return false; |
| 2712 | } |
| 2713 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
| 2714 | "setTaskWindowingModeSplitScreenPrimary: moving task=" + taskId |
| 2715 | + " to createMode=" + createMode + " toTop=" + toTop); |
| 2716 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2717 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2718 | + " non-standard task " + taskId + " to split-screen windowing mode"); |
| 2719 | } |
| 2720 | |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 2721 | mWindowManager.setDockedStackCreateStateLocked(createMode, initialBounds); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2722 | final int windowingMode = task.getWindowingMode(); |
| 2723 | final ActivityStack stack = task.getStack(); |
| 2724 | if (toTop) { |
| 2725 | stack.moveToFront("setTaskWindowingModeSplitScreenPrimary", task); |
| 2726 | } |
| 2727 | stack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, animate, showRecents, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 2728 | false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */, |
| 2729 | false /* creating */); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2730 | return windowingMode != task.getWindowingMode(); |
| 2731 | } finally { |
| 2732 | Binder.restoreCallingIdentity(ident); |
| 2733 | } |
| 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | /** |
| 2738 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 2739 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 2740 | */ |
| 2741 | @Override |
| 2742 | public void removeStacksInWindowingModes(int[] windowingModes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2743 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2744 | "removeStacksInWindowingModes()"); |
| 2745 | |
| 2746 | synchronized (mGlobalLock) { |
| 2747 | final long ident = Binder.clearCallingIdentity(); |
| 2748 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2749 | mRootActivityContainer.removeStacksInWindowingModes(windowingModes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2750 | } finally { |
| 2751 | Binder.restoreCallingIdentity(ident); |
| 2752 | } |
| 2753 | } |
| 2754 | } |
| 2755 | |
| 2756 | @Override |
| 2757 | public void removeStacksWithActivityTypes(int[] activityTypes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2758 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2759 | "removeStacksWithActivityTypes()"); |
| 2760 | |
| 2761 | synchronized (mGlobalLock) { |
| 2762 | final long ident = Binder.clearCallingIdentity(); |
| 2763 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2764 | mRootActivityContainer.removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2765 | } finally { |
| 2766 | Binder.restoreCallingIdentity(ident); |
| 2767 | } |
| 2768 | } |
| 2769 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2770 | |
| 2771 | @Override |
| 2772 | public ParceledListSlice<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, |
| 2773 | int userId) { |
| 2774 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2775 | userId = handleIncomingUser(Binder.getCallingPid(), callingUid, userId, "getRecentTasks"); |
| 2776 | final boolean allowed = isGetTasksAllowed("getRecentTasks", Binder.getCallingPid(), |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2777 | callingUid); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2778 | final boolean detailed = checkGetTasksPermission( |
| 2779 | android.Manifest.permission.GET_DETAILED_TASKS, Binder.getCallingPid(), |
| 2780 | UserHandle.getAppId(callingUid)) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2781 | == PackageManager.PERMISSION_GRANTED; |
| 2782 | |
| 2783 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 2784 | return mRecentTasks.getRecentTasks(maxNum, flags, allowed, detailed, userId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2785 | callingUid); |
| 2786 | } |
| 2787 | } |
| 2788 | |
| 2789 | @Override |
| 2790 | public List<ActivityManager.StackInfo> getAllStackInfos() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2791 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2792 | long ident = Binder.clearCallingIdentity(); |
| 2793 | try { |
| 2794 | synchronized (mGlobalLock) { |
Evan Rosky | fd43969 | 2019-11-06 16:12:59 -0800 | [diff] [blame] | 2795 | return mRootActivityContainer.getAllStackInfos(INVALID_DISPLAY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2796 | } |
| 2797 | } finally { |
| 2798 | Binder.restoreCallingIdentity(ident); |
| 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | @Override |
| 2803 | public ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2804 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2805 | long ident = Binder.clearCallingIdentity(); |
| 2806 | try { |
| 2807 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2808 | return mRootActivityContainer.getStackInfo(windowingMode, activityType); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2809 | } |
| 2810 | } finally { |
| 2811 | Binder.restoreCallingIdentity(ident); |
| 2812 | } |
| 2813 | } |
| 2814 | |
| 2815 | @Override |
Evan Rosky | fd43969 | 2019-11-06 16:12:59 -0800 | [diff] [blame] | 2816 | public List<ActivityManager.StackInfo> getAllStackInfosOnDisplay(int displayId) { |
| 2817 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); |
| 2818 | long ident = Binder.clearCallingIdentity(); |
| 2819 | try { |
| 2820 | synchronized (mGlobalLock) { |
| 2821 | return mRootActivityContainer.getAllStackInfos(displayId); |
| 2822 | } |
| 2823 | } finally { |
| 2824 | Binder.restoreCallingIdentity(ident); |
| 2825 | } |
| 2826 | } |
| 2827 | |
| 2828 | @Override |
| 2829 | public ActivityManager.StackInfo getStackInfoOnDisplay(int windowingMode, int activityType, |
| 2830 | int displayId) { |
| 2831 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
| 2832 | long ident = Binder.clearCallingIdentity(); |
| 2833 | try { |
| 2834 | synchronized (mGlobalLock) { |
| 2835 | return mRootActivityContainer.getStackInfo(windowingMode, activityType, displayId); |
| 2836 | } |
| 2837 | } finally { |
| 2838 | Binder.restoreCallingIdentity(ident); |
| 2839 | } |
| 2840 | } |
| 2841 | |
| 2842 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2843 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2844 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "cancelRecentsAnimation()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2845 | final long callingUid = Binder.getCallingUid(); |
| 2846 | final long origId = Binder.clearCallingIdentity(); |
| 2847 | try { |
| 2848 | synchronized (mGlobalLock) { |
| 2849 | // Cancel the recents animation synchronously (do not hold the WM lock) |
Wale Ogunwale | a441b92 | 2019-06-27 19:21:44 -0700 | [diff] [blame] | 2850 | mWindowManager.cancelRecentsAnimation(restoreHomeStackPosition |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2851 | ? REORDER_MOVE_TO_ORIGINAL_POSITION |
| 2852 | : REORDER_KEEP_IN_PLACE, "cancelRecentsAnimation/uid=" + callingUid); |
| 2853 | } |
| 2854 | } finally { |
| 2855 | Binder.restoreCallingIdentity(origId); |
| 2856 | } |
| 2857 | } |
| 2858 | |
| 2859 | @Override |
| 2860 | public void startLockTaskModeByToken(IBinder token) { |
| 2861 | synchronized (mGlobalLock) { |
| 2862 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2863 | if (r == null) { |
| 2864 | return; |
| 2865 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2866 | startLockTaskModeLocked(r.getTask(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | @Override |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2871 | public void startSystemLockTaskMode(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2872 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "startSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2873 | // This makes inner call to look as if it was initiated by system. |
| 2874 | long ident = Binder.clearCallingIdentity(); |
| 2875 | try { |
| 2876 | synchronized (mGlobalLock) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2877 | final Task task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2878 | MATCH_TASK_IN_STACKS_ONLY); |
| 2879 | if (task == null) { |
| 2880 | return; |
| 2881 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2882 | |
| 2883 | // When starting lock task mode the stack must be in front and focused |
| 2884 | task.getStack().moveToFront("startSystemLockTaskMode"); |
| 2885 | startLockTaskModeLocked(task, true /* isSystemCaller */); |
| 2886 | } |
| 2887 | } finally { |
| 2888 | Binder.restoreCallingIdentity(ident); |
| 2889 | } |
| 2890 | } |
| 2891 | |
| 2892 | @Override |
| 2893 | public void stopLockTaskModeByToken(IBinder token) { |
| 2894 | synchronized (mGlobalLock) { |
| 2895 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2896 | if (r == null) { |
| 2897 | return; |
| 2898 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2899 | stopLockTaskModeInternal(r.getTask(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2900 | } |
| 2901 | } |
| 2902 | |
| 2903 | /** |
| 2904 | * This API should be called by SystemUI only when user perform certain action to dismiss |
| 2905 | * lock task mode. We should only dismiss pinned lock task mode in this case. |
| 2906 | */ |
| 2907 | @Override |
| 2908 | public void stopSystemLockTaskMode() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2909 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "stopSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2910 | stopLockTaskModeInternal(null, true /* isSystemCaller */); |
| 2911 | } |
| 2912 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2913 | private void startLockTaskModeLocked(@Nullable Task task, boolean isSystemCaller) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2914 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "startLockTaskModeLocked: " + task); |
| 2915 | if (task == null || task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) { |
| 2916 | return; |
| 2917 | } |
| 2918 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2919 | final ActivityStack stack = mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 2920 | if (stack == null || task != stack.getTopMostTask()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2921 | throw new IllegalArgumentException("Invalid task, not in foreground"); |
| 2922 | } |
| 2923 | |
| 2924 | // {@code isSystemCaller} is used to distinguish whether this request is initiated by the |
| 2925 | // system or a specific app. |
| 2926 | // * System-initiated requests will only start the pinned mode (screen pinning) |
| 2927 | // * App-initiated requests |
| 2928 | // - will put the device in fully locked mode (LockTask), if the app is whitelisted |
| 2929 | // - will start the pinned mode, otherwise |
| 2930 | final int callingUid = Binder.getCallingUid(); |
| 2931 | long ident = Binder.clearCallingIdentity(); |
| 2932 | try { |
| 2933 | // When a task is locked, dismiss the pinned stack if it exists |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2934 | mRootActivityContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2935 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2936 | getLockTaskController().startLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2937 | } finally { |
| 2938 | Binder.restoreCallingIdentity(ident); |
| 2939 | } |
| 2940 | } |
| 2941 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2942 | private void stopLockTaskModeInternal(@Nullable Task task, boolean isSystemCaller) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2943 | final int callingUid = Binder.getCallingUid(); |
| 2944 | long ident = Binder.clearCallingIdentity(); |
| 2945 | try { |
| 2946 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2947 | getLockTaskController().stopLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2948 | } |
| 2949 | // Launch in-call UI if a call is ongoing. This is necessary to allow stopping the lock |
| 2950 | // task and jumping straight into a call in the case of emergency call back. |
| 2951 | TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
| 2952 | if (tm != null) { |
| 2953 | tm.showInCallScreen(false); |
| 2954 | } |
| 2955 | } finally { |
| 2956 | Binder.restoreCallingIdentity(ident); |
| 2957 | } |
| 2958 | } |
| 2959 | |
| 2960 | @Override |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 2961 | public void updateLockTaskPackages(int userId, String[] packages) { |
| 2962 | final int callingUid = Binder.getCallingUid(); |
| 2963 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 2964 | mAmInternal.enforceCallingPermission(Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
| 2965 | "updateLockTaskPackages()"); |
| 2966 | } |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 2967 | synchronized (mGlobalLock) { |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 2968 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Whitelisting " + userId + ":" |
| 2969 | + Arrays.toString(packages)); |
| 2970 | getLockTaskController().updateLockTaskPackages(userId, packages); |
| 2971 | } |
| 2972 | } |
| 2973 | |
| 2974 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2975 | public boolean isInLockTaskMode() { |
| 2976 | return getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
| 2977 | } |
| 2978 | |
| 2979 | @Override |
| 2980 | public int getLockTaskModeState() { |
| 2981 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2982 | return getLockTaskController().getLockTaskModeState(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2983 | } |
| 2984 | } |
| 2985 | |
| 2986 | @Override |
| 2987 | public void setTaskDescription(IBinder token, ActivityManager.TaskDescription td) { |
| 2988 | synchronized (mGlobalLock) { |
| 2989 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2990 | if (r != null) { |
| 2991 | r.setTaskDescription(td); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2992 | final Task task = r.getTask(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2993 | task.updateTaskDescription(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2994 | } |
| 2995 | } |
| 2996 | } |
| 2997 | |
| 2998 | @Override |
| 2999 | public Bundle getActivityOptions(IBinder token) { |
| 3000 | final long origId = Binder.clearCallingIdentity(); |
| 3001 | try { |
| 3002 | synchronized (mGlobalLock) { |
| 3003 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3004 | if (r != null) { |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 3005 | final ActivityOptions activityOptions = r.takeOptionsLocked( |
| 3006 | true /* fromClient */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3007 | return activityOptions == null ? null : activityOptions.toBundle(); |
| 3008 | } |
| 3009 | return null; |
| 3010 | } |
| 3011 | } finally { |
| 3012 | Binder.restoreCallingIdentity(origId); |
| 3013 | } |
| 3014 | } |
| 3015 | |
| 3016 | @Override |
| 3017 | public List<IBinder> getAppTasks(String callingPackage) { |
| 3018 | int callingUid = Binder.getCallingUid(); |
| 3019 | long ident = Binder.clearCallingIdentity(); |
| 3020 | try { |
| 3021 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3022 | return mRecentTasks.getAppTasksList(callingUid, callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3023 | } |
| 3024 | } finally { |
| 3025 | Binder.restoreCallingIdentity(ident); |
| 3026 | } |
| 3027 | } |
| 3028 | |
| 3029 | @Override |
| 3030 | public void finishVoiceTask(IVoiceInteractionSession session) { |
| 3031 | synchronized (mGlobalLock) { |
| 3032 | final long origId = Binder.clearCallingIdentity(); |
| 3033 | try { |
| 3034 | // TODO: VI Consider treating local voice interactions and voice tasks |
| 3035 | // differently here |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3036 | mRootActivityContainer.finishVoiceTask(session); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3037 | } finally { |
| 3038 | Binder.restoreCallingIdentity(origId); |
| 3039 | } |
| 3040 | } |
| 3041 | |
| 3042 | } |
| 3043 | |
| 3044 | @Override |
| 3045 | public boolean isTopOfTask(IBinder token) { |
| 3046 | synchronized (mGlobalLock) { |
| 3047 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3048 | return r != null && r.getTask().getTopNonFinishingActivity() == r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | @Override |
| 3053 | public void notifyLaunchTaskBehindComplete(IBinder token) { |
| 3054 | mStackSupervisor.scheduleLaunchTaskBehindComplete(token); |
| 3055 | } |
| 3056 | |
| 3057 | @Override |
| 3058 | public void notifyEnterAnimationComplete(IBinder token) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3059 | mH.post(() -> { |
| 3060 | synchronized (mGlobalLock) { |
| 3061 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3062 | if (r != null && r.attachedToProcess()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3063 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3064 | r.app.getThread().scheduleEnterAnimationComplete(r.appToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3065 | } catch (RemoteException e) { |
| 3066 | } |
| 3067 | } |
| 3068 | } |
| 3069 | |
| 3070 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | /** Called from an app when assist data is ready. */ |
| 3074 | @Override |
| 3075 | public void reportAssistContextExtras(IBinder token, Bundle extras, AssistStructure structure, |
| 3076 | AssistContent content, Uri referrer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3077 | PendingAssistExtras pae = (PendingAssistExtras) token; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3078 | synchronized (pae) { |
| 3079 | pae.result = extras; |
| 3080 | pae.structure = structure; |
| 3081 | pae.content = content; |
| 3082 | if (referrer != null) { |
| 3083 | pae.extras.putParcelable(Intent.EXTRA_REFERRER, referrer); |
| 3084 | } |
| 3085 | if (structure != null) { |
Winson Chung | 48b2565 | 2018-10-22 14:04:30 -0700 | [diff] [blame] | 3086 | // Pre-fill the task/activity component for all assist data receivers |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3087 | structure.setTaskId(pae.activity.getTask().mTaskId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3088 | structure.setActivityComponent(pae.activity.mActivityComponent); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3089 | structure.setHomeActivity(pae.isHome); |
| 3090 | } |
| 3091 | pae.haveResult = true; |
| 3092 | pae.notifyAll(); |
| 3093 | if (pae.intent == null && pae.receiver == null) { |
| 3094 | // Caller is just waiting for the result. |
| 3095 | return; |
| 3096 | } |
| 3097 | } |
| 3098 | // We are now ready to launch the assist activity. |
| 3099 | IAssistDataReceiver sendReceiver = null; |
| 3100 | Bundle sendBundle = null; |
| 3101 | synchronized (mGlobalLock) { |
| 3102 | buildAssistBundleLocked(pae, extras); |
| 3103 | boolean exists = mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3104 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3105 | if (!exists) { |
| 3106 | // Timed out. |
| 3107 | return; |
| 3108 | } |
| 3109 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3110 | if ((sendReceiver = pae.receiver) != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3111 | // Caller wants result sent back to them. |
| 3112 | sendBundle = new Bundle(); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3113 | sendBundle.putInt(ActivityTaskManagerInternal.ASSIST_TASK_ID, |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3114 | pae.activity.getTask().mTaskId); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3115 | sendBundle.putBinder(ActivityTaskManagerInternal.ASSIST_ACTIVITY_ID, |
| 3116 | pae.activity.assistToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3117 | sendBundle.putBundle(ASSIST_KEY_DATA, pae.extras); |
| 3118 | sendBundle.putParcelable(ASSIST_KEY_STRUCTURE, pae.structure); |
| 3119 | sendBundle.putParcelable(ASSIST_KEY_CONTENT, pae.content); |
| 3120 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3121 | } |
| 3122 | } |
| 3123 | if (sendReceiver != null) { |
| 3124 | try { |
| 3125 | sendReceiver.onHandleAssistData(sendBundle); |
| 3126 | } catch (RemoteException e) { |
| 3127 | } |
| 3128 | return; |
| 3129 | } |
| 3130 | |
| 3131 | final long ident = Binder.clearCallingIdentity(); |
| 3132 | try { |
| 3133 | if (TextUtils.equals(pae.intent.getAction(), |
| 3134 | android.service.voice.VoiceInteractionService.SERVICE_INTERFACE)) { |
Galia Peycheva | bffbfc3 | 2019-06-18 10:11:35 +0200 | [diff] [blame] | 3135 | // Start voice interaction through VoiceInteractionManagerService. |
| 3136 | mAssistUtils.showSessionForActiveService(sendBundle, SHOW_SOURCE_APPLICATION, |
| 3137 | null, null); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3138 | } else { |
| 3139 | pae.intent.replaceExtras(pae.extras); |
| 3140 | pae.intent.setFlags(FLAG_ACTIVITY_NEW_TASK |
| 3141 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 3142 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 3143 | mInternal.closeSystemDialogs("assist"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3144 | |
| 3145 | try { |
| 3146 | mContext.startActivityAsUser(pae.intent, new UserHandle(pae.userHandle)); |
| 3147 | } catch (ActivityNotFoundException e) { |
| 3148 | Slog.w(TAG, "No activity to handle assist action.", e); |
| 3149 | } |
| 3150 | } |
| 3151 | } finally { |
| 3152 | Binder.restoreCallingIdentity(ident); |
| 3153 | } |
| 3154 | } |
| 3155 | |
| 3156 | @Override |
| 3157 | public int addAppTask(IBinder activityToken, Intent intent, |
| 3158 | ActivityManager.TaskDescription description, Bitmap thumbnail) throws RemoteException { |
| 3159 | final int callingUid = Binder.getCallingUid(); |
| 3160 | final long callingIdent = Binder.clearCallingIdentity(); |
| 3161 | |
| 3162 | try { |
| 3163 | synchronized (mGlobalLock) { |
| 3164 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 3165 | if (r == null) { |
| 3166 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 3167 | + activityToken); |
| 3168 | } |
| 3169 | ComponentName comp = intent.getComponent(); |
| 3170 | if (comp == null) { |
| 3171 | throw new IllegalArgumentException("Intent " + intent |
| 3172 | + " must specify explicit component"); |
| 3173 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3174 | if (thumbnail.getWidth() != mThumbnailWidth |
| 3175 | || thumbnail.getHeight() != mThumbnailHeight) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3176 | throw new IllegalArgumentException("Bad thumbnail size: got " |
| 3177 | + thumbnail.getWidth() + "x" + thumbnail.getHeight() + ", require " |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3178 | + mThumbnailWidth + "x" + mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3179 | } |
| 3180 | if (intent.getSelector() != null) { |
| 3181 | intent.setSelector(null); |
| 3182 | } |
| 3183 | if (intent.getSourceBounds() != null) { |
| 3184 | intent.setSourceBounds(null); |
| 3185 | } |
| 3186 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) { |
| 3187 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) == 0) { |
| 3188 | // The caller has added this as an auto-remove task... that makes no |
| 3189 | // sense, so turn off auto-remove. |
| 3190 | intent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS); |
| 3191 | } |
| 3192 | } |
| 3193 | final ActivityInfo ainfo = AppGlobals.getPackageManager().getActivityInfo(comp, |
| 3194 | STOCK_PM_FLAGS, UserHandle.getUserId(callingUid)); |
| 3195 | if (ainfo.applicationInfo.uid != callingUid) { |
| 3196 | throw new SecurityException( |
| 3197 | "Can't add task for another application: target uid=" |
| 3198 | + ainfo.applicationInfo.uid + ", calling uid=" + callingUid); |
| 3199 | } |
| 3200 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3201 | final ActivityStack stack = r.getActivityStack(); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3202 | final Task task = stack.createTask( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3203 | mStackSupervisor.getNextTaskIdForUserLocked(r.mUserId), ainfo, intent, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3204 | null /* voiceSession */, null /* voiceInteractor */, !ON_TOP); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3205 | if (!mRecentTasks.addToBottom(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3206 | // 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] | 3207 | stack.removeChild(task, "addAppTask"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3208 | return INVALID_TASK_ID; |
| 3209 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 3210 | task.getTaskDescription().copyFrom(description); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3211 | |
| 3212 | // TODO: Send the thumbnail to WM to store it. |
| 3213 | |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 3214 | return task.mTaskId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3215 | } |
| 3216 | } finally { |
| 3217 | Binder.restoreCallingIdentity(callingIdent); |
| 3218 | } |
| 3219 | } |
| 3220 | |
| 3221 | @Override |
| 3222 | public Point getAppTaskThumbnailSize() { |
| 3223 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3224 | return new Point(mThumbnailWidth, mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3225 | } |
| 3226 | } |
| 3227 | |
| 3228 | @Override |
| 3229 | public void setTaskResizeable(int taskId, int resizeableMode) { |
| 3230 | synchronized (mGlobalLock) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3231 | final Task task = mRootActivityContainer.anyTaskForId( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3232 | taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 3233 | if (task == null) { |
| 3234 | Slog.w(TAG, "setTaskResizeable: taskId=" + taskId + " not found"); |
| 3235 | return; |
| 3236 | } |
| 3237 | task.setResizeMode(resizeableMode); |
| 3238 | } |
| 3239 | } |
| 3240 | |
| 3241 | @Override |
| 3242 | public void resizeTask(int taskId, Rect bounds, int resizeMode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3243 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "resizeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3244 | long ident = Binder.clearCallingIdentity(); |
| 3245 | try { |
| 3246 | synchronized (mGlobalLock) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3247 | final Task task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 3248 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3249 | if (task == null) { |
| 3250 | Slog.w(TAG, "resizeTask: taskId=" + taskId + " not found"); |
| 3251 | return; |
| 3252 | } |
| 3253 | // Place the task in the right stack if it isn't there already based on |
| 3254 | // the requested bounds. |
| 3255 | // The stack transition logic is: |
| 3256 | // - a null bounds on a freeform task moves that task to fullscreen |
| 3257 | // - a non-null bounds on a non-freeform (fullscreen OR docked) task moves |
| 3258 | // that task to freeform |
| 3259 | // - otherwise the task is not moved |
| 3260 | ActivityStack stack = task.getStack(); |
| 3261 | if (!task.getWindowConfiguration().canResizeTask()) { |
| 3262 | throw new IllegalArgumentException("resizeTask not allowed on task=" + task); |
| 3263 | } |
| 3264 | if (bounds == null && stack.getWindowingMode() == WINDOWING_MODE_FREEFORM) { |
| 3265 | stack = stack.getDisplay().getOrCreateStack( |
| 3266 | WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), ON_TOP); |
| 3267 | } else if (bounds != null && stack.getWindowingMode() != WINDOWING_MODE_FREEFORM) { |
| 3268 | stack = stack.getDisplay().getOrCreateStack( |
| 3269 | WINDOWING_MODE_FREEFORM, stack.getActivityType(), ON_TOP); |
| 3270 | } |
| 3271 | |
| 3272 | // Reparent the task to the right stack if necessary |
| 3273 | boolean preserveWindow = (resizeMode & RESIZE_MODE_PRESERVE_WINDOW) != 0; |
| 3274 | if (stack != task.getStack()) { |
| 3275 | // Defer resume until the task is resized below |
| 3276 | task.reparent(stack, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, |
| 3277 | DEFER_RESUME, "resizeTask"); |
| 3278 | preserveWindow = false; |
| 3279 | } |
| 3280 | |
| 3281 | // After reparenting (which only resizes the task to the stack bounds), resize the |
| 3282 | // task to the actual bounds provided |
| 3283 | task.resize(bounds, resizeMode, preserveWindow, !DEFER_RESUME); |
| 3284 | } |
| 3285 | } finally { |
| 3286 | Binder.restoreCallingIdentity(ident); |
| 3287 | } |
| 3288 | } |
| 3289 | |
Evan Rosky | ddedfd4 | 2019-10-04 13:38:38 -0700 | [diff] [blame] | 3290 | private void sanitizeAndApplyConfigChange(ConfigurationContainer container, |
| 3291 | WindowContainerTransaction.Change change) { |
Evan Rosky | 282ee67 | 2019-11-13 15:50:46 -0800 | [diff] [blame] | 3292 | if (!(container instanceof Task || container instanceof ActivityStack)) { |
Evan Rosky | ddedfd4 | 2019-10-04 13:38:38 -0700 | [diff] [blame] | 3293 | throw new RuntimeException("Invalid token in task transaction"); |
| 3294 | } |
| 3295 | // The "client"-facing API should prevent bad changes; however, just in case, sanitize |
| 3296 | // masks here. |
| 3297 | int configMask = change.getConfigSetMask(); |
| 3298 | int windowMask = change.getWindowSetMask(); |
| 3299 | configMask &= ActivityInfo.CONFIG_WINDOW_CONFIGURATION |
| 3300 | | ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
| 3301 | windowMask &= WindowConfiguration.WINDOW_CONFIG_BOUNDS; |
| 3302 | Configuration c = new Configuration(container.getRequestedOverrideConfiguration()); |
| 3303 | c.setTo(change.getConfiguration(), configMask, windowMask); |
| 3304 | container.onRequestedOverrideConfigurationChanged(c); |
| 3305 | } |
| 3306 | |
| 3307 | @Override |
| 3308 | public void applyContainerTransaction(WindowContainerTransaction t) { |
| 3309 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "applyContainerTransaction()"); |
| 3310 | long ident = Binder.clearCallingIdentity(); |
| 3311 | try { |
| 3312 | if (t == null) { |
| 3313 | return; |
| 3314 | } |
| 3315 | synchronized (mGlobalLock) { |
| 3316 | Iterator<Map.Entry<IBinder, WindowContainerTransaction.Change>> entries = |
| 3317 | t.getChanges().entrySet().iterator(); |
| 3318 | while (entries.hasNext()) { |
| 3319 | final Map.Entry<IBinder, WindowContainerTransaction.Change> entry = |
| 3320 | entries.next(); |
| 3321 | final ConfigurationContainer cc = ConfigurationContainer.RemoteToken.fromBinder( |
| 3322 | entry.getKey()).getContainer(); |
| 3323 | sanitizeAndApplyConfigChange(cc, entry.getValue()); |
| 3324 | } |
| 3325 | } |
| 3326 | } finally { |
| 3327 | Binder.restoreCallingIdentity(ident); |
| 3328 | } |
| 3329 | } |
| 3330 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3331 | @Override |
| 3332 | public boolean releaseActivityInstance(IBinder token) { |
| 3333 | synchronized (mGlobalLock) { |
| 3334 | final long origId = Binder.clearCallingIdentity(); |
| 3335 | try { |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 3336 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3337 | if (r == null || !r.isDestroyable()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3338 | return false; |
| 3339 | } |
Andrii Kulian | f49a58c | 2019-08-14 17:34:27 -0700 | [diff] [blame] | 3340 | r.destroyImmediately(true /* removeFromApp */, "app-req"); |
| 3341 | return r.isState(DESTROYING, DESTROYED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3342 | } finally { |
| 3343 | Binder.restoreCallingIdentity(origId); |
| 3344 | } |
| 3345 | } |
| 3346 | } |
| 3347 | |
| 3348 | @Override |
| 3349 | public void releaseSomeActivities(IApplicationThread appInt) { |
| 3350 | synchronized (mGlobalLock) { |
| 3351 | final long origId = Binder.clearCallingIdentity(); |
| 3352 | try { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3353 | final WindowProcessController app = getProcessController(appInt); |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 3354 | app.releaseSomeActivities("low-mem"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3355 | } finally { |
| 3356 | Binder.restoreCallingIdentity(origId); |
| 3357 | } |
| 3358 | } |
| 3359 | } |
| 3360 | |
| 3361 | @Override |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 3362 | public void setLockScreenShown(boolean keyguardShowing, boolean aodShowing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3363 | if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3364 | != PackageManager.PERMISSION_GRANTED) { |
| 3365 | throw new SecurityException("Requires permission " |
| 3366 | + android.Manifest.permission.DEVICE_POWER); |
| 3367 | } |
| 3368 | |
| 3369 | synchronized (mGlobalLock) { |
| 3370 | long ident = Binder.clearCallingIdentity(); |
| 3371 | if (mKeyguardShown != keyguardShowing) { |
| 3372 | mKeyguardShown = keyguardShowing; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3373 | final Message msg = PooledLambda.obtainMessage( |
| 3374 | ActivityManagerInternal::reportCurKeyguardUsageEvent, mAmInternal, |
| 3375 | keyguardShowing); |
| 3376 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3377 | } |
| 3378 | try { |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 3379 | mKeyguardController.setKeyguardShown(keyguardShowing, aodShowing); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3380 | } finally { |
| 3381 | Binder.restoreCallingIdentity(ident); |
| 3382 | } |
| 3383 | } |
| 3384 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3385 | mH.post(() -> { |
| 3386 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3387 | mScreenObservers.get(i).onKeyguardStateChanged(keyguardShowing); |
| 3388 | } |
| 3389 | }); |
| 3390 | } |
| 3391 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 3392 | public void onScreenAwakeChanged(boolean isAwake) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3393 | mH.post(() -> { |
| 3394 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3395 | mScreenObservers.get(i).onAwakeStateChanged(isAwake); |
| 3396 | } |
| 3397 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3398 | } |
| 3399 | |
| 3400 | @Override |
| 3401 | public Bitmap getTaskDescriptionIcon(String filePath, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3402 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 3403 | userId, "getTaskDescriptionIcon"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3404 | |
| 3405 | final File passedIconFile = new File(filePath); |
| 3406 | final File legitIconFile = new File(TaskPersister.getUserImagesDir(userId), |
| 3407 | passedIconFile.getName()); |
| 3408 | if (!legitIconFile.getPath().equals(filePath) |
| 3409 | || !filePath.contains(ActivityRecord.ACTIVITY_ICON_SUFFIX)) { |
| 3410 | throw new IllegalArgumentException("Bad file path: " + filePath |
| 3411 | + " passed for userId " + userId); |
| 3412 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3413 | return mRecentTasks.getTaskDescriptionIcon(filePath); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3414 | } |
| 3415 | |
| 3416 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3417 | public void removeStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3418 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "removeStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3419 | synchronized (mGlobalLock) { |
| 3420 | final long ident = Binder.clearCallingIdentity(); |
| 3421 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3422 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3423 | if (stack == null) { |
| 3424 | Slog.w(TAG, "removeStack: No stack with id=" + stackId); |
| 3425 | return; |
| 3426 | } |
| 3427 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3428 | throw new IllegalArgumentException( |
| 3429 | "Removing non-standard stack is not allowed."); |
| 3430 | } |
| 3431 | mStackSupervisor.removeStack(stack); |
| 3432 | } finally { |
| 3433 | Binder.restoreCallingIdentity(ident); |
| 3434 | } |
| 3435 | } |
| 3436 | } |
| 3437 | |
| 3438 | @Override |
| 3439 | public void moveStackToDisplay(int stackId, int displayId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3440 | mAmInternal.enforceCallingPermission(INTERNAL_SYSTEM_WINDOW, "moveStackToDisplay()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3441 | |
| 3442 | synchronized (mGlobalLock) { |
| 3443 | final long ident = Binder.clearCallingIdentity(); |
| 3444 | try { |
| 3445 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveStackToDisplay: moving stackId=" + stackId |
| 3446 | + " to displayId=" + displayId); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3447 | mRootActivityContainer.moveStackToDisplay(stackId, displayId, ON_TOP); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3448 | } finally { |
| 3449 | Binder.restoreCallingIdentity(ident); |
| 3450 | } |
| 3451 | } |
| 3452 | } |
| 3453 | |
| 3454 | @Override |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3455 | public void toggleFreeformWindowingMode(IBinder token) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3456 | synchronized (mGlobalLock) { |
| 3457 | long ident = Binder.clearCallingIdentity(); |
| 3458 | try { |
| 3459 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3460 | if (r == null) { |
| 3461 | throw new IllegalArgumentException( |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3462 | "toggleFreeformWindowingMode: No activity record matching token=" |
| 3463 | + token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3464 | } |
| 3465 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3466 | final ActivityStack stack = r.getActivityStack(); |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3467 | if (stack == null) { |
| 3468 | throw new IllegalStateException("toggleFreeformWindowingMode: the activity " |
| 3469 | + "doesn't have a stack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3472 | if (!stack.inFreeformWindowingMode() |
| 3473 | && stack.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) { |
| 3474 | throw new IllegalStateException("toggleFreeformWindowingMode: You can only " |
| 3475 | + "toggle between fullscreen and freeform."); |
| 3476 | } |
| 3477 | |
| 3478 | if (stack.inFreeformWindowingMode()) { |
| 3479 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Evan Rosky | 3a8d7fe | 2019-11-06 17:08:35 -0800 | [diff] [blame] | 3480 | } else if (!mSizeCompatFreeform && r.inSizeCompatMode()) { |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 3481 | throw new IllegalStateException("Size-compat windows are currently not" |
| 3482 | + "freeform-enabled"); |
Yunfan Chen | e9c1c31 | 2019-04-18 14:49:15 +0900 | [diff] [blame] | 3483 | } else if (stack.getParent().inFreeformWindowingMode()) { |
| 3484 | // If the window is on a freeform display, set it to undefined. It will be |
| 3485 | // resolved to freeform and it can adjust windowing mode when the display mode |
| 3486 | // changes in runtime. |
| 3487 | stack.setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3488 | } else { |
| 3489 | stack.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 3490 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3491 | } finally { |
| 3492 | Binder.restoreCallingIdentity(ident); |
| 3493 | } |
| 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | /** Sets the task stack listener that gets callbacks when a task stack changes. */ |
| 3498 | @Override |
| 3499 | public void registerTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3500 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3501 | "registerTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3502 | mTaskChangeNotificationController.registerTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | /** Unregister a task stack listener so that it stops receiving callbacks. */ |
| 3506 | @Override |
| 3507 | public void unregisterTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3508 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3509 | "unregisterTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3510 | mTaskChangeNotificationController.unregisterTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3511 | } |
| 3512 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3513 | @Override |
| 3514 | public boolean requestAssistContextExtras(int requestType, IAssistDataReceiver receiver, |
| 3515 | Bundle receiverExtras, IBinder activityToken, boolean focused, boolean newSessionId) { |
| 3516 | return enqueueAssistContext(requestType, null, null, receiver, receiverExtras, |
| 3517 | activityToken, focused, newSessionId, UserHandle.getCallingUserId(), null, |
| 3518 | PENDING_ASSIST_EXTRAS_LONG_TIMEOUT, 0) != null; |
| 3519 | } |
| 3520 | |
| 3521 | @Override |
| 3522 | public boolean requestAutofillData(IAssistDataReceiver receiver, Bundle receiverExtras, |
| 3523 | IBinder activityToken, int flags) { |
| 3524 | return enqueueAssistContext(ActivityManager.ASSIST_CONTEXT_AUTOFILL, null, null, |
| 3525 | receiver, receiverExtras, activityToken, true, true, UserHandle.getCallingUserId(), |
| 3526 | null, PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT, flags) != null; |
| 3527 | } |
| 3528 | |
| 3529 | @Override |
| 3530 | public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle, |
| 3531 | Bundle args) { |
| 3532 | return enqueueAssistContext(requestType, intent, hint, null, null, null, |
| 3533 | true /* focused */, true /* newSessionId */, userHandle, args, |
| 3534 | PENDING_ASSIST_EXTRAS_TIMEOUT, 0) != null; |
| 3535 | } |
| 3536 | |
| 3537 | @Override |
| 3538 | public Bundle getAssistContextExtras(int requestType) { |
| 3539 | PendingAssistExtras pae = enqueueAssistContext(requestType, null, null, null, |
| 3540 | null, null, true /* focused */, true /* newSessionId */, |
| 3541 | UserHandle.getCallingUserId(), null, PENDING_ASSIST_EXTRAS_TIMEOUT, 0); |
| 3542 | if (pae == null) { |
| 3543 | return null; |
| 3544 | } |
| 3545 | synchronized (pae) { |
| 3546 | while (!pae.haveResult) { |
| 3547 | try { |
| 3548 | pae.wait(); |
| 3549 | } catch (InterruptedException e) { |
| 3550 | } |
| 3551 | } |
| 3552 | } |
| 3553 | synchronized (mGlobalLock) { |
| 3554 | buildAssistBundleLocked(pae, pae.result); |
| 3555 | mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3556 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3557 | } |
| 3558 | return pae.extras; |
| 3559 | } |
| 3560 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3561 | /** |
| 3562 | * Binder IPC calls go through the public entry point. |
| 3563 | * This can be called with or without the global lock held. |
| 3564 | */ |
| 3565 | private static int checkCallingPermission(String permission) { |
| 3566 | return checkPermission( |
| 3567 | permission, Binder.getCallingPid(), UserHandle.getAppId(Binder.getCallingUid())); |
| 3568 | } |
| 3569 | |
| 3570 | /** This can be called with or without the global lock held. */ |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3571 | private void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3572 | if (!getRecentTasks().isCallerRecents(Binder.getCallingUid())) { |
| 3573 | mAmInternal.enforceCallingPermission(permission, func); |
| 3574 | } |
| 3575 | } |
| 3576 | |
| 3577 | @VisibleForTesting |
| 3578 | int checkGetTasksPermission(String permission, int pid, int uid) { |
| 3579 | return checkPermission(permission, pid, uid); |
| 3580 | } |
| 3581 | |
| 3582 | static int checkPermission(String permission, int pid, int uid) { |
| 3583 | if (permission == null) { |
| 3584 | return PackageManager.PERMISSION_DENIED; |
| 3585 | } |
| 3586 | return checkComponentPermission(permission, pid, uid, -1, true); |
| 3587 | } |
| 3588 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3589 | public static int checkComponentPermission(String permission, int pid, int uid, |
| 3590 | int owningUid, boolean exported) { |
| 3591 | return ActivityManagerService.checkComponentPermission( |
| 3592 | permission, pid, uid, owningUid, exported); |
| 3593 | } |
| 3594 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3595 | boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 3596 | if (getRecentTasks().isCallerRecents(callingUid)) { |
| 3597 | // Always allow the recents component to get tasks |
| 3598 | return true; |
| 3599 | } |
| 3600 | |
| 3601 | boolean allowed = checkGetTasksPermission(android.Manifest.permission.REAL_GET_TASKS, |
| 3602 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED; |
| 3603 | if (!allowed) { |
| 3604 | if (checkGetTasksPermission(android.Manifest.permission.GET_TASKS, |
| 3605 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED) { |
| 3606 | // Temporary compatibility: some existing apps on the system image may |
| 3607 | // still be requesting the old permission and not switched to the new |
| 3608 | // one; if so, we'll still allow them full access. This means we need |
| 3609 | // to see if they are holding the old permission and are a system app. |
| 3610 | try { |
| 3611 | if (AppGlobals.getPackageManager().isUidPrivileged(callingUid)) { |
| 3612 | allowed = true; |
| 3613 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3614 | + " is using old GET_TASKS but privileged; allowing"); |
| 3615 | } |
| 3616 | } catch (RemoteException e) { |
| 3617 | } |
| 3618 | } |
| 3619 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3620 | + " does not hold REAL_GET_TASKS; limiting output"); |
| 3621 | } |
| 3622 | return allowed; |
| 3623 | } |
| 3624 | |
Nicholas Sauer | 0259e53 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 3625 | boolean isCrossUserAllowed(int pid, int uid) { |
| 3626 | return checkPermission(INTERACT_ACROSS_USERS, pid, uid) == PERMISSION_GRANTED |
| 3627 | || checkPermission(INTERACT_ACROSS_USERS_FULL, pid, uid) == PERMISSION_GRANTED; |
| 3628 | } |
| 3629 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3630 | private PendingAssistExtras enqueueAssistContext(int requestType, Intent intent, String hint, |
| 3631 | IAssistDataReceiver receiver, Bundle receiverExtras, IBinder activityToken, |
| 3632 | boolean focused, boolean newSessionId, int userHandle, Bundle args, long timeout, |
| 3633 | int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3634 | mAmInternal.enforceCallingPermission(android.Manifest.permission.GET_TOP_ACTIVITY_INFO, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3635 | "enqueueAssistContext()"); |
| 3636 | |
| 3637 | synchronized (mGlobalLock) { |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3638 | ActivityRecord activity = getTopDisplayFocusedStack().getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3639 | if (activity == null) { |
| 3640 | Slog.w(TAG, "getAssistContextExtras failed: no top activity"); |
| 3641 | return null; |
| 3642 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3643 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3644 | Slog.w(TAG, "getAssistContextExtras failed: no process for " + activity); |
| 3645 | return null; |
| 3646 | } |
| 3647 | if (focused) { |
| 3648 | if (activityToken != null) { |
| 3649 | ActivityRecord caller = ActivityRecord.forTokenLocked(activityToken); |
| 3650 | if (activity != caller) { |
| 3651 | Slog.w(TAG, "enqueueAssistContext failed: caller " + caller |
| 3652 | + " is not current top " + activity); |
| 3653 | return null; |
| 3654 | } |
| 3655 | } |
| 3656 | } else { |
| 3657 | activity = ActivityRecord.forTokenLocked(activityToken); |
| 3658 | if (activity == null) { |
| 3659 | Slog.w(TAG, "enqueueAssistContext failed: activity for token=" + activityToken |
| 3660 | + " couldn't be found"); |
| 3661 | return null; |
| 3662 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3663 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3664 | Slog.w(TAG, "enqueueAssistContext failed: no process for " + activity); |
| 3665 | return null; |
| 3666 | } |
| 3667 | } |
| 3668 | |
| 3669 | PendingAssistExtras pae; |
| 3670 | Bundle extras = new Bundle(); |
| 3671 | if (args != null) { |
| 3672 | extras.putAll(args); |
| 3673 | } |
| 3674 | extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3675 | extras.putInt(Intent.EXTRA_ASSIST_UID, activity.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3676 | |
| 3677 | pae = new PendingAssistExtras(activity, extras, intent, hint, receiver, receiverExtras, |
| 3678 | userHandle); |
| 3679 | pae.isHome = activity.isActivityTypeHome(); |
| 3680 | |
| 3681 | // Increment the sessionId if necessary |
| 3682 | if (newSessionId) { |
| 3683 | mViSessionId++; |
| 3684 | } |
| 3685 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3686 | activity.app.getThread().requestAssistContextExtras(activity.appToken, pae, |
| 3687 | requestType, mViSessionId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3688 | mPendingAssistExtras.add(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3689 | mUiHandler.postDelayed(pae, timeout); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3690 | } catch (RemoteException e) { |
| 3691 | Slog.w(TAG, "getAssistContextExtras failed: crash calling " + activity); |
| 3692 | return null; |
| 3693 | } |
| 3694 | return pae; |
| 3695 | } |
| 3696 | } |
| 3697 | |
| 3698 | private void buildAssistBundleLocked(PendingAssistExtras pae, Bundle result) { |
| 3699 | if (result != null) { |
| 3700 | pae.extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, result); |
| 3701 | } |
| 3702 | if (pae.hint != null) { |
| 3703 | pae.extras.putBoolean(pae.hint, true); |
| 3704 | } |
| 3705 | } |
| 3706 | |
| 3707 | private void pendingAssistExtrasTimedOut(PendingAssistExtras pae) { |
| 3708 | IAssistDataReceiver receiver; |
| 3709 | synchronized (mGlobalLock) { |
| 3710 | mPendingAssistExtras.remove(pae); |
| 3711 | receiver = pae.receiver; |
| 3712 | } |
| 3713 | if (receiver != null) { |
| 3714 | // Caller wants result sent back to them. |
| 3715 | Bundle sendBundle = new Bundle(); |
| 3716 | // At least return the receiver extras |
| 3717 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3718 | try { |
| 3719 | pae.receiver.onHandleAssistData(sendBundle); |
| 3720 | } catch (RemoteException e) { |
| 3721 | } |
| 3722 | } |
| 3723 | } |
| 3724 | |
| 3725 | public class PendingAssistExtras extends Binder implements Runnable { |
| 3726 | public final ActivityRecord activity; |
| 3727 | public boolean isHome; |
| 3728 | public final Bundle extras; |
| 3729 | public final Intent intent; |
| 3730 | public final String hint; |
| 3731 | public final IAssistDataReceiver receiver; |
| 3732 | public final int userHandle; |
| 3733 | public boolean haveResult = false; |
| 3734 | public Bundle result = null; |
| 3735 | public AssistStructure structure = null; |
| 3736 | public AssistContent content = null; |
| 3737 | public Bundle receiverExtras; |
| 3738 | |
| 3739 | public PendingAssistExtras(ActivityRecord _activity, Bundle _extras, Intent _intent, |
| 3740 | String _hint, IAssistDataReceiver _receiver, Bundle _receiverExtras, |
| 3741 | int _userHandle) { |
| 3742 | activity = _activity; |
| 3743 | extras = _extras; |
| 3744 | intent = _intent; |
| 3745 | hint = _hint; |
| 3746 | receiver = _receiver; |
| 3747 | receiverExtras = _receiverExtras; |
| 3748 | userHandle = _userHandle; |
| 3749 | } |
| 3750 | |
| 3751 | @Override |
| 3752 | public void run() { |
| 3753 | Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from " + activity); |
| 3754 | synchronized (this) { |
| 3755 | haveResult = true; |
| 3756 | notifyAll(); |
| 3757 | } |
| 3758 | pendingAssistExtrasTimedOut(this); |
| 3759 | } |
| 3760 | } |
| 3761 | |
| 3762 | @Override |
| 3763 | public boolean isAssistDataAllowedOnCurrentActivity() { |
| 3764 | int userId; |
| 3765 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3766 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3767 | if (focusedStack == null || focusedStack.isActivityTypeAssistant()) { |
| 3768 | return false; |
| 3769 | } |
| 3770 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3771 | final ActivityRecord activity = focusedStack.getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3772 | if (activity == null) { |
| 3773 | return false; |
| 3774 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3775 | userId = activity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3776 | } |
| 3777 | return !DevicePolicyCache.getInstance().getScreenCaptureDisabled(userId); |
| 3778 | } |
| 3779 | |
| 3780 | @Override |
| 3781 | public boolean showAssistFromActivity(IBinder token, Bundle args) { |
| 3782 | long ident = Binder.clearCallingIdentity(); |
| 3783 | try { |
| 3784 | synchronized (mGlobalLock) { |
| 3785 | ActivityRecord caller = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 3786 | ActivityRecord top = getTopDisplayFocusedStack().getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3787 | if (top != caller) { |
| 3788 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3789 | + " is not current top " + top); |
| 3790 | return false; |
| 3791 | } |
| 3792 | if (!top.nowVisible) { |
| 3793 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3794 | + " is not visible"); |
| 3795 | return false; |
| 3796 | } |
| 3797 | } |
| 3798 | return mAssistUtils.showSessionForActiveService(args, SHOW_SOURCE_APPLICATION, null, |
| 3799 | token); |
| 3800 | } finally { |
| 3801 | Binder.restoreCallingIdentity(ident); |
| 3802 | } |
| 3803 | } |
| 3804 | |
| 3805 | @Override |
| 3806 | public boolean isRootVoiceInteraction(IBinder token) { |
| 3807 | synchronized (mGlobalLock) { |
| 3808 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3809 | if (r == null) { |
| 3810 | return false; |
| 3811 | } |
| 3812 | return r.rootVoiceInteraction; |
| 3813 | } |
| 3814 | } |
| 3815 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3816 | private void onLocalVoiceInteractionStartedLocked(IBinder activity, |
| 3817 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 3818 | ActivityRecord activityToCallback = ActivityRecord.forTokenLocked(activity); |
| 3819 | if (activityToCallback == null) return; |
| 3820 | activityToCallback.setVoiceSessionLocked(voiceSession); |
| 3821 | |
| 3822 | // Inform the activity |
| 3823 | try { |
| 3824 | activityToCallback.app.getThread().scheduleLocalVoiceInteractionStarted(activity, |
| 3825 | voiceInteractor); |
| 3826 | long token = Binder.clearCallingIdentity(); |
| 3827 | try { |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 3828 | startRunningVoiceLocked(voiceSession, activityToCallback.info.applicationInfo.uid); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3829 | } finally { |
| 3830 | Binder.restoreCallingIdentity(token); |
| 3831 | } |
| 3832 | // TODO: VI Should we cache the activity so that it's easier to find later |
| 3833 | // rather than scan through all the stacks and activities? |
| 3834 | } catch (RemoteException re) { |
| 3835 | activityToCallback.clearVoiceSessionLocked(); |
| 3836 | // TODO: VI Should this terminate the voice session? |
| 3837 | } |
| 3838 | } |
| 3839 | |
| 3840 | private void startRunningVoiceLocked(IVoiceInteractionSession session, int targetUid) { |
| 3841 | Slog.d(TAG, "<<< startRunningVoiceLocked()"); |
| 3842 | mVoiceWakeLock.setWorkSource(new WorkSource(targetUid)); |
| 3843 | if (mRunningVoice == null || mRunningVoice.asBinder() != session.asBinder()) { |
| 3844 | boolean wasRunningVoice = mRunningVoice != null; |
| 3845 | mRunningVoice = session; |
| 3846 | if (!wasRunningVoice) { |
| 3847 | mVoiceWakeLock.acquire(); |
| 3848 | updateSleepIfNeededLocked(); |
| 3849 | } |
| 3850 | } |
| 3851 | } |
| 3852 | |
| 3853 | void finishRunningVoiceLocked() { |
| 3854 | if (mRunningVoice != null) { |
| 3855 | mRunningVoice = null; |
| 3856 | mVoiceWakeLock.release(); |
| 3857 | updateSleepIfNeededLocked(); |
| 3858 | } |
| 3859 | } |
| 3860 | |
| 3861 | @Override |
| 3862 | public void setVoiceKeepAwake(IVoiceInteractionSession session, boolean keepAwake) { |
| 3863 | synchronized (mGlobalLock) { |
| 3864 | if (mRunningVoice != null && mRunningVoice.asBinder() == session.asBinder()) { |
| 3865 | if (keepAwake) { |
| 3866 | mVoiceWakeLock.acquire(); |
| 3867 | } else { |
| 3868 | mVoiceWakeLock.release(); |
| 3869 | } |
| 3870 | } |
| 3871 | } |
| 3872 | } |
| 3873 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3874 | @Override |
| 3875 | public ComponentName getActivityClassForToken(IBinder token) { |
| 3876 | synchronized (mGlobalLock) { |
| 3877 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3878 | if (r == null) { |
| 3879 | return null; |
| 3880 | } |
| 3881 | return r.intent.getComponent(); |
| 3882 | } |
| 3883 | } |
| 3884 | |
| 3885 | @Override |
| 3886 | public String getPackageForToken(IBinder token) { |
| 3887 | synchronized (mGlobalLock) { |
| 3888 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3889 | if (r == null) { |
| 3890 | return null; |
| 3891 | } |
| 3892 | return r.packageName; |
| 3893 | } |
| 3894 | } |
| 3895 | |
| 3896 | @Override |
| 3897 | public void showLockTaskEscapeMessage(IBinder token) { |
| 3898 | synchronized (mGlobalLock) { |
| 3899 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3900 | if (r == null) { |
| 3901 | return; |
| 3902 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3903 | getLockTaskController().showLockTaskToast(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3904 | } |
| 3905 | } |
| 3906 | |
| 3907 | @Override |
| 3908 | public void keyguardGoingAway(int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3909 | enforceNotIsolatedCaller("keyguardGoingAway"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3910 | final long token = Binder.clearCallingIdentity(); |
| 3911 | try { |
| 3912 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3913 | mKeyguardController.keyguardGoingAway(flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3914 | } |
| 3915 | } finally { |
| 3916 | Binder.restoreCallingIdentity(token); |
| 3917 | } |
| 3918 | } |
| 3919 | |
| 3920 | /** |
| 3921 | * Try to place task to provided position. The final position might be different depending on |
| 3922 | * current user and stacks state. The task will be moved to target stack if it's currently in |
| 3923 | * different stack. |
| 3924 | */ |
| 3925 | @Override |
| 3926 | public void positionTaskInStack(int taskId, int stackId, int position) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3927 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "positionTaskInStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3928 | synchronized (mGlobalLock) { |
| 3929 | long ident = Binder.clearCallingIdentity(); |
| 3930 | try { |
| 3931 | if (DEBUG_STACK) Slog.d(TAG_STACK, "positionTaskInStack: positioning task=" |
| 3932 | + taskId + " in stackId=" + stackId + " at position=" + position); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 3933 | final Task task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3934 | if (task == null) { |
| 3935 | throw new IllegalArgumentException("positionTaskInStack: no task for id=" |
| 3936 | + taskId); |
| 3937 | } |
| 3938 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3939 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3940 | |
| 3941 | if (stack == null) { |
| 3942 | throw new IllegalArgumentException("positionTaskInStack: no stack for id=" |
| 3943 | + stackId); |
| 3944 | } |
| 3945 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3946 | throw new IllegalArgumentException("positionTaskInStack: Attempt to change" |
| 3947 | + " the position of task " + taskId + " in/to non-standard stack"); |
| 3948 | } |
| 3949 | |
| 3950 | // TODO: Have the callers of this API call a separate reparent method if that is |
| 3951 | // what they intended to do vs. having this method also do reparenting. |
| 3952 | if (task.getStack() == stack) { |
| 3953 | // Change position in current stack. |
| 3954 | stack.positionChildAt(task, position); |
| 3955 | } else { |
| 3956 | // Reparent to new stack. |
| 3957 | task.reparent(stack, position, REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, |
| 3958 | !DEFER_RESUME, "positionTaskInStack"); |
| 3959 | } |
| 3960 | } finally { |
| 3961 | Binder.restoreCallingIdentity(ident); |
| 3962 | } |
| 3963 | } |
| 3964 | } |
| 3965 | |
| 3966 | @Override |
| 3967 | public void reportSizeConfigurations(IBinder token, int[] horizontalSizeConfiguration, |
| 3968 | int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { |
| 3969 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Report configuration: " + token + " " |
Yuichiro Hanada | e7e930b | 2019-06-06 19:07:21 +0900 | [diff] [blame] | 3970 | + Arrays.toString(horizontalSizeConfiguration) + " " |
| 3971 | + Arrays.toString(verticalSizeConfigurations)); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3972 | synchronized (mGlobalLock) { |
| 3973 | ActivityRecord record = ActivityRecord.isInStackLocked(token); |
| 3974 | if (record == null) { |
| 3975 | throw new IllegalArgumentException("reportSizeConfigurations: ActivityRecord not " |
| 3976 | + "found for: " + token); |
| 3977 | } |
| 3978 | record.setSizeConfigurations(horizontalSizeConfiguration, |
| 3979 | verticalSizeConfigurations, smallestSizeConfigurations); |
| 3980 | } |
| 3981 | } |
| 3982 | |
| 3983 | /** |
| 3984 | * Dismisses split-screen multi-window mode. |
| 3985 | * @param toTop If true the current primary split-screen stack will be placed or left on top. |
| 3986 | */ |
| 3987 | @Override |
| 3988 | public void dismissSplitScreenMode(boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3989 | enforceCallerIsRecentsOrHasPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3990 | MANAGE_ACTIVITY_STACKS, "dismissSplitScreenMode()"); |
| 3991 | final long ident = Binder.clearCallingIdentity(); |
| 3992 | try { |
| 3993 | synchronized (mGlobalLock) { |
| 3994 | final ActivityStack stack = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3995 | mRootActivityContainer.getDefaultDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3996 | if (stack == null) { |
| 3997 | Slog.w(TAG, "dismissSplitScreenMode: primary split-screen stack not found."); |
| 3998 | return; |
| 3999 | } |
| 4000 | |
| 4001 | if (toTop) { |
| 4002 | // Caller wants the current split-screen primary stack to be the top stack after |
| 4003 | // it goes fullscreen, so move it to the front. |
| 4004 | stack.moveToFront("dismissSplitScreenMode"); |
JinsungKim | 6e7fd3e | 2019-06-17 18:31:28 +0900 | [diff] [blame] | 4005 | } else { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4006 | // In this case the current split-screen primary stack shouldn't be the top |
JinsungKim | 6e7fd3e | 2019-06-17 18:31:28 +0900 | [diff] [blame] | 4007 | // stack after it goes fullscreen, so we move the focus to the top-most |
| 4008 | // split-screen secondary stack next to it. |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4009 | final ActivityStack otherStack = stack.getDisplay().getTopStackInWindowingMode( |
| 4010 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 4011 | if (otherStack != null) { |
| 4012 | otherStack.moveToFront("dismissSplitScreenMode_other"); |
| 4013 | } |
| 4014 | } |
| 4015 | |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 4016 | stack.setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4017 | } |
| 4018 | } finally { |
| 4019 | Binder.restoreCallingIdentity(ident); |
| 4020 | } |
| 4021 | } |
| 4022 | |
| 4023 | /** |
| 4024 | * Dismisses Pip |
| 4025 | * @param animate True if the dismissal should be animated. |
| 4026 | * @param animationDuration The duration of the resize animation in milliseconds or -1 if the |
| 4027 | * default animation duration should be used. |
| 4028 | */ |
| 4029 | @Override |
| 4030 | public void dismissPip(boolean animate, int animationDuration) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4031 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "dismissPip()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4032 | final long ident = Binder.clearCallingIdentity(); |
| 4033 | try { |
| 4034 | synchronized (mGlobalLock) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 4035 | final ActivityStack stack = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4036 | mRootActivityContainer.getDefaultDisplay().getPinnedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4037 | if (stack == null) { |
| 4038 | Slog.w(TAG, "dismissPip: pinned stack not found."); |
| 4039 | return; |
| 4040 | } |
| 4041 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 4042 | throw new IllegalArgumentException("Stack: " + stack |
| 4043 | + " doesn't support animated resize."); |
| 4044 | } |
| 4045 | if (animate) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4046 | stack.animateResizePinnedStack(null /* destBounds */, |
| 4047 | null /* sourceHintBounds */, animationDuration, |
| 4048 | false /* fromFullscreen */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4049 | } else { |
Ben Lin | 6db8fb2 | 2019-10-18 16:03:44 -0700 | [diff] [blame] | 4050 | stack.dismissPip(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4051 | } |
| 4052 | } |
| 4053 | } finally { |
| 4054 | Binder.restoreCallingIdentity(ident); |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | @Override |
| 4059 | public void suppressResizeConfigChanges(boolean suppress) throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4060 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "suppressResizeConfigChanges()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4061 | synchronized (mGlobalLock) { |
| 4062 | mSuppressResizeConfigChanges = suppress; |
| 4063 | } |
| 4064 | } |
| 4065 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4066 | @Override |
| 4067 | // TODO: API should just be about changing windowing modes... |
| 4068 | public void moveTasksToFullscreenStack(int fromStackId, boolean onTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4069 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4070 | "moveTasksToFullscreenStack()"); |
| 4071 | synchronized (mGlobalLock) { |
| 4072 | final long origId = Binder.clearCallingIdentity(); |
| 4073 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4074 | final ActivityStack stack = mRootActivityContainer.getStack(fromStackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4075 | if (stack != null){ |
| 4076 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 4077 | throw new IllegalArgumentException( |
| 4078 | "You can't move tasks from non-standard stacks."); |
| 4079 | } |
| 4080 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, onTop); |
| 4081 | } |
| 4082 | } finally { |
| 4083 | Binder.restoreCallingIdentity(origId); |
| 4084 | } |
| 4085 | } |
| 4086 | } |
| 4087 | |
| 4088 | /** |
| 4089 | * Moves the top activity in the input stackId to the pinned stack. |
| 4090 | * |
| 4091 | * @param stackId Id of stack to move the top activity to pinned stack. |
| 4092 | * @param bounds Bounds to use for pinned stack. |
| 4093 | * |
| 4094 | * @return True if the top activity of the input stack was successfully moved to the pinned |
| 4095 | * stack. |
| 4096 | */ |
| 4097 | @Override |
| 4098 | public boolean moveTopActivityToPinnedStack(int stackId, Rect bounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4099 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4100 | "moveTopActivityToPinnedStack()"); |
| 4101 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4102 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4103 | throw new IllegalStateException("moveTopActivityToPinnedStack:" |
| 4104 | + "Device doesn't support picture-in-picture mode"); |
| 4105 | } |
| 4106 | |
| 4107 | long ident = Binder.clearCallingIdentity(); |
| 4108 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4109 | return mRootActivityContainer.moveTopStackActivityToPinnedStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4110 | } finally { |
| 4111 | Binder.restoreCallingIdentity(ident); |
| 4112 | } |
| 4113 | } |
| 4114 | } |
| 4115 | |
| 4116 | @Override |
| 4117 | public boolean isInMultiWindowMode(IBinder token) { |
| 4118 | final long origId = Binder.clearCallingIdentity(); |
| 4119 | try { |
| 4120 | synchronized (mGlobalLock) { |
| 4121 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4122 | if (r == null) { |
| 4123 | return false; |
| 4124 | } |
| 4125 | // An activity is consider to be in multi-window mode if its task isn't fullscreen. |
| 4126 | return r.inMultiWindowMode(); |
| 4127 | } |
| 4128 | } finally { |
| 4129 | Binder.restoreCallingIdentity(origId); |
| 4130 | } |
| 4131 | } |
| 4132 | |
| 4133 | @Override |
| 4134 | public boolean isInPictureInPictureMode(IBinder token) { |
| 4135 | final long origId = Binder.clearCallingIdentity(); |
| 4136 | try { |
| 4137 | synchronized (mGlobalLock) { |
| 4138 | return isInPictureInPictureMode(ActivityRecord.forTokenLocked(token)); |
| 4139 | } |
| 4140 | } finally { |
| 4141 | Binder.restoreCallingIdentity(origId); |
| 4142 | } |
| 4143 | } |
| 4144 | |
| 4145 | private boolean isInPictureInPictureMode(ActivityRecord r) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4146 | if (r == null || r.getActivityStack() == null || !r.inPinnedWindowingMode() |
| 4147 | || r.getActivityStack().isInStackLocked(r) == null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4148 | return false; |
| 4149 | } |
| 4150 | |
| 4151 | // If we are animating to fullscreen then we have already dispatched the PIP mode |
| 4152 | // changed, so we should reflect that check here as well. |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 4153 | final ActivityStack taskStack = r.getActivityStack(); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 4154 | return !taskStack.isAnimatingBoundsToFullscreen(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4155 | } |
| 4156 | |
| 4157 | @Override |
| 4158 | public boolean enterPictureInPictureMode(IBinder token, final PictureInPictureParams params) { |
| 4159 | final long origId = Binder.clearCallingIdentity(); |
| 4160 | try { |
| 4161 | synchronized (mGlobalLock) { |
| 4162 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 4163 | "enterPictureInPictureMode", token, params); |
| 4164 | |
| 4165 | // If the activity is already in picture in picture mode, then just return early |
| 4166 | if (isInPictureInPictureMode(r)) { |
| 4167 | return true; |
| 4168 | } |
| 4169 | |
| 4170 | // Activity supports picture-in-picture, now check that we can enter PiP at this |
| 4171 | // point, if it is |
| 4172 | if (!r.checkEnterPictureInPictureState("enterPictureInPictureMode", |
| 4173 | false /* beforeStopping */)) { |
| 4174 | return false; |
| 4175 | } |
| 4176 | |
| 4177 | final Runnable enterPipRunnable = () -> { |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4178 | synchronized (mGlobalLock) { |
| 4179 | // Only update the saved args from the args that are set |
| 4180 | r.pictureInPictureArgs.copyOnlySet(params); |
| 4181 | final float aspectRatio = r.pictureInPictureArgs.getAspectRatio(); |
| 4182 | final List<RemoteAction> actions = r.pictureInPictureArgs.getActions(); |
| 4183 | // Adjust the source bounds by the insets for the transition down |
| 4184 | final Rect sourceBounds = new Rect( |
| 4185 | r.pictureInPictureArgs.getSourceRectHint()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4186 | mRootActivityContainer.moveActivityToPinnedStack( |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4187 | r, sourceBounds, aspectRatio, "enterPictureInPictureMode"); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 4188 | final ActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4189 | stack.setPictureInPictureAspectRatio(aspectRatio); |
| 4190 | stack.setPictureInPictureActions(actions); |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 4191 | MetricsLoggerWrapper.logPictureInPictureEnter(mContext, |
| 4192 | r.info.applicationInfo.uid, r.shortComponentName, |
| 4193 | r.supportsEnterPipOnTaskSwitch); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4194 | logPictureInPictureArgs(params); |
| 4195 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4196 | }; |
| 4197 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4198 | if (isKeyguardLocked()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4199 | // If the keyguard is showing or occluded, then try and dismiss it before |
| 4200 | // entering picture-in-picture (this will prompt the user to authenticate if the |
| 4201 | // device is currently locked). |
| 4202 | dismissKeyguard(token, new KeyguardDismissCallback() { |
| 4203 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4204 | public void onDismissSucceeded() { |
| 4205 | mH.post(enterPipRunnable); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4206 | } |
| 4207 | }, null /* message */); |
| 4208 | } else { |
| 4209 | // Enter picture in picture immediately otherwise |
| 4210 | enterPipRunnable.run(); |
| 4211 | } |
| 4212 | return true; |
| 4213 | } |
| 4214 | } finally { |
| 4215 | Binder.restoreCallingIdentity(origId); |
| 4216 | } |
| 4217 | } |
| 4218 | |
| 4219 | @Override |
| 4220 | public void setPictureInPictureParams(IBinder token, final PictureInPictureParams params) { |
| 4221 | final long origId = Binder.clearCallingIdentity(); |
| 4222 | try { |
| 4223 | synchronized (mGlobalLock) { |
| 4224 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 4225 | "setPictureInPictureParams", token, params); |
| 4226 | |
| 4227 | // Only update the saved args from the args that are set |
| 4228 | r.pictureInPictureArgs.copyOnlySet(params); |
| 4229 | if (r.inPinnedWindowingMode()) { |
| 4230 | // If the activity is already in picture-in-picture, update the pinned stack now |
| 4231 | // if it is not already expanding to fullscreen. Otherwise, the arguments will |
| 4232 | // be used the next time the activity enters PiP |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 4233 | final ActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4234 | if (!stack.isAnimatingBoundsToFullscreen()) { |
| 4235 | stack.setPictureInPictureAspectRatio( |
| 4236 | r.pictureInPictureArgs.getAspectRatio()); |
| 4237 | stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions()); |
| 4238 | } |
| 4239 | } |
| 4240 | logPictureInPictureArgs(params); |
| 4241 | } |
| 4242 | } finally { |
| 4243 | Binder.restoreCallingIdentity(origId); |
| 4244 | } |
| 4245 | } |
| 4246 | |
| 4247 | @Override |
| 4248 | public int getMaxNumPictureInPictureActions(IBinder token) { |
| 4249 | // Currently, this is a static constant, but later, we may change this to be dependent on |
| 4250 | // the context of the activity |
| 4251 | return 3; |
| 4252 | } |
| 4253 | |
| 4254 | private void logPictureInPictureArgs(PictureInPictureParams params) { |
| 4255 | if (params.hasSetActions()) { |
| 4256 | MetricsLogger.histogram(mContext, "tron_varz_picture_in_picture_actions_count", |
| 4257 | params.getActions().size()); |
| 4258 | } |
| 4259 | if (params.hasSetAspectRatio()) { |
| 4260 | LogMaker lm = new LogMaker(MetricsEvent.ACTION_PICTURE_IN_PICTURE_ASPECT_RATIO_CHANGED); |
| 4261 | lm.addTaggedData(MetricsEvent.PICTURE_IN_PICTURE_ASPECT_RATIO, params.getAspectRatio()); |
| 4262 | MetricsLogger.action(lm); |
| 4263 | } |
| 4264 | } |
| 4265 | |
| 4266 | /** |
| 4267 | * Checks the state of the system and the activity associated with the given {@param token} to |
| 4268 | * verify that picture-in-picture is supported for that activity. |
| 4269 | * |
| 4270 | * @return the activity record for the given {@param token} if all the checks pass. |
| 4271 | */ |
| 4272 | private ActivityRecord ensureValidPictureInPictureActivityParamsLocked(String caller, |
| 4273 | IBinder token, PictureInPictureParams params) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4274 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4275 | throw new IllegalStateException(caller |
| 4276 | + ": Device doesn't support picture-in-picture mode."); |
| 4277 | } |
| 4278 | |
| 4279 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 4280 | if (r == null) { |
| 4281 | throw new IllegalStateException(caller |
| 4282 | + ": Can't find activity for token=" + token); |
| 4283 | } |
| 4284 | |
| 4285 | if (!r.supportsPictureInPicture()) { |
| 4286 | throw new IllegalStateException(caller |
| 4287 | + ": Current activity does not support picture-in-picture."); |
| 4288 | } |
| 4289 | |
| 4290 | if (params.hasSetAspectRatio() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4291 | && !mWindowManager.isValidPictureInPictureAspectRatio( |
| 4292 | r.getActivityStack().mDisplayId, params.getAspectRatio())) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4293 | final float minAspectRatio = mContext.getResources().getFloat( |
| 4294 | com.android.internal.R.dimen.config_pictureInPictureMinAspectRatio); |
| 4295 | final float maxAspectRatio = mContext.getResources().getFloat( |
| 4296 | com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio); |
| 4297 | throw new IllegalArgumentException(String.format(caller |
| 4298 | + ": Aspect ratio is too extreme (must be between %f and %f).", |
| 4299 | minAspectRatio, maxAspectRatio)); |
| 4300 | } |
| 4301 | |
| 4302 | // Truncate the number of actions if necessary |
| 4303 | params.truncateActions(getMaxNumPictureInPictureActions(token)); |
| 4304 | |
| 4305 | return r; |
| 4306 | } |
| 4307 | |
| 4308 | @Override |
| 4309 | public IBinder getUriPermissionOwnerForActivity(IBinder activityToken) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4310 | enforceNotIsolatedCaller("getUriPermissionOwnerForActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4311 | synchronized (mGlobalLock) { |
| 4312 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 4313 | if (r == null) { |
| 4314 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 4315 | + activityToken); |
| 4316 | } |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 4317 | return r.getUriPermissionsLocked().getExternalToken(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4318 | } |
| 4319 | } |
| 4320 | |
| 4321 | @Override |
| 4322 | public void resizeDockedStack(Rect dockedBounds, Rect tempDockedTaskBounds, |
| 4323 | Rect tempDockedTaskInsetBounds, |
| 4324 | Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4325 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeDockedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4326 | long ident = Binder.clearCallingIdentity(); |
| 4327 | try { |
| 4328 | synchronized (mGlobalLock) { |
| 4329 | mStackSupervisor.resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, |
| 4330 | tempDockedTaskInsetBounds, tempOtherTaskBounds, tempOtherTaskInsetBounds, |
| 4331 | PRESERVE_WINDOWS); |
| 4332 | } |
| 4333 | } finally { |
| 4334 | Binder.restoreCallingIdentity(ident); |
| 4335 | } |
| 4336 | } |
| 4337 | |
| 4338 | @Override |
| 4339 | public void setSplitScreenResizing(boolean resizing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4340 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setSplitScreenResizing()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4341 | final long ident = Binder.clearCallingIdentity(); |
| 4342 | try { |
| 4343 | synchronized (mGlobalLock) { |
| 4344 | mStackSupervisor.setSplitScreenResizing(resizing); |
| 4345 | } |
| 4346 | } finally { |
| 4347 | Binder.restoreCallingIdentity(ident); |
| 4348 | } |
| 4349 | } |
| 4350 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4351 | /** |
| 4352 | * Check that we have the features required for VR-related API calls, and throw an exception if |
| 4353 | * not. |
| 4354 | */ |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 4355 | public void enforceSystemHasVrFeature() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4356 | if (!mContext.getPackageManager().hasSystemFeature( |
| 4357 | PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE)) { |
| 4358 | throw new UnsupportedOperationException("VR mode not supported on this device!"); |
| 4359 | } |
| 4360 | } |
| 4361 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4362 | @Override |
| 4363 | public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4364 | enforceSystemHasVrFeature(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4365 | |
| 4366 | final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class); |
| 4367 | |
| 4368 | ActivityRecord r; |
| 4369 | synchronized (mGlobalLock) { |
| 4370 | r = ActivityRecord.isInStackLocked(token); |
| 4371 | } |
| 4372 | |
| 4373 | if (r == null) { |
| 4374 | throw new IllegalArgumentException(); |
| 4375 | } |
| 4376 | |
| 4377 | int err; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4378 | if ((err = vrService.hasVrPackage(packageName, r.mUserId)) != |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4379 | VrManagerInternal.NO_ERROR) { |
| 4380 | return err; |
| 4381 | } |
| 4382 | |
| 4383 | // Clear the binder calling uid since this path may call moveToTask(). |
| 4384 | final long callingId = Binder.clearCallingIdentity(); |
| 4385 | try { |
| 4386 | synchronized (mGlobalLock) { |
| 4387 | r.requestedVrComponent = (enabled) ? packageName : null; |
| 4388 | |
| 4389 | // Update associated state if this activity is currently focused |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 4390 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4391 | applyUpdateVrModeLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4392 | } |
| 4393 | return 0; |
| 4394 | } |
| 4395 | } finally { |
| 4396 | Binder.restoreCallingIdentity(callingId); |
| 4397 | } |
| 4398 | } |
| 4399 | |
| 4400 | @Override |
| 4401 | public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) { |
| 4402 | Slog.i(TAG, "Activity tried to startLocalVoiceInteraction"); |
| 4403 | synchronized (mGlobalLock) { |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 4404 | ActivityRecord activity = getTopDisplayFocusedStack().getTopNonFinishingActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4405 | if (ActivityRecord.forTokenLocked(callingActivity) != activity) { |
| 4406 | throw new SecurityException("Only focused activity can call startVoiceInteraction"); |
| 4407 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4408 | if (mRunningVoice != null || activity.getTask().voiceSession != null |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4409 | || activity.voiceSession != null) { |
| 4410 | Slog.w(TAG, "Already in a voice interaction, cannot start new voice interaction"); |
| 4411 | return; |
| 4412 | } |
| 4413 | if (activity.pendingVoiceInteractionStart) { |
| 4414 | Slog.w(TAG, "Pending start of voice interaction already."); |
| 4415 | return; |
| 4416 | } |
| 4417 | activity.pendingVoiceInteractionStart = true; |
| 4418 | } |
| 4419 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4420 | .startLocalVoiceInteraction(callingActivity, options); |
| 4421 | } |
| 4422 | |
| 4423 | @Override |
| 4424 | public void stopLocalVoiceInteraction(IBinder callingActivity) { |
| 4425 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4426 | .stopLocalVoiceInteraction(callingActivity); |
| 4427 | } |
| 4428 | |
| 4429 | @Override |
| 4430 | public boolean supportsLocalVoiceInteraction() { |
| 4431 | return LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4432 | .supportsLocalVoiceInteraction(); |
| 4433 | } |
| 4434 | |
| 4435 | /** Notifies all listeners when the pinned stack animation starts. */ |
| 4436 | @Override |
| 4437 | public void notifyPinnedStackAnimationStarted() { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4438 | mTaskChangeNotificationController.notifyPinnedStackAnimationStarted(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4439 | } |
| 4440 | |
| 4441 | /** Notifies all listeners when the pinned stack animation ends. */ |
| 4442 | @Override |
| 4443 | public void notifyPinnedStackAnimationEnded() { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4444 | mTaskChangeNotificationController.notifyPinnedStackAnimationEnded(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | @Override |
| 4448 | public void resizePinnedStack(Rect pinnedBounds, Rect tempPinnedTaskBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4449 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizePinnedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4450 | final long ident = Binder.clearCallingIdentity(); |
| 4451 | try { |
| 4452 | synchronized (mGlobalLock) { |
| 4453 | mStackSupervisor.resizePinnedStackLocked(pinnedBounds, tempPinnedTaskBounds); |
| 4454 | } |
| 4455 | } finally { |
| 4456 | Binder.restoreCallingIdentity(ident); |
| 4457 | } |
| 4458 | } |
| 4459 | |
| 4460 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4461 | public boolean updateConfiguration(Configuration values) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4462 | mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateConfiguration()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4463 | |
| 4464 | synchronized (mGlobalLock) { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 4465 | if (mWindowManager == null) { |
| 4466 | Slog.w(TAG, "Skip updateConfiguration because mWindowManager isn't set"); |
| 4467 | return false; |
| 4468 | } |
| 4469 | |
| 4470 | if (values == null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4471 | // sentinel: fetch the current configuration from the window manager |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4472 | values = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4473 | } |
| 4474 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 4475 | mH.sendMessage(PooledLambda.obtainMessage( |
| 4476 | ActivityManagerInternal::updateOomLevelsForDisplay, mAmInternal, |
| 4477 | DEFAULT_DISPLAY)); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4478 | |
| 4479 | final long origId = Binder.clearCallingIdentity(); |
| 4480 | try { |
| 4481 | if (values != null) { |
| 4482 | Settings.System.clearConfiguration(values); |
| 4483 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4484 | updateConfigurationLocked(values, null, false, false /* persistent */, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4485 | UserHandle.USER_NULL, false /* deferResume */, |
| 4486 | mTmpUpdateConfigurationResult); |
| 4487 | return mTmpUpdateConfigurationResult.changes != 0; |
| 4488 | } finally { |
| 4489 | Binder.restoreCallingIdentity(origId); |
| 4490 | } |
| 4491 | } |
| 4492 | } |
| 4493 | |
| 4494 | @Override |
| 4495 | public void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback, |
| 4496 | CharSequence message) { |
| 4497 | if (message != null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4498 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4499 | Manifest.permission.SHOW_KEYGUARD_MESSAGE, "dismissKeyguard()"); |
| 4500 | } |
| 4501 | final long callingId = Binder.clearCallingIdentity(); |
| 4502 | try { |
| 4503 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4504 | mKeyguardController.dismissKeyguard(token, callback, message); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4505 | } |
| 4506 | } finally { |
| 4507 | Binder.restoreCallingIdentity(callingId); |
| 4508 | } |
| 4509 | } |
| 4510 | |
| 4511 | @Override |
| 4512 | public void cancelTaskWindowTransition(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4513 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4514 | "cancelTaskWindowTransition()"); |
| 4515 | final long ident = Binder.clearCallingIdentity(); |
| 4516 | try { |
| 4517 | synchronized (mGlobalLock) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4518 | final Task task = mRootActivityContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4519 | MATCH_TASK_IN_STACKS_ONLY); |
| 4520 | if (task == null) { |
| 4521 | Slog.w(TAG, "cancelTaskWindowTransition: taskId=" + taskId + " not found"); |
| 4522 | return; |
| 4523 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 4524 | task.cancelTaskWindowTransition(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4525 | } |
| 4526 | } finally { |
| 4527 | Binder.restoreCallingIdentity(ident); |
| 4528 | } |
| 4529 | } |
| 4530 | |
| 4531 | @Override |
| 4532 | public ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4533 | enforceCallerIsRecentsOrHasPermission(READ_FRAME_BUFFER, "getTaskSnapshot()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4534 | final long ident = Binder.clearCallingIdentity(); |
| 4535 | try { |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4536 | return getTaskSnapshot(taskId, reducedResolution, true /* restoreFromDisk */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4537 | } finally { |
| 4538 | Binder.restoreCallingIdentity(ident); |
| 4539 | } |
| 4540 | } |
| 4541 | |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4542 | private ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution, |
| 4543 | boolean restoreFromDisk) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4544 | final Task task; |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4545 | synchronized (mGlobalLock) { |
| 4546 | task = mRootActivityContainer.anyTaskForId(taskId, |
| 4547 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 4548 | if (task == null) { |
| 4549 | Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found"); |
| 4550 | return null; |
| 4551 | } |
| 4552 | } |
| 4553 | // Don't call this while holding the lock as this operation might hit the disk. |
| 4554 | return task.getSnapshot(reducedResolution, restoreFromDisk); |
| 4555 | } |
| 4556 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4557 | @Override |
| 4558 | public void setDisablePreviewScreenshots(IBinder token, boolean disable) { |
| 4559 | synchronized (mGlobalLock) { |
| 4560 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4561 | if (r == null) { |
| 4562 | Slog.w(TAG, "setDisablePreviewScreenshots: Unable to find activity for token=" |
| 4563 | + token); |
| 4564 | return; |
| 4565 | } |
| 4566 | final long origId = Binder.clearCallingIdentity(); |
| 4567 | try { |
| 4568 | r.setDisablePreviewScreenshots(disable); |
| 4569 | } finally { |
| 4570 | Binder.restoreCallingIdentity(origId); |
| 4571 | } |
| 4572 | } |
| 4573 | } |
| 4574 | |
Riddle Hsu | 440f88b | 2019-11-06 22:17:35 +0800 | [diff] [blame] | 4575 | @Override |
| 4576 | public void invalidateHomeTaskSnapshot(IBinder token) { |
| 4577 | synchronized (mGlobalLock) { |
| 4578 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4579 | if (r == null || !r.isActivityTypeHome()) { |
| 4580 | return; |
| 4581 | } |
| 4582 | mWindowManager.mTaskSnapshotController.removeSnapshotCache(r.getTask().mTaskId); |
| 4583 | } |
| 4584 | } |
| 4585 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4586 | /** Return the user id of the last resumed activity. */ |
| 4587 | @Override |
| 4588 | public @UserIdInt |
| 4589 | int getLastResumedActivityUserId() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4590 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4591 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, "getLastResumedActivityUserId()"); |
| 4592 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4593 | if (mLastResumedActivity == null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4594 | return getCurrentUserId(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4595 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4596 | return mLastResumedActivity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4597 | } |
| 4598 | } |
| 4599 | |
| 4600 | @Override |
| 4601 | public void updateLockTaskFeatures(int userId, int flags) { |
| 4602 | final int callingUid = Binder.getCallingUid(); |
| 4603 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4604 | mAmInternal.enforceCallingPermission(android.Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4605 | "updateLockTaskFeatures()"); |
| 4606 | } |
| 4607 | synchronized (mGlobalLock) { |
| 4608 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Allowing features " + userId + ":0x" + |
| 4609 | Integer.toHexString(flags)); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 4610 | getLockTaskController().updateLockTaskFeatures(userId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4611 | } |
| 4612 | } |
| 4613 | |
| 4614 | @Override |
| 4615 | public void setShowWhenLocked(IBinder token, boolean showWhenLocked) { |
| 4616 | synchronized (mGlobalLock) { |
| 4617 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4618 | if (r == null) { |
| 4619 | return; |
| 4620 | } |
| 4621 | final long origId = Binder.clearCallingIdentity(); |
| 4622 | try { |
| 4623 | r.setShowWhenLocked(showWhenLocked); |
| 4624 | } finally { |
| 4625 | Binder.restoreCallingIdentity(origId); |
| 4626 | } |
| 4627 | } |
| 4628 | } |
| 4629 | |
| 4630 | @Override |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 4631 | public void setInheritShowWhenLocked(IBinder token, boolean inheritShowWhenLocked) { |
| 4632 | synchronized (mGlobalLock) { |
| 4633 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4634 | if (r == null) { |
| 4635 | return; |
| 4636 | } |
| 4637 | final long origId = Binder.clearCallingIdentity(); |
| 4638 | try { |
| 4639 | r.setInheritShowWhenLocked(inheritShowWhenLocked); |
| 4640 | } finally { |
| 4641 | Binder.restoreCallingIdentity(origId); |
| 4642 | } |
| 4643 | } |
| 4644 | } |
| 4645 | |
| 4646 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4647 | public void setTurnScreenOn(IBinder token, boolean turnScreenOn) { |
| 4648 | synchronized (mGlobalLock) { |
| 4649 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4650 | if (r == null) { |
| 4651 | return; |
| 4652 | } |
| 4653 | final long origId = Binder.clearCallingIdentity(); |
| 4654 | try { |
| 4655 | r.setTurnScreenOn(turnScreenOn); |
| 4656 | } finally { |
| 4657 | Binder.restoreCallingIdentity(origId); |
| 4658 | } |
| 4659 | } |
| 4660 | } |
| 4661 | |
| 4662 | @Override |
| 4663 | public void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4664 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4665 | "registerRemoteAnimations"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4666 | definition.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4667 | synchronized (mGlobalLock) { |
| 4668 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4669 | if (r == null) { |
| 4670 | return; |
| 4671 | } |
| 4672 | final long origId = Binder.clearCallingIdentity(); |
| 4673 | try { |
| 4674 | r.registerRemoteAnimations(definition); |
| 4675 | } finally { |
| 4676 | Binder.restoreCallingIdentity(origId); |
| 4677 | } |
| 4678 | } |
| 4679 | } |
| 4680 | |
| 4681 | @Override |
| 4682 | public void registerRemoteAnimationForNextActivityStart(String packageName, |
| 4683 | RemoteAnimationAdapter adapter) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4684 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4685 | "registerRemoteAnimationForNextActivityStart"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4686 | adapter.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4687 | synchronized (mGlobalLock) { |
| 4688 | final long origId = Binder.clearCallingIdentity(); |
| 4689 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4690 | getActivityStartController().registerRemoteAnimationForNextActivityStart( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4691 | packageName, adapter); |
| 4692 | } finally { |
| 4693 | Binder.restoreCallingIdentity(origId); |
| 4694 | } |
| 4695 | } |
| 4696 | } |
| 4697 | |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4698 | @Override |
| 4699 | public void registerRemoteAnimationsForDisplay(int displayId, |
| 4700 | RemoteAnimationDefinition definition) { |
| 4701 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
| 4702 | "registerRemoteAnimations"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4703 | definition.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4704 | synchronized (mGlobalLock) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 4705 | final DisplayContent display = mRootActivityContainer.getDisplayContent(displayId); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4706 | if (display == null) { |
| 4707 | Slog.e(TAG, "Couldn't find display with id: " + displayId); |
| 4708 | return; |
| 4709 | } |
| 4710 | final long origId = Binder.clearCallingIdentity(); |
| 4711 | try { |
| 4712 | display.mDisplayContent.registerRemoteAnimations(definition); |
| 4713 | } finally { |
| 4714 | Binder.restoreCallingIdentity(origId); |
| 4715 | } |
| 4716 | } |
| 4717 | } |
| 4718 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4719 | /** @see android.app.ActivityManager#alwaysShowUnsupportedCompileSdkWarning */ |
| 4720 | @Override |
| 4721 | public void alwaysShowUnsupportedCompileSdkWarning(ComponentName activity) { |
| 4722 | synchronized (mGlobalLock) { |
| 4723 | final long origId = Binder.clearCallingIdentity(); |
| 4724 | try { |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 4725 | mAppWarnings.alwaysShowUnsupportedCompileSdkWarning(activity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4726 | } finally { |
| 4727 | Binder.restoreCallingIdentity(origId); |
| 4728 | } |
| 4729 | } |
| 4730 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 4731 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4732 | @Override |
| 4733 | public void setVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4734 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4735 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4736 | final int pid = Binder.getCallingPid(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 4737 | final WindowProcessController wpc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4738 | mVrController.setVrThreadLocked(tid, pid, wpc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4739 | } |
| 4740 | } |
| 4741 | |
| 4742 | @Override |
| 4743 | public void setPersistentVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4744 | if (checkCallingPermission(Manifest.permission.RESTRICTED_VR_ACCESS) |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4745 | != PERMISSION_GRANTED) { |
| 4746 | final String msg = "Permission Denial: setPersistentVrThread() from pid=" |
| 4747 | + Binder.getCallingPid() |
| 4748 | + ", uid=" + Binder.getCallingUid() |
| 4749 | + " requires " + Manifest.permission.RESTRICTED_VR_ACCESS; |
| 4750 | Slog.w(TAG, msg); |
| 4751 | throw new SecurityException(msg); |
| 4752 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4753 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4754 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4755 | final int pid = Binder.getCallingPid(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 4756 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4757 | mVrController.setPersistentVrThreadLocked(tid, pid, proc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4758 | } |
| 4759 | } |
| 4760 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4761 | @Override |
| 4762 | public void stopAppSwitches() { |
| 4763 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "stopAppSwitches"); |
| 4764 | synchronized (mGlobalLock) { |
| 4765 | mAppSwitchesAllowedTime = SystemClock.uptimeMillis() + APP_SWITCH_DELAY_TIME; |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 4766 | mLastStopAppSwitchesTime = SystemClock.uptimeMillis(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4767 | mDidAppSwitch = false; |
| 4768 | getActivityStartController().schedulePendingActivityLaunches(APP_SWITCH_DELAY_TIME); |
| 4769 | } |
| 4770 | } |
| 4771 | |
| 4772 | @Override |
| 4773 | public void resumeAppSwitches() { |
| 4774 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "resumeAppSwitches"); |
| 4775 | synchronized (mGlobalLock) { |
| 4776 | // Note that we don't execute any pending app switches... we will |
| 4777 | // let those wait until either the timeout, or the next start |
| 4778 | // activity request. |
| 4779 | mAppSwitchesAllowedTime = 0; |
| 4780 | } |
| 4781 | } |
| 4782 | |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 4783 | long getLastStopAppSwitchesTime() { |
| 4784 | return mLastStopAppSwitchesTime; |
| 4785 | } |
| 4786 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4787 | void onStartActivitySetDidAppSwitch() { |
| 4788 | if (mDidAppSwitch) { |
| 4789 | // This is the second allowed switch since we stopped switches, so now just generally |
| 4790 | // allow switches. Use case: |
| 4791 | // - user presses home (switches disabled, switch to home, mDidAppSwitch now true); |
| 4792 | // - user taps a home icon (coming from home so allowed, we hit here and now allow |
| 4793 | // anyone to switch again). |
| 4794 | mAppSwitchesAllowedTime = 0; |
| 4795 | } else { |
| 4796 | mDidAppSwitch = true; |
| 4797 | } |
| 4798 | } |
| 4799 | |
| 4800 | /** @return whether the system should disable UI modes incompatible with VR mode. */ |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4801 | boolean shouldDisableNonVrUiLocked() { |
| 4802 | return mVrController.shouldDisableNonVrUiLocked(); |
| 4803 | } |
| 4804 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4805 | private void applyUpdateVrModeLocked(ActivityRecord r) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4806 | // 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] | 4807 | // 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] | 4808 | if (r.requestedVrComponent != null && r.getDisplayId() != DEFAULT_DISPLAY) { |
Wale Ogunwale | b8e6b63 | 2019-06-28 15:19:25 +0000 | [diff] [blame] | 4809 | Slog.i(TAG, "Moving " + r.shortComponentName + " from display " + r.getDisplayId() |
| 4810 | + " to main display for VR"); |
| 4811 | mRootActivityContainer.moveStackToDisplay( |
| 4812 | r.getStackId(), DEFAULT_DISPLAY, true /* toTop */); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4813 | } |
| 4814 | mH.post(() -> { |
| 4815 | if (!mVrController.onVrModeChanged(r)) { |
| 4816 | return; |
| 4817 | } |
| 4818 | synchronized (mGlobalLock) { |
| 4819 | final boolean disableNonVrUi = mVrController.shouldDisableNonVrUiLocked(); |
| 4820 | mWindowManager.disableNonVrUi(disableNonVrUi); |
| 4821 | if (disableNonVrUi) { |
| 4822 | // If we are in a VR mode where Picture-in-Picture mode is unsupported, |
| 4823 | // then remove the pinned stack. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4824 | mRootActivityContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4825 | } |
| 4826 | } |
| 4827 | }); |
| 4828 | } |
| 4829 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4830 | @Override |
| 4831 | public int getPackageScreenCompatMode(String packageName) { |
| 4832 | enforceNotIsolatedCaller("getPackageScreenCompatMode"); |
| 4833 | synchronized (mGlobalLock) { |
| 4834 | return mCompatModePackages.getPackageScreenCompatModeLocked(packageName); |
| 4835 | } |
| 4836 | } |
| 4837 | |
| 4838 | @Override |
| 4839 | public void setPackageScreenCompatMode(String packageName, int mode) { |
| 4840 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4841 | "setPackageScreenCompatMode"); |
| 4842 | synchronized (mGlobalLock) { |
| 4843 | mCompatModePackages.setPackageScreenCompatModeLocked(packageName, mode); |
| 4844 | } |
| 4845 | } |
| 4846 | |
| 4847 | @Override |
| 4848 | public boolean getPackageAskScreenCompat(String packageName) { |
| 4849 | enforceNotIsolatedCaller("getPackageAskScreenCompat"); |
| 4850 | synchronized (mGlobalLock) { |
| 4851 | return mCompatModePackages.getPackageAskCompatModeLocked(packageName); |
| 4852 | } |
| 4853 | } |
| 4854 | |
| 4855 | @Override |
| 4856 | public void setPackageAskScreenCompat(String packageName, boolean ask) { |
| 4857 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4858 | "setPackageAskScreenCompat"); |
| 4859 | synchronized (mGlobalLock) { |
| 4860 | mCompatModePackages.setPackageAskCompatModeLocked(packageName, ask); |
| 4861 | } |
| 4862 | } |
| 4863 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 4864 | public static String relaunchReasonToString(int relaunchReason) { |
| 4865 | switch (relaunchReason) { |
| 4866 | case RELAUNCH_REASON_WINDOWING_MODE_RESIZE: |
| 4867 | return "window_resize"; |
| 4868 | case RELAUNCH_REASON_FREE_RESIZE: |
| 4869 | return "free_resize"; |
| 4870 | default: |
| 4871 | return null; |
| 4872 | } |
| 4873 | } |
| 4874 | |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4875 | ActivityStack getTopDisplayFocusedStack() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4876 | return mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4877 | } |
| 4878 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4879 | /** Pokes the task persister. */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 4880 | void notifyTaskPersisterLocked(Task task, boolean flush) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4881 | mRecentTasks.notifyTaskPersisterLocked(task, flush); |
| 4882 | } |
| 4883 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4884 | boolean isKeyguardLocked() { |
| 4885 | return mKeyguardController.isKeyguardLocked(); |
| 4886 | } |
| 4887 | |
Garfield Tan | 0154863 | 2018-11-27 10:15:48 -0800 | [diff] [blame] | 4888 | /** |
| 4889 | * Clears launch params for the given package. |
| 4890 | * @param packageNames the names of the packages of which the launch params are to be cleared |
| 4891 | */ |
| 4892 | @Override |
| 4893 | public void clearLaunchParamsForPackages(List<String> packageNames) { |
| 4894 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4895 | "clearLaunchParamsForPackages"); |
| 4896 | synchronized (mGlobalLock) { |
| 4897 | for (int i = 0; i < packageNames.size(); ++i) { |
| 4898 | mStackSupervisor.mLaunchParamsPersister.removeRecordForPackage(packageNames.get(i)); |
| 4899 | } |
| 4900 | } |
| 4901 | } |
| 4902 | |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 4903 | /** |
| 4904 | * Makes the display with the given id a single task instance display. I.e the display can only |
| 4905 | * contain one task. |
| 4906 | */ |
| 4907 | @Override |
| 4908 | public void setDisplayToSingleTaskInstance(int displayId) { |
| 4909 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4910 | "setDisplayToSingleTaskInstance"); |
| 4911 | final long origId = Binder.clearCallingIdentity(); |
| 4912 | try { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 4913 | final DisplayContent display = |
| 4914 | mRootActivityContainer.getDisplayContentOrCreate(displayId); |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 4915 | if (display != null) { |
| 4916 | display.setDisplayToSingleTaskInstance(); |
| 4917 | } |
| 4918 | } finally { |
| 4919 | Binder.restoreCallingIdentity(origId); |
| 4920 | } |
| 4921 | } |
| 4922 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4923 | void dumpLastANRLocked(PrintWriter pw) { |
| 4924 | pw.println("ACTIVITY MANAGER LAST ANR (dumpsys activity lastanr)"); |
| 4925 | if (mLastANRState == null) { |
| 4926 | pw.println(" <no ANR has occurred since boot>"); |
| 4927 | } else { |
| 4928 | pw.println(mLastANRState); |
| 4929 | } |
| 4930 | } |
| 4931 | |
| 4932 | void dumpLastANRTracesLocked(PrintWriter pw) { |
| 4933 | pw.println("ACTIVITY MANAGER LAST ANR TRACES (dumpsys activity lastanr-traces)"); |
| 4934 | |
| 4935 | final File[] files = new File(ANR_TRACE_DIR).listFiles(); |
| 4936 | if (ArrayUtils.isEmpty(files)) { |
| 4937 | pw.println(" <no ANR has occurred since boot>"); |
| 4938 | return; |
| 4939 | } |
| 4940 | // Find the latest file. |
| 4941 | File latest = null; |
| 4942 | for (File f : files) { |
| 4943 | if ((latest == null) || (latest.lastModified() < f.lastModified())) { |
| 4944 | latest = f; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4945 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4946 | } |
| 4947 | pw.print("File: "); |
| 4948 | pw.print(latest.getName()); |
| 4949 | pw.println(); |
| 4950 | try (BufferedReader in = new BufferedReader(new FileReader(latest))) { |
| 4951 | String line; |
| 4952 | while ((line = in.readLine()) != null) { |
| 4953 | pw.println(line); |
| 4954 | } |
| 4955 | } catch (IOException e) { |
| 4956 | pw.print("Unable to read: "); |
| 4957 | pw.print(e); |
| 4958 | pw.println(); |
| 4959 | } |
| 4960 | } |
| 4961 | |
| 4962 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4963 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 4964 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage, |
| 4965 | "ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)"); |
| 4966 | } |
| 4967 | |
| 4968 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4969 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage, String header) { |
| 4970 | pw.println(header); |
| 4971 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4972 | boolean printedAnything = mRootActivityContainer.dumpActivities(fd, pw, dumpAll, dumpClient, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4973 | dumpPackage); |
| 4974 | boolean needSep = printedAnything; |
| 4975 | |
| 4976 | boolean printed = ActivityStackSupervisor.printThisActivity(pw, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4977 | mRootActivityContainer.getTopResumedActivity(), dumpPackage, needSep, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4978 | " ResumedActivity: "); |
| 4979 | if (printed) { |
| 4980 | printedAnything = true; |
| 4981 | needSep = false; |
| 4982 | } |
| 4983 | |
| 4984 | if (dumpPackage == null) { |
| 4985 | if (needSep) { |
| 4986 | pw.println(); |
| 4987 | } |
| 4988 | printedAnything = true; |
| 4989 | mStackSupervisor.dump(pw, " "); |
| 4990 | } |
| 4991 | |
| 4992 | if (!printedAnything) { |
| 4993 | pw.println(" (nothing)"); |
| 4994 | } |
| 4995 | } |
| 4996 | |
| 4997 | void dumpActivityContainersLocked(PrintWriter pw) { |
Jeff Chang | de32273 | 2019-07-12 12:16:23 +0800 | [diff] [blame] | 4998 | pw.println("ACTIVITY MANAGER CONTAINERS (dumpsys activity containers)"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4999 | mRootActivityContainer.dumpChildrenNames(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5000 | pw.println(" "); |
| 5001 | } |
| 5002 | |
| 5003 | void dumpActivityStarterLocked(PrintWriter pw, String dumpPackage) { |
| 5004 | pw.println("ACTIVITY MANAGER STARTER (dumpsys activity starter)"); |
| 5005 | getActivityStartController().dump(pw, "", dumpPackage); |
| 5006 | } |
| 5007 | |
| 5008 | /** |
| 5009 | * There are three things that cmd can be: |
| 5010 | * - a flattened component name that matches an existing activity |
| 5011 | * - the cmd arg isn't the flattened component name of an existing activity: |
| 5012 | * dump all activity whose component contains the cmd as a substring |
| 5013 | * - A hex number of the ActivityRecord object instance. |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5014 | * <p> |
| 5015 | * The caller should not hold lock when calling this method because it will wait for the |
| 5016 | * activities to complete the dump. |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5017 | * |
| 5018 | * @param dumpVisibleStacksOnly dump activity with {@param name} only if in a visible stack |
| 5019 | * @param dumpFocusedStackOnly dump activity with {@param name} only if in the focused stack |
| 5020 | */ |
| 5021 | protected boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, String[] args, |
| 5022 | int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, boolean dumpFocusedStackOnly) { |
| 5023 | ArrayList<ActivityRecord> activities; |
| 5024 | |
| 5025 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5026 | activities = mRootActivityContainer.getDumpActivities(name, dumpVisibleStacksOnly, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5027 | dumpFocusedStackOnly); |
| 5028 | } |
| 5029 | |
| 5030 | if (activities.size() <= 0) { |
| 5031 | return false; |
| 5032 | } |
| 5033 | |
| 5034 | String[] newArgs = new String[args.length - opti]; |
| 5035 | System.arraycopy(args, opti, newArgs, 0, args.length - opti); |
| 5036 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5037 | Task lastTask = null; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5038 | boolean needSep = false; |
| 5039 | for (int i = activities.size() - 1; i >= 0; i--) { |
| 5040 | ActivityRecord r = activities.get(i); |
| 5041 | if (needSep) { |
| 5042 | pw.println(); |
| 5043 | } |
| 5044 | needSep = true; |
| 5045 | synchronized (mGlobalLock) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5046 | final Task task = r.getTask(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5047 | if (lastTask != task) { |
| 5048 | lastTask = task; |
| 5049 | pw.print("TASK "); pw.print(lastTask.affinity); |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 5050 | pw.print(" id="); pw.print(lastTask.mTaskId); |
| 5051 | pw.print(" userId="); pw.println(lastTask.mUserId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5052 | if (dumpAll) { |
| 5053 | lastTask.dump(pw, " "); |
| 5054 | } |
| 5055 | } |
| 5056 | } |
| 5057 | dumpActivity(" ", fd, pw, activities.get(i), newArgs, dumpAll); |
| 5058 | } |
| 5059 | return true; |
| 5060 | } |
| 5061 | |
| 5062 | /** |
| 5063 | * Invokes IApplicationThread.dumpActivity() on the thread of the specified activity if |
| 5064 | * there is a thread associated with the activity. |
| 5065 | */ |
| 5066 | private void dumpActivity(String prefix, FileDescriptor fd, PrintWriter pw, |
| 5067 | final ActivityRecord r, String[] args, boolean dumpAll) { |
| 5068 | String innerPrefix = prefix + " "; |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5069 | IApplicationThread appThread = null; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5070 | synchronized (mGlobalLock) { |
| 5071 | pw.print(prefix); pw.print("ACTIVITY "); pw.print(r.shortComponentName); |
| 5072 | pw.print(" "); pw.print(Integer.toHexString(System.identityHashCode(r))); |
| 5073 | pw.print(" pid="); |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5074 | if (r.hasProcess()) { |
| 5075 | pw.println(r.app.getPid()); |
| 5076 | appThread = r.app.getThread(); |
| 5077 | } else { |
| 5078 | pw.println("(not running)"); |
| 5079 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5080 | if (dumpAll) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5081 | r.dump(pw, innerPrefix, true /* dumpAll */); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5082 | } |
| 5083 | } |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5084 | if (appThread != null) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5085 | // flush anything that is already in the PrintWriter since the thread is going |
| 5086 | // to write to the file descriptor directly |
| 5087 | pw.flush(); |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5088 | try (TransferPipe tp = new TransferPipe()) { |
| 5089 | appThread.dumpActivity(tp.getWriteFd(), r.appToken, innerPrefix, args); |
| 5090 | tp.go(fd); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5091 | } catch (IOException e) { |
| 5092 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 5093 | } catch (RemoteException e) { |
| 5094 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 5095 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5096 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5097 | } |
| 5098 | |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 5099 | private void writeSleepStateToProto(ProtoOutputStream proto, int wakeFullness, |
| 5100 | boolean testPssMode) { |
| 5101 | final long sleepToken = proto.start(ActivityManagerServiceDumpProcessesProto.SLEEP_STATUS); |
| 5102 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.WAKEFULNESS, |
| 5103 | PowerManagerInternal.wakefulnessToProtoEnum(wakeFullness)); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5104 | for (ActivityTaskManagerInternal.SleepToken st : mRootActivityContainer.mSleepTokens) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5105 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEP_TOKENS, |
| 5106 | st.toString()); |
| 5107 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5108 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEPING, mSleeping); |
| 5109 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SHUTTING_DOWN, |
| 5110 | mShuttingDown); |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 5111 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.TEST_PSS_MODE, |
| 5112 | testPssMode); |
| 5113 | proto.end(sleepToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5114 | } |
| 5115 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5116 | int getCurrentUserId() { |
| 5117 | return mAmInternal.getCurrentUserId(); |
| 5118 | } |
| 5119 | |
| 5120 | private void enforceNotIsolatedCaller(String caller) { |
| 5121 | if (UserHandle.isIsolated(Binder.getCallingUid())) { |
| 5122 | throw new SecurityException("Isolated process not allowed to call " + caller); |
| 5123 | } |
| 5124 | } |
| 5125 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5126 | public Configuration getConfiguration() { |
| 5127 | Configuration ci; |
| 5128 | synchronized(mGlobalLock) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 5129 | ci = new Configuration(getGlobalConfigurationForCallingPid()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5130 | ci.userSetLocale = false; |
| 5131 | } |
| 5132 | return ci; |
| 5133 | } |
| 5134 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5135 | /** |
| 5136 | * Current global configuration information. Contains general settings for the entire system, |
| 5137 | * also corresponds to the merged configuration of the default display. |
| 5138 | */ |
| 5139 | Configuration getGlobalConfiguration() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5140 | return mRootActivityContainer.getConfiguration(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5141 | } |
| 5142 | |
| 5143 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5144 | boolean initLocale) { |
| 5145 | return updateConfigurationLocked(values, starting, initLocale, false /* deferResume */); |
| 5146 | } |
| 5147 | |
| 5148 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5149 | boolean initLocale, boolean deferResume) { |
| 5150 | // pass UserHandle.USER_NULL as userId because we don't persist configuration for any user |
| 5151 | return updateConfigurationLocked(values, starting, initLocale, false /* persistent */, |
| 5152 | UserHandle.USER_NULL, deferResume); |
| 5153 | } |
| 5154 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 5155 | public void updatePersistentConfiguration(Configuration values, @UserIdInt int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5156 | final long origId = Binder.clearCallingIdentity(); |
| 5157 | try { |
| 5158 | synchronized (mGlobalLock) { |
| 5159 | updateConfigurationLocked(values, null, false, true, userId, |
| 5160 | false /* deferResume */); |
| 5161 | } |
| 5162 | } finally { |
| 5163 | Binder.restoreCallingIdentity(origId); |
| 5164 | } |
| 5165 | } |
| 5166 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5167 | private boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5168 | boolean initLocale, boolean persistent, int userId, boolean deferResume) { |
| 5169 | return updateConfigurationLocked(values, starting, initLocale, persistent, userId, |
| 5170 | deferResume, null /* result */); |
| 5171 | } |
| 5172 | |
| 5173 | /** |
| 5174 | * Do either or both things: (1) change the current configuration, and (2) |
| 5175 | * make sure the given activity is running with the (now) current |
| 5176 | * configuration. Returns true if the activity has been left running, or |
| 5177 | * false if <var>starting</var> is being destroyed to match the new |
| 5178 | * configuration. |
| 5179 | * |
| 5180 | * @param userId is only used when persistent parameter is set to true to persist configuration |
| 5181 | * for that particular user |
| 5182 | */ |
| 5183 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5184 | boolean initLocale, boolean persistent, int userId, boolean deferResume, |
| 5185 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 5186 | int changes = 0; |
| 5187 | boolean kept = true; |
| 5188 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5189 | deferWindowLayout(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5190 | try { |
| 5191 | if (values != null) { |
| 5192 | changes = updateGlobalConfigurationLocked(values, initLocale, persistent, userId, |
| 5193 | deferResume); |
| 5194 | } |
| 5195 | |
| 5196 | kept = ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 5197 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5198 | continueWindowLayout(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5199 | } |
| 5200 | |
| 5201 | if (result != null) { |
| 5202 | result.changes = changes; |
| 5203 | result.activityRelaunched = !kept; |
| 5204 | } |
| 5205 | return kept; |
| 5206 | } |
| 5207 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5208 | /** Update default (global) configuration and notify listeners about changes. */ |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5209 | int updateGlobalConfigurationLocked(@NonNull Configuration values, boolean initLocale, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5210 | boolean persistent, int userId, boolean deferResume) { |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5211 | |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 5212 | final DisplayContent defaultDisplay = |
| 5213 | mRootActivityContainer.getDisplayContent(DEFAULT_DISPLAY); |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5214 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5215 | mTempConfig.setTo(getGlobalConfiguration()); |
| 5216 | final int changes = mTempConfig.updateFrom(values); |
| 5217 | if (changes == 0) { |
| 5218 | // Since calling to Activity.setRequestedOrientation leads to freezing the window with |
| 5219 | // setting WindowManagerService.mWaitingForConfig to true, it is important that we call |
| 5220 | // performDisplayOverrideConfigUpdate in order to send the new display configuration |
| 5221 | // (even if there are no actual changes) to unfreeze the window. |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5222 | defaultDisplay.performDisplayOverrideConfigUpdate(values, deferResume); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5223 | return 0; |
| 5224 | } |
| 5225 | |
| 5226 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.i(TAG_CONFIGURATION, |
| 5227 | "Updating global configuration to: " + values); |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5228 | writeConfigurationChanged(changes); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5229 | StatsLog.write(StatsLog.RESOURCE_CONFIGURATION_CHANGED, |
| 5230 | values.colorMode, |
| 5231 | values.densityDpi, |
| 5232 | values.fontScale, |
| 5233 | values.hardKeyboardHidden, |
| 5234 | values.keyboard, |
| 5235 | values.keyboardHidden, |
| 5236 | values.mcc, |
| 5237 | values.mnc, |
| 5238 | values.navigation, |
| 5239 | values.navigationHidden, |
| 5240 | values.orientation, |
| 5241 | values.screenHeightDp, |
| 5242 | values.screenLayout, |
| 5243 | values.screenWidthDp, |
| 5244 | values.smallestScreenWidthDp, |
| 5245 | values.touchscreen, |
| 5246 | values.uiMode); |
| 5247 | |
| 5248 | |
| 5249 | if (!initLocale && !values.getLocales().isEmpty() && values.userSetLocale) { |
| 5250 | final LocaleList locales = values.getLocales(); |
| 5251 | int bestLocaleIndex = 0; |
| 5252 | if (locales.size() > 1) { |
| 5253 | if (mSupportedSystemLocales == null) { |
| 5254 | mSupportedSystemLocales = Resources.getSystem().getAssets().getLocales(); |
| 5255 | } |
| 5256 | bestLocaleIndex = Math.max(0, locales.getFirstMatchIndex(mSupportedSystemLocales)); |
| 5257 | } |
| 5258 | SystemProperties.set("persist.sys.locale", |
| 5259 | locales.get(bestLocaleIndex).toLanguageTag()); |
| 5260 | LocaleList.setDefault(locales, bestLocaleIndex); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5261 | |
| 5262 | final Message m = PooledLambda.obtainMessage( |
| 5263 | ActivityTaskManagerService::sendLocaleToMountDaemonMsg, this, |
| 5264 | locales.get(bestLocaleIndex)); |
| 5265 | mH.sendMessage(m); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5266 | } |
| 5267 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 5268 | mTempConfig.seq = increaseConfigurationSeqLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5269 | |
| 5270 | // Update stored global config and notify everyone about the change. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5271 | mRootActivityContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5272 | |
| 5273 | Slog.i(TAG, "Config changes=" + Integer.toHexString(changes) + " " + mTempConfig); |
| 5274 | // TODO(multi-display): Update UsageEvents#Event to include displayId. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5275 | mUsageStatsInternal.reportConfigurationChange(mTempConfig, mAmInternal.getCurrentUserId()); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5276 | |
| 5277 | // 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] | 5278 | updateShouldShowDialogsLocked(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5279 | |
| 5280 | AttributeCache ac = AttributeCache.instance(); |
| 5281 | if (ac != null) { |
| 5282 | ac.updateConfiguration(mTempConfig); |
| 5283 | } |
| 5284 | |
| 5285 | // Make sure all resources in our process are updated right now, so that anyone who is going |
| 5286 | // to retrieve resource values after we return will be sure to get the new ones. This is |
| 5287 | // especially important during boot, where the first config change needs to guarantee all |
| 5288 | // resources have that config before following boot code is executed. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5289 | mSystemThread.applyConfigurationToResources(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5290 | |
| 5291 | // We need another copy of global config because we're scheduling some calls instead of |
| 5292 | // running them in place. We need to be sure that object we send will be handled unchanged. |
| 5293 | final Configuration configCopy = new Configuration(mTempConfig); |
| 5294 | if (persistent && Settings.System.hasInterestingConfigurationChanges(changes)) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5295 | final Message msg = PooledLambda.obtainMessage( |
| 5296 | ActivityTaskManagerService::sendPutConfigurationForUserMsg, |
| 5297 | this, userId, configCopy); |
| 5298 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5299 | } |
| 5300 | |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 5301 | SparseArray<WindowProcessController> pidMap = mProcessMap.getPidMap(); |
| 5302 | for (int i = pidMap.size() - 1; i >= 0; i--) { |
| 5303 | final int pid = pidMap.keyAt(i); |
| 5304 | final WindowProcessController app = pidMap.get(pid); |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 5305 | if (DEBUG_CONFIGURATION) { |
| 5306 | Slog.v(TAG_CONFIGURATION, "Update process config of " |
| 5307 | + app.mName + " to new config " + configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5308 | } |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 5309 | app.onConfigurationChanged(configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5310 | } |
| 5311 | |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 5312 | final Message msg = PooledLambda.obtainMessage( |
| 5313 | ActivityManagerInternal::broadcastGlobalConfigurationChanged, |
| 5314 | mAmInternal, changes, initLocale); |
| 5315 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5316 | |
| 5317 | // Override configuration of the default display duplicates global config, so we need to |
| 5318 | // update it also. This will also notify WindowManager about changes. |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5319 | defaultDisplay.performDisplayOverrideConfigUpdate(mRootActivityContainer.getConfiguration(), |
| 5320 | deferResume); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5321 | |
| 5322 | return changes; |
| 5323 | } |
| 5324 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 5325 | /** @see WindowSurfacePlacer#deferLayout */ |
| 5326 | void deferWindowLayout() { |
| 5327 | if (!mWindowManager.mWindowPlacerLocked.isLayoutDeferred()) { |
| 5328 | // Reset the reasons at the first entrance because we only care about the changes in the |
| 5329 | // deferred scope. |
| 5330 | mLayoutReasons = 0; |
| 5331 | } |
| 5332 | |
| 5333 | mWindowManager.mWindowPlacerLocked.deferLayout(); |
| 5334 | } |
| 5335 | |
| 5336 | /** @see WindowSurfacePlacer#continueLayout */ |
| 5337 | void continueWindowLayout() { |
| 5338 | mWindowManager.mWindowPlacerLocked.continueLayout(mLayoutReasons != 0); |
| 5339 | if (DEBUG_ALL && !mWindowManager.mWindowPlacerLocked.isLayoutDeferred()) { |
| 5340 | Slog.i(TAG, "continueWindowLayout reason=" + mLayoutReasons); |
| 5341 | } |
| 5342 | } |
| 5343 | |
| 5344 | /** |
| 5345 | * If a reason is added between {@link #deferWindowLayout} and {@link #continueWindowLayout}, |
| 5346 | * it will make sure {@link WindowSurfacePlacer#performSurfacePlacement} is called when the last |
| 5347 | * defer count is gone. |
| 5348 | */ |
| 5349 | void addWindowLayoutReasons(@LayoutReason int reasons) { |
| 5350 | mLayoutReasons |= reasons; |
| 5351 | } |
| 5352 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5353 | private void updateEventDispatchingLocked(boolean booted) { |
| 5354 | mWindowManager.setEventDispatching(booted && !mShuttingDown); |
| 5355 | } |
| 5356 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5357 | private void sendPutConfigurationForUserMsg(int userId, Configuration config) { |
| 5358 | final ContentResolver resolver = mContext.getContentResolver(); |
| 5359 | Settings.System.putConfigurationForUser(resolver, config, userId); |
| 5360 | } |
| 5361 | |
| 5362 | private void sendLocaleToMountDaemonMsg(Locale l) { |
| 5363 | try { |
| 5364 | IBinder service = ServiceManager.getService("mount"); |
| 5365 | IStorageManager storageManager = IStorageManager.Stub.asInterface(service); |
| 5366 | Log.d(TAG, "Storing locale " + l.toLanguageTag() + " for decryption UI"); |
| 5367 | storageManager.setField(StorageManager.SYSTEM_LOCALE_KEY, l.toLanguageTag()); |
| 5368 | } catch (RemoteException e) { |
| 5369 | Log.e(TAG, "Error storing locale for decryption UI", e); |
| 5370 | } |
| 5371 | } |
| 5372 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5373 | private void expireStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5374 | mStartActivitySources.remove(permissionToken); |
| 5375 | mExpiredStartAsCallerTokens.add(permissionToken); |
| 5376 | } |
| 5377 | |
| 5378 | private void forgetStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5379 | mExpiredStartAsCallerTokens.remove(permissionToken); |
| 5380 | } |
| 5381 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5382 | boolean isActivityStartsLoggingEnabled() { |
| 5383 | return mAmInternal.isActivityStartsLoggingEnabled(); |
| 5384 | } |
| 5385 | |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 5386 | boolean isBackgroundActivityStartsEnabled() { |
| 5387 | return mAmInternal.isBackgroundActivityStartsEnabled(); |
| 5388 | } |
| 5389 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5390 | void enableScreenAfterBoot(boolean booted) { |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5391 | writeBootProgressEnableScreen(SystemClock.uptimeMillis()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5392 | mWindowManager.enableScreenAfterBoot(); |
| 5393 | |
| 5394 | synchronized (mGlobalLock) { |
| 5395 | updateEventDispatchingLocked(booted); |
| 5396 | } |
| 5397 | } |
| 5398 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5399 | static long getInputDispatchingTimeoutLocked(ActivityRecord r) { |
| 5400 | if (r == null || !r.hasProcess()) { |
| 5401 | return KEY_DISPATCHING_TIMEOUT_MS; |
| 5402 | } |
| 5403 | return getInputDispatchingTimeoutLocked(r.app); |
| 5404 | } |
| 5405 | |
| 5406 | private static long getInputDispatchingTimeoutLocked(WindowProcessController r) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 5407 | return r != null ? r.getInputDispatchingTimeout() : KEY_DISPATCHING_TIMEOUT_MS; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5408 | } |
| 5409 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5410 | /** |
| 5411 | * Decide based on the configuration whether we should show the ANR, |
| 5412 | * crash, etc dialogs. The idea is that if there is no affordance to |
| 5413 | * press the on-screen buttons, or the user experience would be more |
| 5414 | * greatly impacted than the crash itself, we shouldn't show the dialog. |
| 5415 | * |
| 5416 | * A thought: SystemUI might also want to get told about this, the Power |
| 5417 | * dialog / global actions also might want different behaviors. |
| 5418 | */ |
| 5419 | private void updateShouldShowDialogsLocked(Configuration config) { |
| 5420 | final boolean inputMethodExists = !(config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 5421 | && config.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH |
| 5422 | && config.navigation == Configuration.NAVIGATION_NONAV); |
| 5423 | int modeType = config.uiMode & Configuration.UI_MODE_TYPE_MASK; |
| 5424 | final boolean uiModeSupportsDialogs = (modeType != Configuration.UI_MODE_TYPE_CAR |
| 5425 | && !(modeType == Configuration.UI_MODE_TYPE_WATCH && Build.IS_USER) |
| 5426 | && modeType != Configuration.UI_MODE_TYPE_TELEVISION |
| 5427 | && modeType != Configuration.UI_MODE_TYPE_VR_HEADSET); |
| 5428 | final boolean hideDialogsSet = Settings.Global.getInt(mContext.getContentResolver(), |
| 5429 | HIDE_ERROR_DIALOGS, 0) != 0; |
| 5430 | mShowDialogs = inputMethodExists && uiModeSupportsDialogs && !hideDialogsSet; |
| 5431 | } |
| 5432 | |
| 5433 | private void updateFontScaleIfNeeded(@UserIdInt int userId) { |
| 5434 | final float scaleFactor = Settings.System.getFloatForUser(mContext.getContentResolver(), |
| 5435 | FONT_SCALE, 1.0f, userId); |
| 5436 | |
Riddle Hsu | 8419e4b | 2019-09-18 23:28:01 +0800 | [diff] [blame] | 5437 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5438 | if (getGlobalConfiguration().fontScale == scaleFactor) { |
| 5439 | return; |
| 5440 | } |
| 5441 | |
| 5442 | final Configuration configuration |
| 5443 | = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
| 5444 | configuration.fontScale = scaleFactor; |
| 5445 | updatePersistentConfiguration(configuration, userId); |
| 5446 | } |
| 5447 | } |
| 5448 | |
| 5449 | // Actually is sleeping or shutting down or whatever else in the future |
| 5450 | // is an inactive state. |
| 5451 | boolean isSleepingOrShuttingDownLocked() { |
| 5452 | return isSleepingLocked() || mShuttingDown; |
| 5453 | } |
| 5454 | |
| 5455 | boolean isSleepingLocked() { |
| 5456 | return mSleeping; |
| 5457 | } |
| 5458 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5459 | /** Update AMS states when an activity is resumed. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5460 | void setResumedActivityUncheckLocked(ActivityRecord r, String reason) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5461 | final Task task = r.getTask(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5462 | if (task.isActivityTypeStandard()) { |
| 5463 | if (mCurAppTimeTracker != r.appTimeTracker) { |
| 5464 | // We are switching app tracking. Complete the current one. |
| 5465 | if (mCurAppTimeTracker != null) { |
| 5466 | mCurAppTimeTracker.stop(); |
| 5467 | mH.obtainMessage( |
| 5468 | REPORT_TIME_TRACKER_MSG, mCurAppTimeTracker).sendToTarget(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5469 | mRootActivityContainer.clearOtherAppTimeTrackers(r.appTimeTracker); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5470 | mCurAppTimeTracker = null; |
| 5471 | } |
| 5472 | if (r.appTimeTracker != null) { |
| 5473 | mCurAppTimeTracker = r.appTimeTracker; |
| 5474 | startTimeTrackingFocusedActivityLocked(); |
| 5475 | } |
| 5476 | } else { |
| 5477 | startTimeTrackingFocusedActivityLocked(); |
| 5478 | } |
| 5479 | } else { |
| 5480 | r.appTimeTracker = null; |
| 5481 | } |
| 5482 | // TODO: VI Maybe r.task.voiceInteractor || r.voiceInteractor != null |
| 5483 | // TODO: Probably not, because we don't want to resume voice on switching |
| 5484 | // back to this activity |
| 5485 | if (task.voiceInteractor != null) { |
| 5486 | startRunningVoiceLocked(task.voiceSession, r.info.applicationInfo.uid); |
| 5487 | } else { |
| 5488 | finishRunningVoiceLocked(); |
| 5489 | |
| 5490 | if (mLastResumedActivity != null) { |
| 5491 | final IVoiceInteractionSession session; |
| 5492 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5493 | final Task lastResumedActivityTask = mLastResumedActivity.getTask(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5494 | if (lastResumedActivityTask != null |
| 5495 | && lastResumedActivityTask.voiceSession != null) { |
| 5496 | session = lastResumedActivityTask.voiceSession; |
| 5497 | } else { |
| 5498 | session = mLastResumedActivity.voiceSession; |
| 5499 | } |
| 5500 | |
| 5501 | if (session != null) { |
| 5502 | // We had been in a voice interaction session, but now focused has |
| 5503 | // move to something different. Just finish the session, we can't |
| 5504 | // return to it and retain the proper state and synchronization with |
| 5505 | // the voice interaction service. |
| 5506 | finishVoiceTask(session); |
| 5507 | } |
| 5508 | } |
| 5509 | } |
| 5510 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5511 | if (mLastResumedActivity != null && r.mUserId != mLastResumedActivity.mUserId) { |
| 5512 | mAmInternal.sendForegroundProfileChanged(r.mUserId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5513 | } |
| 5514 | updateResumedAppTrace(r); |
| 5515 | mLastResumedActivity = r; |
| 5516 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 5517 | r.getDisplay().setFocusedApp(r, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5518 | |
| 5519 | applyUpdateLockStateLocked(r); |
| 5520 | applyUpdateVrModeLocked(r); |
| 5521 | |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 5522 | EventLogTags.writeWmSetResumedActivity( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5523 | r == null ? -1 : r.mUserId, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5524 | r == null ? "NULL" : r.shortComponentName, |
| 5525 | reason); |
| 5526 | } |
| 5527 | |
| 5528 | ActivityTaskManagerInternal.SleepToken acquireSleepToken(String tag, int displayId) { |
| 5529 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5530 | final ActivityTaskManagerInternal.SleepToken token = |
| 5531 | mRootActivityContainer.createSleepToken(tag, displayId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5532 | updateSleepIfNeededLocked(); |
| 5533 | return token; |
| 5534 | } |
| 5535 | } |
| 5536 | |
| 5537 | void updateSleepIfNeededLocked() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5538 | final boolean shouldSleep = !mRootActivityContainer.hasAwakeDisplay(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5539 | final boolean wasSleeping = mSleeping; |
| 5540 | boolean updateOomAdj = false; |
| 5541 | |
| 5542 | if (!shouldSleep) { |
| 5543 | // If wasSleeping is true, we need to wake up activity manager state from when |
| 5544 | // we started sleeping. In either case, we need to apply the sleep tokens, which |
| 5545 | // will wake up stacks or put them to sleep as appropriate. |
| 5546 | if (wasSleeping) { |
| 5547 | mSleeping = false; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 5548 | StatsLog.write(StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5549 | StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__AWAKE); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5550 | startTimeTrackingFocusedActivityLocked(); |
| 5551 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
Varun Shah | 98694fb | 2019-04-11 09:28:27 -0700 | [diff] [blame] | 5552 | Slog.d(TAG, "Top Process State changed to PROCESS_STATE_TOP"); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5553 | mStackSupervisor.comeOutOfSleepIfNeededLocked(); |
| 5554 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5555 | mRootActivityContainer.applySleepTokens(true /* applyToStacks */); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5556 | if (wasSleeping) { |
| 5557 | updateOomAdj = true; |
| 5558 | } |
| 5559 | } else if (!mSleeping && shouldSleep) { |
| 5560 | mSleeping = true; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 5561 | StatsLog.write(StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5562 | StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__ASLEEP); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5563 | if (mCurAppTimeTracker != null) { |
| 5564 | mCurAppTimeTracker.stop(); |
| 5565 | } |
| 5566 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP_SLEEPING; |
Varun Shah | 98694fb | 2019-04-11 09:28:27 -0700 | [diff] [blame] | 5567 | Slog.d(TAG, "Top Process State changed to PROCESS_STATE_TOP_SLEEPING"); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5568 | mStackSupervisor.goingToSleepLocked(); |
| 5569 | updateResumedAppTrace(null /* resumed */); |
| 5570 | updateOomAdj = true; |
| 5571 | } |
| 5572 | if (updateOomAdj) { |
wilsonshih | 8d096d2 | 2019-08-01 17:46:14 +0800 | [diff] [blame] | 5573 | updateOomAdj(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5574 | } |
| 5575 | } |
| 5576 | |
| 5577 | void updateOomAdj() { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 5578 | mH.removeCallbacks(mUpdateOomAdjRunnable); |
| 5579 | mH.post(mUpdateOomAdjRunnable); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5580 | } |
| 5581 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5582 | void updateCpuStats() { |
| 5583 | mH.post(mAmInternal::updateCpuStats); |
| 5584 | } |
| 5585 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5586 | void updateBatteryStats(ActivityRecord component, boolean resumed) { |
| 5587 | final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::updateBatteryStats, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5588 | mAmInternal, component.mActivityComponent, component.app.mUid, component.mUserId, |
| 5589 | resumed); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5590 | mH.sendMessage(m); |
| 5591 | } |
| 5592 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5593 | void updateActivityUsageStats(ActivityRecord activity, int event) { |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5594 | ComponentName taskRoot = null; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 5595 | final Task task = activity.getTask(); |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5596 | if (task != null) { |
| 5597 | final ActivityRecord rootActivity = task.getRootActivity(); |
| 5598 | if (rootActivity != null) { |
| 5599 | taskRoot = rootActivity.mActivityComponent; |
| 5600 | } |
| 5601 | } |
| 5602 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5603 | final Message m = PooledLambda.obtainMessage( |
| 5604 | ActivityManagerInternal::updateActivityUsageStats, mAmInternal, |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5605 | activity.mActivityComponent, activity.mUserId, event, activity.appToken, taskRoot); |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5606 | mH.sendMessage(m); |
| 5607 | } |
| 5608 | |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5609 | void startProcessAsync(ActivityRecord activity, boolean knownToBeDead, boolean isTop, |
| 5610 | String hostingType) { |
| 5611 | try { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5612 | if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) { |
| 5613 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "dispatchingStartProcess:" |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5614 | + activity.processName); |
| 5615 | } |
| 5616 | // Post message to start process to avoid possible deadlock of calling into AMS with the |
| 5617 | // ATMS lock held. |
| 5618 | final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::startProcess, |
| 5619 | mAmInternal, activity.processName, activity.info.applicationInfo, knownToBeDead, |
| 5620 | isTop, hostingType, activity.intent.getComponent()); |
| 5621 | mH.sendMessage(m); |
| 5622 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5623 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 5624 | } |
| 5625 | } |
| 5626 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5627 | void setBooting(boolean booting) { |
| 5628 | mAmInternal.setBooting(booting); |
| 5629 | } |
| 5630 | |
| 5631 | boolean isBooting() { |
| 5632 | return mAmInternal.isBooting(); |
| 5633 | } |
| 5634 | |
| 5635 | void setBooted(boolean booted) { |
| 5636 | mAmInternal.setBooted(booted); |
| 5637 | } |
| 5638 | |
| 5639 | boolean isBooted() { |
| 5640 | return mAmInternal.isBooted(); |
| 5641 | } |
| 5642 | |
| 5643 | void postFinishBooting(boolean finishBooting, boolean enableScreen) { |
| 5644 | mH.post(() -> { |
| 5645 | if (finishBooting) { |
| 5646 | mAmInternal.finishBooting(); |
| 5647 | } |
| 5648 | if (enableScreen) { |
| 5649 | mInternal.enableScreenAfterBoot(isBooted()); |
| 5650 | } |
| 5651 | }); |
| 5652 | } |
| 5653 | |
| 5654 | void setHeavyWeightProcess(ActivityRecord root) { |
| 5655 | mHeavyWeightProcess = root.app; |
| 5656 | final Message m = PooledLambda.obtainMessage( |
| 5657 | ActivityTaskManagerService::postHeavyWeightProcessNotification, this, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5658 | root.app, root.intent, root.mUserId); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5659 | mH.sendMessage(m); |
| 5660 | } |
| 5661 | |
| 5662 | void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
| 5663 | if (mHeavyWeightProcess == null || mHeavyWeightProcess != proc) { |
| 5664 | return; |
| 5665 | } |
| 5666 | |
| 5667 | mHeavyWeightProcess = null; |
| 5668 | final Message m = PooledLambda.obtainMessage( |
| 5669 | ActivityTaskManagerService::cancelHeavyWeightProcessNotification, this, |
| 5670 | proc.mUserId); |
| 5671 | mH.sendMessage(m); |
| 5672 | } |
| 5673 | |
| 5674 | private void cancelHeavyWeightProcessNotification(int userId) { |
| 5675 | final INotificationManager inm = NotificationManager.getService(); |
| 5676 | if (inm == null) { |
| 5677 | return; |
| 5678 | } |
| 5679 | try { |
Julia Reynolds | e4a47dd | 2019-06-07 13:40:59 -0400 | [diff] [blame] | 5680 | inm.cancelNotificationWithTag("android", "android", null, |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5681 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, userId); |
| 5682 | } catch (RuntimeException e) { |
| 5683 | Slog.w(TAG, "Error canceling notification for service", e); |
| 5684 | } catch (RemoteException e) { |
| 5685 | } |
| 5686 | |
| 5687 | } |
| 5688 | |
| 5689 | private void postHeavyWeightProcessNotification( |
| 5690 | WindowProcessController proc, Intent intent, int userId) { |
| 5691 | if (proc == null) { |
| 5692 | return; |
| 5693 | } |
| 5694 | |
| 5695 | final INotificationManager inm = NotificationManager.getService(); |
| 5696 | if (inm == null) { |
| 5697 | return; |
| 5698 | } |
| 5699 | |
| 5700 | try { |
| 5701 | Context context = mContext.createPackageContext(proc.mInfo.packageName, 0); |
| 5702 | String text = mContext.getString(R.string.heavy_weight_notification, |
| 5703 | context.getApplicationInfo().loadLabel(context.getPackageManager())); |
| 5704 | Notification notification = |
| 5705 | new Notification.Builder(context, |
| 5706 | SystemNotificationChannels.HEAVY_WEIGHT_APP) |
| 5707 | .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) |
| 5708 | .setWhen(0) |
| 5709 | .setOngoing(true) |
| 5710 | .setTicker(text) |
| 5711 | .setColor(mContext.getColor( |
| 5712 | com.android.internal.R.color.system_notification_accent_color)) |
| 5713 | .setContentTitle(text) |
| 5714 | .setContentText( |
| 5715 | mContext.getText(R.string.heavy_weight_notification_detail)) |
| 5716 | .setContentIntent(PendingIntent.getActivityAsUser(mContext, 0, |
| 5717 | intent, PendingIntent.FLAG_CANCEL_CURRENT, null, |
| 5718 | new UserHandle(userId))) |
| 5719 | .build(); |
| 5720 | try { |
| 5721 | inm.enqueueNotificationWithTag("android", "android", null, |
| 5722 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, notification, userId); |
| 5723 | } catch (RuntimeException e) { |
| 5724 | Slog.w(TAG, "Error showing notification for heavy-weight app", e); |
| 5725 | } catch (RemoteException e) { |
| 5726 | } |
| 5727 | } catch (PackageManager.NameNotFoundException e) { |
| 5728 | Slog.w(TAG, "Unable to create context for heavy notification", e); |
| 5729 | } |
| 5730 | |
| 5731 | } |
| 5732 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5733 | IIntentSender getIntentSenderLocked(int type, String packageName, int callingUid, int userId, |
| 5734 | IBinder token, String resultWho, int requestCode, Intent[] intents, |
| 5735 | String[] resolvedTypes, int flags, Bundle bOptions) { |
| 5736 | |
| 5737 | ActivityRecord activity = null; |
| 5738 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5739 | activity = ActivityRecord.isInStackLocked(token); |
| 5740 | if (activity == null) { |
| 5741 | Slog.w(TAG, "Failed createPendingResult: activity " + token + " not in any stack"); |
| 5742 | return null; |
| 5743 | } |
| 5744 | if (activity.finishing) { |
| 5745 | Slog.w(TAG, "Failed createPendingResult: activity " + activity + " is finishing"); |
| 5746 | return null; |
| 5747 | } |
| 5748 | } |
| 5749 | |
| 5750 | final PendingIntentRecord rec = mPendingIntentController.getIntentSender(type, packageName, |
| 5751 | callingUid, userId, token, resultWho, requestCode, intents, resolvedTypes, flags, |
| 5752 | bOptions); |
| 5753 | final boolean noCreate = (flags & PendingIntent.FLAG_NO_CREATE) != 0; |
| 5754 | if (noCreate) { |
| 5755 | return rec; |
| 5756 | } |
| 5757 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5758 | if (activity.pendingResults == null) { |
| 5759 | activity.pendingResults = new HashSet<>(); |
| 5760 | } |
| 5761 | activity.pendingResults.add(rec.ref); |
| 5762 | } |
| 5763 | return rec; |
| 5764 | } |
| 5765 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 5766 | // 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] | 5767 | private void startTimeTrackingFocusedActivityLocked() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5768 | final ActivityRecord resumedActivity = mRootActivityContainer.getTopResumedActivity(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5769 | if (!mSleeping && mCurAppTimeTracker != null && resumedActivity != null) { |
| 5770 | mCurAppTimeTracker.start(resumedActivity.packageName); |
| 5771 | } |
| 5772 | } |
| 5773 | |
| 5774 | private void updateResumedAppTrace(@Nullable ActivityRecord resumed) { |
| 5775 | if (mTracedResumedActivity != null) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5776 | Trace.asyncTraceEnd(TRACE_TAG_WINDOW_MANAGER, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5777 | constructResumedTraceName(mTracedResumedActivity.packageName), 0); |
| 5778 | } |
| 5779 | if (resumed != null) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 5780 | Trace.asyncTraceBegin(TRACE_TAG_WINDOW_MANAGER, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5781 | constructResumedTraceName(resumed.packageName), 0); |
| 5782 | } |
| 5783 | mTracedResumedActivity = resumed; |
| 5784 | } |
| 5785 | |
| 5786 | private String constructResumedTraceName(String packageName) { |
| 5787 | return "focused app: " + packageName; |
| 5788 | } |
| 5789 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5790 | /** Applies latest configuration and/or visibility updates if needed. */ |
Shivam Agrawal | 1d3db65 | 2019-07-01 15:26:11 -0700 | [diff] [blame] | 5791 | boolean ensureConfigAndVisibilityAfterUpdate(ActivityRecord starting, int changes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5792 | boolean kept = true; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5793 | final ActivityStack mainStack = mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5794 | // mainStack is null during startup. |
| 5795 | if (mainStack != null) { |
| 5796 | if (changes != 0 && starting == null) { |
| 5797 | // If the configuration changed, and the caller is not already |
| 5798 | // in the process of starting an activity, then find the top |
| 5799 | // activity to check if its configuration needs to change. |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 5800 | starting = mainStack.topRunningActivity(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5801 | } |
| 5802 | |
| 5803 | if (starting != null) { |
| 5804 | kept = starting.ensureActivityConfiguration(changes, |
| 5805 | false /* preserveWindow */); |
| 5806 | // And we need to make sure at this point that all other activities |
| 5807 | // are made visible with the correct configuration. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5808 | mRootActivityContainer.ensureActivitiesVisible(starting, changes, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5809 | !PRESERVE_WINDOWS); |
| 5810 | } |
| 5811 | } |
| 5812 | |
| 5813 | return kept; |
| 5814 | } |
| 5815 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5816 | void scheduleAppGcsLocked() { |
| 5817 | mH.post(() -> mAmInternal.scheduleAppGcs()); |
| 5818 | } |
| 5819 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5820 | CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) { |
| 5821 | return mCompatModePackages.compatibilityInfoForPackageLocked(ai); |
| 5822 | } |
| 5823 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5824 | /** |
| 5825 | * Returns the PackageManager. Used by classes hosted by {@link ActivityTaskManagerService}. The |
| 5826 | * PackageManager could be unavailable at construction time and therefore needs to be accessed |
| 5827 | * on demand. |
| 5828 | */ |
| 5829 | IPackageManager getPackageManager() { |
| 5830 | return AppGlobals.getPackageManager(); |
| 5831 | } |
| 5832 | |
| 5833 | PackageManagerInternal getPackageManagerInternalLocked() { |
| 5834 | if (mPmInternal == null) { |
| 5835 | mPmInternal = LocalServices.getService(PackageManagerInternal.class); |
| 5836 | } |
| 5837 | return mPmInternal; |
| 5838 | } |
| 5839 | |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 5840 | PermissionPolicyInternal getPermissionPolicyInternal() { |
| 5841 | if (mPermissionPolicyInternal == null) { |
| 5842 | mPermissionPolicyInternal = LocalServices.getService(PermissionPolicyInternal.class); |
| 5843 | } |
| 5844 | return mPermissionPolicyInternal; |
| 5845 | } |
| 5846 | |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 5847 | AppWarnings getAppWarningsLocked() { |
| 5848 | return mAppWarnings; |
| 5849 | } |
| 5850 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5851 | Intent getHomeIntent() { |
| 5852 | Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null); |
| 5853 | intent.setComponent(mTopComponent); |
| 5854 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5855 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5856 | intent.addCategory(Intent.CATEGORY_HOME); |
| 5857 | } |
| 5858 | return intent; |
| 5859 | } |
| 5860 | |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5861 | /** |
| 5862 | * Return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} to resolve secondary home |
| 5863 | * activities. |
| 5864 | * |
| 5865 | * @param preferredPackage Specify a preferred package name, otherwise use secondary home |
| 5866 | * component defined in config_secondaryHomeComponent. |
| 5867 | * @return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} |
| 5868 | */ |
| 5869 | Intent getSecondaryHomeIntent(String preferredPackage) { |
| 5870 | 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] | 5871 | final boolean useSystemProvidedLauncher = mContext.getResources().getBoolean( |
| 5872 | com.android.internal.R.bool.config_useSystemProvidedLauncherForSecondary); |
| 5873 | if (preferredPackage == null || useSystemProvidedLauncher) { |
| 5874 | // Using the component stored in config if no package name or forced. |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5875 | final String secondaryHomeComponent = mContext.getResources().getString( |
| 5876 | com.android.internal.R.string.config_secondaryHomeComponent); |
| 5877 | intent.setComponent(ComponentName.unflattenFromString(secondaryHomeComponent)); |
| 5878 | } else { |
| 5879 | intent.setPackage(preferredPackage); |
| 5880 | } |
| 5881 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5882 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5883 | intent.addCategory(Intent.CATEGORY_SECONDARY_HOME); |
| 5884 | } |
| 5885 | return intent; |
| 5886 | } |
| 5887 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5888 | ApplicationInfo getAppInfoForUser(ApplicationInfo info, int userId) { |
| 5889 | if (info == null) return null; |
| 5890 | ApplicationInfo newInfo = new ApplicationInfo(info); |
| 5891 | newInfo.initForUser(userId); |
| 5892 | return newInfo; |
| 5893 | } |
| 5894 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 5895 | WindowProcessController getProcessController(String processName, int uid) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5896 | if (uid == SYSTEM_UID) { |
| 5897 | // The system gets to run in any process. If there are multiple processes with the same |
| 5898 | // uid, just pick the first (this should never happen). |
| 5899 | final SparseArray<WindowProcessController> procs = |
| 5900 | mProcessNames.getMap().get(processName); |
| 5901 | if (procs == null) return null; |
| 5902 | final int procCount = procs.size(); |
| 5903 | for (int i = 0; i < procCount; i++) { |
| 5904 | final int procUid = procs.keyAt(i); |
| 5905 | if (UserHandle.isApp(procUid) || !UserHandle.isSameUser(procUid, uid)) { |
| 5906 | // Don't use an app process or different user process for system component. |
| 5907 | continue; |
| 5908 | } |
| 5909 | return procs.valueAt(i); |
| 5910 | } |
| 5911 | } |
| 5912 | |
| 5913 | return mProcessNames.get(processName, uid); |
| 5914 | } |
| 5915 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5916 | WindowProcessController getProcessController(IApplicationThread thread) { |
| 5917 | if (thread == null) { |
| 5918 | return null; |
| 5919 | } |
| 5920 | |
| 5921 | final IBinder threadBinder = thread.asBinder(); |
| 5922 | final ArrayMap<String, SparseArray<WindowProcessController>> pmap = mProcessNames.getMap(); |
| 5923 | for (int i = pmap.size()-1; i >= 0; i--) { |
| 5924 | final SparseArray<WindowProcessController> procs = pmap.valueAt(i); |
| 5925 | for (int j = procs.size() - 1; j >= 0; j--) { |
| 5926 | final WindowProcessController proc = procs.valueAt(j); |
| 5927 | if (proc.hasThread() && proc.getThread().asBinder() == threadBinder) { |
| 5928 | return proc; |
| 5929 | } |
| 5930 | } |
| 5931 | } |
| 5932 | |
| 5933 | return null; |
| 5934 | } |
| 5935 | |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 5936 | WindowProcessController getProcessController(int pid, int uid) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 5937 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Yunfan Chen | 8546b21 | 2019-04-01 15:34:44 +0900 | [diff] [blame] | 5938 | if (proc == null) return null; |
| 5939 | if (UserHandle.isApp(uid) && proc.mUid == uid) { |
| 5940 | return proc; |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 5941 | } |
| 5942 | return null; |
| 5943 | } |
| 5944 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 5945 | int getUidState(int uid) { |
| 5946 | return mActiveUids.getUidState(uid); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 5947 | } |
| 5948 | |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 5949 | boolean isUidForeground(int uid) { |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 5950 | // A uid is considered to be foreground if it has a visible non-toast window. |
| 5951 | return mWindowManager.mRoot.isAnyNonToastWindowVisibleForUid(uid); |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 5952 | } |
| 5953 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 5954 | boolean isDeviceOwner(int uid) { |
| 5955 | return uid >= 0 && mDeviceOwnerUid == uid; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 5956 | } |
| 5957 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 5958 | void setDeviceOwnerUid(int uid) { |
| 5959 | mDeviceOwnerUid = uid; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 5960 | } |
| 5961 | |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 5962 | /** |
| 5963 | * @return whitelist tag for a uid from mPendingTempWhitelist, null if not currently on |
| 5964 | * the whitelist |
| 5965 | */ |
| 5966 | String getPendingTempWhitelistTagForUidLocked(int uid) { |
| 5967 | return mPendingTempWhitelist.get(uid); |
| 5968 | } |
| 5969 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5970 | void logAppTooSlow(WindowProcessController app, long startTime, String msg) { |
| 5971 | if (true || Build.IS_USER) { |
| 5972 | return; |
| 5973 | } |
| 5974 | |
| 5975 | StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 5976 | StrictMode.allowThreadDiskWrites(); |
| 5977 | try { |
| 5978 | File tracesDir = new File("/data/anr"); |
| 5979 | File tracesFile = null; |
| 5980 | try { |
| 5981 | tracesFile = File.createTempFile("app_slow", null, tracesDir); |
| 5982 | |
| 5983 | StringBuilder sb = new StringBuilder(); |
Neil Fuller | 9774681 | 2019-08-19 14:20:50 +0100 | [diff] [blame] | 5984 | String timeString = |
| 5985 | TimeMigrationUtils.formatMillisWithFixedFormat(System.currentTimeMillis()); |
| 5986 | sb.append(timeString); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5987 | sb.append(": "); |
| 5988 | TimeUtils.formatDuration(SystemClock.uptimeMillis()-startTime, sb); |
| 5989 | sb.append(" since "); |
| 5990 | sb.append(msg); |
| 5991 | FileOutputStream fos = new FileOutputStream(tracesFile); |
| 5992 | fos.write(sb.toString().getBytes()); |
| 5993 | if (app == null) { |
| 5994 | fos.write("\n*** No application process!".getBytes()); |
| 5995 | } |
| 5996 | fos.close(); |
| 5997 | FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1); // -rw-rw-rw- |
| 5998 | } catch (IOException e) { |
| 5999 | Slog.w(TAG, "Unable to prepare slow app traces file: " + tracesFile, e); |
| 6000 | return; |
| 6001 | } |
| 6002 | |
| 6003 | if (app != null && app.getPid() > 0) { |
| 6004 | ArrayList<Integer> firstPids = new ArrayList<Integer>(); |
| 6005 | firstPids.add(app.getPid()); |
| 6006 | dumpStackTraces(tracesFile.getAbsolutePath(), firstPids, null, null); |
| 6007 | } |
| 6008 | |
| 6009 | File lastTracesFile = null; |
| 6010 | File curTracesFile = null; |
| 6011 | for (int i=9; i>=0; i--) { |
| 6012 | String name = String.format(Locale.US, "slow%02d.txt", i); |
| 6013 | curTracesFile = new File(tracesDir, name); |
| 6014 | if (curTracesFile.exists()) { |
| 6015 | if (lastTracesFile != null) { |
| 6016 | curTracesFile.renameTo(lastTracesFile); |
| 6017 | } else { |
| 6018 | curTracesFile.delete(); |
| 6019 | } |
| 6020 | } |
| 6021 | lastTracesFile = curTracesFile; |
| 6022 | } |
| 6023 | tracesFile.renameTo(curTracesFile); |
| 6024 | } finally { |
| 6025 | StrictMode.setThreadPolicy(oldPolicy); |
| 6026 | } |
| 6027 | } |
| 6028 | |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 6029 | boolean isAssociatedCompanionApp(int userId, int uid) { |
| 6030 | final Set<Integer> allUids = mCompanionAppUidsMap.get(userId); |
| 6031 | if (allUids == null) { |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 6032 | return false; |
| 6033 | } |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 6034 | return allUids.contains(uid); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 6035 | } |
| 6036 | |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 6037 | void notifySingleTaskDisplayEmpty(int displayId) { |
| 6038 | mTaskChangeNotificationController.notifySingleTaskDisplayEmpty(displayId); |
| 6039 | } |
| 6040 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6041 | final class H extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6042 | static final int REPORT_TIME_TRACKER_MSG = 1; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 6043 | |
| 6044 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 6045 | static final int FIRST_ACTIVITY_STACK_MSG = 100; |
| 6046 | static final int FIRST_SUPERVISOR_STACK_MSG = 200; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6047 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 6048 | H(Looper looper) { |
| 6049 | super(looper); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6050 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6051 | |
| 6052 | @Override |
| 6053 | public void handleMessage(Message msg) { |
| 6054 | switch (msg.what) { |
| 6055 | case REPORT_TIME_TRACKER_MSG: { |
| 6056 | AppTimeTracker tracker = (AppTimeTracker) msg.obj; |
| 6057 | tracker.deliverResult(mContext); |
| 6058 | } break; |
| 6059 | } |
| 6060 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6061 | } |
| 6062 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6063 | final class UiHandler extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6064 | static final int DISMISS_DIALOG_UI_MSG = 1; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6065 | |
| 6066 | public UiHandler() { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 6067 | super(UiThread.get().getLooper(), null, true); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6068 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6069 | |
| 6070 | @Override |
| 6071 | public void handleMessage(Message msg) { |
| 6072 | switch (msg.what) { |
| 6073 | case DISMISS_DIALOG_UI_MSG: { |
| 6074 | final Dialog d = (Dialog) msg.obj; |
| 6075 | d.dismiss(); |
| 6076 | break; |
| 6077 | } |
| 6078 | } |
| 6079 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6080 | } |
| 6081 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6082 | final class LocalService extends ActivityTaskManagerInternal { |
| 6083 | @Override |
| 6084 | public SleepToken acquireSleepToken(String tag, int displayId) { |
| 6085 | Preconditions.checkNotNull(tag); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6086 | return ActivityTaskManagerService.this.acquireSleepToken(tag, displayId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6087 | } |
| 6088 | |
| 6089 | @Override |
| 6090 | public ComponentName getHomeActivityForUser(int userId) { |
| 6091 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6092 | final ActivityRecord homeActivity = |
| 6093 | mRootActivityContainer.getDefaultDisplayHomeActivityForUser(userId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 6094 | return homeActivity == null ? null : homeActivity.mActivityComponent; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6095 | } |
| 6096 | } |
| 6097 | |
| 6098 | @Override |
| 6099 | public void onLocalVoiceInteractionStarted(IBinder activity, |
| 6100 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 6101 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6102 | onLocalVoiceInteractionStartedLocked(activity, voiceSession, voiceInteractor); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6103 | } |
| 6104 | } |
| 6105 | |
| 6106 | @Override |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 6107 | public void notifySingleTaskDisplayDrawn(int displayId) { |
| 6108 | mTaskChangeNotificationController.notifySingleTaskDisplayDrawn(displayId); |
| 6109 | } |
| 6110 | |
| 6111 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6112 | public void notifyAppTransitionFinished() { |
| 6113 | synchronized (mGlobalLock) { |
| 6114 | mStackSupervisor.notifyAppTransitionDone(); |
| 6115 | } |
| 6116 | } |
| 6117 | |
| 6118 | @Override |
| 6119 | public void notifyAppTransitionCancelled() { |
| 6120 | synchronized (mGlobalLock) { |
| 6121 | mStackSupervisor.notifyAppTransitionDone(); |
| 6122 | } |
| 6123 | } |
| 6124 | |
| 6125 | @Override |
| 6126 | public List<IBinder> getTopVisibleActivities() { |
| 6127 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6128 | return mRootActivityContainer.getTopVisibleActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6129 | } |
| 6130 | } |
| 6131 | |
| 6132 | @Override |
| 6133 | public void notifyDockedStackMinimizedChanged(boolean minimized) { |
| 6134 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6135 | mRootActivityContainer.setDockedStackMinimized(minimized); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | @Override |
| 6140 | public int startActivitiesAsPackage(String packageName, int userId, Intent[] intents, |
| 6141 | Bundle bOptions) { |
| 6142 | Preconditions.checkNotNull(intents, "intents"); |
| 6143 | final String[] resolvedTypes = new String[intents.length]; |
| 6144 | |
| 6145 | // UID of the package on user userId. |
| 6146 | // "= 0" is needed because otherwise catch(RemoteException) would make it look like |
| 6147 | // packageUid may not be initialized. |
| 6148 | int packageUid = 0; |
| 6149 | final long ident = Binder.clearCallingIdentity(); |
| 6150 | |
| 6151 | try { |
| 6152 | for (int i = 0; i < intents.length; i++) { |
| 6153 | resolvedTypes[i] = |
| 6154 | intents[i].resolveTypeIfNeeded(mContext.getContentResolver()); |
| 6155 | } |
| 6156 | |
| 6157 | packageUid = AppGlobals.getPackageManager().getPackageUid( |
| 6158 | packageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId); |
| 6159 | } catch (RemoteException e) { |
| 6160 | // Shouldn't happen. |
| 6161 | } finally { |
| 6162 | Binder.restoreCallingIdentity(ident); |
| 6163 | } |
| 6164 | |
Riddle Hsu | 591bf61 | 2019-02-14 17:55:31 +0800 | [diff] [blame] | 6165 | return getActivityStartController().startActivitiesInPackage( |
| 6166 | packageUid, packageName, |
| 6167 | intents, resolvedTypes, null /* resultTo */, |
| 6168 | SafeActivityOptions.fromBundle(bOptions), userId, |
| 6169 | false /* validateIncomingUser */, null /* originatingPendingIntent */, |
| 6170 | false /* allowBackgroundActivityStart */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6171 | } |
| 6172 | |
| 6173 | @Override |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6174 | public int startActivitiesInPackage(int uid, int realCallingPid, int realCallingUid, |
| 6175 | String callingPackage, Intent[] intents, String[] resolvedTypes, IBinder resultTo, |
| 6176 | SafeActivityOptions options, int userId, boolean validateIncomingUser, |
| 6177 | PendingIntentRecord originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6178 | boolean allowBackgroundActivityStart) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6179 | synchronized (mGlobalLock) { |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6180 | return getActivityStartController().startActivitiesInPackage(uid, realCallingPid, |
| 6181 | realCallingUid, callingPackage, intents, resolvedTypes, resultTo, options, |
| 6182 | userId, validateIncomingUser, originatingPendingIntent, |
| 6183 | allowBackgroundActivityStart); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6184 | } |
| 6185 | } |
| 6186 | |
| 6187 | @Override |
| 6188 | public int startActivityInPackage(int uid, int realCallingPid, int realCallingUid, |
| 6189 | String callingPackage, Intent intent, String resolvedType, IBinder resultTo, |
| 6190 | String resultWho, int requestCode, int startFlags, SafeActivityOptions options, |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 6191 | int userId, Task inTask, String reason, boolean validateIncomingUser, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6192 | PendingIntentRecord originatingPendingIntent, |
| 6193 | boolean allowBackgroundActivityStart) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6194 | synchronized (mGlobalLock) { |
| 6195 | return getActivityStartController().startActivityInPackage(uid, realCallingPid, |
| 6196 | realCallingUid, callingPackage, intent, resolvedType, resultTo, resultWho, |
| 6197 | requestCode, startFlags, options, userId, inTask, reason, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6198 | validateIncomingUser, originatingPendingIntent, |
| 6199 | allowBackgroundActivityStart); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6200 | } |
| 6201 | } |
| 6202 | |
| 6203 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6204 | public int startActivityAsUser(IApplicationThread caller, String callerPacakge, |
| 6205 | Intent intent, Bundle options, int userId) { |
| 6206 | return ActivityTaskManagerService.this.startActivityAsUser( |
| 6207 | caller, callerPacakge, intent, |
| 6208 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 6209 | null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, options, userId, |
| 6210 | false /*validateIncomingUser*/); |
| 6211 | } |
| 6212 | |
| 6213 | @Override |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 6214 | public void notifyKeyguardFlagsChanged(@Nullable Runnable callback, int displayId) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6215 | synchronized (mGlobalLock) { |
| 6216 | |
| 6217 | // We might change the visibilities here, so prepare an empty app transition which |
| 6218 | // might be overridden later if we actually change visibilities. |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6219 | final DisplayContent displayContent = |
| 6220 | mRootActivityContainer.getDisplayContent(displayId); |
| 6221 | if (displayContent == null) { |
lumark | 52ea28e | 2018-11-09 17:30:47 +0800 | [diff] [blame] | 6222 | return; |
| 6223 | } |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6224 | final DisplayContent dc = displayContent.mDisplayContent; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6225 | final boolean wasTransitionSet = |
| 6226 | dc.mAppTransition.getAppTransition() != TRANSIT_NONE; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6227 | if (!wasTransitionSet) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6228 | dc.prepareAppTransition(TRANSIT_NONE, false /* alwaysKeepCurrent */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6229 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6230 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6231 | |
| 6232 | // If there was a transition set already we don't want to interfere with it as we |
| 6233 | // might be starting it too early. |
| 6234 | if (!wasTransitionSet) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6235 | dc.executeAppTransition(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6236 | } |
| 6237 | } |
| 6238 | if (callback != null) { |
| 6239 | callback.run(); |
| 6240 | } |
| 6241 | } |
| 6242 | |
| 6243 | @Override |
| 6244 | public void notifyKeyguardTrustedChanged() { |
| 6245 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6246 | if (mKeyguardController.isKeyguardShowing(DEFAULT_DISPLAY)) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6247 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6248 | } |
| 6249 | } |
| 6250 | } |
| 6251 | |
| 6252 | /** |
| 6253 | * Called after virtual display Id is updated by |
| 6254 | * {@link com.android.server.vr.Vr2dDisplay} with a specific |
| 6255 | * {@param vrVr2dDisplayId}. |
| 6256 | */ |
| 6257 | @Override |
| 6258 | public void setVr2dDisplayId(int vr2dDisplayId) { |
| 6259 | if (DEBUG_STACK) Slog.d(TAG, "setVr2dDisplayId called for: " + vr2dDisplayId); |
| 6260 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6261 | mVr2dDisplayId = vr2dDisplayId; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6262 | } |
| 6263 | } |
| 6264 | |
| 6265 | @Override |
| 6266 | public void setFocusedActivity(IBinder token) { |
| 6267 | synchronized (mGlobalLock) { |
| 6268 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 6269 | if (r == null) { |
| 6270 | throw new IllegalArgumentException( |
| 6271 | "setFocusedActivity: No activity record matching token=" + token); |
| 6272 | } |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 6273 | if (r.moveFocusableActivityToTop("setFocusedActivity")) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6274 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6275 | } |
| 6276 | } |
| 6277 | } |
| 6278 | |
| 6279 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6280 | public void registerScreenObserver(ScreenObserver observer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6281 | mScreenObservers.add(observer); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6282 | } |
| 6283 | |
| 6284 | @Override |
| 6285 | public boolean isCallerRecents(int callingUid) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 6286 | return getRecentTasks().isCallerRecents(callingUid); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6287 | } |
| 6288 | |
| 6289 | @Override |
| 6290 | public boolean isRecentsComponentHomeActivity(int userId) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 6291 | return getRecentTasks().isRecentsComponentHomeActivity(userId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6292 | } |
| 6293 | |
| 6294 | @Override |
| 6295 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
| 6296 | ActivityTaskManagerService.this.cancelRecentsAnimation(restoreHomeStackPosition); |
| 6297 | } |
| 6298 | |
| 6299 | @Override |
| 6300 | public void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6301 | ActivityTaskManagerService.this.enforceCallerIsRecentsOrHasPermission(permission, func); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6302 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6303 | |
| 6304 | @Override |
| 6305 | public void notifyActiveVoiceInteractionServiceChanged(ComponentName component) { |
| 6306 | synchronized (mGlobalLock) { |
| 6307 | mActiveVoiceInteractionServiceComponent = component; |
| 6308 | } |
| 6309 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6310 | |
| 6311 | @Override |
| 6312 | public void setAllowAppSwitches(@NonNull String type, int uid, int userId) { |
| 6313 | if (!mAmInternal.isUserRunning(userId, ActivityManager.FLAG_OR_STOPPED)) { |
| 6314 | return; |
| 6315 | } |
| 6316 | synchronized (mGlobalLock) { |
| 6317 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(userId); |
| 6318 | if (types == null) { |
| 6319 | if (uid < 0) { |
| 6320 | return; |
| 6321 | } |
| 6322 | types = new ArrayMap<>(); |
| 6323 | mAllowAppSwitchUids.put(userId, types); |
| 6324 | } |
| 6325 | if (uid < 0) { |
| 6326 | types.remove(type); |
| 6327 | } else { |
| 6328 | types.put(type, uid); |
| 6329 | } |
| 6330 | } |
| 6331 | } |
| 6332 | |
| 6333 | @Override |
| 6334 | public void onUserStopped(int userId) { |
| 6335 | synchronized (mGlobalLock) { |
| 6336 | getRecentTasks().unloadUserDataFromMemoryLocked(userId); |
| 6337 | mAllowAppSwitchUids.remove(userId); |
| 6338 | } |
| 6339 | } |
| 6340 | |
| 6341 | @Override |
| 6342 | public boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 6343 | synchronized (mGlobalLock) { |
| 6344 | return ActivityTaskManagerService.this.isGetTasksAllowed( |
| 6345 | caller, callingPid, callingUid); |
| 6346 | } |
| 6347 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6348 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6349 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6350 | @Override |
| 6351 | public void onProcessAdded(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6352 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6353 | mProcessNames.put(proc.mName, proc.mUid, proc); |
| 6354 | } |
| 6355 | } |
| 6356 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6357 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6358 | @Override |
| 6359 | public void onProcessRemoved(String name, int uid) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6360 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6361 | mProcessNames.remove(name, uid); |
| 6362 | } |
| 6363 | } |
| 6364 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6365 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6366 | @Override |
| 6367 | public void onCleanUpApplicationRecord(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6368 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6369 | if (proc == mHomeProcess) { |
| 6370 | mHomeProcess = null; |
| 6371 | } |
| 6372 | if (proc == mPreviousProcess) { |
| 6373 | mPreviousProcess = null; |
| 6374 | } |
| 6375 | } |
| 6376 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6377 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6378 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6379 | @Override |
| 6380 | public int getTopProcessState() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6381 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6382 | return mTopProcessState; |
| 6383 | } |
| 6384 | } |
| 6385 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6386 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6387 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6388 | public boolean isHeavyWeightProcess(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6389 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6390 | return proc == mHeavyWeightProcess; |
| 6391 | } |
| 6392 | } |
| 6393 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6394 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6395 | @Override |
| 6396 | public void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6397 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6398 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals(proc); |
| 6399 | } |
| 6400 | } |
| 6401 | |
| 6402 | @Override |
| 6403 | public void finishHeavyWeightApp() { |
| 6404 | synchronized (mGlobalLock) { |
Sudheer Shanka | ee1da27 | 2018-10-20 20:11:44 -0700 | [diff] [blame] | 6405 | if (mHeavyWeightProcess != null) { |
| 6406 | mHeavyWeightProcess.finishActivities(); |
| 6407 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6408 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals( |
| 6409 | mHeavyWeightProcess); |
| 6410 | } |
| 6411 | } |
| 6412 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6413 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6414 | @Override |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6415 | public boolean isSleeping() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6416 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6417 | return isSleepingLocked(); |
| 6418 | } |
| 6419 | } |
| 6420 | |
| 6421 | @Override |
| 6422 | public boolean isShuttingDown() { |
| 6423 | synchronized (mGlobalLock) { |
| 6424 | return mShuttingDown; |
| 6425 | } |
| 6426 | } |
| 6427 | |
| 6428 | @Override |
| 6429 | public boolean shuttingDown(boolean booted, int timeout) { |
| 6430 | synchronized (mGlobalLock) { |
| 6431 | mShuttingDown = true; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6432 | mRootActivityContainer.prepareForShutdown(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6433 | updateEventDispatchingLocked(booted); |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 6434 | notifyTaskPersisterLocked(null, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6435 | return mStackSupervisor.shutdownLocked(timeout); |
| 6436 | } |
| 6437 | } |
| 6438 | |
| 6439 | @Override |
| 6440 | public void enableScreenAfterBoot(boolean booted) { |
| 6441 | synchronized (mGlobalLock) { |
Jeff Chang | d136e77 | 2019-11-05 20:33:52 +0800 | [diff] [blame] | 6442 | writeBootProgressEnableScreen(SystemClock.uptimeMillis()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6443 | mWindowManager.enableScreenAfterBoot(); |
| 6444 | updateEventDispatchingLocked(booted); |
| 6445 | } |
| 6446 | } |
| 6447 | |
| 6448 | @Override |
| 6449 | public boolean showStrictModeViolationDialog() { |
| 6450 | synchronized (mGlobalLock) { |
| 6451 | return mShowDialogs && !mSleeping && !mShuttingDown; |
| 6452 | } |
| 6453 | } |
| 6454 | |
| 6455 | @Override |
| 6456 | public void showSystemReadyErrorDialogsIfNeeded() { |
| 6457 | synchronized (mGlobalLock) { |
| 6458 | try { |
| 6459 | if (AppGlobals.getPackageManager().hasSystemUidErrors()) { |
| 6460 | Slog.e(TAG, "UIDs on the system are inconsistent, you need to wipe your" |
| 6461 | + " data partition or your device will be unstable."); |
| 6462 | mUiHandler.post(() -> { |
| 6463 | if (mShowDialogs) { |
| 6464 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6465 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6466 | d.setCancelable(false); |
| 6467 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6468 | d.setMessage(mUiContext.getText(R.string.system_error_wipe_data)); |
| 6469 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6470 | mUiContext.getText(R.string.ok), |
| 6471 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6472 | d.show(); |
| 6473 | } |
| 6474 | }); |
| 6475 | } |
| 6476 | } catch (RemoteException e) { |
| 6477 | } |
| 6478 | |
| 6479 | if (!Build.isBuildConsistent()) { |
| 6480 | Slog.e(TAG, "Build fingerprint is not consistent, warning user"); |
| 6481 | mUiHandler.post(() -> { |
| 6482 | if (mShowDialogs) { |
| 6483 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6484 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6485 | d.setCancelable(false); |
| 6486 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6487 | d.setMessage(mUiContext.getText(R.string.system_error_manufacturer)); |
| 6488 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6489 | mUiContext.getText(R.string.ok), |
| 6490 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6491 | d.show(); |
| 6492 | } |
| 6493 | }); |
| 6494 | } |
| 6495 | } |
| 6496 | } |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6497 | |
| 6498 | @Override |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6499 | public void onProcessMapped(int pid, WindowProcessController proc) { |
| 6500 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6501 | mProcessMap.put(pid, proc); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6502 | } |
| 6503 | } |
| 6504 | |
| 6505 | @Override |
| 6506 | public void onProcessUnMapped(int pid) { |
| 6507 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6508 | mProcessMap.remove(pid); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6509 | } |
| 6510 | } |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6511 | |
| 6512 | @Override |
| 6513 | public void onPackageDataCleared(String name) { |
| 6514 | synchronized (mGlobalLock) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6515 | mCompatModePackages.handlePackageDataClearedLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6516 | mAppWarnings.onPackageDataCleared(name); |
| 6517 | } |
| 6518 | } |
| 6519 | |
| 6520 | @Override |
| 6521 | public void onPackageUninstalled(String name) { |
| 6522 | synchronized (mGlobalLock) { |
| 6523 | mAppWarnings.onPackageUninstalled(name); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6524 | mCompatModePackages.handlePackageUninstalledLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6525 | } |
| 6526 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6527 | |
| 6528 | @Override |
| 6529 | public void onPackageAdded(String name, boolean replacing) { |
| 6530 | synchronized (mGlobalLock) { |
| 6531 | mCompatModePackages.handlePackageAddedLocked(name, replacing); |
| 6532 | } |
| 6533 | } |
| 6534 | |
| 6535 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6536 | public void onPackageReplaced(ApplicationInfo aInfo) { |
| 6537 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6538 | mRootActivityContainer.updateActivityApplicationInfo(aInfo); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6539 | } |
| 6540 | } |
| 6541 | |
| 6542 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6543 | public CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai) { |
| 6544 | synchronized (mGlobalLock) { |
| 6545 | return compatibilityInfoForPackageLocked(ai); |
| 6546 | } |
| 6547 | } |
| 6548 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6549 | /** |
| 6550 | * Set the corresponding display information for the process global configuration. To be |
| 6551 | * called when we need to show IME on a different display. |
| 6552 | * |
| 6553 | * @param pid The process id associated with the IME window. |
| 6554 | * @param displayId The ID of the display showing the IME. |
| 6555 | */ |
| 6556 | @Override |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6557 | public void onImeWindowSetOnDisplay(final int pid, final int displayId) { |
lumark | 4897353 | 2019-04-12 20:18:15 +0800 | [diff] [blame] | 6558 | // Don't update process-level configuration for Multi-Client IME process since other |
| 6559 | // IMEs on other displays will also receive this configuration change due to IME |
| 6560 | // services use the same application config/context. |
| 6561 | if (InputMethodSystemProperty.MULTI_CLIENT_IME_ENABLED) return; |
lumark | 5df4951 | 2019-04-02 14:56:46 +0800 | [diff] [blame] | 6562 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6563 | if (pid == MY_PID || pid < 0) { |
| 6564 | if (DEBUG_CONFIGURATION) { |
| 6565 | Slog.w(TAG, |
| 6566 | "Trying to update display configuration for system/invalid process."); |
| 6567 | } |
| 6568 | return; |
| 6569 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6570 | synchronized (mGlobalLock) { |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6571 | final DisplayContent displayContent = |
| 6572 | mRootActivityContainer.getDisplayContent(displayId); |
| 6573 | if (displayContent == null) { |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6574 | // Call might come when display is not yet added or has been removed. |
| 6575 | if (DEBUG_CONFIGURATION) { |
| 6576 | Slog.w(TAG, "Trying to update display configuration for non-existing " |
| 6577 | + "displayId=" + displayId); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6578 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6579 | return; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6580 | } |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6581 | final WindowProcessController process = mProcessMap.getProcess(pid); |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6582 | if (process == null) { |
| 6583 | if (DEBUG_CONFIGURATION) { |
| 6584 | Slog.w(TAG, "Trying to update display configuration for invalid " |
| 6585 | + "process, pid=" + pid); |
| 6586 | } |
| 6587 | return; |
| 6588 | } |
lumark | ddc77fb | 2019-06-27 22:22:23 +0800 | [diff] [blame] | 6589 | process.mIsImeProcess = true; |
Louis Chang | 677921f | 2019-12-06 16:44:24 +0800 | [diff] [blame] | 6590 | process.registerDisplayConfigurationListenerLocked(displayContent); |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6591 | } |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6592 | } |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6593 | |
| 6594 | @Override |
| 6595 | public void sendActivityResult(int callingUid, IBinder activityToken, String resultWho, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 6596 | int requestCode, int resultCode, Intent data) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6597 | synchronized (mGlobalLock) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 6598 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 6599 | if (r != null && r.getActivityStack() != null) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 6600 | r.sendResult(callingUid, resultWho, requestCode, resultCode, data); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6601 | } |
| 6602 | } |
| 6603 | } |
| 6604 | |
| 6605 | @Override |
| 6606 | public void clearPendingResultForActivity(IBinder activityToken, |
| 6607 | WeakReference<PendingIntentRecord> pir) { |
| 6608 | synchronized (mGlobalLock) { |
| 6609 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 6610 | if (r != null && r.pendingResults != null) { |
| 6611 | r.pendingResults.remove(pir); |
| 6612 | } |
| 6613 | } |
| 6614 | } |
| 6615 | |
| 6616 | @Override |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6617 | public ActivityTokens getTopActivityForTask(int taskId) { |
| 6618 | synchronized (mGlobalLock) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 6619 | final Task task = mRootActivityContainer.anyTaskForId(taskId); |
| 6620 | if (task == null) { |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6621 | Slog.w(TAG, "getApplicationThreadForTopActivity failed:" |
| 6622 | + " Requested task not found"); |
| 6623 | return null; |
| 6624 | } |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 6625 | final ActivityRecord activity = task.getTopNonFinishingActivity(); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6626 | if (activity == null) { |
| 6627 | Slog.w(TAG, "getApplicationThreadForTopActivity failed:" |
| 6628 | + " Requested activity not found"); |
| 6629 | return null; |
| 6630 | } |
| 6631 | if (!activity.attachedToProcess()) { |
| 6632 | Slog.w(TAG, "getApplicationThreadForTopActivity failed: No process for " |
| 6633 | + activity); |
| 6634 | return null; |
| 6635 | } |
| 6636 | return new ActivityTokens(activity.appToken, activity.assistToken, |
| 6637 | activity.app.getThread()); |
| 6638 | } |
| 6639 | } |
| 6640 | |
| 6641 | @Override |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6642 | public IIntentSender getIntentSender(int type, String packageName, |
| 6643 | int callingUid, int userId, IBinder token, String resultWho, |
| 6644 | int requestCode, Intent[] intents, String[] resolvedTypes, int flags, |
| 6645 | Bundle bOptions) { |
| 6646 | synchronized (mGlobalLock) { |
| 6647 | return getIntentSenderLocked(type, packageName, callingUid, userId, token, |
| 6648 | resultWho, requestCode, intents, resolvedTypes, flags, bOptions); |
| 6649 | } |
| 6650 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 6651 | |
| 6652 | @Override |
| 6653 | public ActivityServiceConnectionsHolder getServiceConnectionsHolder(IBinder token) { |
| 6654 | synchronized (mGlobalLock) { |
| 6655 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 6656 | if (r == null) { |
| 6657 | return null; |
| 6658 | } |
| 6659 | if (r.mServiceConnectionsHolder == null) { |
| 6660 | r.mServiceConnectionsHolder = new ActivityServiceConnectionsHolder( |
| 6661 | ActivityTaskManagerService.this, r); |
| 6662 | } |
| 6663 | |
| 6664 | return r.mServiceConnectionsHolder; |
| 6665 | } |
| 6666 | } |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6667 | |
| 6668 | @Override |
| 6669 | public Intent getHomeIntent() { |
| 6670 | synchronized (mGlobalLock) { |
| 6671 | return ActivityTaskManagerService.this.getHomeIntent(); |
| 6672 | } |
| 6673 | } |
| 6674 | |
| 6675 | @Override |
| 6676 | public boolean startHomeActivity(int userId, String reason) { |
| 6677 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6678 | return mRootActivityContainer.startHomeOnDisplay(userId, reason, DEFAULT_DISPLAY); |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6679 | } |
| 6680 | } |
| 6681 | |
| 6682 | @Override |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 6683 | public boolean startHomeOnDisplay(int userId, String reason, int displayId, |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 6684 | boolean allowInstrumenting, boolean fromHomeKey) { |
Chilun | 5fd5654 | 2019-03-21 19:51:37 +0800 | [diff] [blame] | 6685 | synchronized (mGlobalLock) { |
| 6686 | return mRootActivityContainer.startHomeOnDisplay(userId, reason, displayId, |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 6687 | allowInstrumenting, fromHomeKey); |
Chilun | 5fd5654 | 2019-03-21 19:51:37 +0800 | [diff] [blame] | 6688 | } |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 6689 | } |
| 6690 | |
| 6691 | @Override |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6692 | public boolean startHomeOnAllDisplays(int userId, String reason) { |
| 6693 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6694 | return mRootActivityContainer.startHomeOnAllDisplays(userId, reason); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6695 | } |
| 6696 | } |
| 6697 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6698 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6699 | @Override |
| 6700 | public boolean isFactoryTestProcess(WindowProcessController wpc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6701 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6702 | if (mFactoryTest == FACTORY_TEST_OFF) { |
| 6703 | return false; |
| 6704 | } |
| 6705 | if (mFactoryTest == FACTORY_TEST_LOW_LEVEL && mTopComponent != null |
| 6706 | && wpc.mName.equals(mTopComponent.getPackageName())) { |
| 6707 | return true; |
| 6708 | } |
| 6709 | return mFactoryTest == FACTORY_TEST_HIGH_LEVEL |
| 6710 | && (wpc.mInfo.flags & FLAG_FACTORY_TEST) != 0; |
| 6711 | } |
| 6712 | } |
| 6713 | |
| 6714 | @Override |
| 6715 | public void updateTopComponentForFactoryTest() { |
| 6716 | synchronized (mGlobalLock) { |
| 6717 | if (mFactoryTest != FACTORY_TEST_LOW_LEVEL) { |
| 6718 | return; |
| 6719 | } |
| 6720 | final ResolveInfo ri = mContext.getPackageManager() |
| 6721 | .resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST), STOCK_PM_FLAGS); |
| 6722 | final CharSequence errorMsg; |
| 6723 | if (ri != null) { |
| 6724 | final ActivityInfo ai = ri.activityInfo; |
| 6725 | final ApplicationInfo app = ai.applicationInfo; |
| 6726 | if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 6727 | mTopAction = Intent.ACTION_FACTORY_TEST; |
| 6728 | mTopData = null; |
| 6729 | mTopComponent = new ComponentName(app.packageName, ai.name); |
| 6730 | errorMsg = null; |
| 6731 | } else { |
| 6732 | errorMsg = mContext.getResources().getText( |
| 6733 | com.android.internal.R.string.factorytest_not_system); |
| 6734 | } |
| 6735 | } else { |
| 6736 | errorMsg = mContext.getResources().getText( |
| 6737 | com.android.internal.R.string.factorytest_no_action); |
| 6738 | } |
| 6739 | if (errorMsg == null) { |
| 6740 | return; |
| 6741 | } |
| 6742 | |
| 6743 | mTopAction = null; |
| 6744 | mTopData = null; |
| 6745 | mTopComponent = null; |
| 6746 | mUiHandler.post(() -> { |
| 6747 | Dialog d = new FactoryErrorDialog(mUiContext, errorMsg); |
| 6748 | d.show(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 6749 | mAmInternal.ensureBootCompleted(); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6750 | }); |
| 6751 | } |
| 6752 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6753 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6754 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6755 | @Override |
| 6756 | public void handleAppDied(WindowProcessController wpc, boolean restarting, |
| 6757 | Runnable finishInstrumentationCallback) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6758 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6759 | // Remove this application's activities from active lists. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6760 | boolean hasVisibleActivities = mRootActivityContainer.handleAppDied(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6761 | |
| 6762 | wpc.clearRecentTasks(); |
| 6763 | wpc.clearActivities(); |
| 6764 | |
| 6765 | if (wpc.isInstrumenting()) { |
| 6766 | finishInstrumentationCallback.run(); |
| 6767 | } |
| 6768 | |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6769 | if (!restarting && hasVisibleActivities) { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 6770 | deferWindowLayout(); |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6771 | try { |
| 6772 | if (!mRootActivityContainer.resumeFocusedStacksTopActivities()) { |
| 6773 | // If there was nothing to resume, and we are not already restarting |
| 6774 | // this process, but there is a visible activity that is hosted by the |
| 6775 | // process...then make sure all visible activities are running, taking |
| 6776 | // care of restarting this process. |
| 6777 | mRootActivityContainer.ensureActivitiesVisible(null, 0, |
| 6778 | !PRESERVE_WINDOWS); |
| 6779 | } |
| 6780 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 6781 | continueWindowLayout(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6782 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6783 | } |
| 6784 | } |
| 6785 | } |
| 6786 | |
| 6787 | @Override |
| 6788 | public void closeSystemDialogs(String reason) { |
| 6789 | enforceNotIsolatedCaller("closeSystemDialogs"); |
| 6790 | |
| 6791 | final int pid = Binder.getCallingPid(); |
| 6792 | final int uid = Binder.getCallingUid(); |
| 6793 | final long origId = Binder.clearCallingIdentity(); |
| 6794 | try { |
| 6795 | synchronized (mGlobalLock) { |
| 6796 | // Only allow this from foreground processes, so that background |
| 6797 | // applications can't abuse it to prevent system UI from being shown. |
| 6798 | if (uid >= FIRST_APPLICATION_UID) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6799 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6800 | if (!proc.isPerceptible()) { |
| 6801 | Slog.w(TAG, "Ignoring closeSystemDialogs " + reason |
| 6802 | + " from background process " + proc); |
| 6803 | return; |
| 6804 | } |
| 6805 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6806 | mWindowManager.closeSystemDialogs(reason); |
| 6807 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6808 | mRootActivityContainer.closeSystemDialogs(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6809 | } |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 6810 | // Call into AM outside the synchronized block. |
| 6811 | mAmInternal.broadcastCloseSystemDialogs(reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6812 | } finally { |
| 6813 | Binder.restoreCallingIdentity(origId); |
| 6814 | } |
| 6815 | } |
| 6816 | |
| 6817 | @Override |
| 6818 | public void cleanupDisabledPackageComponents( |
| 6819 | String packageName, Set<String> disabledClasses, int userId, boolean booted) { |
| 6820 | synchronized (mGlobalLock) { |
| 6821 | // Clean-up disabled activities. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6822 | if (mRootActivityContainer.finishDisabledPackageActivities( |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6823 | packageName, disabledClasses, true, false, userId) && booted) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6824 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6825 | mStackSupervisor.scheduleIdleLocked(); |
| 6826 | } |
| 6827 | |
| 6828 | // Clean-up disabled tasks |
| 6829 | getRecentTasks().cleanupDisabledPackageTasksLocked( |
| 6830 | packageName, disabledClasses, userId); |
| 6831 | } |
| 6832 | } |
| 6833 | |
| 6834 | @Override |
| 6835 | public boolean onForceStopPackage(String packageName, boolean doit, boolean evenPersistent, |
| 6836 | int userId) { |
| 6837 | synchronized (mGlobalLock) { |
| 6838 | |
| 6839 | boolean didSomething = |
| 6840 | getActivityStartController().clearPendingActivityLaunches(packageName); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6841 | didSomething |= mRootActivityContainer.finishDisabledPackageActivities(packageName, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6842 | null, doit, evenPersistent, userId); |
| 6843 | return didSomething; |
| 6844 | } |
| 6845 | } |
| 6846 | |
| 6847 | @Override |
| 6848 | public void resumeTopActivities(boolean scheduleIdle) { |
| 6849 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6850 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6851 | if (scheduleIdle) { |
| 6852 | mStackSupervisor.scheduleIdleLocked(); |
| 6853 | } |
| 6854 | } |
| 6855 | } |
| 6856 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6857 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6858 | @Override |
| 6859 | public void preBindApplication(WindowProcessController wpc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6860 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6861 | mStackSupervisor.getActivityMetricsLogger().notifyBindApplication(wpc.mInfo); |
| 6862 | } |
| 6863 | } |
| 6864 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6865 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6866 | @Override |
| 6867 | public boolean attachApplication(WindowProcessController wpc) throws RemoteException { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6868 | synchronized (mGlobalLockWithoutBoost) { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 6869 | if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) { |
| 6870 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "attachApplication:" + wpc.mName); |
| 6871 | } |
| 6872 | try { |
| 6873 | return mRootActivityContainer.attachApplication(wpc); |
| 6874 | } finally { |
| 6875 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 6876 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6877 | } |
| 6878 | } |
| 6879 | |
| 6880 | @Override |
| 6881 | public void notifyLockedProfile(@UserIdInt int userId, int currentUserId) { |
| 6882 | try { |
| 6883 | if (!AppGlobals.getPackageManager().isUidPrivileged(Binder.getCallingUid())) { |
| 6884 | throw new SecurityException("Only privileged app can call notifyLockedProfile"); |
| 6885 | } |
| 6886 | } catch (RemoteException ex) { |
| 6887 | throw new SecurityException("Fail to check is caller a privileged app", ex); |
| 6888 | } |
| 6889 | |
| 6890 | synchronized (mGlobalLock) { |
| 6891 | final long ident = Binder.clearCallingIdentity(); |
| 6892 | try { |
| 6893 | if (mAmInternal.shouldConfirmCredentials(userId)) { |
| 6894 | if (mKeyguardController.isKeyguardLocked()) { |
| 6895 | // Showing launcher to avoid user entering credential twice. |
| 6896 | startHomeActivity(currentUserId, "notifyLockedProfile"); |
| 6897 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6898 | mRootActivityContainer.lockAllProfileTasks(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6899 | } |
| 6900 | } finally { |
| 6901 | Binder.restoreCallingIdentity(ident); |
| 6902 | } |
| 6903 | } |
| 6904 | } |
| 6905 | |
| 6906 | @Override |
| 6907 | public void startConfirmDeviceCredentialIntent(Intent intent, Bundle options) { |
| 6908 | mAmInternal.enforceCallingPermission( |
| 6909 | MANAGE_ACTIVITY_STACKS, "startConfirmDeviceCredentialIntent"); |
| 6910 | |
| 6911 | synchronized (mGlobalLock) { |
| 6912 | final long ident = Binder.clearCallingIdentity(); |
| 6913 | try { |
Pavel Grafov | c0fe0a0 | 2019-05-13 18:19:33 +0100 | [diff] [blame] | 6914 | intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 6915 | final ActivityOptions activityOptions = options != null |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6916 | ? new ActivityOptions(options) : ActivityOptions.makeBasic(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6917 | mContext.startActivityAsUser(intent, activityOptions.toBundle(), |
| 6918 | UserHandle.CURRENT); |
| 6919 | } finally { |
| 6920 | Binder.restoreCallingIdentity(ident); |
| 6921 | } |
| 6922 | } |
| 6923 | } |
| 6924 | |
| 6925 | @Override |
| 6926 | public void writeActivitiesToProto(ProtoOutputStream proto) { |
| 6927 | synchronized (mGlobalLock) { |
| 6928 | // The output proto of "activity --proto activities" |
| 6929 | // is ActivityManagerServiceDumpActivitiesProto |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 6930 | mRootActivityContainer.dumpDebug(proto, |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 6931 | ActivityManagerServiceDumpActivitiesProto.ACTIVITY_STACK_SUPERVISOR, |
| 6932 | WindowTraceLogLevel.ALL); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6933 | } |
| 6934 | } |
| 6935 | |
| 6936 | @Override |
| 6937 | public void saveANRState(String reason) { |
| 6938 | synchronized (mGlobalLock) { |
| 6939 | final StringWriter sw = new StringWriter(); |
| 6940 | final PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
| 6941 | pw.println(" ANR time: " + DateFormat.getDateTimeInstance().format(new Date())); |
| 6942 | if (reason != null) { |
| 6943 | pw.println(" Reason: " + reason); |
| 6944 | } |
| 6945 | pw.println(); |
| 6946 | getActivityStartController().dump(pw, " ", null); |
| 6947 | pw.println(); |
| 6948 | pw.println("-------------------------------------------------------------------------------"); |
| 6949 | dumpActivitiesLocked(null /* fd */, pw, null /* args */, 0 /* opti */, |
| 6950 | true /* dumpAll */, false /* dumpClient */, null /* dumpPackage */, |
| 6951 | "" /* header */); |
| 6952 | pw.println(); |
| 6953 | pw.close(); |
| 6954 | |
| 6955 | mLastANRState = sw.toString(); |
| 6956 | } |
| 6957 | } |
| 6958 | |
| 6959 | @Override |
| 6960 | public void clearSavedANRState() { |
| 6961 | synchronized (mGlobalLock) { |
| 6962 | mLastANRState = null; |
| 6963 | } |
| 6964 | } |
| 6965 | |
| 6966 | @Override |
| 6967 | public void dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args, int opti, |
| 6968 | boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 6969 | synchronized (mGlobalLock) { |
| 6970 | if (DUMP_ACTIVITIES_CMD.equals(cmd) || DUMP_ACTIVITIES_SHORT_CMD.equals(cmd)) { |
| 6971 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage); |
| 6972 | } else if (DUMP_LASTANR_CMD.equals(cmd)) { |
| 6973 | dumpLastANRLocked(pw); |
| 6974 | } else if (DUMP_LASTANR_TRACES_CMD.equals(cmd)) { |
| 6975 | dumpLastANRTracesLocked(pw); |
| 6976 | } else if (DUMP_STARTER_CMD.equals(cmd)) { |
| 6977 | dumpActivityStarterLocked(pw, dumpPackage); |
| 6978 | } else if (DUMP_CONTAINERS_CMD.equals(cmd)) { |
| 6979 | dumpActivityContainersLocked(pw); |
| 6980 | } else if (DUMP_RECENTS_CMD.equals(cmd) || DUMP_RECENTS_SHORT_CMD.equals(cmd)) { |
| 6981 | if (getRecentTasks() != null) { |
| 6982 | getRecentTasks().dump(pw, dumpAll, dumpPackage); |
| 6983 | } |
| 6984 | } |
| 6985 | } |
| 6986 | } |
| 6987 | |
| 6988 | @Override |
| 6989 | public boolean dumpForProcesses(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 6990 | String dumpPackage, int dumpAppId, boolean needSep, boolean testPssMode, |
| 6991 | int wakefulness) { |
| 6992 | synchronized (mGlobalLock) { |
| 6993 | if (mHomeProcess != null && (dumpPackage == null |
| 6994 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
| 6995 | if (needSep) { |
| 6996 | pw.println(); |
| 6997 | needSep = false; |
| 6998 | } |
| 6999 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 7000 | } |
| 7001 | if (mPreviousProcess != null && (dumpPackage == null |
| 7002 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 7003 | if (needSep) { |
| 7004 | pw.println(); |
| 7005 | needSep = false; |
| 7006 | } |
| 7007 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 7008 | } |
| 7009 | if (dumpAll && (mPreviousProcess == null || dumpPackage == null |
| 7010 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 7011 | StringBuilder sb = new StringBuilder(128); |
| 7012 | sb.append(" mPreviousProcessVisibleTime: "); |
| 7013 | TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb); |
| 7014 | pw.println(sb); |
| 7015 | } |
| 7016 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 7017 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
| 7018 | if (needSep) { |
| 7019 | pw.println(); |
| 7020 | needSep = false; |
| 7021 | } |
| 7022 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 7023 | } |
| 7024 | if (dumpPackage == null) { |
| 7025 | pw.println(" mGlobalConfiguration: " + getGlobalConfiguration()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7026 | mRootActivityContainer.dumpDisplayConfigs(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7027 | } |
| 7028 | if (dumpAll) { |
| 7029 | if (dumpPackage == null) { |
| 7030 | pw.println(" mConfigWillChange: " |
| 7031 | + getTopDisplayFocusedStack().mConfigWillChange); |
| 7032 | } |
| 7033 | if (mCompatModePackages.getPackages().size() > 0) { |
| 7034 | boolean printed = false; |
| 7035 | for (Map.Entry<String, Integer> entry |
| 7036 | : mCompatModePackages.getPackages().entrySet()) { |
| 7037 | String pkg = entry.getKey(); |
| 7038 | int mode = entry.getValue(); |
| 7039 | if (dumpPackage != null && !dumpPackage.equals(pkg)) { |
| 7040 | continue; |
| 7041 | } |
| 7042 | if (!printed) { |
| 7043 | pw.println(" mScreenCompatPackages:"); |
| 7044 | printed = true; |
| 7045 | } |
| 7046 | pw.println(" " + pkg + ": " + mode); |
| 7047 | } |
| 7048 | } |
| 7049 | } |
| 7050 | |
| 7051 | if (dumpPackage == null) { |
| 7052 | pw.println(" mWakefulness=" |
| 7053 | + PowerManagerInternal.wakefulnessToString(wakefulness)); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7054 | pw.println(" mSleepTokens=" + mRootActivityContainer.mSleepTokens); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7055 | if (mRunningVoice != null) { |
| 7056 | pw.println(" mRunningVoice=" + mRunningVoice); |
| 7057 | pw.println(" mVoiceWakeLock" + mVoiceWakeLock); |
| 7058 | } |
| 7059 | pw.println(" mSleeping=" + mSleeping); |
| 7060 | pw.println(" mShuttingDown=" + mShuttingDown + " mTestPssMode=" + testPssMode); |
| 7061 | pw.println(" mVrController=" + mVrController); |
| 7062 | } |
| 7063 | if (mCurAppTimeTracker != null) { |
| 7064 | mCurAppTimeTracker.dumpWithHeader(pw, " ", true); |
| 7065 | } |
| 7066 | if (mAllowAppSwitchUids.size() > 0) { |
| 7067 | boolean printed = false; |
| 7068 | for (int i = 0; i < mAllowAppSwitchUids.size(); i++) { |
| 7069 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.valueAt(i); |
| 7070 | for (int j = 0; j < types.size(); j++) { |
| 7071 | if (dumpPackage == null || |
| 7072 | UserHandle.getAppId(types.valueAt(j).intValue()) == dumpAppId) { |
| 7073 | if (needSep) { |
| 7074 | pw.println(); |
| 7075 | needSep = false; |
| 7076 | } |
| 7077 | if (!printed) { |
| 7078 | pw.println(" mAllowAppSwitchUids:"); |
| 7079 | printed = true; |
| 7080 | } |
| 7081 | pw.print(" User "); |
| 7082 | pw.print(mAllowAppSwitchUids.keyAt(i)); |
| 7083 | pw.print(": Type "); |
| 7084 | pw.print(types.keyAt(j)); |
| 7085 | pw.print(" = "); |
| 7086 | UserHandle.formatUid(pw, types.valueAt(j).intValue()); |
| 7087 | pw.println(); |
| 7088 | } |
| 7089 | } |
| 7090 | } |
| 7091 | } |
| 7092 | if (dumpPackage == null) { |
| 7093 | if (mController != null) { |
| 7094 | pw.println(" mController=" + mController |
| 7095 | + " mControllerIsAMonkey=" + mControllerIsAMonkey); |
| 7096 | } |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 7097 | pw.println(" mGoingToSleepWakeLock=" + mStackSupervisor.mGoingToSleepWakeLock); |
| 7098 | pw.println(" mLaunchingActivityWakeLock=" |
| 7099 | + mStackSupervisor.mLaunchingActivityWakeLock); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7100 | } |
| 7101 | |
| 7102 | return needSep; |
| 7103 | } |
| 7104 | } |
| 7105 | |
| 7106 | @Override |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7107 | public void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage, |
| 7108 | int wakeFullness, boolean testPssMode) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7109 | synchronized (mGlobalLock) { |
| 7110 | if (dumpPackage == null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7111 | getGlobalConfiguration().dumpDebug(proto, GLOBAL_CONFIGURATION); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7112 | proto.write(CONFIG_WILL_CHANGE, getTopDisplayFocusedStack().mConfigWillChange); |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7113 | writeSleepStateToProto(proto, wakeFullness, testPssMode); |
| 7114 | if (mRunningVoice != null) { |
| 7115 | final long vrToken = proto.start( |
| 7116 | ActivityManagerServiceDumpProcessesProto.RUNNING_VOICE); |
| 7117 | proto.write(ActivityManagerServiceDumpProcessesProto.Voice.SESSION, |
| 7118 | mRunningVoice.toString()); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7119 | mVoiceWakeLock.dumpDebug( |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7120 | proto, ActivityManagerServiceDumpProcessesProto.Voice.WAKELOCK); |
| 7121 | proto.end(vrToken); |
| 7122 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7123 | mVrController.dumpDebug(proto, |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7124 | ActivityManagerServiceDumpProcessesProto.VR_CONTROLLER); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7125 | if (mController != null) { |
| 7126 | final long token = proto.start(CONTROLLER); |
| 7127 | proto.write(CONTROLLER, mController.toString()); |
| 7128 | proto.write(IS_A_MONKEY, mControllerIsAMonkey); |
| 7129 | proto.end(token); |
| 7130 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7131 | mStackSupervisor.mGoingToSleepWakeLock.dumpDebug(proto, GOING_TO_SLEEP); |
| 7132 | mStackSupervisor.mLaunchingActivityWakeLock.dumpDebug(proto, |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 7133 | LAUNCHING_ACTIVITY); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7134 | } |
| 7135 | |
| 7136 | if (mHomeProcess != null && (dumpPackage == null |
| 7137 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7138 | mHomeProcess.dumpDebug(proto, HOME_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7139 | } |
| 7140 | |
| 7141 | if (mPreviousProcess != null && (dumpPackage == null |
| 7142 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7143 | mPreviousProcess.dumpDebug(proto, PREVIOUS_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7144 | proto.write(PREVIOUS_PROC_VISIBLE_TIME_MS, mPreviousProcessVisibleTime); |
| 7145 | } |
| 7146 | |
| 7147 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 7148 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7149 | mHeavyWeightProcess.dumpDebug(proto, HEAVY_WEIGHT_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7150 | } |
| 7151 | |
| 7152 | for (Map.Entry<String, Integer> entry |
| 7153 | : mCompatModePackages.getPackages().entrySet()) { |
| 7154 | String pkg = entry.getKey(); |
| 7155 | int mode = entry.getValue(); |
| 7156 | if (dumpPackage == null || dumpPackage.equals(pkg)) { |
| 7157 | long compatToken = proto.start(SCREEN_COMPAT_PACKAGES); |
| 7158 | proto.write(PACKAGE, pkg); |
| 7159 | proto.write(MODE, mode); |
| 7160 | proto.end(compatToken); |
| 7161 | } |
| 7162 | } |
| 7163 | |
| 7164 | if (mCurAppTimeTracker != null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 7165 | mCurAppTimeTracker.dumpDebug(proto, CURRENT_TRACKER, true); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7166 | } |
| 7167 | |
| 7168 | } |
| 7169 | } |
| 7170 | |
| 7171 | @Override |
| 7172 | public boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, |
| 7173 | String[] args, int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, |
| 7174 | boolean dumpFocusedStackOnly) { |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 7175 | return ActivityTaskManagerService.this.dumpActivity(fd, pw, name, args, opti, dumpAll, |
| 7176 | dumpVisibleStacksOnly, dumpFocusedStackOnly); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7177 | } |
| 7178 | |
| 7179 | @Override |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 7180 | public void dumpForOom(PrintWriter pw) { |
| 7181 | synchronized (mGlobalLock) { |
| 7182 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 7183 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 7184 | if (mHeavyWeightProcess != null) { |
| 7185 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 7186 | } |
| 7187 | } |
| 7188 | } |
| 7189 | |
| 7190 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7191 | public boolean canGcNow() { |
| 7192 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7193 | return isSleeping() || mRootActivityContainer.allResumedActivitiesIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7194 | } |
| 7195 | } |
| 7196 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7197 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7198 | @Override |
| 7199 | public WindowProcessController getTopApp() { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7200 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7201 | final ActivityRecord top = mRootActivityContainer.getTopResumedActivity(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7202 | return top != null ? top.app : null; |
| 7203 | } |
| 7204 | } |
| 7205 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7206 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7207 | @Override |
| 7208 | public void rankTaskLayersIfNeeded() { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7209 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7210 | if (mRootActivityContainer != null) { |
| 7211 | mRootActivityContainer.rankTaskLayersIfNeeded(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7212 | } |
| 7213 | } |
| 7214 | } |
| 7215 | |
| 7216 | @Override |
| 7217 | public void scheduleDestroyAllActivities(String reason) { |
| 7218 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7219 | mRootActivityContainer.scheduleDestroyAllActivities(null, reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7220 | } |
| 7221 | } |
| 7222 | |
| 7223 | @Override |
| 7224 | public void removeUser(int userId) { |
| 7225 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7226 | mRootActivityContainer.removeUser(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7227 | } |
| 7228 | } |
| 7229 | |
| 7230 | @Override |
| 7231 | public boolean switchUser(int userId, UserState userState) { |
| 7232 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7233 | return mRootActivityContainer.switchUser(userId, userState); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7234 | } |
| 7235 | } |
| 7236 | |
| 7237 | @Override |
| 7238 | public void onHandleAppCrash(WindowProcessController wpc) { |
| 7239 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7240 | mRootActivityContainer.handleAppCrash(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7241 | } |
| 7242 | } |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 7243 | |
| 7244 | @Override |
| 7245 | public int finishTopCrashedActivities(WindowProcessController crashedApp, String reason) { |
| 7246 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7247 | return mRootActivityContainer.finishTopCrashedActivities(crashedApp, reason); |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 7248 | } |
| 7249 | } |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7250 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7251 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7252 | @Override |
| 7253 | public void onUidActive(int uid, int procState) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7254 | mActiveUids.onUidActive(uid, procState); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7255 | } |
| 7256 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7257 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7258 | @Override |
| 7259 | public void onUidInactive(int uid) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7260 | mActiveUids.onUidInactive(uid); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7261 | } |
| 7262 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7263 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7264 | @Override |
| 7265 | public void onActiveUidsCleared() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7266 | mActiveUids.onActiveUidsCleared(); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7267 | } |
| 7268 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7269 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7270 | @Override |
| 7271 | public void onUidProcStateChanged(int uid, int procState) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7272 | mActiveUids.onUidProcStateChanged(uid, procState); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7273 | } |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7274 | |
| 7275 | @Override |
| 7276 | public void onUidAddedToPendingTempWhitelist(int uid, String tag) { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7277 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7278 | mPendingTempWhitelist.put(uid, tag); |
| 7279 | } |
| 7280 | } |
| 7281 | |
| 7282 | @Override |
| 7283 | public void onUidRemovedFromPendingTempWhitelist(int uid) { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7284 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7285 | mPendingTempWhitelist.remove(uid); |
| 7286 | } |
| 7287 | } |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 7288 | |
| 7289 | @Override |
| 7290 | public boolean handleAppCrashInActivityController(String processName, int pid, |
| 7291 | String shortMsg, String longMsg, long timeMillis, String stackTrace, |
| 7292 | Runnable killCrashingAppCallback) { |
| 7293 | synchronized (mGlobalLock) { |
| 7294 | if (mController == null) { |
| 7295 | return false; |
| 7296 | } |
| 7297 | |
| 7298 | try { |
| 7299 | if (!mController.appCrashed(processName, pid, shortMsg, longMsg, timeMillis, |
| 7300 | stackTrace)) { |
| 7301 | killCrashingAppCallback.run(); |
| 7302 | return true; |
| 7303 | } |
| 7304 | } catch (RemoteException e) { |
| 7305 | mController = null; |
| 7306 | Watchdog.getInstance().setActivityController(null); |
| 7307 | } |
| 7308 | return false; |
| 7309 | } |
| 7310 | } |
Wale Ogunwale | d7889f5 | 2018-10-25 11:03:20 -0700 | [diff] [blame] | 7311 | |
| 7312 | @Override |
| 7313 | public void removeRecentTasksByPackageName(String packageName, int userId) { |
| 7314 | synchronized (mGlobalLock) { |
| 7315 | mRecentTasks.removeTasksByPackageName(packageName, userId); |
| 7316 | } |
| 7317 | } |
| 7318 | |
| 7319 | @Override |
| 7320 | public void cleanupRecentTasksForUser(int userId) { |
| 7321 | synchronized (mGlobalLock) { |
| 7322 | mRecentTasks.cleanupLocked(userId); |
| 7323 | } |
| 7324 | } |
| 7325 | |
| 7326 | @Override |
| 7327 | public void loadRecentTasksForUser(int userId) { |
| 7328 | synchronized (mGlobalLock) { |
| 7329 | mRecentTasks.loadUserRecentsLocked(userId); |
| 7330 | } |
| 7331 | } |
| 7332 | |
| 7333 | @Override |
| 7334 | public void onPackagesSuspendedChanged(String[] packages, boolean suspended, int userId) { |
| 7335 | synchronized (mGlobalLock) { |
| 7336 | mRecentTasks.onPackagesSuspendedChanged(packages, suspended, userId); |
| 7337 | } |
| 7338 | } |
| 7339 | |
| 7340 | @Override |
| 7341 | public void flushRecentTasks() { |
| 7342 | mRecentTasks.flush(); |
| 7343 | } |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 7344 | |
| 7345 | @Override |
| 7346 | public WindowProcessController getHomeProcess() { |
| 7347 | synchronized (mGlobalLock) { |
| 7348 | return mHomeProcess; |
| 7349 | } |
| 7350 | } |
| 7351 | |
| 7352 | @Override |
| 7353 | public WindowProcessController getPreviousProcess() { |
| 7354 | synchronized (mGlobalLock) { |
| 7355 | return mPreviousProcess; |
| 7356 | } |
| 7357 | } |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 7358 | |
| 7359 | @Override |
| 7360 | public void clearLockedTasks(String reason) { |
| 7361 | synchronized (mGlobalLock) { |
| 7362 | getLockTaskController().clearLockedTasks(reason); |
| 7363 | } |
| 7364 | } |
| 7365 | |
| 7366 | @Override |
| 7367 | public void updateUserConfiguration() { |
| 7368 | synchronized (mGlobalLock) { |
| 7369 | final Configuration configuration = new Configuration(getGlobalConfiguration()); |
| 7370 | final int currentUserId = mAmInternal.getCurrentUserId(); |
| 7371 | Settings.System.adjustConfigurationForUser(mContext.getContentResolver(), |
| 7372 | configuration, currentUserId, Settings.System.canWrite(mContext)); |
| 7373 | updateConfigurationLocked(configuration, null /* starting */, |
| 7374 | false /* initLocale */, false /* persistent */, currentUserId, |
| 7375 | false /* deferResume */); |
| 7376 | } |
| 7377 | } |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 7378 | |
| 7379 | @Override |
| 7380 | public boolean canShowErrorDialogs() { |
| 7381 | synchronized (mGlobalLock) { |
| 7382 | return mShowDialogs && !mSleeping && !mShuttingDown |
| 7383 | && !mKeyguardController.isKeyguardOrAodShowing(DEFAULT_DISPLAY) |
| 7384 | && !hasUserRestriction(UserManager.DISALLOW_SYSTEM_ERROR_DIALOGS, |
| 7385 | mAmInternal.getCurrentUserId()) |
| 7386 | && !(UserManager.isDeviceInDemoMode(mContext) |
| 7387 | && mAmInternal.getCurrentUser().isDemo()); |
| 7388 | } |
| 7389 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 7390 | |
| 7391 | @Override |
| 7392 | public void setProfileApp(String profileApp) { |
| 7393 | synchronized (mGlobalLock) { |
| 7394 | mProfileApp = profileApp; |
| 7395 | } |
| 7396 | } |
| 7397 | |
| 7398 | @Override |
| 7399 | public void setProfileProc(WindowProcessController wpc) { |
| 7400 | synchronized (mGlobalLock) { |
| 7401 | mProfileProc = wpc; |
| 7402 | } |
| 7403 | } |
| 7404 | |
| 7405 | @Override |
| 7406 | public void setProfilerInfo(ProfilerInfo profilerInfo) { |
| 7407 | synchronized (mGlobalLock) { |
| 7408 | mProfilerInfo = profilerInfo; |
| 7409 | } |
| 7410 | } |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 7411 | |
| 7412 | @Override |
| 7413 | public ActivityMetricsLaunchObserverRegistry getLaunchObserverRegistry() { |
| 7414 | synchronized (mGlobalLock) { |
| 7415 | return mStackSupervisor.getActivityMetricsLogger().getLaunchObserverRegistry(); |
| 7416 | } |
| 7417 | } |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 7418 | |
| 7419 | @Override |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 7420 | public ActivityManager.TaskSnapshot getTaskSnapshotNoRestore(int taskId, |
| 7421 | boolean reducedResolution) { |
| 7422 | return ActivityTaskManagerService.this.getTaskSnapshot(taskId, reducedResolution, |
| 7423 | false /* restoreFromDisk */); |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 7424 | } |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 7425 | |
| 7426 | @Override |
| 7427 | public boolean isUidForeground(int uid) { |
| 7428 | synchronized (mGlobalLock) { |
| 7429 | return ActivityTaskManagerService.this.isUidForeground(uid); |
| 7430 | } |
| 7431 | } |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7432 | |
| 7433 | @Override |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 7434 | public void setDeviceOwnerUid(int uid) { |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7435 | synchronized (mGlobalLock) { |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 7436 | ActivityTaskManagerService.this.setDeviceOwnerUid(uid); |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7437 | } |
| 7438 | } |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7439 | |
| 7440 | @Override |
| 7441 | public void setCompanionAppPackages(int userId, Set<String> companionAppPackages) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7442 | // Translate package names into UIDs |
| 7443 | final Set<Integer> result = new HashSet<>(); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7444 | for (String pkg : companionAppPackages) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7445 | final int uid = getPackageManagerInternalLocked().getPackageUid(pkg, 0, userId); |
| 7446 | if (uid >= 0) { |
| 7447 | result.add(uid); |
| 7448 | } |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7449 | } |
| 7450 | synchronized (mGlobalLock) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7451 | mCompanionAppUidsMap.put(userId, result); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7452 | } |
| 7453 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 7454 | } |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 7455 | } |