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; |
| 22 | import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 23 | import static android.Manifest.permission.MANAGE_ACTIVITY_STACKS; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 24 | import static android.Manifest.permission.READ_FRAME_BUFFER; |
| 25 | import static android.Manifest.permission.REMOVE_TASKS; |
| 26 | import static android.Manifest.permission.START_TASKS_FROM_RECENTS; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 27 | import static android.Manifest.permission.STOP_APP_SWITCHES; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 28 | import static android.app.ActivityManager.LOCK_TASK_MODE_NONE; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 29 | import static android.app.ActivityManagerInternal.ALLOW_FULL_ONLY; |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 30 | import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 31 | import static android.app.ActivityTaskManager.RESIZE_MODE_PRESERVE_WINDOW; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 32 | import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT; |
| 33 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 34 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 35 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 36 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 37 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 38 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 39 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 40 | import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 41 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 42 | import static android.content.pm.ApplicationInfo.FLAG_FACTORY_TEST; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 43 | import static android.content.pm.ConfigurationInfo.GL_ES_VERSION_UNDEFINED; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 44 | import static android.content.pm.PackageManager.FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS; |
| 45 | import static android.content.pm.PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 46 | import static android.content.pm.PackageManager.FEATURE_PC; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 47 | import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 48 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 49 | import static android.content.res.Configuration.UI_MODE_TYPE_TELEVISION; |
| 50 | import static android.os.Build.VERSION_CODES.N; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 51 | import static android.os.FactoryTest.FACTORY_TEST_HIGH_LEVEL; |
| 52 | import static android.os.FactoryTest.FACTORY_TEST_LOW_LEVEL; |
| 53 | import static android.os.FactoryTest.FACTORY_TEST_OFF; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 54 | import static android.os.Process.FIRST_APPLICATION_UID; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 55 | import static android.os.Process.SYSTEM_UID; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 56 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 57 | import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT; |
| 58 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES; |
| 59 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RTL; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 60 | import static android.provider.Settings.Global.HIDE_ERROR_DIALOGS; |
| 61 | import static android.provider.Settings.System.FONT_SCALE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 62 | import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_APPLICATION; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 63 | import static android.text.format.DateUtils.MINUTE_IN_MILLIS; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 64 | import static android.view.Display.DEFAULT_DISPLAY; |
| 65 | import static android.view.Display.INVALID_DISPLAY; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 66 | import static android.view.WindowManager.TRANSIT_NONE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 67 | import static android.view.WindowManager.TRANSIT_TASK_IN_PLACE; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 68 | |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 69 | import static com.android.server.am.ActivityManagerService.ANR_TRACE_DIR; |
| 70 | import static com.android.server.am.ActivityManagerService.MY_PID; |
| 71 | import static com.android.server.am.ActivityManagerService.STOCK_PM_FLAGS; |
| 72 | import static com.android.server.am.ActivityManagerService.dumpStackTraces; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 73 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CONFIG_WILL_CHANGE; |
| 74 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CONTROLLER; |
| 75 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CURRENT_TRACKER; |
| 76 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.Controller.IS_A_MONKEY; |
| 77 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.GLOBAL_CONFIGURATION; |
| 78 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.GOING_TO_SLEEP; |
| 79 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HEAVY_WEIGHT_PROC; |
| 80 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HOME_PROC; |
| 81 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.LAUNCHING_ACTIVITY; |
| 82 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 83 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC_VISIBLE_TIME_MS; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 84 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.SCREEN_COMPAT_PACKAGES; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 85 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.MODE; |
| 86 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage.PACKAGE; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 87 | import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING; |
| 88 | import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 89 | import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; |
| 90 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
| 91 | import static com.android.server.wm.ActivityStackSupervisor.REMOVE_FROM_RECENTS; |
| 92 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL; |
| 93 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONFIGURATION; |
| 94 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_FOCUS; |
| 95 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_IMMERSIVE; |
| 96 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_LOCKTASK; |
| 97 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STACK; |
| 98 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; |
| 99 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 100 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_VISIBILITY; |
| 101 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFIGURATION; |
| 102 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_FOCUS; |
| 103 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_IMMERSIVE; |
| 104 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_LOCKTASK; |
| 105 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; |
| 106 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; |
| 107 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_VISIBILITY; |
| 108 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 109 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 110 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_CONTENT; |
| 111 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_DATA; |
| 112 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_RECEIVER_EXTRAS; |
| 113 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_STRUCTURE; |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 114 | import static com.android.server.wm.ActivityTaskManagerService.H.REPORT_TIME_TRACKER_MSG; |
| 115 | import static com.android.server.wm.ActivityTaskManagerService.UiHandler.DISMISS_DIALOG_UI_MSG; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 116 | import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; |
| 117 | import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 118 | import static com.android.server.wm.RootActivityContainer.MATCH_TASK_IN_STACKS_ONLY; |
| 119 | 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] | 120 | import static com.android.server.wm.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK; |
| 121 | import static com.android.server.wm.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT; |
| 122 | import static com.android.server.wm.TaskRecord.REPARENT_LEAVE_STACK_IN_PLACE; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 123 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 124 | import android.Manifest; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 125 | import android.annotation.NonNull; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 126 | import android.annotation.Nullable; |
| 127 | import android.annotation.UserIdInt; |
| 128 | import android.app.Activity; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 129 | import android.app.ActivityManager; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 130 | import android.app.ActivityManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 131 | import android.app.ActivityOptions; |
| 132 | import android.app.ActivityTaskManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 133 | import android.app.ActivityThread; |
| 134 | import android.app.AlertDialog; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 135 | import android.app.AppGlobals; |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 136 | import android.app.AppOpsManager; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 137 | import android.app.Dialog; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 138 | import android.app.IActivityController; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 139 | import android.app.IActivityTaskManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 140 | import android.app.IApplicationThread; |
| 141 | import android.app.IAssistDataReceiver; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 142 | import android.app.INotificationManager; |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 143 | import android.app.IRequestFinishCallback; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 144 | import android.app.ITaskStackListener; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 145 | import android.app.Notification; |
| 146 | import android.app.NotificationManager; |
| 147 | import android.app.PendingIntent; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 148 | import android.app.PictureInPictureParams; |
| 149 | import android.app.ProfilerInfo; |
| 150 | import android.app.RemoteAction; |
| 151 | import android.app.WaitResult; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 152 | import android.app.WindowConfiguration; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 153 | import android.app.admin.DevicePolicyCache; |
| 154 | import android.app.assist.AssistContent; |
| 155 | import android.app.assist.AssistStructure; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 156 | import android.app.usage.UsageStatsManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 157 | import android.content.ActivityNotFoundException; |
| 158 | import android.content.ComponentName; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 159 | import android.content.ContentResolver; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 160 | import android.content.Context; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 161 | import android.content.DialogInterface; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 162 | import android.content.IIntentSender; |
| 163 | import android.content.Intent; |
| 164 | import android.content.pm.ActivityInfo; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 165 | import android.content.pm.ApplicationInfo; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 166 | import android.content.pm.ConfigurationInfo; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 167 | import android.content.pm.IPackageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 168 | import android.content.pm.PackageManager; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 169 | import android.content.pm.PackageManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 170 | import android.content.pm.ParceledListSlice; |
| 171 | import android.content.pm.ResolveInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 172 | import android.content.res.CompatibilityInfo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 173 | import android.content.res.Configuration; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 174 | import android.content.res.Resources; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 175 | import android.database.ContentObserver; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 176 | import android.graphics.Bitmap; |
| 177 | import android.graphics.Point; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 178 | import android.graphics.Rect; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 179 | import android.metrics.LogMaker; |
| 180 | import android.net.Uri; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 181 | import android.os.Binder; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 182 | import android.os.Build; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 183 | import android.os.Bundle; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 184 | import android.os.FactoryTest; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 185 | import android.os.FileUtils; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 186 | import android.os.Handler; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 187 | import android.os.IBinder; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 188 | import android.os.IUserManager; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 189 | import android.os.LocaleList; |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 190 | import android.os.Looper; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 191 | import android.os.Message; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 192 | import android.os.PersistableBundle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 193 | import android.os.PowerManager; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 194 | import android.os.PowerManagerInternal; |
Marvin Ramin | 830d4e3 | 2019-03-12 13:16:58 +0100 | [diff] [blame] | 195 | import android.os.Process; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 196 | import android.os.RemoteException; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 197 | import android.os.ServiceManager; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 198 | import android.os.StrictMode; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 199 | import android.os.SystemClock; |
| 200 | import android.os.SystemProperties; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 201 | import android.os.Trace; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 202 | import android.os.UpdateLock; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 203 | import android.os.UserHandle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 204 | import android.os.UserManager; |
| 205 | import android.os.WorkSource; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 206 | import android.os.storage.IStorageManager; |
| 207 | import android.os.storage.StorageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 208 | import android.provider.Settings; |
| 209 | import android.service.voice.IVoiceInteractionSession; |
| 210 | import android.service.voice.VoiceInteractionManagerInternal; |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 211 | import android.sysprop.DisplayProperties; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 212 | import android.telecom.TelecomManager; |
| 213 | import android.text.TextUtils; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 214 | import android.text.format.Time; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 215 | import android.util.ArrayMap; |
| 216 | import android.util.EventLog; |
| 217 | import android.util.Log; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 218 | import android.util.Slog; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 219 | import android.util.SparseArray; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 220 | import android.util.SparseIntArray; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 221 | import android.util.StatsLog; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 222 | import android.util.TimeUtils; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 223 | import android.util.proto.ProtoOutputStream; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 224 | import android.view.IRecentsAnimationRunner; |
| 225 | import android.view.RemoteAnimationAdapter; |
| 226 | import android.view.RemoteAnimationDefinition; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 227 | import android.view.WindowManager; |
lumark | 5df4951 | 2019-04-02 14:56:46 +0800 | [diff] [blame] | 228 | import android.view.inputmethod.InputMethodSystemProperty; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 229 | |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 230 | import com.android.internal.R; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 231 | import com.android.internal.annotations.VisibleForTesting; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 232 | import com.android.internal.app.AssistUtils; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 233 | import com.android.internal.app.IAppOpsService; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 234 | import com.android.internal.app.IVoiceInteractor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 235 | import com.android.internal.app.ProcessMap; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 236 | import com.android.internal.logging.MetricsLogger; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 237 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 238 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
| 239 | import com.android.internal.notification.SystemNotificationChannels; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 240 | import com.android.internal.os.TransferPipe; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 241 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 242 | import com.android.internal.policy.IKeyguardDismissCallback; |
| 243 | import com.android.internal.policy.KeyguardDismissCallback; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 244 | import com.android.internal.util.ArrayUtils; |
| 245 | import com.android.internal.util.FastPrintWriter; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 246 | import com.android.internal.util.Preconditions; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 247 | import com.android.internal.util.function.pooled.PooledLambda; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 248 | import com.android.server.AttributeCache; |
Marvin Ramin | 830d4e3 | 2019-03-12 13:16:58 +0100 | [diff] [blame] | 249 | import com.android.server.DeviceIdleController; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 250 | import com.android.server.LocalServices; |
| 251 | import com.android.server.SystemService; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 252 | import com.android.server.SystemServiceManager; |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 253 | import com.android.server.UiThread; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 254 | import com.android.server.Watchdog; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 255 | import com.android.server.am.ActivityManagerService; |
| 256 | import com.android.server.am.ActivityManagerServiceDumpActivitiesProto; |
| 257 | import com.android.server.am.ActivityManagerServiceDumpProcessesProto; |
| 258 | import com.android.server.am.AppTimeTracker; |
| 259 | import com.android.server.am.BaseErrorDialog; |
| 260 | import com.android.server.am.EventLogTags; |
| 261 | import com.android.server.am.PendingIntentController; |
| 262 | import com.android.server.am.PendingIntentRecord; |
| 263 | import com.android.server.am.UserState; |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 264 | import com.android.server.appop.AppOpsService; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 265 | import com.android.server.firewall.IntentFirewall; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 266 | import com.android.server.pm.UserManagerService; |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 267 | import com.android.server.policy.PermissionPolicyInternal; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 268 | import com.android.server.uri.UriGrantsManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 269 | import com.android.server.vr.VrManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 270 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 271 | import java.io.BufferedReader; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 272 | import java.io.File; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 273 | import java.io.FileDescriptor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 274 | import java.io.FileOutputStream; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 275 | import java.io.FileReader; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 276 | import java.io.IOException; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 277 | import java.io.PrintWriter; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 278 | import java.io.StringWriter; |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 279 | import java.lang.annotation.ElementType; |
| 280 | import java.lang.annotation.Retention; |
| 281 | import java.lang.annotation.RetentionPolicy; |
| 282 | import java.lang.annotation.Target; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 283 | import java.lang.ref.WeakReference; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 284 | import java.text.DateFormat; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 285 | import java.util.ArrayList; |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 286 | import java.util.Arrays; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 287 | import java.util.Date; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 288 | import java.util.HashMap; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 289 | import java.util.HashSet; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 290 | import java.util.List; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 291 | import java.util.Locale; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 292 | import java.util.Map; |
| 293 | import java.util.Set; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 294 | |
| 295 | /** |
| 296 | * System service for managing activities and their containers (task, stacks, displays,... ). |
| 297 | * |
| 298 | * {@hide} |
| 299 | */ |
| 300 | public class ActivityTaskManagerService extends IActivityTaskManager.Stub { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 301 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityTaskManagerService" : TAG_ATM; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 302 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 303 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 304 | private static final String TAG_IMMERSIVE = TAG + POSTFIX_IMMERSIVE; |
| 305 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
| 306 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
| 307 | private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 308 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 309 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 310 | // How long we wait until we timeout on key dispatching. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 311 | public static final int KEY_DISPATCHING_TIMEOUT_MS = 5 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 312 | // How long we wait until we timeout on key dispatching during instrumentation. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 313 | static final int INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT_MS = 60 * 1000; |
Michal Karpinski | fc6872e | 2019-05-21 15:18:44 +0100 | [diff] [blame] | 314 | // How long we permit background activity starts after an activity in the process |
| 315 | // started or finished. |
| 316 | static final long ACTIVITY_BG_START_GRACE_PERIOD_MS = 10 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 317 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 318 | /** Used to indicate that an app transition should be animated. */ |
| 319 | static final boolean ANIMATE = true; |
| 320 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 321 | /** Hardware-reported OpenGLES version. */ |
| 322 | final int GL_ES_VERSION; |
| 323 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 324 | public static final String DUMP_ACTIVITIES_CMD = "activities" ; |
| 325 | public static final String DUMP_ACTIVITIES_SHORT_CMD = "a" ; |
| 326 | public static final String DUMP_LASTANR_CMD = "lastanr" ; |
| 327 | public static final String DUMP_LASTANR_TRACES_CMD = "lastanr-traces" ; |
| 328 | public static final String DUMP_STARTER_CMD = "starter" ; |
| 329 | public static final String DUMP_CONTAINERS_CMD = "containers" ; |
| 330 | public static final String DUMP_RECENTS_CMD = "recents" ; |
| 331 | public static final String DUMP_RECENTS_SHORT_CMD = "r" ; |
| 332 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 333 | /** This activity is not being relaunched, or being relaunched for a non-resize reason. */ |
| 334 | public static final int RELAUNCH_REASON_NONE = 0; |
| 335 | /** This activity is being relaunched due to windowing mode change. */ |
| 336 | public static final int RELAUNCH_REASON_WINDOWING_MODE_RESIZE = 1; |
| 337 | /** This activity is being relaunched due to a free-resize operation. */ |
| 338 | public static final int RELAUNCH_REASON_FREE_RESIZE = 2; |
| 339 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 340 | Context mContext; |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 341 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 342 | /** |
| 343 | * This Context is themable and meant for UI display (AlertDialogs, etc.). The theme can |
| 344 | * change at runtime. Use mContext for non-UI purposes. |
| 345 | */ |
| 346 | final Context mUiContext; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 347 | final ActivityThread mSystemThread; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 348 | H mH; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 349 | UiHandler mUiHandler; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 350 | ActivityManagerInternal mAmInternal; |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 351 | UriGrantsManagerInternal mUgmInternal; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 352 | private PackageManagerInternal mPmInternal; |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 353 | private PermissionPolicyInternal mPermissionPolicyInternal; |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 354 | @VisibleForTesting |
| 355 | final ActivityTaskManagerInternal mInternal; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 356 | PowerManagerInternal mPowerManagerInternal; |
| 357 | private UsageStatsManagerInternal mUsageStatsInternal; |
| 358 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 359 | PendingIntentController mPendingIntentController; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 360 | IntentFirewall mIntentFirewall; |
| 361 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 362 | /* Global service lock used by the package the owns this service. */ |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 363 | final WindowManagerGlobalLock mGlobalLock = new WindowManagerGlobalLock(); |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 364 | /** |
| 365 | * It is the same instance as {@link mGlobalLock}, just declared as a type that the |
| 366 | * locked-region-code-injection does't recognize it. It is used to skip wrapping priority |
| 367 | * booster for places that are already in the scope of another booster (e.g. computing oom-adj). |
| 368 | * |
| 369 | * @see WindowManagerThreadPriorityBooster |
| 370 | */ |
| 371 | final Object mGlobalLockWithoutBoost = mGlobalLock; |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 372 | ActivityStackSupervisor mStackSupervisor; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 373 | RootActivityContainer mRootActivityContainer; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 374 | WindowManagerService mWindowManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 375 | private UserManagerService mUserManager; |
| 376 | private AppOpsService mAppOpsService; |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 377 | /** All active uids in the system. */ |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 378 | private final MirrorActiveUids mActiveUids = new MirrorActiveUids(); |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 379 | private final SparseArray<String> mPendingTempWhitelist = new SparseArray<>(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 380 | /** All processes currently running that might have a window organized by name. */ |
| 381 | final ProcessMap<WindowProcessController> mProcessNames = new ProcessMap<>(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 382 | /** All processes we currently have running mapped by pid and uid */ |
| 383 | final WindowProcessControllerMap mProcessMap = new WindowProcessControllerMap(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 384 | /** This is the process holding what we currently consider to be the "home" activity. */ |
| 385 | WindowProcessController mHomeProcess; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 386 | /** The currently running heavy-weight process, if any. */ |
| 387 | WindowProcessController mHeavyWeightProcess = null; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 388 | boolean mHasHeavyWeightFeature; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 389 | /** |
| 390 | * This is the process holding the activity the user last visited that is in a different process |
| 391 | * from the one they are currently in. |
| 392 | */ |
| 393 | WindowProcessController mPreviousProcess; |
| 394 | /** The time at which the previous process was last visible. */ |
| 395 | long mPreviousProcessVisibleTime; |
| 396 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 397 | /** List of intents that were used to start the most recent tasks. */ |
| 398 | private RecentTasks mRecentTasks; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 399 | /** State of external calls telling us if the device is awake or asleep. */ |
| 400 | private boolean mKeyguardShown = false; |
| 401 | |
| 402 | // Wrapper around VoiceInteractionServiceManager |
| 403 | private AssistUtils mAssistUtils; |
| 404 | |
| 405 | // VoiceInteraction session ID that changes for each new request except when |
| 406 | // being called for multi-window assist in a single session. |
| 407 | private int mViSessionId = 1000; |
| 408 | |
| 409 | // How long to wait in getAssistContextExtras for the activity and foreground services |
| 410 | // to respond with the result. |
| 411 | private static final int PENDING_ASSIST_EXTRAS_TIMEOUT = 500; |
| 412 | |
| 413 | // How long top wait when going through the modern assist (which doesn't need to block |
| 414 | // on getting this result before starting to launch its UI). |
| 415 | private static final int PENDING_ASSIST_EXTRAS_LONG_TIMEOUT = 2000; |
| 416 | |
| 417 | // How long to wait in getAutofillAssistStructure() for the activity to respond with the result. |
| 418 | private static final int PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT = 2000; |
| 419 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 420 | // Permission tokens are used to temporarily granted a trusted app the ability to call |
| 421 | // #startActivityAsCaller. A client is expected to dump its token after this time has elapsed, |
| 422 | // showing any appropriate error messages to the user. |
| 423 | private static final long START_AS_CALLER_TOKEN_TIMEOUT = |
| 424 | 10 * MINUTE_IN_MILLIS; |
| 425 | |
| 426 | // How long before the service actually expires a token. This is slightly longer than |
| 427 | // START_AS_CALLER_TOKEN_TIMEOUT, to provide a buffer so clients will rarely encounter the |
| 428 | // expiration exception. |
| 429 | private static final long START_AS_CALLER_TOKEN_TIMEOUT_IMPL = |
| 430 | START_AS_CALLER_TOKEN_TIMEOUT + 2 * 1000; |
| 431 | |
| 432 | // How long the service will remember expired tokens, for the purpose of providing error |
| 433 | // messaging when a client uses an expired token. |
| 434 | private static final long START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT = |
| 435 | START_AS_CALLER_TOKEN_TIMEOUT_IMPL + 20 * MINUTE_IN_MILLIS; |
| 436 | |
Marvin Ramin | 830d4e3 | 2019-03-12 13:16:58 +0100 | [diff] [blame] | 437 | // How long to whitelist the Services for when requested. |
| 438 | private static final int SERVICE_LAUNCH_IDLE_WHITELIST_DURATION_MS = 5 * 1000; |
| 439 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 440 | // Activity tokens of system activities that are delegating their call to |
| 441 | // #startActivityByCaller, keyed by the permissionToken granted to the delegate. |
| 442 | final HashMap<IBinder, IBinder> mStartActivitySources = new HashMap<>(); |
| 443 | |
| 444 | // Permission tokens that have expired, but we remember for error reporting. |
| 445 | final ArrayList<IBinder> mExpiredStartAsCallerTokens = new ArrayList<>(); |
| 446 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 447 | private final ArrayList<PendingAssistExtras> mPendingAssistExtras = new ArrayList<>(); |
| 448 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 449 | // Keeps track of the active voice interaction service component, notified from |
| 450 | // VoiceInteractionManagerService |
| 451 | ComponentName mActiveVoiceInteractionServiceComponent; |
| 452 | |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 453 | // A map userId and all its companion app uids |
| 454 | private final Map<Integer, Set<Integer>> mCompanionAppUidsMap = new ArrayMap<>(); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 455 | |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 456 | VrController mVrController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 457 | KeyguardController mKeyguardController; |
| 458 | private final ClientLifecycleManager mLifecycleManager; |
| 459 | private TaskChangeNotificationController mTaskChangeNotificationController; |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 460 | /** The controller for all operations related to locktask. */ |
| 461 | private LockTaskController mLockTaskController; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 462 | private ActivityStartController mActivityStartController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 463 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 464 | boolean mSuppressResizeConfigChanges; |
| 465 | |
| 466 | private final UpdateConfigurationResult mTmpUpdateConfigurationResult = |
| 467 | new UpdateConfigurationResult(); |
| 468 | |
| 469 | static final class UpdateConfigurationResult { |
| 470 | // Configuration changes that were updated. |
| 471 | int changes; |
| 472 | // If the activity was relaunched to match the new configuration. |
| 473 | boolean activityRelaunched; |
| 474 | |
| 475 | void reset() { |
| 476 | changes = 0; |
| 477 | activityRelaunched = false; |
| 478 | } |
| 479 | } |
| 480 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 481 | /** Current sequencing integer of the configuration, for skipping old configurations. */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 482 | private int mConfigurationSeq; |
| 483 | // To cache the list of supported system locales |
| 484 | private String[] mSupportedSystemLocales = null; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 485 | |
| 486 | /** |
| 487 | * Temp object used when global and/or display override configuration is updated. It is also |
| 488 | * sent to outer world instead of {@link #getGlobalConfiguration} because we don't trust |
| 489 | * anyone... |
| 490 | */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 491 | private Configuration mTempConfig = new Configuration(); |
| 492 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 493 | /** Temporary to avoid allocations. */ |
| 494 | final StringBuilder mStringBuilder = new StringBuilder(256); |
| 495 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 496 | // Amount of time after a call to stopAppSwitches() during which we will |
| 497 | // prevent further untrusted switches from happening. |
| 498 | private static final long APP_SWITCH_DELAY_TIME = 5 * 1000; |
| 499 | |
| 500 | /** |
| 501 | * The time at which we will allow normal application switches again, |
| 502 | * after a call to {@link #stopAppSwitches()}. |
| 503 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 504 | private long mAppSwitchesAllowedTime; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 505 | /** |
| 506 | * This is set to true after the first switch after mAppSwitchesAllowedTime |
| 507 | * is set; any switches after that will clear the time. |
| 508 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 509 | private boolean mDidAppSwitch; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 510 | |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 511 | /** |
| 512 | * Last stop app switches time, apps finished before this time cannot start background activity |
| 513 | * even if they are in grace period. |
| 514 | */ |
| 515 | private long mLastStopAppSwitchesTime; |
| 516 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 517 | IActivityController mController = null; |
| 518 | boolean mControllerIsAMonkey = false; |
| 519 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 520 | final int mFactoryTest; |
| 521 | |
| 522 | /** Used to control how we initialize the service. */ |
| 523 | ComponentName mTopComponent; |
| 524 | String mTopAction = Intent.ACTION_MAIN; |
| 525 | String mTopData; |
| 526 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 527 | /** Profiling app information. */ |
| 528 | String mProfileApp = null; |
| 529 | WindowProcessController mProfileProc = null; |
| 530 | ProfilerInfo mProfilerInfo = null; |
| 531 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 532 | /** |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 533 | * Dump of the activity state at the time of the last ANR. Cleared after |
| 534 | * {@link WindowManagerService#LAST_ANR_LIFETIME_DURATION_MSECS} |
| 535 | */ |
| 536 | String mLastANRState; |
| 537 | |
| 538 | /** |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 539 | * Used to retain an update lock when the foreground activity is in |
| 540 | * immersive mode. |
| 541 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 542 | private final UpdateLock mUpdateLock = new UpdateLock("immersive"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 543 | |
| 544 | /** |
| 545 | * Packages that are being allowed to perform unrestricted app switches. Mapping is |
| 546 | * User -> Type -> uid. |
| 547 | */ |
| 548 | final SparseArray<ArrayMap<String, Integer>> mAllowAppSwitchUids = new SparseArray<>(); |
| 549 | |
| 550 | /** The dimensions of the thumbnails in the Recents UI. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 551 | private int mThumbnailWidth; |
| 552 | private int mThumbnailHeight; |
| 553 | private float mFullscreenThumbnailScale; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 554 | |
| 555 | /** |
| 556 | * Flag that indicates if multi-window is enabled. |
| 557 | * |
| 558 | * For any particular form of multi-window to be enabled, generic multi-window must be enabled |
| 559 | * in {@link com.android.internal.R.bool#config_supportsMultiWindow} config or |
| 560 | * {@link Settings.Global#DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES} development option set. |
| 561 | * At least one of the forms of multi-window must be enabled in order for this flag to be |
| 562 | * initialized to 'true'. |
| 563 | * |
| 564 | * @see #mSupportsSplitScreenMultiWindow |
| 565 | * @see #mSupportsFreeformWindowManagement |
| 566 | * @see #mSupportsPictureInPicture |
| 567 | * @see #mSupportsMultiDisplay |
| 568 | */ |
| 569 | boolean mSupportsMultiWindow; |
| 570 | boolean mSupportsSplitScreenMultiWindow; |
| 571 | boolean mSupportsFreeformWindowManagement; |
| 572 | boolean mSupportsPictureInPicture; |
| 573 | boolean mSupportsMultiDisplay; |
| 574 | boolean mForceResizableActivities; |
| 575 | |
| 576 | final List<ActivityTaskManagerInternal.ScreenObserver> mScreenObservers = new ArrayList<>(); |
| 577 | |
| 578 | // VR Vr2d Display Id. |
| 579 | int mVr2dDisplayId = INVALID_DISPLAY; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 580 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 581 | /** |
| 582 | * Set while we are wanting to sleep, to prevent any |
| 583 | * activities from being started/resumed. |
| 584 | * |
| 585 | * TODO(b/33594039): Clarify the actual state transitions represented by mSleeping. |
| 586 | * |
| 587 | * Currently mSleeping is set to true when transitioning into the sleep state, and remains true |
| 588 | * while in the sleep state until there is a pending transition out of sleep, in which case |
| 589 | * mSleeping is set to false, and remains false while awake. |
| 590 | * |
| 591 | * Whether mSleeping can quickly toggled between true/false without the device actually |
| 592 | * display changing states is undefined. |
| 593 | */ |
| 594 | private boolean mSleeping = false; |
| 595 | |
| 596 | /** |
| 597 | * The process state used for processes that are running the top activities. |
| 598 | * This changes between TOP and TOP_SLEEPING to following mSleeping. |
| 599 | */ |
| 600 | int mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
| 601 | |
| 602 | // Whether we should show our dialogs (ANR, crash, etc) or just perform their default action |
| 603 | // automatically. Important for devices without direct input devices. |
| 604 | private boolean mShowDialogs = true; |
| 605 | |
| 606 | /** Set if we are shutting down the system, similar to sleeping. */ |
| 607 | boolean mShuttingDown = false; |
| 608 | |
| 609 | /** |
| 610 | * We want to hold a wake lock while running a voice interaction session, since |
| 611 | * this may happen with the screen off and we need to keep the CPU running to |
| 612 | * be able to continue to interact with the user. |
| 613 | */ |
| 614 | PowerManager.WakeLock mVoiceWakeLock; |
| 615 | |
| 616 | /** |
| 617 | * Set while we are running a voice interaction. This overrides sleeping while it is active. |
| 618 | */ |
| 619 | IVoiceInteractionSession mRunningVoice; |
| 620 | |
| 621 | /** |
| 622 | * The last resumed activity. This is identical to the current resumed activity most |
| 623 | * of the time but could be different when we're pausing one activity before we resume |
| 624 | * another activity. |
| 625 | */ |
| 626 | ActivityRecord mLastResumedActivity; |
| 627 | |
| 628 | /** |
| 629 | * The activity that is currently being traced as the active resumed activity. |
| 630 | * |
| 631 | * @see #updateResumedAppTrace |
| 632 | */ |
| 633 | private @Nullable ActivityRecord mTracedResumedActivity; |
| 634 | |
| 635 | /** If non-null, we are tracking the time the user spends in the currently focused app. */ |
| 636 | AppTimeTracker mCurAppTimeTracker; |
| 637 | |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 638 | private AppWarnings mAppWarnings; |
| 639 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 640 | /** |
| 641 | * Packages that the user has asked to have run in screen size |
| 642 | * compatibility mode instead of filling the screen. |
| 643 | */ |
| 644 | CompatModePackages mCompatModePackages; |
| 645 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 646 | private FontScaleSettingObserver mFontScaleSettingObserver; |
| 647 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 648 | private int mDeviceOwnerUid = Process.INVALID_UID; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 649 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 650 | private final class FontScaleSettingObserver extends ContentObserver { |
| 651 | private final Uri mFontScaleUri = Settings.System.getUriFor(FONT_SCALE); |
| 652 | private final Uri mHideErrorDialogsUri = Settings.Global.getUriFor(HIDE_ERROR_DIALOGS); |
| 653 | |
| 654 | public FontScaleSettingObserver() { |
| 655 | super(mH); |
| 656 | final ContentResolver resolver = mContext.getContentResolver(); |
| 657 | resolver.registerContentObserver(mFontScaleUri, false, this, UserHandle.USER_ALL); |
| 658 | resolver.registerContentObserver(mHideErrorDialogsUri, false, this, |
| 659 | UserHandle.USER_ALL); |
| 660 | } |
| 661 | |
| 662 | @Override |
| 663 | public void onChange(boolean selfChange, Uri uri, @UserIdInt int userId) { |
| 664 | if (mFontScaleUri.equals(uri)) { |
| 665 | updateFontScaleIfNeeded(userId); |
| 666 | } else if (mHideErrorDialogsUri.equals(uri)) { |
| 667 | synchronized (mGlobalLock) { |
| 668 | updateShouldShowDialogsLocked(getGlobalConfiguration()); |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 674 | /** Indicates that the method may be invoked frequently or is sensitive to performance. */ |
| 675 | @Target(ElementType.METHOD) |
| 676 | @Retention(RetentionPolicy.SOURCE) |
| 677 | @interface HotPath { |
| 678 | int NONE = 0; |
| 679 | int OOM_ADJUSTMENT = 1; |
| 680 | int LRU_UPDATE = 2; |
| 681 | int PROCESS_CHANGE = 3; |
| 682 | int caller() default NONE; |
| 683 | } |
| 684 | |
Charles Chen | 8d98dd2 | 2018-12-26 17:36:54 +0800 | [diff] [blame] | 685 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 686 | public ActivityTaskManagerService(Context context) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 687 | mContext = context; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 688 | mFactoryTest = FactoryTest.getMode(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 689 | mSystemThread = ActivityThread.currentActivityThread(); |
| 690 | mUiContext = mSystemThread.getSystemUiContext(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 691 | mLifecycleManager = new ClientLifecycleManager(); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 692 | mInternal = new LocalService(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 693 | GL_ES_VERSION = SystemProperties.getInt("ro.opengles.version", GL_ES_VERSION_UNDEFINED); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 696 | public void onSystemReady() { |
| 697 | synchronized (mGlobalLock) { |
| 698 | mHasHeavyWeightFeature = mContext.getPackageManager().hasSystemFeature( |
| 699 | PackageManager.FEATURE_CANT_SAVE_STATE); |
| 700 | mAssistUtils = new AssistUtils(mContext); |
| 701 | mVrController.onSystemReady(); |
| 702 | mRecentTasks.onSystemReadyLocked(); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 703 | mStackSupervisor.onSystemReady(); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 704 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 707 | public void onInitPowerManagement() { |
| 708 | synchronized (mGlobalLock) { |
| 709 | mStackSupervisor.initPowerManagement(); |
| 710 | final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 711 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
| 712 | mVoiceWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*voice*"); |
| 713 | mVoiceWakeLock.setReferenceCounted(false); |
| 714 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 717 | public void installSystemProviders() { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 718 | mFontScaleSettingObserver = new FontScaleSettingObserver(); |
| 719 | } |
| 720 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 721 | public void retrieveSettings(ContentResolver resolver) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 722 | final boolean freeformWindowManagement = |
| 723 | mContext.getPackageManager().hasSystemFeature(FEATURE_FREEFORM_WINDOW_MANAGEMENT) |
| 724 | || Settings.Global.getInt( |
| 725 | resolver, DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0; |
| 726 | |
| 727 | final boolean supportsMultiWindow = ActivityTaskManager.supportsMultiWindow(mContext); |
| 728 | final boolean supportsPictureInPicture = supportsMultiWindow && |
| 729 | mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE); |
| 730 | final boolean supportsSplitScreenMultiWindow = |
| 731 | ActivityTaskManager.supportsSplitScreenMultiWindow(mContext); |
| 732 | final boolean supportsMultiDisplay = mContext.getPackageManager() |
| 733 | .hasSystemFeature(FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 734 | final boolean forceRtl = Settings.Global.getInt(resolver, DEVELOPMENT_FORCE_RTL, 0) != 0; |
| 735 | final boolean forceResizable = Settings.Global.getInt( |
| 736 | resolver, DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0; |
Garfield Tan | e084604 | 2018-07-26 13:42:04 -0700 | [diff] [blame] | 737 | final boolean isPc = mContext.getPackageManager().hasSystemFeature(FEATURE_PC); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 738 | |
| 739 | // Transfer any global setting for forcing RTL layout, into a System Property |
Kiyoung Kim | 0fe161d | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 740 | DisplayProperties.debug_force_rtl(forceRtl); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 741 | |
| 742 | final Configuration configuration = new Configuration(); |
| 743 | Settings.System.getConfiguration(resolver, configuration); |
| 744 | if (forceRtl) { |
| 745 | // This will take care of setting the correct layout direction flags |
| 746 | configuration.setLayoutDirection(configuration.locale); |
| 747 | } |
| 748 | |
| 749 | synchronized (mGlobalLock) { |
| 750 | mForceResizableActivities = forceResizable; |
| 751 | final boolean multiWindowFormEnabled = freeformWindowManagement |
| 752 | || supportsSplitScreenMultiWindow |
| 753 | || supportsPictureInPicture |
| 754 | || supportsMultiDisplay; |
| 755 | if ((supportsMultiWindow || forceResizable) && multiWindowFormEnabled) { |
| 756 | mSupportsMultiWindow = true; |
| 757 | mSupportsFreeformWindowManagement = freeformWindowManagement; |
| 758 | mSupportsSplitScreenMultiWindow = supportsSplitScreenMultiWindow; |
| 759 | mSupportsPictureInPicture = supportsPictureInPicture; |
| 760 | mSupportsMultiDisplay = supportsMultiDisplay; |
| 761 | } else { |
| 762 | mSupportsMultiWindow = false; |
| 763 | mSupportsFreeformWindowManagement = false; |
| 764 | mSupportsSplitScreenMultiWindow = false; |
| 765 | mSupportsPictureInPicture = false; |
| 766 | mSupportsMultiDisplay = false; |
| 767 | } |
| 768 | mWindowManager.setForceResizableTasks(mForceResizableActivities); |
| 769 | mWindowManager.setSupportsPictureInPicture(mSupportsPictureInPicture); |
Garfield Tan | e084604 | 2018-07-26 13:42:04 -0700 | [diff] [blame] | 770 | mWindowManager.setSupportsFreeformWindowManagement(mSupportsFreeformWindowManagement); |
| 771 | mWindowManager.setIsPc(isPc); |
Garfield Tan | b5910b4 | 2019-03-14 14:50:59 -0700 | [diff] [blame] | 772 | mWindowManager.mRoot.onSettingsRetrieved(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 773 | // This happens before any activities are started, so we can change global configuration |
| 774 | // in-place. |
| 775 | updateConfigurationLocked(configuration, null, true); |
| 776 | final Configuration globalConfig = getGlobalConfiguration(); |
| 777 | if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Initial config: " + globalConfig); |
| 778 | |
| 779 | // Load resources only after the current configuration has been set. |
| 780 | final Resources res = mContext.getResources(); |
| 781 | mThumbnailWidth = res.getDimensionPixelSize( |
| 782 | com.android.internal.R.dimen.thumbnail_width); |
| 783 | mThumbnailHeight = res.getDimensionPixelSize( |
| 784 | com.android.internal.R.dimen.thumbnail_height); |
| 785 | |
| 786 | if ((globalConfig.uiMode & UI_MODE_TYPE_TELEVISION) == UI_MODE_TYPE_TELEVISION) { |
| 787 | mFullscreenThumbnailScale = (float) res |
| 788 | .getInteger(com.android.internal.R.integer.thumbnail_width_tv) / |
| 789 | (float) globalConfig.screenWidthDp; |
| 790 | } else { |
| 791 | mFullscreenThumbnailScale = res.getFraction( |
| 792 | com.android.internal.R.fraction.thumbnail_fullscreen_scale, 1, 1); |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 797 | public WindowManagerGlobalLock getGlobalLock() { |
| 798 | return mGlobalLock; |
| 799 | } |
| 800 | |
Yunfan Chen | 585f293 | 2019-01-29 16:04:45 +0900 | [diff] [blame] | 801 | /** For test purpose only. */ |
| 802 | @VisibleForTesting |
| 803 | public ActivityTaskManagerInternal getAtmInternal() { |
| 804 | return mInternal; |
| 805 | } |
| 806 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 807 | public void initialize(IntentFirewall intentFirewall, PendingIntentController intentController, |
| 808 | Looper looper) { |
| 809 | mH = new H(looper); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 810 | mUiHandler = new UiHandler(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 811 | mIntentFirewall = intentFirewall; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 812 | final File systemDir = SystemServiceManager.ensureSystemDir(); |
| 813 | mAppWarnings = new AppWarnings(this, mUiContext, mH, mUiHandler, systemDir); |
| 814 | mCompatModePackages = new CompatModePackages(this, systemDir, mH); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 815 | mPendingIntentController = intentController; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 816 | |
| 817 | mTempConfig.setToDefaults(); |
| 818 | mTempConfig.setLocales(LocaleList.getDefault()); |
| 819 | mConfigurationSeq = mTempConfig.seq = 1; |
| 820 | mStackSupervisor = createStackSupervisor(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 821 | mRootActivityContainer = new RootActivityContainer(this); |
| 822 | mRootActivityContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 823 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 824 | mTaskChangeNotificationController = |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 825 | new TaskChangeNotificationController(mGlobalLock, mStackSupervisor, mH); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 826 | mLockTaskController = new LockTaskController(mContext, mStackSupervisor, mH); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 827 | mActivityStartController = new ActivityStartController(this); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 828 | mRecentTasks = createRecentTasks(); |
| 829 | mStackSupervisor.setRecentTasks(mRecentTasks); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 830 | mVrController = new VrController(mGlobalLock); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 831 | mKeyguardController = mStackSupervisor.getKeyguardController(); |
| 832 | } |
| 833 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 834 | public void onActivityManagerInternalAdded() { |
| 835 | synchronized (mGlobalLock) { |
| 836 | mAmInternal = LocalServices.getService(ActivityManagerInternal.class); |
| 837 | mUgmInternal = LocalServices.getService(UriGrantsManagerInternal.class); |
| 838 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 841 | int increaseConfigurationSeqLocked() { |
| 842 | mConfigurationSeq = Math.max(++mConfigurationSeq, 1); |
| 843 | return mConfigurationSeq; |
| 844 | } |
| 845 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 846 | protected ActivityStackSupervisor createStackSupervisor() { |
| 847 | final ActivityStackSupervisor supervisor = new ActivityStackSupervisor(this, mH.getLooper()); |
| 848 | supervisor.initialize(); |
| 849 | return supervisor; |
| 850 | } |
| 851 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 852 | public void setWindowManager(WindowManagerService wm) { |
| 853 | synchronized (mGlobalLock) { |
| 854 | mWindowManager = wm; |
| 855 | mLockTaskController.setWindowManager(wm); |
| 856 | mStackSupervisor.setWindowManager(wm); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 857 | mRootActivityContainer.setWindowManager(wm); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 858 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 861 | public void setUsageStatsManager(UsageStatsManagerInternal usageStatsManager) { |
| 862 | synchronized (mGlobalLock) { |
| 863 | mUsageStatsInternal = usageStatsManager; |
| 864 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 867 | UserManagerService getUserManager() { |
| 868 | if (mUserManager == null) { |
| 869 | IBinder b = ServiceManager.getService(Context.USER_SERVICE); |
| 870 | mUserManager = (UserManagerService) IUserManager.Stub.asInterface(b); |
| 871 | } |
| 872 | return mUserManager; |
| 873 | } |
| 874 | |
| 875 | AppOpsService getAppOpsService() { |
| 876 | if (mAppOpsService == null) { |
| 877 | IBinder b = ServiceManager.getService(Context.APP_OPS_SERVICE); |
| 878 | mAppOpsService = (AppOpsService) IAppOpsService.Stub.asInterface(b); |
| 879 | } |
| 880 | return mAppOpsService; |
| 881 | } |
| 882 | |
| 883 | boolean hasUserRestriction(String restriction, int userId) { |
| 884 | return getUserManager().hasUserRestriction(restriction, userId); |
| 885 | } |
| 886 | |
Michal Karpinski | 1548684 | 2019-04-25 17:33:42 +0100 | [diff] [blame] | 887 | boolean hasSystemAlertWindowPermission(int callingUid, int callingPid, String callingPackage) { |
| 888 | final int mode = getAppOpsService().noteOperation(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, |
| 889 | callingUid, callingPackage); |
| 890 | if (mode == AppOpsManager.MODE_DEFAULT) { |
| 891 | return checkPermission(Manifest.permission.SYSTEM_ALERT_WINDOW, callingPid, callingUid) |
| 892 | == PERMISSION_GRANTED; |
| 893 | } |
| 894 | return mode == AppOpsManager.MODE_ALLOWED; |
| 895 | } |
| 896 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 897 | protected RecentTasks createRecentTasks() { |
| 898 | return new RecentTasks(this, mStackSupervisor); |
| 899 | } |
| 900 | |
| 901 | RecentTasks getRecentTasks() { |
| 902 | return mRecentTasks; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 905 | ClientLifecycleManager getLifecycleManager() { |
| 906 | return mLifecycleManager; |
| 907 | } |
| 908 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 909 | ActivityStartController getActivityStartController() { |
| 910 | return mActivityStartController; |
| 911 | } |
| 912 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 913 | TaskChangeNotificationController getTaskChangeNotificationController() { |
| 914 | return mTaskChangeNotificationController; |
| 915 | } |
| 916 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 917 | LockTaskController getLockTaskController() { |
| 918 | return mLockTaskController; |
| 919 | } |
| 920 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 921 | /** |
| 922 | * Return the global configuration used by the process corresponding to the input pid. This is |
| 923 | * usually the global configuration with some overrides specific to that process. |
| 924 | */ |
| 925 | Configuration getGlobalConfigurationForCallingPid() { |
| 926 | final int pid = Binder.getCallingPid(); |
Yunfan Chen | c2ff6cf | 2018-12-04 16:56:21 -0800 | [diff] [blame] | 927 | return getGlobalConfigurationForPid(pid); |
| 928 | } |
| 929 | |
| 930 | /** |
| 931 | * Return the global configuration used by the process corresponding to the given pid. |
| 932 | */ |
| 933 | Configuration getGlobalConfigurationForPid(int pid) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 934 | if (pid == MY_PID || pid < 0) { |
| 935 | return getGlobalConfiguration(); |
| 936 | } |
| 937 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 938 | final WindowProcessController app = mProcessMap.getProcess(pid); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 939 | return app != null ? app.getConfiguration() : getGlobalConfiguration(); |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | /** |
| 944 | * Return the device configuration info used by the process corresponding to the input pid. |
| 945 | * The value is consistent with the global configuration for the process. |
| 946 | */ |
| 947 | @Override |
| 948 | public ConfigurationInfo getDeviceConfigurationInfo() { |
| 949 | ConfigurationInfo config = new ConfigurationInfo(); |
| 950 | synchronized (mGlobalLock) { |
| 951 | final Configuration globalConfig = getGlobalConfigurationForCallingPid(); |
| 952 | config.reqTouchScreen = globalConfig.touchscreen; |
| 953 | config.reqKeyboardType = globalConfig.keyboard; |
| 954 | config.reqNavigation = globalConfig.navigation; |
| 955 | if (globalConfig.navigation == Configuration.NAVIGATION_DPAD |
| 956 | || globalConfig.navigation == Configuration.NAVIGATION_TRACKBALL) { |
| 957 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 958 | } |
| 959 | if (globalConfig.keyboard != Configuration.KEYBOARD_UNDEFINED |
| 960 | && globalConfig.keyboard != Configuration.KEYBOARD_NOKEYS) { |
| 961 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 962 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 963 | config.reqGlEsVersion = GL_ES_VERSION; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 964 | } |
| 965 | return config; |
| 966 | } |
| 967 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 968 | private void start() { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 969 | LocalServices.addService(ActivityTaskManagerInternal.class, mInternal); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 972 | public static final class Lifecycle extends SystemService { |
| 973 | private final ActivityTaskManagerService mService; |
| 974 | |
| 975 | public Lifecycle(Context context) { |
| 976 | super(context); |
| 977 | mService = new ActivityTaskManagerService(context); |
| 978 | } |
| 979 | |
| 980 | @Override |
| 981 | public void onStart() { |
| 982 | publishBinderService(Context.ACTIVITY_TASK_SERVICE, mService); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 983 | mService.start(); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 984 | } |
| 985 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 986 | @Override |
| 987 | public void onUnlockUser(int userId) { |
| 988 | synchronized (mService.getGlobalLock()) { |
Garfield Tan | 0d407f4 | 2019-03-07 11:47:01 -0800 | [diff] [blame] | 989 | mService.mStackSupervisor.onUserUnlocked(userId); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
| 993 | @Override |
| 994 | public void onCleanupUser(int userId) { |
| 995 | synchronized (mService.getGlobalLock()) { |
| 996 | mService.mStackSupervisor.mLaunchParamsPersister.onCleanupUser(userId); |
| 997 | } |
| 998 | } |
| 999 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 1000 | public ActivityTaskManagerService getService() { |
| 1001 | return mService; |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1006 | public final int startActivity(IApplicationThread caller, String callingPackage, |
| 1007 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1008 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions) { |
| 1009 | return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo, |
| 1010 | resultWho, requestCode, startFlags, profilerInfo, bOptions, |
| 1011 | UserHandle.getCallingUserId()); |
| 1012 | } |
| 1013 | |
| 1014 | @Override |
| 1015 | public final int startActivities(IApplicationThread caller, String callingPackage, |
| 1016 | Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle bOptions, |
| 1017 | int userId) { |
| 1018 | final String reason = "startActivities"; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1019 | enforceNotIsolatedCaller(reason); |
| 1020 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, reason); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1021 | // TODO: Switch to user app stacks here. |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 1022 | return getActivityStartController().startActivities(caller, -1, 0, -1, callingPackage, |
| 1023 | intents, resolvedTypes, resultTo, SafeActivityOptions.fromBundle(bOptions), userId, |
| 1024 | reason, null /* originatingPendingIntent */, |
| 1025 | false /* allowBackgroundActivityStart */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | @Override |
| 1029 | public int startActivityAsUser(IApplicationThread caller, String callingPackage, |
| 1030 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1031 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId) { |
| 1032 | return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo, |
| 1033 | resultWho, requestCode, startFlags, profilerInfo, bOptions, userId, |
| 1034 | true /*validateIncomingUser*/); |
| 1035 | } |
| 1036 | |
Andrii Kulian | a8ccae4 | 2019-07-24 18:35:22 +0000 | [diff] [blame^] | 1037 | int startActivityAsUser(IApplicationThread caller, String callingPackage, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1038 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1039 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId, |
| 1040 | boolean validateIncomingUser) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1041 | enforceNotIsolatedCaller("startActivityAsUser"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1042 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1043 | userId = getActivityStartController().checkTargetUser(userId, validateIncomingUser, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1044 | Binder.getCallingPid(), Binder.getCallingUid(), "startActivityAsUser"); |
| 1045 | |
| 1046 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1047 | return getActivityStartController().obtainStarter(intent, "startActivityAsUser") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1048 | .setCaller(caller) |
| 1049 | .setCallingPackage(callingPackage) |
| 1050 | .setResolvedType(resolvedType) |
| 1051 | .setResultTo(resultTo) |
| 1052 | .setResultWho(resultWho) |
| 1053 | .setRequestCode(requestCode) |
| 1054 | .setStartFlags(startFlags) |
| 1055 | .setProfilerInfo(profilerInfo) |
| 1056 | .setActivityOptions(bOptions) |
| 1057 | .setMayWait(userId) |
| 1058 | .execute(); |
| 1059 | |
| 1060 | } |
| 1061 | |
| 1062 | @Override |
| 1063 | public int startActivityIntentSender(IApplicationThread caller, IIntentSender target, |
| 1064 | IBinder whitelistToken, Intent fillInIntent, String resolvedType, IBinder resultTo, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1065 | String resultWho, int requestCode, int flagsMask, int flagsValues, Bundle bOptions) { |
| 1066 | enforceNotIsolatedCaller("startActivityIntentSender"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1067 | // Refuse possible leaked file descriptors |
| 1068 | if (fillInIntent != null && fillInIntent.hasFileDescriptors()) { |
| 1069 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1070 | } |
| 1071 | |
| 1072 | if (!(target instanceof PendingIntentRecord)) { |
| 1073 | throw new IllegalArgumentException("Bad PendingIntent object"); |
| 1074 | } |
| 1075 | |
| 1076 | PendingIntentRecord pir = (PendingIntentRecord)target; |
| 1077 | |
| 1078 | synchronized (mGlobalLock) { |
| 1079 | // If this is coming from the currently resumed activity, it is |
| 1080 | // effectively saying that app switches are allowed at this point. |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1081 | final ActivityStack stack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1082 | if (stack.mResumedActivity != null && |
| 1083 | stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1084 | mAppSwitchesAllowedTime = 0; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1085 | } |
| 1086 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1087 | return pir.sendInner(0, fillInIntent, resolvedType, whitelistToken, null, null, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1088 | resultTo, resultWho, requestCode, flagsMask, flagsValues, bOptions); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | @Override |
| 1092 | public boolean startNextMatchingActivity(IBinder callingActivity, Intent intent, |
| 1093 | Bundle bOptions) { |
| 1094 | // Refuse possible leaked file descriptors |
| 1095 | if (intent != null && intent.hasFileDescriptors()) { |
| 1096 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1097 | } |
| 1098 | SafeActivityOptions options = SafeActivityOptions.fromBundle(bOptions); |
| 1099 | |
| 1100 | synchronized (mGlobalLock) { |
| 1101 | final ActivityRecord r = ActivityRecord.isInStackLocked(callingActivity); |
| 1102 | if (r == null) { |
| 1103 | SafeActivityOptions.abort(options); |
| 1104 | return false; |
| 1105 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1106 | if (!r.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1107 | // The caller is not running... d'oh! |
| 1108 | SafeActivityOptions.abort(options); |
| 1109 | return false; |
| 1110 | } |
| 1111 | intent = new Intent(intent); |
| 1112 | // The caller is not allowed to change the data. |
| 1113 | intent.setDataAndType(r.intent.getData(), r.intent.getType()); |
| 1114 | // And we are resetting to find the next component... |
| 1115 | intent.setComponent(null); |
| 1116 | |
| 1117 | final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0); |
| 1118 | |
| 1119 | ActivityInfo aInfo = null; |
| 1120 | try { |
| 1121 | List<ResolveInfo> resolves = |
| 1122 | AppGlobals.getPackageManager().queryIntentActivities( |
| 1123 | intent, r.resolvedType, |
| 1124 | PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS, |
| 1125 | UserHandle.getCallingUserId()).getList(); |
| 1126 | |
| 1127 | // Look for the original activity in the list... |
| 1128 | final int N = resolves != null ? resolves.size() : 0; |
| 1129 | for (int i=0; i<N; i++) { |
| 1130 | ResolveInfo rInfo = resolves.get(i); |
| 1131 | if (rInfo.activityInfo.packageName.equals(r.packageName) |
| 1132 | && rInfo.activityInfo.name.equals(r.info.name)) { |
| 1133 | // We found the current one... the next matching is |
| 1134 | // after it. |
| 1135 | i++; |
| 1136 | if (i<N) { |
| 1137 | aInfo = resolves.get(i).activityInfo; |
| 1138 | } |
| 1139 | if (debug) { |
| 1140 | Slog.v(TAG, "Next matching activity: found current " + r.packageName |
| 1141 | + "/" + r.info.name); |
| 1142 | Slog.v(TAG, "Next matching activity: next is " + ((aInfo == null) |
| 1143 | ? "null" : aInfo.packageName + "/" + aInfo.name)); |
| 1144 | } |
| 1145 | break; |
| 1146 | } |
| 1147 | } |
| 1148 | } catch (RemoteException e) { |
| 1149 | } |
| 1150 | |
| 1151 | if (aInfo == null) { |
| 1152 | // Nobody who is next! |
| 1153 | SafeActivityOptions.abort(options); |
| 1154 | if (debug) Slog.d(TAG, "Next matching activity: nothing found"); |
| 1155 | return false; |
| 1156 | } |
| 1157 | |
| 1158 | intent.setComponent(new ComponentName( |
| 1159 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1160 | intent.setFlags(intent.getFlags()&~( |
| 1161 | Intent.FLAG_ACTIVITY_FORWARD_RESULT| |
| 1162 | Intent.FLAG_ACTIVITY_CLEAR_TOP| |
| 1163 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK| |
| 1164 | FLAG_ACTIVITY_NEW_TASK)); |
| 1165 | |
| 1166 | // Okay now we need to start the new activity, replacing the currently running activity. |
| 1167 | // This is a little tricky because we want to start the new one as if the current one is |
| 1168 | // finished, but not finish the current one first so that there is no flicker. |
| 1169 | // And thus... |
| 1170 | final boolean wasFinishing = r.finishing; |
| 1171 | r.finishing = true; |
| 1172 | |
| 1173 | // Propagate reply information over to the new activity. |
| 1174 | final ActivityRecord resultTo = r.resultTo; |
| 1175 | final String resultWho = r.resultWho; |
| 1176 | final int requestCode = r.requestCode; |
| 1177 | r.resultTo = null; |
| 1178 | if (resultTo != null) { |
| 1179 | resultTo.removeResultsLocked(r, resultWho, requestCode); |
| 1180 | } |
| 1181 | |
| 1182 | final long origId = Binder.clearCallingIdentity(); |
| 1183 | // TODO(b/64750076): Check if calling pid should really be -1. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1184 | final int res = getActivityStartController() |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1185 | .obtainStarter(intent, "startNextMatchingActivity") |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1186 | .setCaller(r.app.getThread()) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1187 | .setResolvedType(r.resolvedType) |
| 1188 | .setActivityInfo(aInfo) |
| 1189 | .setResultTo(resultTo != null ? resultTo.appToken : null) |
| 1190 | .setResultWho(resultWho) |
| 1191 | .setRequestCode(requestCode) |
| 1192 | .setCallingPid(-1) |
| 1193 | .setCallingUid(r.launchedFromUid) |
| 1194 | .setCallingPackage(r.launchedFromPackage) |
| 1195 | .setRealCallingPid(-1) |
| 1196 | .setRealCallingUid(r.launchedFromUid) |
| 1197 | .setActivityOptions(options) |
| 1198 | .execute(); |
| 1199 | Binder.restoreCallingIdentity(origId); |
| 1200 | |
| 1201 | r.finishing = wasFinishing; |
| 1202 | if (res != ActivityManager.START_SUCCESS) { |
| 1203 | return false; |
| 1204 | } |
| 1205 | return true; |
| 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | @Override |
| 1210 | public final WaitResult startActivityAndWait(IApplicationThread caller, String callingPackage, |
| 1211 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1212 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId) { |
| 1213 | final WaitResult res = new WaitResult(); |
| 1214 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1215 | enforceNotIsolatedCaller("startActivityAndWait"); |
| 1216 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 1217 | userId, "startActivityAndWait"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1218 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1219 | getActivityStartController().obtainStarter(intent, "startActivityAndWait") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1220 | .setCaller(caller) |
| 1221 | .setCallingPackage(callingPackage) |
| 1222 | .setResolvedType(resolvedType) |
| 1223 | .setResultTo(resultTo) |
| 1224 | .setResultWho(resultWho) |
| 1225 | .setRequestCode(requestCode) |
| 1226 | .setStartFlags(startFlags) |
| 1227 | .setActivityOptions(bOptions) |
| 1228 | .setMayWait(userId) |
| 1229 | .setProfilerInfo(profilerInfo) |
| 1230 | .setWaitResult(res) |
| 1231 | .execute(); |
| 1232 | } |
| 1233 | return res; |
| 1234 | } |
| 1235 | |
| 1236 | @Override |
| 1237 | public final int startActivityWithConfig(IApplicationThread caller, String callingPackage, |
| 1238 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1239 | int startFlags, Configuration config, Bundle bOptions, int userId) { |
| 1240 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1241 | enforceNotIsolatedCaller("startActivityWithConfig"); |
| 1242 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, |
| 1243 | "startActivityWithConfig"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1244 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1245 | return getActivityStartController().obtainStarter(intent, "startActivityWithConfig") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1246 | .setCaller(caller) |
| 1247 | .setCallingPackage(callingPackage) |
| 1248 | .setResolvedType(resolvedType) |
| 1249 | .setResultTo(resultTo) |
| 1250 | .setResultWho(resultWho) |
| 1251 | .setRequestCode(requestCode) |
| 1252 | .setStartFlags(startFlags) |
| 1253 | .setGlobalConfiguration(config) |
| 1254 | .setActivityOptions(bOptions) |
| 1255 | .setMayWait(userId) |
| 1256 | .execute(); |
| 1257 | } |
| 1258 | } |
| 1259 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1260 | |
| 1261 | @Override |
| 1262 | public IBinder requestStartActivityPermissionToken(IBinder delegatorToken) { |
| 1263 | int callingUid = Binder.getCallingUid(); |
| 1264 | if (UserHandle.getAppId(callingUid) != SYSTEM_UID) { |
| 1265 | throw new SecurityException("Only the system process can request a permission token, " |
| 1266 | + "received request from uid: " + callingUid); |
| 1267 | } |
| 1268 | IBinder permissionToken = new Binder(); |
| 1269 | synchronized (mGlobalLock) { |
| 1270 | mStartActivitySources.put(permissionToken, delegatorToken); |
| 1271 | } |
| 1272 | |
| 1273 | Message expireMsg = PooledLambda.obtainMessage( |
| 1274 | ActivityTaskManagerService::expireStartAsCallerTokenMsg, this, permissionToken); |
| 1275 | mUiHandler.sendMessageDelayed(expireMsg, START_AS_CALLER_TOKEN_TIMEOUT_IMPL); |
| 1276 | |
| 1277 | Message forgetMsg = PooledLambda.obtainMessage( |
| 1278 | ActivityTaskManagerService::forgetStartAsCallerTokenMsg, this, permissionToken); |
| 1279 | mUiHandler.sendMessageDelayed(forgetMsg, START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT); |
| 1280 | |
| 1281 | return permissionToken; |
| 1282 | } |
| 1283 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1284 | @Override |
| 1285 | public final int startActivityAsCaller(IApplicationThread caller, String callingPackage, |
| 1286 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1287 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, IBinder permissionToken, |
| 1288 | boolean ignoreTargetSecurity, int userId) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1289 | // 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] | 1290 | // permission grants) as any app that may launch one of your own activities. So we only |
| 1291 | // allow this in two cases: |
| 1292 | // 1) The caller is an activity that is part of the core framework, and then only when it |
| 1293 | // is running as the system. |
| 1294 | // 2) The caller provides a valid permissionToken. Permission tokens are one-time use and |
| 1295 | // can only be requested by a system activity, which may then delegate this call to |
| 1296 | // another app. |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1297 | final ActivityRecord sourceRecord; |
| 1298 | final int targetUid; |
| 1299 | final String targetPackage; |
| 1300 | final boolean isResolver; |
| 1301 | synchronized (mGlobalLock) { |
| 1302 | if (resultTo == null) { |
| 1303 | throw new SecurityException("Must be called from an activity"); |
| 1304 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1305 | final IBinder sourceToken; |
| 1306 | if (permissionToken != null) { |
| 1307 | // To even attempt to use a permissionToken, an app must also have this signature |
| 1308 | // permission. |
| 1309 | mAmInternal.enforceCallingPermission( |
| 1310 | android.Manifest.permission.START_ACTIVITY_AS_CALLER, |
| 1311 | "startActivityAsCaller"); |
| 1312 | // If called with a permissionToken, we want the sourceRecord from the delegator |
| 1313 | // activity that requested this token. |
| 1314 | sourceToken = mStartActivitySources.remove(permissionToken); |
| 1315 | if (sourceToken == null) { |
| 1316 | // Invalid permissionToken, check if it recently expired. |
| 1317 | if (mExpiredStartAsCallerTokens.contains(permissionToken)) { |
| 1318 | throw new SecurityException("Called with expired permission token: " |
| 1319 | + permissionToken); |
| 1320 | } else { |
| 1321 | throw new SecurityException("Called with invalid permission token: " |
| 1322 | + permissionToken); |
| 1323 | } |
| 1324 | } |
| 1325 | } else { |
| 1326 | // This method was called directly by the source. |
| 1327 | sourceToken = resultTo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1328 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1329 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1330 | sourceRecord = mRootActivityContainer.isInAnyStack(sourceToken); |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1331 | if (sourceRecord == null) { |
| 1332 | throw new SecurityException("Called with bad activity token: " + sourceToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1333 | } |
| 1334 | if (sourceRecord.app == null) { |
| 1335 | throw new SecurityException("Called without a process attached to activity"); |
| 1336 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1337 | |
| 1338 | // Whether called directly or from a delegate, the source activity must be from the |
| 1339 | // android package. |
| 1340 | if (!sourceRecord.info.packageName.equals("android")) { |
| 1341 | throw new SecurityException("Must be called from an activity that is " |
| 1342 | + "declared in the android package"); |
| 1343 | } |
| 1344 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1345 | if (UserHandle.getAppId(sourceRecord.app.mUid) != SYSTEM_UID) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1346 | // This is still okay, as long as this activity is running under the |
| 1347 | // uid of the original calling activity. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1348 | if (sourceRecord.app.mUid != sourceRecord.launchedFromUid) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1349 | throw new SecurityException( |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1350 | "Calling activity in uid " + sourceRecord.app.mUid |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1351 | + " must be system uid or original calling uid " |
| 1352 | + sourceRecord.launchedFromUid); |
| 1353 | } |
| 1354 | } |
| 1355 | if (ignoreTargetSecurity) { |
| 1356 | if (intent.getComponent() == null) { |
| 1357 | throw new SecurityException( |
| 1358 | "Component must be specified with ignoreTargetSecurity"); |
| 1359 | } |
| 1360 | if (intent.getSelector() != null) { |
| 1361 | throw new SecurityException( |
| 1362 | "Selector not allowed with ignoreTargetSecurity"); |
| 1363 | } |
| 1364 | } |
| 1365 | targetUid = sourceRecord.launchedFromUid; |
| 1366 | targetPackage = sourceRecord.launchedFromPackage; |
| 1367 | isResolver = sourceRecord.isResolverOrChildActivity(); |
| 1368 | } |
| 1369 | |
| 1370 | if (userId == UserHandle.USER_NULL) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1371 | userId = UserHandle.getUserId(sourceRecord.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | // TODO: Switch to user app stacks here. |
| 1375 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1376 | return getActivityStartController().obtainStarter(intent, "startActivityAsCaller") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1377 | .setCallingUid(targetUid) |
| 1378 | .setCallingPackage(targetPackage) |
| 1379 | .setResolvedType(resolvedType) |
| 1380 | .setResultTo(resultTo) |
| 1381 | .setResultWho(resultWho) |
| 1382 | .setRequestCode(requestCode) |
| 1383 | .setStartFlags(startFlags) |
| 1384 | .setActivityOptions(bOptions) |
| 1385 | .setMayWait(userId) |
| 1386 | .setIgnoreTargetSecurity(ignoreTargetSecurity) |
| 1387 | .setFilterCallingUid(isResolver ? 0 /* system */ : targetUid) |
Alan Stokes | 2f4a4ed | 2019-05-08 16:56:45 +0100 | [diff] [blame] | 1388 | // The target may well be in the background, which would normally prevent it |
| 1389 | // from starting an activity. Here we definitely want the start to succeed. |
| 1390 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1391 | .execute(); |
| 1392 | } catch (SecurityException e) { |
| 1393 | // XXX need to figure out how to propagate to original app. |
| 1394 | // A SecurityException here is generally actually a fault of the original |
| 1395 | // calling activity (such as a fairly granting permissions), so propagate it |
| 1396 | // back to them. |
| 1397 | /* |
| 1398 | StringBuilder msg = new StringBuilder(); |
| 1399 | msg.append("While launching"); |
| 1400 | msg.append(intent.toString()); |
| 1401 | msg.append(": "); |
| 1402 | msg.append(e.getMessage()); |
| 1403 | */ |
| 1404 | throw e; |
| 1405 | } |
| 1406 | } |
| 1407 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1408 | int handleIncomingUser(int callingPid, int callingUid, int userId, String name) { |
| 1409 | return mAmInternal.handleIncomingUser(callingPid, callingUid, userId, false /* allowAll */, |
| 1410 | ALLOW_FULL_ONLY, name, null /* callerPackage */); |
| 1411 | } |
| 1412 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1413 | @Override |
| 1414 | public int startVoiceActivity(String callingPackage, int callingPid, int callingUid, |
| 1415 | Intent intent, String resolvedType, IVoiceInteractionSession session, |
| 1416 | IVoiceInteractor interactor, int startFlags, ProfilerInfo profilerInfo, |
| 1417 | Bundle bOptions, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1418 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startVoiceActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1419 | if (session == null || interactor == null) { |
| 1420 | throw new NullPointerException("null session or interactor"); |
| 1421 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1422 | userId = handleIncomingUser(callingPid, callingUid, userId, "startVoiceActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1423 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1424 | return getActivityStartController().obtainStarter(intent, "startVoiceActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1425 | .setCallingUid(callingUid) |
| 1426 | .setCallingPackage(callingPackage) |
| 1427 | .setResolvedType(resolvedType) |
| 1428 | .setVoiceSession(session) |
| 1429 | .setVoiceInteractor(interactor) |
| 1430 | .setStartFlags(startFlags) |
| 1431 | .setProfilerInfo(profilerInfo) |
| 1432 | .setActivityOptions(bOptions) |
| 1433 | .setMayWait(userId) |
Michal Karpinski | 85fa202 | 2019-02-08 12:05:09 +0000 | [diff] [blame] | 1434 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1435 | .execute(); |
| 1436 | } |
| 1437 | |
| 1438 | @Override |
| 1439 | public int startAssistantActivity(String callingPackage, int callingPid, int callingUid, |
| 1440 | Intent intent, String resolvedType, Bundle bOptions, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1441 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startAssistantActivity()"); |
| 1442 | userId = handleIncomingUser(callingPid, callingUid, userId, "startAssistantActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1443 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1444 | return getActivityStartController().obtainStarter(intent, "startAssistantActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1445 | .setCallingUid(callingUid) |
| 1446 | .setCallingPackage(callingPackage) |
| 1447 | .setResolvedType(resolvedType) |
| 1448 | .setActivityOptions(bOptions) |
| 1449 | .setMayWait(userId) |
Michal Karpinski | 85fa202 | 2019-02-08 12:05:09 +0000 | [diff] [blame] | 1450 | .setAllowBackgroundActivityStart(true) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1451 | .execute(); |
| 1452 | } |
| 1453 | |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1454 | /** |
| 1455 | * Start the recents activity to perform the recents animation. |
| 1456 | * |
| 1457 | * @param intent The intent to start the recents activity. |
| 1458 | * @param recentsAnimationRunner Pass {@code null} to only preload the activity. |
| 1459 | */ |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1460 | @Override |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1461 | public void startRecentsActivity(Intent intent, @Deprecated IAssistDataReceiver unused, |
| 1462 | @Nullable IRecentsAnimationRunner recentsAnimationRunner) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1463 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "startRecentsActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1464 | final int callingPid = Binder.getCallingPid(); |
| 1465 | final long origId = Binder.clearCallingIdentity(); |
| 1466 | try { |
| 1467 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 1468 | final ComponentName recentsComponent = mRecentTasks.getRecentsComponent(); |
| 1469 | final int recentsUid = mRecentTasks.getRecentsComponentUid(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1470 | |
| 1471 | // Start a new recents animation |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1472 | final RecentsAnimation anim = new RecentsAnimation(this, mStackSupervisor, |
Riddle Hsu | 609a8e2 | 2019-06-27 16:46:29 -0600 | [diff] [blame] | 1473 | getActivityStartController(), mWindowManager, intent, recentsComponent, |
| 1474 | recentsUid, callingPid); |
| 1475 | if (recentsAnimationRunner == null) { |
| 1476 | anim.preloadRecentsActivity(); |
| 1477 | } else { |
| 1478 | anim.startRecentsActivity(recentsAnimationRunner); |
| 1479 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1480 | } |
| 1481 | } finally { |
| 1482 | Binder.restoreCallingIdentity(origId); |
| 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | @Override |
| 1487 | public final int startActivityFromRecents(int taskId, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1488 | enforceCallerIsRecentsOrHasPermission(START_TASKS_FROM_RECENTS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1489 | "startActivityFromRecents()"); |
| 1490 | |
| 1491 | final int callingPid = Binder.getCallingPid(); |
| 1492 | final int callingUid = Binder.getCallingUid(); |
| 1493 | final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(bOptions); |
| 1494 | final long origId = Binder.clearCallingIdentity(); |
| 1495 | try { |
| 1496 | synchronized (mGlobalLock) { |
| 1497 | return mStackSupervisor.startActivityFromRecents(callingPid, callingUid, taskId, |
| 1498 | safeOptions); |
| 1499 | } |
| 1500 | } finally { |
| 1501 | Binder.restoreCallingIdentity(origId); |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | /** |
Andrii Kulian | 2eb84b2 | 2018-12-13 18:18:54 -0800 | [diff] [blame] | 1506 | * Public API to check if the client is allowed to start an activity on specified display. |
| 1507 | * |
| 1508 | * If the target display is private or virtual, some restrictions will apply. |
| 1509 | * |
| 1510 | * @param displayId Target display id. |
| 1511 | * @param intent Intent used to launch the activity. |
| 1512 | * @param resolvedType The MIME type of the intent. |
| 1513 | * @param userId The id of the user for whom the call is made. |
| 1514 | * @return {@code true} if a call to start an activity on the target display should succeed and |
| 1515 | * no {@link SecurityException} will be thrown, {@code false} otherwise. |
| 1516 | */ |
| 1517 | @Override |
| 1518 | public final boolean isActivityStartAllowedOnDisplay(int displayId, Intent intent, |
| 1519 | String resolvedType, int userId) { |
| 1520 | final int callingUid = Binder.getCallingUid(); |
| 1521 | final int callingPid = Binder.getCallingPid(); |
| 1522 | final long origId = Binder.clearCallingIdentity(); |
| 1523 | |
| 1524 | try { |
| 1525 | // Collect information about the target of the Intent. |
| 1526 | ActivityInfo aInfo = mStackSupervisor.resolveActivity(intent, resolvedType, |
| 1527 | 0 /* startFlags */, null /* profilerInfo */, userId, |
| 1528 | ActivityStarter.computeResolveFilterUid(callingUid, callingUid, |
| 1529 | UserHandle.USER_NULL)); |
| 1530 | aInfo = mAmInternal.getActivityInfoForUser(aInfo, userId); |
| 1531 | |
| 1532 | synchronized (mGlobalLock) { |
| 1533 | return mStackSupervisor.canPlaceEntityOnDisplay(displayId, callingPid, callingUid, |
| 1534 | aInfo); |
| 1535 | } |
| 1536 | } finally { |
| 1537 | Binder.restoreCallingIdentity(origId); |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | /** |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1542 | * This is the internal entry point for handling Activity.finish(). |
| 1543 | * |
| 1544 | * @param token The Binder token referencing the Activity we want to finish. |
| 1545 | * @param resultCode Result code, if any, from this Activity. |
| 1546 | * @param resultData Result data (Intent), if any, from this Activity. |
| 1547 | * @param finishTask Whether to finish the task associated with this Activity. |
| 1548 | * |
| 1549 | * @return Returns true if the activity successfully finished, or false if it is still running. |
| 1550 | */ |
| 1551 | @Override |
| 1552 | public final boolean finishActivity(IBinder token, int resultCode, Intent resultData, |
| 1553 | int finishTask) { |
| 1554 | // Refuse possible leaked file descriptors |
| 1555 | if (resultData != null && resultData.hasFileDescriptors()) { |
| 1556 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1557 | } |
| 1558 | |
| 1559 | synchronized (mGlobalLock) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 1560 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1561 | if (r == null) { |
| 1562 | return true; |
| 1563 | } |
| 1564 | // 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] | 1565 | final TaskRecord tr = r.getTaskRecord(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1566 | ActivityRecord rootR = tr.getRootActivity(); |
| 1567 | if (rootR == null) { |
| 1568 | Slog.w(TAG, "Finishing task with all activities already finished"); |
| 1569 | } |
| 1570 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps can |
| 1571 | // finish. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1572 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1573 | return false; |
| 1574 | } |
| 1575 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1576 | // TODO: There is a dup. of this block of code in ActivityStack.navigateUpToLocked |
| 1577 | // We should consolidate. |
| 1578 | if (mController != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1579 | // Find the first activity that is not finishing. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1580 | final ActivityRecord next = r.getActivityStack().topRunningActivityLocked(token, 0); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1581 | if (next != null) { |
| 1582 | // ask watcher if this is allowed |
| 1583 | boolean resumeOK = true; |
| 1584 | try { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1585 | resumeOK = mController.activityResuming(next.packageName); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1586 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1587 | mController = null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1588 | Watchdog.getInstance().setActivityController(null); |
| 1589 | } |
| 1590 | |
| 1591 | if (!resumeOK) { |
| 1592 | Slog.i(TAG, "Not finishing activity because controller resumed"); |
| 1593 | return false; |
| 1594 | } |
| 1595 | } |
| 1596 | } |
Michal Karpinski | fc6872e | 2019-05-21 15:18:44 +0100 | [diff] [blame] | 1597 | |
| 1598 | // note down that the process has finished an activity and is in background activity |
| 1599 | // starts grace period |
| 1600 | if (r.app != null) { |
| 1601 | r.app.setLastActivityFinishTimeIfNeeded(SystemClock.uptimeMillis()); |
| 1602 | } |
| 1603 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1604 | final long origId = Binder.clearCallingIdentity(); |
| 1605 | try { |
| 1606 | boolean res; |
| 1607 | final boolean finishWithRootActivity = |
| 1608 | finishTask == Activity.FINISH_TASK_WITH_ROOT_ACTIVITY; |
| 1609 | if (finishTask == Activity.FINISH_TASK_WITH_ACTIVITY |
| 1610 | || (finishWithRootActivity && r == rootR)) { |
| 1611 | // If requested, remove the task that is associated to this activity only if it |
| 1612 | // was the root activity in the task. The result code and data is ignored |
| 1613 | // because we don't support returning them across task boundaries. Also, to |
| 1614 | // keep backwards compatibility we remove the task from recents when finishing |
| 1615 | // task with root activity. |
| 1616 | res = mStackSupervisor.removeTaskByIdLocked(tr.taskId, false, |
| 1617 | finishWithRootActivity, "finish-activity"); |
| 1618 | if (!res) { |
| 1619 | Slog.i(TAG, "Removing task failed to finish activity"); |
| 1620 | } |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 1621 | // Explicitly dismissing the activity so reset its relaunch flag. |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 1622 | r.mRelaunchReason = RELAUNCH_REASON_NONE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1623 | } else { |
| 1624 | res = tr.getStack().requestFinishActivityLocked(token, resultCode, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 1625 | resultData, "app-request", true); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1626 | if (!res) { |
| 1627 | Slog.i(TAG, "Failed to finish by app-request"); |
| 1628 | } |
| 1629 | } |
| 1630 | return res; |
| 1631 | } finally { |
| 1632 | Binder.restoreCallingIdentity(origId); |
| 1633 | } |
| 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | @Override |
| 1638 | public boolean finishActivityAffinity(IBinder token) { |
| 1639 | synchronized (mGlobalLock) { |
| 1640 | final long origId = Binder.clearCallingIdentity(); |
| 1641 | try { |
| 1642 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1643 | if (r == null) { |
| 1644 | return false; |
| 1645 | } |
| 1646 | |
| 1647 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps |
| 1648 | // can finish. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1649 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1650 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1651 | return false; |
| 1652 | } |
| 1653 | return task.getStack().finishActivityAffinityLocked(r); |
| 1654 | } finally { |
| 1655 | Binder.restoreCallingIdentity(origId); |
| 1656 | } |
| 1657 | } |
| 1658 | } |
| 1659 | |
| 1660 | @Override |
| 1661 | public final void activityIdle(IBinder token, Configuration config, boolean stopProfiling) { |
| 1662 | final long origId = Binder.clearCallingIdentity(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1663 | try { |
| 1664 | WindowProcessController proc = null; |
| 1665 | synchronized (mGlobalLock) { |
| 1666 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 1667 | if (stack == null) { |
| 1668 | return; |
| 1669 | } |
| 1670 | final ActivityRecord r = mStackSupervisor.activityIdleInternalLocked(token, |
| 1671 | false /* fromTimeout */, false /* processPausingActivities */, config); |
| 1672 | if (r != null) { |
| 1673 | proc = r.app; |
| 1674 | } |
| 1675 | if (stopProfiling && proc != null) { |
| 1676 | proc.clearProfilerIfNeeded(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1677 | } |
| 1678 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1679 | } finally { |
| 1680 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1681 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | @Override |
| 1685 | public final void activityResumed(IBinder token) { |
| 1686 | final long origId = Binder.clearCallingIdentity(); |
| 1687 | synchronized (mGlobalLock) { |
| 1688 | ActivityRecord.activityResumedLocked(token); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1689 | mWindowManager.notifyAppResumedFinished(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1690 | } |
| 1691 | Binder.restoreCallingIdentity(origId); |
| 1692 | } |
| 1693 | |
| 1694 | @Override |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 1695 | public final void activityTopResumedStateLost() { |
| 1696 | final long origId = Binder.clearCallingIdentity(); |
| 1697 | synchronized (mGlobalLock) { |
| 1698 | mStackSupervisor.handleTopResumedStateReleased(false /* timeout */); |
| 1699 | } |
| 1700 | Binder.restoreCallingIdentity(origId); |
| 1701 | } |
| 1702 | |
| 1703 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1704 | public final void activityPaused(IBinder token) { |
| 1705 | final long origId = Binder.clearCallingIdentity(); |
| 1706 | synchronized (mGlobalLock) { |
| 1707 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 1708 | if (stack != null) { |
| 1709 | stack.activityPausedLocked(token, false); |
| 1710 | } |
| 1711 | } |
| 1712 | Binder.restoreCallingIdentity(origId); |
| 1713 | } |
| 1714 | |
| 1715 | @Override |
| 1716 | public final void activityStopped(IBinder token, Bundle icicle, |
| 1717 | PersistableBundle persistentState, CharSequence description) { |
| 1718 | if (DEBUG_ALL) Slog.v(TAG, "Activity stopped: token=" + token); |
| 1719 | |
| 1720 | // Refuse possible leaked file descriptors |
| 1721 | if (icicle != null && icicle.hasFileDescriptors()) { |
| 1722 | throw new IllegalArgumentException("File descriptors passed in Bundle"); |
| 1723 | } |
| 1724 | |
| 1725 | final long origId = Binder.clearCallingIdentity(); |
| 1726 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1727 | String restartingName = null; |
| 1728 | int restartingUid = 0; |
| 1729 | final ActivityRecord r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1730 | synchronized (mGlobalLock) { |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1731 | r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1732 | if (r != null) { |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1733 | if (r.attachedToProcess() |
| 1734 | && r.isState(ActivityStack.ActivityState.RESTARTING_PROCESS)) { |
| 1735 | // The activity was requested to restart from |
| 1736 | // {@link #restartActivityProcessIfVisible}. |
| 1737 | restartingName = r.app.mName; |
| 1738 | restartingUid = r.app.mUid; |
| 1739 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1740 | r.activityStoppedLocked(icicle, persistentState, description); |
| 1741 | } |
| 1742 | } |
| 1743 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 1744 | if (restartingName != null) { |
| 1745 | // In order to let the foreground activity can be restarted with its saved state from |
| 1746 | // {@link android.app.Activity#onSaveInstanceState}, the kill operation is postponed |
| 1747 | // until the activity reports stopped with the state. And the activity record will be |
| 1748 | // kept because the record state is restarting, then the activity will be restarted |
| 1749 | // immediately if it is still the top one. |
| 1750 | mStackSupervisor.removeRestartTimeouts(r); |
| 1751 | mAmInternal.killProcess(restartingName, restartingUid, "restartActivityProcess"); |
| 1752 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1753 | mAmInternal.trimApplications(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1754 | |
| 1755 | Binder.restoreCallingIdentity(origId); |
| 1756 | } |
| 1757 | |
| 1758 | @Override |
| 1759 | public final void activityDestroyed(IBinder token) { |
| 1760 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "ACTIVITY DESTROYED: " + token); |
| 1761 | synchronized (mGlobalLock) { |
| 1762 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 1763 | if (stack != null) { |
| 1764 | stack.activityDestroyedLocked(token, "activityDestroyed"); |
| 1765 | } |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | @Override |
| 1770 | public final void activityRelaunched(IBinder token) { |
| 1771 | final long origId = Binder.clearCallingIdentity(); |
| 1772 | synchronized (mGlobalLock) { |
| 1773 | mStackSupervisor.activityRelaunchedLocked(token); |
| 1774 | } |
| 1775 | Binder.restoreCallingIdentity(origId); |
| 1776 | } |
| 1777 | |
| 1778 | public final void activitySlept(IBinder token) { |
| 1779 | if (DEBUG_ALL) Slog.v(TAG, "Activity slept: token=" + token); |
| 1780 | |
| 1781 | final long origId = Binder.clearCallingIdentity(); |
| 1782 | |
| 1783 | synchronized (mGlobalLock) { |
| 1784 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1785 | if (r != null) { |
| 1786 | mStackSupervisor.activitySleptLocked(r); |
| 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | Binder.restoreCallingIdentity(origId); |
| 1791 | } |
| 1792 | |
| 1793 | @Override |
| 1794 | public void setRequestedOrientation(IBinder token, int requestedOrientation) { |
| 1795 | synchronized (mGlobalLock) { |
| 1796 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1797 | if (r == null) { |
| 1798 | return; |
| 1799 | } |
| 1800 | final long origId = Binder.clearCallingIdentity(); |
| 1801 | try { |
| 1802 | r.setRequestedOrientation(requestedOrientation); |
| 1803 | } finally { |
| 1804 | Binder.restoreCallingIdentity(origId); |
| 1805 | } |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | @Override |
| 1810 | public int getRequestedOrientation(IBinder token) { |
| 1811 | synchronized (mGlobalLock) { |
| 1812 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1813 | if (r == null) { |
| 1814 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 1815 | } |
Riddle Hsu | 0a343c3 | 2018-12-21 00:40:48 +0800 | [diff] [blame] | 1816 | return r.getOrientation(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | @Override |
| 1821 | public void setImmersive(IBinder token, boolean immersive) { |
| 1822 | synchronized (mGlobalLock) { |
| 1823 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1824 | if (r == null) { |
| 1825 | throw new IllegalArgumentException(); |
| 1826 | } |
| 1827 | r.immersive = immersive; |
| 1828 | |
| 1829 | // update associated state if we're frontmost |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1830 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1831 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, "Frontmost changed immersion: "+ r); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1832 | applyUpdateLockStateLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1833 | } |
| 1834 | } |
| 1835 | } |
| 1836 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1837 | void applyUpdateLockStateLocked(ActivityRecord r) { |
| 1838 | // Modifications to the UpdateLock state are done on our handler, outside |
| 1839 | // the activity manager's locks. The new state is determined based on the |
| 1840 | // state *now* of the relevant activity record. The object is passed to |
| 1841 | // the handler solely for logging detail, not to be consulted/modified. |
| 1842 | final boolean nextState = r != null && r.immersive; |
| 1843 | mH.post(() -> { |
| 1844 | if (mUpdateLock.isHeld() != nextState) { |
| 1845 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, |
| 1846 | "Applying new update lock state '" + nextState + "' for " + r); |
| 1847 | if (nextState) { |
| 1848 | mUpdateLock.acquire(); |
| 1849 | } else { |
| 1850 | mUpdateLock.release(); |
| 1851 | } |
| 1852 | } |
| 1853 | }); |
| 1854 | } |
| 1855 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1856 | @Override |
| 1857 | public boolean isImmersive(IBinder token) { |
| 1858 | synchronized (mGlobalLock) { |
| 1859 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1860 | if (r == null) { |
| 1861 | throw new IllegalArgumentException(); |
| 1862 | } |
| 1863 | return r.immersive; |
| 1864 | } |
| 1865 | } |
| 1866 | |
| 1867 | @Override |
| 1868 | public boolean isTopActivityImmersive() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1869 | enforceNotIsolatedCaller("isTopActivityImmersive"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1870 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1871 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivityLocked(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1872 | return (r != null) ? r.immersive : false; |
| 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | @Override |
| 1877 | public void overridePendingTransition(IBinder token, String packageName, |
| 1878 | int enterAnim, int exitAnim) { |
| 1879 | synchronized (mGlobalLock) { |
| 1880 | ActivityRecord self = ActivityRecord.isInStackLocked(token); |
| 1881 | if (self == null) { |
| 1882 | return; |
| 1883 | } |
| 1884 | |
| 1885 | final long origId = Binder.clearCallingIdentity(); |
| 1886 | |
| 1887 | if (self.isState( |
| 1888 | ActivityStack.ActivityState.RESUMED, ActivityStack.ActivityState.PAUSING)) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 1889 | self.getDisplay().mDisplayContent.mAppTransition.overridePendingAppTransition( |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1890 | packageName, enterAnim, exitAnim, null); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | Binder.restoreCallingIdentity(origId); |
| 1894 | } |
| 1895 | } |
| 1896 | |
| 1897 | @Override |
| 1898 | public int getFrontActivityScreenCompatMode() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1899 | enforceNotIsolatedCaller("getFrontActivityScreenCompatMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1900 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1901 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivityLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1902 | if (r == null) { |
| 1903 | return ActivityManager.COMPAT_MODE_UNKNOWN; |
| 1904 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1905 | return mCompatModePackages.computeCompatModeLocked(r.info.applicationInfo); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | @Override |
| 1910 | public void setFrontActivityScreenCompatMode(int mode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1911 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1912 | "setFrontActivityScreenCompatMode"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1913 | ApplicationInfo ai; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1914 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1915 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivityLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1916 | if (r == null) { |
| 1917 | Slog.w(TAG, "setFrontActivityScreenCompatMode failed: no top activity"); |
| 1918 | return; |
| 1919 | } |
| 1920 | ai = r.info.applicationInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1921 | mCompatModePackages.setPackageScreenCompatModeLocked(ai, mode); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1922 | } |
| 1923 | } |
| 1924 | |
| 1925 | @Override |
| 1926 | public int getLaunchedFromUid(IBinder activityToken) { |
| 1927 | ActivityRecord srec; |
| 1928 | synchronized (mGlobalLock) { |
| 1929 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 1930 | } |
| 1931 | if (srec == null) { |
| 1932 | return -1; |
| 1933 | } |
| 1934 | return srec.launchedFromUid; |
| 1935 | } |
| 1936 | |
| 1937 | @Override |
| 1938 | public String getLaunchedFromPackage(IBinder activityToken) { |
| 1939 | ActivityRecord srec; |
| 1940 | synchronized (mGlobalLock) { |
| 1941 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 1942 | } |
| 1943 | if (srec == null) { |
| 1944 | return null; |
| 1945 | } |
| 1946 | return srec.launchedFromPackage; |
| 1947 | } |
| 1948 | |
| 1949 | @Override |
| 1950 | public boolean convertFromTranslucent(IBinder token) { |
| 1951 | final long origId = Binder.clearCallingIdentity(); |
| 1952 | try { |
| 1953 | synchronized (mGlobalLock) { |
| 1954 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1955 | if (r == null) { |
| 1956 | return false; |
| 1957 | } |
| 1958 | final boolean translucentChanged = r.changeWindowTranslucency(true); |
| 1959 | if (translucentChanged) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1960 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1961 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1962 | mWindowManager.setAppFullscreen(token, true); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1963 | return translucentChanged; |
| 1964 | } |
| 1965 | } finally { |
| 1966 | Binder.restoreCallingIdentity(origId); |
| 1967 | } |
| 1968 | } |
| 1969 | |
| 1970 | @Override |
| 1971 | public boolean convertToTranslucent(IBinder token, Bundle options) { |
| 1972 | SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(options); |
| 1973 | final long origId = Binder.clearCallingIdentity(); |
| 1974 | try { |
| 1975 | synchronized (mGlobalLock) { |
| 1976 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1977 | if (r == null) { |
| 1978 | return false; |
| 1979 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1980 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1981 | int index = task.mActivities.lastIndexOf(r); |
| 1982 | if (index > 0) { |
| 1983 | ActivityRecord under = task.mActivities.get(index - 1); |
| 1984 | under.returningOptions = safeOptions != null ? safeOptions.getOptions(r) : null; |
| 1985 | } |
| 1986 | final boolean translucentChanged = r.changeWindowTranslucency(false); |
| 1987 | if (translucentChanged) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1988 | r.getActivityStack().convertActivityToTranslucent(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1989 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1990 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1991 | mWindowManager.setAppFullscreen(token, false); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1992 | return translucentChanged; |
| 1993 | } |
| 1994 | } finally { |
| 1995 | Binder.restoreCallingIdentity(origId); |
| 1996 | } |
| 1997 | } |
| 1998 | |
| 1999 | @Override |
| 2000 | public void notifyActivityDrawn(IBinder token) { |
| 2001 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, "notifyActivityDrawn: token=" + token); |
| 2002 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2003 | ActivityRecord r = mRootActivityContainer.isInAnyStack(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2004 | if (r != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2005 | r.getActivityStack().notifyActivityDrawnLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2006 | } |
| 2007 | } |
| 2008 | } |
| 2009 | |
| 2010 | @Override |
| 2011 | public void reportActivityFullyDrawn(IBinder token, boolean restoredFromBundle) { |
| 2012 | synchronized (mGlobalLock) { |
| 2013 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2014 | if (r == null) { |
| 2015 | return; |
| 2016 | } |
| 2017 | r.reportFullyDrawnLocked(restoredFromBundle); |
| 2018 | } |
| 2019 | } |
| 2020 | |
| 2021 | @Override |
| 2022 | public int getActivityDisplayId(IBinder activityToken) throws RemoteException { |
| 2023 | synchronized (mGlobalLock) { |
| 2024 | final ActivityStack stack = ActivityRecord.getStackLocked(activityToken); |
| 2025 | if (stack != null && stack.mDisplayId != INVALID_DISPLAY) { |
| 2026 | return stack.mDisplayId; |
| 2027 | } |
| 2028 | return DEFAULT_DISPLAY; |
| 2029 | } |
| 2030 | } |
| 2031 | |
| 2032 | @Override |
| 2033 | public ActivityManager.StackInfo getFocusedStackInfo() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2034 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2035 | long ident = Binder.clearCallingIdentity(); |
| 2036 | try { |
| 2037 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2038 | ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2039 | if (focusedStack != null) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2040 | return mRootActivityContainer.getStackInfo(focusedStack.mStackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2041 | } |
| 2042 | return null; |
| 2043 | } |
| 2044 | } finally { |
| 2045 | Binder.restoreCallingIdentity(ident); |
| 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | @Override |
| 2050 | public void setFocusedStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2051 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2052 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedStack: stackId=" + stackId); |
| 2053 | final long callingId = Binder.clearCallingIdentity(); |
| 2054 | try { |
| 2055 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2056 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2057 | if (stack == null) { |
| 2058 | Slog.w(TAG, "setFocusedStack: No stack with id=" + stackId); |
| 2059 | return; |
| 2060 | } |
| 2061 | final ActivityRecord r = stack.topRunningActivityLocked(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2062 | if (r != null && r.moveFocusableActivityToTop("setFocusedStack")) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2063 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2064 | } |
| 2065 | } |
| 2066 | } finally { |
| 2067 | Binder.restoreCallingIdentity(callingId); |
| 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | @Override |
| 2072 | public void setFocusedTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2073 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2074 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedTask: taskId=" + taskId); |
| 2075 | final long callingId = Binder.clearCallingIdentity(); |
| 2076 | try { |
| 2077 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2078 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2079 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2080 | if (task == null) { |
| 2081 | return; |
| 2082 | } |
| 2083 | final ActivityRecord r = task.topRunningActivityLocked(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 2084 | if (r != null && r.moveFocusableActivityToTop("setFocusedTask")) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2085 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2086 | } |
| 2087 | } |
| 2088 | } finally { |
| 2089 | Binder.restoreCallingIdentity(callingId); |
| 2090 | } |
| 2091 | } |
| 2092 | |
| 2093 | @Override |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2094 | public void restartActivityProcessIfVisible(IBinder activityToken) { |
| 2095 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "restartActivityProcess()"); |
| 2096 | final long callingId = Binder.clearCallingIdentity(); |
| 2097 | try { |
| 2098 | synchronized (mGlobalLock) { |
| 2099 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 2100 | if (r == null) { |
| 2101 | return; |
| 2102 | } |
| 2103 | r.restartProcessIfVisible(); |
| 2104 | } |
| 2105 | } finally { |
| 2106 | Binder.restoreCallingIdentity(callingId); |
| 2107 | } |
| 2108 | } |
| 2109 | |
| 2110 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2111 | public boolean removeTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2112 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2113 | synchronized (mGlobalLock) { |
| 2114 | final long ident = Binder.clearCallingIdentity(); |
| 2115 | try { |
| 2116 | return mStackSupervisor.removeTaskByIdLocked(taskId, true, REMOVE_FROM_RECENTS, |
| 2117 | "remove-task"); |
| 2118 | } finally { |
| 2119 | Binder.restoreCallingIdentity(ident); |
| 2120 | } |
| 2121 | } |
| 2122 | } |
| 2123 | |
| 2124 | @Override |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 2125 | public void removeAllVisibleRecentTasks() { |
| 2126 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeAllVisibleRecentTasks()"); |
| 2127 | synchronized (mGlobalLock) { |
| 2128 | final long ident = Binder.clearCallingIdentity(); |
| 2129 | try { |
Winson Chung | 42fa21f | 2019-04-02 16:23:46 -0700 | [diff] [blame] | 2130 | getRecentTasks().removeAllVisibleTasks(mAmInternal.getCurrentUserId()); |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 2131 | } finally { |
| 2132 | Binder.restoreCallingIdentity(ident); |
| 2133 | } |
| 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2138 | public boolean shouldUpRecreateTask(IBinder token, String destAffinity) { |
| 2139 | synchronized (mGlobalLock) { |
| 2140 | final ActivityRecord srec = ActivityRecord.forTokenLocked(token); |
| 2141 | if (srec != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2142 | return srec.getActivityStack().shouldUpRecreateTaskLocked(srec, destAffinity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2143 | } |
| 2144 | } |
| 2145 | return false; |
| 2146 | } |
| 2147 | |
| 2148 | @Override |
| 2149 | public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode, |
| 2150 | Intent resultData) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2151 | |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 2152 | synchronized (mGlobalLock) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2153 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2154 | if (r != null) { |
| 2155 | return r.getActivityStack().navigateUpToLocked( |
| 2156 | r, destIntent, resultCode, resultData); |
Jeff Sharkey | 344ce7c | 2019-05-29 14:52:59 -0600 | [diff] [blame] | 2157 | } |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2158 | return false; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2159 | } |
| 2160 | } |
| 2161 | |
| 2162 | /** |
| 2163 | * Attempts to move a task backwards in z-order (the order of activities within the task is |
| 2164 | * unchanged). |
| 2165 | * |
| 2166 | * There are several possible results of this call: |
| 2167 | * - if the task is locked, then we will show the lock toast |
| 2168 | * - if there is a task behind the provided task, then that task is made visible and resumed as |
| 2169 | * this task is moved to the back |
| 2170 | * - otherwise, if there are no other tasks in the stack: |
| 2171 | * - if this task is in the pinned stack, then we remove the stack completely, which will |
| 2172 | * have the effect of moving the task to the top or bottom of the fullscreen stack |
| 2173 | * (depending on whether it is visible) |
| 2174 | * - otherwise, we simply return home and hide this task |
| 2175 | * |
| 2176 | * @param token A reference to the activity we wish to move |
| 2177 | * @param nonRoot If false then this only works if the activity is the root |
| 2178 | * of a task; if true it will work for any activity in a task. |
| 2179 | * @return Returns true if the move completed, false if not. |
| 2180 | */ |
| 2181 | @Override |
| 2182 | public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2183 | enforceNotIsolatedCaller("moveActivityTaskToBack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2184 | synchronized (mGlobalLock) { |
| 2185 | final long origId = Binder.clearCallingIdentity(); |
| 2186 | try { |
| 2187 | int taskId = ActivityRecord.getTaskForActivityLocked(token, !nonRoot); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2188 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2189 | if (task != null) { |
| 2190 | return ActivityRecord.getStackLocked(token).moveTaskToBackLocked(taskId); |
| 2191 | } |
| 2192 | } finally { |
| 2193 | Binder.restoreCallingIdentity(origId); |
| 2194 | } |
| 2195 | } |
| 2196 | return false; |
| 2197 | } |
| 2198 | |
| 2199 | @Override |
| 2200 | public Rect getTaskBounds(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2201 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getTaskBounds()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2202 | long ident = Binder.clearCallingIdentity(); |
| 2203 | Rect rect = new Rect(); |
| 2204 | try { |
| 2205 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2206 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2207 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2208 | if (task == null) { |
| 2209 | Slog.w(TAG, "getTaskBounds: taskId=" + taskId + " not found"); |
| 2210 | return rect; |
| 2211 | } |
| 2212 | if (task.getStack() != null) { |
| 2213 | // Return the bounds from window manager since it will be adjusted for various |
| 2214 | // things like the presense of a docked stack for tasks that aren't resizeable. |
| 2215 | task.getWindowContainerBounds(rect); |
| 2216 | } else { |
| 2217 | // Task isn't in window manager yet since it isn't associated with a stack. |
| 2218 | // Return the persist value from activity manager |
| 2219 | if (!task.matchParentBounds()) { |
| 2220 | rect.set(task.getBounds()); |
| 2221 | } else if (task.mLastNonFullscreenBounds != null) { |
| 2222 | rect.set(task.mLastNonFullscreenBounds); |
| 2223 | } |
| 2224 | } |
| 2225 | } |
| 2226 | } finally { |
| 2227 | Binder.restoreCallingIdentity(ident); |
| 2228 | } |
| 2229 | return rect; |
| 2230 | } |
| 2231 | |
| 2232 | @Override |
| 2233 | public ActivityManager.TaskDescription getTaskDescription(int id) { |
| 2234 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2235 | enforceCallerIsRecentsOrHasPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2236 | MANAGE_ACTIVITY_STACKS, "getTaskDescription()"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2237 | final TaskRecord tr = mRootActivityContainer.anyTaskForId(id, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2238 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2239 | if (tr != null) { |
| 2240 | return tr.lastTaskDescription; |
| 2241 | } |
| 2242 | } |
| 2243 | return null; |
| 2244 | } |
| 2245 | |
| 2246 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2247 | public void setTaskWindowingMode(int taskId, int windowingMode, boolean toTop) { |
| 2248 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 2249 | setTaskWindowingModeSplitScreenPrimary(taskId, SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, |
| 2250 | toTop, ANIMATE, null /* initialBounds */, true /* showRecents */); |
| 2251 | return; |
| 2252 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2253 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setTaskWindowingMode()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2254 | synchronized (mGlobalLock) { |
| 2255 | final long ident = Binder.clearCallingIdentity(); |
| 2256 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2257 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2258 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2259 | if (task == null) { |
| 2260 | Slog.w(TAG, "setTaskWindowingMode: No task for id=" + taskId); |
| 2261 | return; |
| 2262 | } |
| 2263 | |
| 2264 | if (DEBUG_STACK) Slog.d(TAG_STACK, "setTaskWindowingMode: moving task=" + taskId |
| 2265 | + " to windowingMode=" + windowingMode + " toTop=" + toTop); |
| 2266 | |
| 2267 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2268 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2269 | + " non-standard task " + taskId + " to windowing mode=" |
| 2270 | + windowingMode); |
| 2271 | } |
| 2272 | |
| 2273 | final ActivityStack stack = task.getStack(); |
| 2274 | if (toTop) { |
| 2275 | stack.moveToFront("setTaskWindowingMode", task); |
| 2276 | } |
| 2277 | stack.setWindowingMode(windowingMode); |
| 2278 | } finally { |
| 2279 | Binder.restoreCallingIdentity(ident); |
| 2280 | } |
| 2281 | } |
| 2282 | } |
| 2283 | |
| 2284 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2285 | public String getCallingPackage(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2286 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2287 | ActivityRecord r = getCallingRecordLocked(token); |
| 2288 | return r != null ? r.info.packageName : null; |
| 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | @Override |
| 2293 | public ComponentName getCallingActivity(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2294 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2295 | ActivityRecord r = getCallingRecordLocked(token); |
| 2296 | return r != null ? r.intent.getComponent() : null; |
| 2297 | } |
| 2298 | } |
| 2299 | |
| 2300 | private ActivityRecord getCallingRecordLocked(IBinder token) { |
| 2301 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2302 | if (r == null) { |
| 2303 | return null; |
| 2304 | } |
| 2305 | return r.resultTo; |
| 2306 | } |
| 2307 | |
| 2308 | @Override |
| 2309 | public void unhandledBack() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2310 | mAmInternal.enforceCallingPermission(android.Manifest.permission.FORCE_BACK, "unhandledBack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2311 | |
| 2312 | synchronized (mGlobalLock) { |
| 2313 | final long origId = Binder.clearCallingIdentity(); |
| 2314 | try { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2315 | getTopDisplayFocusedStack().unhandledBackLocked(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2316 | } finally { |
| 2317 | Binder.restoreCallingIdentity(origId); |
| 2318 | } |
| 2319 | } |
| 2320 | } |
| 2321 | |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 2322 | @Override |
| 2323 | public void onBackPressedOnTaskRoot(IBinder token, IRequestFinishCallback callback) { |
| 2324 | synchronized (mGlobalLock) { |
| 2325 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2326 | if (r == null) { |
| 2327 | return; |
| 2328 | } |
| 2329 | ActivityStack stack = r.getActivityStack(); |
| 2330 | if (stack != null && stack.isSingleTaskInstance()) { |
| 2331 | // Single-task stacks are used for activities which are presented in floating |
| 2332 | // windows above full screen activities. Instead of directly finishing the |
| 2333 | // task, a task change listener is used to notify SystemUI so the action can be |
| 2334 | // handled specially. |
| 2335 | final TaskRecord task = r.getTaskRecord(); |
| 2336 | mTaskChangeNotificationController |
| 2337 | .notifyBackPressedOnTaskRoot(task.getTaskInfo()); |
| 2338 | } else { |
| 2339 | try { |
| 2340 | callback.requestFinish(); |
| 2341 | } catch (RemoteException e) { |
| 2342 | Slog.e(TAG, "Failed to invoke request finish callback", e); |
| 2343 | } |
| 2344 | } |
| 2345 | } |
| 2346 | } |
| 2347 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2348 | /** |
| 2349 | * TODO: Add mController hook |
| 2350 | */ |
| 2351 | @Override |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2352 | public void moveTaskToFront(IApplicationThread appThread, String callingPackage, int taskId, |
| 2353 | int flags, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2354 | mAmInternal.enforceCallingPermission(android.Manifest.permission.REORDER_TASKS, "moveTaskToFront()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2355 | |
| 2356 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToFront: moving taskId=" + taskId); |
| 2357 | synchronized (mGlobalLock) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2358 | moveTaskToFrontLocked(appThread, callingPackage, taskId, flags, |
| 2359 | SafeActivityOptions.fromBundle(bOptions), false /* fromRecents */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2360 | } |
| 2361 | } |
| 2362 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2363 | void moveTaskToFrontLocked(@Nullable IApplicationThread appThread, |
| 2364 | @Nullable String callingPackage, int taskId, int flags, SafeActivityOptions options, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2365 | boolean fromRecents) { |
Andrii Kulian | a8ccae4 | 2019-07-24 18:35:22 +0000 | [diff] [blame^] | 2366 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2367 | final int callingPid = Binder.getCallingPid(); |
| 2368 | final int callingUid = Binder.getCallingUid(); |
Andrii Kulian | a8ccae4 | 2019-07-24 18:35:22 +0000 | [diff] [blame^] | 2369 | if (!isSameApp(callingUid, callingPackage)) { |
| 2370 | String msg = "Permission Denial: moveTaskToFrontLocked() from pid=" |
| 2371 | + Binder.getCallingPid() + " as package " + callingPackage; |
| 2372 | Slog.w(TAG, msg); |
| 2373 | throw new SecurityException(msg); |
| 2374 | } |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2375 | if (!checkAppSwitchAllowedLocked(callingPid, callingUid, -1, -1, "Task to front")) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2376 | SafeActivityOptions.abort(options); |
| 2377 | return; |
| 2378 | } |
| 2379 | final long origId = Binder.clearCallingIdentity(); |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2380 | WindowProcessController callerApp = null; |
| 2381 | if (appThread != null) { |
| 2382 | callerApp = getProcessController(appThread); |
| 2383 | } |
| 2384 | final ActivityStarter starter = getActivityStartController().obtainStarter( |
| 2385 | null /* intent */, "moveTaskToFront"); |
| 2386 | if (starter.shouldAbortBackgroundActivityStart(callingUid, callingPid, callingPackage, -1, |
| 2387 | -1, callerApp, null, false, null)) { |
Alan Stokes | 9e24576 | 2019-05-21 14:54:28 +0100 | [diff] [blame] | 2388 | if (!isBackgroundActivityStartsEnabled()) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2389 | return; |
| 2390 | } |
| 2391 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2392 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2393 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2394 | if (task == null) { |
| 2395 | Slog.d(TAG, "Could not find task for id: "+ taskId); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2396 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2397 | return; |
| 2398 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2399 | if (getLockTaskController().isLockTaskModeViolation(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2400 | Slog.e(TAG, "moveTaskToFront: Attempt to violate Lock Task Mode"); |
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 | } |
| 2404 | ActivityOptions realOptions = options != null |
| 2405 | ? options.getOptions(mStackSupervisor) |
| 2406 | : null; |
| 2407 | mStackSupervisor.findTaskToMoveToFront(task, flags, realOptions, "moveTaskToFront", |
| 2408 | false /* forceNonResizable */); |
| 2409 | |
| 2410 | final ActivityRecord topActivity = task.getTopActivity(); |
| 2411 | if (topActivity != null) { |
| 2412 | |
| 2413 | // We are reshowing a task, use a starting window to hide the initial draw delay |
| 2414 | // so the transition can start earlier. |
| 2415 | topActivity.showStartingWindow(null /* prev */, false /* newTask */, |
| 2416 | true /* taskSwitch */, fromRecents); |
| 2417 | } |
| 2418 | } finally { |
| 2419 | Binder.restoreCallingIdentity(origId); |
| 2420 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2421 | } |
| 2422 | |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2423 | /** |
| 2424 | * Return true if callingUid is system, or packageName belongs to that callingUid. |
| 2425 | */ |
Andrii Kulian | a8ccae4 | 2019-07-24 18:35:22 +0000 | [diff] [blame^] | 2426 | boolean isSameApp(int callingUid, @Nullable String packageName) { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2427 | try { |
| 2428 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 2429 | if (packageName == null) { |
| 2430 | return false; |
| 2431 | } |
| 2432 | final int uid = AppGlobals.getPackageManager().getPackageUid(packageName, |
| 2433 | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, |
| 2434 | UserHandle.getUserId(callingUid)); |
| 2435 | return UserHandle.isSameApp(callingUid, uid); |
| 2436 | } |
| 2437 | } catch (RemoteException e) { |
| 2438 | // Should not happen |
| 2439 | } |
| 2440 | return true; |
| 2441 | } |
| 2442 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2443 | boolean checkAppSwitchAllowedLocked(int sourcePid, int sourceUid, |
| 2444 | int callingPid, int callingUid, String name) { |
| 2445 | if (mAppSwitchesAllowedTime < SystemClock.uptimeMillis()) { |
| 2446 | return true; |
| 2447 | } |
| 2448 | |
| 2449 | if (getRecentTasks().isCallerRecents(sourceUid)) { |
| 2450 | return true; |
| 2451 | } |
| 2452 | |
| 2453 | int perm = checkComponentPermission(STOP_APP_SWITCHES, sourcePid, sourceUid, -1, true); |
| 2454 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2455 | return true; |
| 2456 | } |
| 2457 | if (checkAllowAppSwitchUid(sourceUid)) { |
| 2458 | return true; |
| 2459 | } |
| 2460 | |
| 2461 | // If the actual IPC caller is different from the logical source, then |
| 2462 | // also see if they are allowed to control app switches. |
| 2463 | if (callingUid != -1 && callingUid != sourceUid) { |
| 2464 | perm = checkComponentPermission(STOP_APP_SWITCHES, callingPid, callingUid, -1, true); |
| 2465 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2466 | return true; |
| 2467 | } |
| 2468 | if (checkAllowAppSwitchUid(callingUid)) { |
| 2469 | return true; |
| 2470 | } |
| 2471 | } |
| 2472 | |
| 2473 | Slog.w(TAG, name + " request from " + sourceUid + " stopped"); |
| 2474 | return false; |
| 2475 | } |
| 2476 | |
| 2477 | private boolean checkAllowAppSwitchUid(int uid) { |
| 2478 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(UserHandle.getUserId(uid)); |
| 2479 | if (types != null) { |
| 2480 | for (int i = types.size() - 1; i >= 0; i--) { |
| 2481 | if (types.valueAt(i).intValue() == uid) { |
| 2482 | return true; |
| 2483 | } |
| 2484 | } |
| 2485 | } |
| 2486 | return false; |
| 2487 | } |
| 2488 | |
| 2489 | @Override |
| 2490 | public void setActivityController(IActivityController controller, boolean imAMonkey) { |
| 2491 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER, |
| 2492 | "setActivityController()"); |
| 2493 | synchronized (mGlobalLock) { |
| 2494 | mController = controller; |
| 2495 | mControllerIsAMonkey = imAMonkey; |
| 2496 | Watchdog.getInstance().setActivityController(controller); |
| 2497 | } |
| 2498 | } |
| 2499 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 2500 | public boolean isControllerAMonkey() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2501 | synchronized (mGlobalLock) { |
| 2502 | return mController != null && mControllerIsAMonkey; |
| 2503 | } |
| 2504 | } |
| 2505 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2506 | @Override |
| 2507 | public int getTaskForActivity(IBinder token, boolean onlyRoot) { |
| 2508 | synchronized (mGlobalLock) { |
| 2509 | return ActivityRecord.getTaskForActivityLocked(token, onlyRoot); |
| 2510 | } |
| 2511 | } |
| 2512 | |
| 2513 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2514 | public List<ActivityManager.RunningTaskInfo> getTasks(int maxNum) { |
| 2515 | return getFilteredTasks(maxNum, ACTIVITY_TYPE_UNDEFINED, WINDOWING_MODE_UNDEFINED); |
| 2516 | } |
| 2517 | |
| 2518 | @Override |
| 2519 | public List<ActivityManager.RunningTaskInfo> getFilteredTasks(int maxNum, |
| 2520 | @WindowConfiguration.ActivityType int ignoreActivityType, |
| 2521 | @WindowConfiguration.WindowingMode int ignoreWindowingMode) { |
| 2522 | final int callingUid = Binder.getCallingUid(); |
| 2523 | ArrayList<ActivityManager.RunningTaskInfo> list = new ArrayList<>(); |
| 2524 | |
| 2525 | synchronized (mGlobalLock) { |
| 2526 | if (DEBUG_ALL) Slog.v(TAG, "getTasks: max=" + maxNum); |
| 2527 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2528 | final boolean allowed = isGetTasksAllowed("getTasks", Binder.getCallingPid(), |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2529 | callingUid); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2530 | mRootActivityContainer.getRunningTasks(maxNum, list, ignoreActivityType, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2531 | ignoreWindowingMode, callingUid, allowed); |
| 2532 | } |
| 2533 | |
| 2534 | return list; |
| 2535 | } |
| 2536 | |
| 2537 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2538 | public final void finishSubActivity(IBinder token, String resultWho, int requestCode) { |
| 2539 | synchronized (mGlobalLock) { |
| 2540 | final long origId = Binder.clearCallingIdentity(); |
| 2541 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2542 | if (r != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2543 | r.getActivityStack().finishSubActivityLocked(r, resultWho, requestCode); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2544 | } |
| 2545 | Binder.restoreCallingIdentity(origId); |
| 2546 | } |
| 2547 | } |
| 2548 | |
| 2549 | @Override |
| 2550 | public boolean willActivityBeVisible(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2551 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2552 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 2553 | if (stack != null) { |
| 2554 | return stack.willActivityBeVisibleLocked(token); |
| 2555 | } |
| 2556 | return false; |
| 2557 | } |
| 2558 | } |
| 2559 | |
| 2560 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2561 | public void moveTaskToStack(int taskId, int stackId, boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2562 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "moveTaskToStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2563 | synchronized (mGlobalLock) { |
| 2564 | final long ident = Binder.clearCallingIdentity(); |
| 2565 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2566 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2567 | if (task == null) { |
| 2568 | Slog.w(TAG, "moveTaskToStack: No task for id=" + taskId); |
| 2569 | return; |
| 2570 | } |
| 2571 | |
| 2572 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToStack: moving task=" + taskId |
| 2573 | + " to stackId=" + stackId + " toTop=" + toTop); |
| 2574 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2575 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2576 | if (stack == null) { |
| 2577 | throw new IllegalStateException( |
| 2578 | "moveTaskToStack: No stack for stackId=" + stackId); |
| 2579 | } |
| 2580 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 2581 | throw new IllegalArgumentException("moveTaskToStack: Attempt to move task " |
| 2582 | + taskId + " to stack " + stackId); |
| 2583 | } |
| 2584 | if (stack.inSplitScreenPrimaryWindowingMode()) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2585 | mWindowManager.setDockedStackCreateState( |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2586 | SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */); |
| 2587 | } |
| 2588 | task.reparent(stack, toTop, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME, |
| 2589 | "moveTaskToStack"); |
| 2590 | } finally { |
| 2591 | Binder.restoreCallingIdentity(ident); |
| 2592 | } |
| 2593 | } |
| 2594 | } |
| 2595 | |
| 2596 | @Override |
| 2597 | public void resizeStack(int stackId, Rect destBounds, boolean allowResizeInDockedMode, |
| 2598 | boolean preserveWindows, boolean animate, int animationDuration) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2599 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2600 | |
| 2601 | final long ident = Binder.clearCallingIdentity(); |
| 2602 | try { |
| 2603 | synchronized (mGlobalLock) { |
| 2604 | if (animate) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 2605 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2606 | if (stack == null) { |
| 2607 | Slog.w(TAG, "resizeStack: stackId " + stackId + " not found."); |
| 2608 | return; |
| 2609 | } |
| 2610 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 2611 | throw new IllegalArgumentException("Stack: " + stackId |
| 2612 | + " doesn't support animated resize."); |
| 2613 | } |
| 2614 | stack.animateResizePinnedStack(null /* sourceHintBounds */, destBounds, |
| 2615 | animationDuration, false /* fromFullscreen */); |
| 2616 | } else { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -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 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2622 | mRootActivityContainer.resizeStack(stack, destBounds, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2623 | null /* tempTaskBounds */, null /* tempTaskInsetBounds */, |
| 2624 | preserveWindows, allowResizeInDockedMode, !DEFER_RESUME); |
| 2625 | } |
| 2626 | } |
| 2627 | } finally { |
| 2628 | Binder.restoreCallingIdentity(ident); |
| 2629 | } |
| 2630 | } |
| 2631 | |
wilsonshih | 5c4cf52 | 2019-01-25 09:03:47 +0800 | [diff] [blame] | 2632 | @Override |
| 2633 | public void offsetPinnedStackBounds(int stackId, Rect compareBounds, int xOffset, int yOffset, |
| 2634 | int animationDuration) { |
| 2635 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "offsetPinnedStackBounds()"); |
| 2636 | |
| 2637 | final long ident = Binder.clearCallingIdentity(); |
| 2638 | try { |
| 2639 | synchronized (mGlobalLock) { |
| 2640 | if (xOffset == 0 && yOffset == 0) { |
| 2641 | return; |
| 2642 | } |
| 2643 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
| 2644 | if (stack == null) { |
| 2645 | Slog.w(TAG, "offsetPinnedStackBounds: stackId " + stackId + " not found."); |
| 2646 | return; |
| 2647 | } |
| 2648 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 2649 | throw new IllegalArgumentException("Stack: " + stackId |
| 2650 | + " doesn't support animated resize."); |
| 2651 | } |
| 2652 | final Rect destBounds = new Rect(); |
| 2653 | stack.getAnimationOrCurrentBounds(destBounds); |
wilsonshih | a6e408c | 2019-02-19 17:30:03 +0800 | [diff] [blame] | 2654 | if (destBounds.isEmpty() || !destBounds.equals(compareBounds)) { |
wilsonshih | 5c4cf52 | 2019-01-25 09:03:47 +0800 | [diff] [blame] | 2655 | Slog.w(TAG, "The current stack bounds does not matched! It may be obsolete."); |
| 2656 | return; |
| 2657 | } |
| 2658 | destBounds.offset(xOffset, yOffset); |
| 2659 | stack.animateResizePinnedStack(null /* sourceHintBounds */, destBounds, |
| 2660 | animationDuration, false /* fromFullscreen */); |
| 2661 | } |
| 2662 | } finally { |
| 2663 | Binder.restoreCallingIdentity(ident); |
| 2664 | } |
| 2665 | } |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2666 | /** |
| 2667 | * Moves the specified task to the primary-split-screen stack. |
| 2668 | * |
| 2669 | * @param taskId Id of task to move. |
| 2670 | * @param createMode The mode the primary split screen stack should be created in if it doesn't |
| 2671 | * exist already. See |
| 2672 | * {@link android.app.ActivityTaskManager#SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT} |
| 2673 | * and |
| 2674 | * {@link android.app.ActivityTaskManager#SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT} |
| 2675 | * @param toTop If the task and stack should be moved to the top. |
| 2676 | * @param animate Whether we should play an animation for the moving the task. |
| 2677 | * @param initialBounds If the primary stack gets created, it will use these bounds for the |
| 2678 | * stack. Pass {@code null} to use default bounds. |
| 2679 | * @param showRecents If the recents activity should be shown on the other side of the task |
| 2680 | * going into split-screen mode. |
| 2681 | */ |
| 2682 | @Override |
| 2683 | public boolean setTaskWindowingModeSplitScreenPrimary(int taskId, int createMode, |
| 2684 | boolean toTop, boolean animate, Rect initialBounds, boolean showRecents) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2685 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2686 | "setTaskWindowingModeSplitScreenPrimary()"); |
| 2687 | synchronized (mGlobalLock) { |
| 2688 | final long ident = Binder.clearCallingIdentity(); |
| 2689 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2690 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2691 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2692 | if (task == null) { |
| 2693 | Slog.w(TAG, "setTaskWindowingModeSplitScreenPrimary: No task for id=" + taskId); |
| 2694 | return false; |
| 2695 | } |
| 2696 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
| 2697 | "setTaskWindowingModeSplitScreenPrimary: moving task=" + taskId |
| 2698 | + " to createMode=" + createMode + " toTop=" + toTop); |
| 2699 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2700 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2701 | + " non-standard task " + taskId + " to split-screen windowing mode"); |
| 2702 | } |
| 2703 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2704 | mWindowManager.setDockedStackCreateState(createMode, initialBounds); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2705 | final int windowingMode = task.getWindowingMode(); |
| 2706 | final ActivityStack stack = task.getStack(); |
| 2707 | if (toTop) { |
| 2708 | stack.moveToFront("setTaskWindowingModeSplitScreenPrimary", task); |
| 2709 | } |
| 2710 | stack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, animate, showRecents, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 2711 | false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */, |
| 2712 | false /* creating */); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2713 | return windowingMode != task.getWindowingMode(); |
| 2714 | } finally { |
| 2715 | Binder.restoreCallingIdentity(ident); |
| 2716 | } |
| 2717 | } |
| 2718 | } |
| 2719 | |
| 2720 | /** |
| 2721 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 2722 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 2723 | */ |
| 2724 | @Override |
| 2725 | public void removeStacksInWindowingModes(int[] windowingModes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2726 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2727 | "removeStacksInWindowingModes()"); |
| 2728 | |
| 2729 | synchronized (mGlobalLock) { |
| 2730 | final long ident = Binder.clearCallingIdentity(); |
| 2731 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2732 | mRootActivityContainer.removeStacksInWindowingModes(windowingModes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2733 | } finally { |
| 2734 | Binder.restoreCallingIdentity(ident); |
| 2735 | } |
| 2736 | } |
| 2737 | } |
| 2738 | |
| 2739 | @Override |
| 2740 | public void removeStacksWithActivityTypes(int[] activityTypes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2741 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2742 | "removeStacksWithActivityTypes()"); |
| 2743 | |
| 2744 | synchronized (mGlobalLock) { |
| 2745 | final long ident = Binder.clearCallingIdentity(); |
| 2746 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2747 | mRootActivityContainer.removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2748 | } finally { |
| 2749 | Binder.restoreCallingIdentity(ident); |
| 2750 | } |
| 2751 | } |
| 2752 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2753 | |
| 2754 | @Override |
| 2755 | public ParceledListSlice<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, |
| 2756 | int userId) { |
| 2757 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2758 | userId = handleIncomingUser(Binder.getCallingPid(), callingUid, userId, "getRecentTasks"); |
| 2759 | final boolean allowed = isGetTasksAllowed("getRecentTasks", Binder.getCallingPid(), |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2760 | callingUid); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2761 | final boolean detailed = checkGetTasksPermission( |
| 2762 | android.Manifest.permission.GET_DETAILED_TASKS, Binder.getCallingPid(), |
| 2763 | UserHandle.getAppId(callingUid)) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2764 | == PackageManager.PERMISSION_GRANTED; |
| 2765 | |
| 2766 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 2767 | return mRecentTasks.getRecentTasks(maxNum, flags, allowed, detailed, userId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2768 | callingUid); |
| 2769 | } |
| 2770 | } |
| 2771 | |
| 2772 | @Override |
| 2773 | public List<ActivityManager.StackInfo> getAllStackInfos() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2774 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2775 | long ident = Binder.clearCallingIdentity(); |
| 2776 | try { |
| 2777 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2778 | return mRootActivityContainer.getAllStackInfos(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2779 | } |
| 2780 | } finally { |
| 2781 | Binder.restoreCallingIdentity(ident); |
| 2782 | } |
| 2783 | } |
| 2784 | |
| 2785 | @Override |
| 2786 | public ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2787 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2788 | long ident = Binder.clearCallingIdentity(); |
| 2789 | try { |
| 2790 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2791 | return mRootActivityContainer.getStackInfo(windowingMode, activityType); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2792 | } |
| 2793 | } finally { |
| 2794 | Binder.restoreCallingIdentity(ident); |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | @Override |
| 2799 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2800 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "cancelRecentsAnimation()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2801 | final long callingUid = Binder.getCallingUid(); |
| 2802 | final long origId = Binder.clearCallingIdentity(); |
| 2803 | try { |
| 2804 | synchronized (mGlobalLock) { |
| 2805 | // Cancel the recents animation synchronously (do not hold the WM lock) |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2806 | mWindowManager.cancelRecentsAnimationSynchronously(restoreHomeStackPosition |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2807 | ? REORDER_MOVE_TO_ORIGINAL_POSITION |
| 2808 | : REORDER_KEEP_IN_PLACE, "cancelRecentsAnimation/uid=" + callingUid); |
| 2809 | } |
| 2810 | } finally { |
| 2811 | Binder.restoreCallingIdentity(origId); |
| 2812 | } |
| 2813 | } |
| 2814 | |
| 2815 | @Override |
| 2816 | public void startLockTaskModeByToken(IBinder token) { |
| 2817 | synchronized (mGlobalLock) { |
| 2818 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2819 | if (r == null) { |
| 2820 | return; |
| 2821 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2822 | startLockTaskModeLocked(r.getTaskRecord(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2823 | } |
| 2824 | } |
| 2825 | |
| 2826 | @Override |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2827 | public void startSystemLockTaskMode(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2828 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "startSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2829 | // This makes inner call to look as if it was initiated by system. |
| 2830 | long ident = Binder.clearCallingIdentity(); |
| 2831 | try { |
| 2832 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2833 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2834 | MATCH_TASK_IN_STACKS_ONLY); |
| 2835 | if (task == null) { |
| 2836 | return; |
| 2837 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2838 | |
| 2839 | // When starting lock task mode the stack must be in front and focused |
| 2840 | task.getStack().moveToFront("startSystemLockTaskMode"); |
| 2841 | startLockTaskModeLocked(task, true /* isSystemCaller */); |
| 2842 | } |
| 2843 | } finally { |
| 2844 | Binder.restoreCallingIdentity(ident); |
| 2845 | } |
| 2846 | } |
| 2847 | |
| 2848 | @Override |
| 2849 | public void stopLockTaskModeByToken(IBinder token) { |
| 2850 | synchronized (mGlobalLock) { |
| 2851 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2852 | if (r == null) { |
| 2853 | return; |
| 2854 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2855 | stopLockTaskModeInternal(r.getTaskRecord(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2856 | } |
| 2857 | } |
| 2858 | |
| 2859 | /** |
| 2860 | * This API should be called by SystemUI only when user perform certain action to dismiss |
| 2861 | * lock task mode. We should only dismiss pinned lock task mode in this case. |
| 2862 | */ |
| 2863 | @Override |
| 2864 | public void stopSystemLockTaskMode() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2865 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "stopSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2866 | stopLockTaskModeInternal(null, true /* isSystemCaller */); |
| 2867 | } |
| 2868 | |
| 2869 | private void startLockTaskModeLocked(@Nullable TaskRecord task, boolean isSystemCaller) { |
| 2870 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "startLockTaskModeLocked: " + task); |
| 2871 | if (task == null || task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) { |
| 2872 | return; |
| 2873 | } |
| 2874 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2875 | final ActivityStack stack = mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2876 | if (stack == null || task != stack.topTask()) { |
| 2877 | throw new IllegalArgumentException("Invalid task, not in foreground"); |
| 2878 | } |
| 2879 | |
| 2880 | // {@code isSystemCaller} is used to distinguish whether this request is initiated by the |
| 2881 | // system or a specific app. |
| 2882 | // * System-initiated requests will only start the pinned mode (screen pinning) |
| 2883 | // * App-initiated requests |
| 2884 | // - will put the device in fully locked mode (LockTask), if the app is whitelisted |
| 2885 | // - will start the pinned mode, otherwise |
| 2886 | final int callingUid = Binder.getCallingUid(); |
| 2887 | long ident = Binder.clearCallingIdentity(); |
| 2888 | try { |
| 2889 | // When a task is locked, dismiss the pinned stack if it exists |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2890 | mRootActivityContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2891 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2892 | getLockTaskController().startLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2893 | } finally { |
| 2894 | Binder.restoreCallingIdentity(ident); |
| 2895 | } |
| 2896 | } |
| 2897 | |
| 2898 | private void stopLockTaskModeInternal(@Nullable TaskRecord task, boolean isSystemCaller) { |
| 2899 | final int callingUid = Binder.getCallingUid(); |
| 2900 | long ident = Binder.clearCallingIdentity(); |
| 2901 | try { |
| 2902 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2903 | getLockTaskController().stopLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2904 | } |
| 2905 | // Launch in-call UI if a call is ongoing. This is necessary to allow stopping the lock |
| 2906 | // task and jumping straight into a call in the case of emergency call back. |
| 2907 | TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
| 2908 | if (tm != null) { |
| 2909 | tm.showInCallScreen(false); |
| 2910 | } |
| 2911 | } finally { |
| 2912 | Binder.restoreCallingIdentity(ident); |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | @Override |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 2917 | public void updateLockTaskPackages(int userId, String[] packages) { |
| 2918 | final int callingUid = Binder.getCallingUid(); |
| 2919 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 2920 | mAmInternal.enforceCallingPermission(Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
| 2921 | "updateLockTaskPackages()"); |
| 2922 | } |
| 2923 | synchronized (this) { |
| 2924 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Whitelisting " + userId + ":" |
| 2925 | + Arrays.toString(packages)); |
| 2926 | getLockTaskController().updateLockTaskPackages(userId, packages); |
| 2927 | } |
| 2928 | } |
| 2929 | |
| 2930 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2931 | public boolean isInLockTaskMode() { |
| 2932 | return getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
| 2933 | } |
| 2934 | |
| 2935 | @Override |
| 2936 | public int getLockTaskModeState() { |
| 2937 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2938 | return getLockTaskController().getLockTaskModeState(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2939 | } |
| 2940 | } |
| 2941 | |
| 2942 | @Override |
| 2943 | public void setTaskDescription(IBinder token, ActivityManager.TaskDescription td) { |
| 2944 | synchronized (mGlobalLock) { |
| 2945 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2946 | if (r != null) { |
| 2947 | r.setTaskDescription(td); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2948 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2949 | task.updateTaskDescription(); |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 2950 | mTaskChangeNotificationController.notifyTaskDescriptionChanged(task.getTaskInfo()); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2951 | } |
| 2952 | } |
| 2953 | } |
| 2954 | |
| 2955 | @Override |
| 2956 | public Bundle getActivityOptions(IBinder token) { |
| 2957 | final long origId = Binder.clearCallingIdentity(); |
| 2958 | try { |
| 2959 | synchronized (mGlobalLock) { |
| 2960 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2961 | if (r != null) { |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 2962 | final ActivityOptions activityOptions = r.takeOptionsLocked( |
| 2963 | true /* fromClient */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2964 | return activityOptions == null ? null : activityOptions.toBundle(); |
| 2965 | } |
| 2966 | return null; |
| 2967 | } |
| 2968 | } finally { |
| 2969 | Binder.restoreCallingIdentity(origId); |
| 2970 | } |
| 2971 | } |
| 2972 | |
| 2973 | @Override |
| 2974 | public List<IBinder> getAppTasks(String callingPackage) { |
| 2975 | int callingUid = Binder.getCallingUid(); |
| 2976 | long ident = Binder.clearCallingIdentity(); |
| 2977 | try { |
| 2978 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 2979 | return mRecentTasks.getAppTasksList(callingUid, callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2980 | } |
| 2981 | } finally { |
| 2982 | Binder.restoreCallingIdentity(ident); |
| 2983 | } |
| 2984 | } |
| 2985 | |
| 2986 | @Override |
| 2987 | public void finishVoiceTask(IVoiceInteractionSession session) { |
| 2988 | synchronized (mGlobalLock) { |
| 2989 | final long origId = Binder.clearCallingIdentity(); |
| 2990 | try { |
| 2991 | // TODO: VI Consider treating local voice interactions and voice tasks |
| 2992 | // differently here |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2993 | mRootActivityContainer.finishVoiceTask(session); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2994 | } finally { |
| 2995 | Binder.restoreCallingIdentity(origId); |
| 2996 | } |
| 2997 | } |
| 2998 | |
| 2999 | } |
| 3000 | |
| 3001 | @Override |
| 3002 | public boolean isTopOfTask(IBinder token) { |
| 3003 | synchronized (mGlobalLock) { |
| 3004 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3005 | return r != null && r.getTaskRecord().getTopActivity() == r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3006 | } |
| 3007 | } |
| 3008 | |
| 3009 | @Override |
| 3010 | public void notifyLaunchTaskBehindComplete(IBinder token) { |
| 3011 | mStackSupervisor.scheduleLaunchTaskBehindComplete(token); |
| 3012 | } |
| 3013 | |
| 3014 | @Override |
| 3015 | public void notifyEnterAnimationComplete(IBinder token) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3016 | mH.post(() -> { |
| 3017 | synchronized (mGlobalLock) { |
| 3018 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3019 | if (r != null && r.attachedToProcess()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3020 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3021 | r.app.getThread().scheduleEnterAnimationComplete(r.appToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3022 | } catch (RemoteException e) { |
| 3023 | } |
| 3024 | } |
| 3025 | } |
| 3026 | |
| 3027 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | /** Called from an app when assist data is ready. */ |
| 3031 | @Override |
| 3032 | public void reportAssistContextExtras(IBinder token, Bundle extras, AssistStructure structure, |
| 3033 | AssistContent content, Uri referrer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3034 | PendingAssistExtras pae = (PendingAssistExtras) token; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3035 | synchronized (pae) { |
| 3036 | pae.result = extras; |
| 3037 | pae.structure = structure; |
| 3038 | pae.content = content; |
| 3039 | if (referrer != null) { |
| 3040 | pae.extras.putParcelable(Intent.EXTRA_REFERRER, referrer); |
| 3041 | } |
| 3042 | if (structure != null) { |
Winson Chung | 48b2565 | 2018-10-22 14:04:30 -0700 | [diff] [blame] | 3043 | // Pre-fill the task/activity component for all assist data receivers |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3044 | structure.setTaskId(pae.activity.getTaskRecord().taskId); |
| 3045 | structure.setActivityComponent(pae.activity.mActivityComponent); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3046 | structure.setHomeActivity(pae.isHome); |
| 3047 | } |
| 3048 | pae.haveResult = true; |
| 3049 | pae.notifyAll(); |
| 3050 | if (pae.intent == null && pae.receiver == null) { |
| 3051 | // Caller is just waiting for the result. |
| 3052 | return; |
| 3053 | } |
| 3054 | } |
| 3055 | // We are now ready to launch the assist activity. |
| 3056 | IAssistDataReceiver sendReceiver = null; |
| 3057 | Bundle sendBundle = null; |
| 3058 | synchronized (mGlobalLock) { |
| 3059 | buildAssistBundleLocked(pae, extras); |
| 3060 | boolean exists = mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3061 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3062 | if (!exists) { |
| 3063 | // Timed out. |
| 3064 | return; |
| 3065 | } |
| 3066 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3067 | if ((sendReceiver = pae.receiver) != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3068 | // Caller wants result sent back to them. |
| 3069 | sendBundle = new Bundle(); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 3070 | sendBundle.putInt(ActivityTaskManagerInternal.ASSIST_TASK_ID, |
| 3071 | pae.activity.getTaskRecord().taskId); |
| 3072 | sendBundle.putBinder(ActivityTaskManagerInternal.ASSIST_ACTIVITY_ID, |
| 3073 | pae.activity.assistToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3074 | sendBundle.putBundle(ASSIST_KEY_DATA, pae.extras); |
| 3075 | sendBundle.putParcelable(ASSIST_KEY_STRUCTURE, pae.structure); |
| 3076 | sendBundle.putParcelable(ASSIST_KEY_CONTENT, pae.content); |
| 3077 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3078 | } |
| 3079 | } |
| 3080 | if (sendReceiver != null) { |
| 3081 | try { |
| 3082 | sendReceiver.onHandleAssistData(sendBundle); |
| 3083 | } catch (RemoteException e) { |
| 3084 | } |
| 3085 | return; |
| 3086 | } |
| 3087 | |
| 3088 | final long ident = Binder.clearCallingIdentity(); |
| 3089 | try { |
| 3090 | if (TextUtils.equals(pae.intent.getAction(), |
| 3091 | android.service.voice.VoiceInteractionService.SERVICE_INTERFACE)) { |
| 3092 | pae.intent.putExtras(pae.extras); |
Marvin Ramin | 830d4e3 | 2019-03-12 13:16:58 +0100 | [diff] [blame] | 3093 | |
| 3094 | startVoiceInteractionServiceAsUser(pae.intent, pae.userHandle, "AssistContext"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3095 | } else { |
| 3096 | pae.intent.replaceExtras(pae.extras); |
| 3097 | pae.intent.setFlags(FLAG_ACTIVITY_NEW_TASK |
| 3098 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 3099 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 3100 | mInternal.closeSystemDialogs("assist"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3101 | |
| 3102 | try { |
| 3103 | mContext.startActivityAsUser(pae.intent, new UserHandle(pae.userHandle)); |
| 3104 | } catch (ActivityNotFoundException e) { |
| 3105 | Slog.w(TAG, "No activity to handle assist action.", e); |
| 3106 | } |
| 3107 | } |
| 3108 | } finally { |
| 3109 | Binder.restoreCallingIdentity(ident); |
| 3110 | } |
| 3111 | } |
| 3112 | |
Marvin Ramin | 830d4e3 | 2019-03-12 13:16:58 +0100 | [diff] [blame] | 3113 | /** |
| 3114 | * Workaround for historical API which starts the Assist service with a non-foreground |
| 3115 | * {@code startService()} call. |
| 3116 | */ |
| 3117 | private void startVoiceInteractionServiceAsUser( |
| 3118 | Intent intent, int userHandle, String reason) { |
| 3119 | // Resolve the intent to find out which package we need to whitelist. |
| 3120 | ResolveInfo resolveInfo = |
| 3121 | mContext.getPackageManager().resolveServiceAsUser(intent, 0, userHandle); |
| 3122 | if (resolveInfo == null || resolveInfo.serviceInfo == null) { |
| 3123 | Slog.e(TAG, "VoiceInteractionService intent does not resolve. Not starting."); |
| 3124 | return; |
| 3125 | } |
| 3126 | intent.setPackage(resolveInfo.serviceInfo.packageName); |
| 3127 | |
| 3128 | // Whitelist background services temporarily. |
| 3129 | LocalServices.getService(DeviceIdleController.LocalService.class) |
| 3130 | .addPowerSaveTempWhitelistApp(Process.myUid(), intent.getPackage(), |
| 3131 | SERVICE_LAUNCH_IDLE_WHITELIST_DURATION_MS, userHandle, false, reason); |
| 3132 | |
| 3133 | // Finally, try to start the service. |
| 3134 | try { |
| 3135 | mContext.startServiceAsUser(intent, UserHandle.of(userHandle)); |
| 3136 | } catch (RuntimeException e) { |
| 3137 | Slog.e(TAG, "VoiceInteractionService failed to start.", e); |
| 3138 | } |
| 3139 | } |
| 3140 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3141 | @Override |
| 3142 | public int addAppTask(IBinder activityToken, Intent intent, |
| 3143 | ActivityManager.TaskDescription description, Bitmap thumbnail) throws RemoteException { |
| 3144 | final int callingUid = Binder.getCallingUid(); |
| 3145 | final long callingIdent = Binder.clearCallingIdentity(); |
| 3146 | |
| 3147 | try { |
| 3148 | synchronized (mGlobalLock) { |
| 3149 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 3150 | if (r == null) { |
| 3151 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 3152 | + activityToken); |
| 3153 | } |
| 3154 | ComponentName comp = intent.getComponent(); |
| 3155 | if (comp == null) { |
| 3156 | throw new IllegalArgumentException("Intent " + intent |
| 3157 | + " must specify explicit component"); |
| 3158 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3159 | if (thumbnail.getWidth() != mThumbnailWidth |
| 3160 | || thumbnail.getHeight() != mThumbnailHeight) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3161 | throw new IllegalArgumentException("Bad thumbnail size: got " |
| 3162 | + thumbnail.getWidth() + "x" + thumbnail.getHeight() + ", require " |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3163 | + mThumbnailWidth + "x" + mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3164 | } |
| 3165 | if (intent.getSelector() != null) { |
| 3166 | intent.setSelector(null); |
| 3167 | } |
| 3168 | if (intent.getSourceBounds() != null) { |
| 3169 | intent.setSourceBounds(null); |
| 3170 | } |
| 3171 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) { |
| 3172 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) == 0) { |
| 3173 | // The caller has added this as an auto-remove task... that makes no |
| 3174 | // sense, so turn off auto-remove. |
| 3175 | intent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS); |
| 3176 | } |
| 3177 | } |
| 3178 | final ActivityInfo ainfo = AppGlobals.getPackageManager().getActivityInfo(comp, |
| 3179 | STOCK_PM_FLAGS, UserHandle.getUserId(callingUid)); |
| 3180 | if (ainfo.applicationInfo.uid != callingUid) { |
| 3181 | throw new SecurityException( |
| 3182 | "Can't add task for another application: target uid=" |
| 3183 | + ainfo.applicationInfo.uid + ", calling uid=" + callingUid); |
| 3184 | } |
| 3185 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3186 | final ActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3187 | final TaskRecord task = stack.createTaskRecord( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3188 | mStackSupervisor.getNextTaskIdForUserLocked(r.mUserId), ainfo, intent, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3189 | null /* voiceSession */, null /* voiceInteractor */, !ON_TOP); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3190 | if (!mRecentTasks.addToBottom(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3191 | // The app has too many tasks already and we can't add any more |
| 3192 | stack.removeTask(task, "addAppTask", REMOVE_TASK_MODE_DESTROYING); |
| 3193 | return INVALID_TASK_ID; |
| 3194 | } |
| 3195 | task.lastTaskDescription.copyFrom(description); |
| 3196 | |
| 3197 | // TODO: Send the thumbnail to WM to store it. |
| 3198 | |
| 3199 | return task.taskId; |
| 3200 | } |
| 3201 | } finally { |
| 3202 | Binder.restoreCallingIdentity(callingIdent); |
| 3203 | } |
| 3204 | } |
| 3205 | |
| 3206 | @Override |
| 3207 | public Point getAppTaskThumbnailSize() { |
| 3208 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3209 | return new Point(mThumbnailWidth, mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3210 | } |
| 3211 | } |
| 3212 | |
| 3213 | @Override |
| 3214 | public void setTaskResizeable(int taskId, int resizeableMode) { |
| 3215 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3216 | final TaskRecord task = mRootActivityContainer.anyTaskForId( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3217 | taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 3218 | if (task == null) { |
| 3219 | Slog.w(TAG, "setTaskResizeable: taskId=" + taskId + " not found"); |
| 3220 | return; |
| 3221 | } |
| 3222 | task.setResizeMode(resizeableMode); |
| 3223 | } |
| 3224 | } |
| 3225 | |
| 3226 | @Override |
| 3227 | public void resizeTask(int taskId, Rect bounds, int resizeMode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3228 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "resizeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3229 | long ident = Binder.clearCallingIdentity(); |
| 3230 | try { |
| 3231 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3232 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 3233 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3234 | if (task == null) { |
| 3235 | Slog.w(TAG, "resizeTask: taskId=" + taskId + " not found"); |
| 3236 | return; |
| 3237 | } |
| 3238 | // Place the task in the right stack if it isn't there already based on |
| 3239 | // the requested bounds. |
| 3240 | // The stack transition logic is: |
| 3241 | // - a null bounds on a freeform task moves that task to fullscreen |
| 3242 | // - a non-null bounds on a non-freeform (fullscreen OR docked) task moves |
| 3243 | // that task to freeform |
| 3244 | // - otherwise the task is not moved |
| 3245 | ActivityStack stack = task.getStack(); |
| 3246 | if (!task.getWindowConfiguration().canResizeTask()) { |
| 3247 | throw new IllegalArgumentException("resizeTask not allowed on task=" + task); |
| 3248 | } |
| 3249 | if (bounds == null && stack.getWindowingMode() == WINDOWING_MODE_FREEFORM) { |
| 3250 | stack = stack.getDisplay().getOrCreateStack( |
| 3251 | WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), ON_TOP); |
| 3252 | } else if (bounds != null && stack.getWindowingMode() != WINDOWING_MODE_FREEFORM) { |
| 3253 | stack = stack.getDisplay().getOrCreateStack( |
| 3254 | WINDOWING_MODE_FREEFORM, stack.getActivityType(), ON_TOP); |
| 3255 | } |
| 3256 | |
| 3257 | // Reparent the task to the right stack if necessary |
| 3258 | boolean preserveWindow = (resizeMode & RESIZE_MODE_PRESERVE_WINDOW) != 0; |
| 3259 | if (stack != task.getStack()) { |
| 3260 | // Defer resume until the task is resized below |
| 3261 | task.reparent(stack, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, |
| 3262 | DEFER_RESUME, "resizeTask"); |
| 3263 | preserveWindow = false; |
| 3264 | } |
| 3265 | |
| 3266 | // After reparenting (which only resizes the task to the stack bounds), resize the |
| 3267 | // task to the actual bounds provided |
| 3268 | task.resize(bounds, resizeMode, preserveWindow, !DEFER_RESUME); |
| 3269 | } |
| 3270 | } finally { |
| 3271 | Binder.restoreCallingIdentity(ident); |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | @Override |
| 3276 | public boolean releaseActivityInstance(IBinder token) { |
| 3277 | synchronized (mGlobalLock) { |
| 3278 | final long origId = Binder.clearCallingIdentity(); |
| 3279 | try { |
| 3280 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3281 | if (r == null) { |
| 3282 | return false; |
| 3283 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3284 | return r.getActivityStack().safelyDestroyActivityLocked(r, "app-req"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3285 | } finally { |
| 3286 | Binder.restoreCallingIdentity(origId); |
| 3287 | } |
| 3288 | } |
| 3289 | } |
| 3290 | |
| 3291 | @Override |
| 3292 | public void releaseSomeActivities(IApplicationThread appInt) { |
| 3293 | synchronized (mGlobalLock) { |
| 3294 | final long origId = Binder.clearCallingIdentity(); |
| 3295 | try { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3296 | final WindowProcessController app = getProcessController(appInt); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3297 | mRootActivityContainer.releaseSomeActivitiesLocked(app, "low-mem"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3298 | } finally { |
| 3299 | Binder.restoreCallingIdentity(origId); |
| 3300 | } |
| 3301 | } |
| 3302 | } |
| 3303 | |
| 3304 | @Override |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 3305 | public void setLockScreenShown(boolean keyguardShowing, boolean aodShowing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3306 | if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3307 | != PackageManager.PERMISSION_GRANTED) { |
| 3308 | throw new SecurityException("Requires permission " |
| 3309 | + android.Manifest.permission.DEVICE_POWER); |
| 3310 | } |
| 3311 | |
| 3312 | synchronized (mGlobalLock) { |
| 3313 | long ident = Binder.clearCallingIdentity(); |
| 3314 | if (mKeyguardShown != keyguardShowing) { |
| 3315 | mKeyguardShown = keyguardShowing; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3316 | final Message msg = PooledLambda.obtainMessage( |
| 3317 | ActivityManagerInternal::reportCurKeyguardUsageEvent, mAmInternal, |
| 3318 | keyguardShowing); |
| 3319 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3320 | } |
| 3321 | try { |
wilsonshih | 177261f | 2019-02-22 12:02:18 +0800 | [diff] [blame] | 3322 | mKeyguardController.setKeyguardShown(keyguardShowing, aodShowing); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3323 | } finally { |
| 3324 | Binder.restoreCallingIdentity(ident); |
| 3325 | } |
| 3326 | } |
| 3327 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3328 | mH.post(() -> { |
| 3329 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3330 | mScreenObservers.get(i).onKeyguardStateChanged(keyguardShowing); |
| 3331 | } |
| 3332 | }); |
| 3333 | } |
| 3334 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 3335 | public void onScreenAwakeChanged(boolean isAwake) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3336 | mH.post(() -> { |
| 3337 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3338 | mScreenObservers.get(i).onAwakeStateChanged(isAwake); |
| 3339 | } |
| 3340 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | @Override |
| 3344 | public Bitmap getTaskDescriptionIcon(String filePath, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3345 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 3346 | userId, "getTaskDescriptionIcon"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3347 | |
| 3348 | final File passedIconFile = new File(filePath); |
| 3349 | final File legitIconFile = new File(TaskPersister.getUserImagesDir(userId), |
| 3350 | passedIconFile.getName()); |
| 3351 | if (!legitIconFile.getPath().equals(filePath) |
| 3352 | || !filePath.contains(ActivityRecord.ACTIVITY_ICON_SUFFIX)) { |
| 3353 | throw new IllegalArgumentException("Bad file path: " + filePath |
| 3354 | + " passed for userId " + userId); |
| 3355 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3356 | return mRecentTasks.getTaskDescriptionIcon(filePath); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3360 | public void startInPlaceAnimationOnFrontMostApplication(Bundle opts) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3361 | final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(opts); |
| 3362 | final ActivityOptions activityOptions = safeOptions != null |
| 3363 | ? safeOptions.getOptions(mStackSupervisor) |
| 3364 | : null; |
| 3365 | if (activityOptions == null |
| 3366 | || activityOptions.getAnimationType() != ActivityOptions.ANIM_CUSTOM_IN_PLACE |
| 3367 | || activityOptions.getCustomInPlaceResId() == 0) { |
| 3368 | throw new IllegalArgumentException("Expected in-place ActivityOption " + |
| 3369 | "with valid animation"); |
| 3370 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3371 | // Get top display of front most application. |
| 3372 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
| 3373 | if (focusedStack != null) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3374 | final DisplayContent dc = focusedStack.getDisplay().mDisplayContent; |
| 3375 | dc.prepareAppTransition(TRANSIT_TASK_IN_PLACE, false); |
| 3376 | dc.mAppTransition.overrideInPlaceAppTransition(activityOptions.getPackageName(), |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3377 | activityOptions.getCustomInPlaceResId()); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3378 | dc.executeAppTransition(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3379 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | @Override |
| 3383 | public void removeStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3384 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "removeStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3385 | synchronized (mGlobalLock) { |
| 3386 | final long ident = Binder.clearCallingIdentity(); |
| 3387 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3388 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3389 | if (stack == null) { |
| 3390 | Slog.w(TAG, "removeStack: No stack with id=" + stackId); |
| 3391 | return; |
| 3392 | } |
| 3393 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3394 | throw new IllegalArgumentException( |
| 3395 | "Removing non-standard stack is not allowed."); |
| 3396 | } |
| 3397 | mStackSupervisor.removeStack(stack); |
| 3398 | } finally { |
| 3399 | Binder.restoreCallingIdentity(ident); |
| 3400 | } |
| 3401 | } |
| 3402 | } |
| 3403 | |
| 3404 | @Override |
| 3405 | public void moveStackToDisplay(int stackId, int displayId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3406 | mAmInternal.enforceCallingPermission(INTERNAL_SYSTEM_WINDOW, "moveStackToDisplay()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3407 | |
| 3408 | synchronized (mGlobalLock) { |
| 3409 | final long ident = Binder.clearCallingIdentity(); |
| 3410 | try { |
| 3411 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveStackToDisplay: moving stackId=" + stackId |
| 3412 | + " to displayId=" + displayId); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3413 | mRootActivityContainer.moveStackToDisplay(stackId, displayId, ON_TOP); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3414 | } finally { |
| 3415 | Binder.restoreCallingIdentity(ident); |
| 3416 | } |
| 3417 | } |
| 3418 | } |
| 3419 | |
| 3420 | @Override |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3421 | public void toggleFreeformWindowingMode(IBinder token) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3422 | synchronized (mGlobalLock) { |
| 3423 | long ident = Binder.clearCallingIdentity(); |
| 3424 | try { |
| 3425 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3426 | if (r == null) { |
| 3427 | throw new IllegalArgumentException( |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3428 | "toggleFreeformWindowingMode: No activity record matching token=" |
| 3429 | + token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3430 | } |
| 3431 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3432 | final ActivityStack stack = r.getActivityStack(); |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3433 | if (stack == null) { |
| 3434 | throw new IllegalStateException("toggleFreeformWindowingMode: the activity " |
| 3435 | + "doesn't have a stack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3436 | } |
| 3437 | |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3438 | if (!stack.inFreeformWindowingMode() |
| 3439 | && stack.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) { |
| 3440 | throw new IllegalStateException("toggleFreeformWindowingMode: You can only " |
| 3441 | + "toggle between fullscreen and freeform."); |
| 3442 | } |
| 3443 | |
| 3444 | if (stack.inFreeformWindowingMode()) { |
| 3445 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Yunfan Chen | e9c1c31 | 2019-04-18 14:49:15 +0900 | [diff] [blame] | 3446 | } else if (stack.getParent().inFreeformWindowingMode()) { |
| 3447 | // If the window is on a freeform display, set it to undefined. It will be |
| 3448 | // resolved to freeform and it can adjust windowing mode when the display mode |
| 3449 | // changes in runtime. |
| 3450 | stack.setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Yunfan Chen | d967af8 | 2019-01-17 18:30:18 +0900 | [diff] [blame] | 3451 | } else { |
| 3452 | stack.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 3453 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3454 | } finally { |
| 3455 | Binder.restoreCallingIdentity(ident); |
| 3456 | } |
| 3457 | } |
| 3458 | } |
| 3459 | |
| 3460 | /** Sets the task stack listener that gets callbacks when a task stack changes. */ |
| 3461 | @Override |
| 3462 | public void registerTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3463 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3464 | "registerTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3465 | mTaskChangeNotificationController.registerTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3466 | } |
| 3467 | |
| 3468 | /** Unregister a task stack listener so that it stops receiving callbacks. */ |
| 3469 | @Override |
| 3470 | public void unregisterTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3471 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3472 | "unregisterTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3473 | mTaskChangeNotificationController.unregisterTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3474 | } |
| 3475 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3476 | @Override |
| 3477 | public boolean requestAssistContextExtras(int requestType, IAssistDataReceiver receiver, |
| 3478 | Bundle receiverExtras, IBinder activityToken, boolean focused, boolean newSessionId) { |
| 3479 | return enqueueAssistContext(requestType, null, null, receiver, receiverExtras, |
| 3480 | activityToken, focused, newSessionId, UserHandle.getCallingUserId(), null, |
| 3481 | PENDING_ASSIST_EXTRAS_LONG_TIMEOUT, 0) != null; |
| 3482 | } |
| 3483 | |
| 3484 | @Override |
| 3485 | public boolean requestAutofillData(IAssistDataReceiver receiver, Bundle receiverExtras, |
| 3486 | IBinder activityToken, int flags) { |
| 3487 | return enqueueAssistContext(ActivityManager.ASSIST_CONTEXT_AUTOFILL, null, null, |
| 3488 | receiver, receiverExtras, activityToken, true, true, UserHandle.getCallingUserId(), |
| 3489 | null, PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT, flags) != null; |
| 3490 | } |
| 3491 | |
| 3492 | @Override |
| 3493 | public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle, |
| 3494 | Bundle args) { |
| 3495 | return enqueueAssistContext(requestType, intent, hint, null, null, null, |
| 3496 | true /* focused */, true /* newSessionId */, userHandle, args, |
| 3497 | PENDING_ASSIST_EXTRAS_TIMEOUT, 0) != null; |
| 3498 | } |
| 3499 | |
| 3500 | @Override |
| 3501 | public Bundle getAssistContextExtras(int requestType) { |
| 3502 | PendingAssistExtras pae = enqueueAssistContext(requestType, null, null, null, |
| 3503 | null, null, true /* focused */, true /* newSessionId */, |
| 3504 | UserHandle.getCallingUserId(), null, PENDING_ASSIST_EXTRAS_TIMEOUT, 0); |
| 3505 | if (pae == null) { |
| 3506 | return null; |
| 3507 | } |
| 3508 | synchronized (pae) { |
| 3509 | while (!pae.haveResult) { |
| 3510 | try { |
| 3511 | pae.wait(); |
| 3512 | } catch (InterruptedException e) { |
| 3513 | } |
| 3514 | } |
| 3515 | } |
| 3516 | synchronized (mGlobalLock) { |
| 3517 | buildAssistBundleLocked(pae, pae.result); |
| 3518 | mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3519 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3520 | } |
| 3521 | return pae.extras; |
| 3522 | } |
| 3523 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3524 | /** |
| 3525 | * Binder IPC calls go through the public entry point. |
| 3526 | * This can be called with or without the global lock held. |
| 3527 | */ |
| 3528 | private static int checkCallingPermission(String permission) { |
| 3529 | return checkPermission( |
| 3530 | permission, Binder.getCallingPid(), UserHandle.getAppId(Binder.getCallingUid())); |
| 3531 | } |
| 3532 | |
| 3533 | /** This can be called with or without the global lock held. */ |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3534 | private void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3535 | if (!getRecentTasks().isCallerRecents(Binder.getCallingUid())) { |
| 3536 | mAmInternal.enforceCallingPermission(permission, func); |
| 3537 | } |
| 3538 | } |
| 3539 | |
| 3540 | @VisibleForTesting |
| 3541 | int checkGetTasksPermission(String permission, int pid, int uid) { |
| 3542 | return checkPermission(permission, pid, uid); |
| 3543 | } |
| 3544 | |
| 3545 | static int checkPermission(String permission, int pid, int uid) { |
| 3546 | if (permission == null) { |
| 3547 | return PackageManager.PERMISSION_DENIED; |
| 3548 | } |
| 3549 | return checkComponentPermission(permission, pid, uid, -1, true); |
| 3550 | } |
| 3551 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3552 | public static int checkComponentPermission(String permission, int pid, int uid, |
| 3553 | int owningUid, boolean exported) { |
| 3554 | return ActivityManagerService.checkComponentPermission( |
| 3555 | permission, pid, uid, owningUid, exported); |
| 3556 | } |
| 3557 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3558 | boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 3559 | if (getRecentTasks().isCallerRecents(callingUid)) { |
| 3560 | // Always allow the recents component to get tasks |
| 3561 | return true; |
| 3562 | } |
| 3563 | |
| 3564 | boolean allowed = checkGetTasksPermission(android.Manifest.permission.REAL_GET_TASKS, |
| 3565 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED; |
| 3566 | if (!allowed) { |
| 3567 | if (checkGetTasksPermission(android.Manifest.permission.GET_TASKS, |
| 3568 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED) { |
| 3569 | // Temporary compatibility: some existing apps on the system image may |
| 3570 | // still be requesting the old permission and not switched to the new |
| 3571 | // one; if so, we'll still allow them full access. This means we need |
| 3572 | // to see if they are holding the old permission and are a system app. |
| 3573 | try { |
| 3574 | if (AppGlobals.getPackageManager().isUidPrivileged(callingUid)) { |
| 3575 | allowed = true; |
| 3576 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3577 | + " is using old GET_TASKS but privileged; allowing"); |
| 3578 | } |
| 3579 | } catch (RemoteException e) { |
| 3580 | } |
| 3581 | } |
| 3582 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3583 | + " does not hold REAL_GET_TASKS; limiting output"); |
| 3584 | } |
| 3585 | return allowed; |
| 3586 | } |
| 3587 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3588 | private PendingAssistExtras enqueueAssistContext(int requestType, Intent intent, String hint, |
| 3589 | IAssistDataReceiver receiver, Bundle receiverExtras, IBinder activityToken, |
| 3590 | boolean focused, boolean newSessionId, int userHandle, Bundle args, long timeout, |
| 3591 | int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3592 | mAmInternal.enforceCallingPermission(android.Manifest.permission.GET_TOP_ACTIVITY_INFO, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3593 | "enqueueAssistContext()"); |
| 3594 | |
| 3595 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3596 | ActivityRecord activity = getTopDisplayFocusedStack().getTopActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3597 | if (activity == null) { |
| 3598 | Slog.w(TAG, "getAssistContextExtras failed: no top activity"); |
| 3599 | return null; |
| 3600 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3601 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3602 | Slog.w(TAG, "getAssistContextExtras failed: no process for " + activity); |
| 3603 | return null; |
| 3604 | } |
| 3605 | if (focused) { |
| 3606 | if (activityToken != null) { |
| 3607 | ActivityRecord caller = ActivityRecord.forTokenLocked(activityToken); |
| 3608 | if (activity != caller) { |
| 3609 | Slog.w(TAG, "enqueueAssistContext failed: caller " + caller |
| 3610 | + " is not current top " + activity); |
| 3611 | return null; |
| 3612 | } |
| 3613 | } |
| 3614 | } else { |
| 3615 | activity = ActivityRecord.forTokenLocked(activityToken); |
| 3616 | if (activity == null) { |
| 3617 | Slog.w(TAG, "enqueueAssistContext failed: activity for token=" + activityToken |
| 3618 | + " couldn't be found"); |
| 3619 | return null; |
| 3620 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3621 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3622 | Slog.w(TAG, "enqueueAssistContext failed: no process for " + activity); |
| 3623 | return null; |
| 3624 | } |
| 3625 | } |
| 3626 | |
| 3627 | PendingAssistExtras pae; |
| 3628 | Bundle extras = new Bundle(); |
| 3629 | if (args != null) { |
| 3630 | extras.putAll(args); |
| 3631 | } |
| 3632 | extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3633 | extras.putInt(Intent.EXTRA_ASSIST_UID, activity.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3634 | |
| 3635 | pae = new PendingAssistExtras(activity, extras, intent, hint, receiver, receiverExtras, |
| 3636 | userHandle); |
| 3637 | pae.isHome = activity.isActivityTypeHome(); |
| 3638 | |
| 3639 | // Increment the sessionId if necessary |
| 3640 | if (newSessionId) { |
| 3641 | mViSessionId++; |
| 3642 | } |
| 3643 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3644 | activity.app.getThread().requestAssistContextExtras(activity.appToken, pae, |
| 3645 | requestType, mViSessionId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3646 | mPendingAssistExtras.add(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3647 | mUiHandler.postDelayed(pae, timeout); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3648 | } catch (RemoteException e) { |
| 3649 | Slog.w(TAG, "getAssistContextExtras failed: crash calling " + activity); |
| 3650 | return null; |
| 3651 | } |
| 3652 | return pae; |
| 3653 | } |
| 3654 | } |
| 3655 | |
| 3656 | private void buildAssistBundleLocked(PendingAssistExtras pae, Bundle result) { |
| 3657 | if (result != null) { |
| 3658 | pae.extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, result); |
| 3659 | } |
| 3660 | if (pae.hint != null) { |
| 3661 | pae.extras.putBoolean(pae.hint, true); |
| 3662 | } |
| 3663 | } |
| 3664 | |
| 3665 | private void pendingAssistExtrasTimedOut(PendingAssistExtras pae) { |
| 3666 | IAssistDataReceiver receiver; |
| 3667 | synchronized (mGlobalLock) { |
| 3668 | mPendingAssistExtras.remove(pae); |
| 3669 | receiver = pae.receiver; |
| 3670 | } |
| 3671 | if (receiver != null) { |
| 3672 | // Caller wants result sent back to them. |
| 3673 | Bundle sendBundle = new Bundle(); |
| 3674 | // At least return the receiver extras |
| 3675 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3676 | try { |
| 3677 | pae.receiver.onHandleAssistData(sendBundle); |
| 3678 | } catch (RemoteException e) { |
| 3679 | } |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | public class PendingAssistExtras extends Binder implements Runnable { |
| 3684 | public final ActivityRecord activity; |
| 3685 | public boolean isHome; |
| 3686 | public final Bundle extras; |
| 3687 | public final Intent intent; |
| 3688 | public final String hint; |
| 3689 | public final IAssistDataReceiver receiver; |
| 3690 | public final int userHandle; |
| 3691 | public boolean haveResult = false; |
| 3692 | public Bundle result = null; |
| 3693 | public AssistStructure structure = null; |
| 3694 | public AssistContent content = null; |
| 3695 | public Bundle receiverExtras; |
| 3696 | |
| 3697 | public PendingAssistExtras(ActivityRecord _activity, Bundle _extras, Intent _intent, |
| 3698 | String _hint, IAssistDataReceiver _receiver, Bundle _receiverExtras, |
| 3699 | int _userHandle) { |
| 3700 | activity = _activity; |
| 3701 | extras = _extras; |
| 3702 | intent = _intent; |
| 3703 | hint = _hint; |
| 3704 | receiver = _receiver; |
| 3705 | receiverExtras = _receiverExtras; |
| 3706 | userHandle = _userHandle; |
| 3707 | } |
| 3708 | |
| 3709 | @Override |
| 3710 | public void run() { |
| 3711 | Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from " + activity); |
| 3712 | synchronized (this) { |
| 3713 | haveResult = true; |
| 3714 | notifyAll(); |
| 3715 | } |
| 3716 | pendingAssistExtrasTimedOut(this); |
| 3717 | } |
| 3718 | } |
| 3719 | |
| 3720 | @Override |
| 3721 | public boolean isAssistDataAllowedOnCurrentActivity() { |
| 3722 | int userId; |
| 3723 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3724 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3725 | if (focusedStack == null || focusedStack.isActivityTypeAssistant()) { |
| 3726 | return false; |
| 3727 | } |
| 3728 | |
| 3729 | final ActivityRecord activity = focusedStack.getTopActivity(); |
| 3730 | if (activity == null) { |
| 3731 | return false; |
| 3732 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3733 | userId = activity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3734 | } |
| 3735 | return !DevicePolicyCache.getInstance().getScreenCaptureDisabled(userId); |
| 3736 | } |
| 3737 | |
| 3738 | @Override |
| 3739 | public boolean showAssistFromActivity(IBinder token, Bundle args) { |
| 3740 | long ident = Binder.clearCallingIdentity(); |
| 3741 | try { |
| 3742 | synchronized (mGlobalLock) { |
| 3743 | ActivityRecord caller = ActivityRecord.forTokenLocked(token); |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3744 | ActivityRecord top = getTopDisplayFocusedStack().getTopActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3745 | if (top != caller) { |
| 3746 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3747 | + " is not current top " + top); |
| 3748 | return false; |
| 3749 | } |
| 3750 | if (!top.nowVisible) { |
| 3751 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3752 | + " is not visible"); |
| 3753 | return false; |
| 3754 | } |
| 3755 | } |
| 3756 | return mAssistUtils.showSessionForActiveService(args, SHOW_SOURCE_APPLICATION, null, |
| 3757 | token); |
| 3758 | } finally { |
| 3759 | Binder.restoreCallingIdentity(ident); |
| 3760 | } |
| 3761 | } |
| 3762 | |
| 3763 | @Override |
| 3764 | public boolean isRootVoiceInteraction(IBinder token) { |
| 3765 | synchronized (mGlobalLock) { |
| 3766 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3767 | if (r == null) { |
| 3768 | return false; |
| 3769 | } |
| 3770 | return r.rootVoiceInteraction; |
| 3771 | } |
| 3772 | } |
| 3773 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3774 | private void onLocalVoiceInteractionStartedLocked(IBinder activity, |
| 3775 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 3776 | ActivityRecord activityToCallback = ActivityRecord.forTokenLocked(activity); |
| 3777 | if (activityToCallback == null) return; |
| 3778 | activityToCallback.setVoiceSessionLocked(voiceSession); |
| 3779 | |
| 3780 | // Inform the activity |
| 3781 | try { |
| 3782 | activityToCallback.app.getThread().scheduleLocalVoiceInteractionStarted(activity, |
| 3783 | voiceInteractor); |
| 3784 | long token = Binder.clearCallingIdentity(); |
| 3785 | try { |
| 3786 | startRunningVoiceLocked(voiceSession, activityToCallback.appInfo.uid); |
| 3787 | } finally { |
| 3788 | Binder.restoreCallingIdentity(token); |
| 3789 | } |
| 3790 | // TODO: VI Should we cache the activity so that it's easier to find later |
| 3791 | // rather than scan through all the stacks and activities? |
| 3792 | } catch (RemoteException re) { |
| 3793 | activityToCallback.clearVoiceSessionLocked(); |
| 3794 | // TODO: VI Should this terminate the voice session? |
| 3795 | } |
| 3796 | } |
| 3797 | |
| 3798 | private void startRunningVoiceLocked(IVoiceInteractionSession session, int targetUid) { |
| 3799 | Slog.d(TAG, "<<< startRunningVoiceLocked()"); |
| 3800 | mVoiceWakeLock.setWorkSource(new WorkSource(targetUid)); |
| 3801 | if (mRunningVoice == null || mRunningVoice.asBinder() != session.asBinder()) { |
| 3802 | boolean wasRunningVoice = mRunningVoice != null; |
| 3803 | mRunningVoice = session; |
| 3804 | if (!wasRunningVoice) { |
| 3805 | mVoiceWakeLock.acquire(); |
| 3806 | updateSleepIfNeededLocked(); |
| 3807 | } |
| 3808 | } |
| 3809 | } |
| 3810 | |
| 3811 | void finishRunningVoiceLocked() { |
| 3812 | if (mRunningVoice != null) { |
| 3813 | mRunningVoice = null; |
| 3814 | mVoiceWakeLock.release(); |
| 3815 | updateSleepIfNeededLocked(); |
| 3816 | } |
| 3817 | } |
| 3818 | |
| 3819 | @Override |
| 3820 | public void setVoiceKeepAwake(IVoiceInteractionSession session, boolean keepAwake) { |
| 3821 | synchronized (mGlobalLock) { |
| 3822 | if (mRunningVoice != null && mRunningVoice.asBinder() == session.asBinder()) { |
| 3823 | if (keepAwake) { |
| 3824 | mVoiceWakeLock.acquire(); |
| 3825 | } else { |
| 3826 | mVoiceWakeLock.release(); |
| 3827 | } |
| 3828 | } |
| 3829 | } |
| 3830 | } |
| 3831 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3832 | @Override |
| 3833 | public ComponentName getActivityClassForToken(IBinder token) { |
| 3834 | synchronized (mGlobalLock) { |
| 3835 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3836 | if (r == null) { |
| 3837 | return null; |
| 3838 | } |
| 3839 | return r.intent.getComponent(); |
| 3840 | } |
| 3841 | } |
| 3842 | |
| 3843 | @Override |
| 3844 | public String getPackageForToken(IBinder token) { |
| 3845 | synchronized (mGlobalLock) { |
| 3846 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3847 | if (r == null) { |
| 3848 | return null; |
| 3849 | } |
| 3850 | return r.packageName; |
| 3851 | } |
| 3852 | } |
| 3853 | |
| 3854 | @Override |
| 3855 | public void showLockTaskEscapeMessage(IBinder token) { |
| 3856 | synchronized (mGlobalLock) { |
| 3857 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3858 | if (r == null) { |
| 3859 | return; |
| 3860 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3861 | getLockTaskController().showLockTaskToast(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3862 | } |
| 3863 | } |
| 3864 | |
| 3865 | @Override |
| 3866 | public void keyguardGoingAway(int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3867 | enforceNotIsolatedCaller("keyguardGoingAway"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3868 | final long token = Binder.clearCallingIdentity(); |
| 3869 | try { |
| 3870 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3871 | mKeyguardController.keyguardGoingAway(flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3872 | } |
| 3873 | } finally { |
| 3874 | Binder.restoreCallingIdentity(token); |
| 3875 | } |
| 3876 | } |
| 3877 | |
| 3878 | /** |
| 3879 | * Try to place task to provided position. The final position might be different depending on |
| 3880 | * current user and stacks state. The task will be moved to target stack if it's currently in |
| 3881 | * different stack. |
| 3882 | */ |
| 3883 | @Override |
| 3884 | public void positionTaskInStack(int taskId, int stackId, int position) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3885 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "positionTaskInStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3886 | synchronized (mGlobalLock) { |
| 3887 | long ident = Binder.clearCallingIdentity(); |
| 3888 | try { |
| 3889 | if (DEBUG_STACK) Slog.d(TAG_STACK, "positionTaskInStack: positioning task=" |
| 3890 | + taskId + " in stackId=" + stackId + " at position=" + position); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3891 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3892 | if (task == null) { |
| 3893 | throw new IllegalArgumentException("positionTaskInStack: no task for id=" |
| 3894 | + taskId); |
| 3895 | } |
| 3896 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3897 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3898 | |
| 3899 | if (stack == null) { |
| 3900 | throw new IllegalArgumentException("positionTaskInStack: no stack for id=" |
| 3901 | + stackId); |
| 3902 | } |
| 3903 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3904 | throw new IllegalArgumentException("positionTaskInStack: Attempt to change" |
| 3905 | + " the position of task " + taskId + " in/to non-standard stack"); |
| 3906 | } |
| 3907 | |
| 3908 | // TODO: Have the callers of this API call a separate reparent method if that is |
| 3909 | // what they intended to do vs. having this method also do reparenting. |
| 3910 | if (task.getStack() == stack) { |
| 3911 | // Change position in current stack. |
| 3912 | stack.positionChildAt(task, position); |
| 3913 | } else { |
| 3914 | // Reparent to new stack. |
| 3915 | task.reparent(stack, position, REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, |
| 3916 | !DEFER_RESUME, "positionTaskInStack"); |
| 3917 | } |
| 3918 | } finally { |
| 3919 | Binder.restoreCallingIdentity(ident); |
| 3920 | } |
| 3921 | } |
| 3922 | } |
| 3923 | |
| 3924 | @Override |
| 3925 | public void reportSizeConfigurations(IBinder token, int[] horizontalSizeConfiguration, |
| 3926 | int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { |
| 3927 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Report configuration: " + token + " " |
| 3928 | + horizontalSizeConfiguration + " " + verticalSizeConfigurations); |
| 3929 | synchronized (mGlobalLock) { |
| 3930 | ActivityRecord record = ActivityRecord.isInStackLocked(token); |
| 3931 | if (record == null) { |
| 3932 | throw new IllegalArgumentException("reportSizeConfigurations: ActivityRecord not " |
| 3933 | + "found for: " + token); |
| 3934 | } |
| 3935 | record.setSizeConfigurations(horizontalSizeConfiguration, |
| 3936 | verticalSizeConfigurations, smallestSizeConfigurations); |
| 3937 | } |
| 3938 | } |
| 3939 | |
| 3940 | /** |
| 3941 | * Dismisses split-screen multi-window mode. |
| 3942 | * @param toTop If true the current primary split-screen stack will be placed or left on top. |
| 3943 | */ |
| 3944 | @Override |
| 3945 | public void dismissSplitScreenMode(boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3946 | enforceCallerIsRecentsOrHasPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3947 | MANAGE_ACTIVITY_STACKS, "dismissSplitScreenMode()"); |
| 3948 | final long ident = Binder.clearCallingIdentity(); |
| 3949 | try { |
| 3950 | synchronized (mGlobalLock) { |
| 3951 | final ActivityStack stack = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3952 | mRootActivityContainer.getDefaultDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3953 | if (stack == null) { |
| 3954 | Slog.w(TAG, "dismissSplitScreenMode: primary split-screen stack not found."); |
| 3955 | return; |
| 3956 | } |
| 3957 | |
| 3958 | if (toTop) { |
| 3959 | // Caller wants the current split-screen primary stack to be the top stack after |
| 3960 | // it goes fullscreen, so move it to the front. |
| 3961 | stack.moveToFront("dismissSplitScreenMode"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3962 | } else if (mRootActivityContainer.isTopDisplayFocusedStack(stack)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3963 | // In this case the current split-screen primary stack shouldn't be the top |
| 3964 | // stack after it goes fullscreen, but it current has focus, so we move the |
| 3965 | // focus to the top-most split-screen secondary stack next to it. |
| 3966 | final ActivityStack otherStack = stack.getDisplay().getTopStackInWindowingMode( |
| 3967 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 3968 | if (otherStack != null) { |
| 3969 | otherStack.moveToFront("dismissSplitScreenMode_other"); |
| 3970 | } |
| 3971 | } |
| 3972 | |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 3973 | stack.setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3974 | } |
| 3975 | } finally { |
| 3976 | Binder.restoreCallingIdentity(ident); |
| 3977 | } |
| 3978 | } |
| 3979 | |
| 3980 | /** |
| 3981 | * Dismisses Pip |
| 3982 | * @param animate True if the dismissal should be animated. |
| 3983 | * @param animationDuration The duration of the resize animation in milliseconds or -1 if the |
| 3984 | * default animation duration should be used. |
| 3985 | */ |
| 3986 | @Override |
| 3987 | public void dismissPip(boolean animate, int animationDuration) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3988 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "dismissPip()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3989 | final long ident = Binder.clearCallingIdentity(); |
| 3990 | try { |
| 3991 | synchronized (mGlobalLock) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 3992 | final ActivityStack stack = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3993 | mRootActivityContainer.getDefaultDisplay().getPinnedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3994 | if (stack == null) { |
| 3995 | Slog.w(TAG, "dismissPip: pinned stack not found."); |
| 3996 | return; |
| 3997 | } |
| 3998 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 3999 | throw new IllegalArgumentException("Stack: " + stack |
| 4000 | + " doesn't support animated resize."); |
| 4001 | } |
| 4002 | if (animate) { |
| 4003 | stack.animateResizePinnedStack(null /* sourceHintBounds */, |
| 4004 | null /* destBounds */, animationDuration, false /* fromFullscreen */); |
| 4005 | } else { |
| 4006 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, true /* onTop */); |
| 4007 | } |
| 4008 | } |
| 4009 | } finally { |
| 4010 | Binder.restoreCallingIdentity(ident); |
| 4011 | } |
| 4012 | } |
| 4013 | |
| 4014 | @Override |
| 4015 | public void suppressResizeConfigChanges(boolean suppress) throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4016 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "suppressResizeConfigChanges()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4017 | synchronized (mGlobalLock) { |
| 4018 | mSuppressResizeConfigChanges = suppress; |
| 4019 | } |
| 4020 | } |
| 4021 | |
| 4022 | /** |
| 4023 | * NOTE: For the pinned stack, this method is usually called after the bounds animation has |
| 4024 | * animated the stack to the fullscreen, but can also be called if we are relaunching an |
| 4025 | * activity and clearing the task at the same time. |
| 4026 | */ |
| 4027 | @Override |
| 4028 | // TODO: API should just be about changing windowing modes... |
| 4029 | public void moveTasksToFullscreenStack(int fromStackId, boolean onTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4030 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4031 | "moveTasksToFullscreenStack()"); |
| 4032 | synchronized (mGlobalLock) { |
| 4033 | final long origId = Binder.clearCallingIdentity(); |
| 4034 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4035 | final ActivityStack stack = mRootActivityContainer.getStack(fromStackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4036 | if (stack != null){ |
| 4037 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 4038 | throw new IllegalArgumentException( |
| 4039 | "You can't move tasks from non-standard stacks."); |
| 4040 | } |
| 4041 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, onTop); |
| 4042 | } |
| 4043 | } finally { |
| 4044 | Binder.restoreCallingIdentity(origId); |
| 4045 | } |
| 4046 | } |
| 4047 | } |
| 4048 | |
| 4049 | /** |
| 4050 | * Moves the top activity in the input stackId to the pinned stack. |
| 4051 | * |
| 4052 | * @param stackId Id of stack to move the top activity to pinned stack. |
| 4053 | * @param bounds Bounds to use for pinned stack. |
| 4054 | * |
| 4055 | * @return True if the top activity of the input stack was successfully moved to the pinned |
| 4056 | * stack. |
| 4057 | */ |
| 4058 | @Override |
| 4059 | public boolean moveTopActivityToPinnedStack(int stackId, Rect bounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4060 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4061 | "moveTopActivityToPinnedStack()"); |
| 4062 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4063 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4064 | throw new IllegalStateException("moveTopActivityToPinnedStack:" |
| 4065 | + "Device doesn't support picture-in-picture mode"); |
| 4066 | } |
| 4067 | |
| 4068 | long ident = Binder.clearCallingIdentity(); |
| 4069 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4070 | return mRootActivityContainer.moveTopStackActivityToPinnedStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4071 | } finally { |
| 4072 | Binder.restoreCallingIdentity(ident); |
| 4073 | } |
| 4074 | } |
| 4075 | } |
| 4076 | |
| 4077 | @Override |
| 4078 | public boolean isInMultiWindowMode(IBinder token) { |
| 4079 | final long origId = Binder.clearCallingIdentity(); |
| 4080 | try { |
| 4081 | synchronized (mGlobalLock) { |
| 4082 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4083 | if (r == null) { |
| 4084 | return false; |
| 4085 | } |
| 4086 | // An activity is consider to be in multi-window mode if its task isn't fullscreen. |
| 4087 | return r.inMultiWindowMode(); |
| 4088 | } |
| 4089 | } finally { |
| 4090 | Binder.restoreCallingIdentity(origId); |
| 4091 | } |
| 4092 | } |
| 4093 | |
| 4094 | @Override |
| 4095 | public boolean isInPictureInPictureMode(IBinder token) { |
| 4096 | final long origId = Binder.clearCallingIdentity(); |
| 4097 | try { |
| 4098 | synchronized (mGlobalLock) { |
| 4099 | return isInPictureInPictureMode(ActivityRecord.forTokenLocked(token)); |
| 4100 | } |
| 4101 | } finally { |
| 4102 | Binder.restoreCallingIdentity(origId); |
| 4103 | } |
| 4104 | } |
| 4105 | |
| 4106 | private boolean isInPictureInPictureMode(ActivityRecord r) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4107 | if (r == null || r.getActivityStack() == null || !r.inPinnedWindowingMode() |
| 4108 | || r.getActivityStack().isInStackLocked(r) == null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4109 | return false; |
| 4110 | } |
| 4111 | |
| 4112 | // If we are animating to fullscreen then we have already dispatched the PIP mode |
| 4113 | // changed, so we should reflect that check here as well. |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 4114 | final TaskStack taskStack = r.getActivityStack().getTaskStack(); |
| 4115 | return !taskStack.isAnimatingBoundsToFullscreen(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | @Override |
| 4119 | public boolean enterPictureInPictureMode(IBinder token, final PictureInPictureParams params) { |
| 4120 | final long origId = Binder.clearCallingIdentity(); |
| 4121 | try { |
| 4122 | synchronized (mGlobalLock) { |
| 4123 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 4124 | "enterPictureInPictureMode", token, params); |
| 4125 | |
| 4126 | // If the activity is already in picture in picture mode, then just return early |
| 4127 | if (isInPictureInPictureMode(r)) { |
| 4128 | return true; |
| 4129 | } |
| 4130 | |
| 4131 | // Activity supports picture-in-picture, now check that we can enter PiP at this |
| 4132 | // point, if it is |
| 4133 | if (!r.checkEnterPictureInPictureState("enterPictureInPictureMode", |
| 4134 | false /* beforeStopping */)) { |
| 4135 | return false; |
| 4136 | } |
| 4137 | |
| 4138 | final Runnable enterPipRunnable = () -> { |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4139 | synchronized (mGlobalLock) { |
| 4140 | // Only update the saved args from the args that are set |
| 4141 | r.pictureInPictureArgs.copyOnlySet(params); |
| 4142 | final float aspectRatio = r.pictureInPictureArgs.getAspectRatio(); |
| 4143 | final List<RemoteAction> actions = r.pictureInPictureArgs.getActions(); |
| 4144 | // Adjust the source bounds by the insets for the transition down |
| 4145 | final Rect sourceBounds = new Rect( |
| 4146 | r.pictureInPictureArgs.getSourceRectHint()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4147 | mRootActivityContainer.moveActivityToPinnedStack( |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4148 | r, sourceBounds, aspectRatio, "enterPictureInPictureMode"); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 4149 | final ActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 4150 | stack.setPictureInPictureAspectRatio(aspectRatio); |
| 4151 | stack.setPictureInPictureActions(actions); |
| 4152 | MetricsLoggerWrapper.logPictureInPictureEnter(mContext, r.appInfo.uid, |
| 4153 | r.shortComponentName, r.supportsEnterPipOnTaskSwitch); |
| 4154 | logPictureInPictureArgs(params); |
| 4155 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4156 | }; |
| 4157 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4158 | if (isKeyguardLocked()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4159 | // If the keyguard is showing or occluded, then try and dismiss it before |
| 4160 | // entering picture-in-picture (this will prompt the user to authenticate if the |
| 4161 | // device is currently locked). |
| 4162 | dismissKeyguard(token, new KeyguardDismissCallback() { |
| 4163 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4164 | public void onDismissSucceeded() { |
| 4165 | mH.post(enterPipRunnable); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4166 | } |
| 4167 | }, null /* message */); |
| 4168 | } else { |
| 4169 | // Enter picture in picture immediately otherwise |
| 4170 | enterPipRunnable.run(); |
| 4171 | } |
| 4172 | return true; |
| 4173 | } |
| 4174 | } finally { |
| 4175 | Binder.restoreCallingIdentity(origId); |
| 4176 | } |
| 4177 | } |
| 4178 | |
| 4179 | @Override |
| 4180 | public void setPictureInPictureParams(IBinder token, final PictureInPictureParams params) { |
| 4181 | final long origId = Binder.clearCallingIdentity(); |
| 4182 | try { |
| 4183 | synchronized (mGlobalLock) { |
| 4184 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 4185 | "setPictureInPictureParams", token, params); |
| 4186 | |
| 4187 | // Only update the saved args from the args that are set |
| 4188 | r.pictureInPictureArgs.copyOnlySet(params); |
| 4189 | if (r.inPinnedWindowingMode()) { |
| 4190 | // If the activity is already in picture-in-picture, update the pinned stack now |
| 4191 | // if it is not already expanding to fullscreen. Otherwise, the arguments will |
| 4192 | // be used the next time the activity enters PiP |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 4193 | final ActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4194 | if (!stack.isAnimatingBoundsToFullscreen()) { |
| 4195 | stack.setPictureInPictureAspectRatio( |
| 4196 | r.pictureInPictureArgs.getAspectRatio()); |
| 4197 | stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions()); |
| 4198 | } |
| 4199 | } |
| 4200 | logPictureInPictureArgs(params); |
| 4201 | } |
| 4202 | } finally { |
| 4203 | Binder.restoreCallingIdentity(origId); |
| 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | @Override |
| 4208 | public int getMaxNumPictureInPictureActions(IBinder token) { |
| 4209 | // Currently, this is a static constant, but later, we may change this to be dependent on |
| 4210 | // the context of the activity |
| 4211 | return 3; |
| 4212 | } |
| 4213 | |
| 4214 | private void logPictureInPictureArgs(PictureInPictureParams params) { |
| 4215 | if (params.hasSetActions()) { |
| 4216 | MetricsLogger.histogram(mContext, "tron_varz_picture_in_picture_actions_count", |
| 4217 | params.getActions().size()); |
| 4218 | } |
| 4219 | if (params.hasSetAspectRatio()) { |
| 4220 | LogMaker lm = new LogMaker(MetricsEvent.ACTION_PICTURE_IN_PICTURE_ASPECT_RATIO_CHANGED); |
| 4221 | lm.addTaggedData(MetricsEvent.PICTURE_IN_PICTURE_ASPECT_RATIO, params.getAspectRatio()); |
| 4222 | MetricsLogger.action(lm); |
| 4223 | } |
| 4224 | } |
| 4225 | |
| 4226 | /** |
| 4227 | * Checks the state of the system and the activity associated with the given {@param token} to |
| 4228 | * verify that picture-in-picture is supported for that activity. |
| 4229 | * |
| 4230 | * @return the activity record for the given {@param token} if all the checks pass. |
| 4231 | */ |
| 4232 | private ActivityRecord ensureValidPictureInPictureActivityParamsLocked(String caller, |
| 4233 | IBinder token, PictureInPictureParams params) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4234 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4235 | throw new IllegalStateException(caller |
| 4236 | + ": Device doesn't support picture-in-picture mode."); |
| 4237 | } |
| 4238 | |
| 4239 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 4240 | if (r == null) { |
| 4241 | throw new IllegalStateException(caller |
| 4242 | + ": Can't find activity for token=" + token); |
| 4243 | } |
| 4244 | |
| 4245 | if (!r.supportsPictureInPicture()) { |
| 4246 | throw new IllegalStateException(caller |
| 4247 | + ": Current activity does not support picture-in-picture."); |
| 4248 | } |
| 4249 | |
| 4250 | if (params.hasSetAspectRatio() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4251 | && !mWindowManager.isValidPictureInPictureAspectRatio( |
| 4252 | r.getActivityStack().mDisplayId, params.getAspectRatio())) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4253 | final float minAspectRatio = mContext.getResources().getFloat( |
| 4254 | com.android.internal.R.dimen.config_pictureInPictureMinAspectRatio); |
| 4255 | final float maxAspectRatio = mContext.getResources().getFloat( |
| 4256 | com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio); |
| 4257 | throw new IllegalArgumentException(String.format(caller |
| 4258 | + ": Aspect ratio is too extreme (must be between %f and %f).", |
| 4259 | minAspectRatio, maxAspectRatio)); |
| 4260 | } |
| 4261 | |
| 4262 | // Truncate the number of actions if necessary |
| 4263 | params.truncateActions(getMaxNumPictureInPictureActions(token)); |
| 4264 | |
| 4265 | return r; |
| 4266 | } |
| 4267 | |
| 4268 | @Override |
| 4269 | public IBinder getUriPermissionOwnerForActivity(IBinder activityToken) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4270 | enforceNotIsolatedCaller("getUriPermissionOwnerForActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4271 | synchronized (mGlobalLock) { |
| 4272 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 4273 | if (r == null) { |
| 4274 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 4275 | + activityToken); |
| 4276 | } |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 4277 | return r.getUriPermissionsLocked().getExternalToken(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4278 | } |
| 4279 | } |
| 4280 | |
| 4281 | @Override |
| 4282 | public void resizeDockedStack(Rect dockedBounds, Rect tempDockedTaskBounds, |
| 4283 | Rect tempDockedTaskInsetBounds, |
| 4284 | Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4285 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeDockedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4286 | long ident = Binder.clearCallingIdentity(); |
| 4287 | try { |
| 4288 | synchronized (mGlobalLock) { |
| 4289 | mStackSupervisor.resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, |
| 4290 | tempDockedTaskInsetBounds, tempOtherTaskBounds, tempOtherTaskInsetBounds, |
| 4291 | PRESERVE_WINDOWS); |
| 4292 | } |
| 4293 | } finally { |
| 4294 | Binder.restoreCallingIdentity(ident); |
| 4295 | } |
| 4296 | } |
| 4297 | |
| 4298 | @Override |
| 4299 | public void setSplitScreenResizing(boolean resizing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4300 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setSplitScreenResizing()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4301 | final long ident = Binder.clearCallingIdentity(); |
| 4302 | try { |
| 4303 | synchronized (mGlobalLock) { |
| 4304 | mStackSupervisor.setSplitScreenResizing(resizing); |
| 4305 | } |
| 4306 | } finally { |
| 4307 | Binder.restoreCallingIdentity(ident); |
| 4308 | } |
| 4309 | } |
| 4310 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4311 | /** |
| 4312 | * Check that we have the features required for VR-related API calls, and throw an exception if |
| 4313 | * not. |
| 4314 | */ |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 4315 | public void enforceSystemHasVrFeature() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4316 | if (!mContext.getPackageManager().hasSystemFeature( |
| 4317 | PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE)) { |
| 4318 | throw new UnsupportedOperationException("VR mode not supported on this device!"); |
| 4319 | } |
| 4320 | } |
| 4321 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4322 | @Override |
| 4323 | public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4324 | enforceSystemHasVrFeature(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4325 | |
| 4326 | final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class); |
| 4327 | |
| 4328 | ActivityRecord r; |
| 4329 | synchronized (mGlobalLock) { |
| 4330 | r = ActivityRecord.isInStackLocked(token); |
| 4331 | } |
| 4332 | |
| 4333 | if (r == null) { |
| 4334 | throw new IllegalArgumentException(); |
| 4335 | } |
| 4336 | |
| 4337 | int err; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4338 | if ((err = vrService.hasVrPackage(packageName, r.mUserId)) != |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4339 | VrManagerInternal.NO_ERROR) { |
| 4340 | return err; |
| 4341 | } |
| 4342 | |
| 4343 | // Clear the binder calling uid since this path may call moveToTask(). |
| 4344 | final long callingId = Binder.clearCallingIdentity(); |
| 4345 | try { |
| 4346 | synchronized (mGlobalLock) { |
| 4347 | r.requestedVrComponent = (enabled) ? packageName : null; |
| 4348 | |
| 4349 | // Update associated state if this activity is currently focused |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 4350 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4351 | applyUpdateVrModeLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4352 | } |
| 4353 | return 0; |
| 4354 | } |
| 4355 | } finally { |
| 4356 | Binder.restoreCallingIdentity(callingId); |
| 4357 | } |
| 4358 | } |
| 4359 | |
| 4360 | @Override |
| 4361 | public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) { |
| 4362 | Slog.i(TAG, "Activity tried to startLocalVoiceInteraction"); |
| 4363 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4364 | ActivityRecord activity = getTopDisplayFocusedStack().getTopActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4365 | if (ActivityRecord.forTokenLocked(callingActivity) != activity) { |
| 4366 | throw new SecurityException("Only focused activity can call startVoiceInteraction"); |
| 4367 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4368 | if (mRunningVoice != null || activity.getTaskRecord().voiceSession != null |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4369 | || activity.voiceSession != null) { |
| 4370 | Slog.w(TAG, "Already in a voice interaction, cannot start new voice interaction"); |
| 4371 | return; |
| 4372 | } |
| 4373 | if (activity.pendingVoiceInteractionStart) { |
| 4374 | Slog.w(TAG, "Pending start of voice interaction already."); |
| 4375 | return; |
| 4376 | } |
| 4377 | activity.pendingVoiceInteractionStart = true; |
| 4378 | } |
| 4379 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4380 | .startLocalVoiceInteraction(callingActivity, options); |
| 4381 | } |
| 4382 | |
| 4383 | @Override |
| 4384 | public void stopLocalVoiceInteraction(IBinder callingActivity) { |
| 4385 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4386 | .stopLocalVoiceInteraction(callingActivity); |
| 4387 | } |
| 4388 | |
| 4389 | @Override |
| 4390 | public boolean supportsLocalVoiceInteraction() { |
| 4391 | return LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4392 | .supportsLocalVoiceInteraction(); |
| 4393 | } |
| 4394 | |
| 4395 | /** Notifies all listeners when the pinned stack animation starts. */ |
| 4396 | @Override |
| 4397 | public void notifyPinnedStackAnimationStarted() { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4398 | mTaskChangeNotificationController.notifyPinnedStackAnimationStarted(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4399 | } |
| 4400 | |
| 4401 | /** Notifies all listeners when the pinned stack animation ends. */ |
| 4402 | @Override |
| 4403 | public void notifyPinnedStackAnimationEnded() { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4404 | mTaskChangeNotificationController.notifyPinnedStackAnimationEnded(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4405 | } |
| 4406 | |
| 4407 | @Override |
| 4408 | public void resizePinnedStack(Rect pinnedBounds, Rect tempPinnedTaskBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4409 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizePinnedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4410 | final long ident = Binder.clearCallingIdentity(); |
| 4411 | try { |
| 4412 | synchronized (mGlobalLock) { |
| 4413 | mStackSupervisor.resizePinnedStackLocked(pinnedBounds, tempPinnedTaskBounds); |
| 4414 | } |
| 4415 | } finally { |
| 4416 | Binder.restoreCallingIdentity(ident); |
| 4417 | } |
| 4418 | } |
| 4419 | |
| 4420 | @Override |
| 4421 | public boolean updateDisplayOverrideConfiguration(Configuration values, int displayId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4422 | mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateDisplayOverrideConfiguration()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4423 | |
| 4424 | synchronized (mGlobalLock) { |
| 4425 | // Check if display is initialized in AM. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4426 | if (!mRootActivityContainer.isDisplayAdded(displayId)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4427 | // Call might come when display is not yet added or has already been removed. |
| 4428 | if (DEBUG_CONFIGURATION) { |
| 4429 | Slog.w(TAG, "Trying to update display configuration for non-existing displayId=" |
| 4430 | + displayId); |
| 4431 | } |
| 4432 | return false; |
| 4433 | } |
| 4434 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4435 | if (values == null && mWindowManager != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4436 | // sentinel: fetch the current configuration from the window manager |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4437 | values = mWindowManager.computeNewConfiguration(displayId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4438 | } |
| 4439 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4440 | if (mWindowManager != null) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4441 | final Message msg = PooledLambda.obtainMessage( |
| 4442 | ActivityManagerInternal::updateOomLevelsForDisplay, mAmInternal, displayId); |
| 4443 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | final long origId = Binder.clearCallingIdentity(); |
| 4447 | try { |
| 4448 | if (values != null) { |
| 4449 | Settings.System.clearConfiguration(values); |
| 4450 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4451 | updateDisplayOverrideConfigurationLocked(values, null /* starting */, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4452 | false /* deferResume */, displayId, mTmpUpdateConfigurationResult); |
| 4453 | return mTmpUpdateConfigurationResult.changes != 0; |
| 4454 | } finally { |
| 4455 | Binder.restoreCallingIdentity(origId); |
| 4456 | } |
| 4457 | } |
| 4458 | } |
| 4459 | |
| 4460 | @Override |
| 4461 | public boolean updateConfiguration(Configuration values) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4462 | mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateConfiguration()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4463 | |
| 4464 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4465 | if (values == null && mWindowManager != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4466 | // sentinel: fetch the current configuration from the window manager |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4467 | values = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4468 | } |
| 4469 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4470 | if (mWindowManager != null) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4471 | final Message msg = PooledLambda.obtainMessage( |
| 4472 | ActivityManagerInternal::updateOomLevelsForDisplay, mAmInternal, |
| 4473 | DEFAULT_DISPLAY); |
| 4474 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4475 | } |
| 4476 | |
| 4477 | final long origId = Binder.clearCallingIdentity(); |
| 4478 | try { |
| 4479 | if (values != null) { |
| 4480 | Settings.System.clearConfiguration(values); |
| 4481 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4482 | updateConfigurationLocked(values, null, false, false /* persistent */, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4483 | UserHandle.USER_NULL, false /* deferResume */, |
| 4484 | mTmpUpdateConfigurationResult); |
| 4485 | return mTmpUpdateConfigurationResult.changes != 0; |
| 4486 | } finally { |
| 4487 | Binder.restoreCallingIdentity(origId); |
| 4488 | } |
| 4489 | } |
| 4490 | } |
| 4491 | |
| 4492 | @Override |
| 4493 | public void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback, |
| 4494 | CharSequence message) { |
| 4495 | if (message != null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4496 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4497 | Manifest.permission.SHOW_KEYGUARD_MESSAGE, "dismissKeyguard()"); |
| 4498 | } |
| 4499 | final long callingId = Binder.clearCallingIdentity(); |
| 4500 | try { |
| 4501 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4502 | mKeyguardController.dismissKeyguard(token, callback, message); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4503 | } |
| 4504 | } finally { |
| 4505 | Binder.restoreCallingIdentity(callingId); |
| 4506 | } |
| 4507 | } |
| 4508 | |
| 4509 | @Override |
| 4510 | public void cancelTaskWindowTransition(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4511 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4512 | "cancelTaskWindowTransition()"); |
| 4513 | final long ident = Binder.clearCallingIdentity(); |
| 4514 | try { |
| 4515 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4516 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4517 | MATCH_TASK_IN_STACKS_ONLY); |
| 4518 | if (task == null) { |
| 4519 | Slog.w(TAG, "cancelTaskWindowTransition: taskId=" + taskId + " not found"); |
| 4520 | return; |
| 4521 | } |
| 4522 | task.cancelWindowTransition(); |
| 4523 | } |
| 4524 | } finally { |
| 4525 | Binder.restoreCallingIdentity(ident); |
| 4526 | } |
| 4527 | } |
| 4528 | |
| 4529 | @Override |
| 4530 | public ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4531 | enforceCallerIsRecentsOrHasPermission(READ_FRAME_BUFFER, "getTaskSnapshot()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4532 | final long ident = Binder.clearCallingIdentity(); |
| 4533 | try { |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4534 | return getTaskSnapshot(taskId, reducedResolution, true /* restoreFromDisk */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4535 | } finally { |
| 4536 | Binder.restoreCallingIdentity(ident); |
| 4537 | } |
| 4538 | } |
| 4539 | |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 4540 | private ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution, |
| 4541 | boolean restoreFromDisk) { |
| 4542 | final TaskRecord task; |
| 4543 | synchronized (mGlobalLock) { |
| 4544 | task = mRootActivityContainer.anyTaskForId(taskId, |
| 4545 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 4546 | if (task == null) { |
| 4547 | Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found"); |
| 4548 | return null; |
| 4549 | } |
| 4550 | } |
| 4551 | // Don't call this while holding the lock as this operation might hit the disk. |
| 4552 | return task.getSnapshot(reducedResolution, restoreFromDisk); |
| 4553 | } |
| 4554 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4555 | @Override |
| 4556 | public void setDisablePreviewScreenshots(IBinder token, boolean disable) { |
| 4557 | synchronized (mGlobalLock) { |
| 4558 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4559 | if (r == null) { |
| 4560 | Slog.w(TAG, "setDisablePreviewScreenshots: Unable to find activity for token=" |
| 4561 | + token); |
| 4562 | return; |
| 4563 | } |
| 4564 | final long origId = Binder.clearCallingIdentity(); |
| 4565 | try { |
| 4566 | r.setDisablePreviewScreenshots(disable); |
| 4567 | } finally { |
| 4568 | Binder.restoreCallingIdentity(origId); |
| 4569 | } |
| 4570 | } |
| 4571 | } |
| 4572 | |
| 4573 | /** Return the user id of the last resumed activity. */ |
| 4574 | @Override |
| 4575 | public @UserIdInt |
| 4576 | int getLastResumedActivityUserId() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4577 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4578 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, "getLastResumedActivityUserId()"); |
| 4579 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4580 | if (mLastResumedActivity == null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4581 | return getCurrentUserId(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4582 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4583 | return mLastResumedActivity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4584 | } |
| 4585 | } |
| 4586 | |
| 4587 | @Override |
| 4588 | public void updateLockTaskFeatures(int userId, int flags) { |
| 4589 | final int callingUid = Binder.getCallingUid(); |
| 4590 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4591 | mAmInternal.enforceCallingPermission(android.Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4592 | "updateLockTaskFeatures()"); |
| 4593 | } |
| 4594 | synchronized (mGlobalLock) { |
| 4595 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Allowing features " + userId + ":0x" + |
| 4596 | Integer.toHexString(flags)); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 4597 | getLockTaskController().updateLockTaskFeatures(userId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4598 | } |
| 4599 | } |
| 4600 | |
| 4601 | @Override |
| 4602 | public void setShowWhenLocked(IBinder token, boolean showWhenLocked) { |
| 4603 | synchronized (mGlobalLock) { |
| 4604 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4605 | if (r == null) { |
| 4606 | return; |
| 4607 | } |
| 4608 | final long origId = Binder.clearCallingIdentity(); |
| 4609 | try { |
| 4610 | r.setShowWhenLocked(showWhenLocked); |
| 4611 | } finally { |
| 4612 | Binder.restoreCallingIdentity(origId); |
| 4613 | } |
| 4614 | } |
| 4615 | } |
| 4616 | |
| 4617 | @Override |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 4618 | public void setInheritShowWhenLocked(IBinder token, boolean inheritShowWhenLocked) { |
| 4619 | synchronized (mGlobalLock) { |
| 4620 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4621 | if (r == null) { |
| 4622 | return; |
| 4623 | } |
| 4624 | final long origId = Binder.clearCallingIdentity(); |
| 4625 | try { |
| 4626 | r.setInheritShowWhenLocked(inheritShowWhenLocked); |
| 4627 | } finally { |
| 4628 | Binder.restoreCallingIdentity(origId); |
| 4629 | } |
| 4630 | } |
| 4631 | } |
| 4632 | |
| 4633 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4634 | public void setTurnScreenOn(IBinder token, boolean turnScreenOn) { |
| 4635 | synchronized (mGlobalLock) { |
| 4636 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4637 | if (r == null) { |
| 4638 | return; |
| 4639 | } |
| 4640 | final long origId = Binder.clearCallingIdentity(); |
| 4641 | try { |
| 4642 | r.setTurnScreenOn(turnScreenOn); |
| 4643 | } finally { |
| 4644 | Binder.restoreCallingIdentity(origId); |
| 4645 | } |
| 4646 | } |
| 4647 | } |
| 4648 | |
| 4649 | @Override |
| 4650 | public void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4651 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4652 | "registerRemoteAnimations"); |
| 4653 | definition.setCallingPid(Binder.getCallingPid()); |
| 4654 | synchronized (mGlobalLock) { |
| 4655 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4656 | if (r == null) { |
| 4657 | return; |
| 4658 | } |
| 4659 | final long origId = Binder.clearCallingIdentity(); |
| 4660 | try { |
| 4661 | r.registerRemoteAnimations(definition); |
| 4662 | } finally { |
| 4663 | Binder.restoreCallingIdentity(origId); |
| 4664 | } |
| 4665 | } |
| 4666 | } |
| 4667 | |
| 4668 | @Override |
| 4669 | public void registerRemoteAnimationForNextActivityStart(String packageName, |
| 4670 | RemoteAnimationAdapter adapter) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4671 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4672 | "registerRemoteAnimationForNextActivityStart"); |
| 4673 | adapter.setCallingPid(Binder.getCallingPid()); |
| 4674 | synchronized (mGlobalLock) { |
| 4675 | final long origId = Binder.clearCallingIdentity(); |
| 4676 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4677 | getActivityStartController().registerRemoteAnimationForNextActivityStart( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4678 | packageName, adapter); |
| 4679 | } finally { |
| 4680 | Binder.restoreCallingIdentity(origId); |
| 4681 | } |
| 4682 | } |
| 4683 | } |
| 4684 | |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 4685 | @Override |
| 4686 | public void registerRemoteAnimationsForDisplay(int displayId, |
| 4687 | RemoteAnimationDefinition definition) { |
| 4688 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
| 4689 | "registerRemoteAnimations"); |
| 4690 | definition.setCallingPid(Binder.getCallingPid()); |
| 4691 | synchronized (mGlobalLock) { |
| 4692 | final ActivityDisplay display = mRootActivityContainer.getActivityDisplay(displayId); |
| 4693 | if (display == null) { |
| 4694 | Slog.e(TAG, "Couldn't find display with id: " + displayId); |
| 4695 | return; |
| 4696 | } |
| 4697 | final long origId = Binder.clearCallingIdentity(); |
| 4698 | try { |
| 4699 | display.mDisplayContent.registerRemoteAnimations(definition); |
| 4700 | } finally { |
| 4701 | Binder.restoreCallingIdentity(origId); |
| 4702 | } |
| 4703 | } |
| 4704 | } |
| 4705 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4706 | /** @see android.app.ActivityManager#alwaysShowUnsupportedCompileSdkWarning */ |
| 4707 | @Override |
| 4708 | public void alwaysShowUnsupportedCompileSdkWarning(ComponentName activity) { |
| 4709 | synchronized (mGlobalLock) { |
| 4710 | final long origId = Binder.clearCallingIdentity(); |
| 4711 | try { |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 4712 | mAppWarnings.alwaysShowUnsupportedCompileSdkWarning(activity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4713 | } finally { |
| 4714 | Binder.restoreCallingIdentity(origId); |
| 4715 | } |
| 4716 | } |
| 4717 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 4718 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4719 | @Override |
| 4720 | public void setVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4721 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4722 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4723 | final int pid = Binder.getCallingPid(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 4724 | final WindowProcessController wpc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4725 | mVrController.setVrThreadLocked(tid, pid, wpc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4726 | } |
| 4727 | } |
| 4728 | |
| 4729 | @Override |
| 4730 | public void setPersistentVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4731 | if (checkCallingPermission(Manifest.permission.RESTRICTED_VR_ACCESS) |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4732 | != PERMISSION_GRANTED) { |
| 4733 | final String msg = "Permission Denial: setPersistentVrThread() from pid=" |
| 4734 | + Binder.getCallingPid() |
| 4735 | + ", uid=" + Binder.getCallingUid() |
| 4736 | + " requires " + Manifest.permission.RESTRICTED_VR_ACCESS; |
| 4737 | Slog.w(TAG, msg); |
| 4738 | throw new SecurityException(msg); |
| 4739 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4740 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4741 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4742 | final int pid = Binder.getCallingPid(); |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 4743 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4744 | mVrController.setPersistentVrThreadLocked(tid, pid, proc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4745 | } |
| 4746 | } |
| 4747 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4748 | @Override |
| 4749 | public void stopAppSwitches() { |
| 4750 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "stopAppSwitches"); |
| 4751 | synchronized (mGlobalLock) { |
| 4752 | mAppSwitchesAllowedTime = SystemClock.uptimeMillis() + APP_SWITCH_DELAY_TIME; |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 4753 | mLastStopAppSwitchesTime = SystemClock.uptimeMillis(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4754 | mDidAppSwitch = false; |
| 4755 | getActivityStartController().schedulePendingActivityLaunches(APP_SWITCH_DELAY_TIME); |
| 4756 | } |
| 4757 | } |
| 4758 | |
| 4759 | @Override |
| 4760 | public void resumeAppSwitches() { |
| 4761 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "resumeAppSwitches"); |
| 4762 | synchronized (mGlobalLock) { |
| 4763 | // Note that we don't execute any pending app switches... we will |
| 4764 | // let those wait until either the timeout, or the next start |
| 4765 | // activity request. |
| 4766 | mAppSwitchesAllowedTime = 0; |
| 4767 | } |
| 4768 | } |
| 4769 | |
Ricky Wai | 906af48 | 2019-06-03 17:25:28 +0100 | [diff] [blame] | 4770 | long getLastStopAppSwitchesTime() { |
| 4771 | return mLastStopAppSwitchesTime; |
| 4772 | } |
| 4773 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4774 | void onStartActivitySetDidAppSwitch() { |
| 4775 | if (mDidAppSwitch) { |
| 4776 | // This is the second allowed switch since we stopped switches, so now just generally |
| 4777 | // allow switches. Use case: |
| 4778 | // - user presses home (switches disabled, switch to home, mDidAppSwitch now true); |
| 4779 | // - user taps a home icon (coming from home so allowed, we hit here and now allow |
| 4780 | // anyone to switch again). |
| 4781 | mAppSwitchesAllowedTime = 0; |
| 4782 | } else { |
| 4783 | mDidAppSwitch = true; |
| 4784 | } |
| 4785 | } |
| 4786 | |
| 4787 | /** @return whether the system should disable UI modes incompatible with VR mode. */ |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4788 | boolean shouldDisableNonVrUiLocked() { |
| 4789 | return mVrController.shouldDisableNonVrUiLocked(); |
| 4790 | } |
| 4791 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4792 | private void applyUpdateVrModeLocked(ActivityRecord r) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4793 | // 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] | 4794 | // 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] | 4795 | if (r.requestedVrComponent != null && r.getDisplayId() != DEFAULT_DISPLAY) { |
Wale Ogunwale | b8e6b63 | 2019-06-28 15:19:25 +0000 | [diff] [blame] | 4796 | Slog.i(TAG, "Moving " + r.shortComponentName + " from display " + r.getDisplayId() |
| 4797 | + " to main display for VR"); |
| 4798 | mRootActivityContainer.moveStackToDisplay( |
| 4799 | r.getStackId(), DEFAULT_DISPLAY, true /* toTop */); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4800 | } |
| 4801 | mH.post(() -> { |
| 4802 | if (!mVrController.onVrModeChanged(r)) { |
| 4803 | return; |
| 4804 | } |
| 4805 | synchronized (mGlobalLock) { |
| 4806 | final boolean disableNonVrUi = mVrController.shouldDisableNonVrUiLocked(); |
| 4807 | mWindowManager.disableNonVrUi(disableNonVrUi); |
| 4808 | if (disableNonVrUi) { |
| 4809 | // If we are in a VR mode where Picture-in-Picture mode is unsupported, |
| 4810 | // then remove the pinned stack. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4811 | mRootActivityContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4812 | } |
| 4813 | } |
| 4814 | }); |
| 4815 | } |
| 4816 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4817 | @Override |
| 4818 | public int getPackageScreenCompatMode(String packageName) { |
| 4819 | enforceNotIsolatedCaller("getPackageScreenCompatMode"); |
| 4820 | synchronized (mGlobalLock) { |
| 4821 | return mCompatModePackages.getPackageScreenCompatModeLocked(packageName); |
| 4822 | } |
| 4823 | } |
| 4824 | |
| 4825 | @Override |
| 4826 | public void setPackageScreenCompatMode(String packageName, int mode) { |
| 4827 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4828 | "setPackageScreenCompatMode"); |
| 4829 | synchronized (mGlobalLock) { |
| 4830 | mCompatModePackages.setPackageScreenCompatModeLocked(packageName, mode); |
| 4831 | } |
| 4832 | } |
| 4833 | |
| 4834 | @Override |
| 4835 | public boolean getPackageAskScreenCompat(String packageName) { |
| 4836 | enforceNotIsolatedCaller("getPackageAskScreenCompat"); |
| 4837 | synchronized (mGlobalLock) { |
| 4838 | return mCompatModePackages.getPackageAskCompatModeLocked(packageName); |
| 4839 | } |
| 4840 | } |
| 4841 | |
| 4842 | @Override |
| 4843 | public void setPackageAskScreenCompat(String packageName, boolean ask) { |
| 4844 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4845 | "setPackageAskScreenCompat"); |
| 4846 | synchronized (mGlobalLock) { |
| 4847 | mCompatModePackages.setPackageAskCompatModeLocked(packageName, ask); |
| 4848 | } |
| 4849 | } |
| 4850 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 4851 | public static String relaunchReasonToString(int relaunchReason) { |
| 4852 | switch (relaunchReason) { |
| 4853 | case RELAUNCH_REASON_WINDOWING_MODE_RESIZE: |
| 4854 | return "window_resize"; |
| 4855 | case RELAUNCH_REASON_FREE_RESIZE: |
| 4856 | return "free_resize"; |
| 4857 | default: |
| 4858 | return null; |
| 4859 | } |
| 4860 | } |
| 4861 | |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4862 | ActivityStack getTopDisplayFocusedStack() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4863 | return mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4864 | } |
| 4865 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4866 | /** Pokes the task persister. */ |
| 4867 | void notifyTaskPersisterLocked(TaskRecord task, boolean flush) { |
| 4868 | mRecentTasks.notifyTaskPersisterLocked(task, flush); |
| 4869 | } |
| 4870 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4871 | boolean isKeyguardLocked() { |
| 4872 | return mKeyguardController.isKeyguardLocked(); |
| 4873 | } |
| 4874 | |
Garfield Tan | 0154863 | 2018-11-27 10:15:48 -0800 | [diff] [blame] | 4875 | /** |
| 4876 | * Clears launch params for the given package. |
| 4877 | * @param packageNames the names of the packages of which the launch params are to be cleared |
| 4878 | */ |
| 4879 | @Override |
| 4880 | public void clearLaunchParamsForPackages(List<String> packageNames) { |
| 4881 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4882 | "clearLaunchParamsForPackages"); |
| 4883 | synchronized (mGlobalLock) { |
| 4884 | for (int i = 0; i < packageNames.size(); ++i) { |
| 4885 | mStackSupervisor.mLaunchParamsPersister.removeRecordForPackage(packageNames.get(i)); |
| 4886 | } |
| 4887 | } |
| 4888 | } |
| 4889 | |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 4890 | /** |
| 4891 | * Makes the display with the given id a single task instance display. I.e the display can only |
| 4892 | * contain one task. |
| 4893 | */ |
| 4894 | @Override |
| 4895 | public void setDisplayToSingleTaskInstance(int displayId) { |
| 4896 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4897 | "setDisplayToSingleTaskInstance"); |
| 4898 | final long origId = Binder.clearCallingIdentity(); |
| 4899 | try { |
| 4900 | final ActivityDisplay display = |
| 4901 | mRootActivityContainer.getActivityDisplayOrCreate(displayId); |
| 4902 | if (display != null) { |
| 4903 | display.setDisplayToSingleTaskInstance(); |
| 4904 | } |
| 4905 | } finally { |
| 4906 | Binder.restoreCallingIdentity(origId); |
| 4907 | } |
| 4908 | } |
| 4909 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4910 | void dumpLastANRLocked(PrintWriter pw) { |
| 4911 | pw.println("ACTIVITY MANAGER LAST ANR (dumpsys activity lastanr)"); |
| 4912 | if (mLastANRState == null) { |
| 4913 | pw.println(" <no ANR has occurred since boot>"); |
| 4914 | } else { |
| 4915 | pw.println(mLastANRState); |
| 4916 | } |
| 4917 | } |
| 4918 | |
| 4919 | void dumpLastANRTracesLocked(PrintWriter pw) { |
| 4920 | pw.println("ACTIVITY MANAGER LAST ANR TRACES (dumpsys activity lastanr-traces)"); |
| 4921 | |
| 4922 | final File[] files = new File(ANR_TRACE_DIR).listFiles(); |
| 4923 | if (ArrayUtils.isEmpty(files)) { |
| 4924 | pw.println(" <no ANR has occurred since boot>"); |
| 4925 | return; |
| 4926 | } |
| 4927 | // Find the latest file. |
| 4928 | File latest = null; |
| 4929 | for (File f : files) { |
| 4930 | if ((latest == null) || (latest.lastModified() < f.lastModified())) { |
| 4931 | latest = f; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4932 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4933 | } |
| 4934 | pw.print("File: "); |
| 4935 | pw.print(latest.getName()); |
| 4936 | pw.println(); |
| 4937 | try (BufferedReader in = new BufferedReader(new FileReader(latest))) { |
| 4938 | String line; |
| 4939 | while ((line = in.readLine()) != null) { |
| 4940 | pw.println(line); |
| 4941 | } |
| 4942 | } catch (IOException e) { |
| 4943 | pw.print("Unable to read: "); |
| 4944 | pw.print(e); |
| 4945 | pw.println(); |
| 4946 | } |
| 4947 | } |
| 4948 | |
| 4949 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4950 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 4951 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage, |
| 4952 | "ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)"); |
| 4953 | } |
| 4954 | |
| 4955 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4956 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage, String header) { |
| 4957 | pw.println(header); |
| 4958 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4959 | boolean printedAnything = mRootActivityContainer.dumpActivities(fd, pw, dumpAll, dumpClient, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4960 | dumpPackage); |
| 4961 | boolean needSep = printedAnything; |
| 4962 | |
| 4963 | boolean printed = ActivityStackSupervisor.printThisActivity(pw, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4964 | mRootActivityContainer.getTopResumedActivity(), dumpPackage, needSep, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4965 | " ResumedActivity: "); |
| 4966 | if (printed) { |
| 4967 | printedAnything = true; |
| 4968 | needSep = false; |
| 4969 | } |
| 4970 | |
| 4971 | if (dumpPackage == null) { |
| 4972 | if (needSep) { |
| 4973 | pw.println(); |
| 4974 | } |
| 4975 | printedAnything = true; |
| 4976 | mStackSupervisor.dump(pw, " "); |
| 4977 | } |
| 4978 | |
| 4979 | if (!printedAnything) { |
| 4980 | pw.println(" (nothing)"); |
| 4981 | } |
| 4982 | } |
| 4983 | |
| 4984 | void dumpActivityContainersLocked(PrintWriter pw) { |
| 4985 | pw.println("ACTIVITY MANAGER STARTER (dumpsys activity containers)"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4986 | mRootActivityContainer.dumpChildrenNames(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4987 | pw.println(" "); |
| 4988 | } |
| 4989 | |
| 4990 | void dumpActivityStarterLocked(PrintWriter pw, String dumpPackage) { |
| 4991 | pw.println("ACTIVITY MANAGER STARTER (dumpsys activity starter)"); |
| 4992 | getActivityStartController().dump(pw, "", dumpPackage); |
| 4993 | } |
| 4994 | |
| 4995 | /** |
| 4996 | * There are three things that cmd can be: |
| 4997 | * - a flattened component name that matches an existing activity |
| 4998 | * - the cmd arg isn't the flattened component name of an existing activity: |
| 4999 | * dump all activity whose component contains the cmd as a substring |
| 5000 | * - A hex number of the ActivityRecord object instance. |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5001 | * <p> |
| 5002 | * The caller should not hold lock when calling this method because it will wait for the |
| 5003 | * activities to complete the dump. |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5004 | * |
| 5005 | * @param dumpVisibleStacksOnly dump activity with {@param name} only if in a visible stack |
| 5006 | * @param dumpFocusedStackOnly dump activity with {@param name} only if in the focused stack |
| 5007 | */ |
| 5008 | protected boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, String[] args, |
| 5009 | int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, boolean dumpFocusedStackOnly) { |
| 5010 | ArrayList<ActivityRecord> activities; |
| 5011 | |
| 5012 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5013 | activities = mRootActivityContainer.getDumpActivities(name, dumpVisibleStacksOnly, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5014 | dumpFocusedStackOnly); |
| 5015 | } |
| 5016 | |
| 5017 | if (activities.size() <= 0) { |
| 5018 | return false; |
| 5019 | } |
| 5020 | |
| 5021 | String[] newArgs = new String[args.length - opti]; |
| 5022 | System.arraycopy(args, opti, newArgs, 0, args.length - opti); |
| 5023 | |
| 5024 | TaskRecord lastTask = null; |
| 5025 | boolean needSep = false; |
| 5026 | for (int i = activities.size() - 1; i >= 0; i--) { |
| 5027 | ActivityRecord r = activities.get(i); |
| 5028 | if (needSep) { |
| 5029 | pw.println(); |
| 5030 | } |
| 5031 | needSep = true; |
| 5032 | synchronized (mGlobalLock) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5033 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5034 | if (lastTask != task) { |
| 5035 | lastTask = task; |
| 5036 | pw.print("TASK "); pw.print(lastTask.affinity); |
| 5037 | pw.print(" id="); pw.print(lastTask.taskId); |
| 5038 | pw.print(" userId="); pw.println(lastTask.userId); |
| 5039 | if (dumpAll) { |
| 5040 | lastTask.dump(pw, " "); |
| 5041 | } |
| 5042 | } |
| 5043 | } |
| 5044 | dumpActivity(" ", fd, pw, activities.get(i), newArgs, dumpAll); |
| 5045 | } |
| 5046 | return true; |
| 5047 | } |
| 5048 | |
| 5049 | /** |
| 5050 | * Invokes IApplicationThread.dumpActivity() on the thread of the specified activity if |
| 5051 | * there is a thread associated with the activity. |
| 5052 | */ |
| 5053 | private void dumpActivity(String prefix, FileDescriptor fd, PrintWriter pw, |
| 5054 | final ActivityRecord r, String[] args, boolean dumpAll) { |
| 5055 | String innerPrefix = prefix + " "; |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5056 | IApplicationThread appThread = null; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5057 | synchronized (mGlobalLock) { |
| 5058 | pw.print(prefix); pw.print("ACTIVITY "); pw.print(r.shortComponentName); |
| 5059 | pw.print(" "); pw.print(Integer.toHexString(System.identityHashCode(r))); |
| 5060 | pw.print(" pid="); |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5061 | if (r.hasProcess()) { |
| 5062 | pw.println(r.app.getPid()); |
| 5063 | appThread = r.app.getThread(); |
| 5064 | } else { |
| 5065 | pw.println("(not running)"); |
| 5066 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5067 | if (dumpAll) { |
| 5068 | r.dump(pw, innerPrefix); |
| 5069 | } |
| 5070 | } |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5071 | if (appThread != null) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5072 | // flush anything that is already in the PrintWriter since the thread is going |
| 5073 | // to write to the file descriptor directly |
| 5074 | pw.flush(); |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 5075 | try (TransferPipe tp = new TransferPipe()) { |
| 5076 | appThread.dumpActivity(tp.getWriteFd(), r.appToken, innerPrefix, args); |
| 5077 | tp.go(fd); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 5078 | } catch (IOException e) { |
| 5079 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 5080 | } catch (RemoteException e) { |
| 5081 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 5082 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5083 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5084 | } |
| 5085 | |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 5086 | private void writeSleepStateToProto(ProtoOutputStream proto, int wakeFullness, |
| 5087 | boolean testPssMode) { |
| 5088 | final long sleepToken = proto.start(ActivityManagerServiceDumpProcessesProto.SLEEP_STATUS); |
| 5089 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.WAKEFULNESS, |
| 5090 | PowerManagerInternal.wakefulnessToProtoEnum(wakeFullness)); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5091 | for (ActivityTaskManagerInternal.SleepToken st : mRootActivityContainer.mSleepTokens) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5092 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEP_TOKENS, |
| 5093 | st.toString()); |
| 5094 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5095 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEPING, mSleeping); |
| 5096 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SHUTTING_DOWN, |
| 5097 | mShuttingDown); |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 5098 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.TEST_PSS_MODE, |
| 5099 | testPssMode); |
| 5100 | proto.end(sleepToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5101 | } |
| 5102 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5103 | int getCurrentUserId() { |
| 5104 | return mAmInternal.getCurrentUserId(); |
| 5105 | } |
| 5106 | |
| 5107 | private void enforceNotIsolatedCaller(String caller) { |
| 5108 | if (UserHandle.isIsolated(Binder.getCallingUid())) { |
| 5109 | throw new SecurityException("Isolated process not allowed to call " + caller); |
| 5110 | } |
| 5111 | } |
| 5112 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5113 | public Configuration getConfiguration() { |
| 5114 | Configuration ci; |
| 5115 | synchronized(mGlobalLock) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 5116 | ci = new Configuration(getGlobalConfigurationForCallingPid()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5117 | ci.userSetLocale = false; |
| 5118 | } |
| 5119 | return ci; |
| 5120 | } |
| 5121 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5122 | /** |
| 5123 | * Current global configuration information. Contains general settings for the entire system, |
| 5124 | * also corresponds to the merged configuration of the default display. |
| 5125 | */ |
| 5126 | Configuration getGlobalConfiguration() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5127 | return mRootActivityContainer.getConfiguration(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5128 | } |
| 5129 | |
| 5130 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5131 | boolean initLocale) { |
| 5132 | return updateConfigurationLocked(values, starting, initLocale, false /* deferResume */); |
| 5133 | } |
| 5134 | |
| 5135 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5136 | boolean initLocale, boolean deferResume) { |
| 5137 | // pass UserHandle.USER_NULL as userId because we don't persist configuration for any user |
| 5138 | return updateConfigurationLocked(values, starting, initLocale, false /* persistent */, |
| 5139 | UserHandle.USER_NULL, deferResume); |
| 5140 | } |
| 5141 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 5142 | public void updatePersistentConfiguration(Configuration values, @UserIdInt int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5143 | final long origId = Binder.clearCallingIdentity(); |
| 5144 | try { |
| 5145 | synchronized (mGlobalLock) { |
| 5146 | updateConfigurationLocked(values, null, false, true, userId, |
| 5147 | false /* deferResume */); |
| 5148 | } |
| 5149 | } finally { |
| 5150 | Binder.restoreCallingIdentity(origId); |
| 5151 | } |
| 5152 | } |
| 5153 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5154 | private boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5155 | boolean initLocale, boolean persistent, int userId, boolean deferResume) { |
| 5156 | return updateConfigurationLocked(values, starting, initLocale, persistent, userId, |
| 5157 | deferResume, null /* result */); |
| 5158 | } |
| 5159 | |
| 5160 | /** |
| 5161 | * Do either or both things: (1) change the current configuration, and (2) |
| 5162 | * make sure the given activity is running with the (now) current |
| 5163 | * configuration. Returns true if the activity has been left running, or |
| 5164 | * false if <var>starting</var> is being destroyed to match the new |
| 5165 | * configuration. |
| 5166 | * |
| 5167 | * @param userId is only used when persistent parameter is set to true to persist configuration |
| 5168 | * for that particular user |
| 5169 | */ |
| 5170 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5171 | boolean initLocale, boolean persistent, int userId, boolean deferResume, |
| 5172 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 5173 | int changes = 0; |
| 5174 | boolean kept = true; |
| 5175 | |
| 5176 | if (mWindowManager != null) { |
| 5177 | mWindowManager.deferSurfaceLayout(); |
| 5178 | } |
| 5179 | try { |
| 5180 | if (values != null) { |
| 5181 | changes = updateGlobalConfigurationLocked(values, initLocale, persistent, userId, |
| 5182 | deferResume); |
| 5183 | } |
| 5184 | |
| 5185 | kept = ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 5186 | } finally { |
| 5187 | if (mWindowManager != null) { |
| 5188 | mWindowManager.continueSurfaceLayout(); |
| 5189 | } |
| 5190 | } |
| 5191 | |
| 5192 | if (result != null) { |
| 5193 | result.changes = changes; |
| 5194 | result.activityRelaunched = !kept; |
| 5195 | } |
| 5196 | return kept; |
| 5197 | } |
| 5198 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5199 | /** Update default (global) configuration and notify listeners about changes. */ |
| 5200 | private int updateGlobalConfigurationLocked(@NonNull Configuration values, boolean initLocale, |
| 5201 | boolean persistent, int userId, boolean deferResume) { |
| 5202 | mTempConfig.setTo(getGlobalConfiguration()); |
| 5203 | final int changes = mTempConfig.updateFrom(values); |
| 5204 | if (changes == 0) { |
| 5205 | // Since calling to Activity.setRequestedOrientation leads to freezing the window with |
| 5206 | // setting WindowManagerService.mWaitingForConfig to true, it is important that we call |
| 5207 | // performDisplayOverrideConfigUpdate in order to send the new display configuration |
| 5208 | // (even if there are no actual changes) to unfreeze the window. |
| 5209 | performDisplayOverrideConfigUpdate(values, deferResume, DEFAULT_DISPLAY); |
| 5210 | return 0; |
| 5211 | } |
| 5212 | |
| 5213 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.i(TAG_CONFIGURATION, |
| 5214 | "Updating global configuration to: " + values); |
| 5215 | |
| 5216 | EventLog.writeEvent(EventLogTags.CONFIGURATION_CHANGED, changes); |
| 5217 | StatsLog.write(StatsLog.RESOURCE_CONFIGURATION_CHANGED, |
| 5218 | values.colorMode, |
| 5219 | values.densityDpi, |
| 5220 | values.fontScale, |
| 5221 | values.hardKeyboardHidden, |
| 5222 | values.keyboard, |
| 5223 | values.keyboardHidden, |
| 5224 | values.mcc, |
| 5225 | values.mnc, |
| 5226 | values.navigation, |
| 5227 | values.navigationHidden, |
| 5228 | values.orientation, |
| 5229 | values.screenHeightDp, |
| 5230 | values.screenLayout, |
| 5231 | values.screenWidthDp, |
| 5232 | values.smallestScreenWidthDp, |
| 5233 | values.touchscreen, |
| 5234 | values.uiMode); |
| 5235 | |
| 5236 | |
| 5237 | if (!initLocale && !values.getLocales().isEmpty() && values.userSetLocale) { |
| 5238 | final LocaleList locales = values.getLocales(); |
| 5239 | int bestLocaleIndex = 0; |
| 5240 | if (locales.size() > 1) { |
| 5241 | if (mSupportedSystemLocales == null) { |
| 5242 | mSupportedSystemLocales = Resources.getSystem().getAssets().getLocales(); |
| 5243 | } |
| 5244 | bestLocaleIndex = Math.max(0, locales.getFirstMatchIndex(mSupportedSystemLocales)); |
| 5245 | } |
| 5246 | SystemProperties.set("persist.sys.locale", |
| 5247 | locales.get(bestLocaleIndex).toLanguageTag()); |
| 5248 | LocaleList.setDefault(locales, bestLocaleIndex); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5249 | |
| 5250 | final Message m = PooledLambda.obtainMessage( |
| 5251 | ActivityTaskManagerService::sendLocaleToMountDaemonMsg, this, |
| 5252 | locales.get(bestLocaleIndex)); |
| 5253 | mH.sendMessage(m); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5254 | } |
| 5255 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 5256 | mTempConfig.seq = increaseConfigurationSeqLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5257 | |
| 5258 | // Update stored global config and notify everyone about the change. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5259 | mRootActivityContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5260 | |
| 5261 | Slog.i(TAG, "Config changes=" + Integer.toHexString(changes) + " " + mTempConfig); |
| 5262 | // TODO(multi-display): Update UsageEvents#Event to include displayId. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5263 | mUsageStatsInternal.reportConfigurationChange(mTempConfig, mAmInternal.getCurrentUserId()); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5264 | |
| 5265 | // 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] | 5266 | updateShouldShowDialogsLocked(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5267 | |
| 5268 | AttributeCache ac = AttributeCache.instance(); |
| 5269 | if (ac != null) { |
| 5270 | ac.updateConfiguration(mTempConfig); |
| 5271 | } |
| 5272 | |
| 5273 | // Make sure all resources in our process are updated right now, so that anyone who is going |
| 5274 | // to retrieve resource values after we return will be sure to get the new ones. This is |
| 5275 | // especially important during boot, where the first config change needs to guarantee all |
| 5276 | // resources have that config before following boot code is executed. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5277 | mSystemThread.applyConfigurationToResources(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5278 | |
| 5279 | // We need another copy of global config because we're scheduling some calls instead of |
| 5280 | // running them in place. We need to be sure that object we send will be handled unchanged. |
| 5281 | final Configuration configCopy = new Configuration(mTempConfig); |
| 5282 | if (persistent && Settings.System.hasInterestingConfigurationChanges(changes)) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5283 | final Message msg = PooledLambda.obtainMessage( |
| 5284 | ActivityTaskManagerService::sendPutConfigurationForUserMsg, |
| 5285 | this, userId, configCopy); |
| 5286 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5287 | } |
| 5288 | |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 5289 | SparseArray<WindowProcessController> pidMap = mProcessMap.getPidMap(); |
| 5290 | for (int i = pidMap.size() - 1; i >= 0; i--) { |
| 5291 | final int pid = pidMap.keyAt(i); |
| 5292 | final WindowProcessController app = pidMap.get(pid); |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 5293 | if (DEBUG_CONFIGURATION) { |
| 5294 | Slog.v(TAG_CONFIGURATION, "Update process config of " |
| 5295 | + app.mName + " to new config " + configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5296 | } |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 5297 | app.onConfigurationChanged(configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5298 | } |
| 5299 | |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 5300 | final Message msg = PooledLambda.obtainMessage( |
| 5301 | ActivityManagerInternal::broadcastGlobalConfigurationChanged, |
| 5302 | mAmInternal, changes, initLocale); |
| 5303 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5304 | |
| 5305 | // Override configuration of the default display duplicates global config, so we need to |
| 5306 | // update it also. This will also notify WindowManager about changes. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5307 | performDisplayOverrideConfigUpdate(mRootActivityContainer.getConfiguration(), deferResume, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5308 | DEFAULT_DISPLAY); |
| 5309 | |
| 5310 | return changes; |
| 5311 | } |
| 5312 | |
| 5313 | boolean updateDisplayOverrideConfigurationLocked(Configuration values, ActivityRecord starting, |
| 5314 | boolean deferResume, int displayId) { |
| 5315 | return updateDisplayOverrideConfigurationLocked(values, starting, deferResume /* deferResume */, |
| 5316 | displayId, null /* result */); |
| 5317 | } |
| 5318 | |
| 5319 | /** |
| 5320 | * Updates override configuration specific for the selected display. If no config is provided, |
| 5321 | * new one will be computed in WM based on current display info. |
| 5322 | */ |
| 5323 | boolean updateDisplayOverrideConfigurationLocked(Configuration values, |
| 5324 | ActivityRecord starting, boolean deferResume, int displayId, |
| 5325 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 5326 | int changes = 0; |
| 5327 | boolean kept = true; |
| 5328 | |
| 5329 | if (mWindowManager != null) { |
| 5330 | mWindowManager.deferSurfaceLayout(); |
| 5331 | } |
| 5332 | try { |
| 5333 | if (values != null) { |
| 5334 | if (displayId == DEFAULT_DISPLAY) { |
| 5335 | // Override configuration of the default display duplicates global config, so |
| 5336 | // we're calling global config update instead for default display. It will also |
| 5337 | // apply the correct override config. |
| 5338 | changes = updateGlobalConfigurationLocked(values, false /* initLocale */, |
| 5339 | false /* persistent */, UserHandle.USER_NULL /* userId */, deferResume); |
| 5340 | } else { |
| 5341 | changes = performDisplayOverrideConfigUpdate(values, deferResume, displayId); |
| 5342 | } |
| 5343 | } |
| 5344 | |
| 5345 | kept = ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 5346 | } finally { |
| 5347 | if (mWindowManager != null) { |
| 5348 | mWindowManager.continueSurfaceLayout(); |
| 5349 | } |
| 5350 | } |
| 5351 | |
| 5352 | if (result != null) { |
| 5353 | result.changes = changes; |
| 5354 | result.activityRelaunched = !kept; |
| 5355 | } |
| 5356 | return kept; |
| 5357 | } |
| 5358 | |
| 5359 | private int performDisplayOverrideConfigUpdate(Configuration values, boolean deferResume, |
| 5360 | int displayId) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5361 | mTempConfig.setTo(mRootActivityContainer.getDisplayOverrideConfiguration(displayId)); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5362 | final int changes = mTempConfig.updateFrom(values); |
| 5363 | if (changes != 0) { |
| 5364 | Slog.i(TAG, "Override config changes=" + Integer.toHexString(changes) + " " |
| 5365 | + mTempConfig + " for displayId=" + displayId); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5366 | mRootActivityContainer.setDisplayOverrideConfiguration(mTempConfig, displayId); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5367 | |
| 5368 | final boolean isDensityChange = (changes & ActivityInfo.CONFIG_DENSITY) != 0; |
| 5369 | if (isDensityChange && displayId == DEFAULT_DISPLAY) { |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 5370 | mAppWarnings.onDensityChanged(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5371 | |
Wale Ogunwale | 5c91870 | 2018-10-18 11:06:33 -0700 | [diff] [blame] | 5372 | // Post message to start process to avoid possible deadlock of calling into AMS with |
| 5373 | // the ATMS lock held. |
| 5374 | final Message msg = PooledLambda.obtainMessage( |
| 5375 | ActivityManagerInternal::killAllBackgroundProcessesExcept, mAmInternal, |
Riddle Hsu | aec5544 | 2019-03-12 17:25:35 +0800 | [diff] [blame] | 5376 | N, ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND); |
Wale Ogunwale | 5c91870 | 2018-10-18 11:06:33 -0700 | [diff] [blame] | 5377 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5378 | } |
| 5379 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5380 | return changes; |
| 5381 | } |
| 5382 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5383 | private void updateEventDispatchingLocked(boolean booted) { |
| 5384 | mWindowManager.setEventDispatching(booted && !mShuttingDown); |
| 5385 | } |
| 5386 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5387 | private void sendPutConfigurationForUserMsg(int userId, Configuration config) { |
| 5388 | final ContentResolver resolver = mContext.getContentResolver(); |
| 5389 | Settings.System.putConfigurationForUser(resolver, config, userId); |
| 5390 | } |
| 5391 | |
| 5392 | private void sendLocaleToMountDaemonMsg(Locale l) { |
| 5393 | try { |
| 5394 | IBinder service = ServiceManager.getService("mount"); |
| 5395 | IStorageManager storageManager = IStorageManager.Stub.asInterface(service); |
| 5396 | Log.d(TAG, "Storing locale " + l.toLanguageTag() + " for decryption UI"); |
| 5397 | storageManager.setField(StorageManager.SYSTEM_LOCALE_KEY, l.toLanguageTag()); |
| 5398 | } catch (RemoteException e) { |
| 5399 | Log.e(TAG, "Error storing locale for decryption UI", e); |
| 5400 | } |
| 5401 | } |
| 5402 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5403 | private void expireStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5404 | mStartActivitySources.remove(permissionToken); |
| 5405 | mExpiredStartAsCallerTokens.add(permissionToken); |
| 5406 | } |
| 5407 | |
| 5408 | private void forgetStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5409 | mExpiredStartAsCallerTokens.remove(permissionToken); |
| 5410 | } |
| 5411 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5412 | boolean isActivityStartsLoggingEnabled() { |
| 5413 | return mAmInternal.isActivityStartsLoggingEnabled(); |
| 5414 | } |
| 5415 | |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 5416 | boolean isBackgroundActivityStartsEnabled() { |
| 5417 | return mAmInternal.isBackgroundActivityStartsEnabled(); |
| 5418 | } |
| 5419 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5420 | void enableScreenAfterBoot(boolean booted) { |
| 5421 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_ENABLE_SCREEN, |
| 5422 | SystemClock.uptimeMillis()); |
| 5423 | mWindowManager.enableScreenAfterBoot(); |
| 5424 | |
| 5425 | synchronized (mGlobalLock) { |
| 5426 | updateEventDispatchingLocked(booted); |
| 5427 | } |
| 5428 | } |
| 5429 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5430 | static long getInputDispatchingTimeoutLocked(ActivityRecord r) { |
| 5431 | if (r == null || !r.hasProcess()) { |
| 5432 | return KEY_DISPATCHING_TIMEOUT_MS; |
| 5433 | } |
| 5434 | return getInputDispatchingTimeoutLocked(r.app); |
| 5435 | } |
| 5436 | |
| 5437 | private static long getInputDispatchingTimeoutLocked(WindowProcessController r) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 5438 | return r != null ? r.getInputDispatchingTimeout() : KEY_DISPATCHING_TIMEOUT_MS; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5439 | } |
| 5440 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5441 | /** |
| 5442 | * Decide based on the configuration whether we should show the ANR, |
| 5443 | * crash, etc dialogs. The idea is that if there is no affordance to |
| 5444 | * press the on-screen buttons, or the user experience would be more |
| 5445 | * greatly impacted than the crash itself, we shouldn't show the dialog. |
| 5446 | * |
| 5447 | * A thought: SystemUI might also want to get told about this, the Power |
| 5448 | * dialog / global actions also might want different behaviors. |
| 5449 | */ |
| 5450 | private void updateShouldShowDialogsLocked(Configuration config) { |
| 5451 | final boolean inputMethodExists = !(config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 5452 | && config.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH |
| 5453 | && config.navigation == Configuration.NAVIGATION_NONAV); |
| 5454 | int modeType = config.uiMode & Configuration.UI_MODE_TYPE_MASK; |
| 5455 | final boolean uiModeSupportsDialogs = (modeType != Configuration.UI_MODE_TYPE_CAR |
| 5456 | && !(modeType == Configuration.UI_MODE_TYPE_WATCH && Build.IS_USER) |
| 5457 | && modeType != Configuration.UI_MODE_TYPE_TELEVISION |
| 5458 | && modeType != Configuration.UI_MODE_TYPE_VR_HEADSET); |
| 5459 | final boolean hideDialogsSet = Settings.Global.getInt(mContext.getContentResolver(), |
| 5460 | HIDE_ERROR_DIALOGS, 0) != 0; |
| 5461 | mShowDialogs = inputMethodExists && uiModeSupportsDialogs && !hideDialogsSet; |
| 5462 | } |
| 5463 | |
| 5464 | private void updateFontScaleIfNeeded(@UserIdInt int userId) { |
| 5465 | final float scaleFactor = Settings.System.getFloatForUser(mContext.getContentResolver(), |
| 5466 | FONT_SCALE, 1.0f, userId); |
| 5467 | |
| 5468 | synchronized (this) { |
| 5469 | if (getGlobalConfiguration().fontScale == scaleFactor) { |
| 5470 | return; |
| 5471 | } |
| 5472 | |
| 5473 | final Configuration configuration |
| 5474 | = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
| 5475 | configuration.fontScale = scaleFactor; |
| 5476 | updatePersistentConfiguration(configuration, userId); |
| 5477 | } |
| 5478 | } |
| 5479 | |
| 5480 | // Actually is sleeping or shutting down or whatever else in the future |
| 5481 | // is an inactive state. |
| 5482 | boolean isSleepingOrShuttingDownLocked() { |
| 5483 | return isSleepingLocked() || mShuttingDown; |
| 5484 | } |
| 5485 | |
| 5486 | boolean isSleepingLocked() { |
| 5487 | return mSleeping; |
| 5488 | } |
| 5489 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5490 | /** Update AMS states when an activity is resumed. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5491 | void setResumedActivityUncheckLocked(ActivityRecord r, String reason) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5492 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5493 | if (task.isActivityTypeStandard()) { |
| 5494 | if (mCurAppTimeTracker != r.appTimeTracker) { |
| 5495 | // We are switching app tracking. Complete the current one. |
| 5496 | if (mCurAppTimeTracker != null) { |
| 5497 | mCurAppTimeTracker.stop(); |
| 5498 | mH.obtainMessage( |
| 5499 | REPORT_TIME_TRACKER_MSG, mCurAppTimeTracker).sendToTarget(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5500 | mRootActivityContainer.clearOtherAppTimeTrackers(r.appTimeTracker); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5501 | mCurAppTimeTracker = null; |
| 5502 | } |
| 5503 | if (r.appTimeTracker != null) { |
| 5504 | mCurAppTimeTracker = r.appTimeTracker; |
| 5505 | startTimeTrackingFocusedActivityLocked(); |
| 5506 | } |
| 5507 | } else { |
| 5508 | startTimeTrackingFocusedActivityLocked(); |
| 5509 | } |
| 5510 | } else { |
| 5511 | r.appTimeTracker = null; |
| 5512 | } |
| 5513 | // TODO: VI Maybe r.task.voiceInteractor || r.voiceInteractor != null |
| 5514 | // TODO: Probably not, because we don't want to resume voice on switching |
| 5515 | // back to this activity |
| 5516 | if (task.voiceInteractor != null) { |
| 5517 | startRunningVoiceLocked(task.voiceSession, r.info.applicationInfo.uid); |
| 5518 | } else { |
| 5519 | finishRunningVoiceLocked(); |
| 5520 | |
| 5521 | if (mLastResumedActivity != null) { |
| 5522 | final IVoiceInteractionSession session; |
| 5523 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5524 | final TaskRecord lastResumedActivityTask = mLastResumedActivity.getTaskRecord(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5525 | if (lastResumedActivityTask != null |
| 5526 | && lastResumedActivityTask.voiceSession != null) { |
| 5527 | session = lastResumedActivityTask.voiceSession; |
| 5528 | } else { |
| 5529 | session = mLastResumedActivity.voiceSession; |
| 5530 | } |
| 5531 | |
| 5532 | if (session != null) { |
| 5533 | // We had been in a voice interaction session, but now focused has |
| 5534 | // move to something different. Just finish the session, we can't |
| 5535 | // return to it and retain the proper state and synchronization with |
| 5536 | // the voice interaction service. |
| 5537 | finishVoiceTask(session); |
| 5538 | } |
| 5539 | } |
| 5540 | } |
| 5541 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5542 | if (mLastResumedActivity != null && r.mUserId != mLastResumedActivity.mUserId) { |
| 5543 | mAmInternal.sendForegroundProfileChanged(r.mUserId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5544 | } |
| 5545 | updateResumedAppTrace(r); |
| 5546 | mLastResumedActivity = r; |
| 5547 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 5548 | r.getDisplay().setFocusedApp(r, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5549 | |
| 5550 | applyUpdateLockStateLocked(r); |
| 5551 | applyUpdateVrModeLocked(r); |
| 5552 | |
| 5553 | EventLogTags.writeAmSetResumedActivity( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5554 | r == null ? -1 : r.mUserId, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5555 | r == null ? "NULL" : r.shortComponentName, |
| 5556 | reason); |
| 5557 | } |
| 5558 | |
| 5559 | ActivityTaskManagerInternal.SleepToken acquireSleepToken(String tag, int displayId) { |
| 5560 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5561 | final ActivityTaskManagerInternal.SleepToken token = |
| 5562 | mRootActivityContainer.createSleepToken(tag, displayId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5563 | updateSleepIfNeededLocked(); |
| 5564 | return token; |
| 5565 | } |
| 5566 | } |
| 5567 | |
| 5568 | void updateSleepIfNeededLocked() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5569 | final boolean shouldSleep = !mRootActivityContainer.hasAwakeDisplay(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5570 | final boolean wasSleeping = mSleeping; |
| 5571 | boolean updateOomAdj = false; |
| 5572 | |
| 5573 | if (!shouldSleep) { |
| 5574 | // If wasSleeping is true, we need to wake up activity manager state from when |
| 5575 | // we started sleeping. In either case, we need to apply the sleep tokens, which |
| 5576 | // will wake up stacks or put them to sleep as appropriate. |
| 5577 | if (wasSleeping) { |
| 5578 | mSleeping = false; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 5579 | StatsLog.write(StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5580 | StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__AWAKE); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5581 | startTimeTrackingFocusedActivityLocked(); |
| 5582 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
Varun Shah | 98694fb | 2019-04-11 09:28:27 -0700 | [diff] [blame] | 5583 | Slog.d(TAG, "Top Process State changed to PROCESS_STATE_TOP"); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5584 | mStackSupervisor.comeOutOfSleepIfNeededLocked(); |
| 5585 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5586 | mRootActivityContainer.applySleepTokens(true /* applyToStacks */); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5587 | if (wasSleeping) { |
| 5588 | updateOomAdj = true; |
| 5589 | } |
| 5590 | } else if (!mSleeping && shouldSleep) { |
| 5591 | mSleeping = true; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 5592 | StatsLog.write(StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5593 | StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__ASLEEP); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5594 | if (mCurAppTimeTracker != null) { |
| 5595 | mCurAppTimeTracker.stop(); |
| 5596 | } |
| 5597 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP_SLEEPING; |
Varun Shah | 98694fb | 2019-04-11 09:28:27 -0700 | [diff] [blame] | 5598 | Slog.d(TAG, "Top Process State changed to PROCESS_STATE_TOP_SLEEPING"); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5599 | mStackSupervisor.goingToSleepLocked(); |
| 5600 | updateResumedAppTrace(null /* resumed */); |
| 5601 | updateOomAdj = true; |
| 5602 | } |
| 5603 | if (updateOomAdj) { |
| 5604 | mH.post(mAmInternal::updateOomAdj); |
| 5605 | } |
| 5606 | } |
| 5607 | |
| 5608 | void updateOomAdj() { |
| 5609 | mH.post(mAmInternal::updateOomAdj); |
| 5610 | } |
| 5611 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5612 | void updateCpuStats() { |
| 5613 | mH.post(mAmInternal::updateCpuStats); |
| 5614 | } |
| 5615 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5616 | void updateBatteryStats(ActivityRecord component, boolean resumed) { |
| 5617 | final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::updateBatteryStats, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5618 | mAmInternal, component.mActivityComponent, component.app.mUid, component.mUserId, |
| 5619 | resumed); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5620 | mH.sendMessage(m); |
| 5621 | } |
| 5622 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5623 | void updateActivityUsageStats(ActivityRecord activity, int event) { |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5624 | ComponentName taskRoot = null; |
| 5625 | final TaskRecord task = activity.getTaskRecord(); |
| 5626 | if (task != null) { |
| 5627 | final ActivityRecord rootActivity = task.getRootActivity(); |
| 5628 | if (rootActivity != null) { |
| 5629 | taskRoot = rootActivity.mActivityComponent; |
| 5630 | } |
| 5631 | } |
| 5632 | |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5633 | final Message m = PooledLambda.obtainMessage( |
| 5634 | ActivityManagerInternal::updateActivityUsageStats, mAmInternal, |
Michael Wachenschwanz | 0b4ab1f | 2019-01-07 13:59:10 -0800 | [diff] [blame] | 5635 | activity.mActivityComponent, activity.mUserId, event, activity.appToken, taskRoot); |
Hui Yu | 03d1240 | 2018-12-06 18:00:37 -0800 | [diff] [blame] | 5636 | mH.sendMessage(m); |
| 5637 | } |
| 5638 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5639 | void setBooting(boolean booting) { |
| 5640 | mAmInternal.setBooting(booting); |
| 5641 | } |
| 5642 | |
| 5643 | boolean isBooting() { |
| 5644 | return mAmInternal.isBooting(); |
| 5645 | } |
| 5646 | |
| 5647 | void setBooted(boolean booted) { |
| 5648 | mAmInternal.setBooted(booted); |
| 5649 | } |
| 5650 | |
| 5651 | boolean isBooted() { |
| 5652 | return mAmInternal.isBooted(); |
| 5653 | } |
| 5654 | |
| 5655 | void postFinishBooting(boolean finishBooting, boolean enableScreen) { |
| 5656 | mH.post(() -> { |
| 5657 | if (finishBooting) { |
| 5658 | mAmInternal.finishBooting(); |
| 5659 | } |
| 5660 | if (enableScreen) { |
| 5661 | mInternal.enableScreenAfterBoot(isBooted()); |
| 5662 | } |
| 5663 | }); |
| 5664 | } |
| 5665 | |
| 5666 | void setHeavyWeightProcess(ActivityRecord root) { |
| 5667 | mHeavyWeightProcess = root.app; |
| 5668 | final Message m = PooledLambda.obtainMessage( |
| 5669 | ActivityTaskManagerService::postHeavyWeightProcessNotification, this, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5670 | root.app, root.intent, root.mUserId); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5671 | mH.sendMessage(m); |
| 5672 | } |
| 5673 | |
| 5674 | void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
| 5675 | if (mHeavyWeightProcess == null || mHeavyWeightProcess != proc) { |
| 5676 | return; |
| 5677 | } |
| 5678 | |
| 5679 | mHeavyWeightProcess = null; |
| 5680 | final Message m = PooledLambda.obtainMessage( |
| 5681 | ActivityTaskManagerService::cancelHeavyWeightProcessNotification, this, |
| 5682 | proc.mUserId); |
| 5683 | mH.sendMessage(m); |
| 5684 | } |
| 5685 | |
| 5686 | private void cancelHeavyWeightProcessNotification(int userId) { |
| 5687 | final INotificationManager inm = NotificationManager.getService(); |
| 5688 | if (inm == null) { |
| 5689 | return; |
| 5690 | } |
| 5691 | try { |
| 5692 | inm.cancelNotificationWithTag("android", null, |
| 5693 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, userId); |
| 5694 | } catch (RuntimeException e) { |
| 5695 | Slog.w(TAG, "Error canceling notification for service", e); |
| 5696 | } catch (RemoteException e) { |
| 5697 | } |
| 5698 | |
| 5699 | } |
| 5700 | |
| 5701 | private void postHeavyWeightProcessNotification( |
| 5702 | WindowProcessController proc, Intent intent, int userId) { |
| 5703 | if (proc == null) { |
| 5704 | return; |
| 5705 | } |
| 5706 | |
| 5707 | final INotificationManager inm = NotificationManager.getService(); |
| 5708 | if (inm == null) { |
| 5709 | return; |
| 5710 | } |
| 5711 | |
| 5712 | try { |
| 5713 | Context context = mContext.createPackageContext(proc.mInfo.packageName, 0); |
| 5714 | String text = mContext.getString(R.string.heavy_weight_notification, |
| 5715 | context.getApplicationInfo().loadLabel(context.getPackageManager())); |
| 5716 | Notification notification = |
| 5717 | new Notification.Builder(context, |
| 5718 | SystemNotificationChannels.HEAVY_WEIGHT_APP) |
| 5719 | .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) |
| 5720 | .setWhen(0) |
| 5721 | .setOngoing(true) |
| 5722 | .setTicker(text) |
| 5723 | .setColor(mContext.getColor( |
| 5724 | com.android.internal.R.color.system_notification_accent_color)) |
| 5725 | .setContentTitle(text) |
| 5726 | .setContentText( |
| 5727 | mContext.getText(R.string.heavy_weight_notification_detail)) |
| 5728 | .setContentIntent(PendingIntent.getActivityAsUser(mContext, 0, |
| 5729 | intent, PendingIntent.FLAG_CANCEL_CURRENT, null, |
| 5730 | new UserHandle(userId))) |
| 5731 | .build(); |
| 5732 | try { |
| 5733 | inm.enqueueNotificationWithTag("android", "android", null, |
| 5734 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, notification, userId); |
| 5735 | } catch (RuntimeException e) { |
| 5736 | Slog.w(TAG, "Error showing notification for heavy-weight app", e); |
| 5737 | } catch (RemoteException e) { |
| 5738 | } |
| 5739 | } catch (PackageManager.NameNotFoundException e) { |
| 5740 | Slog.w(TAG, "Unable to create context for heavy notification", e); |
| 5741 | } |
| 5742 | |
| 5743 | } |
| 5744 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5745 | IIntentSender getIntentSenderLocked(int type, String packageName, int callingUid, int userId, |
| 5746 | IBinder token, String resultWho, int requestCode, Intent[] intents, |
| 5747 | String[] resolvedTypes, int flags, Bundle bOptions) { |
| 5748 | |
| 5749 | ActivityRecord activity = null; |
| 5750 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5751 | activity = ActivityRecord.isInStackLocked(token); |
| 5752 | if (activity == null) { |
| 5753 | Slog.w(TAG, "Failed createPendingResult: activity " + token + " not in any stack"); |
| 5754 | return null; |
| 5755 | } |
| 5756 | if (activity.finishing) { |
| 5757 | Slog.w(TAG, "Failed createPendingResult: activity " + activity + " is finishing"); |
| 5758 | return null; |
| 5759 | } |
| 5760 | } |
| 5761 | |
| 5762 | final PendingIntentRecord rec = mPendingIntentController.getIntentSender(type, packageName, |
| 5763 | callingUid, userId, token, resultWho, requestCode, intents, resolvedTypes, flags, |
| 5764 | bOptions); |
| 5765 | final boolean noCreate = (flags & PendingIntent.FLAG_NO_CREATE) != 0; |
| 5766 | if (noCreate) { |
| 5767 | return rec; |
| 5768 | } |
| 5769 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5770 | if (activity.pendingResults == null) { |
| 5771 | activity.pendingResults = new HashSet<>(); |
| 5772 | } |
| 5773 | activity.pendingResults.add(rec.ref); |
| 5774 | } |
| 5775 | return rec; |
| 5776 | } |
| 5777 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 5778 | // 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] | 5779 | private void startTimeTrackingFocusedActivityLocked() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5780 | final ActivityRecord resumedActivity = mRootActivityContainer.getTopResumedActivity(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5781 | if (!mSleeping && mCurAppTimeTracker != null && resumedActivity != null) { |
| 5782 | mCurAppTimeTracker.start(resumedActivity.packageName); |
| 5783 | } |
| 5784 | } |
| 5785 | |
| 5786 | private void updateResumedAppTrace(@Nullable ActivityRecord resumed) { |
| 5787 | if (mTracedResumedActivity != null) { |
| 5788 | Trace.asyncTraceEnd(TRACE_TAG_ACTIVITY_MANAGER, |
| 5789 | constructResumedTraceName(mTracedResumedActivity.packageName), 0); |
| 5790 | } |
| 5791 | if (resumed != null) { |
| 5792 | Trace.asyncTraceBegin(TRACE_TAG_ACTIVITY_MANAGER, |
| 5793 | constructResumedTraceName(resumed.packageName), 0); |
| 5794 | } |
| 5795 | mTracedResumedActivity = resumed; |
| 5796 | } |
| 5797 | |
| 5798 | private String constructResumedTraceName(String packageName) { |
| 5799 | return "focused app: " + packageName; |
| 5800 | } |
| 5801 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5802 | /** Applies latest configuration and/or visibility updates if needed. */ |
| 5803 | private boolean ensureConfigAndVisibilityAfterUpdate(ActivityRecord starting, int changes) { |
| 5804 | boolean kept = true; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5805 | final ActivityStack mainStack = mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5806 | // mainStack is null during startup. |
| 5807 | if (mainStack != null) { |
| 5808 | if (changes != 0 && starting == null) { |
| 5809 | // If the configuration changed, and the caller is not already |
| 5810 | // in the process of starting an activity, then find the top |
| 5811 | // activity to check if its configuration needs to change. |
| 5812 | starting = mainStack.topRunningActivityLocked(); |
| 5813 | } |
| 5814 | |
| 5815 | if (starting != null) { |
| 5816 | kept = starting.ensureActivityConfiguration(changes, |
| 5817 | false /* preserveWindow */); |
| 5818 | // And we need to make sure at this point that all other activities |
| 5819 | // are made visible with the correct configuration. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5820 | mRootActivityContainer.ensureActivitiesVisible(starting, changes, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5821 | !PRESERVE_WINDOWS); |
| 5822 | } |
| 5823 | } |
| 5824 | |
| 5825 | return kept; |
| 5826 | } |
| 5827 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5828 | void scheduleAppGcsLocked() { |
| 5829 | mH.post(() -> mAmInternal.scheduleAppGcs()); |
| 5830 | } |
| 5831 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5832 | CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) { |
| 5833 | return mCompatModePackages.compatibilityInfoForPackageLocked(ai); |
| 5834 | } |
| 5835 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5836 | /** |
| 5837 | * Returns the PackageManager. Used by classes hosted by {@link ActivityTaskManagerService}. The |
| 5838 | * PackageManager could be unavailable at construction time and therefore needs to be accessed |
| 5839 | * on demand. |
| 5840 | */ |
| 5841 | IPackageManager getPackageManager() { |
| 5842 | return AppGlobals.getPackageManager(); |
| 5843 | } |
| 5844 | |
| 5845 | PackageManagerInternal getPackageManagerInternalLocked() { |
| 5846 | if (mPmInternal == null) { |
| 5847 | mPmInternal = LocalServices.getService(PackageManagerInternal.class); |
| 5848 | } |
| 5849 | return mPmInternal; |
| 5850 | } |
| 5851 | |
Hai Zhang | f4da9be | 2019-05-01 13:46:06 +0800 | [diff] [blame] | 5852 | PermissionPolicyInternal getPermissionPolicyInternal() { |
| 5853 | if (mPermissionPolicyInternal == null) { |
| 5854 | mPermissionPolicyInternal = LocalServices.getService(PermissionPolicyInternal.class); |
| 5855 | } |
| 5856 | return mPermissionPolicyInternal; |
| 5857 | } |
| 5858 | |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 5859 | AppWarnings getAppWarningsLocked() { |
| 5860 | return mAppWarnings; |
| 5861 | } |
| 5862 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5863 | Intent getHomeIntent() { |
| 5864 | Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null); |
| 5865 | intent.setComponent(mTopComponent); |
| 5866 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5867 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5868 | intent.addCategory(Intent.CATEGORY_HOME); |
| 5869 | } |
| 5870 | return intent; |
| 5871 | } |
| 5872 | |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5873 | /** |
| 5874 | * Return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} to resolve secondary home |
| 5875 | * activities. |
| 5876 | * |
| 5877 | * @param preferredPackage Specify a preferred package name, otherwise use secondary home |
| 5878 | * component defined in config_secondaryHomeComponent. |
| 5879 | * @return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} |
| 5880 | */ |
| 5881 | Intent getSecondaryHomeIntent(String preferredPackage) { |
| 5882 | 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] | 5883 | final boolean useSystemProvidedLauncher = mContext.getResources().getBoolean( |
| 5884 | com.android.internal.R.bool.config_useSystemProvidedLauncherForSecondary); |
| 5885 | if (preferredPackage == null || useSystemProvidedLauncher) { |
| 5886 | // Using the component stored in config if no package name or forced. |
Chilun | 2ef71f7 | 2018-11-16 17:57:15 +0800 | [diff] [blame] | 5887 | final String secondaryHomeComponent = mContext.getResources().getString( |
| 5888 | com.android.internal.R.string.config_secondaryHomeComponent); |
| 5889 | intent.setComponent(ComponentName.unflattenFromString(secondaryHomeComponent)); |
| 5890 | } else { |
| 5891 | intent.setPackage(preferredPackage); |
| 5892 | } |
| 5893 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5894 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5895 | intent.addCategory(Intent.CATEGORY_SECONDARY_HOME); |
| 5896 | } |
| 5897 | return intent; |
| 5898 | } |
| 5899 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5900 | ApplicationInfo getAppInfoForUser(ApplicationInfo info, int userId) { |
| 5901 | if (info == null) return null; |
| 5902 | ApplicationInfo newInfo = new ApplicationInfo(info); |
| 5903 | newInfo.initForUser(userId); |
| 5904 | return newInfo; |
| 5905 | } |
| 5906 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 5907 | WindowProcessController getProcessController(String processName, int uid) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5908 | if (uid == SYSTEM_UID) { |
| 5909 | // The system gets to run in any process. If there are multiple processes with the same |
| 5910 | // uid, just pick the first (this should never happen). |
| 5911 | final SparseArray<WindowProcessController> procs = |
| 5912 | mProcessNames.getMap().get(processName); |
| 5913 | if (procs == null) return null; |
| 5914 | final int procCount = procs.size(); |
| 5915 | for (int i = 0; i < procCount; i++) { |
| 5916 | final int procUid = procs.keyAt(i); |
| 5917 | if (UserHandle.isApp(procUid) || !UserHandle.isSameUser(procUid, uid)) { |
| 5918 | // Don't use an app process or different user process for system component. |
| 5919 | continue; |
| 5920 | } |
| 5921 | return procs.valueAt(i); |
| 5922 | } |
| 5923 | } |
| 5924 | |
| 5925 | return mProcessNames.get(processName, uid); |
| 5926 | } |
| 5927 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5928 | WindowProcessController getProcessController(IApplicationThread thread) { |
| 5929 | if (thread == null) { |
| 5930 | return null; |
| 5931 | } |
| 5932 | |
| 5933 | final IBinder threadBinder = thread.asBinder(); |
| 5934 | final ArrayMap<String, SparseArray<WindowProcessController>> pmap = mProcessNames.getMap(); |
| 5935 | for (int i = pmap.size()-1; i >= 0; i--) { |
| 5936 | final SparseArray<WindowProcessController> procs = pmap.valueAt(i); |
| 5937 | for (int j = procs.size() - 1; j >= 0; j--) { |
| 5938 | final WindowProcessController proc = procs.valueAt(j); |
| 5939 | if (proc.hasThread() && proc.getThread().asBinder() == threadBinder) { |
| 5940 | return proc; |
| 5941 | } |
| 5942 | } |
| 5943 | } |
| 5944 | |
| 5945 | return null; |
| 5946 | } |
| 5947 | |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 5948 | WindowProcessController getProcessController(int pid, int uid) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 5949 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Yunfan Chen | 8546b21 | 2019-04-01 15:34:44 +0900 | [diff] [blame] | 5950 | if (proc == null) return null; |
| 5951 | if (UserHandle.isApp(uid) && proc.mUid == uid) { |
| 5952 | return proc; |
Michal Karpinski | 9cbb20b | 2019-02-05 17:31:50 +0000 | [diff] [blame] | 5953 | } |
| 5954 | return null; |
| 5955 | } |
| 5956 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 5957 | int getUidState(int uid) { |
| 5958 | return mActiveUids.getUidState(uid); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 5959 | } |
| 5960 | |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 5961 | boolean isUidForeground(int uid) { |
Alan Stokes | eea8d3e | 2019-04-10 17:37:25 +0100 | [diff] [blame] | 5962 | // A uid is considered to be foreground if it has a visible non-toast window. |
| 5963 | return mWindowManager.mRoot.isAnyNonToastWindowVisibleForUid(uid); |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 5964 | } |
| 5965 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 5966 | boolean isDeviceOwner(int uid) { |
| 5967 | return uid >= 0 && mDeviceOwnerUid == uid; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 5968 | } |
| 5969 | |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 5970 | void setDeviceOwnerUid(int uid) { |
| 5971 | mDeviceOwnerUid = uid; |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 5972 | } |
| 5973 | |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 5974 | /** |
| 5975 | * @return whitelist tag for a uid from mPendingTempWhitelist, null if not currently on |
| 5976 | * the whitelist |
| 5977 | */ |
| 5978 | String getPendingTempWhitelistTagForUidLocked(int uid) { |
| 5979 | return mPendingTempWhitelist.get(uid); |
| 5980 | } |
| 5981 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5982 | void logAppTooSlow(WindowProcessController app, long startTime, String msg) { |
| 5983 | if (true || Build.IS_USER) { |
| 5984 | return; |
| 5985 | } |
| 5986 | |
| 5987 | StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 5988 | StrictMode.allowThreadDiskWrites(); |
| 5989 | try { |
| 5990 | File tracesDir = new File("/data/anr"); |
| 5991 | File tracesFile = null; |
| 5992 | try { |
| 5993 | tracesFile = File.createTempFile("app_slow", null, tracesDir); |
| 5994 | |
| 5995 | StringBuilder sb = new StringBuilder(); |
| 5996 | Time tobj = new Time(); |
| 5997 | tobj.set(System.currentTimeMillis()); |
| 5998 | sb.append(tobj.format("%Y-%m-%d %H:%M:%S")); |
| 5999 | sb.append(": "); |
| 6000 | TimeUtils.formatDuration(SystemClock.uptimeMillis()-startTime, sb); |
| 6001 | sb.append(" since "); |
| 6002 | sb.append(msg); |
| 6003 | FileOutputStream fos = new FileOutputStream(tracesFile); |
| 6004 | fos.write(sb.toString().getBytes()); |
| 6005 | if (app == null) { |
| 6006 | fos.write("\n*** No application process!".getBytes()); |
| 6007 | } |
| 6008 | fos.close(); |
| 6009 | FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1); // -rw-rw-rw- |
| 6010 | } catch (IOException e) { |
| 6011 | Slog.w(TAG, "Unable to prepare slow app traces file: " + tracesFile, e); |
| 6012 | return; |
| 6013 | } |
| 6014 | |
| 6015 | if (app != null && app.getPid() > 0) { |
| 6016 | ArrayList<Integer> firstPids = new ArrayList<Integer>(); |
| 6017 | firstPids.add(app.getPid()); |
| 6018 | dumpStackTraces(tracesFile.getAbsolutePath(), firstPids, null, null); |
| 6019 | } |
| 6020 | |
| 6021 | File lastTracesFile = null; |
| 6022 | File curTracesFile = null; |
| 6023 | for (int i=9; i>=0; i--) { |
| 6024 | String name = String.format(Locale.US, "slow%02d.txt", i); |
| 6025 | curTracesFile = new File(tracesDir, name); |
| 6026 | if (curTracesFile.exists()) { |
| 6027 | if (lastTracesFile != null) { |
| 6028 | curTracesFile.renameTo(lastTracesFile); |
| 6029 | } else { |
| 6030 | curTracesFile.delete(); |
| 6031 | } |
| 6032 | } |
| 6033 | lastTracesFile = curTracesFile; |
| 6034 | } |
| 6035 | tracesFile.renameTo(curTracesFile); |
| 6036 | } finally { |
| 6037 | StrictMode.setThreadPolicy(oldPolicy); |
| 6038 | } |
| 6039 | } |
| 6040 | |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 6041 | boolean isAssociatedCompanionApp(int userId, int uid) { |
| 6042 | final Set<Integer> allUids = mCompanionAppUidsMap.get(userId); |
| 6043 | if (allUids == null) { |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 6044 | return false; |
| 6045 | } |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 6046 | return allUids.contains(uid); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 6047 | } |
| 6048 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6049 | final class H extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6050 | static final int REPORT_TIME_TRACKER_MSG = 1; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 6051 | |
| 6052 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 6053 | static final int FIRST_ACTIVITY_STACK_MSG = 100; |
| 6054 | static final int FIRST_SUPERVISOR_STACK_MSG = 200; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6055 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 6056 | H(Looper looper) { |
| 6057 | super(looper); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6058 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6059 | |
| 6060 | @Override |
| 6061 | public void handleMessage(Message msg) { |
| 6062 | switch (msg.what) { |
| 6063 | case REPORT_TIME_TRACKER_MSG: { |
| 6064 | AppTimeTracker tracker = (AppTimeTracker) msg.obj; |
| 6065 | tracker.deliverResult(mContext); |
| 6066 | } break; |
| 6067 | } |
| 6068 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6069 | } |
| 6070 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6071 | final class UiHandler extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6072 | static final int DISMISS_DIALOG_UI_MSG = 1; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6073 | |
| 6074 | public UiHandler() { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 6075 | super(UiThread.get().getLooper(), null, true); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6076 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6077 | |
| 6078 | @Override |
| 6079 | public void handleMessage(Message msg) { |
| 6080 | switch (msg.what) { |
| 6081 | case DISMISS_DIALOG_UI_MSG: { |
| 6082 | final Dialog d = (Dialog) msg.obj; |
| 6083 | d.dismiss(); |
| 6084 | break; |
| 6085 | } |
| 6086 | } |
| 6087 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6088 | } |
| 6089 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6090 | final class LocalService extends ActivityTaskManagerInternal { |
| 6091 | @Override |
| 6092 | public SleepToken acquireSleepToken(String tag, int displayId) { |
| 6093 | Preconditions.checkNotNull(tag); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6094 | return ActivityTaskManagerService.this.acquireSleepToken(tag, displayId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6095 | } |
| 6096 | |
| 6097 | @Override |
| 6098 | public ComponentName getHomeActivityForUser(int userId) { |
| 6099 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6100 | final ActivityRecord homeActivity = |
| 6101 | mRootActivityContainer.getDefaultDisplayHomeActivityForUser(userId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 6102 | return homeActivity == null ? null : homeActivity.mActivityComponent; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6103 | } |
| 6104 | } |
| 6105 | |
| 6106 | @Override |
| 6107 | public void onLocalVoiceInteractionStarted(IBinder activity, |
| 6108 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 6109 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6110 | onLocalVoiceInteractionStartedLocked(activity, voiceSession, voiceInteractor); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6111 | } |
| 6112 | } |
| 6113 | |
| 6114 | @Override |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 6115 | public void notifyAppTransitionStarting(SparseIntArray reasons, |
| 6116 | long timestamp) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6117 | synchronized (mGlobalLock) { |
| 6118 | mStackSupervisor.getActivityMetricsLogger().notifyTransitionStarting( |
| 6119 | reasons, timestamp); |
| 6120 | } |
| 6121 | } |
| 6122 | |
| 6123 | @Override |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 6124 | public void notifySingleTaskDisplayDrawn(int displayId) { |
| 6125 | mTaskChangeNotificationController.notifySingleTaskDisplayDrawn(displayId); |
| 6126 | } |
| 6127 | |
| 6128 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6129 | public void notifyAppTransitionFinished() { |
| 6130 | synchronized (mGlobalLock) { |
| 6131 | mStackSupervisor.notifyAppTransitionDone(); |
| 6132 | } |
| 6133 | } |
| 6134 | |
| 6135 | @Override |
| 6136 | public void notifyAppTransitionCancelled() { |
| 6137 | synchronized (mGlobalLock) { |
| 6138 | mStackSupervisor.notifyAppTransitionDone(); |
| 6139 | } |
| 6140 | } |
| 6141 | |
| 6142 | @Override |
| 6143 | public List<IBinder> getTopVisibleActivities() { |
| 6144 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6145 | return mRootActivityContainer.getTopVisibleActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6146 | } |
| 6147 | } |
| 6148 | |
| 6149 | @Override |
| 6150 | public void notifyDockedStackMinimizedChanged(boolean minimized) { |
| 6151 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6152 | mRootActivityContainer.setDockedStackMinimized(minimized); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6153 | } |
| 6154 | } |
| 6155 | |
| 6156 | @Override |
| 6157 | public int startActivitiesAsPackage(String packageName, int userId, Intent[] intents, |
| 6158 | Bundle bOptions) { |
| 6159 | Preconditions.checkNotNull(intents, "intents"); |
| 6160 | final String[] resolvedTypes = new String[intents.length]; |
| 6161 | |
| 6162 | // UID of the package on user userId. |
| 6163 | // "= 0" is needed because otherwise catch(RemoteException) would make it look like |
| 6164 | // packageUid may not be initialized. |
| 6165 | int packageUid = 0; |
| 6166 | final long ident = Binder.clearCallingIdentity(); |
| 6167 | |
| 6168 | try { |
| 6169 | for (int i = 0; i < intents.length; i++) { |
| 6170 | resolvedTypes[i] = |
| 6171 | intents[i].resolveTypeIfNeeded(mContext.getContentResolver()); |
| 6172 | } |
| 6173 | |
| 6174 | packageUid = AppGlobals.getPackageManager().getPackageUid( |
| 6175 | packageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId); |
| 6176 | } catch (RemoteException e) { |
| 6177 | // Shouldn't happen. |
| 6178 | } finally { |
| 6179 | Binder.restoreCallingIdentity(ident); |
| 6180 | } |
| 6181 | |
Riddle Hsu | 591bf61 | 2019-02-14 17:55:31 +0800 | [diff] [blame] | 6182 | return getActivityStartController().startActivitiesInPackage( |
| 6183 | packageUid, packageName, |
| 6184 | intents, resolvedTypes, null /* resultTo */, |
| 6185 | SafeActivityOptions.fromBundle(bOptions), userId, |
| 6186 | false /* validateIncomingUser */, null /* originatingPendingIntent */, |
| 6187 | false /* allowBackgroundActivityStart */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6188 | } |
| 6189 | |
| 6190 | @Override |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6191 | public int startActivitiesInPackage(int uid, int realCallingPid, int realCallingUid, |
| 6192 | String callingPackage, Intent[] intents, String[] resolvedTypes, IBinder resultTo, |
| 6193 | SafeActivityOptions options, int userId, boolean validateIncomingUser, |
| 6194 | PendingIntentRecord originatingPendingIntent, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6195 | boolean allowBackgroundActivityStart) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6196 | synchronized (mGlobalLock) { |
Michal Karpinski | 84d9ebd | 2019-01-17 18:28:59 +0000 | [diff] [blame] | 6197 | return getActivityStartController().startActivitiesInPackage(uid, realCallingPid, |
| 6198 | realCallingUid, callingPackage, intents, resolvedTypes, resultTo, options, |
| 6199 | userId, validateIncomingUser, originatingPendingIntent, |
| 6200 | allowBackgroundActivityStart); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6201 | } |
| 6202 | } |
| 6203 | |
| 6204 | @Override |
| 6205 | public int startActivityInPackage(int uid, int realCallingPid, int realCallingUid, |
| 6206 | String callingPackage, Intent intent, String resolvedType, IBinder resultTo, |
| 6207 | String resultWho, int requestCode, int startFlags, SafeActivityOptions options, |
| 6208 | int userId, TaskRecord inTask, String reason, boolean validateIncomingUser, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6209 | PendingIntentRecord originatingPendingIntent, |
| 6210 | boolean allowBackgroundActivityStart) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6211 | synchronized (mGlobalLock) { |
| 6212 | return getActivityStartController().startActivityInPackage(uid, realCallingPid, |
| 6213 | realCallingUid, callingPackage, intent, resolvedType, resultTo, resultWho, |
| 6214 | requestCode, startFlags, options, userId, inTask, reason, |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 6215 | validateIncomingUser, originatingPendingIntent, |
| 6216 | allowBackgroundActivityStart); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6217 | } |
| 6218 | } |
| 6219 | |
| 6220 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6221 | public int startActivityAsUser(IApplicationThread caller, String callerPacakge, |
| 6222 | Intent intent, Bundle options, int userId) { |
| 6223 | return ActivityTaskManagerService.this.startActivityAsUser( |
| 6224 | caller, callerPacakge, intent, |
| 6225 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 6226 | null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, options, userId, |
| 6227 | false /*validateIncomingUser*/); |
| 6228 | } |
| 6229 | |
| 6230 | @Override |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 6231 | public void notifyKeyguardFlagsChanged(@Nullable Runnable callback, int displayId) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6232 | synchronized (mGlobalLock) { |
| 6233 | |
| 6234 | // We might change the visibilities here, so prepare an empty app transition which |
| 6235 | // might be overridden later if we actually change visibilities. |
lumark | 52ea28e | 2018-11-09 17:30:47 +0800 | [diff] [blame] | 6236 | final ActivityDisplay activityDisplay = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6237 | mRootActivityContainer.getActivityDisplay(displayId); |
lumark | 52ea28e | 2018-11-09 17:30:47 +0800 | [diff] [blame] | 6238 | if (activityDisplay == null) { |
| 6239 | return; |
| 6240 | } |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6241 | final DisplayContent dc = activityDisplay.mDisplayContent; |
| 6242 | final boolean wasTransitionSet = |
| 6243 | dc.mAppTransition.getAppTransition() != TRANSIT_NONE; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6244 | if (!wasTransitionSet) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6245 | dc.prepareAppTransition(TRANSIT_NONE, false /* alwaysKeepCurrent */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6246 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6247 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6248 | |
| 6249 | // If there was a transition set already we don't want to interfere with it as we |
| 6250 | // might be starting it too early. |
| 6251 | if (!wasTransitionSet) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 6252 | dc.executeAppTransition(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6253 | } |
| 6254 | } |
| 6255 | if (callback != null) { |
| 6256 | callback.run(); |
| 6257 | } |
| 6258 | } |
| 6259 | |
| 6260 | @Override |
| 6261 | public void notifyKeyguardTrustedChanged() { |
| 6262 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6263 | if (mKeyguardController.isKeyguardShowing(DEFAULT_DISPLAY)) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6264 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6265 | } |
| 6266 | } |
| 6267 | } |
| 6268 | |
| 6269 | /** |
| 6270 | * Called after virtual display Id is updated by |
| 6271 | * {@link com.android.server.vr.Vr2dDisplay} with a specific |
| 6272 | * {@param vrVr2dDisplayId}. |
| 6273 | */ |
| 6274 | @Override |
| 6275 | public void setVr2dDisplayId(int vr2dDisplayId) { |
| 6276 | if (DEBUG_STACK) Slog.d(TAG, "setVr2dDisplayId called for: " + vr2dDisplayId); |
| 6277 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6278 | mVr2dDisplayId = vr2dDisplayId; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6279 | } |
| 6280 | } |
| 6281 | |
| 6282 | @Override |
| 6283 | public void setFocusedActivity(IBinder token) { |
| 6284 | synchronized (mGlobalLock) { |
| 6285 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 6286 | if (r == null) { |
| 6287 | throw new IllegalArgumentException( |
| 6288 | "setFocusedActivity: No activity record matching token=" + token); |
| 6289 | } |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 6290 | if (r.moveFocusableActivityToTop("setFocusedActivity")) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6291 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6292 | } |
| 6293 | } |
| 6294 | } |
| 6295 | |
| 6296 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6297 | public void registerScreenObserver(ScreenObserver observer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6298 | mScreenObservers.add(observer); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6299 | } |
| 6300 | |
| 6301 | @Override |
| 6302 | public boolean isCallerRecents(int callingUid) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 6303 | return getRecentTasks().isCallerRecents(callingUid); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6304 | } |
| 6305 | |
| 6306 | @Override |
| 6307 | public boolean isRecentsComponentHomeActivity(int userId) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 6308 | return getRecentTasks().isRecentsComponentHomeActivity(userId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6309 | } |
| 6310 | |
| 6311 | @Override |
| 6312 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
| 6313 | ActivityTaskManagerService.this.cancelRecentsAnimation(restoreHomeStackPosition); |
| 6314 | } |
| 6315 | |
| 6316 | @Override |
| 6317 | public void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6318 | ActivityTaskManagerService.this.enforceCallerIsRecentsOrHasPermission(permission, func); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6319 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 6320 | |
| 6321 | @Override |
| 6322 | public void notifyActiveVoiceInteractionServiceChanged(ComponentName component) { |
| 6323 | synchronized (mGlobalLock) { |
| 6324 | mActiveVoiceInteractionServiceComponent = component; |
| 6325 | } |
| 6326 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 6327 | |
| 6328 | @Override |
| 6329 | public void setAllowAppSwitches(@NonNull String type, int uid, int userId) { |
| 6330 | if (!mAmInternal.isUserRunning(userId, ActivityManager.FLAG_OR_STOPPED)) { |
| 6331 | return; |
| 6332 | } |
| 6333 | synchronized (mGlobalLock) { |
| 6334 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(userId); |
| 6335 | if (types == null) { |
| 6336 | if (uid < 0) { |
| 6337 | return; |
| 6338 | } |
| 6339 | types = new ArrayMap<>(); |
| 6340 | mAllowAppSwitchUids.put(userId, types); |
| 6341 | } |
| 6342 | if (uid < 0) { |
| 6343 | types.remove(type); |
| 6344 | } else { |
| 6345 | types.put(type, uid); |
| 6346 | } |
| 6347 | } |
| 6348 | } |
| 6349 | |
| 6350 | @Override |
| 6351 | public void onUserStopped(int userId) { |
| 6352 | synchronized (mGlobalLock) { |
| 6353 | getRecentTasks().unloadUserDataFromMemoryLocked(userId); |
| 6354 | mAllowAppSwitchUids.remove(userId); |
| 6355 | } |
| 6356 | } |
| 6357 | |
| 6358 | @Override |
| 6359 | public boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 6360 | synchronized (mGlobalLock) { |
| 6361 | return ActivityTaskManagerService.this.isGetTasksAllowed( |
| 6362 | caller, callingPid, callingUid); |
| 6363 | } |
| 6364 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6365 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6366 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6367 | @Override |
| 6368 | public void onProcessAdded(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6369 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6370 | mProcessNames.put(proc.mName, proc.mUid, proc); |
| 6371 | } |
| 6372 | } |
| 6373 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6374 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6375 | @Override |
| 6376 | public void onProcessRemoved(String name, int uid) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6377 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6378 | mProcessNames.remove(name, uid); |
| 6379 | } |
| 6380 | } |
| 6381 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6382 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6383 | @Override |
| 6384 | public void onCleanUpApplicationRecord(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6385 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 6386 | if (proc == mHomeProcess) { |
| 6387 | mHomeProcess = null; |
| 6388 | } |
| 6389 | if (proc == mPreviousProcess) { |
| 6390 | mPreviousProcess = null; |
| 6391 | } |
| 6392 | } |
| 6393 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6394 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6395 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6396 | @Override |
| 6397 | public int getTopProcessState() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6398 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6399 | return mTopProcessState; |
| 6400 | } |
| 6401 | } |
| 6402 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6403 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6404 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6405 | public boolean isHeavyWeightProcess(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6406 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6407 | return proc == mHeavyWeightProcess; |
| 6408 | } |
| 6409 | } |
| 6410 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6411 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6412 | @Override |
| 6413 | public void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6414 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6415 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals(proc); |
| 6416 | } |
| 6417 | } |
| 6418 | |
| 6419 | @Override |
| 6420 | public void finishHeavyWeightApp() { |
| 6421 | synchronized (mGlobalLock) { |
Sudheer Shanka | ee1da27 | 2018-10-20 20:11:44 -0700 | [diff] [blame] | 6422 | if (mHeavyWeightProcess != null) { |
| 6423 | mHeavyWeightProcess.finishActivities(); |
| 6424 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6425 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals( |
| 6426 | mHeavyWeightProcess); |
| 6427 | } |
| 6428 | } |
| 6429 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6430 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6431 | @Override |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6432 | public boolean isSleeping() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6433 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6434 | return isSleepingLocked(); |
| 6435 | } |
| 6436 | } |
| 6437 | |
| 6438 | @Override |
| 6439 | public boolean isShuttingDown() { |
| 6440 | synchronized (mGlobalLock) { |
| 6441 | return mShuttingDown; |
| 6442 | } |
| 6443 | } |
| 6444 | |
| 6445 | @Override |
| 6446 | public boolean shuttingDown(boolean booted, int timeout) { |
| 6447 | synchronized (mGlobalLock) { |
| 6448 | mShuttingDown = true; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6449 | mRootActivityContainer.prepareForShutdown(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6450 | updateEventDispatchingLocked(booted); |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 6451 | notifyTaskPersisterLocked(null, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 6452 | return mStackSupervisor.shutdownLocked(timeout); |
| 6453 | } |
| 6454 | } |
| 6455 | |
| 6456 | @Override |
| 6457 | public void enableScreenAfterBoot(boolean booted) { |
| 6458 | synchronized (mGlobalLock) { |
| 6459 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_ENABLE_SCREEN, |
| 6460 | SystemClock.uptimeMillis()); |
| 6461 | mWindowManager.enableScreenAfterBoot(); |
| 6462 | updateEventDispatchingLocked(booted); |
| 6463 | } |
| 6464 | } |
| 6465 | |
| 6466 | @Override |
| 6467 | public boolean showStrictModeViolationDialog() { |
| 6468 | synchronized (mGlobalLock) { |
| 6469 | return mShowDialogs && !mSleeping && !mShuttingDown; |
| 6470 | } |
| 6471 | } |
| 6472 | |
| 6473 | @Override |
| 6474 | public void showSystemReadyErrorDialogsIfNeeded() { |
| 6475 | synchronized (mGlobalLock) { |
| 6476 | try { |
| 6477 | if (AppGlobals.getPackageManager().hasSystemUidErrors()) { |
| 6478 | Slog.e(TAG, "UIDs on the system are inconsistent, you need to wipe your" |
| 6479 | + " data partition or your device will be unstable."); |
| 6480 | mUiHandler.post(() -> { |
| 6481 | if (mShowDialogs) { |
| 6482 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6483 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6484 | d.setCancelable(false); |
| 6485 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6486 | d.setMessage(mUiContext.getText(R.string.system_error_wipe_data)); |
| 6487 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6488 | mUiContext.getText(R.string.ok), |
| 6489 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6490 | d.show(); |
| 6491 | } |
| 6492 | }); |
| 6493 | } |
| 6494 | } catch (RemoteException e) { |
| 6495 | } |
| 6496 | |
| 6497 | if (!Build.isBuildConsistent()) { |
| 6498 | Slog.e(TAG, "Build fingerprint is not consistent, warning user"); |
| 6499 | mUiHandler.post(() -> { |
| 6500 | if (mShowDialogs) { |
| 6501 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6502 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6503 | d.setCancelable(false); |
| 6504 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6505 | d.setMessage(mUiContext.getText(R.string.system_error_manufacturer)); |
| 6506 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6507 | mUiContext.getText(R.string.ok), |
| 6508 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6509 | d.show(); |
| 6510 | } |
| 6511 | }); |
| 6512 | } |
| 6513 | } |
| 6514 | } |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6515 | |
| 6516 | @Override |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6517 | public void onProcessMapped(int pid, WindowProcessController proc) { |
| 6518 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6519 | mProcessMap.put(pid, proc); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6520 | } |
| 6521 | } |
| 6522 | |
| 6523 | @Override |
| 6524 | public void onProcessUnMapped(int pid) { |
| 6525 | synchronized (mGlobalLock) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6526 | mProcessMap.remove(pid); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6527 | } |
| 6528 | } |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6529 | |
| 6530 | @Override |
| 6531 | public void onPackageDataCleared(String name) { |
| 6532 | synchronized (mGlobalLock) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6533 | mCompatModePackages.handlePackageDataClearedLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6534 | mAppWarnings.onPackageDataCleared(name); |
| 6535 | } |
| 6536 | } |
| 6537 | |
| 6538 | @Override |
| 6539 | public void onPackageUninstalled(String name) { |
| 6540 | synchronized (mGlobalLock) { |
| 6541 | mAppWarnings.onPackageUninstalled(name); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6542 | mCompatModePackages.handlePackageUninstalledLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6543 | } |
| 6544 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6545 | |
| 6546 | @Override |
| 6547 | public void onPackageAdded(String name, boolean replacing) { |
| 6548 | synchronized (mGlobalLock) { |
| 6549 | mCompatModePackages.handlePackageAddedLocked(name, replacing); |
| 6550 | } |
| 6551 | } |
| 6552 | |
| 6553 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6554 | public void onPackageReplaced(ApplicationInfo aInfo) { |
| 6555 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6556 | mRootActivityContainer.updateActivityApplicationInfo(aInfo); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6557 | } |
| 6558 | } |
| 6559 | |
| 6560 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6561 | public CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai) { |
| 6562 | synchronized (mGlobalLock) { |
| 6563 | return compatibilityInfoForPackageLocked(ai); |
| 6564 | } |
| 6565 | } |
| 6566 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6567 | /** |
| 6568 | * Set the corresponding display information for the process global configuration. To be |
| 6569 | * called when we need to show IME on a different display. |
| 6570 | * |
| 6571 | * @param pid The process id associated with the IME window. |
| 6572 | * @param displayId The ID of the display showing the IME. |
| 6573 | */ |
| 6574 | @Override |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6575 | public void onImeWindowSetOnDisplay(final int pid, final int displayId) { |
lumark | 4897353 | 2019-04-12 20:18:15 +0800 | [diff] [blame] | 6576 | // Don't update process-level configuration for Multi-Client IME process since other |
| 6577 | // IMEs on other displays will also receive this configuration change due to IME |
| 6578 | // services use the same application config/context. |
| 6579 | if (InputMethodSystemProperty.MULTI_CLIENT_IME_ENABLED) return; |
lumark | 5df4951 | 2019-04-02 14:56:46 +0800 | [diff] [blame] | 6580 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6581 | if (pid == MY_PID || pid < 0) { |
| 6582 | if (DEBUG_CONFIGURATION) { |
| 6583 | Slog.w(TAG, |
| 6584 | "Trying to update display configuration for system/invalid process."); |
| 6585 | } |
| 6586 | return; |
| 6587 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6588 | synchronized (mGlobalLock) { |
| 6589 | final ActivityDisplay activityDisplay = |
| 6590 | mRootActivityContainer.getActivityDisplay(displayId); |
| 6591 | if (activityDisplay == null) { |
| 6592 | // Call might come when display is not yet added or has been removed. |
| 6593 | if (DEBUG_CONFIGURATION) { |
| 6594 | Slog.w(TAG, "Trying to update display configuration for non-existing " |
| 6595 | + "displayId=" + displayId); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6596 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6597 | return; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6598 | } |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6599 | final WindowProcessController process = mProcessMap.getProcess(pid); |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 6600 | if (process == null) { |
| 6601 | if (DEBUG_CONFIGURATION) { |
| 6602 | Slog.w(TAG, "Trying to update display configuration for invalid " |
| 6603 | + "process, pid=" + pid); |
| 6604 | } |
| 6605 | return; |
| 6606 | } |
| 6607 | process.registerDisplayConfigurationListenerLocked(activityDisplay); |
| 6608 | } |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6609 | } |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6610 | |
| 6611 | @Override |
| 6612 | public void sendActivityResult(int callingUid, IBinder activityToken, String resultWho, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 6613 | int requestCode, int resultCode, Intent data) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6614 | synchronized (mGlobalLock) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 6615 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 6616 | if (r != null && r.getActivityStack() != null) { |
| 6617 | r.getActivityStack().sendActivityResultLocked(callingUid, r, resultWho, |
| 6618 | requestCode, resultCode, data); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6619 | } |
| 6620 | } |
| 6621 | } |
| 6622 | |
| 6623 | @Override |
| 6624 | public void clearPendingResultForActivity(IBinder activityToken, |
| 6625 | WeakReference<PendingIntentRecord> pir) { |
| 6626 | synchronized (mGlobalLock) { |
| 6627 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 6628 | if (r != null && r.pendingResults != null) { |
| 6629 | r.pendingResults.remove(pir); |
| 6630 | } |
| 6631 | } |
| 6632 | } |
| 6633 | |
| 6634 | @Override |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 6635 | public ActivityTokens getTopActivityForTask(int taskId) { |
| 6636 | synchronized (mGlobalLock) { |
| 6637 | final TaskRecord taskRecord = mRootActivityContainer.anyTaskForId(taskId); |
| 6638 | if (taskRecord == null) { |
| 6639 | Slog.w(TAG, "getApplicationThreadForTopActivity failed:" |
| 6640 | + " Requested task not found"); |
| 6641 | return null; |
| 6642 | } |
| 6643 | final ActivityRecord activity = taskRecord.getTopActivity(); |
| 6644 | if (activity == null) { |
| 6645 | Slog.w(TAG, "getApplicationThreadForTopActivity failed:" |
| 6646 | + " Requested activity not found"); |
| 6647 | return null; |
| 6648 | } |
| 6649 | if (!activity.attachedToProcess()) { |
| 6650 | Slog.w(TAG, "getApplicationThreadForTopActivity failed: No process for " |
| 6651 | + activity); |
| 6652 | return null; |
| 6653 | } |
| 6654 | return new ActivityTokens(activity.appToken, activity.assistToken, |
| 6655 | activity.app.getThread()); |
| 6656 | } |
| 6657 | } |
| 6658 | |
| 6659 | @Override |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6660 | public IIntentSender getIntentSender(int type, String packageName, |
| 6661 | int callingUid, int userId, IBinder token, String resultWho, |
| 6662 | int requestCode, Intent[] intents, String[] resolvedTypes, int flags, |
| 6663 | Bundle bOptions) { |
| 6664 | synchronized (mGlobalLock) { |
| 6665 | return getIntentSenderLocked(type, packageName, callingUid, userId, token, |
| 6666 | resultWho, requestCode, intents, resolvedTypes, flags, bOptions); |
| 6667 | } |
| 6668 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 6669 | |
| 6670 | @Override |
| 6671 | public ActivityServiceConnectionsHolder getServiceConnectionsHolder(IBinder token) { |
| 6672 | synchronized (mGlobalLock) { |
| 6673 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 6674 | if (r == null) { |
| 6675 | return null; |
| 6676 | } |
| 6677 | if (r.mServiceConnectionsHolder == null) { |
| 6678 | r.mServiceConnectionsHolder = new ActivityServiceConnectionsHolder( |
| 6679 | ActivityTaskManagerService.this, r); |
| 6680 | } |
| 6681 | |
| 6682 | return r.mServiceConnectionsHolder; |
| 6683 | } |
| 6684 | } |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6685 | |
| 6686 | @Override |
| 6687 | public Intent getHomeIntent() { |
| 6688 | synchronized (mGlobalLock) { |
| 6689 | return ActivityTaskManagerService.this.getHomeIntent(); |
| 6690 | } |
| 6691 | } |
| 6692 | |
| 6693 | @Override |
| 6694 | public boolean startHomeActivity(int userId, String reason) { |
| 6695 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6696 | return mRootActivityContainer.startHomeOnDisplay(userId, reason, DEFAULT_DISPLAY); |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6697 | } |
| 6698 | } |
| 6699 | |
| 6700 | @Override |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 6701 | public boolean startHomeOnDisplay(int userId, String reason, int displayId, |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 6702 | boolean allowInstrumenting, boolean fromHomeKey) { |
Chilun | 5fd5654 | 2019-03-21 19:51:37 +0800 | [diff] [blame] | 6703 | synchronized (mGlobalLock) { |
| 6704 | return mRootActivityContainer.startHomeOnDisplay(userId, reason, displayId, |
Chilun | 3923209 | 2019-03-22 14:41:30 +0800 | [diff] [blame] | 6705 | allowInstrumenting, fromHomeKey); |
Chilun | 5fd5654 | 2019-03-21 19:51:37 +0800 | [diff] [blame] | 6706 | } |
Chilun | 8b1f1be | 2019-03-13 17:14:36 +0800 | [diff] [blame] | 6707 | } |
| 6708 | |
| 6709 | @Override |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6710 | public boolean startHomeOnAllDisplays(int userId, String reason) { |
| 6711 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6712 | return mRootActivityContainer.startHomeOnAllDisplays(userId, reason); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6713 | } |
| 6714 | } |
| 6715 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6716 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6717 | @Override |
| 6718 | public boolean isFactoryTestProcess(WindowProcessController wpc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6719 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6720 | if (mFactoryTest == FACTORY_TEST_OFF) { |
| 6721 | return false; |
| 6722 | } |
| 6723 | if (mFactoryTest == FACTORY_TEST_LOW_LEVEL && mTopComponent != null |
| 6724 | && wpc.mName.equals(mTopComponent.getPackageName())) { |
| 6725 | return true; |
| 6726 | } |
| 6727 | return mFactoryTest == FACTORY_TEST_HIGH_LEVEL |
| 6728 | && (wpc.mInfo.flags & FLAG_FACTORY_TEST) != 0; |
| 6729 | } |
| 6730 | } |
| 6731 | |
| 6732 | @Override |
| 6733 | public void updateTopComponentForFactoryTest() { |
| 6734 | synchronized (mGlobalLock) { |
| 6735 | if (mFactoryTest != FACTORY_TEST_LOW_LEVEL) { |
| 6736 | return; |
| 6737 | } |
| 6738 | final ResolveInfo ri = mContext.getPackageManager() |
| 6739 | .resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST), STOCK_PM_FLAGS); |
| 6740 | final CharSequence errorMsg; |
| 6741 | if (ri != null) { |
| 6742 | final ActivityInfo ai = ri.activityInfo; |
| 6743 | final ApplicationInfo app = ai.applicationInfo; |
| 6744 | if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 6745 | mTopAction = Intent.ACTION_FACTORY_TEST; |
| 6746 | mTopData = null; |
| 6747 | mTopComponent = new ComponentName(app.packageName, ai.name); |
| 6748 | errorMsg = null; |
| 6749 | } else { |
| 6750 | errorMsg = mContext.getResources().getText( |
| 6751 | com.android.internal.R.string.factorytest_not_system); |
| 6752 | } |
| 6753 | } else { |
| 6754 | errorMsg = mContext.getResources().getText( |
| 6755 | com.android.internal.R.string.factorytest_no_action); |
| 6756 | } |
| 6757 | if (errorMsg == null) { |
| 6758 | return; |
| 6759 | } |
| 6760 | |
| 6761 | mTopAction = null; |
| 6762 | mTopData = null; |
| 6763 | mTopComponent = null; |
| 6764 | mUiHandler.post(() -> { |
| 6765 | Dialog d = new FactoryErrorDialog(mUiContext, errorMsg); |
| 6766 | d.show(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 6767 | mAmInternal.ensureBootCompleted(); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6768 | }); |
| 6769 | } |
| 6770 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6771 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6772 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6773 | @Override |
| 6774 | public void handleAppDied(WindowProcessController wpc, boolean restarting, |
| 6775 | Runnable finishInstrumentationCallback) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6776 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6777 | // Remove this application's activities from active lists. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6778 | boolean hasVisibleActivities = mRootActivityContainer.handleAppDied(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6779 | |
| 6780 | wpc.clearRecentTasks(); |
| 6781 | wpc.clearActivities(); |
| 6782 | |
| 6783 | if (wpc.isInstrumenting()) { |
| 6784 | finishInstrumentationCallback.run(); |
| 6785 | } |
| 6786 | |
Jorim Jaggi | d075281 | 2018-10-16 16:07:20 +0200 | [diff] [blame] | 6787 | if (!restarting && hasVisibleActivities) { |
| 6788 | mWindowManager.deferSurfaceLayout(); |
| 6789 | try { |
| 6790 | if (!mRootActivityContainer.resumeFocusedStacksTopActivities()) { |
| 6791 | // If there was nothing to resume, and we are not already restarting |
| 6792 | // this process, but there is a visible activity that is hosted by the |
| 6793 | // process...then make sure all visible activities are running, taking |
| 6794 | // care of restarting this process. |
| 6795 | mRootActivityContainer.ensureActivitiesVisible(null, 0, |
| 6796 | !PRESERVE_WINDOWS); |
| 6797 | } |
| 6798 | } finally { |
| 6799 | mWindowManager.continueSurfaceLayout(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6800 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6801 | } |
| 6802 | } |
| 6803 | } |
| 6804 | |
| 6805 | @Override |
| 6806 | public void closeSystemDialogs(String reason) { |
| 6807 | enforceNotIsolatedCaller("closeSystemDialogs"); |
| 6808 | |
| 6809 | final int pid = Binder.getCallingPid(); |
| 6810 | final int uid = Binder.getCallingUid(); |
| 6811 | final long origId = Binder.clearCallingIdentity(); |
| 6812 | try { |
| 6813 | synchronized (mGlobalLock) { |
| 6814 | // Only allow this from foreground processes, so that background |
| 6815 | // applications can't abuse it to prevent system UI from being shown. |
| 6816 | if (uid >= FIRST_APPLICATION_UID) { |
Michal Karpinski | 2e0aad2 | 2019-04-12 16:22:55 +0100 | [diff] [blame] | 6817 | final WindowProcessController proc = mProcessMap.getProcess(pid); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6818 | if (!proc.isPerceptible()) { |
| 6819 | Slog.w(TAG, "Ignoring closeSystemDialogs " + reason |
| 6820 | + " from background process " + proc); |
| 6821 | return; |
| 6822 | } |
| 6823 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6824 | mWindowManager.closeSystemDialogs(reason); |
| 6825 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6826 | mRootActivityContainer.closeSystemDialogs(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6827 | } |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 6828 | // Call into AM outside the synchronized block. |
| 6829 | mAmInternal.broadcastCloseSystemDialogs(reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6830 | } finally { |
| 6831 | Binder.restoreCallingIdentity(origId); |
| 6832 | } |
| 6833 | } |
| 6834 | |
| 6835 | @Override |
| 6836 | public void cleanupDisabledPackageComponents( |
| 6837 | String packageName, Set<String> disabledClasses, int userId, boolean booted) { |
| 6838 | synchronized (mGlobalLock) { |
| 6839 | // Clean-up disabled activities. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6840 | if (mRootActivityContainer.finishDisabledPackageActivities( |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6841 | packageName, disabledClasses, true, false, userId) && booted) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6842 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6843 | mStackSupervisor.scheduleIdleLocked(); |
| 6844 | } |
| 6845 | |
| 6846 | // Clean-up disabled tasks |
| 6847 | getRecentTasks().cleanupDisabledPackageTasksLocked( |
| 6848 | packageName, disabledClasses, userId); |
| 6849 | } |
| 6850 | } |
| 6851 | |
| 6852 | @Override |
| 6853 | public boolean onForceStopPackage(String packageName, boolean doit, boolean evenPersistent, |
| 6854 | int userId) { |
| 6855 | synchronized (mGlobalLock) { |
| 6856 | |
| 6857 | boolean didSomething = |
| 6858 | getActivityStartController().clearPendingActivityLaunches(packageName); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6859 | didSomething |= mRootActivityContainer.finishDisabledPackageActivities(packageName, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6860 | null, doit, evenPersistent, userId); |
| 6861 | return didSomething; |
| 6862 | } |
| 6863 | } |
| 6864 | |
| 6865 | @Override |
| 6866 | public void resumeTopActivities(boolean scheduleIdle) { |
| 6867 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6868 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6869 | if (scheduleIdle) { |
| 6870 | mStackSupervisor.scheduleIdleLocked(); |
| 6871 | } |
| 6872 | } |
| 6873 | } |
| 6874 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6875 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6876 | @Override |
| 6877 | public void preBindApplication(WindowProcessController wpc) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6878 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6879 | mStackSupervisor.getActivityMetricsLogger().notifyBindApplication(wpc.mInfo); |
| 6880 | } |
| 6881 | } |
| 6882 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6883 | @HotPath(caller = HotPath.PROCESS_CHANGE) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6884 | @Override |
| 6885 | public boolean attachApplication(WindowProcessController wpc) throws RemoteException { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 6886 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6887 | return mRootActivityContainer.attachApplication(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6888 | } |
| 6889 | } |
| 6890 | |
| 6891 | @Override |
| 6892 | public void notifyLockedProfile(@UserIdInt int userId, int currentUserId) { |
| 6893 | try { |
| 6894 | if (!AppGlobals.getPackageManager().isUidPrivileged(Binder.getCallingUid())) { |
| 6895 | throw new SecurityException("Only privileged app can call notifyLockedProfile"); |
| 6896 | } |
| 6897 | } catch (RemoteException ex) { |
| 6898 | throw new SecurityException("Fail to check is caller a privileged app", ex); |
| 6899 | } |
| 6900 | |
| 6901 | synchronized (mGlobalLock) { |
| 6902 | final long ident = Binder.clearCallingIdentity(); |
| 6903 | try { |
| 6904 | if (mAmInternal.shouldConfirmCredentials(userId)) { |
| 6905 | if (mKeyguardController.isKeyguardLocked()) { |
| 6906 | // Showing launcher to avoid user entering credential twice. |
| 6907 | startHomeActivity(currentUserId, "notifyLockedProfile"); |
| 6908 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6909 | mRootActivityContainer.lockAllProfileTasks(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6910 | } |
| 6911 | } finally { |
| 6912 | Binder.restoreCallingIdentity(ident); |
| 6913 | } |
| 6914 | } |
| 6915 | } |
| 6916 | |
| 6917 | @Override |
| 6918 | public void startConfirmDeviceCredentialIntent(Intent intent, Bundle options) { |
| 6919 | mAmInternal.enforceCallingPermission( |
| 6920 | MANAGE_ACTIVITY_STACKS, "startConfirmDeviceCredentialIntent"); |
| 6921 | |
| 6922 | synchronized (mGlobalLock) { |
| 6923 | final long ident = Binder.clearCallingIdentity(); |
| 6924 | try { |
Pavel Grafov | c0fe0a0 | 2019-05-13 18:19:33 +0100 | [diff] [blame] | 6925 | intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 6926 | final ActivityOptions activityOptions = options != null |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6927 | ? new ActivityOptions(options) : ActivityOptions.makeBasic(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6928 | mContext.startActivityAsUser(intent, activityOptions.toBundle(), |
| 6929 | UserHandle.CURRENT); |
| 6930 | } finally { |
| 6931 | Binder.restoreCallingIdentity(ident); |
| 6932 | } |
| 6933 | } |
| 6934 | } |
| 6935 | |
| 6936 | @Override |
| 6937 | public void writeActivitiesToProto(ProtoOutputStream proto) { |
| 6938 | synchronized (mGlobalLock) { |
| 6939 | // The output proto of "activity --proto activities" |
| 6940 | // is ActivityManagerServiceDumpActivitiesProto |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6941 | mRootActivityContainer.writeToProto(proto, |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 6942 | ActivityManagerServiceDumpActivitiesProto.ACTIVITY_STACK_SUPERVISOR, |
| 6943 | WindowTraceLogLevel.ALL); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6944 | } |
| 6945 | } |
| 6946 | |
| 6947 | @Override |
| 6948 | public void saveANRState(String reason) { |
| 6949 | synchronized (mGlobalLock) { |
| 6950 | final StringWriter sw = new StringWriter(); |
| 6951 | final PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
| 6952 | pw.println(" ANR time: " + DateFormat.getDateTimeInstance().format(new Date())); |
| 6953 | if (reason != null) { |
| 6954 | pw.println(" Reason: " + reason); |
| 6955 | } |
| 6956 | pw.println(); |
| 6957 | getActivityStartController().dump(pw, " ", null); |
| 6958 | pw.println(); |
| 6959 | pw.println("-------------------------------------------------------------------------------"); |
| 6960 | dumpActivitiesLocked(null /* fd */, pw, null /* args */, 0 /* opti */, |
| 6961 | true /* dumpAll */, false /* dumpClient */, null /* dumpPackage */, |
| 6962 | "" /* header */); |
| 6963 | pw.println(); |
| 6964 | pw.close(); |
| 6965 | |
| 6966 | mLastANRState = sw.toString(); |
| 6967 | } |
| 6968 | } |
| 6969 | |
| 6970 | @Override |
| 6971 | public void clearSavedANRState() { |
| 6972 | synchronized (mGlobalLock) { |
| 6973 | mLastANRState = null; |
| 6974 | } |
| 6975 | } |
| 6976 | |
| 6977 | @Override |
| 6978 | public void dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args, int opti, |
| 6979 | boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 6980 | synchronized (mGlobalLock) { |
| 6981 | if (DUMP_ACTIVITIES_CMD.equals(cmd) || DUMP_ACTIVITIES_SHORT_CMD.equals(cmd)) { |
| 6982 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage); |
| 6983 | } else if (DUMP_LASTANR_CMD.equals(cmd)) { |
| 6984 | dumpLastANRLocked(pw); |
| 6985 | } else if (DUMP_LASTANR_TRACES_CMD.equals(cmd)) { |
| 6986 | dumpLastANRTracesLocked(pw); |
| 6987 | } else if (DUMP_STARTER_CMD.equals(cmd)) { |
| 6988 | dumpActivityStarterLocked(pw, dumpPackage); |
| 6989 | } else if (DUMP_CONTAINERS_CMD.equals(cmd)) { |
| 6990 | dumpActivityContainersLocked(pw); |
| 6991 | } else if (DUMP_RECENTS_CMD.equals(cmd) || DUMP_RECENTS_SHORT_CMD.equals(cmd)) { |
| 6992 | if (getRecentTasks() != null) { |
| 6993 | getRecentTasks().dump(pw, dumpAll, dumpPackage); |
| 6994 | } |
| 6995 | } |
| 6996 | } |
| 6997 | } |
| 6998 | |
| 6999 | @Override |
| 7000 | public boolean dumpForProcesses(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 7001 | String dumpPackage, int dumpAppId, boolean needSep, boolean testPssMode, |
| 7002 | int wakefulness) { |
| 7003 | synchronized (mGlobalLock) { |
| 7004 | if (mHomeProcess != null && (dumpPackage == null |
| 7005 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
| 7006 | if (needSep) { |
| 7007 | pw.println(); |
| 7008 | needSep = false; |
| 7009 | } |
| 7010 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 7011 | } |
| 7012 | if (mPreviousProcess != null && (dumpPackage == null |
| 7013 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 7014 | if (needSep) { |
| 7015 | pw.println(); |
| 7016 | needSep = false; |
| 7017 | } |
| 7018 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 7019 | } |
| 7020 | if (dumpAll && (mPreviousProcess == null || dumpPackage == null |
| 7021 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 7022 | StringBuilder sb = new StringBuilder(128); |
| 7023 | sb.append(" mPreviousProcessVisibleTime: "); |
| 7024 | TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb); |
| 7025 | pw.println(sb); |
| 7026 | } |
| 7027 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 7028 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
| 7029 | if (needSep) { |
| 7030 | pw.println(); |
| 7031 | needSep = false; |
| 7032 | } |
| 7033 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 7034 | } |
| 7035 | if (dumpPackage == null) { |
| 7036 | pw.println(" mGlobalConfiguration: " + getGlobalConfiguration()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7037 | mRootActivityContainer.dumpDisplayConfigs(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7038 | } |
| 7039 | if (dumpAll) { |
| 7040 | if (dumpPackage == null) { |
| 7041 | pw.println(" mConfigWillChange: " |
| 7042 | + getTopDisplayFocusedStack().mConfigWillChange); |
| 7043 | } |
| 7044 | if (mCompatModePackages.getPackages().size() > 0) { |
| 7045 | boolean printed = false; |
| 7046 | for (Map.Entry<String, Integer> entry |
| 7047 | : mCompatModePackages.getPackages().entrySet()) { |
| 7048 | String pkg = entry.getKey(); |
| 7049 | int mode = entry.getValue(); |
| 7050 | if (dumpPackage != null && !dumpPackage.equals(pkg)) { |
| 7051 | continue; |
| 7052 | } |
| 7053 | if (!printed) { |
| 7054 | pw.println(" mScreenCompatPackages:"); |
| 7055 | printed = true; |
| 7056 | } |
| 7057 | pw.println(" " + pkg + ": " + mode); |
| 7058 | } |
| 7059 | } |
| 7060 | } |
| 7061 | |
| 7062 | if (dumpPackage == null) { |
| 7063 | pw.println(" mWakefulness=" |
| 7064 | + PowerManagerInternal.wakefulnessToString(wakefulness)); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7065 | pw.println(" mSleepTokens=" + mRootActivityContainer.mSleepTokens); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7066 | if (mRunningVoice != null) { |
| 7067 | pw.println(" mRunningVoice=" + mRunningVoice); |
| 7068 | pw.println(" mVoiceWakeLock" + mVoiceWakeLock); |
| 7069 | } |
| 7070 | pw.println(" mSleeping=" + mSleeping); |
| 7071 | pw.println(" mShuttingDown=" + mShuttingDown + " mTestPssMode=" + testPssMode); |
| 7072 | pw.println(" mVrController=" + mVrController); |
| 7073 | } |
| 7074 | if (mCurAppTimeTracker != null) { |
| 7075 | mCurAppTimeTracker.dumpWithHeader(pw, " ", true); |
| 7076 | } |
| 7077 | if (mAllowAppSwitchUids.size() > 0) { |
| 7078 | boolean printed = false; |
| 7079 | for (int i = 0; i < mAllowAppSwitchUids.size(); i++) { |
| 7080 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.valueAt(i); |
| 7081 | for (int j = 0; j < types.size(); j++) { |
| 7082 | if (dumpPackage == null || |
| 7083 | UserHandle.getAppId(types.valueAt(j).intValue()) == dumpAppId) { |
| 7084 | if (needSep) { |
| 7085 | pw.println(); |
| 7086 | needSep = false; |
| 7087 | } |
| 7088 | if (!printed) { |
| 7089 | pw.println(" mAllowAppSwitchUids:"); |
| 7090 | printed = true; |
| 7091 | } |
| 7092 | pw.print(" User "); |
| 7093 | pw.print(mAllowAppSwitchUids.keyAt(i)); |
| 7094 | pw.print(": Type "); |
| 7095 | pw.print(types.keyAt(j)); |
| 7096 | pw.print(" = "); |
| 7097 | UserHandle.formatUid(pw, types.valueAt(j).intValue()); |
| 7098 | pw.println(); |
| 7099 | } |
| 7100 | } |
| 7101 | } |
| 7102 | } |
| 7103 | if (dumpPackage == null) { |
| 7104 | if (mController != null) { |
| 7105 | pw.println(" mController=" + mController |
| 7106 | + " mControllerIsAMonkey=" + mControllerIsAMonkey); |
| 7107 | } |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 7108 | pw.println(" mGoingToSleepWakeLock=" + mStackSupervisor.mGoingToSleepWakeLock); |
| 7109 | pw.println(" mLaunchingActivityWakeLock=" |
| 7110 | + mStackSupervisor.mLaunchingActivityWakeLock); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7111 | } |
| 7112 | |
| 7113 | return needSep; |
| 7114 | } |
| 7115 | } |
| 7116 | |
| 7117 | @Override |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7118 | public void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage, |
| 7119 | int wakeFullness, boolean testPssMode) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7120 | synchronized (mGlobalLock) { |
| 7121 | if (dumpPackage == null) { |
| 7122 | getGlobalConfiguration().writeToProto(proto, GLOBAL_CONFIGURATION); |
| 7123 | proto.write(CONFIG_WILL_CHANGE, getTopDisplayFocusedStack().mConfigWillChange); |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame] | 7124 | writeSleepStateToProto(proto, wakeFullness, testPssMode); |
| 7125 | if (mRunningVoice != null) { |
| 7126 | final long vrToken = proto.start( |
| 7127 | ActivityManagerServiceDumpProcessesProto.RUNNING_VOICE); |
| 7128 | proto.write(ActivityManagerServiceDumpProcessesProto.Voice.SESSION, |
| 7129 | mRunningVoice.toString()); |
| 7130 | mVoiceWakeLock.writeToProto( |
| 7131 | proto, ActivityManagerServiceDumpProcessesProto.Voice.WAKELOCK); |
| 7132 | proto.end(vrToken); |
| 7133 | } |
| 7134 | mVrController.writeToProto(proto, |
| 7135 | ActivityManagerServiceDumpProcessesProto.VR_CONTROLLER); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7136 | if (mController != null) { |
| 7137 | final long token = proto.start(CONTROLLER); |
| 7138 | proto.write(CONTROLLER, mController.toString()); |
| 7139 | proto.write(IS_A_MONKEY, mControllerIsAMonkey); |
| 7140 | proto.end(token); |
| 7141 | } |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 7142 | mStackSupervisor.mGoingToSleepWakeLock.writeToProto(proto, GOING_TO_SLEEP); |
| 7143 | mStackSupervisor.mLaunchingActivityWakeLock.writeToProto(proto, |
| 7144 | LAUNCHING_ACTIVITY); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7145 | } |
| 7146 | |
| 7147 | if (mHomeProcess != null && (dumpPackage == null |
| 7148 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 7149 | mHomeProcess.writeToProto(proto, HOME_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7150 | } |
| 7151 | |
| 7152 | if (mPreviousProcess != null && (dumpPackage == null |
| 7153 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 7154 | mPreviousProcess.writeToProto(proto, PREVIOUS_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7155 | proto.write(PREVIOUS_PROC_VISIBLE_TIME_MS, mPreviousProcessVisibleTime); |
| 7156 | } |
| 7157 | |
| 7158 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 7159 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 7160 | mHeavyWeightProcess.writeToProto(proto, HEAVY_WEIGHT_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7161 | } |
| 7162 | |
| 7163 | for (Map.Entry<String, Integer> entry |
| 7164 | : mCompatModePackages.getPackages().entrySet()) { |
| 7165 | String pkg = entry.getKey(); |
| 7166 | int mode = entry.getValue(); |
| 7167 | if (dumpPackage == null || dumpPackage.equals(pkg)) { |
| 7168 | long compatToken = proto.start(SCREEN_COMPAT_PACKAGES); |
| 7169 | proto.write(PACKAGE, pkg); |
| 7170 | proto.write(MODE, mode); |
| 7171 | proto.end(compatToken); |
| 7172 | } |
| 7173 | } |
| 7174 | |
| 7175 | if (mCurAppTimeTracker != null) { |
| 7176 | mCurAppTimeTracker.writeToProto(proto, CURRENT_TRACKER, true); |
| 7177 | } |
| 7178 | |
| 7179 | } |
| 7180 | } |
| 7181 | |
| 7182 | @Override |
| 7183 | public boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, |
| 7184 | String[] args, int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, |
| 7185 | boolean dumpFocusedStackOnly) { |
Riddle Hsu | d7cd8ed | 2019-07-16 18:19:01 +0800 | [diff] [blame] | 7186 | return ActivityTaskManagerService.this.dumpActivity(fd, pw, name, args, opti, dumpAll, |
| 7187 | dumpVisibleStacksOnly, dumpFocusedStackOnly); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7188 | } |
| 7189 | |
| 7190 | @Override |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 7191 | public void dumpForOom(PrintWriter pw) { |
| 7192 | synchronized (mGlobalLock) { |
| 7193 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 7194 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 7195 | if (mHeavyWeightProcess != null) { |
| 7196 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 7197 | } |
| 7198 | } |
| 7199 | } |
| 7200 | |
| 7201 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7202 | public boolean canGcNow() { |
| 7203 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7204 | return isSleeping() || mRootActivityContainer.allResumedActivitiesIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7205 | } |
| 7206 | } |
| 7207 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7208 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7209 | @Override |
| 7210 | public WindowProcessController getTopApp() { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7211 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7212 | final ActivityRecord top = mRootActivityContainer.getTopResumedActivity(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7213 | return top != null ? top.app : null; |
| 7214 | } |
| 7215 | } |
| 7216 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7217 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7218 | @Override |
| 7219 | public void rankTaskLayersIfNeeded() { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7220 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7221 | if (mRootActivityContainer != null) { |
| 7222 | mRootActivityContainer.rankTaskLayersIfNeeded(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7223 | } |
| 7224 | } |
| 7225 | } |
| 7226 | |
| 7227 | @Override |
| 7228 | public void scheduleDestroyAllActivities(String reason) { |
| 7229 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7230 | mRootActivityContainer.scheduleDestroyAllActivities(null, reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7231 | } |
| 7232 | } |
| 7233 | |
| 7234 | @Override |
| 7235 | public void removeUser(int userId) { |
| 7236 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7237 | mRootActivityContainer.removeUser(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7238 | } |
| 7239 | } |
| 7240 | |
| 7241 | @Override |
| 7242 | public boolean switchUser(int userId, UserState userState) { |
| 7243 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7244 | return mRootActivityContainer.switchUser(userId, userState); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7245 | } |
| 7246 | } |
| 7247 | |
| 7248 | @Override |
| 7249 | public void onHandleAppCrash(WindowProcessController wpc) { |
| 7250 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7251 | mRootActivityContainer.handleAppCrash(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 7252 | } |
| 7253 | } |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 7254 | |
| 7255 | @Override |
| 7256 | public int finishTopCrashedActivities(WindowProcessController crashedApp, String reason) { |
| 7257 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 7258 | return mRootActivityContainer.finishTopCrashedActivities(crashedApp, reason); |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 7259 | } |
| 7260 | } |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7261 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7262 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7263 | @Override |
| 7264 | public void onUidActive(int uid, int procState) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7265 | mActiveUids.onUidActive(uid, procState); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7266 | } |
| 7267 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7268 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7269 | @Override |
| 7270 | public void onUidInactive(int uid) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7271 | mActiveUids.onUidInactive(uid); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7272 | } |
| 7273 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7274 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7275 | @Override |
| 7276 | public void onActiveUidsCleared() { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7277 | mActiveUids.onActiveUidsCleared(); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7278 | } |
| 7279 | |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7280 | @HotPath(caller = HotPath.OOM_ADJUSTMENT) |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7281 | @Override |
| 7282 | public void onUidProcStateChanged(int uid, int procState) { |
Riddle Hsu | a053643 | 2019-02-16 00:38:59 +0800 | [diff] [blame] | 7283 | mActiveUids.onUidProcStateChanged(uid, procState); |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 7284 | } |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7285 | |
| 7286 | @Override |
| 7287 | public void onUidAddedToPendingTempWhitelist(int uid, String tag) { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7288 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7289 | mPendingTempWhitelist.put(uid, tag); |
| 7290 | } |
| 7291 | } |
| 7292 | |
| 7293 | @Override |
| 7294 | public void onUidRemovedFromPendingTempWhitelist(int uid) { |
Riddle Hsu | d7088f8 | 2019-01-30 13:04:50 +0800 | [diff] [blame] | 7295 | synchronized (mGlobalLockWithoutBoost) { |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 7296 | mPendingTempWhitelist.remove(uid); |
| 7297 | } |
| 7298 | } |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 7299 | |
| 7300 | @Override |
| 7301 | public boolean handleAppCrashInActivityController(String processName, int pid, |
| 7302 | String shortMsg, String longMsg, long timeMillis, String stackTrace, |
| 7303 | Runnable killCrashingAppCallback) { |
| 7304 | synchronized (mGlobalLock) { |
| 7305 | if (mController == null) { |
| 7306 | return false; |
| 7307 | } |
| 7308 | |
| 7309 | try { |
| 7310 | if (!mController.appCrashed(processName, pid, shortMsg, longMsg, timeMillis, |
| 7311 | stackTrace)) { |
| 7312 | killCrashingAppCallback.run(); |
| 7313 | return true; |
| 7314 | } |
| 7315 | } catch (RemoteException e) { |
| 7316 | mController = null; |
| 7317 | Watchdog.getInstance().setActivityController(null); |
| 7318 | } |
| 7319 | return false; |
| 7320 | } |
| 7321 | } |
Wale Ogunwale | d7889f5 | 2018-10-25 11:03:20 -0700 | [diff] [blame] | 7322 | |
| 7323 | @Override |
| 7324 | public void removeRecentTasksByPackageName(String packageName, int userId) { |
| 7325 | synchronized (mGlobalLock) { |
| 7326 | mRecentTasks.removeTasksByPackageName(packageName, userId); |
| 7327 | } |
| 7328 | } |
| 7329 | |
| 7330 | @Override |
| 7331 | public void cleanupRecentTasksForUser(int userId) { |
| 7332 | synchronized (mGlobalLock) { |
| 7333 | mRecentTasks.cleanupLocked(userId); |
| 7334 | } |
| 7335 | } |
| 7336 | |
| 7337 | @Override |
| 7338 | public void loadRecentTasksForUser(int userId) { |
| 7339 | synchronized (mGlobalLock) { |
| 7340 | mRecentTasks.loadUserRecentsLocked(userId); |
| 7341 | } |
| 7342 | } |
| 7343 | |
| 7344 | @Override |
| 7345 | public void onPackagesSuspendedChanged(String[] packages, boolean suspended, int userId) { |
| 7346 | synchronized (mGlobalLock) { |
| 7347 | mRecentTasks.onPackagesSuspendedChanged(packages, suspended, userId); |
| 7348 | } |
| 7349 | } |
| 7350 | |
| 7351 | @Override |
| 7352 | public void flushRecentTasks() { |
| 7353 | mRecentTasks.flush(); |
| 7354 | } |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 7355 | |
| 7356 | @Override |
| 7357 | public WindowProcessController getHomeProcess() { |
| 7358 | synchronized (mGlobalLock) { |
| 7359 | return mHomeProcess; |
| 7360 | } |
| 7361 | } |
| 7362 | |
| 7363 | @Override |
| 7364 | public WindowProcessController getPreviousProcess() { |
| 7365 | synchronized (mGlobalLock) { |
| 7366 | return mPreviousProcess; |
| 7367 | } |
| 7368 | } |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 7369 | |
| 7370 | @Override |
| 7371 | public void clearLockedTasks(String reason) { |
| 7372 | synchronized (mGlobalLock) { |
| 7373 | getLockTaskController().clearLockedTasks(reason); |
| 7374 | } |
| 7375 | } |
| 7376 | |
| 7377 | @Override |
| 7378 | public void updateUserConfiguration() { |
| 7379 | synchronized (mGlobalLock) { |
| 7380 | final Configuration configuration = new Configuration(getGlobalConfiguration()); |
| 7381 | final int currentUserId = mAmInternal.getCurrentUserId(); |
| 7382 | Settings.System.adjustConfigurationForUser(mContext.getContentResolver(), |
| 7383 | configuration, currentUserId, Settings.System.canWrite(mContext)); |
| 7384 | updateConfigurationLocked(configuration, null /* starting */, |
| 7385 | false /* initLocale */, false /* persistent */, currentUserId, |
| 7386 | false /* deferResume */); |
| 7387 | } |
| 7388 | } |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 7389 | |
| 7390 | @Override |
| 7391 | public boolean canShowErrorDialogs() { |
| 7392 | synchronized (mGlobalLock) { |
| 7393 | return mShowDialogs && !mSleeping && !mShuttingDown |
| 7394 | && !mKeyguardController.isKeyguardOrAodShowing(DEFAULT_DISPLAY) |
| 7395 | && !hasUserRestriction(UserManager.DISALLOW_SYSTEM_ERROR_DIALOGS, |
| 7396 | mAmInternal.getCurrentUserId()) |
| 7397 | && !(UserManager.isDeviceInDemoMode(mContext) |
| 7398 | && mAmInternal.getCurrentUser().isDemo()); |
| 7399 | } |
| 7400 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 7401 | |
| 7402 | @Override |
| 7403 | public void setProfileApp(String profileApp) { |
| 7404 | synchronized (mGlobalLock) { |
| 7405 | mProfileApp = profileApp; |
| 7406 | } |
| 7407 | } |
| 7408 | |
| 7409 | @Override |
| 7410 | public void setProfileProc(WindowProcessController wpc) { |
| 7411 | synchronized (mGlobalLock) { |
| 7412 | mProfileProc = wpc; |
| 7413 | } |
| 7414 | } |
| 7415 | |
| 7416 | @Override |
| 7417 | public void setProfilerInfo(ProfilerInfo profilerInfo) { |
| 7418 | synchronized (mGlobalLock) { |
| 7419 | mProfilerInfo = profilerInfo; |
| 7420 | } |
| 7421 | } |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 7422 | |
| 7423 | @Override |
| 7424 | public ActivityMetricsLaunchObserverRegistry getLaunchObserverRegistry() { |
| 7425 | synchronized (mGlobalLock) { |
| 7426 | return mStackSupervisor.getActivityMetricsLogger().getLaunchObserverRegistry(); |
| 7427 | } |
| 7428 | } |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 7429 | |
| 7430 | @Override |
Jorim Jaggi | 925bb3c | 2019-06-04 19:51:45 +0200 | [diff] [blame] | 7431 | public ActivityManager.TaskSnapshot getTaskSnapshotNoRestore(int taskId, |
| 7432 | boolean reducedResolution) { |
| 7433 | return ActivityTaskManagerService.this.getTaskSnapshot(taskId, reducedResolution, |
| 7434 | false /* restoreFromDisk */); |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 7435 | } |
Michal Karpinski | cc88d7e | 2019-01-24 15:32:12 +0000 | [diff] [blame] | 7436 | |
| 7437 | @Override |
| 7438 | public boolean isUidForeground(int uid) { |
| 7439 | synchronized (mGlobalLock) { |
| 7440 | return ActivityTaskManagerService.this.isUidForeground(uid); |
| 7441 | } |
| 7442 | } |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7443 | |
| 7444 | @Override |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 7445 | public void setDeviceOwnerUid(int uid) { |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7446 | synchronized (mGlobalLock) { |
Ricky Wai | 96f5c35 | 2019-04-10 18:40:17 +0100 | [diff] [blame] | 7447 | ActivityTaskManagerService.this.setDeviceOwnerUid(uid); |
Michal Karpinski | 4026cae | 2019-02-12 11:51:47 +0000 | [diff] [blame] | 7448 | } |
| 7449 | } |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7450 | |
| 7451 | @Override |
| 7452 | public void setCompanionAppPackages(int userId, Set<String> companionAppPackages) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7453 | // Translate package names into UIDs |
| 7454 | final Set<Integer> result = new HashSet<>(); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7455 | for (String pkg : companionAppPackages) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7456 | final int uid = getPackageManagerInternalLocked().getPackageUid(pkg, 0, userId); |
| 7457 | if (uid >= 0) { |
| 7458 | result.add(uid); |
| 7459 | } |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7460 | } |
| 7461 | synchronized (mGlobalLock) { |
Michal Karpinski | da34cd4 | 2019-04-02 19:46:52 +0100 | [diff] [blame] | 7462 | mCompanionAppUidsMap.put(userId, result); |
Ricky Wai | 2452e2d | 2019-03-18 19:19:08 +0000 | [diff] [blame] | 7463 | } |
| 7464 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 7465 | } |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 7466 | } |