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 | f307365 | 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; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 48 | import static android.content.pm.PackageManager.FEATURE_PC; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 49 | import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 50 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 51 | import static android.content.res.Configuration.UI_MODE_TYPE_TELEVISION; |
| 52 | import static android.os.Build.VERSION_CODES.N; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 53 | import static android.os.FactoryTest.FACTORY_TEST_HIGH_LEVEL; |
| 54 | import static android.os.FactoryTest.FACTORY_TEST_LOW_LEVEL; |
| 55 | import static android.os.FactoryTest.FACTORY_TEST_OFF; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 56 | import static android.os.Process.FIRST_APPLICATION_UID; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 57 | import static android.os.Process.SYSTEM_UID; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 58 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 59 | import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT; |
| 60 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES; |
| 61 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RTL; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 62 | import static android.provider.Settings.Global.HIDE_ERROR_DIALOGS; |
| 63 | import static android.provider.Settings.System.FONT_SCALE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 64 | import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_APPLICATION; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 65 | import static android.text.format.DateUtils.MINUTE_IN_MILLIS; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 66 | import static android.view.Display.DEFAULT_DISPLAY; |
| 67 | import static android.view.Display.INVALID_DISPLAY; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 68 | import static android.view.WindowManager.TRANSIT_NONE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 69 | import static android.view.WindowManager.TRANSIT_TASK_IN_PLACE; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 70 | |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 71 | import static com.android.server.am.ActivityManagerService.ANR_TRACE_DIR; |
| 72 | import static com.android.server.am.ActivityManagerService.MY_PID; |
| 73 | import static com.android.server.am.ActivityManagerService.STOCK_PM_FLAGS; |
| 74 | import static com.android.server.am.ActivityManagerService.dumpStackTraces; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 75 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CONFIG_WILL_CHANGE; |
| 76 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CONTROLLER; |
| 77 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CURRENT_TRACKER; |
| 78 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.Controller.IS_A_MONKEY; |
| 79 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.GLOBAL_CONFIGURATION; |
| 80 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.GOING_TO_SLEEP; |
| 81 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HEAVY_WEIGHT_PROC; |
| 82 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HOME_PROC; |
| 83 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.LAUNCHING_ACTIVITY; |
| 84 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 85 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC_VISIBLE_TIME_MS; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 86 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.SCREEN_COMPAT_PACKAGES; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 87 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.MODE; |
| 88 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.PACKAGE; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 89 | import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING; |
| 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; |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 122 | import static com.android.server.wm.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK; |
| 123 | import static com.android.server.wm.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT; |
| 124 | import static com.android.server.wm.TaskRecord.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; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 127 | import android.annotation.NonNull; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 128 | import android.annotation.Nullable; |
| 129 | import android.annotation.UserIdInt; |
| 130 | import android.app.Activity; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 131 | import android.app.ActivityManager; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 132 | import android.app.ActivityManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 133 | import android.app.ActivityOptions; |
| 134 | import android.app.ActivityTaskManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 135 | import android.app.ActivityThread; |
| 136 | import android.app.AlertDialog; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 137 | import android.app.AppGlobals; |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 138 | import android.app.AppOpsManager; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 139 | import android.app.Dialog; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 140 | import android.app.IActivityController; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 141 | import android.app.IActivityTaskManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 142 | import android.app.IApplicationThread; |
| 143 | import android.app.IAssistDataReceiver; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 144 | import android.app.INotificationManager; |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 145 | import android.app.IRequestFinishCallback; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 146 | import android.app.ITaskStackListener; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 147 | import android.app.Notification; |
| 148 | import android.app.NotificationManager; |
| 149 | import android.app.PendingIntent; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 150 | import android.app.PictureInPictureParams; |
| 151 | import android.app.ProfilerInfo; |
| 152 | import android.app.RemoteAction; |
| 153 | import android.app.WaitResult; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 154 | import android.app.WindowConfiguration; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 155 | import android.app.admin.DevicePolicyCache; |
| 156 | import android.app.assist.AssistContent; |
| 157 | import android.app.assist.AssistStructure; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 158 | import android.app.usage.UsageStatsManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 159 | import android.content.ActivityNotFoundException; |
| 160 | import android.content.ComponentName; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 161 | import android.content.ContentResolver; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 162 | import android.content.Context; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 163 | import android.content.DialogInterface; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 164 | import android.content.IIntentSender; |
| 165 | import android.content.Intent; |
| 166 | import android.content.pm.ActivityInfo; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 167 | import android.content.pm.ApplicationInfo; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 168 | import android.content.pm.ConfigurationInfo; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 169 | import android.content.pm.IPackageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 170 | import android.content.pm.PackageManager; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 171 | import android.content.pm.PackageManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 172 | import android.content.pm.ParceledListSlice; |
| 173 | import android.content.pm.ResolveInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 174 | import android.content.res.CompatibilityInfo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 175 | import android.content.res.Configuration; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 176 | import android.content.res.Resources; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 177 | import android.database.ContentObserver; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 178 | import android.graphics.Bitmap; |
| 179 | import android.graphics.Point; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 180 | import android.graphics.Rect; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 181 | import android.metrics.LogMaker; |
| 182 | import android.net.Uri; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 183 | import android.os.Binder; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 184 | import android.os.Build; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 185 | import android.os.Bundle; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 186 | import android.os.FactoryTest; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 187 | import android.os.FileUtils; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 188 | import android.os.Handler; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 189 | import android.os.IBinder; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 190 | import android.os.IUserManager; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 191 | import android.os.LocaleList; |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 192 | import android.os.Looper; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 193 | import android.os.Message; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 194 | import android.os.PersistableBundle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 195 | import android.os.PowerManager; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 196 | import android.os.PowerManagerInternal; |
Marvin Ramin | 830d4e3 | 2019-03-12 13:16:58 +0100 | [diff] [blame] | 197 | import android.os.Process; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 198 | import android.os.RemoteException; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 199 | import android.os.ServiceManager; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 200 | import android.os.StrictMode; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 201 | import android.os.SystemClock; |
| 202 | import android.os.SystemProperties; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 203 | import android.os.Trace; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 204 | import android.os.UpdateLock; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 205 | import android.os.UserHandle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 206 | import android.os.UserManager; |
| 207 | import android.os.WorkSource; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 208 | import android.os.storage.IStorageManager; |
| 209 | import android.os.storage.StorageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 210 | import android.provider.Settings; |
| 211 | import android.service.voice.IVoiceInteractionSession; |
| 212 | import android.service.voice.VoiceInteractionManagerInternal; |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 213 | import android.sysprop.DisplayProperties; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 214 | import android.telecom.TelecomManager; |
| 215 | import android.text.TextUtils; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 216 | import android.text.format.Time; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 217 | import android.util.ArrayMap; |
Nicholas Sauer | d6b4452 | 2019-09-10 20:23:41 -0700 | [diff] [blame] | 218 | import android.util.ArraySet; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 219 | import android.util.EventLog; |
| 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 | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 223 | import android.util.SparseIntArray; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 224 | import android.util.StatsLog; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 225 | import android.util.TimeUtils; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 226 | import android.util.proto.ProtoOutputStream; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 227 | import android.view.IRecentsAnimationRunner; |
| 228 | import android.view.RemoteAnimationAdapter; |
| 229 | import android.view.RemoteAnimationDefinition; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 230 | import android.view.WindowManager; |
lumark | 5df4951 | 2019-04-02 14:56:46 +0800 | [diff] [blame] | 231 | import android.view.inputmethod.InputMethodSystemProperty; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 232 | |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 233 | import com.android.internal.R; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 234 | import com.android.internal.annotations.VisibleForTesting; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 235 | import com.android.internal.app.AssistUtils; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 236 | import com.android.internal.app.IAppOpsService; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 237 | import com.android.internal.app.IVoiceInteractor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 238 | import com.android.internal.app.ProcessMap; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 239 | import com.android.internal.logging.MetricsLogger; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 240 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 241 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
| 242 | import com.android.internal.notification.SystemNotificationChannels; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 243 | import com.android.internal.os.TransferPipe; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 244 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 245 | import com.android.internal.policy.IKeyguardDismissCallback; |
| 246 | import com.android.internal.policy.KeyguardDismissCallback; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 247 | import com.android.internal.util.ArrayUtils; |
| 248 | import com.android.internal.util.FastPrintWriter; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 249 | import com.android.internal.util.Preconditions; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 250 | import com.android.internal.util.function.pooled.PooledLambda; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 251 | import com.android.server.AttributeCache; |
Marvin Ramin | 830d4e3 | 2019-03-12 13:16:58 +0100 | [diff] [blame] | 252 | import com.android.server.DeviceIdleController; |
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; |
| 263 | import com.android.server.am.EventLogTags; |
| 264 | import com.android.server.am.PendingIntentController; |
| 265 | import com.android.server.am.PendingIntentRecord; |
| 266 | import com.android.server.am.UserState; |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 267 | import com.android.server.appop.AppOpsService; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 268 | import com.android.server.firewall.IntentFirewall; |
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; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 293 | import java.util.List; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 294 | import java.util.Locale; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 295 | import java.util.Map; |
| 296 | import java.util.Set; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 297 | |
| 298 | /** |
| 299 | * System service for managing activities and their containers (task, stacks, displays,... ). |
| 300 | * |
| 301 | * {@hide} |
| 302 | */ |
| 303 | public class ActivityTaskManagerService extends IActivityTaskManager.Stub { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 304 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityTaskManagerService" : TAG_ATM; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 305 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 306 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 307 | private static final String TAG_IMMERSIVE = TAG + POSTFIX_IMMERSIVE; |
| 308 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
| 309 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
| 310 | private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 311 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 312 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 313 | // How long we wait until we timeout on key dispatching. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 314 | public static final int KEY_DISPATCHING_TIMEOUT_MS = 5 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 315 | // How long we wait until we timeout on key dispatching during instrumentation. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 316 | static final int INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT_MS = 60 * 1000; |
Michal Karpinski | fc6872e | 2019-05-21 15:18:44 +0100 | [diff] [blame] | 317 | // How long we permit background activity starts after an activity in the process |
| 318 | // started or finished. |
| 319 | static final long ACTIVITY_BG_START_GRACE_PERIOD_MS = 10 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 320 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 321 | /** Used to indicate that an app transition should be animated. */ |
| 322 | static final boolean ANIMATE = true; |
| 323 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 324 | /** Hardware-reported OpenGLES version. */ |
| 325 | final int GL_ES_VERSION; |
| 326 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 327 | public static final String DUMP_ACTIVITIES_CMD = "activities" ; |
| 328 | public static final String DUMP_ACTIVITIES_SHORT_CMD = "a" ; |
| 329 | public static final String DUMP_LASTANR_CMD = "lastanr" ; |
| 330 | public static final String DUMP_LASTANR_TRACES_CMD = "lastanr-traces" ; |
| 331 | public static final String DUMP_STARTER_CMD = "starter" ; |
| 332 | public static final String DUMP_CONTAINERS_CMD = "containers" ; |
| 333 | public static final String DUMP_RECENTS_CMD = "recents" ; |
| 334 | public static final String DUMP_RECENTS_SHORT_CMD = "r" ; |
| 335 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 336 | /** This activity is not being relaunched, or being relaunched for a non-resize reason. */ |
| 337 | public static final int RELAUNCH_REASON_NONE = 0; |
| 338 | /** This activity is being relaunched due to windowing mode change. */ |
| 339 | public static final int RELAUNCH_REASON_WINDOWING_MODE_RESIZE = 1; |
| 340 | /** This activity is being relaunched due to a free-resize operation. */ |
| 341 | public static final int RELAUNCH_REASON_FREE_RESIZE = 2; |
| 342 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 343 | Context mContext; |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 344 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 345 | /** |
| 346 | * This Context is themable and meant for UI display (AlertDialogs, etc.). The theme can |
| 347 | * change at runtime. Use mContext for non-UI purposes. |
| 348 | */ |
| 349 | final Context mUiContext; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 350 | final ActivityThread mSystemThread; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 351 | H mH; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 352 | UiHandler mUiHandler; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 353 | ActivityManagerInternal mAmInternal; |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 354 | UriGrantsManagerInternal mUgmInternal; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 355 | private PackageManagerInternal mPmInternal; |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 356 | private PermissionPolicyInternal mPermissionPolicyInternal; |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 357 | @VisibleForTesting |
| 358 | final ActivityTaskManagerInternal mInternal; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 359 | PowerManagerInternal mPowerManagerInternal; |
| 360 | private UsageStatsManagerInternal mUsageStatsInternal; |
| 361 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 362 | PendingIntentController mPendingIntentController; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 363 | IntentFirewall mIntentFirewall; |
| 364 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 365 | /* Global service lock used by the package the owns this service. */ |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 366 | final WindowManagerGlobalLock mGlobalLock = new WindowManagerGlobalLock(); |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 367 | /** |
| 368 | * It is the same instance as {@link mGlobalLock}, just declared as a type that the |
| 369 | * locked-region-code-injection does't recognize it. It is used to skip wrapping priority |
| 370 | * booster for places that are already in the scope of another booster (e.g. computing oom-adj). |
| 371 | * |
| 372 | * @see WindowManagerThreadPriorityBooster |
| 373 | */ |
| 374 | final Object mGlobalLockWithoutBoost = mGlobalLock; |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 375 | ActivityStackSupervisor mStackSupervisor; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 376 | RootActivityContainer mRootActivityContainer; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 377 | WindowManagerService mWindowManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 378 | private UserManagerService mUserManager; |
| 379 | private AppOpsService mAppOpsService; |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 380 | /** All active uids in the system. */ |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 381 | private final MirrorActiveUids mActiveUids = new MirrorActiveUids(); |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 382 | private final SparseArray<String> mPendingTempWhitelist = new SparseArray<>(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 383 | /** All processes currently running that might have a window organized by name. */ |
| 384 | final ProcessMap<WindowProcessController> mProcessNames = new ProcessMap<>(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 385 | /** All processes we currently have running mapped by pid and uid */ |
| 386 | final WindowProcessControllerMap mProcessMap = new WindowProcessControllerMap(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 387 | /** This is the process holding what we currently consider to be the "home" activity. */ |
| 388 | WindowProcessController mHomeProcess; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 389 | /** The currently running heavy-weight process, if any. */ |
| 390 | WindowProcessController mHeavyWeightProcess = null; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 391 | boolean mHasHeavyWeightFeature; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 392 | /** |
| 393 | * This is the process holding the activity the user last visited that is in a different process |
| 394 | * from the one they are currently in. |
| 395 | */ |
| 396 | WindowProcessController mPreviousProcess; |
| 397 | /** The time at which the previous process was last visible. */ |
| 398 | long mPreviousProcessVisibleTime; |
| 399 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 400 | /** List of intents that were used to start the most recent tasks. */ |
| 401 | private RecentTasks mRecentTasks; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 402 | /** State of external calls telling us if the device is awake or asleep. */ |
| 403 | private boolean mKeyguardShown = false; |
| 404 | |
| 405 | // Wrapper around VoiceInteractionServiceManager |
| 406 | private AssistUtils mAssistUtils; |
| 407 | |
| 408 | // VoiceInteraction session ID that changes for each new request except when |
| 409 | // being called for multi-window assist in a single session. |
| 410 | private int mViSessionId = 1000; |
| 411 | |
| 412 | // How long to wait in getAssistContextExtras for the activity and foreground services |
| 413 | // to respond with the result. |
| 414 | private static final int PENDING_ASSIST_EXTRAS_TIMEOUT = 500; |
| 415 | |
| 416 | // How long top wait when going through the modern assist (which doesn't need to block |
| 417 | // on getting this result before starting to launch its UI). |
| 418 | private static final int PENDING_ASSIST_EXTRAS_LONG_TIMEOUT = 2000; |
| 419 | |
| 420 | // How long to wait in getAutofillAssistStructure() for the activity to respond with the result. |
| 421 | private static final int PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT = 2000; |
| 422 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 423 | // Permission tokens are used to temporarily granted a trusted app the ability to call |
| 424 | // #startActivityAsCaller. A client is expected to dump its token after this time has elapsed, |
| 425 | // showing any appropriate error messages to the user. |
| 426 | private static final long START_AS_CALLER_TOKEN_TIMEOUT = |
| 427 | 10 * MINUTE_IN_MILLIS; |
| 428 | |
| 429 | // How long before the service actually expires a token. This is slightly longer than |
| 430 | // START_AS_CALLER_TOKEN_TIMEOUT, to provide a buffer so clients will rarely encounter the |
| 431 | // expiration exception. |
| 432 | private static final long START_AS_CALLER_TOKEN_TIMEOUT_IMPL = |
| 433 | START_AS_CALLER_TOKEN_TIMEOUT + 2 * 1000; |
| 434 | |
| 435 | // How long the service will remember expired tokens, for the purpose of providing error |
| 436 | // messaging when a client uses an expired token. |
| 437 | private static final long START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT = |
| 438 | START_AS_CALLER_TOKEN_TIMEOUT_IMPL + 20 * MINUTE_IN_MILLIS; |
| 439 | |
Marvin Ramin | 830d4e3 | 2019-03-12 13:16:58 +0100 | [diff] [blame] | 440 | // How long to whitelist the Services for when requested. |
| 441 | private static final int SERVICE_LAUNCH_IDLE_WHITELIST_DURATION_MS = 5 * 1000; |
| 442 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 443 | // Activity tokens of system activities that are delegating their call to |
| 444 | // #startActivityByCaller, keyed by the permissionToken granted to the delegate. |
| 445 | final HashMap<IBinder, IBinder> mStartActivitySources = new HashMap<>(); |
| 446 | |
| 447 | // Permission tokens that have expired, but we remember for error reporting. |
| 448 | final ArrayList<IBinder> mExpiredStartAsCallerTokens = new ArrayList<>(); |
| 449 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 450 | private final ArrayList<PendingAssistExtras> mPendingAssistExtras = new ArrayList<>(); |
| 451 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 452 | // Keeps track of the active voice interaction service component, notified from |
| 453 | // VoiceInteractionManagerService |
| 454 | ComponentName mActiveVoiceInteractionServiceComponent; |
| 455 | |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 456 | // A map userId and all its companion app uids |
| 457 | private final Map<Integer, Set<Integer>> mCompanionAppUidsMap = new ArrayMap<>(); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 458 | |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 459 | VrController mVrController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 460 | KeyguardController mKeyguardController; |
| 461 | private final ClientLifecycleManager mLifecycleManager; |
| 462 | private TaskChangeNotificationController mTaskChangeNotificationController; |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 463 | /** The controller for all operations related to locktask. */ |
| 464 | private LockTaskController mLockTaskController; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 465 | private ActivityStartController mActivityStartController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 466 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 467 | boolean mSuppressResizeConfigChanges; |
| 468 | |
| 469 | private final UpdateConfigurationResult mTmpUpdateConfigurationResult = |
| 470 | new UpdateConfigurationResult(); |
| 471 | |
| 472 | static final class UpdateConfigurationResult { |
| 473 | // Configuration changes that were updated. |
| 474 | int changes; |
| 475 | // If the activity was relaunched to match the new configuration. |
| 476 | boolean activityRelaunched; |
| 477 | |
| 478 | void reset() { |
| 479 | changes = 0; |
| 480 | activityRelaunched = false; |
| 481 | } |
| 482 | } |
| 483 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 484 | /** Current sequencing integer of the configuration, for skipping old configurations. */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 485 | private int mConfigurationSeq; |
| 486 | // To cache the list of supported system locales |
| 487 | private String[] mSupportedSystemLocales = null; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 488 | |
| 489 | /** |
| 490 | * Temp object used when global and/or display override configuration is updated. It is also |
| 491 | * sent to outer world instead of {@link #getGlobalConfiguration} because we don't trust |
| 492 | * anyone... |
| 493 | */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 494 | private Configuration mTempConfig = new Configuration(); |
| 495 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 496 | /** Temporary to avoid allocations. */ |
| 497 | final StringBuilder mStringBuilder = new StringBuilder(256); |
| 498 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 499 | // Amount of time after a call to stopAppSwitches() during which we will |
| 500 | // prevent further untrusted switches from happening. |
| 501 | private static final long APP_SWITCH_DELAY_TIME = 5 * 1000; |
| 502 | |
| 503 | /** |
| 504 | * The time at which we will allow normal application switches again, |
| 505 | * after a call to {@link #stopAppSwitches()}. |
| 506 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 507 | private long mAppSwitchesAllowedTime; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 508 | /** |
| 509 | * This is set to true after the first switch after mAppSwitchesAllowedTime |
| 510 | * is set; any switches after that will clear the time. |
| 511 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 512 | private boolean mDidAppSwitch; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 513 | |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 514 | /** |
| 515 | * Last stop app switches time, apps finished before this time cannot start background activity |
| 516 | * even if they are in grace period. |
| 517 | */ |
| 518 | private long mLastStopAppSwitchesTime; |
| 519 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 520 | IActivityController mController = null; |
| 521 | boolean mControllerIsAMonkey = false; |
| 522 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 523 | final int mFactoryTest; |
| 524 | |
| 525 | /** Used to control how we initialize the service. */ |
| 526 | ComponentName mTopComponent; |
| 527 | String mTopAction = Intent.ACTION_MAIN; |
| 528 | String mTopData; |
| 529 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 530 | /** Profiling app information. */ |
| 531 | String mProfileApp = null; |
| 532 | WindowProcessController mProfileProc = null; |
| 533 | ProfilerInfo mProfilerInfo = null; |
| 534 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 535 | /** |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 536 | * Dump of the activity state at the time of the last ANR. Cleared after |
| 537 | * {@link WindowManagerService#LAST_ANR_LIFETIME_DURATION_MSECS} |
| 538 | */ |
| 539 | String mLastANRState; |
| 540 | |
| 541 | /** |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 542 | * Used to retain an update lock when the foreground activity is in |
| 543 | * immersive mode. |
| 544 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 545 | private final UpdateLock mUpdateLock = new UpdateLock("immersive"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 546 | |
| 547 | /** |
| 548 | * Packages that are being allowed to perform unrestricted app switches. Mapping is |
| 549 | * User -> Type -> uid. |
| 550 | */ |
| 551 | final SparseArray<ArrayMap<String, Integer>> mAllowAppSwitchUids = new SparseArray<>(); |
| 552 | |
| 553 | /** The dimensions of the thumbnails in the Recents UI. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 554 | private int mThumbnailWidth; |
| 555 | private int mThumbnailHeight; |
| 556 | private float mFullscreenThumbnailScale; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 557 | |
| 558 | /** |
| 559 | * Flag that indicates if multi-window is enabled. |
| 560 | * |
| 561 | * For any particular form of multi-window to be enabled, generic multi-window must be enabled |
| 562 | * in {@link com.android.internal.R.bool#config_supportsMultiWindow} config or |
| 563 | * {@link Settings.Global#DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES} development option set. |
| 564 | * At least one of the forms of multi-window must be enabled in order for this flag to be |
| 565 | * initialized to 'true'. |
| 566 | * |
| 567 | * @see #mSupportsSplitScreenMultiWindow |
| 568 | * @see #mSupportsFreeformWindowManagement |
| 569 | * @see #mSupportsPictureInPicture |
| 570 | * @see #mSupportsMultiDisplay |
| 571 | */ |
| 572 | boolean mSupportsMultiWindow; |
| 573 | boolean mSupportsSplitScreenMultiWindow; |
| 574 | boolean mSupportsFreeformWindowManagement; |
| 575 | boolean mSupportsPictureInPicture; |
| 576 | boolean mSupportsMultiDisplay; |
| 577 | boolean mForceResizableActivities; |
| 578 | |
| 579 | final List<ActivityTaskManagerInternal.ScreenObserver> mScreenObservers = new ArrayList<>(); |
| 580 | |
| 581 | // VR Vr2d Display Id. |
| 582 | int mVr2dDisplayId = INVALID_DISPLAY; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 583 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 584 | /** |
| 585 | * Set while we are wanting to sleep, to prevent any |
| 586 | * activities from being started/resumed. |
| 587 | * |
| 588 | * TODO(b/33594039): Clarify the actual state transitions represented by mSleeping. |
| 589 | * |
| 590 | * Currently mSleeping is set to true when transitioning into the sleep state, and remains true |
| 591 | * while in the sleep state until there is a pending transition out of sleep, in which case |
| 592 | * mSleeping is set to false, and remains false while awake. |
| 593 | * |
| 594 | * Whether mSleeping can quickly toggled between true/false without the device actually |
| 595 | * display changing states is undefined. |
| 596 | */ |
| 597 | private boolean mSleeping = false; |
| 598 | |
| 599 | /** |
| 600 | * The process state used for processes that are running the top activities. |
| 601 | * This changes between TOP and TOP_SLEEPING to following mSleeping. |
| 602 | */ |
| 603 | int mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
| 604 | |
| 605 | // Whether we should show our dialogs (ANR, crash, etc) or just perform their default action |
| 606 | // automatically. Important for devices without direct input devices. |
| 607 | private boolean mShowDialogs = true; |
| 608 | |
| 609 | /** Set if we are shutting down the system, similar to sleeping. */ |
| 610 | boolean mShuttingDown = false; |
| 611 | |
| 612 | /** |
| 613 | * We want to hold a wake lock while running a voice interaction session, since |
| 614 | * this may happen with the screen off and we need to keep the CPU running to |
| 615 | * be able to continue to interact with the user. |
| 616 | */ |
| 617 | PowerManager.WakeLock mVoiceWakeLock; |
| 618 | |
| 619 | /** |
| 620 | * Set while we are running a voice interaction. This overrides sleeping while it is active. |
| 621 | */ |
| 622 | IVoiceInteractionSession mRunningVoice; |
| 623 | |
| 624 | /** |
| 625 | * The last resumed activity. This is identical to the current resumed activity most |
| 626 | * of the time but could be different when we're pausing one activity before we resume |
| 627 | * another activity. |
| 628 | */ |
| 629 | ActivityRecord mLastResumedActivity; |
| 630 | |
| 631 | /** |
| 632 | * The activity that is currently being traced as the active resumed activity. |
| 633 | * |
| 634 | * @see #updateResumedAppTrace |
| 635 | */ |
| 636 | private @Nullable ActivityRecord mTracedResumedActivity; |
| 637 | |
| 638 | /** If non-null, we are tracking the time the user spends in the currently focused app. */ |
| 639 | AppTimeTracker mCurAppTimeTracker; |
| 640 | |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 641 | private AppWarnings mAppWarnings; |
| 642 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 643 | /** |
| 644 | * Packages that the user has asked to have run in screen size |
| 645 | * compatibility mode instead of filling the screen. |
| 646 | */ |
| 647 | CompatModePackages mCompatModePackages; |
| 648 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 649 | private FontScaleSettingObserver mFontScaleSettingObserver; |
| 650 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 651 | private int mDeviceOwnerUid = Process.INVALID_UID; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 652 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 653 | private final class FontScaleSettingObserver extends ContentObserver { |
| 654 | private final Uri mFontScaleUri = Settings.System.getUriFor(FONT_SCALE); |
| 655 | private final Uri mHideErrorDialogsUri = Settings.Global.getUriFor(HIDE_ERROR_DIALOGS); |
| 656 | |
| 657 | public FontScaleSettingObserver() { |
| 658 | super(mH); |
| 659 | final ContentResolver resolver = mContext.getContentResolver(); |
| 660 | resolver.registerContentObserver(mFontScaleUri, false, this, UserHandle.USER_ALL); |
| 661 | resolver.registerContentObserver(mHideErrorDialogsUri, false, this, |
| 662 | UserHandle.USER_ALL); |
| 663 | } |
| 664 | |
| 665 | @Override |
| 666 | public void onChange(boolean selfChange, Uri uri, @UserIdInt int userId) { |
| 667 | if (mFontScaleUri.equals(uri)) { |
| 668 | updateFontScaleIfNeeded(userId); |
| 669 | } else if (mHideErrorDialogsUri.equals(uri)) { |
| 670 | synchronized (mGlobalLock) { |
| 671 | updateShouldShowDialogsLocked(getGlobalConfiguration()); |
| 672 | } |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 677 | /** Indicates that the method may be invoked frequently or is sensitive to performance. */ |
| 678 | @Target(ElementType.METHOD) |
| 679 | @Retention(RetentionPolicy.SOURCE) |
| 680 | @interface HotPath { |
| 681 | int NONE = 0; |
| 682 | int OOM_ADJUSTMENT = 1; |
| 683 | int LRU_UPDATE = 2; |
| 684 | int PROCESS_CHANGE = 3; |
| 685 | int caller() default NONE; |
| 686 | } |
| 687 | |
Charles Chen | 8d98dd2 | 2018-12-26 17:36:54 +0800 | [diff] [blame] | 688 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 689 | public ActivityTaskManagerService(Context context) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 690 | mContext = context; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 691 | mFactoryTest = FactoryTest.getMode(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 692 | mSystemThread = ActivityThread.currentActivityThread(); |
| 693 | mUiContext = mSystemThread.getSystemUiContext(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 694 | mLifecycleManager = new ClientLifecycleManager(); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 695 | mInternal = new LocalService(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 696 | GL_ES_VERSION = SystemProperties.getInt("ro.opengles.version", GL_ES_VERSION_UNDEFINED); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 699 | public void onSystemReady() { |
| 700 | synchronized (mGlobalLock) { |
| 701 | mHasHeavyWeightFeature = mContext.getPackageManager().hasSystemFeature( |
| 702 | PackageManager.FEATURE_CANT_SAVE_STATE); |
| 703 | mAssistUtils = new AssistUtils(mContext); |
| 704 | mVrController.onSystemReady(); |
| 705 | mRecentTasks.onSystemReadyLocked(); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 706 | mStackSupervisor.onSystemReady(); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 707 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 710 | public void onInitPowerManagement() { |
| 711 | synchronized (mGlobalLock) { |
| 712 | mStackSupervisor.initPowerManagement(); |
| 713 | final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 714 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
| 715 | mVoiceWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*voice*"); |
| 716 | mVoiceWakeLock.setReferenceCounted(false); |
| 717 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 720 | public void installSystemProviders() { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 721 | mFontScaleSettingObserver = new FontScaleSettingObserver(); |
| 722 | } |
| 723 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 724 | public void retrieveSettings(ContentResolver resolver) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 725 | final boolean freeformWindowManagement = |
| 726 | mContext.getPackageManager().hasSystemFeature(FEATURE_FREEFORM_WINDOW_MANAGEMENT) |
| 727 | || Settings.Global.getInt( |
| 728 | resolver, DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0; |
| 729 | |
| 730 | final boolean supportsMultiWindow = ActivityTaskManager.supportsMultiWindow(mContext); |
| 731 | final boolean supportsPictureInPicture = supportsMultiWindow && |
| 732 | mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE); |
| 733 | final boolean supportsSplitScreenMultiWindow = |
| 734 | ActivityTaskManager.supportsSplitScreenMultiWindow(mContext); |
| 735 | final boolean supportsMultiDisplay = mContext.getPackageManager() |
| 736 | .hasSystemFeature(FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 737 | final boolean forceRtl = Settings.Global.getInt(resolver, DEVELOPMENT_FORCE_RTL, 0) != 0; |
| 738 | final boolean forceResizable = Settings.Global.getInt( |
| 739 | resolver, DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0; |
Garfield Tan | e084604 | 2018-07-26 13:42:04 -0700 | [diff] [blame] | 740 | final boolean isPc = mContext.getPackageManager().hasSystemFeature(FEATURE_PC); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 741 | |
| 742 | // Transfer any global setting for forcing RTL layout, into a System Property |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 743 | DisplayProperties.debug_force_rtl(forceRtl); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 744 | |
| 745 | final Configuration configuration = new Configuration(); |
| 746 | Settings.System.getConfiguration(resolver, configuration); |
| 747 | if (forceRtl) { |
| 748 | // This will take care of setting the correct layout direction flags |
| 749 | configuration.setLayoutDirection(configuration.locale); |
| 750 | } |
| 751 | |
| 752 | synchronized (mGlobalLock) { |
| 753 | mForceResizableActivities = forceResizable; |
| 754 | final boolean multiWindowFormEnabled = freeformWindowManagement |
| 755 | || supportsSplitScreenMultiWindow |
| 756 | || supportsPictureInPicture |
| 757 | || supportsMultiDisplay; |
| 758 | if ((supportsMultiWindow || forceResizable) && multiWindowFormEnabled) { |
| 759 | mSupportsMultiWindow = true; |
| 760 | mSupportsFreeformWindowManagement = freeformWindowManagement; |
| 761 | mSupportsSplitScreenMultiWindow = supportsSplitScreenMultiWindow; |
| 762 | mSupportsPictureInPicture = supportsPictureInPicture; |
| 763 | mSupportsMultiDisplay = supportsMultiDisplay; |
| 764 | } else { |
| 765 | mSupportsMultiWindow = false; |
| 766 | mSupportsFreeformWindowManagement = false; |
| 767 | mSupportsSplitScreenMultiWindow = false; |
| 768 | mSupportsPictureInPicture = false; |
| 769 | mSupportsMultiDisplay = false; |
| 770 | } |
| 771 | mWindowManager.setForceResizableTasks(mForceResizableActivities); |
| 772 | mWindowManager.setSupportsPictureInPicture(mSupportsPictureInPicture); |
Garfield Tan | e084604 | 2018-07-26 13:42:04 -0700 | [diff] [blame] | 773 | mWindowManager.setSupportsFreeformWindowManagement(mSupportsFreeformWindowManagement); |
| 774 | mWindowManager.setIsPc(isPc); |
Garfield Tan | b5910b4 | 2019-03-14 14:50:59 -0700 | [diff] [blame] | 775 | mWindowManager.mRoot.onSettingsRetrieved(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 776 | // This happens before any activities are started, so we can change global configuration |
| 777 | // in-place. |
| 778 | updateConfigurationLocked(configuration, null, true); |
| 779 | final Configuration globalConfig = getGlobalConfiguration(); |
| 780 | if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Initial config: " + globalConfig); |
| 781 | |
| 782 | // Load resources only after the current configuration has been set. |
| 783 | final Resources res = mContext.getResources(); |
| 784 | mThumbnailWidth = res.getDimensionPixelSize( |
| 785 | com.android.internal.R.dimen.thumbnail_width); |
| 786 | mThumbnailHeight = res.getDimensionPixelSize( |
| 787 | com.android.internal.R.dimen.thumbnail_height); |
| 788 | |
| 789 | if ((globalConfig.uiMode & UI_MODE_TYPE_TELEVISION) == UI_MODE_TYPE_TELEVISION) { |
| 790 | mFullscreenThumbnailScale = (float) res |
| 791 | .getInteger(com.android.internal.R.integer.thumbnail_width_tv) / |
| 792 | (float) globalConfig.screenWidthDp; |
| 793 | } else { |
| 794 | mFullscreenThumbnailScale = res.getFraction( |
| 795 | com.android.internal.R.fraction.thumbnail_fullscreen_scale, 1, 1); |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 800 | public WindowManagerGlobalLock getGlobalLock() { |
| 801 | return mGlobalLock; |
| 802 | } |
| 803 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 804 | /** For test purpose only. */ |
| 805 | @VisibleForTesting |
| 806 | public ActivityTaskManagerInternal getAtmInternal() { |
| 807 | return mInternal; |
| 808 | } |
| 809 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 810 | public void initialize(IntentFirewall intentFirewall, PendingIntentController intentController, |
| 811 | Looper looper) { |
| 812 | mH = new H(looper); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 813 | mUiHandler = new UiHandler(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 814 | mIntentFirewall = intentFirewall; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 815 | final File systemDir = SystemServiceManager.ensureSystemDir(); |
| 816 | mAppWarnings = new AppWarnings(this, mUiContext, mH, mUiHandler, systemDir); |
| 817 | mCompatModePackages = new CompatModePackages(this, systemDir, mH); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 818 | mPendingIntentController = intentController; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 819 | |
| 820 | mTempConfig.setToDefaults(); |
| 821 | mTempConfig.setLocales(LocaleList.getDefault()); |
| 822 | mConfigurationSeq = mTempConfig.seq = 1; |
| 823 | mStackSupervisor = createStackSupervisor(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 824 | mRootActivityContainer = new RootActivityContainer(this); |
| 825 | mRootActivityContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 826 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 827 | mTaskChangeNotificationController = |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 828 | new TaskChangeNotificationController(mGlobalLock, mStackSupervisor, mH); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 829 | mLockTaskController = new LockTaskController(mContext, mStackSupervisor, mH); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 830 | mActivityStartController = new ActivityStartController(this); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 831 | mRecentTasks = createRecentTasks(); |
| 832 | mStackSupervisor.setRecentTasks(mRecentTasks); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 833 | mVrController = new VrController(mGlobalLock); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 834 | mKeyguardController = mStackSupervisor.getKeyguardController(); |
| 835 | } |
| 836 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 837 | public void onActivityManagerInternalAdded() { |
| 838 | synchronized (mGlobalLock) { |
| 839 | mAmInternal = LocalServices.getService(ActivityManagerInternal.class); |
| 840 | mUgmInternal = LocalServices.getService(UriGrantsManagerInternal.class); |
| 841 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 844 | int increaseConfigurationSeqLocked() { |
| 845 | mConfigurationSeq = Math.max(++mConfigurationSeq, 1); |
| 846 | return mConfigurationSeq; |
| 847 | } |
| 848 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 849 | protected ActivityStackSupervisor createStackSupervisor() { |
| 850 | final ActivityStackSupervisor supervisor = new ActivityStackSupervisor(this, mH.getLooper()); |
| 851 | supervisor.initialize(); |
| 852 | return supervisor; |
| 853 | } |
| 854 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 855 | public void setWindowManager(WindowManagerService wm) { |
| 856 | synchronized (mGlobalLock) { |
| 857 | mWindowManager = wm; |
| 858 | mLockTaskController.setWindowManager(wm); |
| 859 | mStackSupervisor.setWindowManager(wm); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 860 | mRootActivityContainer.setWindowManager(wm); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 861 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 862 | } |
| 863 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 864 | public void setUsageStatsManager(UsageStatsManagerInternal usageStatsManager) { |
| 865 | synchronized (mGlobalLock) { |
| 866 | mUsageStatsInternal = usageStatsManager; |
| 867 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 870 | UserManagerService getUserManager() { |
| 871 | if (mUserManager == null) { |
| 872 | IBinder b = ServiceManager.getService(Context.USER_SERVICE); |
| 873 | mUserManager = (UserManagerService) IUserManager.Stub.asInterface(b); |
| 874 | } |
| 875 | return mUserManager; |
| 876 | } |
| 877 | |
| 878 | AppOpsService getAppOpsService() { |
| 879 | if (mAppOpsService == null) { |
| 880 | IBinder b = ServiceManager.getService(Context.APP_OPS_SERVICE); |
| 881 | mAppOpsService = (AppOpsService) IAppOpsService.Stub.asInterface(b); |
| 882 | } |
| 883 | return mAppOpsService; |
| 884 | } |
| 885 | |
| 886 | boolean hasUserRestriction(String restriction, int userId) { |
| 887 | return getUserManager().hasUserRestriction(restriction, userId); |
| 888 | } |
| 889 | |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 890 | boolean hasSystemAlertWindowPermission(int callingUid, int callingPid, String callingPackage) { |
| 891 | final int mode = getAppOpsService().noteOperation(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, |
| 892 | callingUid, callingPackage); |
| 893 | if (mode == AppOpsManager.MODE_DEFAULT) { |
| 894 | return checkPermission(Manifest.permission.SYSTEM_ALERT_WINDOW, callingPid, callingUid) |
| 895 | == PERMISSION_GRANTED; |
| 896 | } |
| 897 | return mode == AppOpsManager.MODE_ALLOWED; |
| 898 | } |
| 899 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 900 | protected RecentTasks createRecentTasks() { |
| 901 | return new RecentTasks(this, mStackSupervisor); |
| 902 | } |
| 903 | |
| 904 | RecentTasks getRecentTasks() { |
| 905 | return mRecentTasks; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 908 | ClientLifecycleManager getLifecycleManager() { |
| 909 | return mLifecycleManager; |
| 910 | } |
| 911 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 912 | ActivityStartController getActivityStartController() { |
| 913 | return mActivityStartController; |
| 914 | } |
| 915 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 916 | TaskChangeNotificationController getTaskChangeNotificationController() { |
| 917 | return mTaskChangeNotificationController; |
| 918 | } |
| 919 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 920 | LockTaskController getLockTaskController() { |
| 921 | return mLockTaskController; |
| 922 | } |
| 923 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 924 | /** |
| 925 | * Return the global configuration used by the process corresponding to the input pid. This is |
| 926 | * usually the global configuration with some overrides specific to that process. |
| 927 | */ |
| 928 | Configuration getGlobalConfigurationForCallingPid() { |
| 929 | final int pid = Binder.getCallingPid(); |
Yunfan Chen | c2ff6cf | 2018-12-04 16:56:21 -0800 | [diff] [blame] | 930 | return getGlobalConfigurationForPid(pid); |
| 931 | } |
| 932 | |
| 933 | /** |
| 934 | * Return the global configuration used by the process corresponding to the given pid. |
| 935 | */ |
| 936 | Configuration getGlobalConfigurationForPid(int pid) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 937 | if (pid == MY_PID || pid < 0) { |
| 938 | return getGlobalConfiguration(); |
| 939 | } |
| 940 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 941 | final WindowProcessController app = mProcessMap.getProcess(pid); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 942 | return app != null ? app.getConfiguration() : getGlobalConfiguration(); |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | /** |
| 947 | * Return the device configuration info used by the process corresponding to the input pid. |
| 948 | * The value is consistent with the global configuration for the process. |
| 949 | */ |
| 950 | @Override |
| 951 | public ConfigurationInfo getDeviceConfigurationInfo() { |
| 952 | ConfigurationInfo config = new ConfigurationInfo(); |
| 953 | synchronized (mGlobalLock) { |
| 954 | final Configuration globalConfig = getGlobalConfigurationForCallingPid(); |
| 955 | config.reqTouchScreen = globalConfig.touchscreen; |
| 956 | config.reqKeyboardType = globalConfig.keyboard; |
| 957 | config.reqNavigation = globalConfig.navigation; |
| 958 | if (globalConfig.navigation == Configuration.NAVIGATION_DPAD |
| 959 | || globalConfig.navigation == Configuration.NAVIGATION_TRACKBALL) { |
| 960 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 961 | } |
| 962 | if (globalConfig.keyboard != Configuration.KEYBOARD_UNDEFINED |
| 963 | && globalConfig.keyboard != Configuration.KEYBOARD_NOKEYS) { |
| 964 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 965 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 966 | config.reqGlEsVersion = GL_ES_VERSION; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 967 | } |
| 968 | return config; |
| 969 | } |
| 970 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 971 | private void start() { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 972 | LocalServices.addService(ActivityTaskManagerInternal.class, mInternal); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 973 | } |
| 974 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 975 | public static final class Lifecycle extends SystemService { |
| 976 | private final ActivityTaskManagerService mService; |
| 977 | |
| 978 | public Lifecycle(Context context) { |
| 979 | super(context); |
| 980 | mService = new ActivityTaskManagerService(context); |
| 981 | } |
| 982 | |
| 983 | @Override |
| 984 | public void onStart() { |
| 985 | publishBinderService(Context.ACTIVITY_TASK_SERVICE, mService); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 986 | mService.start(); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 987 | } |
| 988 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 989 | @Override |
| 990 | public void onUnlockUser(int userId) { |
| 991 | synchronized (mService.getGlobalLock()) { |
Garfield Tan | 0d407f4 | 2019-03-07 11:47:01 -0800 | [diff] [blame] | 992 | mService.mStackSupervisor.onUserUnlocked(userId); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 993 | } |
| 994 | } |
| 995 | |
| 996 | @Override |
| 997 | public void onCleanupUser(int userId) { |
| 998 | synchronized (mService.getGlobalLock()) { |
| 999 | mService.mStackSupervisor.mLaunchParamsPersister.onCleanupUser(userId); |
| 1000 | } |
| 1001 | } |
| 1002 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1003 | public ActivityTaskManagerService getService() { |
| 1004 | return mService; |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1009 | public final int startActivity(IApplicationThread caller, String callingPackage, |
| 1010 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1011 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions) { |
| 1012 | return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo, |
| 1013 | resultWho, requestCode, startFlags, profilerInfo, bOptions, |
| 1014 | UserHandle.getCallingUserId()); |
| 1015 | } |
| 1016 | |
| 1017 | @Override |
| 1018 | public final int startActivities(IApplicationThread caller, String callingPackage, |
| 1019 | Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle bOptions, |
| 1020 | int userId) { |
| 1021 | final String reason = "startActivities"; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1022 | enforceNotIsolatedCaller(reason); |
| 1023 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, reason); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1024 | // TODO: Switch to user app stacks here. |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 1025 | return getActivityStartController().startActivities(caller, -1, 0, -1, callingPackage, |
| 1026 | intents, resolvedTypes, resultTo, SafeActivityOptions.fromBundle(bOptions), userId, |
| 1027 | reason, null /* originatingPendingIntent */, |
| 1028 | false /* allowBackgroundActivityStart */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | @Override |
| 1032 | public int startActivityAsUser(IApplicationThread caller, String callingPackage, |
| 1033 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1034 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId) { |
| 1035 | return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo, |
| 1036 | resultWho, requestCode, startFlags, profilerInfo, bOptions, userId, |
| 1037 | true /*validateIncomingUser*/); |
| 1038 | } |
| 1039 | |
Andrii Kulian | a8ccae4 | 2019-07-24 18:35:22 +0000 | [diff] [blame] | 1040 | int startActivityAsUser(IApplicationThread caller, String callingPackage, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1041 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1042 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId, |
| 1043 | boolean validateIncomingUser) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1044 | enforceNotIsolatedCaller("startActivityAsUser"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1045 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1046 | userId = getActivityStartController().checkTargetUser(userId, validateIncomingUser, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1047 | Binder.getCallingPid(), Binder.getCallingUid(), "startActivityAsUser"); |
| 1048 | |
| 1049 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1050 | return getActivityStartController().obtainStarter(intent, "startActivityAsUser") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1051 | .setCaller(caller) |
| 1052 | .setCallingPackage(callingPackage) |
| 1053 | .setResolvedType(resolvedType) |
| 1054 | .setResultTo(resultTo) |
| 1055 | .setResultWho(resultWho) |
| 1056 | .setRequestCode(requestCode) |
| 1057 | .setStartFlags(startFlags) |
| 1058 | .setProfilerInfo(profilerInfo) |
| 1059 | .setActivityOptions(bOptions) |
| 1060 | .setMayWait(userId) |
| 1061 | .execute(); |
| 1062 | |
| 1063 | } |
| 1064 | |
| 1065 | @Override |
| 1066 | public int startActivityIntentSender(IApplicationThread caller, IIntentSender target, |
| 1067 | IBinder whitelistToken, Intent fillInIntent, String resolvedType, IBinder resultTo, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1068 | String resultWho, int requestCode, int flagsMask, int flagsValues, Bundle bOptions) { |
| 1069 | enforceNotIsolatedCaller("startActivityIntentSender"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1070 | // Refuse possible leaked file descriptors |
| 1071 | if (fillInIntent != null && fillInIntent.hasFileDescriptors()) { |
| 1072 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1073 | } |
| 1074 | |
| 1075 | if (!(target instanceof PendingIntentRecord)) { |
| 1076 | throw new IllegalArgumentException("Bad PendingIntent object"); |
| 1077 | } |
| 1078 | |
| 1079 | PendingIntentRecord pir = (PendingIntentRecord)target; |
| 1080 | |
| 1081 | synchronized (mGlobalLock) { |
| 1082 | // If this is coming from the currently resumed activity, it is |
| 1083 | // effectively saying that app switches are allowed at this point. |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1084 | final ActivityStack stack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1085 | if (stack.mResumedActivity != null && |
| 1086 | stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1087 | mAppSwitchesAllowedTime = 0; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1088 | } |
| 1089 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1090 | return pir.sendInner(0, fillInIntent, resolvedType, whitelistToken, null, null, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1091 | resultTo, resultWho, requestCode, flagsMask, flagsValues, bOptions); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | @Override |
| 1095 | public boolean startNextMatchingActivity(IBinder callingActivity, Intent intent, |
| 1096 | Bundle bOptions) { |
| 1097 | // Refuse possible leaked file descriptors |
| 1098 | if (intent != null && intent.hasFileDescriptors()) { |
| 1099 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1100 | } |
| 1101 | SafeActivityOptions options = SafeActivityOptions.fromBundle(bOptions); |
| 1102 | |
| 1103 | synchronized (mGlobalLock) { |
| 1104 | final ActivityRecord r = ActivityRecord.isInStackLocked(callingActivity); |
| 1105 | if (r == null) { |
| 1106 | SafeActivityOptions.abort(options); |
| 1107 | return false; |
| 1108 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1109 | if (!r.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1110 | // The caller is not running... d'oh! |
| 1111 | SafeActivityOptions.abort(options); |
| 1112 | return false; |
| 1113 | } |
| 1114 | intent = new Intent(intent); |
| 1115 | // The caller is not allowed to change the data. |
| 1116 | intent.setDataAndType(r.intent.getData(), r.intent.getType()); |
| 1117 | // And we are resetting to find the next component... |
| 1118 | intent.setComponent(null); |
| 1119 | |
| 1120 | final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0); |
| 1121 | |
| 1122 | ActivityInfo aInfo = null; |
| 1123 | try { |
| 1124 | List<ResolveInfo> resolves = |
| 1125 | AppGlobals.getPackageManager().queryIntentActivities( |
| 1126 | intent, r.resolvedType, |
| 1127 | PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS, |
| 1128 | UserHandle.getCallingUserId()).getList(); |
| 1129 | |
| 1130 | // Look for the original activity in the list... |
| 1131 | final int N = resolves != null ? resolves.size() : 0; |
| 1132 | for (int i=0; i<N; i++) { |
| 1133 | ResolveInfo rInfo = resolves.get(i); |
| 1134 | if (rInfo.activityInfo.packageName.equals(r.packageName) |
| 1135 | && rInfo.activityInfo.name.equals(r.info.name)) { |
| 1136 | // We found the current one... the next matching is |
| 1137 | // after it. |
| 1138 | i++; |
| 1139 | if (i<N) { |
| 1140 | aInfo = resolves.get(i).activityInfo; |
| 1141 | } |
| 1142 | if (debug) { |
| 1143 | Slog.v(TAG, "Next matching activity: found current " + r.packageName |
| 1144 | + "/" + r.info.name); |
| 1145 | Slog.v(TAG, "Next matching activity: next is " + ((aInfo == null) |
| 1146 | ? "null" : aInfo.packageName + "/" + aInfo.name)); |
| 1147 | } |
| 1148 | break; |
| 1149 | } |
| 1150 | } |
| 1151 | } catch (RemoteException e) { |
| 1152 | } |
| 1153 | |
| 1154 | if (aInfo == null) { |
| 1155 | // Nobody who is next! |
| 1156 | SafeActivityOptions.abort(options); |
| 1157 | if (debug) Slog.d(TAG, "Next matching activity: nothing found"); |
| 1158 | return false; |
| 1159 | } |
| 1160 | |
| 1161 | intent.setComponent(new ComponentName( |
| 1162 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1163 | intent.setFlags(intent.getFlags()&~( |
| 1164 | Intent.FLAG_ACTIVITY_FORWARD_RESULT| |
| 1165 | Intent.FLAG_ACTIVITY_CLEAR_TOP| |
| 1166 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK| |
| 1167 | FLAG_ACTIVITY_NEW_TASK)); |
| 1168 | |
| 1169 | // Okay now we need to start the new activity, replacing the currently running activity. |
| 1170 | // This is a little tricky because we want to start the new one as if the current one is |
| 1171 | // finished, but not finish the current one first so that there is no flicker. |
| 1172 | // And thus... |
| 1173 | final boolean wasFinishing = r.finishing; |
| 1174 | r.finishing = true; |
| 1175 | |
| 1176 | // Propagate reply information over to the new activity. |
| 1177 | final ActivityRecord resultTo = r.resultTo; |
| 1178 | final String resultWho = r.resultWho; |
| 1179 | final int requestCode = r.requestCode; |
| 1180 | r.resultTo = null; |
| 1181 | if (resultTo != null) { |
| 1182 | resultTo.removeResultsLocked(r, resultWho, requestCode); |
| 1183 | } |
| 1184 | |
| 1185 | final long origId = Binder.clearCallingIdentity(); |
| 1186 | // TODO(b/64750076): Check if calling pid should really be -1. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1187 | final int res = getActivityStartController() |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1188 | .obtainStarter(intent, "startNextMatchingActivity") |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1189 | .setCaller(r.app.getThread()) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1190 | .setResolvedType(r.resolvedType) |
| 1191 | .setActivityInfo(aInfo) |
| 1192 | .setResultTo(resultTo != null ? resultTo.appToken : null) |
| 1193 | .setResultWho(resultWho) |
| 1194 | .setRequestCode(requestCode) |
| 1195 | .setCallingPid(-1) |
| 1196 | .setCallingUid(r.launchedFromUid) |
| 1197 | .setCallingPackage(r.launchedFromPackage) |
| 1198 | .setRealCallingPid(-1) |
| 1199 | .setRealCallingUid(r.launchedFromUid) |
| 1200 | .setActivityOptions(options) |
| 1201 | .execute(); |
| 1202 | Binder.restoreCallingIdentity(origId); |
| 1203 | |
| 1204 | r.finishing = wasFinishing; |
| 1205 | if (res != ActivityManager.START_SUCCESS) { |
| 1206 | return false; |
| 1207 | } |
| 1208 | return true; |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | @Override |
| 1213 | public final WaitResult startActivityAndWait(IApplicationThread caller, String callingPackage, |
| 1214 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1215 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId) { |
| 1216 | final WaitResult res = new WaitResult(); |
| 1217 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1218 | enforceNotIsolatedCaller("startActivityAndWait"); |
| 1219 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 1220 | userId, "startActivityAndWait"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1221 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1222 | getActivityStartController().obtainStarter(intent, "startActivityAndWait") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1223 | .setCaller(caller) |
| 1224 | .setCallingPackage(callingPackage) |
| 1225 | .setResolvedType(resolvedType) |
| 1226 | .setResultTo(resultTo) |
| 1227 | .setResultWho(resultWho) |
| 1228 | .setRequestCode(requestCode) |
| 1229 | .setStartFlags(startFlags) |
| 1230 | .setActivityOptions(bOptions) |
| 1231 | .setMayWait(userId) |
| 1232 | .setProfilerInfo(profilerInfo) |
| 1233 | .setWaitResult(res) |
| 1234 | .execute(); |
| 1235 | } |
| 1236 | return res; |
| 1237 | } |
| 1238 | |
| 1239 | @Override |
| 1240 | public final int startActivityWithConfig(IApplicationThread caller, String callingPackage, |
| 1241 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1242 | int startFlags, Configuration config, Bundle bOptions, int userId) { |
| 1243 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1244 | enforceNotIsolatedCaller("startActivityWithConfig"); |
| 1245 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, |
| 1246 | "startActivityWithConfig"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1247 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1248 | return getActivityStartController().obtainStarter(intent, "startActivityWithConfig") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1249 | .setCaller(caller) |
| 1250 | .setCallingPackage(callingPackage) |
| 1251 | .setResolvedType(resolvedType) |
| 1252 | .setResultTo(resultTo) |
| 1253 | .setResultWho(resultWho) |
| 1254 | .setRequestCode(requestCode) |
| 1255 | .setStartFlags(startFlags) |
| 1256 | .setGlobalConfiguration(config) |
| 1257 | .setActivityOptions(bOptions) |
| 1258 | .setMayWait(userId) |
| 1259 | .execute(); |
| 1260 | } |
| 1261 | } |
| 1262 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1263 | |
| 1264 | @Override |
| 1265 | public IBinder requestStartActivityPermissionToken(IBinder delegatorToken) { |
| 1266 | int callingUid = Binder.getCallingUid(); |
| 1267 | if (UserHandle.getAppId(callingUid) != SYSTEM_UID) { |
| 1268 | throw new SecurityException("Only the system process can request a permission token, " |
| 1269 | + "received request from uid: " + callingUid); |
| 1270 | } |
| 1271 | IBinder permissionToken = new Binder(); |
| 1272 | synchronized (mGlobalLock) { |
| 1273 | mStartActivitySources.put(permissionToken, delegatorToken); |
| 1274 | } |
| 1275 | |
| 1276 | Message expireMsg = PooledLambda.obtainMessage( |
| 1277 | ActivityTaskManagerService::expireStartAsCallerTokenMsg, this, permissionToken); |
| 1278 | mUiHandler.sendMessageDelayed(expireMsg, START_AS_CALLER_TOKEN_TIMEOUT_IMPL); |
| 1279 | |
| 1280 | Message forgetMsg = PooledLambda.obtainMessage( |
| 1281 | ActivityTaskManagerService::forgetStartAsCallerTokenMsg, this, permissionToken); |
| 1282 | mUiHandler.sendMessageDelayed(forgetMsg, START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT); |
| 1283 | |
| 1284 | return permissionToken; |
| 1285 | } |
| 1286 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1287 | @Override |
| 1288 | public final int startActivityAsCaller(IApplicationThread caller, String callingPackage, |
| 1289 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1290 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, IBinder permissionToken, |
| 1291 | boolean ignoreTargetSecurity, int userId) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1292 | // 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] | 1293 | // permission grants) as any app that may launch one of your own activities. So we only |
| 1294 | // allow this in two cases: |
| 1295 | // 1) The caller is an activity that is part of the core framework, and then only when it |
| 1296 | // is running as the system. |
| 1297 | // 2) The caller provides a valid permissionToken. Permission tokens are one-time use and |
| 1298 | // can only be requested by a system activity, which may then delegate this call to |
| 1299 | // another app. |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1300 | final ActivityRecord sourceRecord; |
| 1301 | final int targetUid; |
| 1302 | final String targetPackage; |
| 1303 | final boolean isResolver; |
| 1304 | synchronized (mGlobalLock) { |
| 1305 | if (resultTo == null) { |
| 1306 | throw new SecurityException("Must be called from an activity"); |
| 1307 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1308 | final IBinder sourceToken; |
| 1309 | if (permissionToken != null) { |
| 1310 | // To even attempt to use a permissionToken, an app must also have this signature |
| 1311 | // permission. |
| 1312 | mAmInternal.enforceCallingPermission( |
| 1313 | android.Manifest.permission.START_ACTIVITY_AS_CALLER, |
| 1314 | "startActivityAsCaller"); |
| 1315 | // If called with a permissionToken, we want the sourceRecord from the delegator |
| 1316 | // activity that requested this token. |
| 1317 | sourceToken = mStartActivitySources.remove(permissionToken); |
| 1318 | if (sourceToken == null) { |
| 1319 | // Invalid permissionToken, check if it recently expired. |
| 1320 | if (mExpiredStartAsCallerTokens.contains(permissionToken)) { |
| 1321 | throw new SecurityException("Called with expired permission token: " |
| 1322 | + permissionToken); |
| 1323 | } else { |
| 1324 | throw new SecurityException("Called with invalid permission token: " |
| 1325 | + permissionToken); |
| 1326 | } |
| 1327 | } |
| 1328 | } else { |
| 1329 | // This method was called directly by the source. |
| 1330 | sourceToken = resultTo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1331 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1332 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1333 | sourceRecord = mRootActivityContainer.isInAnyStack(sourceToken); |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1334 | if (sourceRecord == null) { |
| 1335 | throw new SecurityException("Called with bad activity token: " + sourceToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1336 | } |
| 1337 | if (sourceRecord.app == null) { |
| 1338 | throw new SecurityException("Called without a process attached to activity"); |
| 1339 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1340 | |
| 1341 | // Whether called directly or from a delegate, the source activity must be from the |
| 1342 | // android package. |
| 1343 | if (!sourceRecord.info.packageName.equals("android")) { |
| 1344 | throw new SecurityException("Must be called from an activity that is " |
| 1345 | + "declared in the android package"); |
| 1346 | } |
| 1347 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1348 | if (UserHandle.getAppId(sourceRecord.app.mUid) != SYSTEM_UID) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1349 | // This is still okay, as long as this activity is running under the |
| 1350 | // uid of the original calling activity. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1351 | if (sourceRecord.app.mUid != sourceRecord.launchedFromUid) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1352 | throw new SecurityException( |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1353 | "Calling activity in uid " + sourceRecord.app.mUid |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1354 | + " must be system uid or original calling uid " |
| 1355 | + sourceRecord.launchedFromUid); |
| 1356 | } |
| 1357 | } |
| 1358 | if (ignoreTargetSecurity) { |
| 1359 | if (intent.getComponent() == null) { |
| 1360 | throw new SecurityException( |
| 1361 | "Component must be specified with ignoreTargetSecurity"); |
| 1362 | } |
| 1363 | if (intent.getSelector() != null) { |
| 1364 | throw new SecurityException( |
| 1365 | "Selector not allowed with ignoreTargetSecurity"); |
| 1366 | } |
| 1367 | } |
| 1368 | targetUid = sourceRecord.launchedFromUid; |
| 1369 | targetPackage = sourceRecord.launchedFromPackage; |
| 1370 | isResolver = sourceRecord.isResolverOrChildActivity(); |
| 1371 | } |
| 1372 | |
| 1373 | if (userId == UserHandle.USER_NULL) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1374 | userId = UserHandle.getUserId(sourceRecord.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | // TODO: Switch to user app stacks here. |
| 1378 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1379 | return getActivityStartController().obtainStarter(intent, "startActivityAsCaller") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1380 | .setCallingUid(targetUid) |
| 1381 | .setCallingPackage(targetPackage) |
| 1382 | .setResolvedType(resolvedType) |
| 1383 | .setResultTo(resultTo) |
| 1384 | .setResultWho(resultWho) |
| 1385 | .setRequestCode(requestCode) |
| 1386 | .setStartFlags(startFlags) |
| 1387 | .setActivityOptions(bOptions) |
| 1388 | .setMayWait(userId) |
| 1389 | .setIgnoreTargetSecurity(ignoreTargetSecurity) |
| 1390 | .setFilterCallingUid(isResolver ? 0 /* system */ : targetUid) |
Alan Stokes | 2f4a4ed | 2019-05-08 16:56:45 +0100 | [diff] [blame] | 1391 | // The target may well be in the background, which would normally prevent it |
| 1392 | // from starting an activity. Here we definitely want the start to succeed. |
| 1393 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1394 | .execute(); |
| 1395 | } catch (SecurityException e) { |
| 1396 | // XXX need to figure out how to propagate to original app. |
| 1397 | // A SecurityException here is generally actually a fault of the original |
| 1398 | // calling activity (such as a fairly granting permissions), so propagate it |
| 1399 | // back to them. |
| 1400 | /* |
| 1401 | StringBuilder msg = new StringBuilder(); |
| 1402 | msg.append("While launching"); |
| 1403 | msg.append(intent.toString()); |
| 1404 | msg.append(": "); |
| 1405 | msg.append(e.getMessage()); |
| 1406 | */ |
| 1407 | throw e; |
| 1408 | } |
| 1409 | } |
| 1410 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1411 | int handleIncomingUser(int callingPid, int callingUid, int userId, String name) { |
| 1412 | return mAmInternal.handleIncomingUser(callingPid, callingUid, userId, false /* allowAll */, |
| 1413 | ALLOW_FULL_ONLY, name, null /* callerPackage */); |
| 1414 | } |
| 1415 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1416 | @Override |
| 1417 | public int startVoiceActivity(String callingPackage, int callingPid, int callingUid, |
| 1418 | Intent intent, String resolvedType, IVoiceInteractionSession session, |
| 1419 | IVoiceInteractor interactor, int startFlags, ProfilerInfo profilerInfo, |
| 1420 | Bundle bOptions, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1421 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startVoiceActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1422 | if (session == null || interactor == null) { |
| 1423 | throw new NullPointerException("null session or interactor"); |
| 1424 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1425 | userId = handleIncomingUser(callingPid, callingUid, userId, "startVoiceActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1426 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1427 | return getActivityStartController().obtainStarter(intent, "startVoiceActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1428 | .setCallingUid(callingUid) |
| 1429 | .setCallingPackage(callingPackage) |
| 1430 | .setResolvedType(resolvedType) |
| 1431 | .setVoiceSession(session) |
| 1432 | .setVoiceInteractor(interactor) |
| 1433 | .setStartFlags(startFlags) |
| 1434 | .setProfilerInfo(profilerInfo) |
| 1435 | .setActivityOptions(bOptions) |
| 1436 | .setMayWait(userId) |
Michal Karpinski | 85fa202 | 2019-02-08 12:05:09 +0000 | [diff] [blame] | 1437 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1438 | .execute(); |
| 1439 | } |
| 1440 | |
| 1441 | @Override |
| 1442 | public int startAssistantActivity(String callingPackage, int callingPid, int callingUid, |
| 1443 | Intent intent, String resolvedType, Bundle bOptions, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1444 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startAssistantActivity()"); |
| 1445 | userId = handleIncomingUser(callingPid, callingUid, userId, "startAssistantActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1446 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1447 | return getActivityStartController().obtainStarter(intent, "startAssistantActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1448 | .setCallingUid(callingUid) |
| 1449 | .setCallingPackage(callingPackage) |
| 1450 | .setResolvedType(resolvedType) |
| 1451 | .setActivityOptions(bOptions) |
| 1452 | .setMayWait(userId) |
Michal Karpinski | 85fa202 | 2019-02-08 12:05:09 +0000 | [diff] [blame] | 1453 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1454 | .execute(); |
| 1455 | } |
| 1456 | |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1457 | /** |
| 1458 | * Start the recents activity to perform the recents animation. |
| 1459 | * |
| 1460 | * @param intent The intent to start the recents activity. |
| 1461 | * @param recentsAnimationRunner Pass {@code null} to only preload the activity. |
| 1462 | */ |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1463 | @Override |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1464 | public void startRecentsActivity(Intent intent, @Deprecated IAssistDataReceiver unused, |
| 1465 | @Nullable IRecentsAnimationRunner recentsAnimationRunner) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1466 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "startRecentsActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1467 | final int callingPid = Binder.getCallingPid(); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1468 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1469 | final long origId = Binder.clearCallingIdentity(); |
| 1470 | try { |
| 1471 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 1472 | final ComponentName recentsComponent = mRecentTasks.getRecentsComponent(); |
| 1473 | final int recentsUid = mRecentTasks.getRecentsComponentUid(); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1474 | final WindowProcessController caller = getProcessController(callingPid, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1475 | |
| 1476 | // Start a new recents animation |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1477 | final RecentsAnimation anim = new RecentsAnimation(this, mStackSupervisor, |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1478 | getActivityStartController(), mWindowManager, intent, recentsComponent, |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 1479 | recentsUid, caller); |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1480 | if (recentsAnimationRunner == null) { |
| 1481 | anim.preloadRecentsActivity(); |
| 1482 | } else { |
| 1483 | anim.startRecentsActivity(recentsAnimationRunner); |
| 1484 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1485 | } |
| 1486 | } finally { |
| 1487 | Binder.restoreCallingIdentity(origId); |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | @Override |
| 1492 | public final int startActivityFromRecents(int taskId, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1493 | enforceCallerIsRecentsOrHasPermission(START_TASKS_FROM_RECENTS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1494 | "startActivityFromRecents()"); |
| 1495 | |
| 1496 | final int callingPid = Binder.getCallingPid(); |
| 1497 | final int callingUid = Binder.getCallingUid(); |
| 1498 | final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(bOptions); |
| 1499 | final long origId = Binder.clearCallingIdentity(); |
| 1500 | try { |
| 1501 | synchronized (mGlobalLock) { |
| 1502 | return mStackSupervisor.startActivityFromRecents(callingPid, callingUid, taskId, |
| 1503 | safeOptions); |
| 1504 | } |
| 1505 | } finally { |
| 1506 | Binder.restoreCallingIdentity(origId); |
| 1507 | } |
| 1508 | } |
| 1509 | |
| 1510 | /** |
Andrii Kulian | 2eb84b2 | 2018-12-13 18:18:54 -0800 | [diff] [blame] | 1511 | * Public API to check if the client is allowed to start an activity on specified display. |
| 1512 | * |
| 1513 | * If the target display is private or virtual, some restrictions will apply. |
| 1514 | * |
| 1515 | * @param displayId Target display id. |
| 1516 | * @param intent Intent used to launch the activity. |
| 1517 | * @param resolvedType The MIME type of the intent. |
| 1518 | * @param userId The id of the user for whom the call is made. |
| 1519 | * @return {@code true} if a call to start an activity on the target display should succeed and |
| 1520 | * no {@link SecurityException} will be thrown, {@code false} otherwise. |
| 1521 | */ |
| 1522 | @Override |
| 1523 | public final boolean isActivityStartAllowedOnDisplay(int displayId, Intent intent, |
| 1524 | String resolvedType, int userId) { |
| 1525 | final int callingUid = Binder.getCallingUid(); |
| 1526 | final int callingPid = Binder.getCallingPid(); |
| 1527 | final long origId = Binder.clearCallingIdentity(); |
| 1528 | |
| 1529 | try { |
| 1530 | // Collect information about the target of the Intent. |
| 1531 | ActivityInfo aInfo = mStackSupervisor.resolveActivity(intent, resolvedType, |
| 1532 | 0 /* startFlags */, null /* profilerInfo */, userId, |
| 1533 | ActivityStarter.computeResolveFilterUid(callingUid, callingUid, |
| 1534 | UserHandle.USER_NULL)); |
| 1535 | aInfo = mAmInternal.getActivityInfoForUser(aInfo, userId); |
| 1536 | |
| 1537 | synchronized (mGlobalLock) { |
| 1538 | return mStackSupervisor.canPlaceEntityOnDisplay(displayId, callingPid, callingUid, |
| 1539 | aInfo); |
| 1540 | } |
| 1541 | } finally { |
| 1542 | Binder.restoreCallingIdentity(origId); |
| 1543 | } |
| 1544 | } |
| 1545 | |
| 1546 | /** |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1547 | * This is the internal entry point for handling Activity.finish(). |
| 1548 | * |
| 1549 | * @param token The Binder token referencing the Activity we want to finish. |
| 1550 | * @param resultCode Result code, if any, from this Activity. |
| 1551 | * @param resultData Result data (Intent), if any, from this Activity. |
| 1552 | * @param finishTask Whether to finish the task associated with this Activity. |
| 1553 | * |
| 1554 | * @return Returns true if the activity successfully finished, or false if it is still running. |
| 1555 | */ |
| 1556 | @Override |
| 1557 | public final boolean finishActivity(IBinder token, int resultCode, Intent resultData, |
| 1558 | int finishTask) { |
| 1559 | // Refuse possible leaked file descriptors |
| 1560 | if (resultData != null && resultData.hasFileDescriptors()) { |
| 1561 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1562 | } |
| 1563 | |
| 1564 | synchronized (mGlobalLock) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 1565 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1566 | if (r == null) { |
| 1567 | return true; |
| 1568 | } |
| 1569 | // Keep track of the root activity of the task before we finish it |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1570 | final TaskRecord tr = r.getTaskRecord(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1571 | ActivityRecord rootR = tr.getRootActivity(); |
| 1572 | if (rootR == null) { |
| 1573 | Slog.w(TAG, "Finishing task with all activities already finished"); |
| 1574 | } |
| 1575 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps can |
| 1576 | // finish. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1577 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1578 | return false; |
| 1579 | } |
| 1580 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1581 | // TODO: There is a dup. of this block of code in ActivityStack.navigateUpToLocked |
| 1582 | // We should consolidate. |
| 1583 | if (mController != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1584 | // Find the first activity that is not finishing. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1585 | final ActivityRecord next = r.getActivityStack().topRunningActivityLocked(token, 0); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1586 | if (next != null) { |
| 1587 | // ask watcher if this is allowed |
| 1588 | boolean resumeOK = true; |
| 1589 | try { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1590 | resumeOK = mController.activityResuming(next.packageName); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1591 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1592 | mController = null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1593 | Watchdog.getInstance().setActivityController(null); |
| 1594 | } |
| 1595 | |
| 1596 | if (!resumeOK) { |
| 1597 | Slog.i(TAG, "Not finishing activity because controller resumed"); |
| 1598 | return false; |
| 1599 | } |
| 1600 | } |
| 1601 | } |
Michal Karpinski | fc6872e | 2019-05-21 15:18:44 +0100 | [diff] [blame] | 1602 | |
| 1603 | // note down that the process has finished an activity and is in background activity |
| 1604 | // starts grace period |
| 1605 | if (r.app != null) { |
| 1606 | r.app.setLastActivityFinishTimeIfNeeded(SystemClock.uptimeMillis()); |
| 1607 | } |
| 1608 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1609 | final long origId = Binder.clearCallingIdentity(); |
| 1610 | try { |
| 1611 | boolean res; |
| 1612 | final boolean finishWithRootActivity = |
| 1613 | finishTask == Activity.FINISH_TASK_WITH_ROOT_ACTIVITY; |
| 1614 | if (finishTask == Activity.FINISH_TASK_WITH_ACTIVITY |
| 1615 | || (finishWithRootActivity && r == rootR)) { |
| 1616 | // If requested, remove the task that is associated to this activity only if it |
| 1617 | // was the root activity in the task. The result code and data is ignored |
| 1618 | // because we don't support returning them across task boundaries. Also, to |
| 1619 | // keep backwards compatibility we remove the task from recents when finishing |
| 1620 | // task with root activity. |
| 1621 | res = mStackSupervisor.removeTaskByIdLocked(tr.taskId, false, |
| 1622 | finishWithRootActivity, "finish-activity"); |
| 1623 | if (!res) { |
| 1624 | Slog.i(TAG, "Removing task failed to finish activity"); |
| 1625 | } |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 1626 | // Explicitly dismissing the activity so reset its relaunch flag. |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 1627 | r.mRelaunchReason = RELAUNCH_REASON_NONE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1628 | } else { |
| 1629 | res = tr.getStack().requestFinishActivityLocked(token, resultCode, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 1630 | resultData, "app-request", true); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1631 | if (!res) { |
| 1632 | Slog.i(TAG, "Failed to finish by app-request"); |
| 1633 | } |
| 1634 | } |
| 1635 | return res; |
| 1636 | } finally { |
| 1637 | Binder.restoreCallingIdentity(origId); |
| 1638 | } |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | @Override |
| 1643 | public boolean finishActivityAffinity(IBinder token) { |
| 1644 | synchronized (mGlobalLock) { |
| 1645 | final long origId = Binder.clearCallingIdentity(); |
| 1646 | try { |
| 1647 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1648 | if (r == null) { |
| 1649 | return false; |
| 1650 | } |
| 1651 | |
| 1652 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps |
| 1653 | // can finish. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1654 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1655 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1656 | return false; |
| 1657 | } |
| 1658 | return task.getStack().finishActivityAffinityLocked(r); |
| 1659 | } finally { |
| 1660 | Binder.restoreCallingIdentity(origId); |
| 1661 | } |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | @Override |
| 1666 | public final void activityIdle(IBinder token, Configuration config, boolean stopProfiling) { |
| 1667 | final long origId = Binder.clearCallingIdentity(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1668 | try { |
| 1669 | WindowProcessController proc = null; |
| 1670 | synchronized (mGlobalLock) { |
| 1671 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 1672 | if (stack == null) { |
| 1673 | return; |
| 1674 | } |
| 1675 | final ActivityRecord r = mStackSupervisor.activityIdleInternalLocked(token, |
| 1676 | false /* fromTimeout */, false /* processPausingActivities */, config); |
| 1677 | if (r != null) { |
| 1678 | proc = r.app; |
| 1679 | } |
| 1680 | if (stopProfiling && proc != null) { |
| 1681 | proc.clearProfilerIfNeeded(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1682 | } |
| 1683 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1684 | } finally { |
| 1685 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1686 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | @Override |
| 1690 | public final void activityResumed(IBinder token) { |
| 1691 | final long origId = Binder.clearCallingIdentity(); |
| 1692 | synchronized (mGlobalLock) { |
| 1693 | ActivityRecord.activityResumedLocked(token); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1694 | mWindowManager.notifyAppResumedFinished(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1695 | } |
| 1696 | Binder.restoreCallingIdentity(origId); |
| 1697 | } |
| 1698 | |
| 1699 | @Override |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 1700 | public final void activityTopResumedStateLost() { |
| 1701 | final long origId = Binder.clearCallingIdentity(); |
| 1702 | synchronized (mGlobalLock) { |
| 1703 | mStackSupervisor.handleTopResumedStateReleased(false /* timeout */); |
| 1704 | } |
| 1705 | Binder.restoreCallingIdentity(origId); |
| 1706 | } |
| 1707 | |
| 1708 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1709 | public final void activityPaused(IBinder token) { |
| 1710 | final long origId = Binder.clearCallingIdentity(); |
| 1711 | synchronized (mGlobalLock) { |
| 1712 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 1713 | if (stack != null) { |
| 1714 | stack.activityPausedLocked(token, false); |
| 1715 | } |
| 1716 | } |
| 1717 | Binder.restoreCallingIdentity(origId); |
| 1718 | } |
| 1719 | |
| 1720 | @Override |
| 1721 | public final void activityStopped(IBinder token, Bundle icicle, |
| 1722 | PersistableBundle persistentState, CharSequence description) { |
| 1723 | if (DEBUG_ALL) Slog.v(TAG, "Activity stopped: token=" + token); |
| 1724 | |
| 1725 | // Refuse possible leaked file descriptors |
| 1726 | if (icicle != null && icicle.hasFileDescriptors()) { |
| 1727 | throw new IllegalArgumentException("File descriptors passed in Bundle"); |
| 1728 | } |
| 1729 | |
| 1730 | final long origId = Binder.clearCallingIdentity(); |
| 1731 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1732 | String restartingName = null; |
| 1733 | int restartingUid = 0; |
| 1734 | final ActivityRecord r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1735 | synchronized (mGlobalLock) { |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1736 | r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1737 | if (r != null) { |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1738 | if (r.attachedToProcess() |
| 1739 | && r.isState(ActivityStack.ActivityState.RESTARTING_PROCESS)) { |
| 1740 | // The activity was requested to restart from |
| 1741 | // {@link #restartActivityProcessIfVisible}. |
| 1742 | restartingName = r.app.mName; |
| 1743 | restartingUid = r.app.mUid; |
| 1744 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1745 | r.activityStoppedLocked(icicle, persistentState, description); |
| 1746 | } |
| 1747 | } |
| 1748 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1749 | if (restartingName != null) { |
| 1750 | // In order to let the foreground activity can be restarted with its saved state from |
| 1751 | // {@link android.app.Activity#onSaveInstanceState}, the kill operation is postponed |
| 1752 | // until the activity reports stopped with the state. And the activity record will be |
| 1753 | // kept because the record state is restarting, then the activity will be restarted |
| 1754 | // immediately if it is still the top one. |
| 1755 | mStackSupervisor.removeRestartTimeouts(r); |
| 1756 | mAmInternal.killProcess(restartingName, restartingUid, "restartActivityProcess"); |
| 1757 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1758 | mAmInternal.trimApplications(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1759 | |
| 1760 | Binder.restoreCallingIdentity(origId); |
| 1761 | } |
| 1762 | |
| 1763 | @Override |
| 1764 | public final void activityDestroyed(IBinder token) { |
| 1765 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "ACTIVITY DESTROYED: " + token); |
| 1766 | synchronized (mGlobalLock) { |
| 1767 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 1768 | if (stack != null) { |
| 1769 | stack.activityDestroyedLocked(token, "activityDestroyed"); |
| 1770 | } |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | @Override |
| 1775 | public final void activityRelaunched(IBinder token) { |
| 1776 | final long origId = Binder.clearCallingIdentity(); |
| 1777 | synchronized (mGlobalLock) { |
| 1778 | mStackSupervisor.activityRelaunchedLocked(token); |
| 1779 | } |
| 1780 | Binder.restoreCallingIdentity(origId); |
| 1781 | } |
| 1782 | |
| 1783 | public final void activitySlept(IBinder token) { |
| 1784 | if (DEBUG_ALL) Slog.v(TAG, "Activity slept: token=" + token); |
| 1785 | |
| 1786 | final long origId = Binder.clearCallingIdentity(); |
| 1787 | |
| 1788 | synchronized (mGlobalLock) { |
| 1789 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1790 | if (r != null) { |
| 1791 | mStackSupervisor.activitySleptLocked(r); |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | Binder.restoreCallingIdentity(origId); |
| 1796 | } |
| 1797 | |
| 1798 | @Override |
| 1799 | public void setRequestedOrientation(IBinder token, int requestedOrientation) { |
| 1800 | synchronized (mGlobalLock) { |
| 1801 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1802 | if (r == null) { |
| 1803 | return; |
| 1804 | } |
| 1805 | final long origId = Binder.clearCallingIdentity(); |
| 1806 | try { |
| 1807 | r.setRequestedOrientation(requestedOrientation); |
| 1808 | } finally { |
| 1809 | Binder.restoreCallingIdentity(origId); |
| 1810 | } |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | @Override |
| 1815 | public int getRequestedOrientation(IBinder token) { |
| 1816 | synchronized (mGlobalLock) { |
| 1817 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1818 | if (r == null) { |
| 1819 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 1820 | } |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 1821 | return r.getOrientation(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | @Override |
| 1826 | public void setImmersive(IBinder token, boolean immersive) { |
| 1827 | synchronized (mGlobalLock) { |
| 1828 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1829 | if (r == null) { |
| 1830 | throw new IllegalArgumentException(); |
| 1831 | } |
| 1832 | r.immersive = immersive; |
| 1833 | |
| 1834 | // update associated state if we're frontmost |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1835 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1836 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, "Frontmost changed immersion: "+ r); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1837 | applyUpdateLockStateLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1838 | } |
| 1839 | } |
| 1840 | } |
| 1841 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1842 | void applyUpdateLockStateLocked(ActivityRecord r) { |
| 1843 | // Modifications to the UpdateLock state are done on our handler, outside |
| 1844 | // the activity manager's locks. The new state is determined based on the |
| 1845 | // state *now* of the relevant activity record. The object is passed to |
| 1846 | // the handler solely for logging detail, not to be consulted/modified. |
| 1847 | final boolean nextState = r != null && r.immersive; |
| 1848 | mH.post(() -> { |
| 1849 | if (mUpdateLock.isHeld() != nextState) { |
| 1850 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, |
| 1851 | "Applying new update lock state '" + nextState + "' for " + r); |
| 1852 | if (nextState) { |
| 1853 | mUpdateLock.acquire(); |
| 1854 | } else { |
| 1855 | mUpdateLock.release(); |
| 1856 | } |
| 1857 | } |
| 1858 | }); |
| 1859 | } |
| 1860 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1861 | @Override |
| 1862 | public boolean isImmersive(IBinder token) { |
| 1863 | synchronized (mGlobalLock) { |
| 1864 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1865 | if (r == null) { |
| 1866 | throw new IllegalArgumentException(); |
| 1867 | } |
| 1868 | return r.immersive; |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | @Override |
| 1873 | public boolean isTopActivityImmersive() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1874 | enforceNotIsolatedCaller("isTopActivityImmersive"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1875 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1876 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivityLocked(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1877 | return (r != null) ? r.immersive : false; |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | @Override |
| 1882 | public void overridePendingTransition(IBinder token, String packageName, |
| 1883 | int enterAnim, int exitAnim) { |
| 1884 | synchronized (mGlobalLock) { |
| 1885 | ActivityRecord self = ActivityRecord.isInStackLocked(token); |
| 1886 | if (self == null) { |
| 1887 | return; |
| 1888 | } |
| 1889 | |
| 1890 | final long origId = Binder.clearCallingIdentity(); |
| 1891 | |
| 1892 | if (self.isState( |
| 1893 | ActivityStack.ActivityState.RESUMED, ActivityStack.ActivityState.PAUSING)) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1894 | self.getDisplay().mDisplayContent.mAppTransition.overridePendingAppTransition( |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1895 | packageName, enterAnim, exitAnim, null); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | Binder.restoreCallingIdentity(origId); |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | @Override |
| 1903 | public int getFrontActivityScreenCompatMode() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1904 | enforceNotIsolatedCaller("getFrontActivityScreenCompatMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1905 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1906 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivityLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1907 | if (r == null) { |
| 1908 | return ActivityManager.COMPAT_MODE_UNKNOWN; |
| 1909 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1910 | return mCompatModePackages.computeCompatModeLocked(r.info.applicationInfo); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1911 | } |
| 1912 | } |
| 1913 | |
| 1914 | @Override |
| 1915 | public void setFrontActivityScreenCompatMode(int mode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1916 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1917 | "setFrontActivityScreenCompatMode"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1918 | ApplicationInfo ai; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1919 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1920 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivityLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1921 | if (r == null) { |
| 1922 | Slog.w(TAG, "setFrontActivityScreenCompatMode failed: no top activity"); |
| 1923 | return; |
| 1924 | } |
| 1925 | ai = r.info.applicationInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1926 | mCompatModePackages.setPackageScreenCompatModeLocked(ai, mode); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | @Override |
| 1931 | public int getLaunchedFromUid(IBinder activityToken) { |
| 1932 | ActivityRecord srec; |
| 1933 | synchronized (mGlobalLock) { |
| 1934 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 1935 | } |
| 1936 | if (srec == null) { |
| 1937 | return -1; |
| 1938 | } |
| 1939 | return srec.launchedFromUid; |
| 1940 | } |
| 1941 | |
| 1942 | @Override |
| 1943 | public String getLaunchedFromPackage(IBinder activityToken) { |
| 1944 | ActivityRecord srec; |
| 1945 | synchronized (mGlobalLock) { |
| 1946 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 1947 | } |
| 1948 | if (srec == null) { |
| 1949 | return null; |
| 1950 | } |
| 1951 | return srec.launchedFromPackage; |
| 1952 | } |
| 1953 | |
| 1954 | @Override |
| 1955 | public boolean convertFromTranslucent(IBinder token) { |
| 1956 | final long origId = Binder.clearCallingIdentity(); |
| 1957 | try { |
| 1958 | synchronized (mGlobalLock) { |
| 1959 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1960 | if (r == null) { |
| 1961 | return false; |
| 1962 | } |
| 1963 | final boolean translucentChanged = r.changeWindowTranslucency(true); |
| 1964 | if (translucentChanged) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1965 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1966 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1967 | mWindowManager.setAppFullscreen(token, true); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1968 | return translucentChanged; |
| 1969 | } |
| 1970 | } finally { |
| 1971 | Binder.restoreCallingIdentity(origId); |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | @Override |
| 1976 | public boolean convertToTranslucent(IBinder token, Bundle options) { |
| 1977 | SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(options); |
| 1978 | final long origId = Binder.clearCallingIdentity(); |
| 1979 | try { |
| 1980 | synchronized (mGlobalLock) { |
| 1981 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1982 | if (r == null) { |
| 1983 | return false; |
| 1984 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1985 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1986 | int index = task.mActivities.lastIndexOf(r); |
| 1987 | if (index > 0) { |
| 1988 | ActivityRecord under = task.mActivities.get(index - 1); |
| 1989 | under.returningOptions = safeOptions != null ? safeOptions.getOptions(r) : null; |
| 1990 | } |
| 1991 | final boolean translucentChanged = r.changeWindowTranslucency(false); |
| 1992 | if (translucentChanged) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1993 | r.getActivityStack().convertActivityToTranslucent(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1994 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1995 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1996 | mWindowManager.setAppFullscreen(token, false); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1997 | return translucentChanged; |
| 1998 | } |
| 1999 | } finally { |
| 2000 | Binder.restoreCallingIdentity(origId); |
| 2001 | } |
| 2002 | } |
| 2003 | |
| 2004 | @Override |
| 2005 | public void notifyActivityDrawn(IBinder token) { |
| 2006 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, "notifyActivityDrawn: token=" + token); |
| 2007 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2008 | ActivityRecord r = mRootActivityContainer.isInAnyStack(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2009 | if (r != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2010 | r.getActivityStack().notifyActivityDrawnLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2011 | } |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | @Override |
| 2016 | public void reportActivityFullyDrawn(IBinder token, boolean restoredFromBundle) { |
| 2017 | synchronized (mGlobalLock) { |
| 2018 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2019 | if (r == null) { |
| 2020 | return; |
| 2021 | } |
| 2022 | r.reportFullyDrawnLocked(restoredFromBundle); |
| 2023 | } |
| 2024 | } |
| 2025 | |
| 2026 | @Override |
| 2027 | public int getActivityDisplayId(IBinder activityToken) throws RemoteException { |
| 2028 | synchronized (mGlobalLock) { |
| 2029 | final ActivityStack stack = ActivityRecord.getStackLocked(activityToken); |
| 2030 | if (stack != null && stack.mDisplayId != INVALID_DISPLAY) { |
| 2031 | return stack.mDisplayId; |
| 2032 | } |
| 2033 | return DEFAULT_DISPLAY; |
| 2034 | } |
| 2035 | } |
| 2036 | |
| 2037 | @Override |
| 2038 | public ActivityManager.StackInfo getFocusedStackInfo() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2039 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2040 | long ident = Binder.clearCallingIdentity(); |
| 2041 | try { |
| 2042 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2043 | ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2044 | if (focusedStack != null) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2045 | return mRootActivityContainer.getStackInfo(focusedStack.mStackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2046 | } |
| 2047 | return null; |
| 2048 | } |
| 2049 | } finally { |
| 2050 | Binder.restoreCallingIdentity(ident); |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | @Override |
| 2055 | public void setFocusedStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2056 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2057 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedStack: stackId=" + stackId); |
| 2058 | final long callingId = Binder.clearCallingIdentity(); |
| 2059 | try { |
| 2060 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2061 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2062 | if (stack == null) { |
| 2063 | Slog.w(TAG, "setFocusedStack: No stack with id=" + stackId); |
| 2064 | return; |
| 2065 | } |
| 2066 | final ActivityRecord r = stack.topRunningActivityLocked(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2067 | if (r != null && r.moveFocusableActivityToTop("setFocusedStack")) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2068 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2069 | } |
| 2070 | } |
| 2071 | } finally { |
| 2072 | Binder.restoreCallingIdentity(callingId); |
| 2073 | } |
| 2074 | } |
| 2075 | |
| 2076 | @Override |
| 2077 | public void setFocusedTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2078 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2079 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedTask: taskId=" + taskId); |
| 2080 | final long callingId = Binder.clearCallingIdentity(); |
| 2081 | try { |
| 2082 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2083 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2084 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2085 | if (task == null) { |
| 2086 | return; |
| 2087 | } |
| 2088 | final ActivityRecord r = task.topRunningActivityLocked(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2089 | if (r != null && r.moveFocusableActivityToTop("setFocusedTask")) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2090 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2091 | } |
| 2092 | } |
| 2093 | } finally { |
| 2094 | Binder.restoreCallingIdentity(callingId); |
| 2095 | } |
| 2096 | } |
| 2097 | |
| 2098 | @Override |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2099 | public void restartActivityProcessIfVisible(IBinder activityToken) { |
| 2100 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "restartActivityProcess()"); |
| 2101 | final long callingId = Binder.clearCallingIdentity(); |
| 2102 | try { |
| 2103 | synchronized (mGlobalLock) { |
| 2104 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 2105 | if (r == null) { |
| 2106 | return; |
| 2107 | } |
| 2108 | r.restartProcessIfVisible(); |
| 2109 | } |
| 2110 | } finally { |
| 2111 | Binder.restoreCallingIdentity(callingId); |
| 2112 | } |
| 2113 | } |
| 2114 | |
| 2115 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2116 | public boolean removeTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2117 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2118 | synchronized (mGlobalLock) { |
| 2119 | final long ident = Binder.clearCallingIdentity(); |
| 2120 | try { |
| 2121 | return mStackSupervisor.removeTaskByIdLocked(taskId, true, REMOVE_FROM_RECENTS, |
| 2122 | "remove-task"); |
| 2123 | } finally { |
| 2124 | Binder.restoreCallingIdentity(ident); |
| 2125 | } |
| 2126 | } |
| 2127 | } |
| 2128 | |
| 2129 | @Override |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 2130 | public void removeAllVisibleRecentTasks() { |
| 2131 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeAllVisibleRecentTasks()"); |
| 2132 | synchronized (mGlobalLock) { |
| 2133 | final long ident = Binder.clearCallingIdentity(); |
| 2134 | try { |
Winson Chung | 42fa21f | 2019-04-02 16:23:46 -0700 | [diff] [blame] | 2135 | getRecentTasks().removeAllVisibleTasks(mAmInternal.getCurrentUserId()); |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 2136 | } finally { |
| 2137 | Binder.restoreCallingIdentity(ident); |
| 2138 | } |
| 2139 | } |
| 2140 | } |
| 2141 | |
| 2142 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2143 | public boolean shouldUpRecreateTask(IBinder token, String destAffinity) { |
| 2144 | synchronized (mGlobalLock) { |
| 2145 | final ActivityRecord srec = ActivityRecord.forTokenLocked(token); |
| 2146 | if (srec != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2147 | return srec.getActivityStack().shouldUpRecreateTaskLocked(srec, destAffinity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2148 | } |
| 2149 | } |
| 2150 | return false; |
| 2151 | } |
| 2152 | |
| 2153 | @Override |
| 2154 | public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode, |
| 2155 | Intent resultData) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2156 | |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 2157 | synchronized (mGlobalLock) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2158 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2159 | if (r != null) { |
| 2160 | return r.getActivityStack().navigateUpToLocked( |
| 2161 | r, destIntent, resultCode, resultData); |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 2162 | } |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2163 | return false; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | /** |
| 2168 | * Attempts to move a task backwards in z-order (the order of activities within the task is |
| 2169 | * unchanged). |
| 2170 | * |
| 2171 | * There are several possible results of this call: |
| 2172 | * - if the task is locked, then we will show the lock toast |
| 2173 | * - if there is a task behind the provided task, then that task is made visible and resumed as |
| 2174 | * this task is moved to the back |
| 2175 | * - otherwise, if there are no other tasks in the stack: |
| 2176 | * - if this task is in the pinned stack, then we remove the stack completely, which will |
| 2177 | * have the effect of moving the task to the top or bottom of the fullscreen stack |
| 2178 | * (depending on whether it is visible) |
| 2179 | * - otherwise, we simply return home and hide this task |
| 2180 | * |
| 2181 | * @param token A reference to the activity we wish to move |
| 2182 | * @param nonRoot If false then this only works if the activity is the root |
| 2183 | * of a task; if true it will work for any activity in a task. |
| 2184 | * @return Returns true if the move completed, false if not. |
| 2185 | */ |
| 2186 | @Override |
| 2187 | public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2188 | enforceNotIsolatedCaller("moveActivityTaskToBack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2189 | synchronized (mGlobalLock) { |
| 2190 | final long origId = Binder.clearCallingIdentity(); |
| 2191 | try { |
| 2192 | int taskId = ActivityRecord.getTaskForActivityLocked(token, !nonRoot); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2193 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2194 | if (task != null) { |
| 2195 | return ActivityRecord.getStackLocked(token).moveTaskToBackLocked(taskId); |
| 2196 | } |
| 2197 | } finally { |
| 2198 | Binder.restoreCallingIdentity(origId); |
| 2199 | } |
| 2200 | } |
| 2201 | return false; |
| 2202 | } |
| 2203 | |
| 2204 | @Override |
| 2205 | public Rect getTaskBounds(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2206 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getTaskBounds()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2207 | long ident = Binder.clearCallingIdentity(); |
| 2208 | Rect rect = new Rect(); |
| 2209 | try { |
| 2210 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2211 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2212 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2213 | if (task == null) { |
| 2214 | Slog.w(TAG, "getTaskBounds: taskId=" + taskId + " not found"); |
| 2215 | return rect; |
| 2216 | } |
| 2217 | if (task.getStack() != null) { |
| 2218 | // Return the bounds from window manager since it will be adjusted for various |
| 2219 | // things like the presense of a docked stack for tasks that aren't resizeable. |
| 2220 | task.getWindowContainerBounds(rect); |
| 2221 | } else { |
| 2222 | // Task isn't in window manager yet since it isn't associated with a stack. |
| 2223 | // Return the persist value from activity manager |
| 2224 | if (!task.matchParentBounds()) { |
| 2225 | rect.set(task.getBounds()); |
| 2226 | } else if (task.mLastNonFullscreenBounds != null) { |
| 2227 | rect.set(task.mLastNonFullscreenBounds); |
| 2228 | } |
| 2229 | } |
| 2230 | } |
| 2231 | } finally { |
| 2232 | Binder.restoreCallingIdentity(ident); |
| 2233 | } |
| 2234 | return rect; |
| 2235 | } |
| 2236 | |
| 2237 | @Override |
| 2238 | public ActivityManager.TaskDescription getTaskDescription(int id) { |
| 2239 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2240 | enforceCallerIsRecentsOrHasPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2241 | MANAGE_ACTIVITY_STACKS, "getTaskDescription()"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2242 | final TaskRecord tr = mRootActivityContainer.anyTaskForId(id, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2243 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2244 | if (tr != null) { |
| 2245 | return tr.lastTaskDescription; |
| 2246 | } |
| 2247 | } |
| 2248 | return null; |
| 2249 | } |
| 2250 | |
| 2251 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2252 | public void setTaskWindowingMode(int taskId, int windowingMode, boolean toTop) { |
| 2253 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 2254 | setTaskWindowingModeSplitScreenPrimary(taskId, SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, |
| 2255 | toTop, ANIMATE, null /* initialBounds */, true /* showRecents */); |
| 2256 | return; |
| 2257 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2258 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setTaskWindowingMode()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2259 | synchronized (mGlobalLock) { |
| 2260 | final long ident = Binder.clearCallingIdentity(); |
| 2261 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2262 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2263 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2264 | if (task == null) { |
| 2265 | Slog.w(TAG, "setTaskWindowingMode: No task for id=" + taskId); |
| 2266 | return; |
| 2267 | } |
| 2268 | |
| 2269 | if (DEBUG_STACK) Slog.d(TAG_STACK, "setTaskWindowingMode: moving task=" + taskId |
| 2270 | + " to windowingMode=" + windowingMode + " toTop=" + toTop); |
| 2271 | |
| 2272 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2273 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2274 | + " non-standard task " + taskId + " to windowing mode=" |
| 2275 | + windowingMode); |
| 2276 | } |
| 2277 | |
| 2278 | final ActivityStack stack = task.getStack(); |
| 2279 | if (toTop) { |
| 2280 | stack.moveToFront("setTaskWindowingMode", task); |
| 2281 | } |
| 2282 | stack.setWindowingMode(windowingMode); |
| 2283 | } finally { |
| 2284 | Binder.restoreCallingIdentity(ident); |
| 2285 | } |
| 2286 | } |
| 2287 | } |
| 2288 | |
| 2289 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2290 | public String getCallingPackage(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2291 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2292 | ActivityRecord r = getCallingRecordLocked(token); |
| 2293 | return r != null ? r.info.packageName : null; |
| 2294 | } |
| 2295 | } |
| 2296 | |
| 2297 | @Override |
| 2298 | public ComponentName getCallingActivity(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2299 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2300 | ActivityRecord r = getCallingRecordLocked(token); |
| 2301 | return r != null ? r.intent.getComponent() : null; |
| 2302 | } |
| 2303 | } |
| 2304 | |
| 2305 | private ActivityRecord getCallingRecordLocked(IBinder token) { |
| 2306 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2307 | if (r == null) { |
| 2308 | return null; |
| 2309 | } |
| 2310 | return r.resultTo; |
| 2311 | } |
| 2312 | |
| 2313 | @Override |
| 2314 | public void unhandledBack() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2315 | mAmInternal.enforceCallingPermission(android.Manifest.permission.FORCE_BACK, "unhandledBack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2316 | |
| 2317 | synchronized (mGlobalLock) { |
| 2318 | final long origId = Binder.clearCallingIdentity(); |
| 2319 | try { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2320 | getTopDisplayFocusedStack().unhandledBackLocked(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2321 | } finally { |
| 2322 | Binder.restoreCallingIdentity(origId); |
| 2323 | } |
| 2324 | } |
| 2325 | } |
| 2326 | |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2327 | @Override |
| 2328 | public void onBackPressedOnTaskRoot(IBinder token, IRequestFinishCallback callback) { |
| 2329 | synchronized (mGlobalLock) { |
| 2330 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2331 | if (r == null) { |
| 2332 | return; |
| 2333 | } |
| 2334 | ActivityStack stack = r.getActivityStack(); |
| 2335 | if (stack != null && stack.isSingleTaskInstance()) { |
| 2336 | // Single-task stacks are used for activities which are presented in floating |
| 2337 | // windows above full screen activities. Instead of directly finishing the |
| 2338 | // task, a task change listener is used to notify SystemUI so the action can be |
| 2339 | // handled specially. |
| 2340 | final TaskRecord task = r.getTaskRecord(); |
| 2341 | mTaskChangeNotificationController |
| 2342 | .notifyBackPressedOnTaskRoot(task.getTaskInfo()); |
| 2343 | } else { |
| 2344 | try { |
| 2345 | callback.requestFinish(); |
| 2346 | } catch (RemoteException e) { |
| 2347 | Slog.e(TAG, "Failed to invoke request finish callback", e); |
| 2348 | } |
| 2349 | } |
| 2350 | } |
| 2351 | } |
| 2352 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2353 | /** |
| 2354 | * TODO: Add mController hook |
| 2355 | */ |
| 2356 | @Override |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2357 | public void moveTaskToFront(IApplicationThread appThread, String callingPackage, int taskId, |
| 2358 | int flags, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2359 | mAmInternal.enforceCallingPermission(android.Manifest.permission.REORDER_TASKS, "moveTaskToFront()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2360 | |
| 2361 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToFront: moving taskId=" + taskId); |
| 2362 | synchronized (mGlobalLock) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2363 | moveTaskToFrontLocked(appThread, callingPackage, taskId, flags, |
| 2364 | SafeActivityOptions.fromBundle(bOptions), false /* fromRecents */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2365 | } |
| 2366 | } |
| 2367 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2368 | void moveTaskToFrontLocked(@Nullable IApplicationThread appThread, |
| 2369 | @Nullable String callingPackage, int taskId, int flags, SafeActivityOptions options, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2370 | boolean fromRecents) { |
Andrii Kulian | a8ccae4 | 2019-07-24 18:35:22 +0000 | [diff] [blame] | 2371 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2372 | final int callingPid = Binder.getCallingPid(); |
| 2373 | final int callingUid = Binder.getCallingUid(); |
Andrii Kulian | a8ccae4 | 2019-07-24 18:35:22 +0000 | [diff] [blame] | 2374 | if (!isSameApp(callingUid, callingPackage)) { |
| 2375 | String msg = "Permission Denial: moveTaskToFrontLocked() from pid=" |
| 2376 | + Binder.getCallingPid() + " as package " + callingPackage; |
| 2377 | Slog.w(TAG, msg); |
| 2378 | throw new SecurityException(msg); |
| 2379 | } |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2380 | if (!checkAppSwitchAllowedLocked(callingPid, callingUid, -1, -1, "Task to front")) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2381 | SafeActivityOptions.abort(options); |
| 2382 | return; |
| 2383 | } |
| 2384 | final long origId = Binder.clearCallingIdentity(); |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2385 | WindowProcessController callerApp = null; |
| 2386 | if (appThread != null) { |
| 2387 | callerApp = getProcessController(appThread); |
| 2388 | } |
| 2389 | final ActivityStarter starter = getActivityStartController().obtainStarter( |
| 2390 | null /* intent */, "moveTaskToFront"); |
| 2391 | if (starter.shouldAbortBackgroundActivityStart(callingUid, callingPid, callingPackage, -1, |
| 2392 | -1, callerApp, null, false, null)) { |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 2393 | if (!isBackgroundActivityStartsEnabled()) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2394 | return; |
| 2395 | } |
| 2396 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2397 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2398 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2399 | if (task == null) { |
| 2400 | Slog.d(TAG, "Could not find task for id: "+ taskId); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2401 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2402 | return; |
| 2403 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2404 | if (getLockTaskController().isLockTaskModeViolation(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2405 | Slog.e(TAG, "moveTaskToFront: Attempt to violate Lock Task Mode"); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2406 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2407 | return; |
| 2408 | } |
| 2409 | ActivityOptions realOptions = options != null |
| 2410 | ? options.getOptions(mStackSupervisor) |
| 2411 | : null; |
| 2412 | mStackSupervisor.findTaskToMoveToFront(task, flags, realOptions, "moveTaskToFront", |
| 2413 | false /* forceNonResizable */); |
| 2414 | |
| 2415 | final ActivityRecord topActivity = task.getTopActivity(); |
| 2416 | if (topActivity != null) { |
| 2417 | |
| 2418 | // We are reshowing a task, use a starting window to hide the initial draw delay |
| 2419 | // so the transition can start earlier. |
| 2420 | topActivity.showStartingWindow(null /* prev */, false /* newTask */, |
| 2421 | true /* taskSwitch */, fromRecents); |
| 2422 | } |
| 2423 | } finally { |
| 2424 | Binder.restoreCallingIdentity(origId); |
| 2425 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2426 | } |
| 2427 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2428 | /** |
| 2429 | * Return true if callingUid is system, or packageName belongs to that callingUid. |
| 2430 | */ |
Andrii Kulian | a8ccae4 | 2019-07-24 18:35:22 +0000 | [diff] [blame] | 2431 | boolean isSameApp(int callingUid, @Nullable String packageName) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2432 | try { |
| 2433 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 2434 | if (packageName == null) { |
| 2435 | return false; |
| 2436 | } |
| 2437 | final int uid = AppGlobals.getPackageManager().getPackageUid(packageName, |
| 2438 | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 2439 | UserHandle.getUserId(callingUid)); |
| 2440 | return UserHandle.isSameApp(callingUid, uid); |
| 2441 | } |
| 2442 | } catch (RemoteException e) { |
| 2443 | // Should not happen |
| 2444 | } |
| 2445 | return true; |
| 2446 | } |
| 2447 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2448 | boolean checkAppSwitchAllowedLocked(int sourcePid, int sourceUid, |
| 2449 | int callingPid, int callingUid, String name) { |
| 2450 | if (mAppSwitchesAllowedTime < SystemClock.uptimeMillis()) { |
| 2451 | return true; |
| 2452 | } |
| 2453 | |
| 2454 | if (getRecentTasks().isCallerRecents(sourceUid)) { |
| 2455 | return true; |
| 2456 | } |
| 2457 | |
| 2458 | int perm = checkComponentPermission(STOP_APP_SWITCHES, sourcePid, sourceUid, -1, true); |
| 2459 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2460 | return true; |
| 2461 | } |
| 2462 | if (checkAllowAppSwitchUid(sourceUid)) { |
| 2463 | return true; |
| 2464 | } |
| 2465 | |
| 2466 | // If the actual IPC caller is different from the logical source, then |
| 2467 | // also see if they are allowed to control app switches. |
| 2468 | if (callingUid != -1 && callingUid != sourceUid) { |
| 2469 | perm = checkComponentPermission(STOP_APP_SWITCHES, callingPid, callingUid, -1, true); |
| 2470 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2471 | return true; |
| 2472 | } |
| 2473 | if (checkAllowAppSwitchUid(callingUid)) { |
| 2474 | return true; |
| 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | Slog.w(TAG, name + " request from " + sourceUid + " stopped"); |
| 2479 | return false; |
| 2480 | } |
| 2481 | |
| 2482 | private boolean checkAllowAppSwitchUid(int uid) { |
| 2483 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(UserHandle.getUserId(uid)); |
| 2484 | if (types != null) { |
| 2485 | for (int i = types.size() - 1; i >= 0; i--) { |
| 2486 | if (types.valueAt(i).intValue() == uid) { |
| 2487 | return true; |
| 2488 | } |
| 2489 | } |
| 2490 | } |
| 2491 | return false; |
| 2492 | } |
| 2493 | |
| 2494 | @Override |
| 2495 | public void setActivityController(IActivityController controller, boolean imAMonkey) { |
| 2496 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER, |
| 2497 | "setActivityController()"); |
| 2498 | synchronized (mGlobalLock) { |
| 2499 | mController = controller; |
| 2500 | mControllerIsAMonkey = imAMonkey; |
| 2501 | Watchdog.getInstance().setActivityController(controller); |
| 2502 | } |
| 2503 | } |
| 2504 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 2505 | public boolean isControllerAMonkey() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2506 | synchronized (mGlobalLock) { |
| 2507 | return mController != null && mControllerIsAMonkey; |
| 2508 | } |
| 2509 | } |
| 2510 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2511 | @Override |
| 2512 | public int getTaskForActivity(IBinder token, boolean onlyRoot) { |
| 2513 | synchronized (mGlobalLock) { |
| 2514 | return ActivityRecord.getTaskForActivityLocked(token, onlyRoot); |
| 2515 | } |
| 2516 | } |
| 2517 | |
| 2518 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2519 | public List<ActivityManager.RunningTaskInfo> getTasks(int maxNum) { |
| 2520 | return getFilteredTasks(maxNum, ACTIVITY_TYPE_UNDEFINED, WINDOWING_MODE_UNDEFINED); |
| 2521 | } |
| 2522 | |
| 2523 | @Override |
| 2524 | public List<ActivityManager.RunningTaskInfo> getFilteredTasks(int maxNum, |
| 2525 | @WindowConfiguration.ActivityType int ignoreActivityType, |
| 2526 | @WindowConfiguration.WindowingMode int ignoreWindowingMode) { |
| 2527 | final int callingUid = Binder.getCallingUid(); |
Nicholas Sauer | f307365 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 2528 | final int callingPid = Binder.getCallingPid(); |
| 2529 | final boolean crossUser = isCrossUserAllowed(callingPid, callingUid); |
Nicholas Sauer | d6b4452 | 2019-09-10 20:23:41 -0700 | [diff] [blame] | 2530 | final int[] profileIds = getUserManager().getProfileIds( |
| 2531 | UserHandle.getUserId(callingUid), true); |
| 2532 | ArraySet<Integer> callingProfileIds = new ArraySet<>(); |
| 2533 | for (int i = 0; i < profileIds.length; i++) { |
| 2534 | callingProfileIds.add(profileIds[i]); |
| 2535 | } |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2536 | ArrayList<ActivityManager.RunningTaskInfo> list = new ArrayList<>(); |
| 2537 | |
| 2538 | synchronized (mGlobalLock) { |
| 2539 | if (DEBUG_ALL) Slog.v(TAG, "getTasks: max=" + maxNum); |
| 2540 | |
Nicholas Sauer | f307365 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 2541 | final boolean allowed = isGetTasksAllowed("getTasks", callingPid, callingUid); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2542 | mRootActivityContainer.getRunningTasks(maxNum, list, ignoreActivityType, |
Nicholas Sauer | d6b4452 | 2019-09-10 20:23:41 -0700 | [diff] [blame] | 2543 | ignoreWindowingMode, callingUid, allowed, crossUser, callingProfileIds); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | return list; |
| 2547 | } |
| 2548 | |
| 2549 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2550 | public final void finishSubActivity(IBinder token, String resultWho, int requestCode) { |
| 2551 | synchronized (mGlobalLock) { |
| 2552 | final long origId = Binder.clearCallingIdentity(); |
| 2553 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2554 | if (r != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2555 | r.getActivityStack().finishSubActivityLocked(r, resultWho, requestCode); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2556 | } |
| 2557 | Binder.restoreCallingIdentity(origId); |
| 2558 | } |
| 2559 | } |
| 2560 | |
| 2561 | @Override |
| 2562 | public boolean willActivityBeVisible(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2563 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2564 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 2565 | if (stack != null) { |
| 2566 | return stack.willActivityBeVisibleLocked(token); |
| 2567 | } |
| 2568 | return false; |
| 2569 | } |
| 2570 | } |
| 2571 | |
| 2572 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2573 | public void moveTaskToStack(int taskId, int stackId, boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2574 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "moveTaskToStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2575 | synchronized (mGlobalLock) { |
| 2576 | final long ident = Binder.clearCallingIdentity(); |
| 2577 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2578 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2579 | if (task == null) { |
| 2580 | Slog.w(TAG, "moveTaskToStack: No task for id=" + taskId); |
| 2581 | return; |
| 2582 | } |
| 2583 | |
| 2584 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToStack: moving task=" + taskId |
| 2585 | + " to stackId=" + stackId + " toTop=" + toTop); |
| 2586 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2587 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2588 | if (stack == null) { |
| 2589 | throw new IllegalStateException( |
| 2590 | "moveTaskToStack: No stack for stackId=" + stackId); |
| 2591 | } |
| 2592 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 2593 | throw new IllegalArgumentException("moveTaskToStack: Attempt to move task " |
| 2594 | + taskId + " to stack " + stackId); |
| 2595 | } |
| 2596 | if (stack.inSplitScreenPrimaryWindowingMode()) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2597 | mWindowManager.setDockedStackCreateState( |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2598 | SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */); |
| 2599 | } |
| 2600 | task.reparent(stack, toTop, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME, |
| 2601 | "moveTaskToStack"); |
| 2602 | } finally { |
| 2603 | Binder.restoreCallingIdentity(ident); |
| 2604 | } |
| 2605 | } |
| 2606 | } |
| 2607 | |
| 2608 | @Override |
| 2609 | public void resizeStack(int stackId, Rect destBounds, boolean allowResizeInDockedMode, |
| 2610 | boolean preserveWindows, boolean animate, int animationDuration) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2611 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2612 | |
| 2613 | final long ident = Binder.clearCallingIdentity(); |
| 2614 | try { |
| 2615 | synchronized (mGlobalLock) { |
| 2616 | if (animate) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 2617 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2618 | if (stack == null) { |
| 2619 | Slog.w(TAG, "resizeStack: stackId " + stackId + " not found."); |
| 2620 | return; |
| 2621 | } |
| 2622 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 2623 | throw new IllegalArgumentException("Stack: " + stackId |
| 2624 | + " doesn't support animated resize."); |
| 2625 | } |
| 2626 | stack.animateResizePinnedStack(null /* sourceHintBounds */, destBounds, |
| 2627 | animationDuration, false /* fromFullscreen */); |
| 2628 | } else { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2629 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2630 | if (stack == null) { |
| 2631 | Slog.w(TAG, "resizeStack: stackId " + stackId + " not found."); |
| 2632 | return; |
| 2633 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2634 | mRootActivityContainer.resizeStack(stack, destBounds, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2635 | null /* tempTaskBounds */, null /* tempTaskInsetBounds */, |
| 2636 | preserveWindows, allowResizeInDockedMode, !DEFER_RESUME); |
| 2637 | } |
| 2638 | } |
| 2639 | } finally { |
| 2640 | Binder.restoreCallingIdentity(ident); |
| 2641 | } |
| 2642 | } |
| 2643 | |
wilsonshih | 5c4cf52 | 2019-01-25 09:03:47 +0800 | [diff] [blame] | 2644 | @Override |
| 2645 | public void offsetPinnedStackBounds(int stackId, Rect compareBounds, int xOffset, int yOffset, |
| 2646 | int animationDuration) { |
| 2647 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "offsetPinnedStackBounds()"); |
| 2648 | |
| 2649 | final long ident = Binder.clearCallingIdentity(); |
| 2650 | try { |
| 2651 | synchronized (mGlobalLock) { |
| 2652 | if (xOffset == 0 && yOffset == 0) { |
| 2653 | return; |
| 2654 | } |
| 2655 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
| 2656 | if (stack == null) { |
| 2657 | Slog.w(TAG, "offsetPinnedStackBounds: stackId " + stackId + " not found."); |
| 2658 | return; |
| 2659 | } |
| 2660 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 2661 | throw new IllegalArgumentException("Stack: " + stackId |
| 2662 | + " doesn't support animated resize."); |
| 2663 | } |
| 2664 | final Rect destBounds = new Rect(); |
| 2665 | stack.getAnimationOrCurrentBounds(destBounds); |
wilsonshih | a6e408c | 2019-02-19 17:30:03 +0800 | [diff] [blame] | 2666 | if (destBounds.isEmpty() || !destBounds.equals(compareBounds)) { |
wilsonshih | 5c4cf52 | 2019-01-25 09:03:47 +0800 | [diff] [blame] | 2667 | Slog.w(TAG, "The current stack bounds does not matched! It may be obsolete."); |
| 2668 | return; |
| 2669 | } |
| 2670 | destBounds.offset(xOffset, yOffset); |
| 2671 | stack.animateResizePinnedStack(null /* sourceHintBounds */, destBounds, |
| 2672 | animationDuration, false /* fromFullscreen */); |
| 2673 | } |
| 2674 | } finally { |
| 2675 | Binder.restoreCallingIdentity(ident); |
| 2676 | } |
| 2677 | } |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2678 | /** |
| 2679 | * Moves the specified task to the primary-split-screen stack. |
| 2680 | * |
| 2681 | * @param taskId Id of task to move. |
| 2682 | * @param createMode The mode the primary split screen stack should be created in if it doesn't |
| 2683 | * exist already. See |
| 2684 | * {@link android.app.ActivityTaskManager#SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT} |
| 2685 | * and |
| 2686 | * {@link android.app.ActivityTaskManager#SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT} |
| 2687 | * @param toTop If the task and stack should be moved to the top. |
| 2688 | * @param animate Whether we should play an animation for the moving the task. |
| 2689 | * @param initialBounds If the primary stack gets created, it will use these bounds for the |
| 2690 | * stack. Pass {@code null} to use default bounds. |
| 2691 | * @param showRecents If the recents activity should be shown on the other side of the task |
| 2692 | * going into split-screen mode. |
| 2693 | */ |
| 2694 | @Override |
| 2695 | public boolean setTaskWindowingModeSplitScreenPrimary(int taskId, int createMode, |
| 2696 | boolean toTop, boolean animate, Rect initialBounds, boolean showRecents) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2697 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2698 | "setTaskWindowingModeSplitScreenPrimary()"); |
| 2699 | synchronized (mGlobalLock) { |
| 2700 | final long ident = Binder.clearCallingIdentity(); |
| 2701 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2702 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2703 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2704 | if (task == null) { |
| 2705 | Slog.w(TAG, "setTaskWindowingModeSplitScreenPrimary: No task for id=" + taskId); |
| 2706 | return false; |
| 2707 | } |
| 2708 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
| 2709 | "setTaskWindowingModeSplitScreenPrimary: moving task=" + taskId |
| 2710 | + " to createMode=" + createMode + " toTop=" + toTop); |
| 2711 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2712 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2713 | + " non-standard task " + taskId + " to split-screen windowing mode"); |
| 2714 | } |
| 2715 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2716 | mWindowManager.setDockedStackCreateState(createMode, initialBounds); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2717 | final int windowingMode = task.getWindowingMode(); |
| 2718 | final ActivityStack stack = task.getStack(); |
| 2719 | if (toTop) { |
| 2720 | stack.moveToFront("setTaskWindowingModeSplitScreenPrimary", task); |
| 2721 | } |
| 2722 | stack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, animate, showRecents, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 2723 | false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */, |
| 2724 | false /* creating */); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2725 | return windowingMode != task.getWindowingMode(); |
| 2726 | } finally { |
| 2727 | Binder.restoreCallingIdentity(ident); |
| 2728 | } |
| 2729 | } |
| 2730 | } |
| 2731 | |
| 2732 | /** |
| 2733 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 2734 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 2735 | */ |
| 2736 | @Override |
| 2737 | public void removeStacksInWindowingModes(int[] windowingModes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2738 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2739 | "removeStacksInWindowingModes()"); |
| 2740 | |
| 2741 | synchronized (mGlobalLock) { |
| 2742 | final long ident = Binder.clearCallingIdentity(); |
| 2743 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2744 | mRootActivityContainer.removeStacksInWindowingModes(windowingModes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2745 | } finally { |
| 2746 | Binder.restoreCallingIdentity(ident); |
| 2747 | } |
| 2748 | } |
| 2749 | } |
| 2750 | |
| 2751 | @Override |
| 2752 | public void removeStacksWithActivityTypes(int[] activityTypes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2753 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2754 | "removeStacksWithActivityTypes()"); |
| 2755 | |
| 2756 | synchronized (mGlobalLock) { |
| 2757 | final long ident = Binder.clearCallingIdentity(); |
| 2758 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2759 | mRootActivityContainer.removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2760 | } finally { |
| 2761 | Binder.restoreCallingIdentity(ident); |
| 2762 | } |
| 2763 | } |
| 2764 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2765 | |
| 2766 | @Override |
| 2767 | public ParceledListSlice<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, |
| 2768 | int userId) { |
| 2769 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2770 | userId = handleIncomingUser(Binder.getCallingPid(), callingUid, userId, "getRecentTasks"); |
| 2771 | final boolean allowed = isGetTasksAllowed("getRecentTasks", Binder.getCallingPid(), |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2772 | callingUid); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2773 | final boolean detailed = checkGetTasksPermission( |
| 2774 | android.Manifest.permission.GET_DETAILED_TASKS, Binder.getCallingPid(), |
| 2775 | UserHandle.getAppId(callingUid)) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2776 | == PackageManager.PERMISSION_GRANTED; |
| 2777 | |
| 2778 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 2779 | return mRecentTasks.getRecentTasks(maxNum, flags, allowed, detailed, userId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2780 | callingUid); |
| 2781 | } |
| 2782 | } |
| 2783 | |
| 2784 | @Override |
| 2785 | public List<ActivityManager.StackInfo> getAllStackInfos() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2786 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2787 | long ident = Binder.clearCallingIdentity(); |
| 2788 | try { |
| 2789 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2790 | return mRootActivityContainer.getAllStackInfos(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2791 | } |
| 2792 | } finally { |
| 2793 | Binder.restoreCallingIdentity(ident); |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | @Override |
| 2798 | public ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2799 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2800 | long ident = Binder.clearCallingIdentity(); |
| 2801 | try { |
| 2802 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2803 | return mRootActivityContainer.getStackInfo(windowingMode, activityType); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2804 | } |
| 2805 | } finally { |
| 2806 | Binder.restoreCallingIdentity(ident); |
| 2807 | } |
| 2808 | } |
| 2809 | |
| 2810 | @Override |
| 2811 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2812 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "cancelRecentsAnimation()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2813 | final long callingUid = Binder.getCallingUid(); |
| 2814 | final long origId = Binder.clearCallingIdentity(); |
| 2815 | try { |
| 2816 | synchronized (mGlobalLock) { |
| 2817 | // Cancel the recents animation synchronously (do not hold the WM lock) |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2818 | mWindowManager.cancelRecentsAnimationSynchronously(restoreHomeStackPosition |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2819 | ? REORDER_MOVE_TO_ORIGINAL_POSITION |
| 2820 | : REORDER_KEEP_IN_PLACE, "cancelRecentsAnimation/uid=" + callingUid); |
| 2821 | } |
| 2822 | } finally { |
| 2823 | Binder.restoreCallingIdentity(origId); |
| 2824 | } |
| 2825 | } |
| 2826 | |
| 2827 | @Override |
| 2828 | public void startLockTaskModeByToken(IBinder token) { |
| 2829 | synchronized (mGlobalLock) { |
| 2830 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2831 | if (r == null) { |
| 2832 | return; |
| 2833 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2834 | startLockTaskModeLocked(r.getTaskRecord(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2835 | } |
| 2836 | } |
| 2837 | |
| 2838 | @Override |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2839 | public void startSystemLockTaskMode(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2840 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "startSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2841 | // This makes inner call to look as if it was initiated by system. |
| 2842 | long ident = Binder.clearCallingIdentity(); |
| 2843 | try { |
| 2844 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2845 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2846 | MATCH_TASK_IN_STACKS_ONLY); |
| 2847 | if (task == null) { |
| 2848 | return; |
| 2849 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2850 | |
| 2851 | // When starting lock task mode the stack must be in front and focused |
| 2852 | task.getStack().moveToFront("startSystemLockTaskMode"); |
| 2853 | startLockTaskModeLocked(task, true /* isSystemCaller */); |
| 2854 | } |
| 2855 | } finally { |
| 2856 | Binder.restoreCallingIdentity(ident); |
| 2857 | } |
| 2858 | } |
| 2859 | |
| 2860 | @Override |
| 2861 | public void stopLockTaskModeByToken(IBinder token) { |
| 2862 | synchronized (mGlobalLock) { |
| 2863 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2864 | if (r == null) { |
| 2865 | return; |
| 2866 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2867 | stopLockTaskModeInternal(r.getTaskRecord(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2868 | } |
| 2869 | } |
| 2870 | |
| 2871 | /** |
| 2872 | * This API should be called by SystemUI only when user perform certain action to dismiss |
| 2873 | * lock task mode. We should only dismiss pinned lock task mode in this case. |
| 2874 | */ |
| 2875 | @Override |
| 2876 | public void stopSystemLockTaskMode() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2877 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "stopSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2878 | stopLockTaskModeInternal(null, true /* isSystemCaller */); |
| 2879 | } |
| 2880 | |
| 2881 | private void startLockTaskModeLocked(@Nullable TaskRecord task, boolean isSystemCaller) { |
| 2882 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "startLockTaskModeLocked: " + task); |
| 2883 | if (task == null || task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) { |
| 2884 | return; |
| 2885 | } |
| 2886 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2887 | final ActivityStack stack = mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2888 | if (stack == null || task != stack.topTask()) { |
| 2889 | throw new IllegalArgumentException("Invalid task, not in foreground"); |
| 2890 | } |
| 2891 | |
| 2892 | // {@code isSystemCaller} is used to distinguish whether this request is initiated by the |
| 2893 | // system or a specific app. |
| 2894 | // * System-initiated requests will only start the pinned mode (screen pinning) |
| 2895 | // * App-initiated requests |
| 2896 | // - will put the device in fully locked mode (LockTask), if the app is whitelisted |
| 2897 | // - will start the pinned mode, otherwise |
| 2898 | final int callingUid = Binder.getCallingUid(); |
| 2899 | long ident = Binder.clearCallingIdentity(); |
| 2900 | try { |
| 2901 | // When a task is locked, dismiss the pinned stack if it exists |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2902 | mRootActivityContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2903 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2904 | getLockTaskController().startLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2905 | } finally { |
| 2906 | Binder.restoreCallingIdentity(ident); |
| 2907 | } |
| 2908 | } |
| 2909 | |
| 2910 | private void stopLockTaskModeInternal(@Nullable TaskRecord task, boolean isSystemCaller) { |
| 2911 | final int callingUid = Binder.getCallingUid(); |
| 2912 | long ident = Binder.clearCallingIdentity(); |
| 2913 | try { |
| 2914 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2915 | getLockTaskController().stopLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2916 | } |
| 2917 | // Launch in-call UI if a call is ongoing. This is necessary to allow stopping the lock |
| 2918 | // task and jumping straight into a call in the case of emergency call back. |
| 2919 | TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
| 2920 | if (tm != null) { |
| 2921 | tm.showInCallScreen(false); |
| 2922 | } |
| 2923 | } finally { |
| 2924 | Binder.restoreCallingIdentity(ident); |
| 2925 | } |
| 2926 | } |
| 2927 | |
| 2928 | @Override |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 2929 | public void updateLockTaskPackages(int userId, String[] packages) { |
| 2930 | final int callingUid = Binder.getCallingUid(); |
| 2931 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 2932 | mAmInternal.enforceCallingPermission(Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
| 2933 | "updateLockTaskPackages()"); |
| 2934 | } |
| 2935 | synchronized (this) { |
| 2936 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Whitelisting " + userId + ":" |
| 2937 | + Arrays.toString(packages)); |
| 2938 | getLockTaskController().updateLockTaskPackages(userId, packages); |
| 2939 | } |
| 2940 | } |
| 2941 | |
| 2942 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2943 | public boolean isInLockTaskMode() { |
| 2944 | return getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
| 2945 | } |
| 2946 | |
| 2947 | @Override |
| 2948 | public int getLockTaskModeState() { |
| 2949 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2950 | return getLockTaskController().getLockTaskModeState(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2951 | } |
| 2952 | } |
| 2953 | |
| 2954 | @Override |
| 2955 | public void setTaskDescription(IBinder token, ActivityManager.TaskDescription td) { |
| 2956 | synchronized (mGlobalLock) { |
| 2957 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2958 | if (r != null) { |
| 2959 | r.setTaskDescription(td); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2960 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2961 | task.updateTaskDescription(); |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 2962 | mTaskChangeNotificationController.notifyTaskDescriptionChanged(task.getTaskInfo()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2963 | } |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | @Override |
| 2968 | public Bundle getActivityOptions(IBinder token) { |
| 2969 | final long origId = Binder.clearCallingIdentity(); |
| 2970 | try { |
| 2971 | synchronized (mGlobalLock) { |
| 2972 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2973 | if (r != null) { |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 2974 | final ActivityOptions activityOptions = r.takeOptionsLocked( |
| 2975 | true /* fromClient */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2976 | return activityOptions == null ? null : activityOptions.toBundle(); |
| 2977 | } |
| 2978 | return null; |
| 2979 | } |
| 2980 | } finally { |
| 2981 | Binder.restoreCallingIdentity(origId); |
| 2982 | } |
| 2983 | } |
| 2984 | |
| 2985 | @Override |
| 2986 | public List<IBinder> getAppTasks(String callingPackage) { |
| 2987 | int callingUid = Binder.getCallingUid(); |
| 2988 | long ident = Binder.clearCallingIdentity(); |
| 2989 | try { |
| 2990 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 2991 | return mRecentTasks.getAppTasksList(callingUid, callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2992 | } |
| 2993 | } finally { |
| 2994 | Binder.restoreCallingIdentity(ident); |
| 2995 | } |
| 2996 | } |
| 2997 | |
| 2998 | @Override |
| 2999 | public void finishVoiceTask(IVoiceInteractionSession session) { |
| 3000 | synchronized (mGlobalLock) { |
| 3001 | final long origId = Binder.clearCallingIdentity(); |
| 3002 | try { |
| 3003 | // TODO: VI Consider treating local voice interactions and voice tasks |
| 3004 | // differently here |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3005 | mRootActivityContainer.finishVoiceTask(session); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3006 | } finally { |
| 3007 | Binder.restoreCallingIdentity(origId); |
| 3008 | } |
| 3009 | } |
| 3010 | |
| 3011 | } |
| 3012 | |
| 3013 | @Override |
| 3014 | public boolean isTopOfTask(IBinder token) { |
| 3015 | synchronized (mGlobalLock) { |
| 3016 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3017 | return r != null && r.getTaskRecord().getTopActivity() == r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3018 | } |
| 3019 | } |
| 3020 | |
| 3021 | @Override |
| 3022 | public void notifyLaunchTaskBehindComplete(IBinder token) { |
| 3023 | mStackSupervisor.scheduleLaunchTaskBehindComplete(token); |
| 3024 | } |
| 3025 | |
| 3026 | @Override |
| 3027 | public void notifyEnterAnimationComplete(IBinder token) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3028 | mH.post(() -> { |
| 3029 | synchronized (mGlobalLock) { |
| 3030 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3031 | if (r != null && r.attachedToProcess()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3032 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3033 | r.app.getThread().scheduleEnterAnimationComplete(r.appToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3034 | } catch (RemoteException e) { |
| 3035 | } |
| 3036 | } |
| 3037 | } |
| 3038 | |
| 3039 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | /** Called from an app when assist data is ready. */ |
| 3043 | @Override |
| 3044 | public void reportAssistContextExtras(IBinder token, Bundle extras, AssistStructure structure, |
| 3045 | AssistContent content, Uri referrer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3046 | PendingAssistExtras pae = (PendingAssistExtras) token; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3047 | synchronized (pae) { |
| 3048 | pae.result = extras; |
| 3049 | pae.structure = structure; |
| 3050 | pae.content = content; |
| 3051 | if (referrer != null) { |
| 3052 | pae.extras.putParcelable(Intent.EXTRA_REFERRER, referrer); |
| 3053 | } |
| 3054 | if (structure != null) { |
Winson Chung | 48b2565 | 2018-10-22 14:04:30 -0700 | [diff] [blame] | 3055 | // Pre-fill the task/activity component for all assist data receivers |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3056 | structure.setTaskId(pae.activity.getTaskRecord().taskId); |
| 3057 | structure.setActivityComponent(pae.activity.mActivityComponent); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3058 | structure.setHomeActivity(pae.isHome); |
| 3059 | } |
| 3060 | pae.haveResult = true; |
| 3061 | pae.notifyAll(); |
| 3062 | if (pae.intent == null && pae.receiver == null) { |
| 3063 | // Caller is just waiting for the result. |
| 3064 | return; |
| 3065 | } |
| 3066 | } |
| 3067 | // We are now ready to launch the assist activity. |
| 3068 | IAssistDataReceiver sendReceiver = null; |
| 3069 | Bundle sendBundle = null; |
| 3070 | synchronized (mGlobalLock) { |
| 3071 | buildAssistBundleLocked(pae, extras); |
| 3072 | boolean exists = mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3073 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3074 | if (!exists) { |
| 3075 | // Timed out. |
| 3076 | return; |
| 3077 | } |
| 3078 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3079 | if ((sendReceiver = pae.receiver) != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3080 | // Caller wants result sent back to them. |
| 3081 | sendBundle = new Bundle(); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3082 | sendBundle.putInt(ActivityTaskManagerInternal.ASSIST_TASK_ID, |
| 3083 | pae.activity.getTaskRecord().taskId); |
| 3084 | sendBundle.putBinder(ActivityTaskManagerInternal.ASSIST_ACTIVITY_ID, |
| 3085 | pae.activity.assistToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3086 | sendBundle.putBundle(ASSIST_KEY_DATA, pae.extras); |
| 3087 | sendBundle.putParcelable(ASSIST_KEY_STRUCTURE, pae.structure); |
| 3088 | sendBundle.putParcelable(ASSIST_KEY_CONTENT, pae.content); |
| 3089 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3090 | } |
| 3091 | } |
| 3092 | if (sendReceiver != null) { |
| 3093 | try { |
| 3094 | sendReceiver.onHandleAssistData(sendBundle); |
| 3095 | } catch (RemoteException e) { |
| 3096 | } |
| 3097 | return; |
| 3098 | } |
| 3099 | |
| 3100 | final long ident = Binder.clearCallingIdentity(); |
| 3101 | try { |
| 3102 | if (TextUtils.equals(pae.intent.getAction(), |
| 3103 | android.service.voice.VoiceInteractionService.SERVICE_INTERFACE)) { |
| 3104 | pae.intent.putExtras(pae.extras); |
Marvin Ramin | 830d4e3 | 2019-03-12 13:16:58 +0100 | [diff] [blame] | 3105 | |
| 3106 | startVoiceInteractionServiceAsUser(pae.intent, pae.userHandle, "AssistContext"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3107 | } else { |
| 3108 | pae.intent.replaceExtras(pae.extras); |
| 3109 | pae.intent.setFlags(FLAG_ACTIVITY_NEW_TASK |
| 3110 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 3111 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 3112 | mInternal.closeSystemDialogs("assist"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3113 | |
| 3114 | try { |
| 3115 | mContext.startActivityAsUser(pae.intent, new UserHandle(pae.userHandle)); |
| 3116 | } catch (ActivityNotFoundException e) { |
| 3117 | Slog.w(TAG, "No activity to handle assist action.", e); |
| 3118 | } |
| 3119 | } |
| 3120 | } finally { |
| 3121 | Binder.restoreCallingIdentity(ident); |
| 3122 | } |
| 3123 | } |
| 3124 | |
Marvin Ramin | 830d4e3 | 2019-03-12 13:16:58 +0100 | [diff] [blame] | 3125 | /** |
| 3126 | * Workaround for historical API which starts the Assist service with a non-foreground |
| 3127 | * {@code startService()} call. |
| 3128 | */ |
| 3129 | private void startVoiceInteractionServiceAsUser( |
| 3130 | Intent intent, int userHandle, String reason) { |
| 3131 | // Resolve the intent to find out which package we need to whitelist. |
| 3132 | ResolveInfo resolveInfo = |
| 3133 | mContext.getPackageManager().resolveServiceAsUser(intent, 0, userHandle); |
| 3134 | if (resolveInfo == null || resolveInfo.serviceInfo == null) { |
| 3135 | Slog.e(TAG, "VoiceInteractionService intent does not resolve. Not starting."); |
| 3136 | return; |
| 3137 | } |
| 3138 | intent.setPackage(resolveInfo.serviceInfo.packageName); |
| 3139 | |
| 3140 | // Whitelist background services temporarily. |
| 3141 | LocalServices.getService(DeviceIdleController.LocalService.class) |
| 3142 | .addPowerSaveTempWhitelistApp(Process.myUid(), intent.getPackage(), |
| 3143 | SERVICE_LAUNCH_IDLE_WHITELIST_DURATION_MS, userHandle, false, reason); |
| 3144 | |
| 3145 | // Finally, try to start the service. |
| 3146 | try { |
| 3147 | mContext.startServiceAsUser(intent, UserHandle.of(userHandle)); |
| 3148 | } catch (RuntimeException e) { |
| 3149 | Slog.e(TAG, "VoiceInteractionService failed to start.", e); |
| 3150 | } |
| 3151 | } |
| 3152 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3153 | @Override |
| 3154 | public int addAppTask(IBinder activityToken, Intent intent, |
| 3155 | ActivityManager.TaskDescription description, Bitmap thumbnail) throws RemoteException { |
| 3156 | final int callingUid = Binder.getCallingUid(); |
| 3157 | final long callingIdent = Binder.clearCallingIdentity(); |
| 3158 | |
| 3159 | try { |
| 3160 | synchronized (mGlobalLock) { |
| 3161 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 3162 | if (r == null) { |
| 3163 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 3164 | + activityToken); |
| 3165 | } |
| 3166 | ComponentName comp = intent.getComponent(); |
| 3167 | if (comp == null) { |
| 3168 | throw new IllegalArgumentException("Intent " + intent |
| 3169 | + " must specify explicit component"); |
| 3170 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3171 | if (thumbnail.getWidth() != mThumbnailWidth |
| 3172 | || thumbnail.getHeight() != mThumbnailHeight) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3173 | throw new IllegalArgumentException("Bad thumbnail size: got " |
| 3174 | + thumbnail.getWidth() + "x" + thumbnail.getHeight() + ", require " |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3175 | + mThumbnailWidth + "x" + mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3176 | } |
| 3177 | if (intent.getSelector() != null) { |
| 3178 | intent.setSelector(null); |
| 3179 | } |
| 3180 | if (intent.getSourceBounds() != null) { |
| 3181 | intent.setSourceBounds(null); |
| 3182 | } |
| 3183 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) { |
| 3184 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) == 0) { |
| 3185 | // The caller has added this as an auto-remove task... that makes no |
| 3186 | // sense, so turn off auto-remove. |
| 3187 | intent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS); |
| 3188 | } |
| 3189 | } |
| 3190 | final ActivityInfo ainfo = AppGlobals.getPackageManager().getActivityInfo(comp, |
| 3191 | STOCK_PM_FLAGS, UserHandle.getUserId(callingUid)); |
| 3192 | if (ainfo.applicationInfo.uid != callingUid) { |
| 3193 | throw new SecurityException( |
| 3194 | "Can't add task for another application: target uid=" |
| 3195 | + ainfo.applicationInfo.uid + ", calling uid=" + callingUid); |
| 3196 | } |
| 3197 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3198 | final ActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3199 | final TaskRecord task = stack.createTaskRecord( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3200 | mStackSupervisor.getNextTaskIdForUserLocked(r.mUserId), ainfo, intent, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3201 | null /* voiceSession */, null /* voiceInteractor */, !ON_TOP); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3202 | if (!mRecentTasks.addToBottom(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3203 | // The app has too many tasks already and we can't add any more |
| 3204 | stack.removeTask(task, "addAppTask", REMOVE_TASK_MODE_DESTROYING); |
| 3205 | return INVALID_TASK_ID; |
| 3206 | } |
| 3207 | task.lastTaskDescription.copyFrom(description); |
| 3208 | |
| 3209 | // TODO: Send the thumbnail to WM to store it. |
| 3210 | |
| 3211 | return task.taskId; |
| 3212 | } |
| 3213 | } finally { |
| 3214 | Binder.restoreCallingIdentity(callingIdent); |
| 3215 | } |
| 3216 | } |
| 3217 | |
| 3218 | @Override |
| 3219 | public Point getAppTaskThumbnailSize() { |
| 3220 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3221 | return new Point(mThumbnailWidth, mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3222 | } |
| 3223 | } |
| 3224 | |
| 3225 | @Override |
| 3226 | public void setTaskResizeable(int taskId, int resizeableMode) { |
| 3227 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3228 | final TaskRecord task = mRootActivityContainer.anyTaskForId( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3229 | taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 3230 | if (task == null) { |
| 3231 | Slog.w(TAG, "setTaskResizeable: taskId=" + taskId + " not found"); |
| 3232 | return; |
| 3233 | } |
| 3234 | task.setResizeMode(resizeableMode); |
| 3235 | } |
| 3236 | } |
| 3237 | |
| 3238 | @Override |
| 3239 | public void resizeTask(int taskId, Rect bounds, int resizeMode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3240 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "resizeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3241 | long ident = Binder.clearCallingIdentity(); |
| 3242 | try { |
| 3243 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3244 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 3245 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3246 | if (task == null) { |
| 3247 | Slog.w(TAG, "resizeTask: taskId=" + taskId + " not found"); |
| 3248 | return; |
| 3249 | } |
| 3250 | // Place the task in the right stack if it isn't there already based on |
| 3251 | // the requested bounds. |
| 3252 | // The stack transition logic is: |
| 3253 | // - a null bounds on a freeform task moves that task to fullscreen |
| 3254 | // - a non-null bounds on a non-freeform (fullscreen OR docked) task moves |
| 3255 | // that task to freeform |
| 3256 | // - otherwise the task is not moved |
| 3257 | ActivityStack stack = task.getStack(); |
| 3258 | if (!task.getWindowConfiguration().canResizeTask()) { |
| 3259 | throw new IllegalArgumentException("resizeTask not allowed on task=" + task); |
| 3260 | } |
| 3261 | if (bounds == null && stack.getWindowingMode() == WINDOWING_MODE_FREEFORM) { |
| 3262 | stack = stack.getDisplay().getOrCreateStack( |
| 3263 | WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), ON_TOP); |
| 3264 | } else if (bounds != null && stack.getWindowingMode() != WINDOWING_MODE_FREEFORM) { |
| 3265 | stack = stack.getDisplay().getOrCreateStack( |
| 3266 | WINDOWING_MODE_FREEFORM, stack.getActivityType(), ON_TOP); |
| 3267 | } |
| 3268 | |
| 3269 | // Reparent the task to the right stack if necessary |
| 3270 | boolean preserveWindow = (resizeMode & RESIZE_MODE_PRESERVE_WINDOW) != 0; |
| 3271 | if (stack != task.getStack()) { |
| 3272 | // Defer resume until the task is resized below |
| 3273 | task.reparent(stack, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, |
| 3274 | DEFER_RESUME, "resizeTask"); |
| 3275 | preserveWindow = false; |
| 3276 | } |
| 3277 | |
| 3278 | // After reparenting (which only resizes the task to the stack bounds), resize the |
| 3279 | // task to the actual bounds provided |
| 3280 | task.resize(bounds, resizeMode, preserveWindow, !DEFER_RESUME); |
| 3281 | } |
| 3282 | } finally { |
| 3283 | Binder.restoreCallingIdentity(ident); |
| 3284 | } |
| 3285 | } |
| 3286 | |
| 3287 | @Override |
| 3288 | public boolean releaseActivityInstance(IBinder token) { |
| 3289 | synchronized (mGlobalLock) { |
| 3290 | final long origId = Binder.clearCallingIdentity(); |
| 3291 | try { |
| 3292 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3293 | if (r == null) { |
| 3294 | return false; |
| 3295 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3296 | return r.getActivityStack().safelyDestroyActivityLocked(r, "app-req"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3297 | } finally { |
| 3298 | Binder.restoreCallingIdentity(origId); |
| 3299 | } |
| 3300 | } |
| 3301 | } |
| 3302 | |
| 3303 | @Override |
| 3304 | public void releaseSomeActivities(IApplicationThread appInt) { |
| 3305 | synchronized (mGlobalLock) { |
| 3306 | final long origId = Binder.clearCallingIdentity(); |
| 3307 | try { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3308 | final WindowProcessController app = getProcessController(appInt); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3309 | mRootActivityContainer.releaseSomeActivitiesLocked(app, "low-mem"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3310 | } finally { |
| 3311 | Binder.restoreCallingIdentity(origId); |
| 3312 | } |
| 3313 | } |
| 3314 | } |
| 3315 | |
| 3316 | @Override |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 3317 | public void setLockScreenShown(boolean keyguardShowing, boolean aodShowing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3318 | if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3319 | != PackageManager.PERMISSION_GRANTED) { |
| 3320 | throw new SecurityException("Requires permission " |
| 3321 | + android.Manifest.permission.DEVICE_POWER); |
| 3322 | } |
| 3323 | |
| 3324 | synchronized (mGlobalLock) { |
| 3325 | long ident = Binder.clearCallingIdentity(); |
| 3326 | if (mKeyguardShown != keyguardShowing) { |
| 3327 | mKeyguardShown = keyguardShowing; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3328 | final Message msg = PooledLambda.obtainMessage( |
| 3329 | ActivityManagerInternal::reportCurKeyguardUsageEvent, mAmInternal, |
| 3330 | keyguardShowing); |
| 3331 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3332 | } |
| 3333 | try { |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 3334 | mKeyguardController.setKeyguardShown(keyguardShowing, aodShowing); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3335 | } finally { |
| 3336 | Binder.restoreCallingIdentity(ident); |
| 3337 | } |
| 3338 | } |
| 3339 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3340 | mH.post(() -> { |
| 3341 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3342 | mScreenObservers.get(i).onKeyguardStateChanged(keyguardShowing); |
| 3343 | } |
| 3344 | }); |
| 3345 | } |
| 3346 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 3347 | public void onScreenAwakeChanged(boolean isAwake) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3348 | mH.post(() -> { |
| 3349 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3350 | mScreenObservers.get(i).onAwakeStateChanged(isAwake); |
| 3351 | } |
| 3352 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3353 | } |
| 3354 | |
| 3355 | @Override |
| 3356 | public Bitmap getTaskDescriptionIcon(String filePath, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3357 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 3358 | userId, "getTaskDescriptionIcon"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3359 | |
| 3360 | final File passedIconFile = new File(filePath); |
| 3361 | final File legitIconFile = new File(TaskPersister.getUserImagesDir(userId), |
| 3362 | passedIconFile.getName()); |
| 3363 | if (!legitIconFile.getPath().equals(filePath) |
| 3364 | || !filePath.contains(ActivityRecord.ACTIVITY_ICON_SUFFIX)) { |
| 3365 | throw new IllegalArgumentException("Bad file path: " + filePath |
| 3366 | + " passed for userId " + userId); |
| 3367 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3368 | return mRecentTasks.getTaskDescriptionIcon(filePath); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
| 3371 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3372 | public void startInPlaceAnimationOnFrontMostApplication(Bundle opts) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3373 | final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(opts); |
| 3374 | final ActivityOptions activityOptions = safeOptions != null |
| 3375 | ? safeOptions.getOptions(mStackSupervisor) |
| 3376 | : null; |
| 3377 | if (activityOptions == null |
| 3378 | || activityOptions.getAnimationType() != ActivityOptions.ANIM_CUSTOM_IN_PLACE |
| 3379 | || activityOptions.getCustomInPlaceResId() == 0) { |
| 3380 | throw new IllegalArgumentException("Expected in-place ActivityOption " + |
| 3381 | "with valid animation"); |
| 3382 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3383 | // Get top display of front most application. |
| 3384 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
| 3385 | if (focusedStack != null) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3386 | final DisplayContent dc = focusedStack.getDisplay().mDisplayContent; |
| 3387 | dc.prepareAppTransition(TRANSIT_TASK_IN_PLACE, false); |
| 3388 | dc.mAppTransition.overrideInPlaceAppTransition(activityOptions.getPackageName(), |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3389 | activityOptions.getCustomInPlaceResId()); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3390 | dc.executeAppTransition(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3391 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | @Override |
| 3395 | public void removeStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3396 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "removeStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3397 | synchronized (mGlobalLock) { |
| 3398 | final long ident = Binder.clearCallingIdentity(); |
| 3399 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3400 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3401 | if (stack == null) { |
| 3402 | Slog.w(TAG, "removeStack: No stack with id=" + stackId); |
| 3403 | return; |
| 3404 | } |
| 3405 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3406 | throw new IllegalArgumentException( |
| 3407 | "Removing non-standard stack is not allowed."); |
| 3408 | } |
| 3409 | mStackSupervisor.removeStack(stack); |
| 3410 | } finally { |
| 3411 | Binder.restoreCallingIdentity(ident); |
| 3412 | } |
| 3413 | } |
| 3414 | } |
| 3415 | |
| 3416 | @Override |
| 3417 | public void moveStackToDisplay(int stackId, int displayId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3418 | mAmInternal.enforceCallingPermission(INTERNAL_SYSTEM_WINDOW, "moveStackToDisplay()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3419 | |
| 3420 | synchronized (mGlobalLock) { |
| 3421 | final long ident = Binder.clearCallingIdentity(); |
| 3422 | try { |
| 3423 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveStackToDisplay: moving stackId=" + stackId |
| 3424 | + " to displayId=" + displayId); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3425 | mRootActivityContainer.moveStackToDisplay(stackId, displayId, ON_TOP); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3426 | } finally { |
| 3427 | Binder.restoreCallingIdentity(ident); |
| 3428 | } |
| 3429 | } |
| 3430 | } |
| 3431 | |
| 3432 | @Override |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3433 | public void toggleFreeformWindowingMode(IBinder token) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3434 | synchronized (mGlobalLock) { |
| 3435 | long ident = Binder.clearCallingIdentity(); |
| 3436 | try { |
| 3437 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3438 | if (r == null) { |
| 3439 | throw new IllegalArgumentException( |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3440 | "toggleFreeformWindowingMode: No activity record matching token=" |
| 3441 | + token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3442 | } |
| 3443 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3444 | final ActivityStack stack = r.getActivityStack(); |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3445 | if (stack == null) { |
| 3446 | throw new IllegalStateException("toggleFreeformWindowingMode: the activity " |
| 3447 | + "doesn't have a stack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3448 | } |
| 3449 | |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3450 | if (!stack.inFreeformWindowingMode() |
| 3451 | && stack.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) { |
| 3452 | throw new IllegalStateException("toggleFreeformWindowingMode: You can only " |
| 3453 | + "toggle between fullscreen and freeform."); |
| 3454 | } |
| 3455 | |
| 3456 | if (stack.inFreeformWindowingMode()) { |
| 3457 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Yunfan Chen | e9c1c31 | 2019-04-18 14:49:15 +0900 | [diff] [blame] | 3458 | } else if (stack.getParent().inFreeformWindowingMode()) { |
| 3459 | // If the window is on a freeform display, set it to undefined. It will be |
| 3460 | // resolved to freeform and it can adjust windowing mode when the display mode |
| 3461 | // changes in runtime. |
| 3462 | stack.setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3463 | } else { |
| 3464 | stack.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 3465 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3466 | } finally { |
| 3467 | Binder.restoreCallingIdentity(ident); |
| 3468 | } |
| 3469 | } |
| 3470 | } |
| 3471 | |
| 3472 | /** Sets the task stack listener that gets callbacks when a task stack changes. */ |
| 3473 | @Override |
| 3474 | public void registerTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3475 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3476 | "registerTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3477 | mTaskChangeNotificationController.registerTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3478 | } |
| 3479 | |
| 3480 | /** Unregister a task stack listener so that it stops receiving callbacks. */ |
| 3481 | @Override |
| 3482 | public void unregisterTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3483 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3484 | "unregisterTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3485 | mTaskChangeNotificationController.unregisterTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3486 | } |
| 3487 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3488 | @Override |
| 3489 | public boolean requestAssistContextExtras(int requestType, IAssistDataReceiver receiver, |
| 3490 | Bundle receiverExtras, IBinder activityToken, boolean focused, boolean newSessionId) { |
| 3491 | return enqueueAssistContext(requestType, null, null, receiver, receiverExtras, |
| 3492 | activityToken, focused, newSessionId, UserHandle.getCallingUserId(), null, |
| 3493 | PENDING_ASSIST_EXTRAS_LONG_TIMEOUT, 0) != null; |
| 3494 | } |
| 3495 | |
| 3496 | @Override |
| 3497 | public boolean requestAutofillData(IAssistDataReceiver receiver, Bundle receiverExtras, |
| 3498 | IBinder activityToken, int flags) { |
| 3499 | return enqueueAssistContext(ActivityManager.ASSIST_CONTEXT_AUTOFILL, null, null, |
| 3500 | receiver, receiverExtras, activityToken, true, true, UserHandle.getCallingUserId(), |
| 3501 | null, PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT, flags) != null; |
| 3502 | } |
| 3503 | |
| 3504 | @Override |
| 3505 | public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle, |
| 3506 | Bundle args) { |
| 3507 | return enqueueAssistContext(requestType, intent, hint, null, null, null, |
| 3508 | true /* focused */, true /* newSessionId */, userHandle, args, |
| 3509 | PENDING_ASSIST_EXTRAS_TIMEOUT, 0) != null; |
| 3510 | } |
| 3511 | |
| 3512 | @Override |
| 3513 | public Bundle getAssistContextExtras(int requestType) { |
| 3514 | PendingAssistExtras pae = enqueueAssistContext(requestType, null, null, null, |
| 3515 | null, null, true /* focused */, true /* newSessionId */, |
| 3516 | UserHandle.getCallingUserId(), null, PENDING_ASSIST_EXTRAS_TIMEOUT, 0); |
| 3517 | if (pae == null) { |
| 3518 | return null; |
| 3519 | } |
| 3520 | synchronized (pae) { |
| 3521 | while (!pae.haveResult) { |
| 3522 | try { |
| 3523 | pae.wait(); |
| 3524 | } catch (InterruptedException e) { |
| 3525 | } |
| 3526 | } |
| 3527 | } |
| 3528 | synchronized (mGlobalLock) { |
| 3529 | buildAssistBundleLocked(pae, pae.result); |
| 3530 | mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3531 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3532 | } |
| 3533 | return pae.extras; |
| 3534 | } |
| 3535 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3536 | /** |
| 3537 | * Binder IPC calls go through the public entry point. |
| 3538 | * This can be called with or without the global lock held. |
| 3539 | */ |
| 3540 | private static int checkCallingPermission(String permission) { |
| 3541 | return checkPermission( |
| 3542 | permission, Binder.getCallingPid(), UserHandle.getAppId(Binder.getCallingUid())); |
| 3543 | } |
| 3544 | |
| 3545 | /** This can be called with or without the global lock held. */ |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3546 | private void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3547 | if (!getRecentTasks().isCallerRecents(Binder.getCallingUid())) { |
| 3548 | mAmInternal.enforceCallingPermission(permission, func); |
| 3549 | } |
| 3550 | } |
| 3551 | |
| 3552 | @VisibleForTesting |
| 3553 | int checkGetTasksPermission(String permission, int pid, int uid) { |
| 3554 | return checkPermission(permission, pid, uid); |
| 3555 | } |
| 3556 | |
| 3557 | static int checkPermission(String permission, int pid, int uid) { |
| 3558 | if (permission == null) { |
| 3559 | return PackageManager.PERMISSION_DENIED; |
| 3560 | } |
| 3561 | return checkComponentPermission(permission, pid, uid, -1, true); |
| 3562 | } |
| 3563 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3564 | public static int checkComponentPermission(String permission, int pid, int uid, |
| 3565 | int owningUid, boolean exported) { |
| 3566 | return ActivityManagerService.checkComponentPermission( |
| 3567 | permission, pid, uid, owningUid, exported); |
| 3568 | } |
| 3569 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3570 | boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 3571 | if (getRecentTasks().isCallerRecents(callingUid)) { |
| 3572 | // Always allow the recents component to get tasks |
| 3573 | return true; |
| 3574 | } |
| 3575 | |
| 3576 | boolean allowed = checkGetTasksPermission(android.Manifest.permission.REAL_GET_TASKS, |
| 3577 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED; |
| 3578 | if (!allowed) { |
| 3579 | if (checkGetTasksPermission(android.Manifest.permission.GET_TASKS, |
| 3580 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED) { |
| 3581 | // Temporary compatibility: some existing apps on the system image may |
| 3582 | // still be requesting the old permission and not switched to the new |
| 3583 | // one; if so, we'll still allow them full access. This means we need |
| 3584 | // to see if they are holding the old permission and are a system app. |
| 3585 | try { |
| 3586 | if (AppGlobals.getPackageManager().isUidPrivileged(callingUid)) { |
| 3587 | allowed = true; |
| 3588 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3589 | + " is using old GET_TASKS but privileged; allowing"); |
| 3590 | } |
| 3591 | } catch (RemoteException e) { |
| 3592 | } |
| 3593 | } |
| 3594 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3595 | + " does not hold REAL_GET_TASKS; limiting output"); |
| 3596 | } |
| 3597 | return allowed; |
| 3598 | } |
| 3599 | |
Nicholas Sauer | f307365 | 2019-08-30 08:24:55 -0700 | [diff] [blame] | 3600 | boolean isCrossUserAllowed(int pid, int uid) { |
| 3601 | return checkPermission(INTERACT_ACROSS_USERS, pid, uid) == PERMISSION_GRANTED |
| 3602 | || checkPermission(INTERACT_ACROSS_USERS_FULL, pid, uid) == PERMISSION_GRANTED; |
| 3603 | } |
| 3604 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3605 | private PendingAssistExtras enqueueAssistContext(int requestType, Intent intent, String hint, |
| 3606 | IAssistDataReceiver receiver, Bundle receiverExtras, IBinder activityToken, |
| 3607 | boolean focused, boolean newSessionId, int userHandle, Bundle args, long timeout, |
| 3608 | int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3609 | mAmInternal.enforceCallingPermission(android.Manifest.permission.GET_TOP_ACTIVITY_INFO, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3610 | "enqueueAssistContext()"); |
| 3611 | |
| 3612 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3613 | ActivityRecord activity = getTopDisplayFocusedStack().getTopActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3614 | if (activity == null) { |
| 3615 | Slog.w(TAG, "getAssistContextExtras failed: no top activity"); |
| 3616 | return null; |
| 3617 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3618 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3619 | Slog.w(TAG, "getAssistContextExtras failed: no process for " + activity); |
| 3620 | return null; |
| 3621 | } |
| 3622 | if (focused) { |
| 3623 | if (activityToken != null) { |
| 3624 | ActivityRecord caller = ActivityRecord.forTokenLocked(activityToken); |
| 3625 | if (activity != caller) { |
| 3626 | Slog.w(TAG, "enqueueAssistContext failed: caller " + caller |
| 3627 | + " is not current top " + activity); |
| 3628 | return null; |
| 3629 | } |
| 3630 | } |
| 3631 | } else { |
| 3632 | activity = ActivityRecord.forTokenLocked(activityToken); |
| 3633 | if (activity == null) { |
| 3634 | Slog.w(TAG, "enqueueAssistContext failed: activity for token=" + activityToken |
| 3635 | + " couldn't be found"); |
| 3636 | return null; |
| 3637 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3638 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3639 | Slog.w(TAG, "enqueueAssistContext failed: no process for " + activity); |
| 3640 | return null; |
| 3641 | } |
| 3642 | } |
| 3643 | |
| 3644 | PendingAssistExtras pae; |
| 3645 | Bundle extras = new Bundle(); |
| 3646 | if (args != null) { |
| 3647 | extras.putAll(args); |
| 3648 | } |
| 3649 | extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3650 | extras.putInt(Intent.EXTRA_ASSIST_UID, activity.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3651 | |
| 3652 | pae = new PendingAssistExtras(activity, extras, intent, hint, receiver, receiverExtras, |
| 3653 | userHandle); |
| 3654 | pae.isHome = activity.isActivityTypeHome(); |
| 3655 | |
| 3656 | // Increment the sessionId if necessary |
| 3657 | if (newSessionId) { |
| 3658 | mViSessionId++; |
| 3659 | } |
| 3660 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3661 | activity.app.getThread().requestAssistContextExtras(activity.appToken, pae, |
| 3662 | requestType, mViSessionId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3663 | mPendingAssistExtras.add(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3664 | mUiHandler.postDelayed(pae, timeout); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3665 | } catch (RemoteException e) { |
| 3666 | Slog.w(TAG, "getAssistContextExtras failed: crash calling " + activity); |
| 3667 | return null; |
| 3668 | } |
| 3669 | return pae; |
| 3670 | } |
| 3671 | } |
| 3672 | |
| 3673 | private void buildAssistBundleLocked(PendingAssistExtras pae, Bundle result) { |
| 3674 | if (result != null) { |
| 3675 | pae.extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, result); |
| 3676 | } |
| 3677 | if (pae.hint != null) { |
| 3678 | pae.extras.putBoolean(pae.hint, true); |
| 3679 | } |
| 3680 | } |
| 3681 | |
| 3682 | private void pendingAssistExtrasTimedOut(PendingAssistExtras pae) { |
| 3683 | IAssistDataReceiver receiver; |
| 3684 | synchronized (mGlobalLock) { |
| 3685 | mPendingAssistExtras.remove(pae); |
| 3686 | receiver = pae.receiver; |
| 3687 | } |
| 3688 | if (receiver != null) { |
| 3689 | // Caller wants result sent back to them. |
| 3690 | Bundle sendBundle = new Bundle(); |
| 3691 | // At least return the receiver extras |
| 3692 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3693 | try { |
| 3694 | pae.receiver.onHandleAssistData(sendBundle); |
| 3695 | } catch (RemoteException e) { |
| 3696 | } |
| 3697 | } |
| 3698 | } |
| 3699 | |
| 3700 | public class PendingAssistExtras extends Binder implements Runnable { |
| 3701 | public final ActivityRecord activity; |
| 3702 | public boolean isHome; |
| 3703 | public final Bundle extras; |
| 3704 | public final Intent intent; |
| 3705 | public final String hint; |
| 3706 | public final IAssistDataReceiver receiver; |
| 3707 | public final int userHandle; |
| 3708 | public boolean haveResult = false; |
| 3709 | public Bundle result = null; |
| 3710 | public AssistStructure structure = null; |
| 3711 | public AssistContent content = null; |
| 3712 | public Bundle receiverExtras; |
| 3713 | |
| 3714 | public PendingAssistExtras(ActivityRecord _activity, Bundle _extras, Intent _intent, |
| 3715 | String _hint, IAssistDataReceiver _receiver, Bundle _receiverExtras, |
| 3716 | int _userHandle) { |
| 3717 | activity = _activity; |
| 3718 | extras = _extras; |
| 3719 | intent = _intent; |
| 3720 | hint = _hint; |
| 3721 | receiver = _receiver; |
| 3722 | receiverExtras = _receiverExtras; |
| 3723 | userHandle = _userHandle; |
| 3724 | } |
| 3725 | |
| 3726 | @Override |
| 3727 | public void run() { |
| 3728 | Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from " + activity); |
| 3729 | synchronized (this) { |
| 3730 | haveResult = true; |
| 3731 | notifyAll(); |
| 3732 | } |
| 3733 | pendingAssistExtrasTimedOut(this); |
| 3734 | } |
| 3735 | } |
| 3736 | |
| 3737 | @Override |
| 3738 | public boolean isAssistDataAllowedOnCurrentActivity() { |
| 3739 | int userId; |
| 3740 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3741 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3742 | if (focusedStack == null || focusedStack.isActivityTypeAssistant()) { |
| 3743 | return false; |
| 3744 | } |
| 3745 | |
| 3746 | final ActivityRecord activity = focusedStack.getTopActivity(); |
| 3747 | if (activity == null) { |
| 3748 | return false; |
| 3749 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3750 | userId = activity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3751 | } |
| 3752 | return !DevicePolicyCache.getInstance().getScreenCaptureDisabled(userId); |
| 3753 | } |
| 3754 | |
| 3755 | @Override |
| 3756 | public boolean showAssistFromActivity(IBinder token, Bundle args) { |
| 3757 | long ident = Binder.clearCallingIdentity(); |
| 3758 | try { |
| 3759 | synchronized (mGlobalLock) { |
| 3760 | ActivityRecord caller = ActivityRecord.forTokenLocked(token); |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3761 | ActivityRecord top = getTopDisplayFocusedStack().getTopActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3762 | if (top != caller) { |
| 3763 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3764 | + " is not current top " + top); |
| 3765 | return false; |
| 3766 | } |
| 3767 | if (!top.nowVisible) { |
| 3768 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3769 | + " is not visible"); |
| 3770 | return false; |
| 3771 | } |
| 3772 | } |
| 3773 | return mAssistUtils.showSessionForActiveService(args, SHOW_SOURCE_APPLICATION, null, |
| 3774 | token); |
| 3775 | } finally { |
| 3776 | Binder.restoreCallingIdentity(ident); |
| 3777 | } |
| 3778 | } |
| 3779 | |
| 3780 | @Override |
| 3781 | public boolean isRootVoiceInteraction(IBinder token) { |
| 3782 | synchronized (mGlobalLock) { |
| 3783 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3784 | if (r == null) { |
| 3785 | return false; |
| 3786 | } |
| 3787 | return r.rootVoiceInteraction; |
| 3788 | } |
| 3789 | } |
| 3790 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3791 | private void onLocalVoiceInteractionStartedLocked(IBinder activity, |
| 3792 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 3793 | ActivityRecord activityToCallback = ActivityRecord.forTokenLocked(activity); |
| 3794 | if (activityToCallback == null) return; |
| 3795 | activityToCallback.setVoiceSessionLocked(voiceSession); |
| 3796 | |
| 3797 | // Inform the activity |
| 3798 | try { |
| 3799 | activityToCallback.app.getThread().scheduleLocalVoiceInteractionStarted(activity, |
| 3800 | voiceInteractor); |
| 3801 | long token = Binder.clearCallingIdentity(); |
| 3802 | try { |
| 3803 | startRunningVoiceLocked(voiceSession, activityToCallback.appInfo.uid); |
| 3804 | } finally { |
| 3805 | Binder.restoreCallingIdentity(token); |
| 3806 | } |
| 3807 | // TODO: VI Should we cache the activity so that it's easier to find later |
| 3808 | // rather than scan through all the stacks and activities? |
| 3809 | } catch (RemoteException re) { |
| 3810 | activityToCallback.clearVoiceSessionLocked(); |
| 3811 | // TODO: VI Should this terminate the voice session? |
| 3812 | } |
| 3813 | } |
| 3814 | |
| 3815 | private void startRunningVoiceLocked(IVoiceInteractionSession session, int targetUid) { |
| 3816 | Slog.d(TAG, "<<< startRunningVoiceLocked()"); |
| 3817 | mVoiceWakeLock.setWorkSource(new WorkSource(targetUid)); |
| 3818 | if (mRunningVoice == null || mRunningVoice.asBinder() != session.asBinder()) { |
| 3819 | boolean wasRunningVoice = mRunningVoice != null; |
| 3820 | mRunningVoice = session; |
| 3821 | if (!wasRunningVoice) { |
| 3822 | mVoiceWakeLock.acquire(); |
| 3823 | updateSleepIfNeededLocked(); |
| 3824 | } |
| 3825 | } |
| 3826 | } |
| 3827 | |
| 3828 | void finishRunningVoiceLocked() { |
| 3829 | if (mRunningVoice != null) { |
| 3830 | mRunningVoice = null; |
| 3831 | mVoiceWakeLock.release(); |
| 3832 | updateSleepIfNeededLocked(); |
| 3833 | } |
| 3834 | } |
| 3835 | |
| 3836 | @Override |
| 3837 | public void setVoiceKeepAwake(IVoiceInteractionSession session, boolean keepAwake) { |
| 3838 | synchronized (mGlobalLock) { |
| 3839 | if (mRunningVoice != null && mRunningVoice.asBinder() == session.asBinder()) { |
| 3840 | if (keepAwake) { |
| 3841 | mVoiceWakeLock.acquire(); |
| 3842 | } else { |
| 3843 | mVoiceWakeLock.release(); |
| 3844 | } |
| 3845 | } |
| 3846 | } |
| 3847 | } |
| 3848 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3849 | @Override |
| 3850 | public ComponentName getActivityClassForToken(IBinder token) { |
| 3851 | synchronized (mGlobalLock) { |
| 3852 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3853 | if (r == null) { |
| 3854 | return null; |
| 3855 | } |
| 3856 | return r.intent.getComponent(); |
| 3857 | } |
| 3858 | } |
| 3859 | |
| 3860 | @Override |
| 3861 | public String getPackageForToken(IBinder token) { |
| 3862 | synchronized (mGlobalLock) { |
| 3863 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3864 | if (r == null) { |
| 3865 | return null; |
| 3866 | } |
| 3867 | return r.packageName; |
| 3868 | } |
| 3869 | } |
| 3870 | |
| 3871 | @Override |
| 3872 | public void showLockTaskEscapeMessage(IBinder token) { |
| 3873 | synchronized (mGlobalLock) { |
| 3874 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3875 | if (r == null) { |
| 3876 | return; |
| 3877 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3878 | getLockTaskController().showLockTaskToast(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3879 | } |
| 3880 | } |
| 3881 | |
| 3882 | @Override |
| 3883 | public void keyguardGoingAway(int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3884 | enforceNotIsolatedCaller("keyguardGoingAway"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3885 | final long token = Binder.clearCallingIdentity(); |
| 3886 | try { |
| 3887 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3888 | mKeyguardController.keyguardGoingAway(flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3889 | } |
| 3890 | } finally { |
| 3891 | Binder.restoreCallingIdentity(token); |
| 3892 | } |
| 3893 | } |
| 3894 | |
| 3895 | /** |
| 3896 | * Try to place task to provided position. The final position might be different depending on |
| 3897 | * current user and stacks state. The task will be moved to target stack if it's currently in |
| 3898 | * different stack. |
| 3899 | */ |
| 3900 | @Override |
| 3901 | public void positionTaskInStack(int taskId, int stackId, int position) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3902 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "positionTaskInStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3903 | synchronized (mGlobalLock) { |
| 3904 | long ident = Binder.clearCallingIdentity(); |
| 3905 | try { |
| 3906 | if (DEBUG_STACK) Slog.d(TAG_STACK, "positionTaskInStack: positioning task=" |
| 3907 | + taskId + " in stackId=" + stackId + " at position=" + position); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3908 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3909 | if (task == null) { |
| 3910 | throw new IllegalArgumentException("positionTaskInStack: no task for id=" |
| 3911 | + taskId); |
| 3912 | } |
| 3913 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3914 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3915 | |
| 3916 | if (stack == null) { |
| 3917 | throw new IllegalArgumentException("positionTaskInStack: no stack for id=" |
| 3918 | + stackId); |
| 3919 | } |
| 3920 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3921 | throw new IllegalArgumentException("positionTaskInStack: Attempt to change" |
| 3922 | + " the position of task " + taskId + " in/to non-standard stack"); |
| 3923 | } |
| 3924 | |
| 3925 | // TODO: Have the callers of this API call a separate reparent method if that is |
| 3926 | // what they intended to do vs. having this method also do reparenting. |
| 3927 | if (task.getStack() == stack) { |
| 3928 | // Change position in current stack. |
| 3929 | stack.positionChildAt(task, position); |
| 3930 | } else { |
| 3931 | // Reparent to new stack. |
| 3932 | task.reparent(stack, position, REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, |
| 3933 | !DEFER_RESUME, "positionTaskInStack"); |
| 3934 | } |
| 3935 | } finally { |
| 3936 | Binder.restoreCallingIdentity(ident); |
| 3937 | } |
| 3938 | } |
| 3939 | } |
| 3940 | |
| 3941 | @Override |
| 3942 | public void reportSizeConfigurations(IBinder token, int[] horizontalSizeConfiguration, |
| 3943 | int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { |
| 3944 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Report configuration: " + token + " " |
| 3945 | + horizontalSizeConfiguration + " " + verticalSizeConfigurations); |
| 3946 | synchronized (mGlobalLock) { |
| 3947 | ActivityRecord record = ActivityRecord.isInStackLocked(token); |
| 3948 | if (record == null) { |
| 3949 | throw new IllegalArgumentException("reportSizeConfigurations: ActivityRecord not " |
| 3950 | + "found for: " + token); |
| 3951 | } |
| 3952 | record.setSizeConfigurations(horizontalSizeConfiguration, |
| 3953 | verticalSizeConfigurations, smallestSizeConfigurations); |
| 3954 | } |
| 3955 | } |
| 3956 | |
| 3957 | /** |
| 3958 | * Dismisses split-screen multi-window mode. |
| 3959 | * @param toTop If true the current primary split-screen stack will be placed or left on top. |
| 3960 | */ |
| 3961 | @Override |
| 3962 | public void dismissSplitScreenMode(boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3963 | enforceCallerIsRecentsOrHasPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3964 | MANAGE_ACTIVITY_STACKS, "dismissSplitScreenMode()"); |
| 3965 | final long ident = Binder.clearCallingIdentity(); |
| 3966 | try { |
| 3967 | synchronized (mGlobalLock) { |
| 3968 | final ActivityStack stack = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3969 | mRootActivityContainer.getDefaultDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3970 | if (stack == null) { |
| 3971 | Slog.w(TAG, "dismissSplitScreenMode: primary split-screen stack not found."); |
| 3972 | return; |
| 3973 | } |
| 3974 | |
| 3975 | if (toTop) { |
| 3976 | // Caller wants the current split-screen primary stack to be the top stack after |
| 3977 | // it goes fullscreen, so move it to the front. |
| 3978 | stack.moveToFront("dismissSplitScreenMode"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3979 | } else if (mRootActivityContainer.isTopDisplayFocusedStack(stack)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3980 | // In this case the current split-screen primary stack shouldn't be the top |
| 3981 | // stack after it goes fullscreen, but it current has focus, so we move the |
| 3982 | // focus to the top-most split-screen secondary stack next to it. |
| 3983 | final ActivityStack otherStack = stack.getDisplay().getTopStackInWindowingMode( |
| 3984 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 3985 | if (otherStack != null) { |
| 3986 | otherStack.moveToFront("dismissSplitScreenMode_other"); |
| 3987 | } |
| 3988 | } |
| 3989 | |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 3990 | stack.setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3991 | } |
| 3992 | } finally { |
| 3993 | Binder.restoreCallingIdentity(ident); |
| 3994 | } |
| 3995 | } |
| 3996 | |
| 3997 | /** |
| 3998 | * Dismisses Pip |
| 3999 | * @param animate True if the dismissal should be animated. |
| 4000 | * @param animationDuration The duration of the resize animation in milliseconds or -1 if the |
| 4001 | * default animation duration should be used. |
| 4002 | */ |
| 4003 | @Override |
| 4004 | public void dismissPip(boolean animate, int animationDuration) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4005 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "dismissPip()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4006 | final long ident = Binder.clearCallingIdentity(); |
| 4007 | try { |
| 4008 | synchronized (mGlobalLock) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 4009 | final ActivityStack stack = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4010 | mRootActivityContainer.getDefaultDisplay().getPinnedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4011 | if (stack == null) { |
| 4012 | Slog.w(TAG, "dismissPip: pinned stack not found."); |
| 4013 | return; |
| 4014 | } |
| 4015 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 4016 | throw new IllegalArgumentException("Stack: " + stack |
| 4017 | + " doesn't support animated resize."); |
| 4018 | } |
| 4019 | if (animate) { |
| 4020 | stack.animateResizePinnedStack(null /* sourceHintBounds */, |
| 4021 | null /* destBounds */, animationDuration, false /* fromFullscreen */); |
| 4022 | } else { |
| 4023 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, true /* onTop */); |
| 4024 | } |
| 4025 | } |
| 4026 | } finally { |
| 4027 | Binder.restoreCallingIdentity(ident); |
| 4028 | } |
| 4029 | } |
| 4030 | |
| 4031 | @Override |
| 4032 | public void suppressResizeConfigChanges(boolean suppress) throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4033 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "suppressResizeConfigChanges()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4034 | synchronized (mGlobalLock) { |
| 4035 | mSuppressResizeConfigChanges = suppress; |
| 4036 | } |
| 4037 | } |
| 4038 | |
| 4039 | /** |
| 4040 | * NOTE: For the pinned stack, this method is usually called after the bounds animation has |
| 4041 | * animated the stack to the fullscreen, but can also be called if we are relaunching an |
| 4042 | * activity and clearing the task at the same time. |
| 4043 | */ |
| 4044 | @Override |
| 4045 | // TODO: API should just be about changing windowing modes... |
| 4046 | public void moveTasksToFullscreenStack(int fromStackId, boolean onTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4047 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4048 | "moveTasksToFullscreenStack()"); |
| 4049 | synchronized (mGlobalLock) { |
| 4050 | final long origId = Binder.clearCallingIdentity(); |
| 4051 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4052 | final ActivityStack stack = mRootActivityContainer.getStack(fromStackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4053 | if (stack != null){ |
| 4054 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 4055 | throw new IllegalArgumentException( |
| 4056 | "You can't move tasks from non-standard stacks."); |
| 4057 | } |
| 4058 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, onTop); |
| 4059 | } |
| 4060 | } finally { |
| 4061 | Binder.restoreCallingIdentity(origId); |
| 4062 | } |
| 4063 | } |
| 4064 | } |
| 4065 | |
| 4066 | /** |
| 4067 | * Moves the top activity in the input stackId to the pinned stack. |
| 4068 | * |
| 4069 | * @param stackId Id of stack to move the top activity to pinned stack. |
| 4070 | * @param bounds Bounds to use for pinned stack. |
| 4071 | * |
| 4072 | * @return True if the top activity of the input stack was successfully moved to the pinned |
| 4073 | * stack. |
| 4074 | */ |
| 4075 | @Override |
| 4076 | public boolean moveTopActivityToPinnedStack(int stackId, Rect bounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4077 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4078 | "moveTopActivityToPinnedStack()"); |
| 4079 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4080 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4081 | throw new IllegalStateException("moveTopActivityToPinnedStack:" |
| 4082 | + "Device doesn't support picture-in-picture mode"); |
| 4083 | } |
| 4084 | |
| 4085 | long ident = Binder.clearCallingIdentity(); |
| 4086 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4087 | return mRootActivityContainer.moveTopStackActivityToPinnedStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4088 | } finally { |
| 4089 | Binder.restoreCallingIdentity(ident); |
| 4090 | } |
| 4091 | } |
| 4092 | } |
| 4093 | |
| 4094 | @Override |
| 4095 | public boolean isInMultiWindowMode(IBinder token) { |
| 4096 | final long origId = Binder.clearCallingIdentity(); |
| 4097 | try { |
| 4098 | synchronized (mGlobalLock) { |
| 4099 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4100 | if (r == null) { |
| 4101 | return false; |
| 4102 | } |
| 4103 | // An activity is consider to be in multi-window mode if its task isn't fullscreen. |
| 4104 | return r.inMultiWindowMode(); |
| 4105 | } |
| 4106 | } finally { |
| 4107 | Binder.restoreCallingIdentity(origId); |
| 4108 | } |
| 4109 | } |
| 4110 | |
| 4111 | @Override |
| 4112 | public boolean isInPictureInPictureMode(IBinder token) { |
| 4113 | final long origId = Binder.clearCallingIdentity(); |
| 4114 | try { |
| 4115 | synchronized (mGlobalLock) { |
| 4116 | return isInPictureInPictureMode(ActivityRecord.forTokenLocked(token)); |
| 4117 | } |
| 4118 | } finally { |
| 4119 | Binder.restoreCallingIdentity(origId); |
| 4120 | } |
| 4121 | } |
| 4122 | |
| 4123 | private boolean isInPictureInPictureMode(ActivityRecord r) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4124 | if (r == null || r.getActivityStack() == null || !r.inPinnedWindowingMode() |
| 4125 | || r.getActivityStack().isInStackLocked(r) == null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4126 | return false; |
| 4127 | } |
| 4128 | |
| 4129 | // If we are animating to fullscreen then we have already dispatched the PIP mode |
| 4130 | // changed, so we should reflect that check here as well. |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 4131 | final TaskStack taskStack = r.getActivityStack().getTaskStack(); |
| 4132 | return !taskStack.isAnimatingBoundsToFullscreen(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | @Override |
| 4136 | public boolean enterPictureInPictureMode(IBinder token, final PictureInPictureParams params) { |
| 4137 | final long origId = Binder.clearCallingIdentity(); |
| 4138 | try { |
| 4139 | synchronized (mGlobalLock) { |
| 4140 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 4141 | "enterPictureInPictureMode", token, params); |
| 4142 | |
| 4143 | // If the activity is already in picture in picture mode, then just return early |
| 4144 | if (isInPictureInPictureMode(r)) { |
| 4145 | return true; |
| 4146 | } |
| 4147 | |
| 4148 | // Activity supports picture-in-picture, now check that we can enter PiP at this |
| 4149 | // point, if it is |
| 4150 | if (!r.checkEnterPictureInPictureState("enterPictureInPictureMode", |
| 4151 | false /* beforeStopping */)) { |
| 4152 | return false; |
| 4153 | } |
| 4154 | |
| 4155 | final Runnable enterPipRunnable = () -> { |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4156 | synchronized (mGlobalLock) { |
| 4157 | // Only update the saved args from the args that are set |
| 4158 | r.pictureInPictureArgs.copyOnlySet(params); |
| 4159 | final float aspectRatio = r.pictureInPictureArgs.getAspectRatio(); |
| 4160 | final List<RemoteAction> actions = r.pictureInPictureArgs.getActions(); |
| 4161 | // Adjust the source bounds by the insets for the transition down |
| 4162 | final Rect sourceBounds = new Rect( |
| 4163 | r.pictureInPictureArgs.getSourceRectHint()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4164 | mRootActivityContainer.moveActivityToPinnedStack( |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4165 | r, sourceBounds, aspectRatio, "enterPictureInPictureMode"); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 4166 | final ActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4167 | stack.setPictureInPictureAspectRatio(aspectRatio); |
| 4168 | stack.setPictureInPictureActions(actions); |
| 4169 | MetricsLoggerWrapper.logPictureInPictureEnter(mContext, r.appInfo.uid, |
| 4170 | r.shortComponentName, r.supportsEnterPipOnTaskSwitch); |
| 4171 | logPictureInPictureArgs(params); |
| 4172 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4173 | }; |
| 4174 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4175 | if (isKeyguardLocked()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4176 | // If the keyguard is showing or occluded, then try and dismiss it before |
| 4177 | // entering picture-in-picture (this will prompt the user to authenticate if the |
| 4178 | // device is currently locked). |
| 4179 | dismissKeyguard(token, new KeyguardDismissCallback() { |
| 4180 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4181 | public void onDismissSucceeded() { |
| 4182 | mH.post(enterPipRunnable); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4183 | } |
| 4184 | }, null /* message */); |
| 4185 | } else { |
| 4186 | // Enter picture in picture immediately otherwise |
| 4187 | enterPipRunnable.run(); |
| 4188 | } |
| 4189 | return true; |
| 4190 | } |
| 4191 | } finally { |
| 4192 | Binder.restoreCallingIdentity(origId); |
| 4193 | } |
| 4194 | } |
| 4195 | |
| 4196 | @Override |
| 4197 | public void setPictureInPictureParams(IBinder token, final PictureInPictureParams params) { |
| 4198 | final long origId = Binder.clearCallingIdentity(); |
| 4199 | try { |
| 4200 | synchronized (mGlobalLock) { |
| 4201 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 4202 | "setPictureInPictureParams", token, params); |
| 4203 | |
| 4204 | // Only update the saved args from the args that are set |
| 4205 | r.pictureInPictureArgs.copyOnlySet(params); |
| 4206 | if (r.inPinnedWindowingMode()) { |
| 4207 | // If the activity is already in picture-in-picture, update the pinned stack now |
| 4208 | // if it is not already expanding to fullscreen. Otherwise, the arguments will |
| 4209 | // be used the next time the activity enters PiP |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 4210 | final ActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4211 | if (!stack.isAnimatingBoundsToFullscreen()) { |
| 4212 | stack.setPictureInPictureAspectRatio( |
| 4213 | r.pictureInPictureArgs.getAspectRatio()); |
| 4214 | stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions()); |
| 4215 | } |
| 4216 | } |
| 4217 | logPictureInPictureArgs(params); |
| 4218 | } |
| 4219 | } finally { |
| 4220 | Binder.restoreCallingIdentity(origId); |
| 4221 | } |
| 4222 | } |
| 4223 | |
| 4224 | @Override |
| 4225 | public int getMaxNumPictureInPictureActions(IBinder token) { |
| 4226 | // Currently, this is a static constant, but later, we may change this to be dependent on |
| 4227 | // the context of the activity |
| 4228 | return 3; |
| 4229 | } |
| 4230 | |
| 4231 | private void logPictureInPictureArgs(PictureInPictureParams params) { |
| 4232 | if (params.hasSetActions()) { |
| 4233 | MetricsLogger.histogram(mContext, "tron_varz_picture_in_picture_actions_count", |
| 4234 | params.getActions().size()); |
| 4235 | } |
| 4236 | if (params.hasSetAspectRatio()) { |
| 4237 | LogMaker lm = new LogMaker(MetricsEvent.ACTION_PICTURE_IN_PICTURE_ASPECT_RATIO_CHANGED); |
| 4238 | lm.addTaggedData(MetricsEvent.PICTURE_IN_PICTURE_ASPECT_RATIO, params.getAspectRatio()); |
| 4239 | MetricsLogger.action(lm); |
| 4240 | } |
| 4241 | } |
| 4242 | |
| 4243 | /** |
| 4244 | * Checks the state of the system and the activity associated with the given {@param token} to |
| 4245 | * verify that picture-in-picture is supported for that activity. |
| 4246 | * |
| 4247 | * @return the activity record for the given {@param token} if all the checks pass. |
| 4248 | */ |
| 4249 | private ActivityRecord ensureValidPictureInPictureActivityParamsLocked(String caller, |
| 4250 | IBinder token, PictureInPictureParams params) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4251 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4252 | throw new IllegalStateException(caller |
| 4253 | + ": Device doesn't support picture-in-picture mode."); |
| 4254 | } |
| 4255 | |
| 4256 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 4257 | if (r == null) { |
| 4258 | throw new IllegalStateException(caller |
| 4259 | + ": Can't find activity for token=" + token); |
| 4260 | } |
| 4261 | |
| 4262 | if (!r.supportsPictureInPicture()) { |
| 4263 | throw new IllegalStateException(caller |
| 4264 | + ": Current activity does not support picture-in-picture."); |
| 4265 | } |
| 4266 | |
| 4267 | if (params.hasSetAspectRatio() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4268 | && !mWindowManager.isValidPictureInPictureAspectRatio( |
| 4269 | r.getActivityStack().mDisplayId, params.getAspectRatio())) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4270 | final float minAspectRatio = mContext.getResources().getFloat( |
| 4271 | com.android.internal.R.dimen.config_pictureInPictureMinAspectRatio); |
| 4272 | final float maxAspectRatio = mContext.getResources().getFloat( |
| 4273 | com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio); |
| 4274 | throw new IllegalArgumentException(String.format(caller |
| 4275 | + ": Aspect ratio is too extreme (must be between %f and %f).", |
| 4276 | minAspectRatio, maxAspectRatio)); |
| 4277 | } |
| 4278 | |
| 4279 | // Truncate the number of actions if necessary |
| 4280 | params.truncateActions(getMaxNumPictureInPictureActions(token)); |
| 4281 | |
| 4282 | return r; |
| 4283 | } |
| 4284 | |
| 4285 | @Override |
| 4286 | public IBinder getUriPermissionOwnerForActivity(IBinder activityToken) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4287 | enforceNotIsolatedCaller("getUriPermissionOwnerForActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4288 | synchronized (mGlobalLock) { |
| 4289 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 4290 | if (r == null) { |
| 4291 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 4292 | + activityToken); |
| 4293 | } |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 4294 | return r.getUriPermissionsLocked().getExternalToken(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4295 | } |
| 4296 | } |
| 4297 | |
| 4298 | @Override |
| 4299 | public void resizeDockedStack(Rect dockedBounds, Rect tempDockedTaskBounds, |
| 4300 | Rect tempDockedTaskInsetBounds, |
| 4301 | Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4302 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeDockedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4303 | long ident = Binder.clearCallingIdentity(); |
| 4304 | try { |
| 4305 | synchronized (mGlobalLock) { |
| 4306 | mStackSupervisor.resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, |
| 4307 | tempDockedTaskInsetBounds, tempOtherTaskBounds, tempOtherTaskInsetBounds, |
| 4308 | PRESERVE_WINDOWS); |
| 4309 | } |
| 4310 | } finally { |
| 4311 | Binder.restoreCallingIdentity(ident); |
| 4312 | } |
| 4313 | } |
| 4314 | |
| 4315 | @Override |
| 4316 | public void setSplitScreenResizing(boolean resizing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4317 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setSplitScreenResizing()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4318 | final long ident = Binder.clearCallingIdentity(); |
| 4319 | try { |
| 4320 | synchronized (mGlobalLock) { |
| 4321 | mStackSupervisor.setSplitScreenResizing(resizing); |
| 4322 | } |
| 4323 | } finally { |
| 4324 | Binder.restoreCallingIdentity(ident); |
| 4325 | } |
| 4326 | } |
| 4327 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4328 | /** |
| 4329 | * Check that we have the features required for VR-related API calls, and throw an exception if |
| 4330 | * not. |
| 4331 | */ |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 4332 | public void enforceSystemHasVrFeature() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4333 | if (!mContext.getPackageManager().hasSystemFeature( |
| 4334 | PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE)) { |
| 4335 | throw new UnsupportedOperationException("VR mode not supported on this device!"); |
| 4336 | } |
| 4337 | } |
| 4338 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4339 | @Override |
| 4340 | public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4341 | enforceSystemHasVrFeature(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4342 | |
| 4343 | final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class); |
| 4344 | |
| 4345 | ActivityRecord r; |
| 4346 | synchronized (mGlobalLock) { |
| 4347 | r = ActivityRecord.isInStackLocked(token); |
| 4348 | } |
| 4349 | |
| 4350 | if (r == null) { |
| 4351 | throw new IllegalArgumentException(); |
| 4352 | } |
| 4353 | |
| 4354 | int err; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4355 | if ((err = vrService.hasVrPackage(packageName, r.mUserId)) != |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4356 | VrManagerInternal.NO_ERROR) { |
| 4357 | return err; |
| 4358 | } |
| 4359 | |
| 4360 | // Clear the binder calling uid since this path may call moveToTask(). |
| 4361 | final long callingId = Binder.clearCallingIdentity(); |
| 4362 | try { |
| 4363 | synchronized (mGlobalLock) { |
| 4364 | r.requestedVrComponent = (enabled) ? packageName : null; |
| 4365 | |
| 4366 | // Update associated state if this activity is currently focused |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 4367 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4368 | applyUpdateVrModeLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4369 | } |
| 4370 | return 0; |
| 4371 | } |
| 4372 | } finally { |
| 4373 | Binder.restoreCallingIdentity(callingId); |
| 4374 | } |
| 4375 | } |
| 4376 | |
| 4377 | @Override |
| 4378 | public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) { |
| 4379 | Slog.i(TAG, "Activity tried to startLocalVoiceInteraction"); |
| 4380 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4381 | ActivityRecord activity = getTopDisplayFocusedStack().getTopActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4382 | if (ActivityRecord.forTokenLocked(callingActivity) != activity) { |
| 4383 | throw new SecurityException("Only focused activity can call startVoiceInteraction"); |
| 4384 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4385 | if (mRunningVoice != null || activity.getTaskRecord().voiceSession != null |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4386 | || activity.voiceSession != null) { |
| 4387 | Slog.w(TAG, "Already in a voice interaction, cannot start new voice interaction"); |
| 4388 | return; |
| 4389 | } |
| 4390 | if (activity.pendingVoiceInteractionStart) { |
| 4391 | Slog.w(TAG, "Pending start of voice interaction already."); |
| 4392 | return; |
| 4393 | } |
| 4394 | activity.pendingVoiceInteractionStart = true; |
| 4395 | } |
| 4396 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4397 | .startLocalVoiceInteraction(callingActivity, options); |
| 4398 | } |
| 4399 | |
| 4400 | @Override |
| 4401 | public void stopLocalVoiceInteraction(IBinder callingActivity) { |
| 4402 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4403 | .stopLocalVoiceInteraction(callingActivity); |
| 4404 | } |
| 4405 | |
| 4406 | @Override |
| 4407 | public boolean supportsLocalVoiceInteraction() { |
| 4408 | return LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4409 | .supportsLocalVoiceInteraction(); |
| 4410 | } |
| 4411 | |
| 4412 | /** Notifies all listeners when the pinned stack animation starts. */ |
| 4413 | @Override |
| 4414 | public void notifyPinnedStackAnimationStarted() { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4415 | mTaskChangeNotificationController.notifyPinnedStackAnimationStarted(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4416 | } |
| 4417 | |
| 4418 | /** Notifies all listeners when the pinned stack animation ends. */ |
| 4419 | @Override |
| 4420 | public void notifyPinnedStackAnimationEnded() { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4421 | mTaskChangeNotificationController.notifyPinnedStackAnimationEnded(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4422 | } |
| 4423 | |
| 4424 | @Override |
| 4425 | public void resizePinnedStack(Rect pinnedBounds, Rect tempPinnedTaskBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4426 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizePinnedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4427 | final long ident = Binder.clearCallingIdentity(); |
| 4428 | try { |
| 4429 | synchronized (mGlobalLock) { |
| 4430 | mStackSupervisor.resizePinnedStackLocked(pinnedBounds, tempPinnedTaskBounds); |
| 4431 | } |
| 4432 | } finally { |
| 4433 | Binder.restoreCallingIdentity(ident); |
| 4434 | } |
| 4435 | } |
| 4436 | |
| 4437 | @Override |
| 4438 | public boolean updateDisplayOverrideConfiguration(Configuration values, int displayId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4439 | mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateDisplayOverrideConfiguration()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4440 | |
| 4441 | synchronized (mGlobalLock) { |
| 4442 | // Check if display is initialized in AM. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4443 | if (!mRootActivityContainer.isDisplayAdded(displayId)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4444 | // Call might come when display is not yet added or has already been removed. |
| 4445 | if (DEBUG_CONFIGURATION) { |
| 4446 | Slog.w(TAG, "Trying to update display configuration for non-existing displayId=" |
| 4447 | + displayId); |
| 4448 | } |
| 4449 | return false; |
| 4450 | } |
| 4451 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4452 | if (values == null && mWindowManager != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4453 | // sentinel: fetch the current configuration from the window manager |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4454 | values = mWindowManager.computeNewConfiguration(displayId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4455 | } |
| 4456 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4457 | if (mWindowManager != null) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4458 | final Message msg = PooledLambda.obtainMessage( |
| 4459 | ActivityManagerInternal::updateOomLevelsForDisplay, mAmInternal, displayId); |
| 4460 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | final long origId = Binder.clearCallingIdentity(); |
| 4464 | try { |
| 4465 | if (values != null) { |
| 4466 | Settings.System.clearConfiguration(values); |
| 4467 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4468 | updateDisplayOverrideConfigurationLocked(values, null /* starting */, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4469 | false /* deferResume */, displayId, mTmpUpdateConfigurationResult); |
| 4470 | return mTmpUpdateConfigurationResult.changes != 0; |
| 4471 | } finally { |
| 4472 | Binder.restoreCallingIdentity(origId); |
| 4473 | } |
| 4474 | } |
| 4475 | } |
| 4476 | |
| 4477 | @Override |
| 4478 | public boolean updateConfiguration(Configuration values) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4479 | mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateConfiguration()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4480 | |
| 4481 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4482 | if (values == null && mWindowManager != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4483 | // sentinel: fetch the current configuration from the window manager |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4484 | values = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4485 | } |
| 4486 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4487 | if (mWindowManager != null) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4488 | final Message msg = PooledLambda.obtainMessage( |
| 4489 | ActivityManagerInternal::updateOomLevelsForDisplay, mAmInternal, |
| 4490 | DEFAULT_DISPLAY); |
| 4491 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | final long origId = Binder.clearCallingIdentity(); |
| 4495 | try { |
| 4496 | if (values != null) { |
| 4497 | Settings.System.clearConfiguration(values); |
| 4498 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4499 | updateConfigurationLocked(values, null, false, false /* persistent */, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4500 | UserHandle.USER_NULL, false /* deferResume */, |
| 4501 | mTmpUpdateConfigurationResult); |
| 4502 | return mTmpUpdateConfigurationResult.changes != 0; |
| 4503 | } finally { |
| 4504 | Binder.restoreCallingIdentity(origId); |
| 4505 | } |
| 4506 | } |
| 4507 | } |
| 4508 | |
| 4509 | @Override |
| 4510 | public void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback, |
| 4511 | CharSequence message) { |
| 4512 | if (message != null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4513 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4514 | Manifest.permission.SHOW_KEYGUARD_MESSAGE, "dismissKeyguard()"); |
| 4515 | } |
| 4516 | final long callingId = Binder.clearCallingIdentity(); |
| 4517 | try { |
| 4518 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4519 | mKeyguardController.dismissKeyguard(token, callback, message); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4520 | } |
| 4521 | } finally { |
| 4522 | Binder.restoreCallingIdentity(callingId); |
| 4523 | } |
| 4524 | } |
| 4525 | |
| 4526 | @Override |
| 4527 | public void cancelTaskWindowTransition(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4528 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4529 | "cancelTaskWindowTransition()"); |
| 4530 | final long ident = Binder.clearCallingIdentity(); |
| 4531 | try { |
| 4532 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4533 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4534 | MATCH_TASK_IN_STACKS_ONLY); |
| 4535 | if (task == null) { |
| 4536 | Slog.w(TAG, "cancelTaskWindowTransition: taskId=" + taskId + " not found"); |
| 4537 | return; |
| 4538 | } |
| 4539 | task.cancelWindowTransition(); |
| 4540 | } |
| 4541 | } finally { |
| 4542 | Binder.restoreCallingIdentity(ident); |
| 4543 | } |
| 4544 | } |
| 4545 | |
| 4546 | @Override |
| 4547 | public ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4548 | enforceCallerIsRecentsOrHasPermission(READ_FRAME_BUFFER, "getTaskSnapshot()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4549 | final long ident = Binder.clearCallingIdentity(); |
| 4550 | try { |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4551 | return getTaskSnapshot(taskId, reducedResolution, true /* restoreFromDisk */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4552 | } finally { |
| 4553 | Binder.restoreCallingIdentity(ident); |
| 4554 | } |
| 4555 | } |
| 4556 | |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4557 | private ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution, |
| 4558 | boolean restoreFromDisk) { |
| 4559 | final TaskRecord task; |
| 4560 | synchronized (mGlobalLock) { |
| 4561 | task = mRootActivityContainer.anyTaskForId(taskId, |
| 4562 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 4563 | if (task == null) { |
| 4564 | Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found"); |
| 4565 | return null; |
| 4566 | } |
| 4567 | } |
| 4568 | // Don't call this while holding the lock as this operation might hit the disk. |
| 4569 | return task.getSnapshot(reducedResolution, restoreFromDisk); |
| 4570 | } |
| 4571 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4572 | @Override |
| 4573 | public void setDisablePreviewScreenshots(IBinder token, boolean disable) { |
| 4574 | synchronized (mGlobalLock) { |
| 4575 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4576 | if (r == null) { |
| 4577 | Slog.w(TAG, "setDisablePreviewScreenshots: Unable to find activity for token=" |
| 4578 | + token); |
| 4579 | return; |
| 4580 | } |
| 4581 | final long origId = Binder.clearCallingIdentity(); |
| 4582 | try { |
| 4583 | r.setDisablePreviewScreenshots(disable); |
| 4584 | } finally { |
| 4585 | Binder.restoreCallingIdentity(origId); |
| 4586 | } |
| 4587 | } |
| 4588 | } |
| 4589 | |
| 4590 | /** Return the user id of the last resumed activity. */ |
| 4591 | @Override |
| 4592 | public @UserIdInt |
| 4593 | int getLastResumedActivityUserId() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4594 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4595 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, "getLastResumedActivityUserId()"); |
| 4596 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4597 | if (mLastResumedActivity == null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4598 | return getCurrentUserId(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4599 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4600 | return mLastResumedActivity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4601 | } |
| 4602 | } |
| 4603 | |
| 4604 | @Override |
| 4605 | public void updateLockTaskFeatures(int userId, int flags) { |
| 4606 | final int callingUid = Binder.getCallingUid(); |
| 4607 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4608 | mAmInternal.enforceCallingPermission(android.Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4609 | "updateLockTaskFeatures()"); |
| 4610 | } |
| 4611 | synchronized (mGlobalLock) { |
| 4612 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Allowing features " + userId + ":0x" + |
| 4613 | Integer.toHexString(flags)); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 4614 | getLockTaskController().updateLockTaskFeatures(userId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4615 | } |
| 4616 | } |
| 4617 | |
| 4618 | @Override |
| 4619 | public void setShowWhenLocked(IBinder token, boolean showWhenLocked) { |
| 4620 | synchronized (mGlobalLock) { |
| 4621 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4622 | if (r == null) { |
| 4623 | return; |
| 4624 | } |
| 4625 | final long origId = Binder.clearCallingIdentity(); |
| 4626 | try { |
| 4627 | r.setShowWhenLocked(showWhenLocked); |
| 4628 | } finally { |
| 4629 | Binder.restoreCallingIdentity(origId); |
| 4630 | } |
| 4631 | } |
| 4632 | } |
| 4633 | |
| 4634 | @Override |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 4635 | public void setInheritShowWhenLocked(IBinder token, boolean inheritShowWhenLocked) { |
| 4636 | synchronized (mGlobalLock) { |
| 4637 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4638 | if (r == null) { |
| 4639 | return; |
| 4640 | } |
| 4641 | final long origId = Binder.clearCallingIdentity(); |
| 4642 | try { |
| 4643 | r.setInheritShowWhenLocked(inheritShowWhenLocked); |
| 4644 | } finally { |
| 4645 | Binder.restoreCallingIdentity(origId); |
| 4646 | } |
| 4647 | } |
| 4648 | } |
| 4649 | |
| 4650 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4651 | public void setTurnScreenOn(IBinder token, boolean turnScreenOn) { |
| 4652 | synchronized (mGlobalLock) { |
| 4653 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4654 | if (r == null) { |
| 4655 | return; |
| 4656 | } |
| 4657 | final long origId = Binder.clearCallingIdentity(); |
| 4658 | try { |
| 4659 | r.setTurnScreenOn(turnScreenOn); |
| 4660 | } finally { |
| 4661 | Binder.restoreCallingIdentity(origId); |
| 4662 | } |
| 4663 | } |
| 4664 | } |
| 4665 | |
| 4666 | @Override |
| 4667 | public void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4668 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4669 | "registerRemoteAnimations"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4670 | definition.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4671 | synchronized (mGlobalLock) { |
| 4672 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4673 | if (r == null) { |
| 4674 | return; |
| 4675 | } |
| 4676 | final long origId = Binder.clearCallingIdentity(); |
| 4677 | try { |
| 4678 | r.registerRemoteAnimations(definition); |
| 4679 | } finally { |
| 4680 | Binder.restoreCallingIdentity(origId); |
| 4681 | } |
| 4682 | } |
| 4683 | } |
| 4684 | |
| 4685 | @Override |
| 4686 | public void registerRemoteAnimationForNextActivityStart(String packageName, |
| 4687 | RemoteAnimationAdapter adapter) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4688 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4689 | "registerRemoteAnimationForNextActivityStart"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4690 | adapter.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4691 | synchronized (mGlobalLock) { |
| 4692 | final long origId = Binder.clearCallingIdentity(); |
| 4693 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4694 | getActivityStartController().registerRemoteAnimationForNextActivityStart( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4695 | packageName, adapter); |
| 4696 | } finally { |
| 4697 | Binder.restoreCallingIdentity(origId); |
| 4698 | } |
| 4699 | } |
| 4700 | } |
| 4701 | |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4702 | @Override |
| 4703 | public void registerRemoteAnimationsForDisplay(int displayId, |
| 4704 | RemoteAnimationDefinition definition) { |
| 4705 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
| 4706 | "registerRemoteAnimations"); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 4707 | definition.setCallingPidUid(Binder.getCallingPid(), Binder.getCallingUid()); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4708 | synchronized (mGlobalLock) { |
| 4709 | final ActivityDisplay display = mRootActivityContainer.getActivityDisplay(displayId); |
| 4710 | if (display == null) { |
| 4711 | Slog.e(TAG, "Couldn't find display with id: " + displayId); |
| 4712 | return; |
| 4713 | } |
| 4714 | final long origId = Binder.clearCallingIdentity(); |
| 4715 | try { |
| 4716 | display.mDisplayContent.registerRemoteAnimations(definition); |
| 4717 | } finally { |
| 4718 | Binder.restoreCallingIdentity(origId); |
| 4719 | } |
| 4720 | } |
| 4721 | } |
| 4722 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4723 | /** @see android.app.ActivityManager#alwaysShowUnsupportedCompileSdkWarning */ |
| 4724 | @Override |
| 4725 | public void alwaysShowUnsupportedCompileSdkWarning(ComponentName activity) { |
| 4726 | synchronized (mGlobalLock) { |
| 4727 | final long origId = Binder.clearCallingIdentity(); |
| 4728 | try { |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 4729 | mAppWarnings.alwaysShowUnsupportedCompileSdkWarning(activity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4730 | } finally { |
| 4731 | Binder.restoreCallingIdentity(origId); |
| 4732 | } |
| 4733 | } |
| 4734 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 4735 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4736 | @Override |
| 4737 | public void setVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4738 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4739 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4740 | final int pid = Binder.getCallingPid(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 4741 | final WindowProcessController wpc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4742 | mVrController.setVrThreadLocked(tid, pid, wpc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4743 | } |
| 4744 | } |
| 4745 | |
| 4746 | @Override |
| 4747 | public void setPersistentVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4748 | if (checkCallingPermission(Manifest.permission.RESTRICTED_VR_ACCESS) |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4749 | != PERMISSION_GRANTED) { |
| 4750 | final String msg = "Permission Denial: setPersistentVrThread() from pid=" |
| 4751 | + Binder.getCallingPid() |
| 4752 | + ", uid=" + Binder.getCallingUid() |
| 4753 | + " requires " + Manifest.permission.RESTRICTED_VR_ACCESS; |
| 4754 | Slog.w(TAG, msg); |
| 4755 | throw new SecurityException(msg); |
| 4756 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4757 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4758 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4759 | final int pid = Binder.getCallingPid(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 4760 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4761 | mVrController.setPersistentVrThreadLocked(tid, pid, proc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4762 | } |
| 4763 | } |
| 4764 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4765 | @Override |
| 4766 | public void stopAppSwitches() { |
| 4767 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "stopAppSwitches"); |
| 4768 | synchronized (mGlobalLock) { |
| 4769 | mAppSwitchesAllowedTime = SystemClock.uptimeMillis() + APP_SWITCH_DELAY_TIME; |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 4770 | mLastStopAppSwitchesTime = SystemClock.uptimeMillis(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4771 | mDidAppSwitch = false; |
| 4772 | getActivityStartController().schedulePendingActivityLaunches(APP_SWITCH_DELAY_TIME); |
| 4773 | } |
| 4774 | } |
| 4775 | |
| 4776 | @Override |
| 4777 | public void resumeAppSwitches() { |
| 4778 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "resumeAppSwitches"); |
| 4779 | synchronized (mGlobalLock) { |
| 4780 | // Note that we don't execute any pending app switches... we will |
| 4781 | // let those wait until either the timeout, or the next start |
| 4782 | // activity request. |
| 4783 | mAppSwitchesAllowedTime = 0; |
| 4784 | } |
| 4785 | } |
| 4786 | |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 4787 | long getLastStopAppSwitchesTime() { |
| 4788 | return mLastStopAppSwitchesTime; |
| 4789 | } |
| 4790 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4791 | void onStartActivitySetDidAppSwitch() { |
| 4792 | if (mDidAppSwitch) { |
| 4793 | // This is the second allowed switch since we stopped switches, so now just generally |
| 4794 | // allow switches. Use case: |
| 4795 | // - user presses home (switches disabled, switch to home, mDidAppSwitch now true); |
| 4796 | // - user taps a home icon (coming from home so allowed, we hit here and now allow |
| 4797 | // anyone to switch again). |
| 4798 | mAppSwitchesAllowedTime = 0; |
| 4799 | } else { |
| 4800 | mDidAppSwitch = true; |
| 4801 | } |
| 4802 | } |
| 4803 | |
| 4804 | /** @return whether the system should disable UI modes incompatible with VR mode. */ |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4805 | boolean shouldDisableNonVrUiLocked() { |
| 4806 | return mVrController.shouldDisableNonVrUiLocked(); |
| 4807 | } |
| 4808 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4809 | private void applyUpdateVrModeLocked(ActivityRecord r) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4810 | // 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] | 4811 | // 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] | 4812 | if (r.requestedVrComponent != null && r.getDisplayId() != DEFAULT_DISPLAY) { |
Wale Ogunwale | b8e6b63 | 2019-06-28 15:19:25 +0000 | [diff] [blame] | 4813 | Slog.i(TAG, "Moving " + r.shortComponentName + " from display " + r.getDisplayId() |
| 4814 | + " to main display for VR"); |
| 4815 | mRootActivityContainer.moveStackToDisplay( |
| 4816 | r.getStackId(), DEFAULT_DISPLAY, true /* toTop */); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4817 | } |
| 4818 | mH.post(() -> { |
| 4819 | if (!mVrController.onVrModeChanged(r)) { |
| 4820 | return; |
| 4821 | } |
| 4822 | synchronized (mGlobalLock) { |
| 4823 | final boolean disableNonVrUi = mVrController.shouldDisableNonVrUiLocked(); |
| 4824 | mWindowManager.disableNonVrUi(disableNonVrUi); |
| 4825 | if (disableNonVrUi) { |
| 4826 | // If we are in a VR mode where Picture-in-Picture mode is unsupported, |
| 4827 | // then remove the pinned stack. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4828 | mRootActivityContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4829 | } |
| 4830 | } |
| 4831 | }); |
| 4832 | } |
| 4833 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4834 | @Override |
| 4835 | public int getPackageScreenCompatMode(String packageName) { |
| 4836 | enforceNotIsolatedCaller("getPackageScreenCompatMode"); |
| 4837 | synchronized (mGlobalLock) { |
| 4838 | return mCompatModePackages.getPackageScreenCompatModeLocked(packageName); |
| 4839 | } |
| 4840 | } |
| 4841 | |
| 4842 | @Override |
| 4843 | public void setPackageScreenCompatMode(String packageName, int mode) { |
| 4844 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4845 | "setPackageScreenCompatMode"); |
| 4846 | synchronized (mGlobalLock) { |
| 4847 | mCompatModePackages.setPackageScreenCompatModeLocked(packageName, mode); |
| 4848 | } |
| 4849 | } |
| 4850 | |
| 4851 | @Override |
| 4852 | public boolean getPackageAskScreenCompat(String packageName) { |
| 4853 | enforceNotIsolatedCaller("getPackageAskScreenCompat"); |
| 4854 | synchronized (mGlobalLock) { |
| 4855 | return mCompatModePackages.getPackageAskCompatModeLocked(packageName); |
| 4856 | } |
| 4857 | } |
| 4858 | |
| 4859 | @Override |
| 4860 | public void setPackageAskScreenCompat(String packageName, boolean ask) { |
| 4861 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4862 | "setPackageAskScreenCompat"); |
| 4863 | synchronized (mGlobalLock) { |
| 4864 | mCompatModePackages.setPackageAskCompatModeLocked(packageName, ask); |
| 4865 | } |
| 4866 | } |
| 4867 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 4868 | public static String relaunchReasonToString(int relaunchReason) { |
| 4869 | switch (relaunchReason) { |
| 4870 | case RELAUNCH_REASON_WINDOWING_MODE_RESIZE: |
| 4871 | return "window_resize"; |
| 4872 | case RELAUNCH_REASON_FREE_RESIZE: |
| 4873 | return "free_resize"; |
| 4874 | default: |
| 4875 | return null; |
| 4876 | } |
| 4877 | } |
| 4878 | |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4879 | ActivityStack getTopDisplayFocusedStack() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4880 | return mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4881 | } |
| 4882 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4883 | /** Pokes the task persister. */ |
| 4884 | void notifyTaskPersisterLocked(TaskRecord task, boolean flush) { |
| 4885 | mRecentTasks.notifyTaskPersisterLocked(task, flush); |
| 4886 | } |
| 4887 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4888 | boolean isKeyguardLocked() { |
| 4889 | return mKeyguardController.isKeyguardLocked(); |
| 4890 | } |
| 4891 | |
Garfield Tan | 0154863 | 2018-11-27 10:15:48 -0800 | [diff] [blame] | 4892 | /** |
| 4893 | * Clears launch params for the given package. |
| 4894 | * @param packageNames the names of the packages of which the launch params are to be cleared |
| 4895 | */ |
| 4896 | @Override |
| 4897 | public void clearLaunchParamsForPackages(List<String> packageNames) { |
| 4898 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4899 | "clearLaunchParamsForPackages"); |
| 4900 | synchronized (mGlobalLock) { |
| 4901 | for (int i = 0; i < packageNames.size(); ++i) { |
| 4902 | mStackSupervisor.mLaunchParamsPersister.removeRecordForPackage(packageNames.get(i)); |
| 4903 | } |
| 4904 | } |
| 4905 | } |
| 4906 | |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 4907 | /** |
| 4908 | * Makes the display with the given id a single task instance display. I.e the display can only |
| 4909 | * contain one task. |
| 4910 | */ |
| 4911 | @Override |
| 4912 | public void setDisplayToSingleTaskInstance(int displayId) { |
| 4913 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4914 | "setDisplayToSingleTaskInstance"); |
| 4915 | final long origId = Binder.clearCallingIdentity(); |
| 4916 | try { |
| 4917 | final ActivityDisplay display = |
| 4918 | mRootActivityContainer.getActivityDisplayOrCreate(displayId); |
| 4919 | if (display != null) { |
| 4920 | display.setDisplayToSingleTaskInstance(); |
| 4921 | } |
| 4922 | } finally { |
| 4923 | Binder.restoreCallingIdentity(origId); |
| 4924 | } |
| 4925 | } |
| 4926 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4927 | void dumpLastANRLocked(PrintWriter pw) { |
| 4928 | pw.println("ACTIVITY MANAGER LAST ANR (dumpsys activity lastanr)"); |
| 4929 | if (mLastANRState == null) { |
| 4930 | pw.println(" <no ANR has occurred since boot>"); |
| 4931 | } else { |
| 4932 | pw.println(mLastANRState); |
| 4933 | } |
| 4934 | } |
| 4935 | |
| 4936 | void dumpLastANRTracesLocked(PrintWriter pw) { |
| 4937 | pw.println("ACTIVITY MANAGER LAST ANR TRACES (dumpsys activity lastanr-traces)"); |
| 4938 | |
| 4939 | final File[] files = new File(ANR_TRACE_DIR).listFiles(); |
| 4940 | if (ArrayUtils.isEmpty(files)) { |
| 4941 | pw.println(" <no ANR has occurred since boot>"); |
| 4942 | return; |
| 4943 | } |
| 4944 | // Find the latest file. |
| 4945 | File latest = null; |
| 4946 | for (File f : files) { |
| 4947 | if ((latest == null) || (latest.lastModified() < f.lastModified())) { |
| 4948 | latest = f; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4949 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4950 | } |
| 4951 | pw.print("File: "); |
| 4952 | pw.print(latest.getName()); |
| 4953 | pw.println(); |
| 4954 | try (BufferedReader in = new BufferedReader(new FileReader(latest))) { |
| 4955 | String line; |
| 4956 | while ((line = in.readLine()) != null) { |
| 4957 | pw.println(line); |
| 4958 | } |
| 4959 | } catch (IOException e) { |
| 4960 | pw.print("Unable to read: "); |
| 4961 | pw.print(e); |
| 4962 | pw.println(); |
| 4963 | } |
| 4964 | } |
| 4965 | |
| 4966 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4967 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 4968 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage, |
| 4969 | "ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)"); |
| 4970 | } |
| 4971 | |
| 4972 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4973 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage, String header) { |
| 4974 | pw.println(header); |
| 4975 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4976 | boolean printedAnything = mRootActivityContainer.dumpActivities(fd, pw, dumpAll, dumpClient, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4977 | dumpPackage); |
| 4978 | boolean needSep = printedAnything; |
| 4979 | |
| 4980 | boolean printed = ActivityStackSupervisor.printThisActivity(pw, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4981 | mRootActivityContainer.getTopResumedActivity(), dumpPackage, needSep, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4982 | " ResumedActivity: "); |
| 4983 | if (printed) { |
| 4984 | printedAnything = true; |
| 4985 | needSep = false; |
| 4986 | } |
| 4987 | |
| 4988 | if (dumpPackage == null) { |
| 4989 | if (needSep) { |
| 4990 | pw.println(); |
| 4991 | } |
| 4992 | printedAnything = true; |
| 4993 | mStackSupervisor.dump(pw, " "); |
| 4994 | } |
| 4995 | |
| 4996 | if (!printedAnything) { |
| 4997 | pw.println(" (nothing)"); |
| 4998 | } |
| 4999 | } |
| 5000 | |
| 5001 | void dumpActivityContainersLocked(PrintWriter pw) { |
| 5002 | pw.println("ACTIVITY MANAGER STARTER (dumpsys activity containers)"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5003 | mRootActivityContainer.dumpChildrenNames(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5004 | pw.println(" "); |
| 5005 | } |
| 5006 | |
| 5007 | void dumpActivityStarterLocked(PrintWriter pw, String dumpPackage) { |
| 5008 | pw.println("ACTIVITY MANAGER STARTER (dumpsys activity starter)"); |
| 5009 | getActivityStartController().dump(pw, "", dumpPackage); |
| 5010 | } |
| 5011 | |
| 5012 | /** |
| 5013 | * There are three things that cmd can be: |
| 5014 | * - a flattened component name that matches an existing activity |
| 5015 | * - the cmd arg isn't the flattened component name of an existing activity: |
| 5016 | * dump all activity whose component contains the cmd as a substring |
| 5017 | * - A hex number of the ActivityRecord object instance. |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5018 | * <p> |
| 5019 | * The caller should not hold lock when calling this method because it will wait for the |
| 5020 | * activities to complete the dump. |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5021 | * |
| 5022 | * @param dumpVisibleStacksOnly dump activity with {@param name} only if in a visible stack |
| 5023 | * @param dumpFocusedStackOnly dump activity with {@param name} only if in the focused stack |
| 5024 | */ |
| 5025 | protected boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, String[] args, |
| 5026 | int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, boolean dumpFocusedStackOnly) { |
| 5027 | ArrayList<ActivityRecord> activities; |
| 5028 | |
| 5029 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5030 | activities = mRootActivityContainer.getDumpActivities(name, dumpVisibleStacksOnly, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5031 | dumpFocusedStackOnly); |
| 5032 | } |
| 5033 | |
| 5034 | if (activities.size() <= 0) { |
| 5035 | return false; |
| 5036 | } |
| 5037 | |
| 5038 | String[] newArgs = new String[args.length - opti]; |
| 5039 | System.arraycopy(args, opti, newArgs, 0, args.length - opti); |
| 5040 | |
| 5041 | TaskRecord lastTask = null; |
| 5042 | boolean needSep = false; |
| 5043 | for (int i = activities.size() - 1; i >= 0; i--) { |
| 5044 | ActivityRecord r = activities.get(i); |
| 5045 | if (needSep) { |
| 5046 | pw.println(); |
| 5047 | } |
| 5048 | needSep = true; |
| 5049 | synchronized (mGlobalLock) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5050 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5051 | if (lastTask != task) { |
| 5052 | lastTask = task; |
| 5053 | pw.print("TASK "); pw.print(lastTask.affinity); |
| 5054 | pw.print(" id="); pw.print(lastTask.taskId); |
| 5055 | pw.print(" userId="); pw.println(lastTask.userId); |
| 5056 | if (dumpAll) { |
| 5057 | lastTask.dump(pw, " "); |
| 5058 | } |
| 5059 | } |
| 5060 | } |
| 5061 | dumpActivity(" ", fd, pw, activities.get(i), newArgs, dumpAll); |
| 5062 | } |
| 5063 | return true; |
| 5064 | } |
| 5065 | |
| 5066 | /** |
| 5067 | * Invokes IApplicationThread.dumpActivity() on the thread of the specified activity if |
| 5068 | * there is a thread associated with the activity. |
| 5069 | */ |
| 5070 | private void dumpActivity(String prefix, FileDescriptor fd, PrintWriter pw, |
| 5071 | final ActivityRecord r, String[] args, boolean dumpAll) { |
| 5072 | String innerPrefix = prefix + " "; |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5073 | IApplicationThread appThread = null; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5074 | synchronized (mGlobalLock) { |
| 5075 | pw.print(prefix); pw.print("ACTIVITY "); pw.print(r.shortComponentName); |
| 5076 | pw.print(" "); pw.print(Integer.toHexString(System.identityHashCode(r))); |
| 5077 | pw.print(" pid="); |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5078 | if (r.hasProcess()) { |
| 5079 | pw.println(r.app.getPid()); |
| 5080 | appThread = r.app.getThread(); |
| 5081 | } else { |
| 5082 | pw.println("(not running)"); |
| 5083 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5084 | if (dumpAll) { |
| 5085 | r.dump(pw, innerPrefix); |
| 5086 | } |
| 5087 | } |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5088 | if (appThread != null) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5089 | // flush anything that is already in the PrintWriter since the thread is going |
| 5090 | // to write to the file descriptor directly |
| 5091 | pw.flush(); |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5092 | try (TransferPipe tp = new TransferPipe()) { |
| 5093 | appThread.dumpActivity(tp.getWriteFd(), r.appToken, innerPrefix, args); |
| 5094 | tp.go(fd); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5095 | } catch (IOException e) { |
| 5096 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 5097 | } catch (RemoteException e) { |
| 5098 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 5099 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5100 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5101 | } |
| 5102 | |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 5103 | private void writeSleepStateToProto(ProtoOutputStream proto, int wakeFullness, |
| 5104 | boolean testPssMode) { |
| 5105 | final long sleepToken = proto.start(ActivityManagerServiceDumpProcessesProto.SLEEP_STATUS); |
| 5106 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.WAKEFULNESS, |
| 5107 | PowerManagerInternal.wakefulnessToProtoEnum(wakeFullness)); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5108 | for (ActivityTaskManagerInternal.SleepToken st : mRootActivityContainer.mSleepTokens) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5109 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEP_TOKENS, |
| 5110 | st.toString()); |
| 5111 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5112 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEPING, mSleeping); |
| 5113 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SHUTTING_DOWN, |
| 5114 | mShuttingDown); |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 5115 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.TEST_PSS_MODE, |
| 5116 | testPssMode); |
| 5117 | proto.end(sleepToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5118 | } |
| 5119 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5120 | int getCurrentUserId() { |
| 5121 | return mAmInternal.getCurrentUserId(); |
| 5122 | } |
| 5123 | |
| 5124 | private void enforceNotIsolatedCaller(String caller) { |
| 5125 | if (UserHandle.isIsolated(Binder.getCallingUid())) { |
| 5126 | throw new SecurityException("Isolated process not allowed to call " + caller); |
| 5127 | } |
| 5128 | } |
| 5129 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5130 | public Configuration getConfiguration() { |
| 5131 | Configuration ci; |
| 5132 | synchronized(mGlobalLock) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 5133 | ci = new Configuration(getGlobalConfigurationForCallingPid()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5134 | ci.userSetLocale = false; |
| 5135 | } |
| 5136 | return ci; |
| 5137 | } |
| 5138 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5139 | /** |
| 5140 | * Current global configuration information. Contains general settings for the entire system, |
| 5141 | * also corresponds to the merged configuration of the default display. |
| 5142 | */ |
| 5143 | Configuration getGlobalConfiguration() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5144 | return mRootActivityContainer.getConfiguration(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5145 | } |
| 5146 | |
| 5147 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5148 | boolean initLocale) { |
| 5149 | return updateConfigurationLocked(values, starting, initLocale, false /* deferResume */); |
| 5150 | } |
| 5151 | |
| 5152 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5153 | boolean initLocale, boolean deferResume) { |
| 5154 | // pass UserHandle.USER_NULL as userId because we don't persist configuration for any user |
| 5155 | return updateConfigurationLocked(values, starting, initLocale, false /* persistent */, |
| 5156 | UserHandle.USER_NULL, deferResume); |
| 5157 | } |
| 5158 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 5159 | public void updatePersistentConfiguration(Configuration values, @UserIdInt int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5160 | final long origId = Binder.clearCallingIdentity(); |
| 5161 | try { |
| 5162 | synchronized (mGlobalLock) { |
| 5163 | updateConfigurationLocked(values, null, false, true, userId, |
| 5164 | false /* deferResume */); |
| 5165 | } |
| 5166 | } finally { |
| 5167 | Binder.restoreCallingIdentity(origId); |
| 5168 | } |
| 5169 | } |
| 5170 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5171 | private boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5172 | boolean initLocale, boolean persistent, int userId, boolean deferResume) { |
| 5173 | return updateConfigurationLocked(values, starting, initLocale, persistent, userId, |
| 5174 | deferResume, null /* result */); |
| 5175 | } |
| 5176 | |
| 5177 | /** |
| 5178 | * Do either or both things: (1) change the current configuration, and (2) |
| 5179 | * make sure the given activity is running with the (now) current |
| 5180 | * configuration. Returns true if the activity has been left running, or |
| 5181 | * false if <var>starting</var> is being destroyed to match the new |
| 5182 | * configuration. |
| 5183 | * |
| 5184 | * @param userId is only used when persistent parameter is set to true to persist configuration |
| 5185 | * for that particular user |
| 5186 | */ |
| 5187 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5188 | boolean initLocale, boolean persistent, int userId, boolean deferResume, |
| 5189 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 5190 | int changes = 0; |
| 5191 | boolean kept = true; |
| 5192 | |
| 5193 | if (mWindowManager != null) { |
| 5194 | mWindowManager.deferSurfaceLayout(); |
| 5195 | } |
| 5196 | try { |
| 5197 | if (values != null) { |
| 5198 | changes = updateGlobalConfigurationLocked(values, initLocale, persistent, userId, |
| 5199 | deferResume); |
| 5200 | } |
| 5201 | |
| 5202 | kept = ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 5203 | } finally { |
| 5204 | if (mWindowManager != null) { |
| 5205 | mWindowManager.continueSurfaceLayout(); |
| 5206 | } |
| 5207 | } |
| 5208 | |
| 5209 | if (result != null) { |
| 5210 | result.changes = changes; |
| 5211 | result.activityRelaunched = !kept; |
| 5212 | } |
| 5213 | return kept; |
| 5214 | } |
| 5215 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5216 | /** Update default (global) configuration and notify listeners about changes. */ |
| 5217 | private int updateGlobalConfigurationLocked(@NonNull Configuration values, boolean initLocale, |
| 5218 | boolean persistent, int userId, boolean deferResume) { |
| 5219 | mTempConfig.setTo(getGlobalConfiguration()); |
| 5220 | final int changes = mTempConfig.updateFrom(values); |
| 5221 | if (changes == 0) { |
| 5222 | // Since calling to Activity.setRequestedOrientation leads to freezing the window with |
| 5223 | // setting WindowManagerService.mWaitingForConfig to true, it is important that we call |
| 5224 | // performDisplayOverrideConfigUpdate in order to send the new display configuration |
| 5225 | // (even if there are no actual changes) to unfreeze the window. |
| 5226 | performDisplayOverrideConfigUpdate(values, deferResume, DEFAULT_DISPLAY); |
| 5227 | return 0; |
| 5228 | } |
| 5229 | |
| 5230 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.i(TAG_CONFIGURATION, |
| 5231 | "Updating global configuration to: " + values); |
| 5232 | |
| 5233 | EventLog.writeEvent(EventLogTags.CONFIGURATION_CHANGED, changes); |
| 5234 | StatsLog.write(StatsLog.RESOURCE_CONFIGURATION_CHANGED, |
| 5235 | values.colorMode, |
| 5236 | values.densityDpi, |
| 5237 | values.fontScale, |
| 5238 | values.hardKeyboardHidden, |
| 5239 | values.keyboard, |
| 5240 | values.keyboardHidden, |
| 5241 | values.mcc, |
| 5242 | values.mnc, |
| 5243 | values.navigation, |
| 5244 | values.navigationHidden, |
| 5245 | values.orientation, |
| 5246 | values.screenHeightDp, |
| 5247 | values.screenLayout, |
| 5248 | values.screenWidthDp, |
| 5249 | values.smallestScreenWidthDp, |
| 5250 | values.touchscreen, |
| 5251 | values.uiMode); |
| 5252 | |
| 5253 | |
| 5254 | if (!initLocale && !values.getLocales().isEmpty() && values.userSetLocale) { |
| 5255 | final LocaleList locales = values.getLocales(); |
| 5256 | int bestLocaleIndex = 0; |
| 5257 | if (locales.size() > 1) { |
| 5258 | if (mSupportedSystemLocales == null) { |
| 5259 | mSupportedSystemLocales = Resources.getSystem().getAssets().getLocales(); |
| 5260 | } |
| 5261 | bestLocaleIndex = Math.max(0, locales.getFirstMatchIndex(mSupportedSystemLocales)); |
| 5262 | } |
| 5263 | SystemProperties.set("persist.sys.locale", |
| 5264 | locales.get(bestLocaleIndex).toLanguageTag()); |
| 5265 | LocaleList.setDefault(locales, bestLocaleIndex); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5266 | |
| 5267 | final Message m = PooledLambda.obtainMessage( |
| 5268 | ActivityTaskManagerService::sendLocaleToMountDaemonMsg, this, |
| 5269 | locales.get(bestLocaleIndex)); |
| 5270 | mH.sendMessage(m); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5271 | } |
| 5272 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 5273 | mTempConfig.seq = increaseConfigurationSeqLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5274 | |
| 5275 | // Update stored global config and notify everyone about the change. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5276 | mRootActivityContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5277 | |
| 5278 | Slog.i(TAG, "Config changes=" + Integer.toHexString(changes) + " " + mTempConfig); |
| 5279 | // TODO(multi-display): Update UsageEvents#Event to include displayId. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5280 | mUsageStatsInternal.reportConfigurationChange(mTempConfig, mAmInternal.getCurrentUserId()); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5281 | |
| 5282 | // 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] | 5283 | updateShouldShowDialogsLocked(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5284 | |
| 5285 | AttributeCache ac = AttributeCache.instance(); |
| 5286 | if (ac != null) { |
| 5287 | ac.updateConfiguration(mTempConfig); |
| 5288 | } |
| 5289 | |
| 5290 | // Make sure all resources in our process are updated right now, so that anyone who is going |
| 5291 | // to retrieve resource values after we return will be sure to get the new ones. This is |
| 5292 | // especially important during boot, where the first config change needs to guarantee all |
| 5293 | // resources have that config before following boot code is executed. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5294 | mSystemThread.applyConfigurationToResources(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5295 | |
| 5296 | // We need another copy of global config because we're scheduling some calls instead of |
| 5297 | // running them in place. We need to be sure that object we send will be handled unchanged. |
| 5298 | final Configuration configCopy = new Configuration(mTempConfig); |
| 5299 | if (persistent && Settings.System.hasInterestingConfigurationChanges(changes)) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5300 | final Message msg = PooledLambda.obtainMessage( |
| 5301 | ActivityTaskManagerService::sendPutConfigurationForUserMsg, |
| 5302 | this, userId, configCopy); |
| 5303 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5304 | } |
| 5305 | |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 5306 | SparseArray<WindowProcessController> pidMap = mProcessMap.getPidMap(); |
| 5307 | for (int i = pidMap.size() - 1; i >= 0; i--) { |
| 5308 | final int pid = pidMap.keyAt(i); |
| 5309 | final WindowProcessController app = pidMap.get(pid); |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 5310 | if (DEBUG_CONFIGURATION) { |
| 5311 | Slog.v(TAG_CONFIGURATION, "Update process config of " |
| 5312 | + app.mName + " to new config " + configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5313 | } |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 5314 | app.onConfigurationChanged(configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5315 | } |
| 5316 | |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 5317 | final Message msg = PooledLambda.obtainMessage( |
| 5318 | ActivityManagerInternal::broadcastGlobalConfigurationChanged, |
| 5319 | mAmInternal, changes, initLocale); |
| 5320 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5321 | |
| 5322 | // Override configuration of the default display duplicates global config, so we need to |
| 5323 | // update it also. This will also notify WindowManager about changes. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5324 | performDisplayOverrideConfigUpdate(mRootActivityContainer.getConfiguration(), deferResume, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5325 | DEFAULT_DISPLAY); |
| 5326 | |
| 5327 | return changes; |
| 5328 | } |
| 5329 | |
| 5330 | boolean updateDisplayOverrideConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5331 | boolean deferResume, int displayId) { |
| 5332 | return updateDisplayOverrideConfigurationLocked(values, starting, deferResume /* deferResume */, |
| 5333 | displayId, null /* result */); |
| 5334 | } |
| 5335 | |
| 5336 | /** |
| 5337 | * Updates override configuration specific for the selected display. If no config is provided, |
| 5338 | * new one will be computed in WM based on current display info. |
| 5339 | */ |
| 5340 | boolean updateDisplayOverrideConfigurationLocked(Configuration values, |
| 5341 | ActivityRecord starting, boolean deferResume, int displayId, |
| 5342 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 5343 | int changes = 0; |
| 5344 | boolean kept = true; |
| 5345 | |
| 5346 | if (mWindowManager != null) { |
| 5347 | mWindowManager.deferSurfaceLayout(); |
| 5348 | } |
| 5349 | try { |
| 5350 | if (values != null) { |
| 5351 | if (displayId == DEFAULT_DISPLAY) { |
| 5352 | // Override configuration of the default display duplicates global config, so |
| 5353 | // we're calling global config update instead for default display. It will also |
| 5354 | // apply the correct override config. |
| 5355 | changes = updateGlobalConfigurationLocked(values, false /* initLocale */, |
| 5356 | false /* persistent */, UserHandle.USER_NULL /* userId */, deferResume); |
| 5357 | } else { |
| 5358 | changes = performDisplayOverrideConfigUpdate(values, deferResume, displayId); |
| 5359 | } |
| 5360 | } |
| 5361 | |
| 5362 | kept = ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 5363 | } finally { |
| 5364 | if (mWindowManager != null) { |
| 5365 | mWindowManager.continueSurfaceLayout(); |
| 5366 | } |
| 5367 | } |
| 5368 | |
| 5369 | if (result != null) { |
| 5370 | result.changes = changes; |
| 5371 | result.activityRelaunched = !kept; |
| 5372 | } |
| 5373 | return kept; |
| 5374 | } |
| 5375 | |
| 5376 | private int performDisplayOverrideConfigUpdate(Configuration values, boolean deferResume, |
| 5377 | int displayId) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5378 | mTempConfig.setTo(mRootActivityContainer.getDisplayOverrideConfiguration(displayId)); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5379 | final int changes = mTempConfig.updateFrom(values); |
| 5380 | if (changes != 0) { |
| 5381 | Slog.i(TAG, "Override config changes=" + Integer.toHexString(changes) + " " |
| 5382 | + mTempConfig + " for displayId=" + displayId); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5383 | mRootActivityContainer.setDisplayOverrideConfiguration(mTempConfig, displayId); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5384 | |
| 5385 | final boolean isDensityChange = (changes & ActivityInfo.CONFIG_DENSITY) != 0; |
| 5386 | if (isDensityChange && displayId == DEFAULT_DISPLAY) { |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 5387 | mAppWarnings.onDensityChanged(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5388 | |
Wale Ogunwale | 5c91870 | 2018-10-18 11:06:33 -0700 | [diff] [blame] | 5389 | // Post message to start process to avoid possible deadlock of calling into AMS with |
| 5390 | // the ATMS lock held. |
| 5391 | final Message msg = PooledLambda.obtainMessage( |
| 5392 | ActivityManagerInternal::killAllBackgroundProcessesExcept, mAmInternal, |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 5393 | N, ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND); |
Wale Ogunwale | 5c91870 | 2018-10-18 11:06:33 -0700 | [diff] [blame] | 5394 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5395 | } |
| 5396 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5397 | return changes; |
| 5398 | } |
| 5399 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5400 | private void updateEventDispatchingLocked(boolean booted) { |
| 5401 | mWindowManager.setEventDispatching(booted && !mShuttingDown); |
| 5402 | } |
| 5403 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5404 | private void sendPutConfigurationForUserMsg(int userId, Configuration config) { |
| 5405 | final ContentResolver resolver = mContext.getContentResolver(); |
| 5406 | Settings.System.putConfigurationForUser(resolver, config, userId); |
| 5407 | } |
| 5408 | |
| 5409 | private void sendLocaleToMountDaemonMsg(Locale l) { |
| 5410 | try { |
| 5411 | IBinder service = ServiceManager.getService("mount"); |
| 5412 | IStorageManager storageManager = IStorageManager.Stub.asInterface(service); |
| 5413 | Log.d(TAG, "Storing locale " + l.toLanguageTag() + " for decryption UI"); |
| 5414 | storageManager.setField(StorageManager.SYSTEM_LOCALE_KEY, l.toLanguageTag()); |
| 5415 | } catch (RemoteException e) { |
| 5416 | Log.e(TAG, "Error storing locale for decryption UI", e); |
| 5417 | } |
| 5418 | } |
| 5419 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5420 | private void expireStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5421 | mStartActivitySources.remove(permissionToken); |
| 5422 | mExpiredStartAsCallerTokens.add(permissionToken); |
| 5423 | } |
| 5424 | |
| 5425 | private void forgetStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5426 | mExpiredStartAsCallerTokens.remove(permissionToken); |
| 5427 | } |
| 5428 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5429 | boolean isActivityStartsLoggingEnabled() { |
| 5430 | return mAmInternal.isActivityStartsLoggingEnabled(); |
| 5431 | } |
| 5432 | |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 5433 | boolean isBackgroundActivityStartsEnabled() { |
| 5434 | return mAmInternal.isBackgroundActivityStartsEnabled(); |
| 5435 | } |
| 5436 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5437 | void enableScreenAfterBoot(boolean booted) { |
| 5438 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_ENABLE_SCREEN, |
| 5439 | SystemClock.uptimeMillis()); |
| 5440 | mWindowManager.enableScreenAfterBoot(); |
| 5441 | |
| 5442 | synchronized (mGlobalLock) { |
| 5443 | updateEventDispatchingLocked(booted); |
| 5444 | } |
| 5445 | } |
| 5446 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5447 | static long getInputDispatchingTimeoutLocked(ActivityRecord r) { |
| 5448 | if (r == null || !r.hasProcess()) { |
| 5449 | return KEY_DISPATCHING_TIMEOUT_MS; |
| 5450 | } |
| 5451 | return getInputDispatchingTimeoutLocked(r.app); |
| 5452 | } |
| 5453 | |
| 5454 | private static long getInputDispatchingTimeoutLocked(WindowProcessController r) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 5455 | return r != null ? r.getInputDispatchingTimeout() : KEY_DISPATCHING_TIMEOUT_MS; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5456 | } |
| 5457 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5458 | /** |
| 5459 | * Decide based on the configuration whether we should show the ANR, |
| 5460 | * crash, etc dialogs. The idea is that if there is no affordance to |
| 5461 | * press the on-screen buttons, or the user experience would be more |
| 5462 | * greatly impacted than the crash itself, we shouldn't show the dialog. |
| 5463 | * |
| 5464 | * A thought: SystemUI might also want to get told about this, the Power |
| 5465 | * dialog / global actions also might want different behaviors. |
| 5466 | */ |
| 5467 | private void updateShouldShowDialogsLocked(Configuration config) { |
| 5468 | final boolean inputMethodExists = !(config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 5469 | && config.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH |
| 5470 | && config.navigation == Configuration.NAVIGATION_NONAV); |
| 5471 | int modeType = config.uiMode & Configuration.UI_MODE_TYPE_MASK; |
| 5472 | final boolean uiModeSupportsDialogs = (modeType != Configuration.UI_MODE_TYPE_CAR |
| 5473 | && !(modeType == Configuration.UI_MODE_TYPE_WATCH && Build.IS_USER) |
| 5474 | && modeType != Configuration.UI_MODE_TYPE_TELEVISION |
| 5475 | && modeType != Configuration.UI_MODE_TYPE_VR_HEADSET); |
| 5476 | final boolean hideDialogsSet = Settings.Global.getInt(mContext.getContentResolver(), |
| 5477 | HIDE_ERROR_DIALOGS, 0) != 0; |
| 5478 | mShowDialogs = inputMethodExists && uiModeSupportsDialogs && !hideDialogsSet; |
| 5479 | } |
| 5480 | |
| 5481 | private void updateFontScaleIfNeeded(@UserIdInt int userId) { |
| 5482 | final float scaleFactor = Settings.System.getFloatForUser(mContext.getContentResolver(), |
| 5483 | FONT_SCALE, 1.0f, userId); |
| 5484 | |
| 5485 | synchronized (this) { |
| 5486 | if (getGlobalConfiguration().fontScale == scaleFactor) { |
| 5487 | return; |
| 5488 | } |
| 5489 | |
| 5490 | final Configuration configuration |
| 5491 | = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
| 5492 | configuration.fontScale = scaleFactor; |
| 5493 | updatePersistentConfiguration(configuration, userId); |
| 5494 | } |
| 5495 | } |
| 5496 | |
| 5497 | // Actually is sleeping or shutting down or whatever else in the future |
| 5498 | // is an inactive state. |
| 5499 | boolean isSleepingOrShuttingDownLocked() { |
| 5500 | return isSleepingLocked() || mShuttingDown; |
| 5501 | } |
| 5502 | |
| 5503 | boolean isSleepingLocked() { |
| 5504 | return mSleeping; |
| 5505 | } |
| 5506 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5507 | /** Update AMS states when an activity is resumed. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5508 | void setResumedActivityUncheckLocked(ActivityRecord r, String reason) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5509 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5510 | if (task.isActivityTypeStandard()) { |
| 5511 | if (mCurAppTimeTracker != r.appTimeTracker) { |
| 5512 | // We are switching app tracking. Complete the current one. |
| 5513 | if (mCurAppTimeTracker != null) { |
| 5514 | mCurAppTimeTracker.stop(); |
| 5515 | mH.obtainMessage( |
| 5516 | REPORT_TIME_TRACKER_MSG, mCurAppTimeTracker).sendToTarget(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5517 | mRootActivityContainer.clearOtherAppTimeTrackers(r.appTimeTracker); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5518 | mCurAppTimeTracker = null; |
| 5519 | } |
| 5520 | if (r.appTimeTracker != null) { |
| 5521 | mCurAppTimeTracker = r.appTimeTracker; |
| 5522 | startTimeTrackingFocusedActivityLocked(); |
| 5523 | } |
| 5524 | } else { |
| 5525 | startTimeTrackingFocusedActivityLocked(); |
| 5526 | } |
| 5527 | } else { |
| 5528 | r.appTimeTracker = null; |
| 5529 | } |
| 5530 | // TODO: VI Maybe r.task.voiceInteractor || r.voiceInteractor != null |
| 5531 | // TODO: Probably not, because we don't want to resume voice on switching |
| 5532 | // back to this activity |
| 5533 | if (task.voiceInteractor != null) { |
| 5534 | startRunningVoiceLocked(task.voiceSession, r.info.applicationInfo.uid); |
| 5535 | } else { |
| 5536 | finishRunningVoiceLocked(); |
| 5537 | |
| 5538 | if (mLastResumedActivity != null) { |
| 5539 | final IVoiceInteractionSession session; |
| 5540 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5541 | final TaskRecord lastResumedActivityTask = mLastResumedActivity.getTaskRecord(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5542 | if (lastResumedActivityTask != null |
| 5543 | && lastResumedActivityTask.voiceSession != null) { |
| 5544 | session = lastResumedActivityTask.voiceSession; |
| 5545 | } else { |
| 5546 | session = mLastResumedActivity.voiceSession; |
| 5547 | } |
| 5548 | |
| 5549 | if (session != null) { |
| 5550 | // We had been in a voice interaction session, but now focused has |
| 5551 | // move to something different. Just finish the session, we can't |
| 5552 | // return to it and retain the proper state and synchronization with |
| 5553 | // the voice interaction service. |
| 5554 | finishVoiceTask(session); |
| 5555 | } |
| 5556 | } |
| 5557 | } |
| 5558 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5559 | if (mLastResumedActivity != null && r.mUserId != mLastResumedActivity.mUserId) { |
| 5560 | mAmInternal.sendForegroundProfileChanged(r.mUserId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5561 | } |
| 5562 | updateResumedAppTrace(r); |
| 5563 | mLastResumedActivity = r; |
| 5564 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 5565 | r.getDisplay().setFocusedApp(r, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5566 | |
| 5567 | applyUpdateLockStateLocked(r); |
| 5568 | applyUpdateVrModeLocked(r); |
| 5569 | |
| 5570 | EventLogTags.writeAmSetResumedActivity( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5571 | r == null ? -1 : r.mUserId, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5572 | r == null ? "NULL" : r.shortComponentName, |
| 5573 | reason); |
| 5574 | } |
| 5575 | |
| 5576 | ActivityTaskManagerInternal.SleepToken acquireSleepToken(String tag, int displayId) { |
| 5577 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5578 | final ActivityTaskManagerInternal.SleepToken token = |
| 5579 | mRootActivityContainer.createSleepToken(tag, displayId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5580 | updateSleepIfNeededLocked(); |
| 5581 | return token; |
| 5582 | } |
| 5583 | } |
| 5584 | |
| 5585 | void updateSleepIfNeededLocked() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5586 | final boolean shouldSleep = !mRootActivityContainer.hasAwakeDisplay(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5587 | final boolean wasSleeping = mSleeping; |
| 5588 | boolean updateOomAdj = false; |
| 5589 | |
| 5590 | if (!shouldSleep) { |
| 5591 | // If wasSleeping is true, we need to wake up activity manager state from when |
| 5592 | // we started sleeping. In either case, we need to apply the sleep tokens, which |
| 5593 | // will wake up stacks or put them to sleep as appropriate. |
| 5594 | if (wasSleeping) { |
| 5595 | mSleeping = false; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 5596 | StatsLog.write(StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5597 | StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__AWAKE); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5598 | startTimeTrackingFocusedActivityLocked(); |
| 5599 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
Varun Shah | 98694fb | 2019-04-11 09:28:27 -0700 | [diff] [blame] | 5600 | Slog.d(TAG, "Top Process State changed to PROCESS_STATE_TOP"); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5601 | mStackSupervisor.comeOutOfSleepIfNeededLocked(); |
| 5602 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5603 | mRootActivityContainer.applySleepTokens(true /* applyToStacks */); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5604 | if (wasSleeping) { |
| 5605 | updateOomAdj = true; |
| 5606 | } |
| 5607 | } else if (!mSleeping && shouldSleep) { |
| 5608 | mSleeping = true; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 5609 | StatsLog.write(StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5610 | StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__ASLEEP); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5611 | if (mCurAppTimeTracker != null) { |
| 5612 | mCurAppTimeTracker.stop(); |
| 5613 | } |
| 5614 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP_SLEEPING; |
Varun Shah | 98694fb | 2019-04-11 09:28:27 -0700 | [diff] [blame] | 5615 | Slog.d(TAG, "Top Process State changed to PROCESS_STATE_TOP_SLEEPING"); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5616 | mStackSupervisor.goingToSleepLocked(); |
| 5617 | updateResumedAppTrace(null /* resumed */); |
| 5618 | updateOomAdj = true; |
| 5619 | } |
| 5620 | if (updateOomAdj) { |
| 5621 | mH.post(mAmInternal::updateOomAdj); |
| 5622 | } |
| 5623 | } |
| 5624 | |
| 5625 | void updateOomAdj() { |
| 5626 | mH.post(mAmInternal::updateOomAdj); |
| 5627 | } |
| 5628 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5629 | void updateCpuStats() { |
| 5630 | mH.post(mAmInternal::updateCpuStats); |
| 5631 | } |
| 5632 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5633 | void updateBatteryStats(ActivityRecord component, boolean resumed) { |
| 5634 | final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::updateBatteryStats, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5635 | mAmInternal, component.mActivityComponent, component.app.mUid, component.mUserId, |
| 5636 | resumed); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5637 | mH.sendMessage(m); |
| 5638 | } |
| 5639 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5640 | void updateActivityUsageStats(ActivityRecord activity, int event) { |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5641 | ComponentName taskRoot = null; |
| 5642 | final TaskRecord task = activity.getTaskRecord(); |
| 5643 | if (task != null) { |
| 5644 | final ActivityRecord rootActivity = task.getRootActivity(); |
| 5645 | if (rootActivity != null) { |
| 5646 | taskRoot = rootActivity.mActivityComponent; |
| 5647 | } |
| 5648 | } |
| 5649 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5650 | final Message m = PooledLambda.obtainMessage( |
| 5651 | ActivityManagerInternal::updateActivityUsageStats, mAmInternal, |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5652 | activity.mActivityComponent, activity.mUserId, event, activity.appToken, taskRoot); |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5653 | mH.sendMessage(m); |
| 5654 | } |
| 5655 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5656 | void setBooting(boolean booting) { |
| 5657 | mAmInternal.setBooting(booting); |
| 5658 | } |
| 5659 | |
| 5660 | boolean isBooting() { |
| 5661 | return mAmInternal.isBooting(); |
| 5662 | } |
| 5663 | |
| 5664 | void setBooted(boolean booted) { |
| 5665 | mAmInternal.setBooted(booted); |
| 5666 | } |
| 5667 | |
| 5668 | boolean isBooted() { |
| 5669 | return mAmInternal.isBooted(); |
| 5670 | } |
| 5671 | |
| 5672 | void postFinishBooting(boolean finishBooting, boolean enableScreen) { |
| 5673 | mH.post(() -> { |
| 5674 | if (finishBooting) { |
| 5675 | mAmInternal.finishBooting(); |
| 5676 | } |
| 5677 | if (enableScreen) { |
| 5678 | mInternal.enableScreenAfterBoot(isBooted()); |
| 5679 | } |
| 5680 | }); |
| 5681 | } |
| 5682 | |
| 5683 | void setHeavyWeightProcess(ActivityRecord root) { |
| 5684 | mHeavyWeightProcess = root.app; |
| 5685 | final Message m = PooledLambda.obtainMessage( |
| 5686 | ActivityTaskManagerService::postHeavyWeightProcessNotification, this, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5687 | root.app, root.intent, root.mUserId); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5688 | mH.sendMessage(m); |
| 5689 | } |
| 5690 | |
| 5691 | void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
| 5692 | if (mHeavyWeightProcess == null || mHeavyWeightProcess != proc) { |
| 5693 | return; |
| 5694 | } |
| 5695 | |
| 5696 | mHeavyWeightProcess = null; |
| 5697 | final Message m = PooledLambda.obtainMessage( |
| 5698 | ActivityTaskManagerService::cancelHeavyWeightProcessNotification, this, |
| 5699 | proc.mUserId); |
| 5700 | mH.sendMessage(m); |
| 5701 | } |
| 5702 | |
| 5703 | private void cancelHeavyWeightProcessNotification(int userId) { |
| 5704 | final INotificationManager inm = NotificationManager.getService(); |
| 5705 | if (inm == null) { |
| 5706 | return; |
| 5707 | } |
| 5708 | try { |
| 5709 | inm.cancelNotificationWithTag("android", null, |
| 5710 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, userId); |
| 5711 | } catch (RuntimeException e) { |
| 5712 | Slog.w(TAG, "Error canceling notification for service", e); |
| 5713 | } catch (RemoteException e) { |
| 5714 | } |
| 5715 | |
| 5716 | } |
| 5717 | |
| 5718 | private void postHeavyWeightProcessNotification( |
| 5719 | WindowProcessController proc, Intent intent, int userId) { |
| 5720 | if (proc == null) { |
| 5721 | return; |
| 5722 | } |
| 5723 | |
| 5724 | final INotificationManager inm = NotificationManager.getService(); |
| 5725 | if (inm == null) { |
| 5726 | return; |
| 5727 | } |
| 5728 | |
| 5729 | try { |
| 5730 | Context context = mContext.createPackageContext(proc.mInfo.packageName, 0); |
| 5731 | String text = mContext.getString(R.string.heavy_weight_notification, |
| 5732 | context.getApplicationInfo().loadLabel(context.getPackageManager())); |
| 5733 | Notification notification = |
| 5734 | new Notification.Builder(context, |
| 5735 | SystemNotificationChannels.HEAVY_WEIGHT_APP) |
| 5736 | .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) |
| 5737 | .setWhen(0) |
| 5738 | .setOngoing(true) |
| 5739 | .setTicker(text) |
| 5740 | .setColor(mContext.getColor( |
| 5741 | com.android.internal.R.color.system_notification_accent_color)) |
| 5742 | .setContentTitle(text) |
| 5743 | .setContentText( |
| 5744 | mContext.getText(R.string.heavy_weight_notification_detail)) |
| 5745 | .setContentIntent(PendingIntent.getActivityAsUser(mContext, 0, |
| 5746 | intent, PendingIntent.FLAG_CANCEL_CURRENT, null, |
| 5747 | new UserHandle(userId))) |
| 5748 | .build(); |
| 5749 | try { |
| 5750 | inm.enqueueNotificationWithTag("android", "android", null, |
| 5751 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, notification, userId); |
| 5752 | } catch (RuntimeException e) { |
| 5753 | Slog.w(TAG, "Error showing notification for heavy-weight app", e); |
| 5754 | } catch (RemoteException e) { |
| 5755 | } |
| 5756 | } catch (PackageManager.NameNotFoundException e) { |
| 5757 | Slog.w(TAG, "Unable to create context for heavy notification", e); |
| 5758 | } |
| 5759 | |
| 5760 | } |
| 5761 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5762 | IIntentSender getIntentSenderLocked(int type, String packageName, int callingUid, int userId, |
| 5763 | IBinder token, String resultWho, int requestCode, Intent[] intents, |
| 5764 | String[] resolvedTypes, int flags, Bundle bOptions) { |
| 5765 | |
| 5766 | ActivityRecord activity = null; |
| 5767 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5768 | activity = ActivityRecord.isInStackLocked(token); |
| 5769 | if (activity == null) { |
| 5770 | Slog.w(TAG, "Failed createPendingResult: activity " + token + " not in any stack"); |
| 5771 | return null; |
| 5772 | } |
| 5773 | if (activity.finishing) { |
| 5774 | Slog.w(TAG, "Failed createPendingResult: activity " + activity + " is finishing"); |
| 5775 | return null; |
| 5776 | } |
| 5777 | } |
| 5778 | |
| 5779 | final PendingIntentRecord rec = mPendingIntentController.getIntentSender(type, packageName, |
| 5780 | callingUid, userId, token, resultWho, requestCode, intents, resolvedTypes, flags, |
| 5781 | bOptions); |
| 5782 | final boolean noCreate = (flags & PendingIntent.FLAG_NO_CREATE) != 0; |
| 5783 | if (noCreate) { |
| 5784 | return rec; |
| 5785 | } |
| 5786 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5787 | if (activity.pendingResults == null) { |
| 5788 | activity.pendingResults = new HashSet<>(); |
| 5789 | } |
| 5790 | activity.pendingResults.add(rec.ref); |
| 5791 | } |
| 5792 | return rec; |
| 5793 | } |
| 5794 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 5795 | // 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] | 5796 | private void startTimeTrackingFocusedActivityLocked() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5797 | final ActivityRecord resumedActivity = mRootActivityContainer.getTopResumedActivity(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5798 | if (!mSleeping && mCurAppTimeTracker != null && resumedActivity != null) { |
| 5799 | mCurAppTimeTracker.start(resumedActivity.packageName); |
| 5800 | } |
| 5801 | } |
| 5802 | |
| 5803 | private void updateResumedAppTrace(@Nullable ActivityRecord resumed) { |
| 5804 | if (mTracedResumedActivity != null) { |
| 5805 | Trace.asyncTraceEnd(TRACE_TAG_ACTIVITY_MANAGER, |
| 5806 | constructResumedTraceName(mTracedResumedActivity.packageName), 0); |
| 5807 | } |
| 5808 | if (resumed != null) { |
| 5809 | Trace.asyncTraceBegin(TRACE_TAG_ACTIVITY_MANAGER, |
| 5810 | constructResumedTraceName(resumed.packageName), 0); |
| 5811 | } |
| 5812 | mTracedResumedActivity = resumed; |
| 5813 | } |
| 5814 | |
| 5815 | private String constructResumedTraceName(String packageName) { |
| 5816 | return "focused app: " + packageName; |
| 5817 | } |
| 5818 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5819 | /** Applies latest configuration and/or visibility updates if needed. */ |
| 5820 | private boolean ensureConfigAndVisibilityAfterUpdate(ActivityRecord starting, int changes) { |
| 5821 | boolean kept = true; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5822 | final ActivityStack mainStack = mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5823 | // mainStack is null during startup. |
| 5824 | if (mainStack != null) { |
| 5825 | if (changes != 0 && starting == null) { |
| 5826 | // If the configuration changed, and the caller is not already |
| 5827 | // in the process of starting an activity, then find the top |
| 5828 | // activity to check if its configuration needs to change. |
| 5829 | starting = mainStack.topRunningActivityLocked(); |
| 5830 | } |
| 5831 | |
| 5832 | if (starting != null) { |
| 5833 | kept = starting.ensureActivityConfiguration(changes, |
| 5834 | false /* preserveWindow */); |
| 5835 | // And we need to make sure at this point that all other activities |
| 5836 | // are made visible with the correct configuration. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5837 | mRootActivityContainer.ensureActivitiesVisible(starting, changes, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5838 | !PRESERVE_WINDOWS); |
| 5839 | } |
| 5840 | } |
| 5841 | |
| 5842 | return kept; |
| 5843 | } |
| 5844 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5845 | void scheduleAppGcsLocked() { |
| 5846 | mH.post(() -> mAmInternal.scheduleAppGcs()); |
| 5847 | } |
| 5848 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5849 | CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) { |
| 5850 | return mCompatModePackages.compatibilityInfoForPackageLocked(ai); |
| 5851 | } |
| 5852 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5853 | /** |
| 5854 | * Returns the PackageManager. Used by classes hosted by {@link ActivityTaskManagerService}. The |
| 5855 | * PackageManager could be unavailable at construction time and therefore needs to be accessed |
| 5856 | * on demand. |
| 5857 | */ |
| 5858 | IPackageManager getPackageManager() { |
| 5859 | return AppGlobals.getPackageManager(); |
| 5860 | } |
| 5861 | |
| 5862 | PackageManagerInternal getPackageManagerInternalLocked() { |
| 5863 | if (mPmInternal == null) { |
| 5864 | mPmInternal = LocalServices.getService(PackageManagerInternal.class); |
| 5865 | } |
| 5866 | return mPmInternal; |
| 5867 | } |
| 5868 | |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 5869 | PermissionPolicyInternal getPermissionPolicyInternal() { |
| 5870 | if (mPermissionPolicyInternal == null) { |
| 5871 | mPermissionPolicyInternal = LocalServices.getService(PermissionPolicyInternal.class); |
| 5872 | } |
| 5873 | return mPermissionPolicyInternal; |
| 5874 | } |
| 5875 | |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 5876 | AppWarnings getAppWarningsLocked() { |
| 5877 | return mAppWarnings; |
| 5878 | } |
| 5879 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5880 | Intent getHomeIntent() { |
| 5881 | Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null); |
| 5882 | intent.setComponent(mTopComponent); |
| 5883 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5884 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5885 | intent.addCategory(Intent.CATEGORY_HOME); |
| 5886 | } |
| 5887 | return intent; |
| 5888 | } |
| 5889 | |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5890 | /** |
| 5891 | * Return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} to resolve secondary home |
| 5892 | * activities. |
| 5893 | * |
| 5894 | * @param preferredPackage Specify a preferred package name, otherwise use secondary home |
| 5895 | * component defined in config_secondaryHomeComponent. |
| 5896 | * @return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} |
| 5897 | */ |
| 5898 | Intent getSecondaryHomeIntent(String preferredPackage) { |
| 5899 | 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] | 5900 | final boolean useSystemProvidedLauncher = mContext.getResources().getBoolean( |
| 5901 | com.android.internal.R.bool.config_useSystemProvidedLauncherForSecondary); |
| 5902 | if (preferredPackage == null || useSystemProvidedLauncher) { |
| 5903 | // Using the component stored in config if no package name or forced. |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5904 | final String secondaryHomeComponent = mContext.getResources().getString( |
| 5905 | com.android.internal.R.string.config_secondaryHomeComponent); |
| 5906 | intent.setComponent(ComponentName.unflattenFromString(secondaryHomeComponent)); |
| 5907 | } else { |
| 5908 | intent.setPackage(preferredPackage); |
| 5909 | } |
| 5910 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5911 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5912 | intent.addCategory(Intent.CATEGORY_SECONDARY_HOME); |
| 5913 | } |
| 5914 | return intent; |
| 5915 | } |
| 5916 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5917 | ApplicationInfo getAppInfoForUser(ApplicationInfo info, int userId) { |
| 5918 | if (info == null) return null; |
| 5919 | ApplicationInfo newInfo = new ApplicationInfo(info); |
| 5920 | newInfo.initForUser(userId); |
| 5921 | return newInfo; |
| 5922 | } |
| 5923 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 5924 | WindowProcessController getProcessController(String processName, int uid) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5925 | if (uid == SYSTEM_UID) { |
| 5926 | // The system gets to run in any process. If there are multiple processes with the same |
| 5927 | // uid, just pick the first (this should never happen). |
| 5928 | final SparseArray<WindowProcessController> procs = |
| 5929 | mProcessNames.getMap().get(processName); |
| 5930 | if (procs == null) return null; |
| 5931 | final int procCount = procs.size(); |
| 5932 | for (int i = 0; i < procCount; i++) { |
| 5933 | final int procUid = procs.keyAt(i); |
| 5934 | if (UserHandle.isApp(procUid) || !UserHandle.isSameUser(procUid, uid)) { |
| 5935 | // Don't use an app process or different user process for system component. |
| 5936 | continue; |
| 5937 | } |
| 5938 | return procs.valueAt(i); |
| 5939 | } |
| 5940 | } |
| 5941 | |
| 5942 | return mProcessNames.get(processName, uid); |
| 5943 | } |
| 5944 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5945 | WindowProcessController getProcessController(IApplicationThread thread) { |
| 5946 | if (thread == null) { |
| 5947 | return null; |
| 5948 | } |
| 5949 | |
| 5950 | final IBinder threadBinder = thread.asBinder(); |
| 5951 | final ArrayMap<String, SparseArray<WindowProcessController>> pmap = mProcessNames.getMap(); |
| 5952 | for (int i = pmap.size()-1; i >= 0; i--) { |
| 5953 | final SparseArray<WindowProcessController> procs = pmap.valueAt(i); |
| 5954 | for (int j = procs.size() - 1; j >= 0; j--) { |
| 5955 | final WindowProcessController proc = procs.valueAt(j); |
| 5956 | if (proc.hasThread() && proc.getThread().asBinder() == threadBinder) { |
| 5957 | return proc; |
| 5958 | } |
| 5959 | } |
| 5960 | } |
| 5961 | |
| 5962 | return null; |
| 5963 | } |
| 5964 | |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 5965 | WindowProcessController getProcessController(int pid, int uid) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 5966 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Yunfan Chen | 8546b21 | 2019-04-01 15:34:44 +0900 | [diff] [blame] | 5967 | if (proc == null) return null; |
| 5968 | if (UserHandle.isApp(uid) && proc.mUid == uid) { |
| 5969 | return proc; |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 5970 | } |
| 5971 | return null; |
| 5972 | } |
| 5973 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 5974 | int getUidState(int uid) { |
| 5975 | return mActiveUids.getUidState(uid); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 5976 | } |
| 5977 | |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 5978 | boolean isUidForeground(int uid) { |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 5979 | // A uid is considered to be foreground if it has a visible non-toast window. |
| 5980 | return mWindowManager.mRoot.isAnyNonToastWindowVisibleForUid(uid); |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 5981 | } |
| 5982 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 5983 | boolean isDeviceOwner(int uid) { |
| 5984 | return uid >= 0 && mDeviceOwnerUid == uid; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 5985 | } |
| 5986 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 5987 | void setDeviceOwnerUid(int uid) { |
| 5988 | mDeviceOwnerUid = uid; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 5989 | } |
| 5990 | |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 5991 | /** |
| 5992 | * @return whitelist tag for a uid from mPendingTempWhitelist, null if not currently on |
| 5993 | * the whitelist |
| 5994 | */ |
| 5995 | String getPendingTempWhitelistTagForUidLocked(int uid) { |
| 5996 | return mPendingTempWhitelist.get(uid); |
| 5997 | } |
| 5998 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5999 | void logAppTooSlow(WindowProcessController app, long startTime, String msg) { |
| 6000 | if (true || Build.IS_USER) { |
| 6001 | return; |
| 6002 | } |
| 6003 | |
| 6004 | StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 6005 | StrictMode.allowThreadDiskWrites(); |
| 6006 | try { |
| 6007 | File tracesDir = new File("/data/anr"); |
| 6008 | File tracesFile = null; |
| 6009 | try { |
| 6010 | tracesFile = File.createTempFile("app_slow", null, tracesDir); |
| 6011 | |
| 6012 | StringBuilder sb = new StringBuilder(); |
| 6013 | Time tobj = new Time(); |
| 6014 | tobj.set(System.currentTimeMillis()); |
| 6015 | sb.append(tobj.format("%Y-%m-%d %H:%M:%S")); |
| 6016 | sb.append(": "); |
| 6017 | TimeUtils.formatDuration(SystemClock.uptimeMillis()-startTime, sb); |
| 6018 | sb.append(" since "); |
| 6019 | sb.append(msg); |
| 6020 | FileOutputStream fos = new FileOutputStream(tracesFile); |
| 6021 | fos.write(sb.toString().getBytes()); |
| 6022 | if (app == null) { |
| 6023 | fos.write("\n*** No application process!".getBytes()); |
| 6024 | } |
| 6025 | fos.close(); |
| 6026 | FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1); // -rw-rw-rw- |
| 6027 | } catch (IOException e) { |
| 6028 | Slog.w(TAG, "Unable to prepare slow app traces file: " + tracesFile, e); |
| 6029 | return; |
| 6030 | } |
| 6031 | |
| 6032 | if (app != null && app.getPid() > 0) { |
| 6033 | ArrayList<Integer> firstPids = new ArrayList<Integer>(); |
| 6034 | firstPids.add(app.getPid()); |
| 6035 | dumpStackTraces(tracesFile.getAbsolutePath(), firstPids, null, null); |
| 6036 | } |
| 6037 | |
| 6038 | File lastTracesFile = null; |
| 6039 | File curTracesFile = null; |
| 6040 | for (int i=9; i>=0; i--) { |
| 6041 | String name = String.format(Locale.US, "slow%02d.txt", i); |
| 6042 | curTracesFile = new File(tracesDir, name); |
| 6043 | if (curTracesFile.exists()) { |
| 6044 | if (lastTracesFile != null) { |
| 6045 | curTracesFile.renameTo(lastTracesFile); |
| 6046 | } else { |
| 6047 | curTracesFile.delete(); |
| 6048 | } |
| 6049 | } |
| 6050 | lastTracesFile = curTracesFile; |
| 6051 | } |
| 6052 | tracesFile.renameTo(curTracesFile); |
| 6053 | } finally { |
| 6054 | StrictMode.setThreadPolicy(oldPolicy); |
| 6055 | } |
| 6056 | } |
| 6057 | |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 6058 | boolean isAssociatedCompanionApp(int userId, int uid) { |
| 6059 | final Set<Integer> allUids = mCompanionAppUidsMap.get(userId); |
| 6060 | if (allUids == null) { |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 6061 | return false; |
| 6062 | } |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 6063 | return allUids.contains(uid); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 6064 | } |
| 6065 | |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 6066 | void notifySingleTaskDisplayEmpty(int displayId) { |
| 6067 | mTaskChangeNotificationController.notifySingleTaskDisplayEmpty(displayId); |
| 6068 | } |
| 6069 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6070 | final class H extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6071 | static final int REPORT_TIME_TRACKER_MSG = 1; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 6072 | |
| 6073 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 6074 | static final int FIRST_ACTIVITY_STACK_MSG = 100; |
| 6075 | static final int FIRST_SUPERVISOR_STACK_MSG = 200; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6076 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 6077 | H(Looper looper) { |
| 6078 | super(looper); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6079 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6080 | |
| 6081 | @Override |
| 6082 | public void handleMessage(Message msg) { |
| 6083 | switch (msg.what) { |
| 6084 | case REPORT_TIME_TRACKER_MSG: { |
| 6085 | AppTimeTracker tracker = (AppTimeTracker) msg.obj; |
| 6086 | tracker.deliverResult(mContext); |
| 6087 | } break; |
| 6088 | } |
| 6089 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6090 | } |
| 6091 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6092 | final class UiHandler extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6093 | static final int DISMISS_DIALOG_UI_MSG = 1; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6094 | |
| 6095 | public UiHandler() { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 6096 | super(UiThread.get().getLooper(), null, true); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6097 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6098 | |
| 6099 | @Override |
| 6100 | public void handleMessage(Message msg) { |
| 6101 | switch (msg.what) { |
| 6102 | case DISMISS_DIALOG_UI_MSG: { |
| 6103 | final Dialog d = (Dialog) msg.obj; |
| 6104 | d.dismiss(); |
| 6105 | break; |
| 6106 | } |
| 6107 | } |
| 6108 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6109 | } |
| 6110 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6111 | final class LocalService extends ActivityTaskManagerInternal { |
| 6112 | @Override |
| 6113 | public SleepToken acquireSleepToken(String tag, int displayId) { |
| 6114 | Preconditions.checkNotNull(tag); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6115 | return ActivityTaskManagerService.this.acquireSleepToken(tag, displayId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6116 | } |
| 6117 | |
| 6118 | @Override |
| 6119 | public ComponentName getHomeActivityForUser(int userId) { |
| 6120 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6121 | final ActivityRecord homeActivity = |
| 6122 | mRootActivityContainer.getDefaultDisplayHomeActivityForUser(userId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 6123 | return homeActivity == null ? null : homeActivity.mActivityComponent; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6124 | } |
| 6125 | } |
| 6126 | |
| 6127 | @Override |
| 6128 | public void onLocalVoiceInteractionStarted(IBinder activity, |
| 6129 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 6130 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6131 | onLocalVoiceInteractionStartedLocked(activity, voiceSession, voiceInteractor); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6132 | } |
| 6133 | } |
| 6134 | |
| 6135 | @Override |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 6136 | public void notifyAppTransitionStarting(SparseIntArray reasons, |
| 6137 | long timestamp) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6138 | synchronized (mGlobalLock) { |
| 6139 | mStackSupervisor.getActivityMetricsLogger().notifyTransitionStarting( |
| 6140 | reasons, timestamp); |
| 6141 | } |
| 6142 | } |
| 6143 | |
| 6144 | @Override |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 6145 | public void notifySingleTaskDisplayDrawn(int displayId) { |
| 6146 | mTaskChangeNotificationController.notifySingleTaskDisplayDrawn(displayId); |
| 6147 | } |
| 6148 | |
| 6149 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6150 | public void notifyAppTransitionFinished() { |
| 6151 | synchronized (mGlobalLock) { |
| 6152 | mStackSupervisor.notifyAppTransitionDone(); |
| 6153 | } |
| 6154 | } |
| 6155 | |
| 6156 | @Override |
| 6157 | public void notifyAppTransitionCancelled() { |
| 6158 | synchronized (mGlobalLock) { |
| 6159 | mStackSupervisor.notifyAppTransitionDone(); |
| 6160 | } |
| 6161 | } |
| 6162 | |
| 6163 | @Override |
| 6164 | public List<IBinder> getTopVisibleActivities() { |
| 6165 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6166 | return mRootActivityContainer.getTopVisibleActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6167 | } |
| 6168 | } |
| 6169 | |
| 6170 | @Override |
| 6171 | public void notifyDockedStackMinimizedChanged(boolean minimized) { |
| 6172 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6173 | mRootActivityContainer.setDockedStackMinimized(minimized); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6174 | } |
| 6175 | } |
| 6176 | |
| 6177 | @Override |
| 6178 | public int startActivitiesAsPackage(String packageName, int userId, Intent[] intents, |
| 6179 | Bundle bOptions) { |
| 6180 | Preconditions.checkNotNull(intents, "intents"); |
| 6181 | final String[] resolvedTypes = new String[intents.length]; |
| 6182 | |
| 6183 | // UID of the package on user userId. |
| 6184 | // "= 0" is needed because otherwise catch(RemoteException) would make it look like |
| 6185 | // packageUid may not be initialized. |
| 6186 | int packageUid = 0; |
| 6187 | final long ident = Binder.clearCallingIdentity(); |
| 6188 | |
| 6189 | try { |
| 6190 | for (int i = 0; i < intents.length; i++) { |
| 6191 | resolvedTypes[i] = |
| 6192 | intents[i].resolveTypeIfNeeded(mContext.getContentResolver()); |
| 6193 | } |
| 6194 | |
| 6195 | packageUid = AppGlobals.getPackageManager().getPackageUid( |
| 6196 | packageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId); |
| 6197 | } catch (RemoteException e) { |
| 6198 | // Shouldn't happen. |
| 6199 | } finally { |
| 6200 | Binder.restoreCallingIdentity(ident); |
| 6201 | } |
| 6202 | |
Riddle Hsu | 591bf61 | 2019-02-14 17:55:31 +0800 | [diff] [blame] | 6203 | return getActivityStartController().startActivitiesInPackage( |
| 6204 | packageUid, packageName, |
| 6205 | intents, resolvedTypes, null /* resultTo */, |
| 6206 | SafeActivityOptions.fromBundle(bOptions), userId, |
| 6207 | false /* validateIncomingUser */, null /* originatingPendingIntent */, |
| 6208 | false /* allowBackgroundActivityStart */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6209 | } |
| 6210 | |
| 6211 | @Override |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6212 | public int startActivitiesInPackage(int uid, int realCallingPid, int realCallingUid, |
| 6213 | String callingPackage, Intent[] intents, String[] resolvedTypes, IBinder resultTo, |
| 6214 | SafeActivityOptions options, int userId, boolean validateIncomingUser, |
| 6215 | PendingIntentRecord originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6216 | boolean allowBackgroundActivityStart) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6217 | synchronized (mGlobalLock) { |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6218 | return getActivityStartController().startActivitiesInPackage(uid, realCallingPid, |
| 6219 | realCallingUid, callingPackage, intents, resolvedTypes, resultTo, options, |
| 6220 | userId, validateIncomingUser, originatingPendingIntent, |
| 6221 | allowBackgroundActivityStart); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6222 | } |
| 6223 | } |
| 6224 | |
| 6225 | @Override |
| 6226 | public int startActivityInPackage(int uid, int realCallingPid, int realCallingUid, |
| 6227 | String callingPackage, Intent intent, String resolvedType, IBinder resultTo, |
| 6228 | String resultWho, int requestCode, int startFlags, SafeActivityOptions options, |
| 6229 | int userId, TaskRecord inTask, String reason, boolean validateIncomingUser, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6230 | PendingIntentRecord originatingPendingIntent, |
| 6231 | boolean allowBackgroundActivityStart) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6232 | synchronized (mGlobalLock) { |
| 6233 | return getActivityStartController().startActivityInPackage(uid, realCallingPid, |
| 6234 | realCallingUid, callingPackage, intent, resolvedType, resultTo, resultWho, |
| 6235 | requestCode, startFlags, options, userId, inTask, reason, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6236 | validateIncomingUser, originatingPendingIntent, |
| 6237 | allowBackgroundActivityStart); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6238 | } |
| 6239 | } |
| 6240 | |
| 6241 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6242 | public int startActivityAsUser(IApplicationThread caller, String callerPacakge, |
| 6243 | Intent intent, Bundle options, int userId) { |
| 6244 | return ActivityTaskManagerService.this.startActivityAsUser( |
| 6245 | caller, callerPacakge, intent, |
| 6246 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 6247 | null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, options, userId, |
| 6248 | false /*validateIncomingUser*/); |
| 6249 | } |
| 6250 | |
| 6251 | @Override |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 6252 | public void notifyKeyguardFlagsChanged(@Nullable Runnable callback, int displayId) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6253 | synchronized (mGlobalLock) { |
| 6254 | |
| 6255 | // We might change the visibilities here, so prepare an empty app transition which |
| 6256 | // might be overridden later if we actually change visibilities. |
lumark | 52ea28e | 2018-11-09 17:30:47 +0800 | [diff] [blame] | 6257 | final ActivityDisplay activityDisplay = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6258 | mRootActivityContainer.getActivityDisplay(displayId); |
lumark | 52ea28e | 2018-11-09 17:30:47 +0800 | [diff] [blame] | 6259 | if (activityDisplay == null) { |
| 6260 | return; |
| 6261 | } |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6262 | final DisplayContent dc = activityDisplay.mDisplayContent; |
| 6263 | final boolean wasTransitionSet = |
| 6264 | dc.mAppTransition.getAppTransition() != TRANSIT_NONE; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6265 | if (!wasTransitionSet) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6266 | dc.prepareAppTransition(TRANSIT_NONE, false /* alwaysKeepCurrent */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6267 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6268 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6269 | |
| 6270 | // If there was a transition set already we don't want to interfere with it as we |
| 6271 | // might be starting it too early. |
| 6272 | if (!wasTransitionSet) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6273 | dc.executeAppTransition(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6274 | } |
| 6275 | } |
| 6276 | if (callback != null) { |
| 6277 | callback.run(); |
| 6278 | } |
| 6279 | } |
| 6280 | |
| 6281 | @Override |
| 6282 | public void notifyKeyguardTrustedChanged() { |
| 6283 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6284 | if (mKeyguardController.isKeyguardShowing(DEFAULT_DISPLAY)) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6285 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6286 | } |
| 6287 | } |
| 6288 | } |
| 6289 | |
| 6290 | /** |
| 6291 | * Called after virtual display Id is updated by |
| 6292 | * {@link com.android.server.vr.Vr2dDisplay} with a specific |
| 6293 | * {@param vrVr2dDisplayId}. |
| 6294 | */ |
| 6295 | @Override |
| 6296 | public void setVr2dDisplayId(int vr2dDisplayId) { |
| 6297 | if (DEBUG_STACK) Slog.d(TAG, "setVr2dDisplayId called for: " + vr2dDisplayId); |
| 6298 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6299 | mVr2dDisplayId = vr2dDisplayId; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6300 | } |
| 6301 | } |
| 6302 | |
| 6303 | @Override |
| 6304 | public void setFocusedActivity(IBinder token) { |
| 6305 | synchronized (mGlobalLock) { |
| 6306 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 6307 | if (r == null) { |
| 6308 | throw new IllegalArgumentException( |
| 6309 | "setFocusedActivity: No activity record matching token=" + token); |
| 6310 | } |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 6311 | if (r.moveFocusableActivityToTop("setFocusedActivity")) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6312 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6313 | } |
| 6314 | } |
| 6315 | } |
| 6316 | |
| 6317 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6318 | public void registerScreenObserver(ScreenObserver observer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6319 | mScreenObservers.add(observer); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6320 | } |
| 6321 | |
| 6322 | @Override |
| 6323 | public boolean isCallerRecents(int callingUid) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 6324 | return getRecentTasks().isCallerRecents(callingUid); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6325 | } |
| 6326 | |
| 6327 | @Override |
| 6328 | public boolean isRecentsComponentHomeActivity(int userId) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 6329 | return getRecentTasks().isRecentsComponentHomeActivity(userId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6330 | } |
| 6331 | |
| 6332 | @Override |
| 6333 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
| 6334 | ActivityTaskManagerService.this.cancelRecentsAnimation(restoreHomeStackPosition); |
| 6335 | } |
| 6336 | |
| 6337 | @Override |
| 6338 | public void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6339 | ActivityTaskManagerService.this.enforceCallerIsRecentsOrHasPermission(permission, func); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6340 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6341 | |
| 6342 | @Override |
| 6343 | public void notifyActiveVoiceInteractionServiceChanged(ComponentName component) { |
| 6344 | synchronized (mGlobalLock) { |
| 6345 | mActiveVoiceInteractionServiceComponent = component; |
| 6346 | } |
| 6347 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6348 | |
| 6349 | @Override |
| 6350 | public void setAllowAppSwitches(@NonNull String type, int uid, int userId) { |
| 6351 | if (!mAmInternal.isUserRunning(userId, ActivityManager.FLAG_OR_STOPPED)) { |
| 6352 | return; |
| 6353 | } |
| 6354 | synchronized (mGlobalLock) { |
| 6355 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(userId); |
| 6356 | if (types == null) { |
| 6357 | if (uid < 0) { |
| 6358 | return; |
| 6359 | } |
| 6360 | types = new ArrayMap<>(); |
| 6361 | mAllowAppSwitchUids.put(userId, types); |
| 6362 | } |
| 6363 | if (uid < 0) { |
| 6364 | types.remove(type); |
| 6365 | } else { |
| 6366 | types.put(type, uid); |
| 6367 | } |
| 6368 | } |
| 6369 | } |
| 6370 | |
| 6371 | @Override |
| 6372 | public void onUserStopped(int userId) { |
| 6373 | synchronized (mGlobalLock) { |
| 6374 | getRecentTasks().unloadUserDataFromMemoryLocked(userId); |
| 6375 | mAllowAppSwitchUids.remove(userId); |
| 6376 | } |
| 6377 | } |
| 6378 | |
| 6379 | @Override |
| 6380 | public boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 6381 | synchronized (mGlobalLock) { |
| 6382 | return ActivityTaskManagerService.this.isGetTasksAllowed( |
| 6383 | caller, callingPid, callingUid); |
| 6384 | } |
| 6385 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6386 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6387 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6388 | @Override |
| 6389 | public void onProcessAdded(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6390 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6391 | mProcessNames.put(proc.mName, proc.mUid, proc); |
| 6392 | } |
| 6393 | } |
| 6394 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6395 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6396 | @Override |
| 6397 | public void onProcessRemoved(String name, int uid) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6398 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6399 | mProcessNames.remove(name, uid); |
| 6400 | } |
| 6401 | } |
| 6402 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6403 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6404 | @Override |
| 6405 | public void onCleanUpApplicationRecord(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6406 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6407 | if (proc == mHomeProcess) { |
| 6408 | mHomeProcess = null; |
| 6409 | } |
| 6410 | if (proc == mPreviousProcess) { |
| 6411 | mPreviousProcess = null; |
| 6412 | } |
| 6413 | } |
| 6414 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6415 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6416 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6417 | @Override |
| 6418 | public int getTopProcessState() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6419 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6420 | return mTopProcessState; |
| 6421 | } |
| 6422 | } |
| 6423 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6424 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6425 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6426 | public boolean isHeavyWeightProcess(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6427 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6428 | return proc == mHeavyWeightProcess; |
| 6429 | } |
| 6430 | } |
| 6431 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6432 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6433 | @Override |
| 6434 | public void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6435 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6436 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals(proc); |
| 6437 | } |
| 6438 | } |
| 6439 | |
| 6440 | @Override |
| 6441 | public void finishHeavyWeightApp() { |
| 6442 | synchronized (mGlobalLock) { |
Sudheer Shanka | ee1da27 | 2018-10-20 20:11:44 -0700 | [diff] [blame] | 6443 | if (mHeavyWeightProcess != null) { |
| 6444 | mHeavyWeightProcess.finishActivities(); |
| 6445 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6446 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals( |
| 6447 | mHeavyWeightProcess); |
| 6448 | } |
| 6449 | } |
| 6450 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6451 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6452 | @Override |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6453 | public boolean isSleeping() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6454 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6455 | return isSleepingLocked(); |
| 6456 | } |
| 6457 | } |
| 6458 | |
| 6459 | @Override |
| 6460 | public boolean isShuttingDown() { |
| 6461 | synchronized (mGlobalLock) { |
| 6462 | return mShuttingDown; |
| 6463 | } |
| 6464 | } |
| 6465 | |
| 6466 | @Override |
| 6467 | public boolean shuttingDown(boolean booted, int timeout) { |
| 6468 | synchronized (mGlobalLock) { |
| 6469 | mShuttingDown = true; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6470 | mRootActivityContainer.prepareForShutdown(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6471 | updateEventDispatchingLocked(booted); |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 6472 | notifyTaskPersisterLocked(null, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6473 | return mStackSupervisor.shutdownLocked(timeout); |
| 6474 | } |
| 6475 | } |
| 6476 | |
| 6477 | @Override |
| 6478 | public void enableScreenAfterBoot(boolean booted) { |
| 6479 | synchronized (mGlobalLock) { |
| 6480 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_ENABLE_SCREEN, |
| 6481 | SystemClock.uptimeMillis()); |
| 6482 | mWindowManager.enableScreenAfterBoot(); |
| 6483 | updateEventDispatchingLocked(booted); |
| 6484 | } |
| 6485 | } |
| 6486 | |
| 6487 | @Override |
| 6488 | public boolean showStrictModeViolationDialog() { |
| 6489 | synchronized (mGlobalLock) { |
| 6490 | return mShowDialogs && !mSleeping && !mShuttingDown; |
| 6491 | } |
| 6492 | } |
| 6493 | |
| 6494 | @Override |
| 6495 | public void showSystemReadyErrorDialogsIfNeeded() { |
| 6496 | synchronized (mGlobalLock) { |
| 6497 | try { |
| 6498 | if (AppGlobals.getPackageManager().hasSystemUidErrors()) { |
| 6499 | Slog.e(TAG, "UIDs on the system are inconsistent, you need to wipe your" |
| 6500 | + " data partition or your device will be unstable."); |
| 6501 | mUiHandler.post(() -> { |
| 6502 | if (mShowDialogs) { |
| 6503 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6504 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6505 | d.setCancelable(false); |
| 6506 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6507 | d.setMessage(mUiContext.getText(R.string.system_error_wipe_data)); |
| 6508 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6509 | mUiContext.getText(R.string.ok), |
| 6510 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6511 | d.show(); |
| 6512 | } |
| 6513 | }); |
| 6514 | } |
| 6515 | } catch (RemoteException e) { |
| 6516 | } |
| 6517 | |
| 6518 | if (!Build.isBuildConsistent()) { |
| 6519 | Slog.e(TAG, "Build fingerprint is not consistent, warning user"); |
| 6520 | mUiHandler.post(() -> { |
| 6521 | if (mShowDialogs) { |
| 6522 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6523 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6524 | d.setCancelable(false); |
| 6525 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6526 | d.setMessage(mUiContext.getText(R.string.system_error_manufacturer)); |
| 6527 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6528 | mUiContext.getText(R.string.ok), |
| 6529 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6530 | d.show(); |
| 6531 | } |
| 6532 | }); |
| 6533 | } |
| 6534 | } |
| 6535 | } |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6536 | |
| 6537 | @Override |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6538 | public void onProcessMapped(int pid, WindowProcessController proc) { |
| 6539 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6540 | mProcessMap.put(pid, proc); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6541 | } |
| 6542 | } |
| 6543 | |
| 6544 | @Override |
| 6545 | public void onProcessUnMapped(int pid) { |
| 6546 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6547 | mProcessMap.remove(pid); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6548 | } |
| 6549 | } |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6550 | |
| 6551 | @Override |
| 6552 | public void onPackageDataCleared(String name) { |
| 6553 | synchronized (mGlobalLock) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6554 | mCompatModePackages.handlePackageDataClearedLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6555 | mAppWarnings.onPackageDataCleared(name); |
| 6556 | } |
| 6557 | } |
| 6558 | |
| 6559 | @Override |
| 6560 | public void onPackageUninstalled(String name) { |
| 6561 | synchronized (mGlobalLock) { |
| 6562 | mAppWarnings.onPackageUninstalled(name); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6563 | mCompatModePackages.handlePackageUninstalledLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6564 | } |
| 6565 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6566 | |
| 6567 | @Override |
| 6568 | public void onPackageAdded(String name, boolean replacing) { |
| 6569 | synchronized (mGlobalLock) { |
| 6570 | mCompatModePackages.handlePackageAddedLocked(name, replacing); |
| 6571 | } |
| 6572 | } |
| 6573 | |
| 6574 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6575 | public void onPackageReplaced(ApplicationInfo aInfo) { |
| 6576 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6577 | mRootActivityContainer.updateActivityApplicationInfo(aInfo); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6578 | } |
| 6579 | } |
| 6580 | |
| 6581 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6582 | public CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai) { |
| 6583 | synchronized (mGlobalLock) { |
| 6584 | return compatibilityInfoForPackageLocked(ai); |
| 6585 | } |
| 6586 | } |
| 6587 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6588 | /** |
| 6589 | * Set the corresponding display information for the process global configuration. To be |
| 6590 | * called when we need to show IME on a different display. |
| 6591 | * |
| 6592 | * @param pid The process id associated with the IME window. |
| 6593 | * @param displayId The ID of the display showing the IME. |
| 6594 | */ |
| 6595 | @Override |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6596 | public void onImeWindowSetOnDisplay(final int pid, final int displayId) { |
lumark | 4897353 | 2019-04-12 20:18:15 +0800 | [diff] [blame] | 6597 | // Don't update process-level configuration for Multi-Client IME process since other |
| 6598 | // IMEs on other displays will also receive this configuration change due to IME |
| 6599 | // services use the same application config/context. |
| 6600 | if (InputMethodSystemProperty.MULTI_CLIENT_IME_ENABLED) return; |
lumark | 5df4951 | 2019-04-02 14:56:46 +0800 | [diff] [blame] | 6601 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6602 | if (pid == MY_PID || pid < 0) { |
| 6603 | if (DEBUG_CONFIGURATION) { |
| 6604 | Slog.w(TAG, |
| 6605 | "Trying to update display configuration for system/invalid process."); |
| 6606 | } |
| 6607 | return; |
| 6608 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6609 | synchronized (mGlobalLock) { |
| 6610 | final ActivityDisplay activityDisplay = |
| 6611 | mRootActivityContainer.getActivityDisplay(displayId); |
| 6612 | if (activityDisplay == null) { |
| 6613 | // Call might come when display is not yet added or has been removed. |
| 6614 | if (DEBUG_CONFIGURATION) { |
| 6615 | Slog.w(TAG, "Trying to update display configuration for non-existing " |
| 6616 | + "displayId=" + displayId); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6617 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6618 | return; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6619 | } |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6620 | final WindowProcessController process = mProcessMap.getProcess(pid); |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6621 | if (process == null) { |
| 6622 | if (DEBUG_CONFIGURATION) { |
| 6623 | Slog.w(TAG, "Trying to update display configuration for invalid " |
| 6624 | + "process, pid=" + pid); |
| 6625 | } |
| 6626 | return; |
| 6627 | } |
| 6628 | process.registerDisplayConfigurationListenerLocked(activityDisplay); |
| 6629 | } |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6630 | } |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6631 | |
| 6632 | @Override |
| 6633 | public void sendActivityResult(int callingUid, IBinder activityToken, String resultWho, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 6634 | int requestCode, int resultCode, Intent data) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6635 | synchronized (mGlobalLock) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 6636 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 6637 | if (r != null && r.getActivityStack() != null) { |
| 6638 | r.getActivityStack().sendActivityResultLocked(callingUid, r, resultWho, |
| 6639 | requestCode, resultCode, data); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6640 | } |
| 6641 | } |
| 6642 | } |
| 6643 | |
| 6644 | @Override |
| 6645 | public void clearPendingResultForActivity(IBinder activityToken, |
| 6646 | WeakReference<PendingIntentRecord> pir) { |
| 6647 | synchronized (mGlobalLock) { |
| 6648 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 6649 | if (r != null && r.pendingResults != null) { |
| 6650 | r.pendingResults.remove(pir); |
| 6651 | } |
| 6652 | } |
| 6653 | } |
| 6654 | |
| 6655 | @Override |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6656 | public ActivityTokens getTopActivityForTask(int taskId) { |
| 6657 | synchronized (mGlobalLock) { |
| 6658 | final TaskRecord taskRecord = mRootActivityContainer.anyTaskForId(taskId); |
| 6659 | if (taskRecord == null) { |
| 6660 | Slog.w(TAG, "getApplicationThreadForTopActivity failed:" |
| 6661 | + " Requested task not found"); |
| 6662 | return null; |
| 6663 | } |
| 6664 | final ActivityRecord activity = taskRecord.getTopActivity(); |
| 6665 | if (activity == null) { |
| 6666 | Slog.w(TAG, "getApplicationThreadForTopActivity failed:" |
| 6667 | + " Requested activity not found"); |
| 6668 | return null; |
| 6669 | } |
| 6670 | if (!activity.attachedToProcess()) { |
| 6671 | Slog.w(TAG, "getApplicationThreadForTopActivity failed: No process for " |
| 6672 | + activity); |
| 6673 | return null; |
| 6674 | } |
| 6675 | return new ActivityTokens(activity.appToken, activity.assistToken, |
| 6676 | activity.app.getThread()); |
| 6677 | } |
| 6678 | } |
| 6679 | |
| 6680 | @Override |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6681 | public IIntentSender getIntentSender(int type, String packageName, |
| 6682 | int callingUid, int userId, IBinder token, String resultWho, |
| 6683 | int requestCode, Intent[] intents, String[] resolvedTypes, int flags, |
| 6684 | Bundle bOptions) { |
| 6685 | synchronized (mGlobalLock) { |
| 6686 | return getIntentSenderLocked(type, packageName, callingUid, userId, token, |
| 6687 | resultWho, requestCode, intents, resolvedTypes, flags, bOptions); |
| 6688 | } |
| 6689 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 6690 | |
| 6691 | @Override |
| 6692 | public ActivityServiceConnectionsHolder getServiceConnectionsHolder(IBinder token) { |
| 6693 | synchronized (mGlobalLock) { |
| 6694 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 6695 | if (r == null) { |
| 6696 | return null; |
| 6697 | } |
| 6698 | if (r.mServiceConnectionsHolder == null) { |
| 6699 | r.mServiceConnectionsHolder = new ActivityServiceConnectionsHolder( |
| 6700 | ActivityTaskManagerService.this, r); |
| 6701 | } |
| 6702 | |
| 6703 | return r.mServiceConnectionsHolder; |
| 6704 | } |
| 6705 | } |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6706 | |
| 6707 | @Override |
| 6708 | public Intent getHomeIntent() { |
| 6709 | synchronized (mGlobalLock) { |
| 6710 | return ActivityTaskManagerService.this.getHomeIntent(); |
| 6711 | } |
| 6712 | } |
| 6713 | |
| 6714 | @Override |
| 6715 | public boolean startHomeActivity(int userId, String reason) { |
| 6716 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6717 | return mRootActivityContainer.startHomeOnDisplay(userId, reason, DEFAULT_DISPLAY); |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6718 | } |
| 6719 | } |
| 6720 | |
| 6721 | @Override |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 6722 | public boolean startHomeOnDisplay(int userId, String reason, int displayId, |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 6723 | boolean allowInstrumenting, boolean fromHomeKey) { |
Chilun | 5fd5654 | 2019-03-21 19:51:37 +0800 | [diff] [blame] | 6724 | synchronized (mGlobalLock) { |
| 6725 | return mRootActivityContainer.startHomeOnDisplay(userId, reason, displayId, |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 6726 | allowInstrumenting, fromHomeKey); |
Chilun | 5fd5654 | 2019-03-21 19:51:37 +0800 | [diff] [blame] | 6727 | } |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 6728 | } |
| 6729 | |
| 6730 | @Override |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6731 | public boolean startHomeOnAllDisplays(int userId, String reason) { |
| 6732 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6733 | return mRootActivityContainer.startHomeOnAllDisplays(userId, reason); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6734 | } |
| 6735 | } |
| 6736 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6737 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6738 | @Override |
| 6739 | public boolean isFactoryTestProcess(WindowProcessController wpc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6740 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6741 | if (mFactoryTest == FACTORY_TEST_OFF) { |
| 6742 | return false; |
| 6743 | } |
| 6744 | if (mFactoryTest == FACTORY_TEST_LOW_LEVEL && mTopComponent != null |
| 6745 | && wpc.mName.equals(mTopComponent.getPackageName())) { |
| 6746 | return true; |
| 6747 | } |
| 6748 | return mFactoryTest == FACTORY_TEST_HIGH_LEVEL |
| 6749 | && (wpc.mInfo.flags & FLAG_FACTORY_TEST) != 0; |
| 6750 | } |
| 6751 | } |
| 6752 | |
| 6753 | @Override |
| 6754 | public void updateTopComponentForFactoryTest() { |
| 6755 | synchronized (mGlobalLock) { |
| 6756 | if (mFactoryTest != FACTORY_TEST_LOW_LEVEL) { |
| 6757 | return; |
| 6758 | } |
| 6759 | final ResolveInfo ri = mContext.getPackageManager() |
| 6760 | .resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST), STOCK_PM_FLAGS); |
| 6761 | final CharSequence errorMsg; |
| 6762 | if (ri != null) { |
| 6763 | final ActivityInfo ai = ri.activityInfo; |
| 6764 | final ApplicationInfo app = ai.applicationInfo; |
| 6765 | if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 6766 | mTopAction = Intent.ACTION_FACTORY_TEST; |
| 6767 | mTopData = null; |
| 6768 | mTopComponent = new ComponentName(app.packageName, ai.name); |
| 6769 | errorMsg = null; |
| 6770 | } else { |
| 6771 | errorMsg = mContext.getResources().getText( |
| 6772 | com.android.internal.R.string.factorytest_not_system); |
| 6773 | } |
| 6774 | } else { |
| 6775 | errorMsg = mContext.getResources().getText( |
| 6776 | com.android.internal.R.string.factorytest_no_action); |
| 6777 | } |
| 6778 | if (errorMsg == null) { |
| 6779 | return; |
| 6780 | } |
| 6781 | |
| 6782 | mTopAction = null; |
| 6783 | mTopData = null; |
| 6784 | mTopComponent = null; |
| 6785 | mUiHandler.post(() -> { |
| 6786 | Dialog d = new FactoryErrorDialog(mUiContext, errorMsg); |
| 6787 | d.show(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 6788 | mAmInternal.ensureBootCompleted(); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6789 | }); |
| 6790 | } |
| 6791 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6792 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6793 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6794 | @Override |
| 6795 | public void handleAppDied(WindowProcessController wpc, boolean restarting, |
| 6796 | Runnable finishInstrumentationCallback) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6797 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6798 | // Remove this application's activities from active lists. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6799 | boolean hasVisibleActivities = mRootActivityContainer.handleAppDied(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6800 | |
| 6801 | wpc.clearRecentTasks(); |
| 6802 | wpc.clearActivities(); |
| 6803 | |
| 6804 | if (wpc.isInstrumenting()) { |
| 6805 | finishInstrumentationCallback.run(); |
| 6806 | } |
| 6807 | |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6808 | if (!restarting && hasVisibleActivities) { |
| 6809 | mWindowManager.deferSurfaceLayout(); |
| 6810 | try { |
| 6811 | if (!mRootActivityContainer.resumeFocusedStacksTopActivities()) { |
| 6812 | // If there was nothing to resume, and we are not already restarting |
| 6813 | // this process, but there is a visible activity that is hosted by the |
| 6814 | // process...then make sure all visible activities are running, taking |
| 6815 | // care of restarting this process. |
| 6816 | mRootActivityContainer.ensureActivitiesVisible(null, 0, |
| 6817 | !PRESERVE_WINDOWS); |
| 6818 | } |
| 6819 | } finally { |
| 6820 | mWindowManager.continueSurfaceLayout(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6821 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6822 | } |
| 6823 | } |
| 6824 | } |
| 6825 | |
| 6826 | @Override |
| 6827 | public void closeSystemDialogs(String reason) { |
| 6828 | enforceNotIsolatedCaller("closeSystemDialogs"); |
| 6829 | |
| 6830 | final int pid = Binder.getCallingPid(); |
| 6831 | final int uid = Binder.getCallingUid(); |
| 6832 | final long origId = Binder.clearCallingIdentity(); |
| 6833 | try { |
| 6834 | synchronized (mGlobalLock) { |
| 6835 | // Only allow this from foreground processes, so that background |
| 6836 | // applications can't abuse it to prevent system UI from being shown. |
| 6837 | if (uid >= FIRST_APPLICATION_UID) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6838 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6839 | if (!proc.isPerceptible()) { |
| 6840 | Slog.w(TAG, "Ignoring closeSystemDialogs " + reason |
| 6841 | + " from background process " + proc); |
| 6842 | return; |
| 6843 | } |
| 6844 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6845 | mWindowManager.closeSystemDialogs(reason); |
| 6846 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6847 | mRootActivityContainer.closeSystemDialogs(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6848 | } |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 6849 | // Call into AM outside the synchronized block. |
| 6850 | mAmInternal.broadcastCloseSystemDialogs(reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6851 | } finally { |
| 6852 | Binder.restoreCallingIdentity(origId); |
| 6853 | } |
| 6854 | } |
| 6855 | |
| 6856 | @Override |
| 6857 | public void cleanupDisabledPackageComponents( |
| 6858 | String packageName, Set<String> disabledClasses, int userId, boolean booted) { |
| 6859 | synchronized (mGlobalLock) { |
| 6860 | // Clean-up disabled activities. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6861 | if (mRootActivityContainer.finishDisabledPackageActivities( |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6862 | packageName, disabledClasses, true, false, userId) && booted) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6863 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6864 | mStackSupervisor.scheduleIdleLocked(); |
| 6865 | } |
| 6866 | |
| 6867 | // Clean-up disabled tasks |
| 6868 | getRecentTasks().cleanupDisabledPackageTasksLocked( |
| 6869 | packageName, disabledClasses, userId); |
| 6870 | } |
| 6871 | } |
| 6872 | |
| 6873 | @Override |
| 6874 | public boolean onForceStopPackage(String packageName, boolean doit, boolean evenPersistent, |
| 6875 | int userId) { |
| 6876 | synchronized (mGlobalLock) { |
| 6877 | |
| 6878 | boolean didSomething = |
| 6879 | getActivityStartController().clearPendingActivityLaunches(packageName); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6880 | didSomething |= mRootActivityContainer.finishDisabledPackageActivities(packageName, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6881 | null, doit, evenPersistent, userId); |
| 6882 | return didSomething; |
| 6883 | } |
| 6884 | } |
| 6885 | |
| 6886 | @Override |
| 6887 | public void resumeTopActivities(boolean scheduleIdle) { |
| 6888 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6889 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6890 | if (scheduleIdle) { |
| 6891 | mStackSupervisor.scheduleIdleLocked(); |
| 6892 | } |
| 6893 | } |
| 6894 | } |
| 6895 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6896 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6897 | @Override |
| 6898 | public void preBindApplication(WindowProcessController wpc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6899 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6900 | mStackSupervisor.getActivityMetricsLogger().notifyBindApplication(wpc.mInfo); |
| 6901 | } |
| 6902 | } |
| 6903 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6904 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6905 | @Override |
| 6906 | public boolean attachApplication(WindowProcessController wpc) throws RemoteException { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6907 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6908 | return mRootActivityContainer.attachApplication(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6909 | } |
| 6910 | } |
| 6911 | |
| 6912 | @Override |
| 6913 | public void notifyLockedProfile(@UserIdInt int userId, int currentUserId) { |
| 6914 | try { |
| 6915 | if (!AppGlobals.getPackageManager().isUidPrivileged(Binder.getCallingUid())) { |
| 6916 | throw new SecurityException("Only privileged app can call notifyLockedProfile"); |
| 6917 | } |
| 6918 | } catch (RemoteException ex) { |
| 6919 | throw new SecurityException("Fail to check is caller a privileged app", ex); |
| 6920 | } |
| 6921 | |
| 6922 | synchronized (mGlobalLock) { |
| 6923 | final long ident = Binder.clearCallingIdentity(); |
| 6924 | try { |
| 6925 | if (mAmInternal.shouldConfirmCredentials(userId)) { |
| 6926 | if (mKeyguardController.isKeyguardLocked()) { |
| 6927 | // Showing launcher to avoid user entering credential twice. |
| 6928 | startHomeActivity(currentUserId, "notifyLockedProfile"); |
| 6929 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6930 | mRootActivityContainer.lockAllProfileTasks(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6931 | } |
| 6932 | } finally { |
| 6933 | Binder.restoreCallingIdentity(ident); |
| 6934 | } |
| 6935 | } |
| 6936 | } |
| 6937 | |
| 6938 | @Override |
| 6939 | public void startConfirmDeviceCredentialIntent(Intent intent, Bundle options) { |
| 6940 | mAmInternal.enforceCallingPermission( |
| 6941 | MANAGE_ACTIVITY_STACKS, "startConfirmDeviceCredentialIntent"); |
| 6942 | |
| 6943 | synchronized (mGlobalLock) { |
| 6944 | final long ident = Binder.clearCallingIdentity(); |
| 6945 | try { |
Pavel Grafov | c0fe0a0 | 2019-05-13 18:19:33 +0100 | [diff] [blame] | 6946 | intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 6947 | final ActivityOptions activityOptions = options != null |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6948 | ? new ActivityOptions(options) : ActivityOptions.makeBasic(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6949 | mContext.startActivityAsUser(intent, activityOptions.toBundle(), |
| 6950 | UserHandle.CURRENT); |
| 6951 | } finally { |
| 6952 | Binder.restoreCallingIdentity(ident); |
| 6953 | } |
| 6954 | } |
| 6955 | } |
| 6956 | |
| 6957 | @Override |
| 6958 | public void writeActivitiesToProto(ProtoOutputStream proto) { |
| 6959 | synchronized (mGlobalLock) { |
| 6960 | // The output proto of "activity --proto activities" |
| 6961 | // is ActivityManagerServiceDumpActivitiesProto |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6962 | mRootActivityContainer.writeToProto(proto, |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 6963 | ActivityManagerServiceDumpActivitiesProto.ACTIVITY_STACK_SUPERVISOR, |
| 6964 | WindowTraceLogLevel.ALL); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6965 | } |
| 6966 | } |
| 6967 | |
| 6968 | @Override |
| 6969 | public void saveANRState(String reason) { |
| 6970 | synchronized (mGlobalLock) { |
| 6971 | final StringWriter sw = new StringWriter(); |
| 6972 | final PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
| 6973 | pw.println(" ANR time: " + DateFormat.getDateTimeInstance().format(new Date())); |
| 6974 | if (reason != null) { |
| 6975 | pw.println(" Reason: " + reason); |
| 6976 | } |
| 6977 | pw.println(); |
| 6978 | getActivityStartController().dump(pw, " ", null); |
| 6979 | pw.println(); |
| 6980 | pw.println("-------------------------------------------------------------------------------"); |
| 6981 | dumpActivitiesLocked(null /* fd */, pw, null /* args */, 0 /* opti */, |
| 6982 | true /* dumpAll */, false /* dumpClient */, null /* dumpPackage */, |
| 6983 | "" /* header */); |
| 6984 | pw.println(); |
| 6985 | pw.close(); |
| 6986 | |
| 6987 | mLastANRState = sw.toString(); |
| 6988 | } |
| 6989 | } |
| 6990 | |
| 6991 | @Override |
| 6992 | public void clearSavedANRState() { |
| 6993 | synchronized (mGlobalLock) { |
| 6994 | mLastANRState = null; |
| 6995 | } |
| 6996 | } |
| 6997 | |
| 6998 | @Override |
| 6999 | public void dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args, int opti, |
| 7000 | boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 7001 | synchronized (mGlobalLock) { |
| 7002 | if (DUMP_ACTIVITIES_CMD.equals(cmd) || DUMP_ACTIVITIES_SHORT_CMD.equals(cmd)) { |
| 7003 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage); |
| 7004 | } else if (DUMP_LASTANR_CMD.equals(cmd)) { |
| 7005 | dumpLastANRLocked(pw); |
| 7006 | } else if (DUMP_LASTANR_TRACES_CMD.equals(cmd)) { |
| 7007 | dumpLastANRTracesLocked(pw); |
| 7008 | } else if (DUMP_STARTER_CMD.equals(cmd)) { |
| 7009 | dumpActivityStarterLocked(pw, dumpPackage); |
| 7010 | } else if (DUMP_CONTAINERS_CMD.equals(cmd)) { |
| 7011 | dumpActivityContainersLocked(pw); |
| 7012 | } else if (DUMP_RECENTS_CMD.equals(cmd) || DUMP_RECENTS_SHORT_CMD.equals(cmd)) { |
| 7013 | if (getRecentTasks() != null) { |
| 7014 | getRecentTasks().dump(pw, dumpAll, dumpPackage); |
| 7015 | } |
| 7016 | } |
| 7017 | } |
| 7018 | } |
| 7019 | |
| 7020 | @Override |
| 7021 | public boolean dumpForProcesses(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 7022 | String dumpPackage, int dumpAppId, boolean needSep, boolean testPssMode, |
| 7023 | int wakefulness) { |
| 7024 | synchronized (mGlobalLock) { |
| 7025 | if (mHomeProcess != null && (dumpPackage == null |
| 7026 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
| 7027 | if (needSep) { |
| 7028 | pw.println(); |
| 7029 | needSep = false; |
| 7030 | } |
| 7031 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 7032 | } |
| 7033 | if (mPreviousProcess != null && (dumpPackage == null |
| 7034 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 7035 | if (needSep) { |
| 7036 | pw.println(); |
| 7037 | needSep = false; |
| 7038 | } |
| 7039 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 7040 | } |
| 7041 | if (dumpAll && (mPreviousProcess == null || dumpPackage == null |
| 7042 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 7043 | StringBuilder sb = new StringBuilder(128); |
| 7044 | sb.append(" mPreviousProcessVisibleTime: "); |
| 7045 | TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb); |
| 7046 | pw.println(sb); |
| 7047 | } |
| 7048 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 7049 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
| 7050 | if (needSep) { |
| 7051 | pw.println(); |
| 7052 | needSep = false; |
| 7053 | } |
| 7054 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 7055 | } |
| 7056 | if (dumpPackage == null) { |
| 7057 | pw.println(" mGlobalConfiguration: " + getGlobalConfiguration()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7058 | mRootActivityContainer.dumpDisplayConfigs(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7059 | } |
| 7060 | if (dumpAll) { |
| 7061 | if (dumpPackage == null) { |
| 7062 | pw.println(" mConfigWillChange: " |
| 7063 | + getTopDisplayFocusedStack().mConfigWillChange); |
| 7064 | } |
| 7065 | if (mCompatModePackages.getPackages().size() > 0) { |
| 7066 | boolean printed = false; |
| 7067 | for (Map.Entry<String, Integer> entry |
| 7068 | : mCompatModePackages.getPackages().entrySet()) { |
| 7069 | String pkg = entry.getKey(); |
| 7070 | int mode = entry.getValue(); |
| 7071 | if (dumpPackage != null && !dumpPackage.equals(pkg)) { |
| 7072 | continue; |
| 7073 | } |
| 7074 | if (!printed) { |
| 7075 | pw.println(" mScreenCompatPackages:"); |
| 7076 | printed = true; |
| 7077 | } |
| 7078 | pw.println(" " + pkg + ": " + mode); |
| 7079 | } |
| 7080 | } |
| 7081 | } |
| 7082 | |
| 7083 | if (dumpPackage == null) { |
| 7084 | pw.println(" mWakefulness=" |
| 7085 | + PowerManagerInternal.wakefulnessToString(wakefulness)); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7086 | pw.println(" mSleepTokens=" + mRootActivityContainer.mSleepTokens); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7087 | if (mRunningVoice != null) { |
| 7088 | pw.println(" mRunningVoice=" + mRunningVoice); |
| 7089 | pw.println(" mVoiceWakeLock" + mVoiceWakeLock); |
| 7090 | } |
| 7091 | pw.println(" mSleeping=" + mSleeping); |
| 7092 | pw.println(" mShuttingDown=" + mShuttingDown + " mTestPssMode=" + testPssMode); |
| 7093 | pw.println(" mVrController=" + mVrController); |
| 7094 | } |
| 7095 | if (mCurAppTimeTracker != null) { |
| 7096 | mCurAppTimeTracker.dumpWithHeader(pw, " ", true); |
| 7097 | } |
| 7098 | if (mAllowAppSwitchUids.size() > 0) { |
| 7099 | boolean printed = false; |
| 7100 | for (int i = 0; i < mAllowAppSwitchUids.size(); i++) { |
| 7101 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.valueAt(i); |
| 7102 | for (int j = 0; j < types.size(); j++) { |
| 7103 | if (dumpPackage == null || |
| 7104 | UserHandle.getAppId(types.valueAt(j).intValue()) == dumpAppId) { |
| 7105 | if (needSep) { |
| 7106 | pw.println(); |
| 7107 | needSep = false; |
| 7108 | } |
| 7109 | if (!printed) { |
| 7110 | pw.println(" mAllowAppSwitchUids:"); |
| 7111 | printed = true; |
| 7112 | } |
| 7113 | pw.print(" User "); |
| 7114 | pw.print(mAllowAppSwitchUids.keyAt(i)); |
| 7115 | pw.print(": Type "); |
| 7116 | pw.print(types.keyAt(j)); |
| 7117 | pw.print(" = "); |
| 7118 | UserHandle.formatUid(pw, types.valueAt(j).intValue()); |
| 7119 | pw.println(); |
| 7120 | } |
| 7121 | } |
| 7122 | } |
| 7123 | } |
| 7124 | if (dumpPackage == null) { |
| 7125 | if (mController != null) { |
| 7126 | pw.println(" mController=" + mController |
| 7127 | + " mControllerIsAMonkey=" + mControllerIsAMonkey); |
| 7128 | } |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 7129 | pw.println(" mGoingToSleepWakeLock=" + mStackSupervisor.mGoingToSleepWakeLock); |
| 7130 | pw.println(" mLaunchingActivityWakeLock=" |
| 7131 | + mStackSupervisor.mLaunchingActivityWakeLock); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7132 | } |
| 7133 | |
| 7134 | return needSep; |
| 7135 | } |
| 7136 | } |
| 7137 | |
| 7138 | @Override |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7139 | public void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage, |
| 7140 | int wakeFullness, boolean testPssMode) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7141 | synchronized (mGlobalLock) { |
| 7142 | if (dumpPackage == null) { |
| 7143 | getGlobalConfiguration().writeToProto(proto, GLOBAL_CONFIGURATION); |
| 7144 | proto.write(CONFIG_WILL_CHANGE, getTopDisplayFocusedStack().mConfigWillChange); |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7145 | writeSleepStateToProto(proto, wakeFullness, testPssMode); |
| 7146 | if (mRunningVoice != null) { |
| 7147 | final long vrToken = proto.start( |
| 7148 | ActivityManagerServiceDumpProcessesProto.RUNNING_VOICE); |
| 7149 | proto.write(ActivityManagerServiceDumpProcessesProto.Voice.SESSION, |
| 7150 | mRunningVoice.toString()); |
| 7151 | mVoiceWakeLock.writeToProto( |
| 7152 | proto, ActivityManagerServiceDumpProcessesProto.Voice.WAKELOCK); |
| 7153 | proto.end(vrToken); |
| 7154 | } |
| 7155 | mVrController.writeToProto(proto, |
| 7156 | ActivityManagerServiceDumpProcessesProto.VR_CONTROLLER); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7157 | if (mController != null) { |
| 7158 | final long token = proto.start(CONTROLLER); |
| 7159 | proto.write(CONTROLLER, mController.toString()); |
| 7160 | proto.write(IS_A_MONKEY, mControllerIsAMonkey); |
| 7161 | proto.end(token); |
| 7162 | } |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 7163 | mStackSupervisor.mGoingToSleepWakeLock.writeToProto(proto, GOING_TO_SLEEP); |
| 7164 | mStackSupervisor.mLaunchingActivityWakeLock.writeToProto(proto, |
| 7165 | LAUNCHING_ACTIVITY); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7166 | } |
| 7167 | |
| 7168 | if (mHomeProcess != null && (dumpPackage == null |
| 7169 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 7170 | mHomeProcess.writeToProto(proto, HOME_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7171 | } |
| 7172 | |
| 7173 | if (mPreviousProcess != null && (dumpPackage == null |
| 7174 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 7175 | mPreviousProcess.writeToProto(proto, PREVIOUS_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7176 | proto.write(PREVIOUS_PROC_VISIBLE_TIME_MS, mPreviousProcessVisibleTime); |
| 7177 | } |
| 7178 | |
| 7179 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 7180 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 7181 | mHeavyWeightProcess.writeToProto(proto, HEAVY_WEIGHT_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7182 | } |
| 7183 | |
| 7184 | for (Map.Entry<String, Integer> entry |
| 7185 | : mCompatModePackages.getPackages().entrySet()) { |
| 7186 | String pkg = entry.getKey(); |
| 7187 | int mode = entry.getValue(); |
| 7188 | if (dumpPackage == null || dumpPackage.equals(pkg)) { |
| 7189 | long compatToken = proto.start(SCREEN_COMPAT_PACKAGES); |
| 7190 | proto.write(PACKAGE, pkg); |
| 7191 | proto.write(MODE, mode); |
| 7192 | proto.end(compatToken); |
| 7193 | } |
| 7194 | } |
| 7195 | |
| 7196 | if (mCurAppTimeTracker != null) { |
| 7197 | mCurAppTimeTracker.writeToProto(proto, CURRENT_TRACKER, true); |
| 7198 | } |
| 7199 | |
| 7200 | } |
| 7201 | } |
| 7202 | |
| 7203 | @Override |
| 7204 | public boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, |
| 7205 | String[] args, int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, |
| 7206 | boolean dumpFocusedStackOnly) { |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 7207 | return ActivityTaskManagerService.this.dumpActivity(fd, pw, name, args, opti, dumpAll, |
| 7208 | dumpVisibleStacksOnly, dumpFocusedStackOnly); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7209 | } |
| 7210 | |
| 7211 | @Override |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 7212 | public void dumpForOom(PrintWriter pw) { |
| 7213 | synchronized (mGlobalLock) { |
| 7214 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 7215 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 7216 | if (mHeavyWeightProcess != null) { |
| 7217 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 7218 | } |
| 7219 | } |
| 7220 | } |
| 7221 | |
| 7222 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7223 | public boolean canGcNow() { |
| 7224 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7225 | return isSleeping() || mRootActivityContainer.allResumedActivitiesIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7226 | } |
| 7227 | } |
| 7228 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7229 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7230 | @Override |
| 7231 | public WindowProcessController getTopApp() { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7232 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7233 | final ActivityRecord top = mRootActivityContainer.getTopResumedActivity(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7234 | return top != null ? top.app : null; |
| 7235 | } |
| 7236 | } |
| 7237 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7238 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7239 | @Override |
| 7240 | public void rankTaskLayersIfNeeded() { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7241 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7242 | if (mRootActivityContainer != null) { |
| 7243 | mRootActivityContainer.rankTaskLayersIfNeeded(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7244 | } |
| 7245 | } |
| 7246 | } |
| 7247 | |
| 7248 | @Override |
| 7249 | public void scheduleDestroyAllActivities(String reason) { |
| 7250 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7251 | mRootActivityContainer.scheduleDestroyAllActivities(null, reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7252 | } |
| 7253 | } |
| 7254 | |
| 7255 | @Override |
| 7256 | public void removeUser(int userId) { |
| 7257 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7258 | mRootActivityContainer.removeUser(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7259 | } |
| 7260 | } |
| 7261 | |
| 7262 | @Override |
| 7263 | public boolean switchUser(int userId, UserState userState) { |
| 7264 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7265 | return mRootActivityContainer.switchUser(userId, userState); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7266 | } |
| 7267 | } |
| 7268 | |
| 7269 | @Override |
| 7270 | public void onHandleAppCrash(WindowProcessController wpc) { |
| 7271 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7272 | mRootActivityContainer.handleAppCrash(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7273 | } |
| 7274 | } |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 7275 | |
| 7276 | @Override |
| 7277 | public int finishTopCrashedActivities(WindowProcessController crashedApp, String reason) { |
| 7278 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7279 | return mRootActivityContainer.finishTopCrashedActivities(crashedApp, reason); |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 7280 | } |
| 7281 | } |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7282 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7283 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7284 | @Override |
| 7285 | public void onUidActive(int uid, int procState) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7286 | mActiveUids.onUidActive(uid, procState); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7287 | } |
| 7288 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7289 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7290 | @Override |
| 7291 | public void onUidInactive(int uid) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7292 | mActiveUids.onUidInactive(uid); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7293 | } |
| 7294 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7295 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7296 | @Override |
| 7297 | public void onActiveUidsCleared() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7298 | mActiveUids.onActiveUidsCleared(); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7299 | } |
| 7300 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7301 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7302 | @Override |
| 7303 | public void onUidProcStateChanged(int uid, int procState) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7304 | mActiveUids.onUidProcStateChanged(uid, procState); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7305 | } |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7306 | |
| 7307 | @Override |
| 7308 | public void onUidAddedToPendingTempWhitelist(int uid, String tag) { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7309 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7310 | mPendingTempWhitelist.put(uid, tag); |
| 7311 | } |
| 7312 | } |
| 7313 | |
| 7314 | @Override |
| 7315 | public void onUidRemovedFromPendingTempWhitelist(int uid) { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7316 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7317 | mPendingTempWhitelist.remove(uid); |
| 7318 | } |
| 7319 | } |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 7320 | |
| 7321 | @Override |
| 7322 | public boolean handleAppCrashInActivityController(String processName, int pid, |
| 7323 | String shortMsg, String longMsg, long timeMillis, String stackTrace, |
| 7324 | Runnable killCrashingAppCallback) { |
| 7325 | synchronized (mGlobalLock) { |
| 7326 | if (mController == null) { |
| 7327 | return false; |
| 7328 | } |
| 7329 | |
| 7330 | try { |
| 7331 | if (!mController.appCrashed(processName, pid, shortMsg, longMsg, timeMillis, |
| 7332 | stackTrace)) { |
| 7333 | killCrashingAppCallback.run(); |
| 7334 | return true; |
| 7335 | } |
| 7336 | } catch (RemoteException e) { |
| 7337 | mController = null; |
| 7338 | Watchdog.getInstance().setActivityController(null); |
| 7339 | } |
| 7340 | return false; |
| 7341 | } |
| 7342 | } |
Wale Ogunwale | d7889f5 | 2018-10-25 11:03:20 -0700 | [diff] [blame] | 7343 | |
| 7344 | @Override |
| 7345 | public void removeRecentTasksByPackageName(String packageName, int userId) { |
| 7346 | synchronized (mGlobalLock) { |
| 7347 | mRecentTasks.removeTasksByPackageName(packageName, userId); |
| 7348 | } |
| 7349 | } |
| 7350 | |
| 7351 | @Override |
| 7352 | public void cleanupRecentTasksForUser(int userId) { |
| 7353 | synchronized (mGlobalLock) { |
| 7354 | mRecentTasks.cleanupLocked(userId); |
| 7355 | } |
| 7356 | } |
| 7357 | |
| 7358 | @Override |
| 7359 | public void loadRecentTasksForUser(int userId) { |
| 7360 | synchronized (mGlobalLock) { |
| 7361 | mRecentTasks.loadUserRecentsLocked(userId); |
| 7362 | } |
| 7363 | } |
| 7364 | |
| 7365 | @Override |
| 7366 | public void onPackagesSuspendedChanged(String[] packages, boolean suspended, int userId) { |
| 7367 | synchronized (mGlobalLock) { |
| 7368 | mRecentTasks.onPackagesSuspendedChanged(packages, suspended, userId); |
| 7369 | } |
| 7370 | } |
| 7371 | |
| 7372 | @Override |
| 7373 | public void flushRecentTasks() { |
| 7374 | mRecentTasks.flush(); |
| 7375 | } |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 7376 | |
| 7377 | @Override |
| 7378 | public WindowProcessController getHomeProcess() { |
| 7379 | synchronized (mGlobalLock) { |
| 7380 | return mHomeProcess; |
| 7381 | } |
| 7382 | } |
| 7383 | |
| 7384 | @Override |
| 7385 | public WindowProcessController getPreviousProcess() { |
| 7386 | synchronized (mGlobalLock) { |
| 7387 | return mPreviousProcess; |
| 7388 | } |
| 7389 | } |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 7390 | |
| 7391 | @Override |
| 7392 | public void clearLockedTasks(String reason) { |
| 7393 | synchronized (mGlobalLock) { |
| 7394 | getLockTaskController().clearLockedTasks(reason); |
| 7395 | } |
| 7396 | } |
| 7397 | |
| 7398 | @Override |
| 7399 | public void updateUserConfiguration() { |
| 7400 | synchronized (mGlobalLock) { |
| 7401 | final Configuration configuration = new Configuration(getGlobalConfiguration()); |
| 7402 | final int currentUserId = mAmInternal.getCurrentUserId(); |
| 7403 | Settings.System.adjustConfigurationForUser(mContext.getContentResolver(), |
| 7404 | configuration, currentUserId, Settings.System.canWrite(mContext)); |
| 7405 | updateConfigurationLocked(configuration, null /* starting */, |
| 7406 | false /* initLocale */, false /* persistent */, currentUserId, |
| 7407 | false /* deferResume */); |
| 7408 | } |
| 7409 | } |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 7410 | |
| 7411 | @Override |
| 7412 | public boolean canShowErrorDialogs() { |
| 7413 | synchronized (mGlobalLock) { |
| 7414 | return mShowDialogs && !mSleeping && !mShuttingDown |
| 7415 | && !mKeyguardController.isKeyguardOrAodShowing(DEFAULT_DISPLAY) |
| 7416 | && !hasUserRestriction(UserManager.DISALLOW_SYSTEM_ERROR_DIALOGS, |
| 7417 | mAmInternal.getCurrentUserId()) |
| 7418 | && !(UserManager.isDeviceInDemoMode(mContext) |
| 7419 | && mAmInternal.getCurrentUser().isDemo()); |
| 7420 | } |
| 7421 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 7422 | |
| 7423 | @Override |
| 7424 | public void setProfileApp(String profileApp) { |
| 7425 | synchronized (mGlobalLock) { |
| 7426 | mProfileApp = profileApp; |
| 7427 | } |
| 7428 | } |
| 7429 | |
| 7430 | @Override |
| 7431 | public void setProfileProc(WindowProcessController wpc) { |
| 7432 | synchronized (mGlobalLock) { |
| 7433 | mProfileProc = wpc; |
| 7434 | } |
| 7435 | } |
| 7436 | |
| 7437 | @Override |
| 7438 | public void setProfilerInfo(ProfilerInfo profilerInfo) { |
| 7439 | synchronized (mGlobalLock) { |
| 7440 | mProfilerInfo = profilerInfo; |
| 7441 | } |
| 7442 | } |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 7443 | |
| 7444 | @Override |
| 7445 | public ActivityMetricsLaunchObserverRegistry getLaunchObserverRegistry() { |
| 7446 | synchronized (mGlobalLock) { |
| 7447 | return mStackSupervisor.getActivityMetricsLogger().getLaunchObserverRegistry(); |
| 7448 | } |
| 7449 | } |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 7450 | |
| 7451 | @Override |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 7452 | public ActivityManager.TaskSnapshot getTaskSnapshotNoRestore(int taskId, |
| 7453 | boolean reducedResolution) { |
| 7454 | return ActivityTaskManagerService.this.getTaskSnapshot(taskId, reducedResolution, |
| 7455 | false /* restoreFromDisk */); |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 7456 | } |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 7457 | |
| 7458 | @Override |
| 7459 | public boolean isUidForeground(int uid) { |
| 7460 | synchronized (mGlobalLock) { |
| 7461 | return ActivityTaskManagerService.this.isUidForeground(uid); |
| 7462 | } |
| 7463 | } |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7464 | |
| 7465 | @Override |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 7466 | public void setDeviceOwnerUid(int uid) { |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7467 | synchronized (mGlobalLock) { |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 7468 | ActivityTaskManagerService.this.setDeviceOwnerUid(uid); |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7469 | } |
| 7470 | } |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7471 | |
| 7472 | @Override |
| 7473 | public void setCompanionAppPackages(int userId, Set<String> companionAppPackages) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7474 | // Translate package names into UIDs |
| 7475 | final Set<Integer> result = new HashSet<>(); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7476 | for (String pkg : companionAppPackages) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7477 | final int uid = getPackageManagerInternalLocked().getPackageUid(pkg, 0, userId); |
| 7478 | if (uid >= 0) { |
| 7479 | result.add(uid); |
| 7480 | } |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7481 | } |
| 7482 | synchronized (mGlobalLock) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7483 | mCompanionAppUidsMap.put(userId, result); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7484 | } |
| 7485 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 7486 | } |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 7487 | } |