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; |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 29 | import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 30 | import static android.app.ActivityManagerInternal.ALLOW_FULL_ONLY; |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 31 | import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 32 | import static android.app.ActivityTaskManager.RESIZE_MODE_PRESERVE_WINDOW; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 33 | import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT; |
| 34 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 35 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 36 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 37 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 38 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 39 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 40 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 41 | import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 42 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 43 | import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 44 | import static android.content.pm.ApplicationInfo.FLAG_FACTORY_TEST; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 45 | import static android.content.pm.ConfigurationInfo.GL_ES_VERSION_UNDEFINED; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 46 | import static android.content.pm.PackageManager.FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS; |
| 47 | import static android.content.pm.PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 48 | import static android.content.pm.PackageManager.FEATURE_PC; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 49 | import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 50 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 51 | import static android.content.res.Configuration.UI_MODE_TYPE_TELEVISION; |
| 52 | import static android.os.Build.VERSION_CODES.N; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 53 | import static android.os.FactoryTest.FACTORY_TEST_HIGH_LEVEL; |
| 54 | import static android.os.FactoryTest.FACTORY_TEST_LOW_LEVEL; |
| 55 | import static android.os.FactoryTest.FACTORY_TEST_OFF; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 56 | import static android.os.Process.FIRST_APPLICATION_UID; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 57 | import static android.os.Process.SYSTEM_UID; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 58 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 59 | import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT; |
| 60 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES; |
| 61 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RTL; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 62 | import static android.provider.Settings.Global.HIDE_ERROR_DIALOGS; |
| 63 | import static android.provider.Settings.System.FONT_SCALE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 64 | import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_APPLICATION; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 65 | import static android.text.format.DateUtils.MINUTE_IN_MILLIS; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 66 | import static android.view.Display.DEFAULT_DISPLAY; |
| 67 | import static android.view.Display.INVALID_DISPLAY; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 68 | import static android.view.WindowManager.TRANSIT_NONE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 69 | import static android.view.WindowManager.TRANSIT_TASK_IN_PLACE; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 70 | |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 71 | import static com.android.server.am.ActivityManagerService.ANR_TRACE_DIR; |
| 72 | import static com.android.server.am.ActivityManagerService.MY_PID; |
| 73 | import static com.android.server.am.ActivityManagerService.STOCK_PM_FLAGS; |
| 74 | import static com.android.server.am.ActivityManagerService.dumpStackTraces; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 75 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CONFIG_WILL_CHANGE; |
| 76 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CONTROLLER; |
| 77 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.CURRENT_TRACKER; |
| 78 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.Controller.IS_A_MONKEY; |
| 79 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.GLOBAL_CONFIGURATION; |
| 80 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.GOING_TO_SLEEP; |
| 81 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HEAVY_WEIGHT_PROC; |
| 82 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.HOME_PROC; |
| 83 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.LAUNCHING_ACTIVITY; |
| 84 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.PREVIOUS_PROC; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 85 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto |
| 86 | .PREVIOUS_PROC_VISIBLE_TIME_MS; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 87 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.SCREEN_COMPAT_PACKAGES; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 88 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage |
| 89 | .MODE; |
| 90 | import static com.android.server.am.ActivityManagerServiceDumpProcessesProto.ScreenCompatPackage |
| 91 | .PACKAGE; |
| 92 | import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING; |
| 93 | import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 94 | import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; |
| 95 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
| 96 | import static com.android.server.wm.ActivityStackSupervisor.REMOVE_FROM_RECENTS; |
| 97 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL; |
| 98 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONFIGURATION; |
| 99 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_FOCUS; |
| 100 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_IMMERSIVE; |
| 101 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_LOCKTASK; |
| 102 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STACK; |
| 103 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; |
| 104 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 105 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_VISIBILITY; |
| 106 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONFIGURATION; |
| 107 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_FOCUS; |
| 108 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_IMMERSIVE; |
| 109 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_LOCKTASK; |
| 110 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; |
| 111 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; |
| 112 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_VISIBILITY; |
| 113 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 114 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 115 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_CONTENT; |
| 116 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_DATA; |
| 117 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_RECEIVER_EXTRAS; |
| 118 | import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_STRUCTURE; |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 119 | import static com.android.server.wm.ActivityTaskManagerService.H.REPORT_TIME_TRACKER_MSG; |
| 120 | import static com.android.server.wm.ActivityTaskManagerService.UiHandler.DISMISS_DIALOG_UI_MSG; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 121 | import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; |
| 122 | import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 123 | import static com.android.server.wm.RootActivityContainer.MATCH_TASK_IN_STACKS_ONLY; |
| 124 | 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] | 125 | import static com.android.server.wm.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK; |
| 126 | import static com.android.server.wm.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT; |
| 127 | import static com.android.server.wm.TaskRecord.REPARENT_LEAVE_STACK_IN_PLACE; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 128 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 129 | import android.Manifest; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 130 | import android.annotation.NonNull; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 131 | import android.annotation.Nullable; |
| 132 | import android.annotation.UserIdInt; |
| 133 | import android.app.Activity; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 134 | import android.app.ActivityManager; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 135 | import android.app.ActivityManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 136 | import android.app.ActivityOptions; |
| 137 | import android.app.ActivityTaskManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 138 | import android.app.ActivityThread; |
| 139 | import android.app.AlertDialog; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 140 | import android.app.AppGlobals; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 141 | import android.app.Dialog; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 142 | import android.app.IActivityController; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 143 | import android.app.IActivityTaskManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 144 | import android.app.IApplicationThread; |
| 145 | import android.app.IAssistDataReceiver; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 146 | import android.app.INotificationManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 147 | import android.app.ITaskStackListener; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 148 | import android.app.Notification; |
| 149 | import android.app.NotificationManager; |
| 150 | import android.app.PendingIntent; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 151 | import android.app.PictureInPictureParams; |
| 152 | import android.app.ProfilerInfo; |
| 153 | import android.app.RemoteAction; |
| 154 | import android.app.WaitResult; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 155 | import android.app.WindowConfiguration; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 156 | import android.app.admin.DevicePolicyCache; |
| 157 | import android.app.assist.AssistContent; |
| 158 | import android.app.assist.AssistStructure; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 159 | import android.app.usage.UsageStatsManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 160 | import android.content.ActivityNotFoundException; |
| 161 | import android.content.ComponentName; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 162 | import android.content.ContentResolver; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 163 | import android.content.Context; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 164 | import android.content.DialogInterface; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 165 | import android.content.IIntentSender; |
| 166 | import android.content.Intent; |
| 167 | import android.content.pm.ActivityInfo; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 168 | import android.content.pm.ApplicationInfo; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 169 | import android.content.pm.ConfigurationInfo; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 170 | import android.content.pm.IPackageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 171 | import android.content.pm.PackageManager; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 172 | import android.content.pm.PackageManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 173 | import android.content.pm.ParceledListSlice; |
| 174 | import android.content.pm.ResolveInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 175 | import android.content.res.CompatibilityInfo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 176 | import android.content.res.Configuration; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 177 | import android.content.res.Resources; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 178 | import android.database.ContentObserver; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 179 | import android.graphics.Bitmap; |
| 180 | import android.graphics.Point; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 181 | import android.graphics.Rect; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 182 | import android.metrics.LogMaker; |
| 183 | import android.net.Uri; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 184 | import android.os.Binder; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 185 | import android.os.Build; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 186 | import android.os.Bundle; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 187 | import android.os.FactoryTest; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 188 | import android.os.FileUtils; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 189 | import android.os.Handler; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 190 | import android.os.IBinder; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 191 | import android.os.IUserManager; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 192 | import android.os.LocaleList; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 193 | import android.os.Message; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 194 | import android.os.PersistableBundle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 195 | import android.os.PowerManager; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 196 | import android.os.PowerManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 197 | import android.os.RemoteException; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 198 | import android.os.ServiceManager; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 199 | import android.os.StrictMode; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 200 | import android.os.SystemClock; |
| 201 | import android.os.SystemProperties; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 202 | import android.os.Trace; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 203 | import android.os.UpdateLock; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 204 | import android.os.UserHandle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 205 | import android.os.UserManager; |
| 206 | import android.os.WorkSource; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 207 | import android.os.storage.IStorageManager; |
| 208 | import android.os.storage.StorageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 209 | import android.provider.Settings; |
| 210 | import android.service.voice.IVoiceInteractionSession; |
| 211 | import android.service.voice.VoiceInteractionManagerInternal; |
| 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; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 228 | |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 229 | import com.android.internal.R; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 230 | import com.android.internal.annotations.VisibleForTesting; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 231 | import com.android.internal.app.AssistUtils; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 232 | import com.android.internal.app.IAppOpsService; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 233 | import com.android.internal.app.IVoiceInteractor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 234 | import com.android.internal.app.ProcessMap; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 235 | import com.android.internal.logging.MetricsLogger; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 236 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 237 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
| 238 | import com.android.internal.notification.SystemNotificationChannels; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 239 | import com.android.internal.os.TransferPipe; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 240 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 241 | import com.android.internal.policy.IKeyguardDismissCallback; |
| 242 | import com.android.internal.policy.KeyguardDismissCallback; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 243 | import com.android.internal.util.ArrayUtils; |
| 244 | import com.android.internal.util.FastPrintWriter; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 245 | import com.android.internal.util.Preconditions; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 246 | import com.android.internal.util.function.pooled.PooledLambda; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 247 | import com.android.server.AppOpsService; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 248 | import com.android.server.AttributeCache; |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 249 | import com.android.server.DisplayThread; |
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; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 264 | import com.android.server.firewall.IntentFirewall; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 265 | import com.android.server.pm.UserManagerService; |
| 266 | import com.android.server.uri.UriGrantsManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 267 | import com.android.server.vr.VrManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 268 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 269 | import java.io.BufferedReader; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 270 | import java.io.File; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 271 | import java.io.FileDescriptor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 272 | import java.io.FileOutputStream; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 273 | import java.io.FileReader; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 274 | import java.io.IOException; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 275 | import java.io.PrintWriter; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 276 | import java.io.StringWriter; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 277 | import java.lang.ref.WeakReference; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 278 | import java.text.DateFormat; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 279 | import java.util.ArrayList; |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 280 | import java.util.Arrays; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 281 | import java.util.Date; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 282 | import java.util.HashMap; |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 283 | import java.util.HashSet; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 284 | import java.util.List; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 285 | import java.util.Locale; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 286 | import java.util.Map; |
| 287 | import java.util.Set; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 288 | |
| 289 | /** |
| 290 | * System service for managing activities and their containers (task, stacks, displays,... ). |
| 291 | * |
| 292 | * {@hide} |
| 293 | */ |
| 294 | public class ActivityTaskManagerService extends IActivityTaskManager.Stub { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 295 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityTaskManagerService" : TAG_ATM; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 296 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 297 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 298 | private static final String TAG_IMMERSIVE = TAG + POSTFIX_IMMERSIVE; |
| 299 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
| 300 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
| 301 | private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 302 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 303 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 304 | // How long we wait until we timeout on key dispatching. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 305 | public static final int KEY_DISPATCHING_TIMEOUT_MS = 5 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 306 | // How long we wait until we timeout on key dispatching during instrumentation. |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 307 | static final int INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT_MS = 60 * 1000; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 308 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 309 | /** Used to indicate that an app transition should be animated. */ |
| 310 | static final boolean ANIMATE = true; |
| 311 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 312 | /** Hardware-reported OpenGLES version. */ |
| 313 | final int GL_ES_VERSION; |
| 314 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 315 | public static final String DUMP_ACTIVITIES_CMD = "activities" ; |
| 316 | public static final String DUMP_ACTIVITIES_SHORT_CMD = "a" ; |
| 317 | public static final String DUMP_LASTANR_CMD = "lastanr" ; |
| 318 | public static final String DUMP_LASTANR_TRACES_CMD = "lastanr-traces" ; |
| 319 | public static final String DUMP_STARTER_CMD = "starter" ; |
| 320 | public static final String DUMP_CONTAINERS_CMD = "containers" ; |
| 321 | public static final String DUMP_RECENTS_CMD = "recents" ; |
| 322 | public static final String DUMP_RECENTS_SHORT_CMD = "r" ; |
| 323 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 324 | /** This activity is not being relaunched, or being relaunched for a non-resize reason. */ |
| 325 | public static final int RELAUNCH_REASON_NONE = 0; |
| 326 | /** This activity is being relaunched due to windowing mode change. */ |
| 327 | public static final int RELAUNCH_REASON_WINDOWING_MODE_RESIZE = 1; |
| 328 | /** This activity is being relaunched due to a free-resize operation. */ |
| 329 | public static final int RELAUNCH_REASON_FREE_RESIZE = 2; |
| 330 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 331 | Context mContext; |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 332 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 333 | /** |
| 334 | * This Context is themable and meant for UI display (AlertDialogs, etc.). The theme can |
| 335 | * change at runtime. Use mContext for non-UI purposes. |
| 336 | */ |
| 337 | final Context mUiContext; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 338 | final ActivityThread mSystemThread; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 339 | H mH; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 340 | UiHandler mUiHandler; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 341 | ActivityManagerInternal mAmInternal; |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 342 | UriGrantsManagerInternal mUgmInternal; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 343 | private PackageManagerInternal mPmInternal; |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 344 | @VisibleForTesting |
| 345 | final ActivityTaskManagerInternal mInternal; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 346 | PowerManagerInternal mPowerManagerInternal; |
| 347 | private UsageStatsManagerInternal mUsageStatsInternal; |
| 348 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 349 | PendingIntentController mPendingIntentController; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 350 | IntentFirewall mIntentFirewall; |
| 351 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 352 | /* Global service lock used by the package the owns this service. */ |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 353 | final WindowManagerGlobalLock mGlobalLock = new WindowManagerGlobalLock(); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 354 | ActivityStackSupervisor mStackSupervisor; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 355 | RootActivityContainer mRootActivityContainer; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 356 | WindowManagerService mWindowManager; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 357 | private UserManagerService mUserManager; |
| 358 | private AppOpsService mAppOpsService; |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 359 | /** All active uids in the system. */ |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 360 | private final SparseArray<Integer> mActiveUids = new SparseArray<>(); |
| 361 | private final SparseArray<String> mPendingTempWhitelist = new SparseArray<>(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 362 | /** All processes currently running that might have a window organized by name. */ |
| 363 | final ProcessMap<WindowProcessController> mProcessNames = new ProcessMap<>(); |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 364 | /** All processes we currently have running mapped by pid */ |
| 365 | final SparseArray<WindowProcessController> mPidMap = new SparseArray<>(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 366 | /** This is the process holding what we currently consider to be the "home" activity. */ |
| 367 | WindowProcessController mHomeProcess; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 368 | /** The currently running heavy-weight process, if any. */ |
| 369 | WindowProcessController mHeavyWeightProcess = null; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 370 | boolean mHasHeavyWeightFeature; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 371 | /** |
| 372 | * This is the process holding the activity the user last visited that is in a different process |
| 373 | * from the one they are currently in. |
| 374 | */ |
| 375 | WindowProcessController mPreviousProcess; |
| 376 | /** The time at which the previous process was last visible. */ |
| 377 | long mPreviousProcessVisibleTime; |
| 378 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 379 | /** List of intents that were used to start the most recent tasks. */ |
| 380 | private RecentTasks mRecentTasks; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 381 | /** State of external calls telling us if the device is awake or asleep. */ |
| 382 | private boolean mKeyguardShown = false; |
| 383 | |
| 384 | // Wrapper around VoiceInteractionServiceManager |
| 385 | private AssistUtils mAssistUtils; |
| 386 | |
| 387 | // VoiceInteraction session ID that changes for each new request except when |
| 388 | // being called for multi-window assist in a single session. |
| 389 | private int mViSessionId = 1000; |
| 390 | |
| 391 | // How long to wait in getAssistContextExtras for the activity and foreground services |
| 392 | // to respond with the result. |
| 393 | private static final int PENDING_ASSIST_EXTRAS_TIMEOUT = 500; |
| 394 | |
| 395 | // How long top wait when going through the modern assist (which doesn't need to block |
| 396 | // on getting this result before starting to launch its UI). |
| 397 | private static final int PENDING_ASSIST_EXTRAS_LONG_TIMEOUT = 2000; |
| 398 | |
| 399 | // How long to wait in getAutofillAssistStructure() for the activity to respond with the result. |
| 400 | private static final int PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT = 2000; |
| 401 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 402 | // Permission tokens are used to temporarily granted a trusted app the ability to call |
| 403 | // #startActivityAsCaller. A client is expected to dump its token after this time has elapsed, |
| 404 | // showing any appropriate error messages to the user. |
| 405 | private static final long START_AS_CALLER_TOKEN_TIMEOUT = |
| 406 | 10 * MINUTE_IN_MILLIS; |
| 407 | |
| 408 | // How long before the service actually expires a token. This is slightly longer than |
| 409 | // START_AS_CALLER_TOKEN_TIMEOUT, to provide a buffer so clients will rarely encounter the |
| 410 | // expiration exception. |
| 411 | private static final long START_AS_CALLER_TOKEN_TIMEOUT_IMPL = |
| 412 | START_AS_CALLER_TOKEN_TIMEOUT + 2 * 1000; |
| 413 | |
| 414 | // How long the service will remember expired tokens, for the purpose of providing error |
| 415 | // messaging when a client uses an expired token. |
| 416 | private static final long START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT = |
| 417 | START_AS_CALLER_TOKEN_TIMEOUT_IMPL + 20 * MINUTE_IN_MILLIS; |
| 418 | |
| 419 | // Activity tokens of system activities that are delegating their call to |
| 420 | // #startActivityByCaller, keyed by the permissionToken granted to the delegate. |
| 421 | final HashMap<IBinder, IBinder> mStartActivitySources = new HashMap<>(); |
| 422 | |
| 423 | // Permission tokens that have expired, but we remember for error reporting. |
| 424 | final ArrayList<IBinder> mExpiredStartAsCallerTokens = new ArrayList<>(); |
| 425 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 426 | private final ArrayList<PendingAssistExtras> mPendingAssistExtras = new ArrayList<>(); |
| 427 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 428 | // Keeps track of the active voice interaction service component, notified from |
| 429 | // VoiceInteractionManagerService |
| 430 | ComponentName mActiveVoiceInteractionServiceComponent; |
| 431 | |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 432 | VrController mVrController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 433 | KeyguardController mKeyguardController; |
| 434 | private final ClientLifecycleManager mLifecycleManager; |
| 435 | private TaskChangeNotificationController mTaskChangeNotificationController; |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 436 | /** The controller for all operations related to locktask. */ |
| 437 | private LockTaskController mLockTaskController; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 438 | private ActivityStartController mActivityStartController; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 439 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 440 | boolean mSuppressResizeConfigChanges; |
| 441 | |
| 442 | private final UpdateConfigurationResult mTmpUpdateConfigurationResult = |
| 443 | new UpdateConfigurationResult(); |
| 444 | |
| 445 | static final class UpdateConfigurationResult { |
| 446 | // Configuration changes that were updated. |
| 447 | int changes; |
| 448 | // If the activity was relaunched to match the new configuration. |
| 449 | boolean activityRelaunched; |
| 450 | |
| 451 | void reset() { |
| 452 | changes = 0; |
| 453 | activityRelaunched = false; |
| 454 | } |
| 455 | } |
| 456 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 457 | /** Current sequencing integer of the configuration, for skipping old configurations. */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 458 | private int mConfigurationSeq; |
| 459 | // To cache the list of supported system locales |
| 460 | private String[] mSupportedSystemLocales = null; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 461 | |
| 462 | /** |
| 463 | * Temp object used when global and/or display override configuration is updated. It is also |
| 464 | * sent to outer world instead of {@link #getGlobalConfiguration} because we don't trust |
| 465 | * anyone... |
| 466 | */ |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 467 | private Configuration mTempConfig = new Configuration(); |
| 468 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 469 | /** Temporary to avoid allocations. */ |
| 470 | final StringBuilder mStringBuilder = new StringBuilder(256); |
| 471 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 472 | // Amount of time after a call to stopAppSwitches() during which we will |
| 473 | // prevent further untrusted switches from happening. |
| 474 | private static final long APP_SWITCH_DELAY_TIME = 5 * 1000; |
| 475 | |
| 476 | /** |
| 477 | * The time at which we will allow normal application switches again, |
| 478 | * after a call to {@link #stopAppSwitches()}. |
| 479 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 480 | private long mAppSwitchesAllowedTime; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 481 | /** |
| 482 | * This is set to true after the first switch after mAppSwitchesAllowedTime |
| 483 | * is set; any switches after that will clear the time. |
| 484 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 485 | private boolean mDidAppSwitch; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 486 | |
| 487 | IActivityController mController = null; |
| 488 | boolean mControllerIsAMonkey = false; |
| 489 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 490 | final int mFactoryTest; |
| 491 | |
| 492 | /** Used to control how we initialize the service. */ |
| 493 | ComponentName mTopComponent; |
| 494 | String mTopAction = Intent.ACTION_MAIN; |
| 495 | String mTopData; |
| 496 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 497 | /** Profiling app information. */ |
| 498 | String mProfileApp = null; |
| 499 | WindowProcessController mProfileProc = null; |
| 500 | ProfilerInfo mProfilerInfo = null; |
| 501 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 502 | /** |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 503 | * Dump of the activity state at the time of the last ANR. Cleared after |
| 504 | * {@link WindowManagerService#LAST_ANR_LIFETIME_DURATION_MSECS} |
| 505 | */ |
| 506 | String mLastANRState; |
| 507 | |
| 508 | /** |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 509 | * Used to retain an update lock when the foreground activity is in |
| 510 | * immersive mode. |
| 511 | */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 512 | private final UpdateLock mUpdateLock = new UpdateLock("immersive"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 513 | |
| 514 | /** |
| 515 | * Packages that are being allowed to perform unrestricted app switches. Mapping is |
| 516 | * User -> Type -> uid. |
| 517 | */ |
| 518 | final SparseArray<ArrayMap<String, Integer>> mAllowAppSwitchUids = new SparseArray<>(); |
| 519 | |
| 520 | /** The dimensions of the thumbnails in the Recents UI. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 521 | private int mThumbnailWidth; |
| 522 | private int mThumbnailHeight; |
| 523 | private float mFullscreenThumbnailScale; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 524 | |
| 525 | /** |
| 526 | * Flag that indicates if multi-window is enabled. |
| 527 | * |
| 528 | * For any particular form of multi-window to be enabled, generic multi-window must be enabled |
| 529 | * in {@link com.android.internal.R.bool#config_supportsMultiWindow} config or |
| 530 | * {@link Settings.Global#DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES} development option set. |
| 531 | * At least one of the forms of multi-window must be enabled in order for this flag to be |
| 532 | * initialized to 'true'. |
| 533 | * |
| 534 | * @see #mSupportsSplitScreenMultiWindow |
| 535 | * @see #mSupportsFreeformWindowManagement |
| 536 | * @see #mSupportsPictureInPicture |
| 537 | * @see #mSupportsMultiDisplay |
| 538 | */ |
| 539 | boolean mSupportsMultiWindow; |
| 540 | boolean mSupportsSplitScreenMultiWindow; |
| 541 | boolean mSupportsFreeformWindowManagement; |
| 542 | boolean mSupportsPictureInPicture; |
| 543 | boolean mSupportsMultiDisplay; |
| 544 | boolean mForceResizableActivities; |
| 545 | |
| 546 | final List<ActivityTaskManagerInternal.ScreenObserver> mScreenObservers = new ArrayList<>(); |
| 547 | |
| 548 | // VR Vr2d Display Id. |
| 549 | int mVr2dDisplayId = INVALID_DISPLAY; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 550 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 551 | /** |
| 552 | * Set while we are wanting to sleep, to prevent any |
| 553 | * activities from being started/resumed. |
| 554 | * |
| 555 | * TODO(b/33594039): Clarify the actual state transitions represented by mSleeping. |
| 556 | * |
| 557 | * Currently mSleeping is set to true when transitioning into the sleep state, and remains true |
| 558 | * while in the sleep state until there is a pending transition out of sleep, in which case |
| 559 | * mSleeping is set to false, and remains false while awake. |
| 560 | * |
| 561 | * Whether mSleeping can quickly toggled between true/false without the device actually |
| 562 | * display changing states is undefined. |
| 563 | */ |
| 564 | private boolean mSleeping = false; |
| 565 | |
| 566 | /** |
| 567 | * The process state used for processes that are running the top activities. |
| 568 | * This changes between TOP and TOP_SLEEPING to following mSleeping. |
| 569 | */ |
| 570 | int mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
| 571 | |
| 572 | // Whether we should show our dialogs (ANR, crash, etc) or just perform their default action |
| 573 | // automatically. Important for devices without direct input devices. |
| 574 | private boolean mShowDialogs = true; |
| 575 | |
| 576 | /** Set if we are shutting down the system, similar to sleeping. */ |
| 577 | boolean mShuttingDown = false; |
| 578 | |
| 579 | /** |
| 580 | * We want to hold a wake lock while running a voice interaction session, since |
| 581 | * this may happen with the screen off and we need to keep the CPU running to |
| 582 | * be able to continue to interact with the user. |
| 583 | */ |
| 584 | PowerManager.WakeLock mVoiceWakeLock; |
| 585 | |
| 586 | /** |
| 587 | * Set while we are running a voice interaction. This overrides sleeping while it is active. |
| 588 | */ |
| 589 | IVoiceInteractionSession mRunningVoice; |
| 590 | |
| 591 | /** |
| 592 | * The last resumed activity. This is identical to the current resumed activity most |
| 593 | * of the time but could be different when we're pausing one activity before we resume |
| 594 | * another activity. |
| 595 | */ |
| 596 | ActivityRecord mLastResumedActivity; |
| 597 | |
| 598 | /** |
| 599 | * The activity that is currently being traced as the active resumed activity. |
| 600 | * |
| 601 | * @see #updateResumedAppTrace |
| 602 | */ |
| 603 | private @Nullable ActivityRecord mTracedResumedActivity; |
| 604 | |
| 605 | /** If non-null, we are tracking the time the user spends in the currently focused app. */ |
| 606 | AppTimeTracker mCurAppTimeTracker; |
| 607 | |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 608 | private AppWarnings mAppWarnings; |
| 609 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 610 | /** |
| 611 | * Packages that the user has asked to have run in screen size |
| 612 | * compatibility mode instead of filling the screen. |
| 613 | */ |
| 614 | CompatModePackages mCompatModePackages; |
| 615 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 616 | private FontScaleSettingObserver mFontScaleSettingObserver; |
| 617 | |
| 618 | private final class FontScaleSettingObserver extends ContentObserver { |
| 619 | private final Uri mFontScaleUri = Settings.System.getUriFor(FONT_SCALE); |
| 620 | private final Uri mHideErrorDialogsUri = Settings.Global.getUriFor(HIDE_ERROR_DIALOGS); |
| 621 | |
| 622 | public FontScaleSettingObserver() { |
| 623 | super(mH); |
| 624 | final ContentResolver resolver = mContext.getContentResolver(); |
| 625 | resolver.registerContentObserver(mFontScaleUri, false, this, UserHandle.USER_ALL); |
| 626 | resolver.registerContentObserver(mHideErrorDialogsUri, false, this, |
| 627 | UserHandle.USER_ALL); |
| 628 | } |
| 629 | |
| 630 | @Override |
| 631 | public void onChange(boolean selfChange, Uri uri, @UserIdInt int userId) { |
| 632 | if (mFontScaleUri.equals(uri)) { |
| 633 | updateFontScaleIfNeeded(userId); |
| 634 | } else if (mHideErrorDialogsUri.equals(uri)) { |
| 635 | synchronized (mGlobalLock) { |
| 636 | updateShouldShowDialogsLocked(getGlobalConfiguration()); |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 642 | ActivityTaskManagerService(Context context) { |
| 643 | mContext = context; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 644 | mFactoryTest = FactoryTest.getMode(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 645 | mSystemThread = ActivityThread.currentActivityThread(); |
| 646 | mUiContext = mSystemThread.getSystemUiContext(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 647 | mLifecycleManager = new ClientLifecycleManager(); |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 648 | mInternal = new LocalService(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 649 | GL_ES_VERSION = SystemProperties.getInt("ro.opengles.version", GL_ES_VERSION_UNDEFINED); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 652 | public void onSystemReady() { |
| 653 | synchronized (mGlobalLock) { |
| 654 | mHasHeavyWeightFeature = mContext.getPackageManager().hasSystemFeature( |
| 655 | PackageManager.FEATURE_CANT_SAVE_STATE); |
| 656 | mAssistUtils = new AssistUtils(mContext); |
| 657 | mVrController.onSystemReady(); |
| 658 | mRecentTasks.onSystemReadyLocked(); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 659 | mStackSupervisor.onSystemReady(); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 660 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 663 | public void onInitPowerManagement() { |
| 664 | synchronized (mGlobalLock) { |
| 665 | mStackSupervisor.initPowerManagement(); |
| 666 | final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 667 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
| 668 | mVoiceWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*voice*"); |
| 669 | mVoiceWakeLock.setReferenceCounted(false); |
| 670 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 673 | public void installSystemProviders() { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 674 | mFontScaleSettingObserver = new FontScaleSettingObserver(); |
| 675 | } |
| 676 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 677 | public void retrieveSettings(ContentResolver resolver) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 678 | final boolean freeformWindowManagement = |
| 679 | mContext.getPackageManager().hasSystemFeature(FEATURE_FREEFORM_WINDOW_MANAGEMENT) |
| 680 | || Settings.Global.getInt( |
| 681 | resolver, DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0; |
| 682 | |
| 683 | final boolean supportsMultiWindow = ActivityTaskManager.supportsMultiWindow(mContext); |
| 684 | final boolean supportsPictureInPicture = supportsMultiWindow && |
| 685 | mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE); |
| 686 | final boolean supportsSplitScreenMultiWindow = |
| 687 | ActivityTaskManager.supportsSplitScreenMultiWindow(mContext); |
| 688 | final boolean supportsMultiDisplay = mContext.getPackageManager() |
| 689 | .hasSystemFeature(FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 690 | final boolean forceRtl = Settings.Global.getInt(resolver, DEVELOPMENT_FORCE_RTL, 0) != 0; |
| 691 | final boolean forceResizable = Settings.Global.getInt( |
| 692 | resolver, DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0; |
Garfield Tan | e084604 | 2018-07-26 13:42:04 -0700 | [diff] [blame] | 693 | final boolean isPc = mContext.getPackageManager().hasSystemFeature(FEATURE_PC); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 694 | |
| 695 | // Transfer any global setting for forcing RTL layout, into a System Property |
| 696 | SystemProperties.set(DEVELOPMENT_FORCE_RTL, forceRtl ? "1":"0"); |
| 697 | |
| 698 | final Configuration configuration = new Configuration(); |
| 699 | Settings.System.getConfiguration(resolver, configuration); |
| 700 | if (forceRtl) { |
| 701 | // This will take care of setting the correct layout direction flags |
| 702 | configuration.setLayoutDirection(configuration.locale); |
| 703 | } |
| 704 | |
| 705 | synchronized (mGlobalLock) { |
| 706 | mForceResizableActivities = forceResizable; |
| 707 | final boolean multiWindowFormEnabled = freeformWindowManagement |
| 708 | || supportsSplitScreenMultiWindow |
| 709 | || supportsPictureInPicture |
| 710 | || supportsMultiDisplay; |
| 711 | if ((supportsMultiWindow || forceResizable) && multiWindowFormEnabled) { |
| 712 | mSupportsMultiWindow = true; |
| 713 | mSupportsFreeformWindowManagement = freeformWindowManagement; |
| 714 | mSupportsSplitScreenMultiWindow = supportsSplitScreenMultiWindow; |
| 715 | mSupportsPictureInPicture = supportsPictureInPicture; |
| 716 | mSupportsMultiDisplay = supportsMultiDisplay; |
| 717 | } else { |
| 718 | mSupportsMultiWindow = false; |
| 719 | mSupportsFreeformWindowManagement = false; |
| 720 | mSupportsSplitScreenMultiWindow = false; |
| 721 | mSupportsPictureInPicture = false; |
| 722 | mSupportsMultiDisplay = false; |
| 723 | } |
| 724 | mWindowManager.setForceResizableTasks(mForceResizableActivities); |
| 725 | mWindowManager.setSupportsPictureInPicture(mSupportsPictureInPicture); |
Garfield Tan | e084604 | 2018-07-26 13:42:04 -0700 | [diff] [blame] | 726 | mWindowManager.setSupportsFreeformWindowManagement(mSupportsFreeformWindowManagement); |
| 727 | mWindowManager.setIsPc(isPc); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 728 | // This happens before any activities are started, so we can change global configuration |
| 729 | // in-place. |
| 730 | updateConfigurationLocked(configuration, null, true); |
| 731 | final Configuration globalConfig = getGlobalConfiguration(); |
| 732 | if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Initial config: " + globalConfig); |
| 733 | |
| 734 | // Load resources only after the current configuration has been set. |
| 735 | final Resources res = mContext.getResources(); |
| 736 | mThumbnailWidth = res.getDimensionPixelSize( |
| 737 | com.android.internal.R.dimen.thumbnail_width); |
| 738 | mThumbnailHeight = res.getDimensionPixelSize( |
| 739 | com.android.internal.R.dimen.thumbnail_height); |
| 740 | |
| 741 | if ((globalConfig.uiMode & UI_MODE_TYPE_TELEVISION) == UI_MODE_TYPE_TELEVISION) { |
| 742 | mFullscreenThumbnailScale = (float) res |
| 743 | .getInteger(com.android.internal.R.integer.thumbnail_width_tv) / |
| 744 | (float) globalConfig.screenWidthDp; |
| 745 | } else { |
| 746 | mFullscreenThumbnailScale = res.getFraction( |
| 747 | com.android.internal.R.fraction.thumbnail_fullscreen_scale, 1, 1); |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 752 | public WindowManagerGlobalLock getGlobalLock() { |
| 753 | return mGlobalLock; |
| 754 | } |
| 755 | |
| 756 | public void setActivityManagerService(IntentFirewall intentFirewall, |
| 757 | PendingIntentController intentController) { |
| 758 | mH = new H(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 759 | mUiHandler = new UiHandler(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 760 | mIntentFirewall = intentFirewall; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 761 | final File systemDir = SystemServiceManager.ensureSystemDir(); |
| 762 | mAppWarnings = new AppWarnings(this, mUiContext, mH, mUiHandler, systemDir); |
| 763 | mCompatModePackages = new CompatModePackages(this, systemDir, mH); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 764 | mPendingIntentController = intentController; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 765 | |
| 766 | mTempConfig.setToDefaults(); |
| 767 | mTempConfig.setLocales(LocaleList.getDefault()); |
| 768 | mConfigurationSeq = mTempConfig.seq = 1; |
| 769 | mStackSupervisor = createStackSupervisor(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 770 | mRootActivityContainer = new RootActivityContainer(this); |
| 771 | mRootActivityContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 772 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 773 | mTaskChangeNotificationController = |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 774 | new TaskChangeNotificationController(mGlobalLock, mStackSupervisor, mH); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 775 | mLockTaskController = new LockTaskController(mContext, mStackSupervisor, mH); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 776 | mActivityStartController = new ActivityStartController(this); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 777 | mRecentTasks = createRecentTasks(); |
| 778 | mStackSupervisor.setRecentTasks(mRecentTasks); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 779 | mVrController = new VrController(mGlobalLock); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 780 | mKeyguardController = mStackSupervisor.getKeyguardController(); |
| 781 | } |
| 782 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 783 | public void onActivityManagerInternalAdded() { |
| 784 | synchronized (mGlobalLock) { |
| 785 | mAmInternal = LocalServices.getService(ActivityManagerInternal.class); |
| 786 | mUgmInternal = LocalServices.getService(UriGrantsManagerInternal.class); |
| 787 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 790 | int increaseConfigurationSeqLocked() { |
| 791 | mConfigurationSeq = Math.max(++mConfigurationSeq, 1); |
| 792 | return mConfigurationSeq; |
| 793 | } |
| 794 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 795 | protected ActivityStackSupervisor createStackSupervisor() { |
| 796 | final ActivityStackSupervisor supervisor = new ActivityStackSupervisor(this, mH.getLooper()); |
| 797 | supervisor.initialize(); |
| 798 | return supervisor; |
| 799 | } |
| 800 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 801 | public void setWindowManager(WindowManagerService wm) { |
| 802 | synchronized (mGlobalLock) { |
| 803 | mWindowManager = wm; |
| 804 | mLockTaskController.setWindowManager(wm); |
| 805 | mStackSupervisor.setWindowManager(wm); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 806 | mRootActivityContainer.setWindowManager(wm); |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 807 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 810 | public void setUsageStatsManager(UsageStatsManagerInternal usageStatsManager) { |
| 811 | synchronized (mGlobalLock) { |
| 812 | mUsageStatsInternal = usageStatsManager; |
| 813 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 816 | UserManagerService getUserManager() { |
| 817 | if (mUserManager == null) { |
| 818 | IBinder b = ServiceManager.getService(Context.USER_SERVICE); |
| 819 | mUserManager = (UserManagerService) IUserManager.Stub.asInterface(b); |
| 820 | } |
| 821 | return mUserManager; |
| 822 | } |
| 823 | |
| 824 | AppOpsService getAppOpsService() { |
| 825 | if (mAppOpsService == null) { |
| 826 | IBinder b = ServiceManager.getService(Context.APP_OPS_SERVICE); |
| 827 | mAppOpsService = (AppOpsService) IAppOpsService.Stub.asInterface(b); |
| 828 | } |
| 829 | return mAppOpsService; |
| 830 | } |
| 831 | |
| 832 | boolean hasUserRestriction(String restriction, int userId) { |
| 833 | return getUserManager().hasUserRestriction(restriction, userId); |
| 834 | } |
| 835 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 836 | protected RecentTasks createRecentTasks() { |
| 837 | return new RecentTasks(this, mStackSupervisor); |
| 838 | } |
| 839 | |
| 840 | RecentTasks getRecentTasks() { |
| 841 | return mRecentTasks; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 844 | ClientLifecycleManager getLifecycleManager() { |
| 845 | return mLifecycleManager; |
| 846 | } |
| 847 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 848 | ActivityStartController getActivityStartController() { |
| 849 | return mActivityStartController; |
| 850 | } |
| 851 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 852 | TaskChangeNotificationController getTaskChangeNotificationController() { |
| 853 | return mTaskChangeNotificationController; |
| 854 | } |
| 855 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 856 | LockTaskController getLockTaskController() { |
| 857 | return mLockTaskController; |
| 858 | } |
| 859 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 860 | /** |
| 861 | * Return the global configuration used by the process corresponding to the input pid. This is |
| 862 | * usually the global configuration with some overrides specific to that process. |
| 863 | */ |
| 864 | Configuration getGlobalConfigurationForCallingPid() { |
| 865 | final int pid = Binder.getCallingPid(); |
| 866 | if (pid == MY_PID || pid < 0) { |
| 867 | return getGlobalConfiguration(); |
| 868 | } |
| 869 | synchronized (mGlobalLock) { |
| 870 | final WindowProcessController app = mPidMap.get(pid); |
| 871 | return app != null ? app.getConfiguration() : getGlobalConfiguration(); |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | /** |
| 876 | * Return the device configuration info used by the process corresponding to the input pid. |
| 877 | * The value is consistent with the global configuration for the process. |
| 878 | */ |
| 879 | @Override |
| 880 | public ConfigurationInfo getDeviceConfigurationInfo() { |
| 881 | ConfigurationInfo config = new ConfigurationInfo(); |
| 882 | synchronized (mGlobalLock) { |
| 883 | final Configuration globalConfig = getGlobalConfigurationForCallingPid(); |
| 884 | config.reqTouchScreen = globalConfig.touchscreen; |
| 885 | config.reqKeyboardType = globalConfig.keyboard; |
| 886 | config.reqNavigation = globalConfig.navigation; |
| 887 | if (globalConfig.navigation == Configuration.NAVIGATION_DPAD |
| 888 | || globalConfig.navigation == Configuration.NAVIGATION_TRACKBALL) { |
| 889 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV; |
| 890 | } |
| 891 | if (globalConfig.keyboard != Configuration.KEYBOARD_UNDEFINED |
| 892 | && globalConfig.keyboard != Configuration.KEYBOARD_NOKEYS) { |
| 893 | config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD; |
| 894 | } |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 895 | config.reqGlEsVersion = GL_ES_VERSION; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 896 | } |
| 897 | return config; |
| 898 | } |
| 899 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 900 | private void start() { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 901 | LocalServices.addService(ActivityTaskManagerInternal.class, mInternal); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 904 | public static final class Lifecycle extends SystemService { |
| 905 | private final ActivityTaskManagerService mService; |
| 906 | |
| 907 | public Lifecycle(Context context) { |
| 908 | super(context); |
| 909 | mService = new ActivityTaskManagerService(context); |
| 910 | } |
| 911 | |
| 912 | @Override |
| 913 | public void onStart() { |
| 914 | publishBinderService(Context.ACTIVITY_TASK_SERVICE, mService); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 915 | mService.start(); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 916 | } |
| 917 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 918 | @Override |
| 919 | public void onUnlockUser(int userId) { |
| 920 | synchronized (mService.getGlobalLock()) { |
| 921 | mService.mStackSupervisor.mLaunchParamsPersister.onUnlockUser(userId); |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | @Override |
| 926 | public void onCleanupUser(int userId) { |
| 927 | synchronized (mService.getGlobalLock()) { |
| 928 | mService.mStackSupervisor.mLaunchParamsPersister.onCleanupUser(userId); |
| 929 | } |
| 930 | } |
| 931 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 932 | public ActivityTaskManagerService getService() { |
| 933 | return mService; |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 938 | public final int startActivity(IApplicationThread caller, String callingPackage, |
| 939 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 940 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions) { |
| 941 | return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo, |
| 942 | resultWho, requestCode, startFlags, profilerInfo, bOptions, |
| 943 | UserHandle.getCallingUserId()); |
| 944 | } |
| 945 | |
| 946 | @Override |
| 947 | public final int startActivities(IApplicationThread caller, String callingPackage, |
| 948 | Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle bOptions, |
| 949 | int userId) { |
| 950 | final String reason = "startActivities"; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 951 | enforceNotIsolatedCaller(reason); |
| 952 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, reason); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 953 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 954 | return getActivityStartController().startActivities(caller, -1, callingPackage, intents, |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 955 | resolvedTypes, resultTo, SafeActivityOptions.fromBundle(bOptions), userId, reason, |
| 956 | null /* originatingPendingIntent */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | @Override |
| 960 | public int startActivityAsUser(IApplicationThread caller, String callingPackage, |
| 961 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 962 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId) { |
| 963 | return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo, |
| 964 | resultWho, requestCode, startFlags, profilerInfo, bOptions, userId, |
| 965 | true /*validateIncomingUser*/); |
| 966 | } |
| 967 | |
| 968 | int startActivityAsUser(IApplicationThread caller, String callingPackage, |
| 969 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 970 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId, |
| 971 | boolean validateIncomingUser) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 972 | enforceNotIsolatedCaller("startActivityAsUser"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 973 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 974 | userId = getActivityStartController().checkTargetUser(userId, validateIncomingUser, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 975 | Binder.getCallingPid(), Binder.getCallingUid(), "startActivityAsUser"); |
| 976 | |
| 977 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 978 | return getActivityStartController().obtainStarter(intent, "startActivityAsUser") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 979 | .setCaller(caller) |
| 980 | .setCallingPackage(callingPackage) |
| 981 | .setResolvedType(resolvedType) |
| 982 | .setResultTo(resultTo) |
| 983 | .setResultWho(resultWho) |
| 984 | .setRequestCode(requestCode) |
| 985 | .setStartFlags(startFlags) |
| 986 | .setProfilerInfo(profilerInfo) |
| 987 | .setActivityOptions(bOptions) |
| 988 | .setMayWait(userId) |
| 989 | .execute(); |
| 990 | |
| 991 | } |
| 992 | |
| 993 | @Override |
| 994 | public int startActivityIntentSender(IApplicationThread caller, IIntentSender target, |
| 995 | IBinder whitelistToken, Intent fillInIntent, String resolvedType, IBinder resultTo, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 996 | String resultWho, int requestCode, int flagsMask, int flagsValues, Bundle bOptions) { |
| 997 | enforceNotIsolatedCaller("startActivityIntentSender"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 998 | // Refuse possible leaked file descriptors |
| 999 | if (fillInIntent != null && fillInIntent.hasFileDescriptors()) { |
| 1000 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1001 | } |
| 1002 | |
| 1003 | if (!(target instanceof PendingIntentRecord)) { |
| 1004 | throw new IllegalArgumentException("Bad PendingIntent object"); |
| 1005 | } |
| 1006 | |
| 1007 | PendingIntentRecord pir = (PendingIntentRecord)target; |
| 1008 | |
| 1009 | synchronized (mGlobalLock) { |
| 1010 | // If this is coming from the currently resumed activity, it is |
| 1011 | // effectively saying that app switches are allowed at this point. |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1012 | final ActivityStack stack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1013 | if (stack.mResumedActivity != null && |
| 1014 | stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1015 | mAppSwitchesAllowedTime = 0; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1016 | } |
| 1017 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1018 | return pir.sendInner(0, fillInIntent, resolvedType, whitelistToken, null, null, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1019 | resultTo, resultWho, requestCode, flagsMask, flagsValues, bOptions); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | @Override |
| 1023 | public boolean startNextMatchingActivity(IBinder callingActivity, Intent intent, |
| 1024 | Bundle bOptions) { |
| 1025 | // Refuse possible leaked file descriptors |
| 1026 | if (intent != null && intent.hasFileDescriptors()) { |
| 1027 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1028 | } |
| 1029 | SafeActivityOptions options = SafeActivityOptions.fromBundle(bOptions); |
| 1030 | |
| 1031 | synchronized (mGlobalLock) { |
| 1032 | final ActivityRecord r = ActivityRecord.isInStackLocked(callingActivity); |
| 1033 | if (r == null) { |
| 1034 | SafeActivityOptions.abort(options); |
| 1035 | return false; |
| 1036 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1037 | if (!r.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1038 | // The caller is not running... d'oh! |
| 1039 | SafeActivityOptions.abort(options); |
| 1040 | return false; |
| 1041 | } |
| 1042 | intent = new Intent(intent); |
| 1043 | // The caller is not allowed to change the data. |
| 1044 | intent.setDataAndType(r.intent.getData(), r.intent.getType()); |
| 1045 | // And we are resetting to find the next component... |
| 1046 | intent.setComponent(null); |
| 1047 | |
| 1048 | final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0); |
| 1049 | |
| 1050 | ActivityInfo aInfo = null; |
| 1051 | try { |
| 1052 | List<ResolveInfo> resolves = |
| 1053 | AppGlobals.getPackageManager().queryIntentActivities( |
| 1054 | intent, r.resolvedType, |
| 1055 | PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS, |
| 1056 | UserHandle.getCallingUserId()).getList(); |
| 1057 | |
| 1058 | // Look for the original activity in the list... |
| 1059 | final int N = resolves != null ? resolves.size() : 0; |
| 1060 | for (int i=0; i<N; i++) { |
| 1061 | ResolveInfo rInfo = resolves.get(i); |
| 1062 | if (rInfo.activityInfo.packageName.equals(r.packageName) |
| 1063 | && rInfo.activityInfo.name.equals(r.info.name)) { |
| 1064 | // We found the current one... the next matching is |
| 1065 | // after it. |
| 1066 | i++; |
| 1067 | if (i<N) { |
| 1068 | aInfo = resolves.get(i).activityInfo; |
| 1069 | } |
| 1070 | if (debug) { |
| 1071 | Slog.v(TAG, "Next matching activity: found current " + r.packageName |
| 1072 | + "/" + r.info.name); |
| 1073 | Slog.v(TAG, "Next matching activity: next is " + ((aInfo == null) |
| 1074 | ? "null" : aInfo.packageName + "/" + aInfo.name)); |
| 1075 | } |
| 1076 | break; |
| 1077 | } |
| 1078 | } |
| 1079 | } catch (RemoteException e) { |
| 1080 | } |
| 1081 | |
| 1082 | if (aInfo == null) { |
| 1083 | // Nobody who is next! |
| 1084 | SafeActivityOptions.abort(options); |
| 1085 | if (debug) Slog.d(TAG, "Next matching activity: nothing found"); |
| 1086 | return false; |
| 1087 | } |
| 1088 | |
| 1089 | intent.setComponent(new ComponentName( |
| 1090 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1091 | intent.setFlags(intent.getFlags()&~( |
| 1092 | Intent.FLAG_ACTIVITY_FORWARD_RESULT| |
| 1093 | Intent.FLAG_ACTIVITY_CLEAR_TOP| |
| 1094 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK| |
| 1095 | FLAG_ACTIVITY_NEW_TASK)); |
| 1096 | |
| 1097 | // Okay now we need to start the new activity, replacing the currently running activity. |
| 1098 | // This is a little tricky because we want to start the new one as if the current one is |
| 1099 | // finished, but not finish the current one first so that there is no flicker. |
| 1100 | // And thus... |
| 1101 | final boolean wasFinishing = r.finishing; |
| 1102 | r.finishing = true; |
| 1103 | |
| 1104 | // Propagate reply information over to the new activity. |
| 1105 | final ActivityRecord resultTo = r.resultTo; |
| 1106 | final String resultWho = r.resultWho; |
| 1107 | final int requestCode = r.requestCode; |
| 1108 | r.resultTo = null; |
| 1109 | if (resultTo != null) { |
| 1110 | resultTo.removeResultsLocked(r, resultWho, requestCode); |
| 1111 | } |
| 1112 | |
| 1113 | final long origId = Binder.clearCallingIdentity(); |
| 1114 | // TODO(b/64750076): Check if calling pid should really be -1. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1115 | final int res = getActivityStartController() |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1116 | .obtainStarter(intent, "startNextMatchingActivity") |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1117 | .setCaller(r.app.getThread()) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1118 | .setResolvedType(r.resolvedType) |
| 1119 | .setActivityInfo(aInfo) |
| 1120 | .setResultTo(resultTo != null ? resultTo.appToken : null) |
| 1121 | .setResultWho(resultWho) |
| 1122 | .setRequestCode(requestCode) |
| 1123 | .setCallingPid(-1) |
| 1124 | .setCallingUid(r.launchedFromUid) |
| 1125 | .setCallingPackage(r.launchedFromPackage) |
| 1126 | .setRealCallingPid(-1) |
| 1127 | .setRealCallingUid(r.launchedFromUid) |
| 1128 | .setActivityOptions(options) |
| 1129 | .execute(); |
| 1130 | Binder.restoreCallingIdentity(origId); |
| 1131 | |
| 1132 | r.finishing = wasFinishing; |
| 1133 | if (res != ActivityManager.START_SUCCESS) { |
| 1134 | return false; |
| 1135 | } |
| 1136 | return true; |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | @Override |
| 1141 | public final WaitResult startActivityAndWait(IApplicationThread caller, String callingPackage, |
| 1142 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1143 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId) { |
| 1144 | final WaitResult res = new WaitResult(); |
| 1145 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1146 | enforceNotIsolatedCaller("startActivityAndWait"); |
| 1147 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 1148 | userId, "startActivityAndWait"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1149 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1150 | getActivityStartController().obtainStarter(intent, "startActivityAndWait") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1151 | .setCaller(caller) |
| 1152 | .setCallingPackage(callingPackage) |
| 1153 | .setResolvedType(resolvedType) |
| 1154 | .setResultTo(resultTo) |
| 1155 | .setResultWho(resultWho) |
| 1156 | .setRequestCode(requestCode) |
| 1157 | .setStartFlags(startFlags) |
| 1158 | .setActivityOptions(bOptions) |
| 1159 | .setMayWait(userId) |
| 1160 | .setProfilerInfo(profilerInfo) |
| 1161 | .setWaitResult(res) |
| 1162 | .execute(); |
| 1163 | } |
| 1164 | return res; |
| 1165 | } |
| 1166 | |
| 1167 | @Override |
| 1168 | public final int startActivityWithConfig(IApplicationThread caller, String callingPackage, |
| 1169 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
| 1170 | int startFlags, Configuration config, Bundle bOptions, int userId) { |
| 1171 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1172 | enforceNotIsolatedCaller("startActivityWithConfig"); |
| 1173 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, |
| 1174 | "startActivityWithConfig"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1175 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1176 | return getActivityStartController().obtainStarter(intent, "startActivityWithConfig") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1177 | .setCaller(caller) |
| 1178 | .setCallingPackage(callingPackage) |
| 1179 | .setResolvedType(resolvedType) |
| 1180 | .setResultTo(resultTo) |
| 1181 | .setResultWho(resultWho) |
| 1182 | .setRequestCode(requestCode) |
| 1183 | .setStartFlags(startFlags) |
| 1184 | .setGlobalConfiguration(config) |
| 1185 | .setActivityOptions(bOptions) |
| 1186 | .setMayWait(userId) |
| 1187 | .execute(); |
| 1188 | } |
| 1189 | } |
| 1190 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1191 | |
| 1192 | @Override |
| 1193 | public IBinder requestStartActivityPermissionToken(IBinder delegatorToken) { |
| 1194 | int callingUid = Binder.getCallingUid(); |
| 1195 | if (UserHandle.getAppId(callingUid) != SYSTEM_UID) { |
| 1196 | throw new SecurityException("Only the system process can request a permission token, " |
| 1197 | + "received request from uid: " + callingUid); |
| 1198 | } |
| 1199 | IBinder permissionToken = new Binder(); |
| 1200 | synchronized (mGlobalLock) { |
| 1201 | mStartActivitySources.put(permissionToken, delegatorToken); |
| 1202 | } |
| 1203 | |
| 1204 | Message expireMsg = PooledLambda.obtainMessage( |
| 1205 | ActivityTaskManagerService::expireStartAsCallerTokenMsg, this, permissionToken); |
| 1206 | mUiHandler.sendMessageDelayed(expireMsg, START_AS_CALLER_TOKEN_TIMEOUT_IMPL); |
| 1207 | |
| 1208 | Message forgetMsg = PooledLambda.obtainMessage( |
| 1209 | ActivityTaskManagerService::forgetStartAsCallerTokenMsg, this, permissionToken); |
| 1210 | mUiHandler.sendMessageDelayed(forgetMsg, START_AS_CALLER_TOKEN_EXPIRED_TIMEOUT); |
| 1211 | |
| 1212 | return permissionToken; |
| 1213 | } |
| 1214 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1215 | @Override |
| 1216 | public final int startActivityAsCaller(IApplicationThread caller, String callingPackage, |
| 1217 | Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode, |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1218 | int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, IBinder permissionToken, |
| 1219 | boolean ignoreTargetSecurity, int userId) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1220 | // 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] | 1221 | // permission grants) as any app that may launch one of your own activities. So we only |
| 1222 | // allow this in two cases: |
| 1223 | // 1) The caller is an activity that is part of the core framework, and then only when it |
| 1224 | // is running as the system. |
| 1225 | // 2) The caller provides a valid permissionToken. Permission tokens are one-time use and |
| 1226 | // can only be requested by a system activity, which may then delegate this call to |
| 1227 | // another app. |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1228 | final ActivityRecord sourceRecord; |
| 1229 | final int targetUid; |
| 1230 | final String targetPackage; |
| 1231 | final boolean isResolver; |
| 1232 | synchronized (mGlobalLock) { |
| 1233 | if (resultTo == null) { |
| 1234 | throw new SecurityException("Must be called from an activity"); |
| 1235 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1236 | final IBinder sourceToken; |
| 1237 | if (permissionToken != null) { |
| 1238 | // To even attempt to use a permissionToken, an app must also have this signature |
| 1239 | // permission. |
| 1240 | mAmInternal.enforceCallingPermission( |
| 1241 | android.Manifest.permission.START_ACTIVITY_AS_CALLER, |
| 1242 | "startActivityAsCaller"); |
| 1243 | // If called with a permissionToken, we want the sourceRecord from the delegator |
| 1244 | // activity that requested this token. |
| 1245 | sourceToken = mStartActivitySources.remove(permissionToken); |
| 1246 | if (sourceToken == null) { |
| 1247 | // Invalid permissionToken, check if it recently expired. |
| 1248 | if (mExpiredStartAsCallerTokens.contains(permissionToken)) { |
| 1249 | throw new SecurityException("Called with expired permission token: " |
| 1250 | + permissionToken); |
| 1251 | } else { |
| 1252 | throw new SecurityException("Called with invalid permission token: " |
| 1253 | + permissionToken); |
| 1254 | } |
| 1255 | } |
| 1256 | } else { |
| 1257 | // This method was called directly by the source. |
| 1258 | sourceToken = resultTo; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1259 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1260 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1261 | sourceRecord = mRootActivityContainer.isInAnyStack(sourceToken); |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1262 | if (sourceRecord == null) { |
| 1263 | throw new SecurityException("Called with bad activity token: " + sourceToken); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1264 | } |
| 1265 | if (sourceRecord.app == null) { |
| 1266 | throw new SecurityException("Called without a process attached to activity"); |
| 1267 | } |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 1268 | |
| 1269 | // Whether called directly or from a delegate, the source activity must be from the |
| 1270 | // android package. |
| 1271 | if (!sourceRecord.info.packageName.equals("android")) { |
| 1272 | throw new SecurityException("Must be called from an activity that is " |
| 1273 | + "declared in the android package"); |
| 1274 | } |
| 1275 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1276 | if (UserHandle.getAppId(sourceRecord.app.mUid) != SYSTEM_UID) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1277 | // This is still okay, as long as this activity is running under the |
| 1278 | // uid of the original calling activity. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1279 | if (sourceRecord.app.mUid != sourceRecord.launchedFromUid) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1280 | throw new SecurityException( |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1281 | "Calling activity in uid " + sourceRecord.app.mUid |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1282 | + " must be system uid or original calling uid " |
| 1283 | + sourceRecord.launchedFromUid); |
| 1284 | } |
| 1285 | } |
| 1286 | if (ignoreTargetSecurity) { |
| 1287 | if (intent.getComponent() == null) { |
| 1288 | throw new SecurityException( |
| 1289 | "Component must be specified with ignoreTargetSecurity"); |
| 1290 | } |
| 1291 | if (intent.getSelector() != null) { |
| 1292 | throw new SecurityException( |
| 1293 | "Selector not allowed with ignoreTargetSecurity"); |
| 1294 | } |
| 1295 | } |
| 1296 | targetUid = sourceRecord.launchedFromUid; |
| 1297 | targetPackage = sourceRecord.launchedFromPackage; |
| 1298 | isResolver = sourceRecord.isResolverOrChildActivity(); |
| 1299 | } |
| 1300 | |
| 1301 | if (userId == UserHandle.USER_NULL) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1302 | userId = UserHandle.getUserId(sourceRecord.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | // TODO: Switch to user app stacks here. |
| 1306 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1307 | return getActivityStartController().obtainStarter(intent, "startActivityAsCaller") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1308 | .setCallingUid(targetUid) |
| 1309 | .setCallingPackage(targetPackage) |
| 1310 | .setResolvedType(resolvedType) |
| 1311 | .setResultTo(resultTo) |
| 1312 | .setResultWho(resultWho) |
| 1313 | .setRequestCode(requestCode) |
| 1314 | .setStartFlags(startFlags) |
| 1315 | .setActivityOptions(bOptions) |
| 1316 | .setMayWait(userId) |
| 1317 | .setIgnoreTargetSecurity(ignoreTargetSecurity) |
| 1318 | .setFilterCallingUid(isResolver ? 0 /* system */ : targetUid) |
| 1319 | .execute(); |
| 1320 | } catch (SecurityException e) { |
| 1321 | // XXX need to figure out how to propagate to original app. |
| 1322 | // A SecurityException here is generally actually a fault of the original |
| 1323 | // calling activity (such as a fairly granting permissions), so propagate it |
| 1324 | // back to them. |
| 1325 | /* |
| 1326 | StringBuilder msg = new StringBuilder(); |
| 1327 | msg.append("While launching"); |
| 1328 | msg.append(intent.toString()); |
| 1329 | msg.append(": "); |
| 1330 | msg.append(e.getMessage()); |
| 1331 | */ |
| 1332 | throw e; |
| 1333 | } |
| 1334 | } |
| 1335 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1336 | int handleIncomingUser(int callingPid, int callingUid, int userId, String name) { |
| 1337 | return mAmInternal.handleIncomingUser(callingPid, callingUid, userId, false /* allowAll */, |
| 1338 | ALLOW_FULL_ONLY, name, null /* callerPackage */); |
| 1339 | } |
| 1340 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1341 | @Override |
| 1342 | public int startVoiceActivity(String callingPackage, int callingPid, int callingUid, |
| 1343 | Intent intent, String resolvedType, IVoiceInteractionSession session, |
| 1344 | IVoiceInteractor interactor, int startFlags, ProfilerInfo profilerInfo, |
| 1345 | Bundle bOptions, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1346 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startVoiceActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1347 | if (session == null || interactor == null) { |
| 1348 | throw new NullPointerException("null session or interactor"); |
| 1349 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1350 | userId = handleIncomingUser(callingPid, callingUid, userId, "startVoiceActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1351 | // TODO: Switch to user app stacks here. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1352 | return getActivityStartController().obtainStarter(intent, "startVoiceActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1353 | .setCallingUid(callingUid) |
| 1354 | .setCallingPackage(callingPackage) |
| 1355 | .setResolvedType(resolvedType) |
| 1356 | .setVoiceSession(session) |
| 1357 | .setVoiceInteractor(interactor) |
| 1358 | .setStartFlags(startFlags) |
| 1359 | .setProfilerInfo(profilerInfo) |
| 1360 | .setActivityOptions(bOptions) |
| 1361 | .setMayWait(userId) |
| 1362 | .execute(); |
| 1363 | } |
| 1364 | |
| 1365 | @Override |
| 1366 | public int startAssistantActivity(String callingPackage, int callingPid, int callingUid, |
| 1367 | Intent intent, String resolvedType, Bundle bOptions, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1368 | mAmInternal.enforceCallingPermission(BIND_VOICE_INTERACTION, "startAssistantActivity()"); |
| 1369 | userId = handleIncomingUser(callingPid, callingUid, userId, "startAssistantActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1370 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1371 | return getActivityStartController().obtainStarter(intent, "startAssistantActivity") |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1372 | .setCallingUid(callingUid) |
| 1373 | .setCallingPackage(callingPackage) |
| 1374 | .setResolvedType(resolvedType) |
| 1375 | .setActivityOptions(bOptions) |
| 1376 | .setMayWait(userId) |
| 1377 | .execute(); |
| 1378 | } |
| 1379 | |
| 1380 | @Override |
| 1381 | public void startRecentsActivity(Intent intent, IAssistDataReceiver assistDataReceiver, |
| 1382 | IRecentsAnimationRunner recentsAnimationRunner) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1383 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "startRecentsActivity()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1384 | final int callingPid = Binder.getCallingPid(); |
| 1385 | final long origId = Binder.clearCallingIdentity(); |
| 1386 | try { |
| 1387 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 1388 | final ComponentName recentsComponent = mRecentTasks.getRecentsComponent(); |
| 1389 | final int recentsUid = mRecentTasks.getRecentsComponentUid(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1390 | |
| 1391 | // Start a new recents animation |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1392 | final RecentsAnimation anim = new RecentsAnimation(this, mStackSupervisor, |
| 1393 | getActivityStartController(), mWindowManager, callingPid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1394 | anim.startRecentsActivity(intent, recentsAnimationRunner, recentsComponent, |
| 1395 | recentsUid, assistDataReceiver); |
| 1396 | } |
| 1397 | } finally { |
| 1398 | Binder.restoreCallingIdentity(origId); |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | @Override |
| 1403 | public final int startActivityFromRecents(int taskId, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1404 | enforceCallerIsRecentsOrHasPermission(START_TASKS_FROM_RECENTS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1405 | "startActivityFromRecents()"); |
| 1406 | |
| 1407 | final int callingPid = Binder.getCallingPid(); |
| 1408 | final int callingUid = Binder.getCallingUid(); |
| 1409 | final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(bOptions); |
| 1410 | final long origId = Binder.clearCallingIdentity(); |
| 1411 | try { |
| 1412 | synchronized (mGlobalLock) { |
| 1413 | return mStackSupervisor.startActivityFromRecents(callingPid, callingUid, taskId, |
| 1414 | safeOptions); |
| 1415 | } |
| 1416 | } finally { |
| 1417 | Binder.restoreCallingIdentity(origId); |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | /** |
| 1422 | * This is the internal entry point for handling Activity.finish(). |
| 1423 | * |
| 1424 | * @param token The Binder token referencing the Activity we want to finish. |
| 1425 | * @param resultCode Result code, if any, from this Activity. |
| 1426 | * @param resultData Result data (Intent), if any, from this Activity. |
| 1427 | * @param finishTask Whether to finish the task associated with this Activity. |
| 1428 | * |
| 1429 | * @return Returns true if the activity successfully finished, or false if it is still running. |
| 1430 | */ |
| 1431 | @Override |
| 1432 | public final boolean finishActivity(IBinder token, int resultCode, Intent resultData, |
| 1433 | int finishTask) { |
| 1434 | // Refuse possible leaked file descriptors |
| 1435 | if (resultData != null && resultData.hasFileDescriptors()) { |
| 1436 | throw new IllegalArgumentException("File descriptors passed in Intent"); |
| 1437 | } |
| 1438 | |
| 1439 | synchronized (mGlobalLock) { |
| 1440 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1441 | if (r == null) { |
| 1442 | return true; |
| 1443 | } |
| 1444 | // Keep track of the root activity of the task before we finish it |
| 1445 | TaskRecord tr = r.getTask(); |
| 1446 | ActivityRecord rootR = tr.getRootActivity(); |
| 1447 | if (rootR == null) { |
| 1448 | Slog.w(TAG, "Finishing task with all activities already finished"); |
| 1449 | } |
| 1450 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps can |
| 1451 | // finish. |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1452 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1453 | return false; |
| 1454 | } |
| 1455 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1456 | // TODO: There is a dup. of this block of code in ActivityStack.navigateUpToLocked |
| 1457 | // We should consolidate. |
| 1458 | if (mController != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1459 | // Find the first activity that is not finishing. |
| 1460 | ActivityRecord next = r.getStack().topRunningActivityLocked(token, 0); |
| 1461 | if (next != null) { |
| 1462 | // ask watcher if this is allowed |
| 1463 | boolean resumeOK = true; |
| 1464 | try { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1465 | resumeOK = mController.activityResuming(next.packageName); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1466 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1467 | mController = null; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1468 | Watchdog.getInstance().setActivityController(null); |
| 1469 | } |
| 1470 | |
| 1471 | if (!resumeOK) { |
| 1472 | Slog.i(TAG, "Not finishing activity because controller resumed"); |
| 1473 | return false; |
| 1474 | } |
| 1475 | } |
| 1476 | } |
| 1477 | final long origId = Binder.clearCallingIdentity(); |
| 1478 | try { |
| 1479 | boolean res; |
| 1480 | final boolean finishWithRootActivity = |
| 1481 | finishTask == Activity.FINISH_TASK_WITH_ROOT_ACTIVITY; |
| 1482 | if (finishTask == Activity.FINISH_TASK_WITH_ACTIVITY |
| 1483 | || (finishWithRootActivity && r == rootR)) { |
| 1484 | // If requested, remove the task that is associated to this activity only if it |
| 1485 | // was the root activity in the task. The result code and data is ignored |
| 1486 | // because we don't support returning them across task boundaries. Also, to |
| 1487 | // keep backwards compatibility we remove the task from recents when finishing |
| 1488 | // task with root activity. |
| 1489 | res = mStackSupervisor.removeTaskByIdLocked(tr.taskId, false, |
| 1490 | finishWithRootActivity, "finish-activity"); |
| 1491 | if (!res) { |
| 1492 | Slog.i(TAG, "Removing task failed to finish activity"); |
| 1493 | } |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 1494 | // Explicitly dismissing the activity so reset its relaunch flag. |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 1495 | r.mRelaunchReason = RELAUNCH_REASON_NONE; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1496 | } else { |
| 1497 | res = tr.getStack().requestFinishActivityLocked(token, resultCode, |
| 1498 | resultData, "app-request", true); |
| 1499 | if (!res) { |
| 1500 | Slog.i(TAG, "Failed to finish by app-request"); |
| 1501 | } |
| 1502 | } |
| 1503 | return res; |
| 1504 | } finally { |
| 1505 | Binder.restoreCallingIdentity(origId); |
| 1506 | } |
| 1507 | } |
| 1508 | } |
| 1509 | |
| 1510 | @Override |
| 1511 | public boolean finishActivityAffinity(IBinder token) { |
| 1512 | synchronized (mGlobalLock) { |
| 1513 | final long origId = Binder.clearCallingIdentity(); |
| 1514 | try { |
| 1515 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1516 | if (r == null) { |
| 1517 | return false; |
| 1518 | } |
| 1519 | |
| 1520 | // Do not allow task to finish if last task in lockTask mode. Launchable priv-apps |
| 1521 | // can finish. |
| 1522 | final TaskRecord task = r.getTask(); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 1523 | if (getLockTaskController().activityBlockedFromFinish(r)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1524 | return false; |
| 1525 | } |
| 1526 | return task.getStack().finishActivityAffinityLocked(r); |
| 1527 | } finally { |
| 1528 | Binder.restoreCallingIdentity(origId); |
| 1529 | } |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | @Override |
| 1534 | public final void activityIdle(IBinder token, Configuration config, boolean stopProfiling) { |
| 1535 | final long origId = Binder.clearCallingIdentity(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1536 | try { |
| 1537 | WindowProcessController proc = null; |
| 1538 | synchronized (mGlobalLock) { |
| 1539 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 1540 | if (stack == null) { |
| 1541 | return; |
| 1542 | } |
| 1543 | final ActivityRecord r = mStackSupervisor.activityIdleInternalLocked(token, |
| 1544 | false /* fromTimeout */, false /* processPausingActivities */, config); |
| 1545 | if (r != null) { |
| 1546 | proc = r.app; |
| 1547 | } |
| 1548 | if (stopProfiling && proc != null) { |
| 1549 | proc.clearProfilerIfNeeded(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1550 | } |
| 1551 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1552 | } finally { |
| 1553 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1554 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | @Override |
| 1558 | public final void activityResumed(IBinder token) { |
| 1559 | final long origId = Binder.clearCallingIdentity(); |
| 1560 | synchronized (mGlobalLock) { |
| 1561 | ActivityRecord.activityResumedLocked(token); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1562 | mWindowManager.notifyAppResumedFinished(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1563 | } |
| 1564 | Binder.restoreCallingIdentity(origId); |
| 1565 | } |
| 1566 | |
| 1567 | @Override |
| 1568 | public final void activityPaused(IBinder token) { |
| 1569 | final long origId = Binder.clearCallingIdentity(); |
| 1570 | synchronized (mGlobalLock) { |
| 1571 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 1572 | if (stack != null) { |
| 1573 | stack.activityPausedLocked(token, false); |
| 1574 | } |
| 1575 | } |
| 1576 | Binder.restoreCallingIdentity(origId); |
| 1577 | } |
| 1578 | |
| 1579 | @Override |
| 1580 | public final void activityStopped(IBinder token, Bundle icicle, |
| 1581 | PersistableBundle persistentState, CharSequence description) { |
| 1582 | if (DEBUG_ALL) Slog.v(TAG, "Activity stopped: token=" + token); |
| 1583 | |
| 1584 | // Refuse possible leaked file descriptors |
| 1585 | if (icicle != null && icicle.hasFileDescriptors()) { |
| 1586 | throw new IllegalArgumentException("File descriptors passed in Bundle"); |
| 1587 | } |
| 1588 | |
| 1589 | final long origId = Binder.clearCallingIdentity(); |
| 1590 | |
| 1591 | synchronized (mGlobalLock) { |
| 1592 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1593 | if (r != null) { |
| 1594 | r.activityStoppedLocked(icicle, persistentState, description); |
| 1595 | } |
| 1596 | } |
| 1597 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1598 | mAmInternal.trimApplications(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1599 | |
| 1600 | Binder.restoreCallingIdentity(origId); |
| 1601 | } |
| 1602 | |
| 1603 | @Override |
| 1604 | public final void activityDestroyed(IBinder token) { |
| 1605 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "ACTIVITY DESTROYED: " + token); |
| 1606 | synchronized (mGlobalLock) { |
| 1607 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 1608 | if (stack != null) { |
| 1609 | stack.activityDestroyedLocked(token, "activityDestroyed"); |
| 1610 | } |
| 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | @Override |
| 1615 | public final void activityRelaunched(IBinder token) { |
| 1616 | final long origId = Binder.clearCallingIdentity(); |
| 1617 | synchronized (mGlobalLock) { |
| 1618 | mStackSupervisor.activityRelaunchedLocked(token); |
| 1619 | } |
| 1620 | Binder.restoreCallingIdentity(origId); |
| 1621 | } |
| 1622 | |
| 1623 | public final void activitySlept(IBinder token) { |
| 1624 | if (DEBUG_ALL) Slog.v(TAG, "Activity slept: token=" + token); |
| 1625 | |
| 1626 | final long origId = Binder.clearCallingIdentity(); |
| 1627 | |
| 1628 | synchronized (mGlobalLock) { |
| 1629 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1630 | if (r != null) { |
| 1631 | mStackSupervisor.activitySleptLocked(r); |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | Binder.restoreCallingIdentity(origId); |
| 1636 | } |
| 1637 | |
| 1638 | @Override |
| 1639 | public void setRequestedOrientation(IBinder token, int requestedOrientation) { |
| 1640 | synchronized (mGlobalLock) { |
| 1641 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1642 | if (r == null) { |
| 1643 | return; |
| 1644 | } |
| 1645 | final long origId = Binder.clearCallingIdentity(); |
| 1646 | try { |
| 1647 | r.setRequestedOrientation(requestedOrientation); |
| 1648 | } finally { |
| 1649 | Binder.restoreCallingIdentity(origId); |
| 1650 | } |
| 1651 | } |
| 1652 | } |
| 1653 | |
| 1654 | @Override |
| 1655 | public int getRequestedOrientation(IBinder token) { |
| 1656 | synchronized (mGlobalLock) { |
| 1657 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1658 | if (r == null) { |
| 1659 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 1660 | } |
| 1661 | return r.getRequestedOrientation(); |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | @Override |
| 1666 | public void setImmersive(IBinder token, boolean immersive) { |
| 1667 | synchronized (mGlobalLock) { |
| 1668 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1669 | if (r == null) { |
| 1670 | throw new IllegalArgumentException(); |
| 1671 | } |
| 1672 | r.immersive = immersive; |
| 1673 | |
| 1674 | // update associated state if we're frontmost |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1675 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1676 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, "Frontmost changed immersion: "+ r); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1677 | applyUpdateLockStateLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1678 | } |
| 1679 | } |
| 1680 | } |
| 1681 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1682 | void applyUpdateLockStateLocked(ActivityRecord r) { |
| 1683 | // Modifications to the UpdateLock state are done on our handler, outside |
| 1684 | // the activity manager's locks. The new state is determined based on the |
| 1685 | // state *now* of the relevant activity record. The object is passed to |
| 1686 | // the handler solely for logging detail, not to be consulted/modified. |
| 1687 | final boolean nextState = r != null && r.immersive; |
| 1688 | mH.post(() -> { |
| 1689 | if (mUpdateLock.isHeld() != nextState) { |
| 1690 | if (DEBUG_IMMERSIVE) Slog.d(TAG_IMMERSIVE, |
| 1691 | "Applying new update lock state '" + nextState + "' for " + r); |
| 1692 | if (nextState) { |
| 1693 | mUpdateLock.acquire(); |
| 1694 | } else { |
| 1695 | mUpdateLock.release(); |
| 1696 | } |
| 1697 | } |
| 1698 | }); |
| 1699 | } |
| 1700 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1701 | @Override |
| 1702 | public boolean isImmersive(IBinder token) { |
| 1703 | synchronized (mGlobalLock) { |
| 1704 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1705 | if (r == null) { |
| 1706 | throw new IllegalArgumentException(); |
| 1707 | } |
| 1708 | return r.immersive; |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | @Override |
| 1713 | public boolean isTopActivityImmersive() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1714 | enforceNotIsolatedCaller("isTopActivityImmersive"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1715 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1716 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivityLocked(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1717 | return (r != null) ? r.immersive : false; |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | @Override |
| 1722 | public void overridePendingTransition(IBinder token, String packageName, |
| 1723 | int enterAnim, int exitAnim) { |
| 1724 | synchronized (mGlobalLock) { |
| 1725 | ActivityRecord self = ActivityRecord.isInStackLocked(token); |
| 1726 | if (self == null) { |
| 1727 | return; |
| 1728 | } |
| 1729 | |
| 1730 | final long origId = Binder.clearCallingIdentity(); |
| 1731 | |
| 1732 | if (self.isState( |
| 1733 | ActivityStack.ActivityState.RESUMED, ActivityStack.ActivityState.PAUSING)) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1734 | self.getDisplay().getWindowContainerController().overridePendingAppTransition( |
| 1735 | packageName, enterAnim, exitAnim, null); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | Binder.restoreCallingIdentity(origId); |
| 1739 | } |
| 1740 | } |
| 1741 | |
| 1742 | @Override |
| 1743 | public int getFrontActivityScreenCompatMode() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1744 | enforceNotIsolatedCaller("getFrontActivityScreenCompatMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1745 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1746 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivityLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1747 | if (r == null) { |
| 1748 | return ActivityManager.COMPAT_MODE_UNKNOWN; |
| 1749 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1750 | return mCompatModePackages.computeCompatModeLocked(r.info.applicationInfo); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1751 | } |
| 1752 | } |
| 1753 | |
| 1754 | @Override |
| 1755 | public void setFrontActivityScreenCompatMode(int mode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1756 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1757 | "setFrontActivityScreenCompatMode"); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1758 | ApplicationInfo ai; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1759 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1760 | final ActivityRecord r = getTopDisplayFocusedStack().topRunningActivityLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1761 | if (r == null) { |
| 1762 | Slog.w(TAG, "setFrontActivityScreenCompatMode failed: no top activity"); |
| 1763 | return; |
| 1764 | } |
| 1765 | ai = r.info.applicationInfo; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1766 | mCompatModePackages.setPackageScreenCompatModeLocked(ai, mode); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1767 | } |
| 1768 | } |
| 1769 | |
| 1770 | @Override |
| 1771 | public int getLaunchedFromUid(IBinder activityToken) { |
| 1772 | ActivityRecord srec; |
| 1773 | synchronized (mGlobalLock) { |
| 1774 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 1775 | } |
| 1776 | if (srec == null) { |
| 1777 | return -1; |
| 1778 | } |
| 1779 | return srec.launchedFromUid; |
| 1780 | } |
| 1781 | |
| 1782 | @Override |
| 1783 | public String getLaunchedFromPackage(IBinder activityToken) { |
| 1784 | ActivityRecord srec; |
| 1785 | synchronized (mGlobalLock) { |
| 1786 | srec = ActivityRecord.forTokenLocked(activityToken); |
| 1787 | } |
| 1788 | if (srec == null) { |
| 1789 | return null; |
| 1790 | } |
| 1791 | return srec.launchedFromPackage; |
| 1792 | } |
| 1793 | |
| 1794 | @Override |
| 1795 | public boolean convertFromTranslucent(IBinder token) { |
| 1796 | final long origId = Binder.clearCallingIdentity(); |
| 1797 | try { |
| 1798 | synchronized (mGlobalLock) { |
| 1799 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1800 | if (r == null) { |
| 1801 | return false; |
| 1802 | } |
| 1803 | final boolean translucentChanged = r.changeWindowTranslucency(true); |
| 1804 | if (translucentChanged) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1805 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1806 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1807 | mWindowManager.setAppFullscreen(token, true); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1808 | return translucentChanged; |
| 1809 | } |
| 1810 | } finally { |
| 1811 | Binder.restoreCallingIdentity(origId); |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | @Override |
| 1816 | public boolean convertToTranslucent(IBinder token, Bundle options) { |
| 1817 | SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(options); |
| 1818 | final long origId = Binder.clearCallingIdentity(); |
| 1819 | try { |
| 1820 | synchronized (mGlobalLock) { |
| 1821 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1822 | if (r == null) { |
| 1823 | return false; |
| 1824 | } |
| 1825 | final TaskRecord task = r.getTask(); |
| 1826 | int index = task.mActivities.lastIndexOf(r); |
| 1827 | if (index > 0) { |
| 1828 | ActivityRecord under = task.mActivities.get(index - 1); |
| 1829 | under.returningOptions = safeOptions != null ? safeOptions.getOptions(r) : null; |
| 1830 | } |
| 1831 | final boolean translucentChanged = r.changeWindowTranslucency(false); |
| 1832 | if (translucentChanged) { |
| 1833 | r.getStack().convertActivityToTranslucent(r); |
| 1834 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1835 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1836 | mWindowManager.setAppFullscreen(token, false); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1837 | return translucentChanged; |
| 1838 | } |
| 1839 | } finally { |
| 1840 | Binder.restoreCallingIdentity(origId); |
| 1841 | } |
| 1842 | } |
| 1843 | |
| 1844 | @Override |
| 1845 | public void notifyActivityDrawn(IBinder token) { |
| 1846 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, "notifyActivityDrawn: token=" + token); |
| 1847 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1848 | ActivityRecord r = mRootActivityContainer.isInAnyStack(token); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1849 | if (r != null) { |
| 1850 | r.getStack().notifyActivityDrawnLocked(r); |
| 1851 | } |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | @Override |
| 1856 | public void reportActivityFullyDrawn(IBinder token, boolean restoredFromBundle) { |
| 1857 | synchronized (mGlobalLock) { |
| 1858 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 1859 | if (r == null) { |
| 1860 | return; |
| 1861 | } |
| 1862 | r.reportFullyDrawnLocked(restoredFromBundle); |
| 1863 | } |
| 1864 | } |
| 1865 | |
| 1866 | @Override |
| 1867 | public int getActivityDisplayId(IBinder activityToken) throws RemoteException { |
| 1868 | synchronized (mGlobalLock) { |
| 1869 | final ActivityStack stack = ActivityRecord.getStackLocked(activityToken); |
| 1870 | if (stack != null && stack.mDisplayId != INVALID_DISPLAY) { |
| 1871 | return stack.mDisplayId; |
| 1872 | } |
| 1873 | return DEFAULT_DISPLAY; |
| 1874 | } |
| 1875 | } |
| 1876 | |
| 1877 | @Override |
| 1878 | public ActivityManager.StackInfo getFocusedStackInfo() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1879 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1880 | long ident = Binder.clearCallingIdentity(); |
| 1881 | try { |
| 1882 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1883 | ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1884 | if (focusedStack != null) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1885 | return mRootActivityContainer.getStackInfo(focusedStack.mStackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1886 | } |
| 1887 | return null; |
| 1888 | } |
| 1889 | } finally { |
| 1890 | Binder.restoreCallingIdentity(ident); |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | @Override |
| 1895 | public void setFocusedStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1896 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1897 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedStack: stackId=" + stackId); |
| 1898 | final long callingId = Binder.clearCallingIdentity(); |
| 1899 | try { |
| 1900 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1901 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1902 | if (stack == null) { |
| 1903 | Slog.w(TAG, "setFocusedStack: No stack with id=" + stackId); |
| 1904 | return; |
| 1905 | } |
| 1906 | final ActivityRecord r = stack.topRunningActivityLocked(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 1907 | if (r != null && r.moveFocusableActivityToTop("setFocusedStack")) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1908 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1909 | } |
| 1910 | } |
| 1911 | } finally { |
| 1912 | Binder.restoreCallingIdentity(callingId); |
| 1913 | } |
| 1914 | } |
| 1915 | |
| 1916 | @Override |
| 1917 | public void setFocusedTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1918 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1919 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedTask: taskId=" + taskId); |
| 1920 | final long callingId = Binder.clearCallingIdentity(); |
| 1921 | try { |
| 1922 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1923 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 1924 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1925 | if (task == null) { |
| 1926 | return; |
| 1927 | } |
| 1928 | final ActivityRecord r = task.topRunningActivityLocked(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 1929 | if (r != null && r.moveFocusableActivityToTop("setFocusedTask")) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1930 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1931 | } |
| 1932 | } |
| 1933 | } finally { |
| 1934 | Binder.restoreCallingIdentity(callingId); |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | @Override |
| 1939 | public boolean removeTask(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1940 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1941 | synchronized (mGlobalLock) { |
| 1942 | final long ident = Binder.clearCallingIdentity(); |
| 1943 | try { |
| 1944 | return mStackSupervisor.removeTaskByIdLocked(taskId, true, REMOVE_FROM_RECENTS, |
| 1945 | "remove-task"); |
| 1946 | } finally { |
| 1947 | Binder.restoreCallingIdentity(ident); |
| 1948 | } |
| 1949 | } |
| 1950 | } |
| 1951 | |
| 1952 | @Override |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 1953 | public void removeAllVisibleRecentTasks() { |
| 1954 | enforceCallerIsRecentsOrHasPermission(REMOVE_TASKS, "removeAllVisibleRecentTasks()"); |
| 1955 | synchronized (mGlobalLock) { |
| 1956 | final long ident = Binder.clearCallingIdentity(); |
| 1957 | try { |
| 1958 | getRecentTasks().removeAllVisibleTasks(); |
| 1959 | } finally { |
| 1960 | Binder.restoreCallingIdentity(ident); |
| 1961 | } |
| 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1966 | public boolean shouldUpRecreateTask(IBinder token, String destAffinity) { |
| 1967 | synchronized (mGlobalLock) { |
| 1968 | final ActivityRecord srec = ActivityRecord.forTokenLocked(token); |
| 1969 | if (srec != null) { |
| 1970 | return srec.getStack().shouldUpRecreateTaskLocked(srec, destAffinity); |
| 1971 | } |
| 1972 | } |
| 1973 | return false; |
| 1974 | } |
| 1975 | |
| 1976 | @Override |
| 1977 | public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode, |
| 1978 | Intent resultData) { |
| 1979 | |
| 1980 | synchronized (mGlobalLock) { |
| 1981 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 1982 | if (r != null) { |
| 1983 | return r.getStack().navigateUpToLocked(r, destIntent, resultCode, resultData); |
| 1984 | } |
| 1985 | return false; |
| 1986 | } |
| 1987 | } |
| 1988 | |
| 1989 | /** |
| 1990 | * Attempts to move a task backwards in z-order (the order of activities within the task is |
| 1991 | * unchanged). |
| 1992 | * |
| 1993 | * There are several possible results of this call: |
| 1994 | * - if the task is locked, then we will show the lock toast |
| 1995 | * - if there is a task behind the provided task, then that task is made visible and resumed as |
| 1996 | * this task is moved to the back |
| 1997 | * - otherwise, if there are no other tasks in the stack: |
| 1998 | * - if this task is in the pinned stack, then we remove the stack completely, which will |
| 1999 | * have the effect of moving the task to the top or bottom of the fullscreen stack |
| 2000 | * (depending on whether it is visible) |
| 2001 | * - otherwise, we simply return home and hide this task |
| 2002 | * |
| 2003 | * @param token A reference to the activity we wish to move |
| 2004 | * @param nonRoot If false then this only works if the activity is the root |
| 2005 | * of a task; if true it will work for any activity in a task. |
| 2006 | * @return Returns true if the move completed, false if not. |
| 2007 | */ |
| 2008 | @Override |
| 2009 | public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2010 | enforceNotIsolatedCaller("moveActivityTaskToBack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2011 | synchronized (mGlobalLock) { |
| 2012 | final long origId = Binder.clearCallingIdentity(); |
| 2013 | try { |
| 2014 | int taskId = ActivityRecord.getTaskForActivityLocked(token, !nonRoot); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2015 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2016 | if (task != null) { |
| 2017 | return ActivityRecord.getStackLocked(token).moveTaskToBackLocked(taskId); |
| 2018 | } |
| 2019 | } finally { |
| 2020 | Binder.restoreCallingIdentity(origId); |
| 2021 | } |
| 2022 | } |
| 2023 | return false; |
| 2024 | } |
| 2025 | |
| 2026 | @Override |
| 2027 | public Rect getTaskBounds(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2028 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getTaskBounds()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2029 | long ident = Binder.clearCallingIdentity(); |
| 2030 | Rect rect = new Rect(); |
| 2031 | try { |
| 2032 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2033 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2034 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2035 | if (task == null) { |
| 2036 | Slog.w(TAG, "getTaskBounds: taskId=" + taskId + " not found"); |
| 2037 | return rect; |
| 2038 | } |
| 2039 | if (task.getStack() != null) { |
| 2040 | // Return the bounds from window manager since it will be adjusted for various |
| 2041 | // things like the presense of a docked stack for tasks that aren't resizeable. |
| 2042 | task.getWindowContainerBounds(rect); |
| 2043 | } else { |
| 2044 | // Task isn't in window manager yet since it isn't associated with a stack. |
| 2045 | // Return the persist value from activity manager |
| 2046 | if (!task.matchParentBounds()) { |
| 2047 | rect.set(task.getBounds()); |
| 2048 | } else if (task.mLastNonFullscreenBounds != null) { |
| 2049 | rect.set(task.mLastNonFullscreenBounds); |
| 2050 | } |
| 2051 | } |
| 2052 | } |
| 2053 | } finally { |
| 2054 | Binder.restoreCallingIdentity(ident); |
| 2055 | } |
| 2056 | return rect; |
| 2057 | } |
| 2058 | |
| 2059 | @Override |
| 2060 | public ActivityManager.TaskDescription getTaskDescription(int id) { |
| 2061 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2062 | enforceCallerIsRecentsOrHasPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2063 | MANAGE_ACTIVITY_STACKS, "getTaskDescription()"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2064 | final TaskRecord tr = mRootActivityContainer.anyTaskForId(id, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2065 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2066 | if (tr != null) { |
| 2067 | return tr.lastTaskDescription; |
| 2068 | } |
| 2069 | } |
| 2070 | return null; |
| 2071 | } |
| 2072 | |
| 2073 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2074 | public void setTaskWindowingMode(int taskId, int windowingMode, boolean toTop) { |
| 2075 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 2076 | setTaskWindowingModeSplitScreenPrimary(taskId, SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, |
| 2077 | toTop, ANIMATE, null /* initialBounds */, true /* showRecents */); |
| 2078 | return; |
| 2079 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2080 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setTaskWindowingMode()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2081 | synchronized (mGlobalLock) { |
| 2082 | final long ident = Binder.clearCallingIdentity(); |
| 2083 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2084 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2085 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2086 | if (task == null) { |
| 2087 | Slog.w(TAG, "setTaskWindowingMode: No task for id=" + taskId); |
| 2088 | return; |
| 2089 | } |
| 2090 | |
| 2091 | if (DEBUG_STACK) Slog.d(TAG_STACK, "setTaskWindowingMode: moving task=" + taskId |
| 2092 | + " to windowingMode=" + windowingMode + " toTop=" + toTop); |
| 2093 | |
| 2094 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2095 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2096 | + " non-standard task " + taskId + " to windowing mode=" |
| 2097 | + windowingMode); |
| 2098 | } |
| 2099 | |
| 2100 | final ActivityStack stack = task.getStack(); |
| 2101 | if (toTop) { |
| 2102 | stack.moveToFront("setTaskWindowingMode", task); |
| 2103 | } |
| 2104 | stack.setWindowingMode(windowingMode); |
| 2105 | } finally { |
| 2106 | Binder.restoreCallingIdentity(ident); |
| 2107 | } |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2112 | public String getCallingPackage(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2113 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2114 | ActivityRecord r = getCallingRecordLocked(token); |
| 2115 | return r != null ? r.info.packageName : null; |
| 2116 | } |
| 2117 | } |
| 2118 | |
| 2119 | @Override |
| 2120 | public ComponentName getCallingActivity(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2121 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2122 | ActivityRecord r = getCallingRecordLocked(token); |
| 2123 | return r != null ? r.intent.getComponent() : null; |
| 2124 | } |
| 2125 | } |
| 2126 | |
| 2127 | private ActivityRecord getCallingRecordLocked(IBinder token) { |
| 2128 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2129 | if (r == null) { |
| 2130 | return null; |
| 2131 | } |
| 2132 | return r.resultTo; |
| 2133 | } |
| 2134 | |
| 2135 | @Override |
| 2136 | public void unhandledBack() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2137 | mAmInternal.enforceCallingPermission(android.Manifest.permission.FORCE_BACK, "unhandledBack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2138 | |
| 2139 | synchronized (mGlobalLock) { |
| 2140 | final long origId = Binder.clearCallingIdentity(); |
| 2141 | try { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2142 | getTopDisplayFocusedStack().unhandledBackLocked(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2143 | } finally { |
| 2144 | Binder.restoreCallingIdentity(origId); |
| 2145 | } |
| 2146 | } |
| 2147 | } |
| 2148 | |
| 2149 | /** |
| 2150 | * TODO: Add mController hook |
| 2151 | */ |
| 2152 | @Override |
| 2153 | public void moveTaskToFront(int taskId, int flags, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2154 | mAmInternal.enforceCallingPermission(android.Manifest.permission.REORDER_TASKS, "moveTaskToFront()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2155 | |
| 2156 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToFront: moving taskId=" + taskId); |
| 2157 | synchronized (mGlobalLock) { |
| 2158 | moveTaskToFrontLocked(taskId, flags, SafeActivityOptions.fromBundle(bOptions), |
| 2159 | false /* fromRecents */); |
| 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | void moveTaskToFrontLocked(int taskId, int flags, SafeActivityOptions options, |
| 2164 | boolean fromRecents) { |
| 2165 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2166 | if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(), |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2167 | Binder.getCallingUid(), -1, -1, "Task to front")) { |
| 2168 | SafeActivityOptions.abort(options); |
| 2169 | return; |
| 2170 | } |
| 2171 | final long origId = Binder.clearCallingIdentity(); |
| 2172 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2173 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2174 | if (task == null) { |
| 2175 | Slog.d(TAG, "Could not find task for id: "+ taskId); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2176 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2177 | return; |
| 2178 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2179 | if (getLockTaskController().isLockTaskModeViolation(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2180 | Slog.e(TAG, "moveTaskToFront: Attempt to violate Lock Task Mode"); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2181 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2182 | return; |
| 2183 | } |
| 2184 | ActivityOptions realOptions = options != null |
| 2185 | ? options.getOptions(mStackSupervisor) |
| 2186 | : null; |
| 2187 | mStackSupervisor.findTaskToMoveToFront(task, flags, realOptions, "moveTaskToFront", |
| 2188 | false /* forceNonResizable */); |
| 2189 | |
| 2190 | final ActivityRecord topActivity = task.getTopActivity(); |
| 2191 | if (topActivity != null) { |
| 2192 | |
| 2193 | // We are reshowing a task, use a starting window to hide the initial draw delay |
| 2194 | // so the transition can start earlier. |
| 2195 | topActivity.showStartingWindow(null /* prev */, false /* newTask */, |
| 2196 | true /* taskSwitch */, fromRecents); |
| 2197 | } |
| 2198 | } finally { |
| 2199 | Binder.restoreCallingIdentity(origId); |
| 2200 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2201 | } |
| 2202 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2203 | boolean checkAppSwitchAllowedLocked(int sourcePid, int sourceUid, |
| 2204 | int callingPid, int callingUid, String name) { |
| 2205 | if (mAppSwitchesAllowedTime < SystemClock.uptimeMillis()) { |
| 2206 | return true; |
| 2207 | } |
| 2208 | |
| 2209 | if (getRecentTasks().isCallerRecents(sourceUid)) { |
| 2210 | return true; |
| 2211 | } |
| 2212 | |
| 2213 | int perm = checkComponentPermission(STOP_APP_SWITCHES, sourcePid, sourceUid, -1, true); |
| 2214 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2215 | return true; |
| 2216 | } |
| 2217 | if (checkAllowAppSwitchUid(sourceUid)) { |
| 2218 | return true; |
| 2219 | } |
| 2220 | |
| 2221 | // If the actual IPC caller is different from the logical source, then |
| 2222 | // also see if they are allowed to control app switches. |
| 2223 | if (callingUid != -1 && callingUid != sourceUid) { |
| 2224 | perm = checkComponentPermission(STOP_APP_SWITCHES, callingPid, callingUid, -1, true); |
| 2225 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2226 | return true; |
| 2227 | } |
| 2228 | if (checkAllowAppSwitchUid(callingUid)) { |
| 2229 | return true; |
| 2230 | } |
| 2231 | } |
| 2232 | |
| 2233 | Slog.w(TAG, name + " request from " + sourceUid + " stopped"); |
| 2234 | return false; |
| 2235 | } |
| 2236 | |
| 2237 | private boolean checkAllowAppSwitchUid(int uid) { |
| 2238 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(UserHandle.getUserId(uid)); |
| 2239 | if (types != null) { |
| 2240 | for (int i = types.size() - 1; i >= 0; i--) { |
| 2241 | if (types.valueAt(i).intValue() == uid) { |
| 2242 | return true; |
| 2243 | } |
| 2244 | } |
| 2245 | } |
| 2246 | return false; |
| 2247 | } |
| 2248 | |
| 2249 | @Override |
| 2250 | public void setActivityController(IActivityController controller, boolean imAMonkey) { |
| 2251 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER, |
| 2252 | "setActivityController()"); |
| 2253 | synchronized (mGlobalLock) { |
| 2254 | mController = controller; |
| 2255 | mControllerIsAMonkey = imAMonkey; |
| 2256 | Watchdog.getInstance().setActivityController(controller); |
| 2257 | } |
| 2258 | } |
| 2259 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 2260 | public boolean isControllerAMonkey() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2261 | synchronized (mGlobalLock) { |
| 2262 | return mController != null && mControllerIsAMonkey; |
| 2263 | } |
| 2264 | } |
| 2265 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2266 | @Override |
| 2267 | public int getTaskForActivity(IBinder token, boolean onlyRoot) { |
| 2268 | synchronized (mGlobalLock) { |
| 2269 | return ActivityRecord.getTaskForActivityLocked(token, onlyRoot); |
| 2270 | } |
| 2271 | } |
| 2272 | |
| 2273 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2274 | public List<ActivityManager.RunningTaskInfo> getTasks(int maxNum) { |
| 2275 | return getFilteredTasks(maxNum, ACTIVITY_TYPE_UNDEFINED, WINDOWING_MODE_UNDEFINED); |
| 2276 | } |
| 2277 | |
| 2278 | @Override |
| 2279 | public List<ActivityManager.RunningTaskInfo> getFilteredTasks(int maxNum, |
| 2280 | @WindowConfiguration.ActivityType int ignoreActivityType, |
| 2281 | @WindowConfiguration.WindowingMode int ignoreWindowingMode) { |
| 2282 | final int callingUid = Binder.getCallingUid(); |
| 2283 | ArrayList<ActivityManager.RunningTaskInfo> list = new ArrayList<>(); |
| 2284 | |
| 2285 | synchronized (mGlobalLock) { |
| 2286 | if (DEBUG_ALL) Slog.v(TAG, "getTasks: max=" + maxNum); |
| 2287 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2288 | final boolean allowed = isGetTasksAllowed("getTasks", Binder.getCallingPid(), |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2289 | callingUid); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2290 | mRootActivityContainer.getRunningTasks(maxNum, list, ignoreActivityType, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2291 | ignoreWindowingMode, callingUid, allowed); |
| 2292 | } |
| 2293 | |
| 2294 | return list; |
| 2295 | } |
| 2296 | |
| 2297 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2298 | public final void finishSubActivity(IBinder token, String resultWho, int requestCode) { |
| 2299 | synchronized (mGlobalLock) { |
| 2300 | final long origId = Binder.clearCallingIdentity(); |
| 2301 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2302 | if (r != null) { |
| 2303 | r.getStack().finishSubActivityLocked(r, resultWho, requestCode); |
| 2304 | } |
| 2305 | Binder.restoreCallingIdentity(origId); |
| 2306 | } |
| 2307 | } |
| 2308 | |
| 2309 | @Override |
| 2310 | public boolean willActivityBeVisible(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2311 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2312 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 2313 | if (stack != null) { |
| 2314 | return stack.willActivityBeVisibleLocked(token); |
| 2315 | } |
| 2316 | return false; |
| 2317 | } |
| 2318 | } |
| 2319 | |
| 2320 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2321 | public void moveTaskToStack(int taskId, int stackId, boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2322 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "moveTaskToStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2323 | synchronized (mGlobalLock) { |
| 2324 | final long ident = Binder.clearCallingIdentity(); |
| 2325 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2326 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2327 | if (task == null) { |
| 2328 | Slog.w(TAG, "moveTaskToStack: No task for id=" + taskId); |
| 2329 | return; |
| 2330 | } |
| 2331 | |
| 2332 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToStack: moving task=" + taskId |
| 2333 | + " to stackId=" + stackId + " toTop=" + toTop); |
| 2334 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2335 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2336 | if (stack == null) { |
| 2337 | throw new IllegalStateException( |
| 2338 | "moveTaskToStack: No stack for stackId=" + stackId); |
| 2339 | } |
| 2340 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 2341 | throw new IllegalArgumentException("moveTaskToStack: Attempt to move task " |
| 2342 | + taskId + " to stack " + stackId); |
| 2343 | } |
| 2344 | if (stack.inSplitScreenPrimaryWindowingMode()) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2345 | mWindowManager.setDockedStackCreateState( |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2346 | SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */); |
| 2347 | } |
| 2348 | task.reparent(stack, toTop, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME, |
| 2349 | "moveTaskToStack"); |
| 2350 | } finally { |
| 2351 | Binder.restoreCallingIdentity(ident); |
| 2352 | } |
| 2353 | } |
| 2354 | } |
| 2355 | |
| 2356 | @Override |
| 2357 | public void resizeStack(int stackId, Rect destBounds, boolean allowResizeInDockedMode, |
| 2358 | boolean preserveWindows, boolean animate, int animationDuration) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2359 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2360 | |
| 2361 | final long ident = Binder.clearCallingIdentity(); |
| 2362 | try { |
| 2363 | synchronized (mGlobalLock) { |
| 2364 | if (animate) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2365 | final PinnedActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2366 | if (stack == null) { |
| 2367 | Slog.w(TAG, "resizeStack: stackId " + stackId + " not found."); |
| 2368 | return; |
| 2369 | } |
| 2370 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 2371 | throw new IllegalArgumentException("Stack: " + stackId |
| 2372 | + " doesn't support animated resize."); |
| 2373 | } |
| 2374 | stack.animateResizePinnedStack(null /* sourceHintBounds */, destBounds, |
| 2375 | animationDuration, false /* fromFullscreen */); |
| 2376 | } else { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2377 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2378 | if (stack == null) { |
| 2379 | Slog.w(TAG, "resizeStack: stackId " + stackId + " not found."); |
| 2380 | return; |
| 2381 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2382 | mRootActivityContainer.resizeStack(stack, destBounds, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2383 | null /* tempTaskBounds */, null /* tempTaskInsetBounds */, |
| 2384 | preserveWindows, allowResizeInDockedMode, !DEFER_RESUME); |
| 2385 | } |
| 2386 | } |
| 2387 | } finally { |
| 2388 | Binder.restoreCallingIdentity(ident); |
| 2389 | } |
| 2390 | } |
| 2391 | |
| 2392 | /** |
| 2393 | * Moves the specified task to the primary-split-screen stack. |
| 2394 | * |
| 2395 | * @param taskId Id of task to move. |
| 2396 | * @param createMode The mode the primary split screen stack should be created in if it doesn't |
| 2397 | * exist already. See |
| 2398 | * {@link android.app.ActivityTaskManager#SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT} |
| 2399 | * and |
| 2400 | * {@link android.app.ActivityTaskManager#SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT} |
| 2401 | * @param toTop If the task and stack should be moved to the top. |
| 2402 | * @param animate Whether we should play an animation for the moving the task. |
| 2403 | * @param initialBounds If the primary stack gets created, it will use these bounds for the |
| 2404 | * stack. Pass {@code null} to use default bounds. |
| 2405 | * @param showRecents If the recents activity should be shown on the other side of the task |
| 2406 | * going into split-screen mode. |
| 2407 | */ |
| 2408 | @Override |
| 2409 | public boolean setTaskWindowingModeSplitScreenPrimary(int taskId, int createMode, |
| 2410 | boolean toTop, boolean animate, Rect initialBounds, boolean showRecents) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2411 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2412 | "setTaskWindowingModeSplitScreenPrimary()"); |
| 2413 | synchronized (mGlobalLock) { |
| 2414 | final long ident = Binder.clearCallingIdentity(); |
| 2415 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2416 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2417 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2418 | if (task == null) { |
| 2419 | Slog.w(TAG, "setTaskWindowingModeSplitScreenPrimary: No task for id=" + taskId); |
| 2420 | return false; |
| 2421 | } |
| 2422 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
| 2423 | "setTaskWindowingModeSplitScreenPrimary: moving task=" + taskId |
| 2424 | + " to createMode=" + createMode + " toTop=" + toTop); |
| 2425 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2426 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2427 | + " non-standard task " + taskId + " to split-screen windowing mode"); |
| 2428 | } |
| 2429 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2430 | mWindowManager.setDockedStackCreateState(createMode, initialBounds); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2431 | final int windowingMode = task.getWindowingMode(); |
| 2432 | final ActivityStack stack = task.getStack(); |
| 2433 | if (toTop) { |
| 2434 | stack.moveToFront("setTaskWindowingModeSplitScreenPrimary", task); |
| 2435 | } |
| 2436 | stack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, animate, showRecents, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 2437 | false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */, |
| 2438 | false /* creating */); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2439 | return windowingMode != task.getWindowingMode(); |
| 2440 | } finally { |
| 2441 | Binder.restoreCallingIdentity(ident); |
| 2442 | } |
| 2443 | } |
| 2444 | } |
| 2445 | |
| 2446 | /** |
| 2447 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 2448 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 2449 | */ |
| 2450 | @Override |
| 2451 | public void removeStacksInWindowingModes(int[] windowingModes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2452 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2453 | "removeStacksInWindowingModes()"); |
| 2454 | |
| 2455 | synchronized (mGlobalLock) { |
| 2456 | final long ident = Binder.clearCallingIdentity(); |
| 2457 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2458 | mRootActivityContainer.removeStacksInWindowingModes(windowingModes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2459 | } finally { |
| 2460 | Binder.restoreCallingIdentity(ident); |
| 2461 | } |
| 2462 | } |
| 2463 | } |
| 2464 | |
| 2465 | @Override |
| 2466 | public void removeStacksWithActivityTypes(int[] activityTypes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2467 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2468 | "removeStacksWithActivityTypes()"); |
| 2469 | |
| 2470 | synchronized (mGlobalLock) { |
| 2471 | final long ident = Binder.clearCallingIdentity(); |
| 2472 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2473 | mRootActivityContainer.removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2474 | } finally { |
| 2475 | Binder.restoreCallingIdentity(ident); |
| 2476 | } |
| 2477 | } |
| 2478 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2479 | |
| 2480 | @Override |
| 2481 | public ParceledListSlice<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, |
| 2482 | int userId) { |
| 2483 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2484 | userId = handleIncomingUser(Binder.getCallingPid(), callingUid, userId, "getRecentTasks"); |
| 2485 | final boolean allowed = isGetTasksAllowed("getRecentTasks", Binder.getCallingPid(), |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2486 | callingUid); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2487 | final boolean detailed = checkGetTasksPermission( |
| 2488 | android.Manifest.permission.GET_DETAILED_TASKS, Binder.getCallingPid(), |
| 2489 | UserHandle.getAppId(callingUid)) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2490 | == PackageManager.PERMISSION_GRANTED; |
| 2491 | |
| 2492 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 2493 | return mRecentTasks.getRecentTasks(maxNum, flags, allowed, detailed, userId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2494 | callingUid); |
| 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | @Override |
| 2499 | public List<ActivityManager.StackInfo> getAllStackInfos() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2500 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2501 | long ident = Binder.clearCallingIdentity(); |
| 2502 | try { |
| 2503 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2504 | return mRootActivityContainer.getAllStackInfos(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2505 | } |
| 2506 | } finally { |
| 2507 | Binder.restoreCallingIdentity(ident); |
| 2508 | } |
| 2509 | } |
| 2510 | |
| 2511 | @Override |
| 2512 | public ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2513 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2514 | long ident = Binder.clearCallingIdentity(); |
| 2515 | try { |
| 2516 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2517 | return mRootActivityContainer.getStackInfo(windowingMode, activityType); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2518 | } |
| 2519 | } finally { |
| 2520 | Binder.restoreCallingIdentity(ident); |
| 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | @Override |
| 2525 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2526 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "cancelRecentsAnimation()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2527 | final long callingUid = Binder.getCallingUid(); |
| 2528 | final long origId = Binder.clearCallingIdentity(); |
| 2529 | try { |
| 2530 | synchronized (mGlobalLock) { |
| 2531 | // Cancel the recents animation synchronously (do not hold the WM lock) |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2532 | mWindowManager.cancelRecentsAnimationSynchronously(restoreHomeStackPosition |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2533 | ? REORDER_MOVE_TO_ORIGINAL_POSITION |
| 2534 | : REORDER_KEEP_IN_PLACE, "cancelRecentsAnimation/uid=" + callingUid); |
| 2535 | } |
| 2536 | } finally { |
| 2537 | Binder.restoreCallingIdentity(origId); |
| 2538 | } |
| 2539 | } |
| 2540 | |
| 2541 | @Override |
| 2542 | public void startLockTaskModeByToken(IBinder token) { |
| 2543 | synchronized (mGlobalLock) { |
| 2544 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2545 | if (r == null) { |
| 2546 | return; |
| 2547 | } |
| 2548 | startLockTaskModeLocked(r.getTask(), false /* isSystemCaller */); |
| 2549 | } |
| 2550 | } |
| 2551 | |
| 2552 | @Override |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2553 | public void startSystemLockTaskMode(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2554 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "startSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2555 | // This makes inner call to look as if it was initiated by system. |
| 2556 | long ident = Binder.clearCallingIdentity(); |
| 2557 | try { |
| 2558 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2559 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2560 | MATCH_TASK_IN_STACKS_ONLY); |
| 2561 | if (task == null) { |
| 2562 | return; |
| 2563 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2564 | |
| 2565 | // When starting lock task mode the stack must be in front and focused |
| 2566 | task.getStack().moveToFront("startSystemLockTaskMode"); |
| 2567 | startLockTaskModeLocked(task, true /* isSystemCaller */); |
| 2568 | } |
| 2569 | } finally { |
| 2570 | Binder.restoreCallingIdentity(ident); |
| 2571 | } |
| 2572 | } |
| 2573 | |
| 2574 | @Override |
| 2575 | public void stopLockTaskModeByToken(IBinder token) { |
| 2576 | synchronized (mGlobalLock) { |
| 2577 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2578 | if (r == null) { |
| 2579 | return; |
| 2580 | } |
| 2581 | stopLockTaskModeInternal(r.getTask(), false /* isSystemCaller */); |
| 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | /** |
| 2586 | * This API should be called by SystemUI only when user perform certain action to dismiss |
| 2587 | * lock task mode. We should only dismiss pinned lock task mode in this case. |
| 2588 | */ |
| 2589 | @Override |
| 2590 | public void stopSystemLockTaskMode() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2591 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "stopSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2592 | stopLockTaskModeInternal(null, true /* isSystemCaller */); |
| 2593 | } |
| 2594 | |
| 2595 | private void startLockTaskModeLocked(@Nullable TaskRecord task, boolean isSystemCaller) { |
| 2596 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "startLockTaskModeLocked: " + task); |
| 2597 | if (task == null || task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) { |
| 2598 | return; |
| 2599 | } |
| 2600 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2601 | final ActivityStack stack = mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2602 | if (stack == null || task != stack.topTask()) { |
| 2603 | throw new IllegalArgumentException("Invalid task, not in foreground"); |
| 2604 | } |
| 2605 | |
| 2606 | // {@code isSystemCaller} is used to distinguish whether this request is initiated by the |
| 2607 | // system or a specific app. |
| 2608 | // * System-initiated requests will only start the pinned mode (screen pinning) |
| 2609 | // * App-initiated requests |
| 2610 | // - will put the device in fully locked mode (LockTask), if the app is whitelisted |
| 2611 | // - will start the pinned mode, otherwise |
| 2612 | final int callingUid = Binder.getCallingUid(); |
| 2613 | long ident = Binder.clearCallingIdentity(); |
| 2614 | try { |
| 2615 | // When a task is locked, dismiss the pinned stack if it exists |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2616 | mRootActivityContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2617 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2618 | getLockTaskController().startLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2619 | } finally { |
| 2620 | Binder.restoreCallingIdentity(ident); |
| 2621 | } |
| 2622 | } |
| 2623 | |
| 2624 | private void stopLockTaskModeInternal(@Nullable TaskRecord task, boolean isSystemCaller) { |
| 2625 | final int callingUid = Binder.getCallingUid(); |
| 2626 | long ident = Binder.clearCallingIdentity(); |
| 2627 | try { |
| 2628 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2629 | getLockTaskController().stopLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2630 | } |
| 2631 | // Launch in-call UI if a call is ongoing. This is necessary to allow stopping the lock |
| 2632 | // task and jumping straight into a call in the case of emergency call back. |
| 2633 | TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
| 2634 | if (tm != null) { |
| 2635 | tm.showInCallScreen(false); |
| 2636 | } |
| 2637 | } finally { |
| 2638 | Binder.restoreCallingIdentity(ident); |
| 2639 | } |
| 2640 | } |
| 2641 | |
| 2642 | @Override |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 2643 | public void updateLockTaskPackages(int userId, String[] packages) { |
| 2644 | final int callingUid = Binder.getCallingUid(); |
| 2645 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 2646 | mAmInternal.enforceCallingPermission(Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
| 2647 | "updateLockTaskPackages()"); |
| 2648 | } |
| 2649 | synchronized (this) { |
| 2650 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Whitelisting " + userId + ":" |
| 2651 | + Arrays.toString(packages)); |
| 2652 | getLockTaskController().updateLockTaskPackages(userId, packages); |
| 2653 | } |
| 2654 | } |
| 2655 | |
| 2656 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2657 | public boolean isInLockTaskMode() { |
| 2658 | return getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
| 2659 | } |
| 2660 | |
| 2661 | @Override |
| 2662 | public int getLockTaskModeState() { |
| 2663 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2664 | return getLockTaskController().getLockTaskModeState(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2665 | } |
| 2666 | } |
| 2667 | |
| 2668 | @Override |
| 2669 | public void setTaskDescription(IBinder token, ActivityManager.TaskDescription td) { |
| 2670 | synchronized (mGlobalLock) { |
| 2671 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2672 | if (r != null) { |
| 2673 | r.setTaskDescription(td); |
| 2674 | final TaskRecord task = r.getTask(); |
| 2675 | task.updateTaskDescription(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2676 | mTaskChangeNotificationController.notifyTaskDescriptionChanged(task.taskId, td); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2677 | } |
| 2678 | } |
| 2679 | } |
| 2680 | |
| 2681 | @Override |
| 2682 | public Bundle getActivityOptions(IBinder token) { |
| 2683 | final long origId = Binder.clearCallingIdentity(); |
| 2684 | try { |
| 2685 | synchronized (mGlobalLock) { |
| 2686 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2687 | if (r != null) { |
| 2688 | final ActivityOptions activityOptions = r.takeOptionsLocked(); |
| 2689 | return activityOptions == null ? null : activityOptions.toBundle(); |
| 2690 | } |
| 2691 | return null; |
| 2692 | } |
| 2693 | } finally { |
| 2694 | Binder.restoreCallingIdentity(origId); |
| 2695 | } |
| 2696 | } |
| 2697 | |
| 2698 | @Override |
| 2699 | public List<IBinder> getAppTasks(String callingPackage) { |
| 2700 | int callingUid = Binder.getCallingUid(); |
| 2701 | long ident = Binder.clearCallingIdentity(); |
| 2702 | try { |
| 2703 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 2704 | return mRecentTasks.getAppTasksList(callingUid, callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2705 | } |
| 2706 | } finally { |
| 2707 | Binder.restoreCallingIdentity(ident); |
| 2708 | } |
| 2709 | } |
| 2710 | |
| 2711 | @Override |
| 2712 | public void finishVoiceTask(IVoiceInteractionSession session) { |
| 2713 | synchronized (mGlobalLock) { |
| 2714 | final long origId = Binder.clearCallingIdentity(); |
| 2715 | try { |
| 2716 | // TODO: VI Consider treating local voice interactions and voice tasks |
| 2717 | // differently here |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2718 | mRootActivityContainer.finishVoiceTask(session); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2719 | } finally { |
| 2720 | Binder.restoreCallingIdentity(origId); |
| 2721 | } |
| 2722 | } |
| 2723 | |
| 2724 | } |
| 2725 | |
| 2726 | @Override |
| 2727 | public boolean isTopOfTask(IBinder token) { |
| 2728 | synchronized (mGlobalLock) { |
| 2729 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Riddle Hsu | 66b74a8 | 2018-07-26 00:20:12 +0800 | [diff] [blame] | 2730 | return r != null && r.getTask().getTopActivity() == r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2731 | } |
| 2732 | } |
| 2733 | |
| 2734 | @Override |
| 2735 | public void notifyLaunchTaskBehindComplete(IBinder token) { |
| 2736 | mStackSupervisor.scheduleLaunchTaskBehindComplete(token); |
| 2737 | } |
| 2738 | |
| 2739 | @Override |
| 2740 | public void notifyEnterAnimationComplete(IBinder token) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2741 | mH.post(() -> { |
| 2742 | synchronized (mGlobalLock) { |
| 2743 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2744 | if (r != null && r.attachedToProcess()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2745 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2746 | r.app.getThread().scheduleEnterAnimationComplete(r.appToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2747 | } catch (RemoteException e) { |
| 2748 | } |
| 2749 | } |
| 2750 | } |
| 2751 | |
| 2752 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | /** Called from an app when assist data is ready. */ |
| 2756 | @Override |
| 2757 | public void reportAssistContextExtras(IBinder token, Bundle extras, AssistStructure structure, |
| 2758 | AssistContent content, Uri referrer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2759 | PendingAssistExtras pae = (PendingAssistExtras) token; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2760 | synchronized (pae) { |
| 2761 | pae.result = extras; |
| 2762 | pae.structure = structure; |
| 2763 | pae.content = content; |
| 2764 | if (referrer != null) { |
| 2765 | pae.extras.putParcelable(Intent.EXTRA_REFERRER, referrer); |
| 2766 | } |
| 2767 | if (structure != null) { |
Winson Chung | 48b2565 | 2018-10-22 14:04:30 -0700 | [diff] [blame] | 2768 | // Pre-fill the task/activity component for all assist data receivers |
| 2769 | structure.setTaskId(pae.activity.getTask().taskId); |
| 2770 | structure.setActivityComponent(pae.activity.realActivity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2771 | structure.setHomeActivity(pae.isHome); |
| 2772 | } |
| 2773 | pae.haveResult = true; |
| 2774 | pae.notifyAll(); |
| 2775 | if (pae.intent == null && pae.receiver == null) { |
| 2776 | // Caller is just waiting for the result. |
| 2777 | return; |
| 2778 | } |
| 2779 | } |
| 2780 | // We are now ready to launch the assist activity. |
| 2781 | IAssistDataReceiver sendReceiver = null; |
| 2782 | Bundle sendBundle = null; |
| 2783 | synchronized (mGlobalLock) { |
| 2784 | buildAssistBundleLocked(pae, extras); |
| 2785 | boolean exists = mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2786 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2787 | if (!exists) { |
| 2788 | // Timed out. |
| 2789 | return; |
| 2790 | } |
| 2791 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2792 | if ((sendReceiver = pae.receiver) != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2793 | // Caller wants result sent back to them. |
| 2794 | sendBundle = new Bundle(); |
| 2795 | sendBundle.putBundle(ASSIST_KEY_DATA, pae.extras); |
| 2796 | sendBundle.putParcelable(ASSIST_KEY_STRUCTURE, pae.structure); |
| 2797 | sendBundle.putParcelable(ASSIST_KEY_CONTENT, pae.content); |
| 2798 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 2799 | } |
| 2800 | } |
| 2801 | if (sendReceiver != null) { |
| 2802 | try { |
| 2803 | sendReceiver.onHandleAssistData(sendBundle); |
| 2804 | } catch (RemoteException e) { |
| 2805 | } |
| 2806 | return; |
| 2807 | } |
| 2808 | |
| 2809 | final long ident = Binder.clearCallingIdentity(); |
| 2810 | try { |
| 2811 | if (TextUtils.equals(pae.intent.getAction(), |
| 2812 | android.service.voice.VoiceInteractionService.SERVICE_INTERFACE)) { |
| 2813 | pae.intent.putExtras(pae.extras); |
| 2814 | mContext.startServiceAsUser(pae.intent, new UserHandle(pae.userHandle)); |
| 2815 | } else { |
| 2816 | pae.intent.replaceExtras(pae.extras); |
| 2817 | pae.intent.setFlags(FLAG_ACTIVITY_NEW_TASK |
| 2818 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 2819 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 2820 | mInternal.closeSystemDialogs("assist"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2821 | |
| 2822 | try { |
| 2823 | mContext.startActivityAsUser(pae.intent, new UserHandle(pae.userHandle)); |
| 2824 | } catch (ActivityNotFoundException e) { |
| 2825 | Slog.w(TAG, "No activity to handle assist action.", e); |
| 2826 | } |
| 2827 | } |
| 2828 | } finally { |
| 2829 | Binder.restoreCallingIdentity(ident); |
| 2830 | } |
| 2831 | } |
| 2832 | |
| 2833 | @Override |
| 2834 | public int addAppTask(IBinder activityToken, Intent intent, |
| 2835 | ActivityManager.TaskDescription description, Bitmap thumbnail) throws RemoteException { |
| 2836 | final int callingUid = Binder.getCallingUid(); |
| 2837 | final long callingIdent = Binder.clearCallingIdentity(); |
| 2838 | |
| 2839 | try { |
| 2840 | synchronized (mGlobalLock) { |
| 2841 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 2842 | if (r == null) { |
| 2843 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 2844 | + activityToken); |
| 2845 | } |
| 2846 | ComponentName comp = intent.getComponent(); |
| 2847 | if (comp == null) { |
| 2848 | throw new IllegalArgumentException("Intent " + intent |
| 2849 | + " must specify explicit component"); |
| 2850 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2851 | if (thumbnail.getWidth() != mThumbnailWidth |
| 2852 | || thumbnail.getHeight() != mThumbnailHeight) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2853 | throw new IllegalArgumentException("Bad thumbnail size: got " |
| 2854 | + thumbnail.getWidth() + "x" + thumbnail.getHeight() + ", require " |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2855 | + mThumbnailWidth + "x" + mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2856 | } |
| 2857 | if (intent.getSelector() != null) { |
| 2858 | intent.setSelector(null); |
| 2859 | } |
| 2860 | if (intent.getSourceBounds() != null) { |
| 2861 | intent.setSourceBounds(null); |
| 2862 | } |
| 2863 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) { |
| 2864 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) == 0) { |
| 2865 | // The caller has added this as an auto-remove task... that makes no |
| 2866 | // sense, so turn off auto-remove. |
| 2867 | intent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS); |
| 2868 | } |
| 2869 | } |
| 2870 | final ActivityInfo ainfo = AppGlobals.getPackageManager().getActivityInfo(comp, |
| 2871 | STOCK_PM_FLAGS, UserHandle.getUserId(callingUid)); |
| 2872 | if (ainfo.applicationInfo.uid != callingUid) { |
| 2873 | throw new SecurityException( |
| 2874 | "Can't add task for another application: target uid=" |
| 2875 | + ainfo.applicationInfo.uid + ", calling uid=" + callingUid); |
| 2876 | } |
| 2877 | |
| 2878 | final ActivityStack stack = r.getStack(); |
| 2879 | final TaskRecord task = stack.createTaskRecord( |
| 2880 | mStackSupervisor.getNextTaskIdForUserLocked(r.userId), ainfo, intent, |
| 2881 | null /* voiceSession */, null /* voiceInteractor */, !ON_TOP); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 2882 | if (!mRecentTasks.addToBottom(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2883 | // The app has too many tasks already and we can't add any more |
| 2884 | stack.removeTask(task, "addAppTask", REMOVE_TASK_MODE_DESTROYING); |
| 2885 | return INVALID_TASK_ID; |
| 2886 | } |
| 2887 | task.lastTaskDescription.copyFrom(description); |
| 2888 | |
| 2889 | // TODO: Send the thumbnail to WM to store it. |
| 2890 | |
| 2891 | return task.taskId; |
| 2892 | } |
| 2893 | } finally { |
| 2894 | Binder.restoreCallingIdentity(callingIdent); |
| 2895 | } |
| 2896 | } |
| 2897 | |
| 2898 | @Override |
| 2899 | public Point getAppTaskThumbnailSize() { |
| 2900 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2901 | return new Point(mThumbnailWidth, mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2902 | } |
| 2903 | } |
| 2904 | |
| 2905 | @Override |
| 2906 | public void setTaskResizeable(int taskId, int resizeableMode) { |
| 2907 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2908 | final TaskRecord task = mRootActivityContainer.anyTaskForId( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2909 | taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2910 | if (task == null) { |
| 2911 | Slog.w(TAG, "setTaskResizeable: taskId=" + taskId + " not found"); |
| 2912 | return; |
| 2913 | } |
| 2914 | task.setResizeMode(resizeableMode); |
| 2915 | } |
| 2916 | } |
| 2917 | |
| 2918 | @Override |
| 2919 | public void resizeTask(int taskId, Rect bounds, int resizeMode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2920 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "resizeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2921 | long ident = Binder.clearCallingIdentity(); |
| 2922 | try { |
| 2923 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2924 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2925 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2926 | if (task == null) { |
| 2927 | Slog.w(TAG, "resizeTask: taskId=" + taskId + " not found"); |
| 2928 | return; |
| 2929 | } |
| 2930 | // Place the task in the right stack if it isn't there already based on |
| 2931 | // the requested bounds. |
| 2932 | // The stack transition logic is: |
| 2933 | // - a null bounds on a freeform task moves that task to fullscreen |
| 2934 | // - a non-null bounds on a non-freeform (fullscreen OR docked) task moves |
| 2935 | // that task to freeform |
| 2936 | // - otherwise the task is not moved |
| 2937 | ActivityStack stack = task.getStack(); |
| 2938 | if (!task.getWindowConfiguration().canResizeTask()) { |
| 2939 | throw new IllegalArgumentException("resizeTask not allowed on task=" + task); |
| 2940 | } |
| 2941 | if (bounds == null && stack.getWindowingMode() == WINDOWING_MODE_FREEFORM) { |
| 2942 | stack = stack.getDisplay().getOrCreateStack( |
| 2943 | WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), ON_TOP); |
| 2944 | } else if (bounds != null && stack.getWindowingMode() != WINDOWING_MODE_FREEFORM) { |
| 2945 | stack = stack.getDisplay().getOrCreateStack( |
| 2946 | WINDOWING_MODE_FREEFORM, stack.getActivityType(), ON_TOP); |
| 2947 | } |
| 2948 | |
| 2949 | // Reparent the task to the right stack if necessary |
| 2950 | boolean preserveWindow = (resizeMode & RESIZE_MODE_PRESERVE_WINDOW) != 0; |
| 2951 | if (stack != task.getStack()) { |
| 2952 | // Defer resume until the task is resized below |
| 2953 | task.reparent(stack, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, |
| 2954 | DEFER_RESUME, "resizeTask"); |
| 2955 | preserveWindow = false; |
| 2956 | } |
| 2957 | |
| 2958 | // After reparenting (which only resizes the task to the stack bounds), resize the |
| 2959 | // task to the actual bounds provided |
| 2960 | task.resize(bounds, resizeMode, preserveWindow, !DEFER_RESUME); |
| 2961 | } |
| 2962 | } finally { |
| 2963 | Binder.restoreCallingIdentity(ident); |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | @Override |
| 2968 | public boolean releaseActivityInstance(IBinder token) { |
| 2969 | synchronized (mGlobalLock) { |
| 2970 | final long origId = Binder.clearCallingIdentity(); |
| 2971 | try { |
| 2972 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2973 | if (r == null) { |
| 2974 | return false; |
| 2975 | } |
| 2976 | return r.getStack().safelyDestroyActivityLocked(r, "app-req"); |
| 2977 | } finally { |
| 2978 | Binder.restoreCallingIdentity(origId); |
| 2979 | } |
| 2980 | } |
| 2981 | } |
| 2982 | |
| 2983 | @Override |
| 2984 | public void releaseSomeActivities(IApplicationThread appInt) { |
| 2985 | synchronized (mGlobalLock) { |
| 2986 | final long origId = Binder.clearCallingIdentity(); |
| 2987 | try { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 2988 | final WindowProcessController app = getProcessController(appInt); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2989 | mRootActivityContainer.releaseSomeActivitiesLocked(app, "low-mem"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2990 | } finally { |
| 2991 | Binder.restoreCallingIdentity(origId); |
| 2992 | } |
| 2993 | } |
| 2994 | } |
| 2995 | |
| 2996 | @Override |
| 2997 | public void setLockScreenShown(boolean keyguardShowing, boolean aodShowing, |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 2998 | int[] secondaryDisplaysShowing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2999 | if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3000 | != PackageManager.PERMISSION_GRANTED) { |
| 3001 | throw new SecurityException("Requires permission " |
| 3002 | + android.Manifest.permission.DEVICE_POWER); |
| 3003 | } |
| 3004 | |
| 3005 | synchronized (mGlobalLock) { |
| 3006 | long ident = Binder.clearCallingIdentity(); |
| 3007 | if (mKeyguardShown != keyguardShowing) { |
| 3008 | mKeyguardShown = keyguardShowing; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3009 | final Message msg = PooledLambda.obtainMessage( |
| 3010 | ActivityManagerInternal::reportCurKeyguardUsageEvent, mAmInternal, |
| 3011 | keyguardShowing); |
| 3012 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3013 | } |
| 3014 | try { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3015 | mKeyguardController.setKeyguardShown(keyguardShowing, aodShowing, |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 3016 | secondaryDisplaysShowing); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3017 | } finally { |
| 3018 | Binder.restoreCallingIdentity(ident); |
| 3019 | } |
| 3020 | } |
| 3021 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3022 | mH.post(() -> { |
| 3023 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3024 | mScreenObservers.get(i).onKeyguardStateChanged(keyguardShowing); |
| 3025 | } |
| 3026 | }); |
| 3027 | } |
| 3028 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 3029 | public void onScreenAwakeChanged(boolean isAwake) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3030 | mH.post(() -> { |
| 3031 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3032 | mScreenObservers.get(i).onAwakeStateChanged(isAwake); |
| 3033 | } |
| 3034 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | @Override |
| 3038 | public Bitmap getTaskDescriptionIcon(String filePath, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3039 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 3040 | userId, "getTaskDescriptionIcon"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3041 | |
| 3042 | final File passedIconFile = new File(filePath); |
| 3043 | final File legitIconFile = new File(TaskPersister.getUserImagesDir(userId), |
| 3044 | passedIconFile.getName()); |
| 3045 | if (!legitIconFile.getPath().equals(filePath) |
| 3046 | || !filePath.contains(ActivityRecord.ACTIVITY_ICON_SUFFIX)) { |
| 3047 | throw new IllegalArgumentException("Bad file path: " + filePath |
| 3048 | + " passed for userId " + userId); |
| 3049 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3050 | return mRecentTasks.getTaskDescriptionIcon(filePath); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3051 | } |
| 3052 | |
| 3053 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3054 | public void startInPlaceAnimationOnFrontMostApplication(Bundle opts) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3055 | final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(opts); |
| 3056 | final ActivityOptions activityOptions = safeOptions != null |
| 3057 | ? safeOptions.getOptions(mStackSupervisor) |
| 3058 | : null; |
| 3059 | if (activityOptions == null |
| 3060 | || activityOptions.getAnimationType() != ActivityOptions.ANIM_CUSTOM_IN_PLACE |
| 3061 | || activityOptions.getCustomInPlaceResId() == 0) { |
| 3062 | throw new IllegalArgumentException("Expected in-place ActivityOption " + |
| 3063 | "with valid animation"); |
| 3064 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3065 | // Get top display of front most application. |
| 3066 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
| 3067 | if (focusedStack != null) { |
| 3068 | final DisplayWindowController dwc = |
| 3069 | focusedStack.getDisplay().getWindowContainerController(); |
| 3070 | dwc.prepareAppTransition(TRANSIT_TASK_IN_PLACE, false); |
| 3071 | dwc.overridePendingAppTransitionInPlace(activityOptions.getPackageName(), |
| 3072 | activityOptions.getCustomInPlaceResId()); |
| 3073 | dwc.executeAppTransition(); |
| 3074 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | @Override |
| 3078 | public void removeStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3079 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "removeStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3080 | synchronized (mGlobalLock) { |
| 3081 | final long ident = Binder.clearCallingIdentity(); |
| 3082 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3083 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3084 | if (stack == null) { |
| 3085 | Slog.w(TAG, "removeStack: No stack with id=" + stackId); |
| 3086 | return; |
| 3087 | } |
| 3088 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3089 | throw new IllegalArgumentException( |
| 3090 | "Removing non-standard stack is not allowed."); |
| 3091 | } |
| 3092 | mStackSupervisor.removeStack(stack); |
| 3093 | } finally { |
| 3094 | Binder.restoreCallingIdentity(ident); |
| 3095 | } |
| 3096 | } |
| 3097 | } |
| 3098 | |
| 3099 | @Override |
| 3100 | public void moveStackToDisplay(int stackId, int displayId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3101 | mAmInternal.enforceCallingPermission(INTERNAL_SYSTEM_WINDOW, "moveStackToDisplay()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3102 | |
| 3103 | synchronized (mGlobalLock) { |
| 3104 | final long ident = Binder.clearCallingIdentity(); |
| 3105 | try { |
| 3106 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveStackToDisplay: moving stackId=" + stackId |
| 3107 | + " to displayId=" + displayId); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3108 | mRootActivityContainer.moveStackToDisplay(stackId, displayId, ON_TOP); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3109 | } finally { |
| 3110 | Binder.restoreCallingIdentity(ident); |
| 3111 | } |
| 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3116 | public void exitFreeformMode(IBinder token) { |
| 3117 | synchronized (mGlobalLock) { |
| 3118 | long ident = Binder.clearCallingIdentity(); |
| 3119 | try { |
| 3120 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3121 | if (r == null) { |
| 3122 | throw new IllegalArgumentException( |
| 3123 | "exitFreeformMode: No activity record matching token=" + token); |
| 3124 | } |
| 3125 | |
| 3126 | final ActivityStack stack = r.getStack(); |
| 3127 | if (stack == null || !stack.inFreeformWindowingMode()) { |
| 3128 | throw new IllegalStateException( |
| 3129 | "exitFreeformMode: You can only go fullscreen from freeform."); |
| 3130 | } |
| 3131 | |
| 3132 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 3133 | } finally { |
| 3134 | Binder.restoreCallingIdentity(ident); |
| 3135 | } |
| 3136 | } |
| 3137 | } |
| 3138 | |
| 3139 | /** Sets the task stack listener that gets callbacks when a task stack changes. */ |
| 3140 | @Override |
| 3141 | public void registerTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3142 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3143 | "registerTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3144 | mTaskChangeNotificationController.registerTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | /** Unregister a task stack listener so that it stops receiving callbacks. */ |
| 3148 | @Override |
| 3149 | public void unregisterTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3150 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3151 | "unregisterTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3152 | mTaskChangeNotificationController.unregisterTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3153 | } |
| 3154 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3155 | @Override |
| 3156 | public boolean requestAssistContextExtras(int requestType, IAssistDataReceiver receiver, |
| 3157 | Bundle receiverExtras, IBinder activityToken, boolean focused, boolean newSessionId) { |
| 3158 | return enqueueAssistContext(requestType, null, null, receiver, receiverExtras, |
| 3159 | activityToken, focused, newSessionId, UserHandle.getCallingUserId(), null, |
| 3160 | PENDING_ASSIST_EXTRAS_LONG_TIMEOUT, 0) != null; |
| 3161 | } |
| 3162 | |
| 3163 | @Override |
| 3164 | public boolean requestAutofillData(IAssistDataReceiver receiver, Bundle receiverExtras, |
| 3165 | IBinder activityToken, int flags) { |
| 3166 | return enqueueAssistContext(ActivityManager.ASSIST_CONTEXT_AUTOFILL, null, null, |
| 3167 | receiver, receiverExtras, activityToken, true, true, UserHandle.getCallingUserId(), |
| 3168 | null, PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT, flags) != null; |
| 3169 | } |
| 3170 | |
| 3171 | @Override |
| 3172 | public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle, |
| 3173 | Bundle args) { |
| 3174 | return enqueueAssistContext(requestType, intent, hint, null, null, null, |
| 3175 | true /* focused */, true /* newSessionId */, userHandle, args, |
| 3176 | PENDING_ASSIST_EXTRAS_TIMEOUT, 0) != null; |
| 3177 | } |
| 3178 | |
| 3179 | @Override |
| 3180 | public Bundle getAssistContextExtras(int requestType) { |
| 3181 | PendingAssistExtras pae = enqueueAssistContext(requestType, null, null, null, |
| 3182 | null, null, true /* focused */, true /* newSessionId */, |
| 3183 | UserHandle.getCallingUserId(), null, PENDING_ASSIST_EXTRAS_TIMEOUT, 0); |
| 3184 | if (pae == null) { |
| 3185 | return null; |
| 3186 | } |
| 3187 | synchronized (pae) { |
| 3188 | while (!pae.haveResult) { |
| 3189 | try { |
| 3190 | pae.wait(); |
| 3191 | } catch (InterruptedException e) { |
| 3192 | } |
| 3193 | } |
| 3194 | } |
| 3195 | synchronized (mGlobalLock) { |
| 3196 | buildAssistBundleLocked(pae, pae.result); |
| 3197 | mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3198 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3199 | } |
| 3200 | return pae.extras; |
| 3201 | } |
| 3202 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3203 | /** |
| 3204 | * Binder IPC calls go through the public entry point. |
| 3205 | * This can be called with or without the global lock held. |
| 3206 | */ |
| 3207 | private static int checkCallingPermission(String permission) { |
| 3208 | return checkPermission( |
| 3209 | permission, Binder.getCallingPid(), UserHandle.getAppId(Binder.getCallingUid())); |
| 3210 | } |
| 3211 | |
| 3212 | /** This can be called with or without the global lock held. */ |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3213 | private void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3214 | if (!getRecentTasks().isCallerRecents(Binder.getCallingUid())) { |
| 3215 | mAmInternal.enforceCallingPermission(permission, func); |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | @VisibleForTesting |
| 3220 | int checkGetTasksPermission(String permission, int pid, int uid) { |
| 3221 | return checkPermission(permission, pid, uid); |
| 3222 | } |
| 3223 | |
| 3224 | static int checkPermission(String permission, int pid, int uid) { |
| 3225 | if (permission == null) { |
| 3226 | return PackageManager.PERMISSION_DENIED; |
| 3227 | } |
| 3228 | return checkComponentPermission(permission, pid, uid, -1, true); |
| 3229 | } |
| 3230 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3231 | public static int checkComponentPermission(String permission, int pid, int uid, |
| 3232 | int owningUid, boolean exported) { |
| 3233 | return ActivityManagerService.checkComponentPermission( |
| 3234 | permission, pid, uid, owningUid, exported); |
| 3235 | } |
| 3236 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3237 | boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 3238 | if (getRecentTasks().isCallerRecents(callingUid)) { |
| 3239 | // Always allow the recents component to get tasks |
| 3240 | return true; |
| 3241 | } |
| 3242 | |
| 3243 | boolean allowed = checkGetTasksPermission(android.Manifest.permission.REAL_GET_TASKS, |
| 3244 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED; |
| 3245 | if (!allowed) { |
| 3246 | if (checkGetTasksPermission(android.Manifest.permission.GET_TASKS, |
| 3247 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED) { |
| 3248 | // Temporary compatibility: some existing apps on the system image may |
| 3249 | // still be requesting the old permission and not switched to the new |
| 3250 | // one; if so, we'll still allow them full access. This means we need |
| 3251 | // to see if they are holding the old permission and are a system app. |
| 3252 | try { |
| 3253 | if (AppGlobals.getPackageManager().isUidPrivileged(callingUid)) { |
| 3254 | allowed = true; |
| 3255 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3256 | + " is using old GET_TASKS but privileged; allowing"); |
| 3257 | } |
| 3258 | } catch (RemoteException e) { |
| 3259 | } |
| 3260 | } |
| 3261 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3262 | + " does not hold REAL_GET_TASKS; limiting output"); |
| 3263 | } |
| 3264 | return allowed; |
| 3265 | } |
| 3266 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3267 | private PendingAssistExtras enqueueAssistContext(int requestType, Intent intent, String hint, |
| 3268 | IAssistDataReceiver receiver, Bundle receiverExtras, IBinder activityToken, |
| 3269 | boolean focused, boolean newSessionId, int userHandle, Bundle args, long timeout, |
| 3270 | int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3271 | mAmInternal.enforceCallingPermission(android.Manifest.permission.GET_TOP_ACTIVITY_INFO, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3272 | "enqueueAssistContext()"); |
| 3273 | |
| 3274 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3275 | ActivityRecord activity = getTopDisplayFocusedStack().getTopActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3276 | if (activity == null) { |
| 3277 | Slog.w(TAG, "getAssistContextExtras failed: no top activity"); |
| 3278 | return null; |
| 3279 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3280 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3281 | Slog.w(TAG, "getAssistContextExtras failed: no process for " + activity); |
| 3282 | return null; |
| 3283 | } |
| 3284 | if (focused) { |
| 3285 | if (activityToken != null) { |
| 3286 | ActivityRecord caller = ActivityRecord.forTokenLocked(activityToken); |
| 3287 | if (activity != caller) { |
| 3288 | Slog.w(TAG, "enqueueAssistContext failed: caller " + caller |
| 3289 | + " is not current top " + activity); |
| 3290 | return null; |
| 3291 | } |
| 3292 | } |
| 3293 | } else { |
| 3294 | activity = ActivityRecord.forTokenLocked(activityToken); |
| 3295 | if (activity == null) { |
| 3296 | Slog.w(TAG, "enqueueAssistContext failed: activity for token=" + activityToken |
| 3297 | + " couldn't be found"); |
| 3298 | return null; |
| 3299 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3300 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3301 | Slog.w(TAG, "enqueueAssistContext failed: no process for " + activity); |
| 3302 | return null; |
| 3303 | } |
| 3304 | } |
| 3305 | |
| 3306 | PendingAssistExtras pae; |
| 3307 | Bundle extras = new Bundle(); |
| 3308 | if (args != null) { |
| 3309 | extras.putAll(args); |
| 3310 | } |
| 3311 | extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3312 | extras.putInt(Intent.EXTRA_ASSIST_UID, activity.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3313 | |
| 3314 | pae = new PendingAssistExtras(activity, extras, intent, hint, receiver, receiverExtras, |
| 3315 | userHandle); |
| 3316 | pae.isHome = activity.isActivityTypeHome(); |
| 3317 | |
| 3318 | // Increment the sessionId if necessary |
| 3319 | if (newSessionId) { |
| 3320 | mViSessionId++; |
| 3321 | } |
| 3322 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3323 | activity.app.getThread().requestAssistContextExtras(activity.appToken, pae, |
| 3324 | requestType, mViSessionId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3325 | mPendingAssistExtras.add(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3326 | mUiHandler.postDelayed(pae, timeout); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3327 | } catch (RemoteException e) { |
| 3328 | Slog.w(TAG, "getAssistContextExtras failed: crash calling " + activity); |
| 3329 | return null; |
| 3330 | } |
| 3331 | return pae; |
| 3332 | } |
| 3333 | } |
| 3334 | |
| 3335 | private void buildAssistBundleLocked(PendingAssistExtras pae, Bundle result) { |
| 3336 | if (result != null) { |
| 3337 | pae.extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, result); |
| 3338 | } |
| 3339 | if (pae.hint != null) { |
| 3340 | pae.extras.putBoolean(pae.hint, true); |
| 3341 | } |
| 3342 | } |
| 3343 | |
| 3344 | private void pendingAssistExtrasTimedOut(PendingAssistExtras pae) { |
| 3345 | IAssistDataReceiver receiver; |
| 3346 | synchronized (mGlobalLock) { |
| 3347 | mPendingAssistExtras.remove(pae); |
| 3348 | receiver = pae.receiver; |
| 3349 | } |
| 3350 | if (receiver != null) { |
| 3351 | // Caller wants result sent back to them. |
| 3352 | Bundle sendBundle = new Bundle(); |
| 3353 | // At least return the receiver extras |
| 3354 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3355 | try { |
| 3356 | pae.receiver.onHandleAssistData(sendBundle); |
| 3357 | } catch (RemoteException e) { |
| 3358 | } |
| 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | public class PendingAssistExtras extends Binder implements Runnable { |
| 3363 | public final ActivityRecord activity; |
| 3364 | public boolean isHome; |
| 3365 | public final Bundle extras; |
| 3366 | public final Intent intent; |
| 3367 | public final String hint; |
| 3368 | public final IAssistDataReceiver receiver; |
| 3369 | public final int userHandle; |
| 3370 | public boolean haveResult = false; |
| 3371 | public Bundle result = null; |
| 3372 | public AssistStructure structure = null; |
| 3373 | public AssistContent content = null; |
| 3374 | public Bundle receiverExtras; |
| 3375 | |
| 3376 | public PendingAssistExtras(ActivityRecord _activity, Bundle _extras, Intent _intent, |
| 3377 | String _hint, IAssistDataReceiver _receiver, Bundle _receiverExtras, |
| 3378 | int _userHandle) { |
| 3379 | activity = _activity; |
| 3380 | extras = _extras; |
| 3381 | intent = _intent; |
| 3382 | hint = _hint; |
| 3383 | receiver = _receiver; |
| 3384 | receiverExtras = _receiverExtras; |
| 3385 | userHandle = _userHandle; |
| 3386 | } |
| 3387 | |
| 3388 | @Override |
| 3389 | public void run() { |
| 3390 | Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from " + activity); |
| 3391 | synchronized (this) { |
| 3392 | haveResult = true; |
| 3393 | notifyAll(); |
| 3394 | } |
| 3395 | pendingAssistExtrasTimedOut(this); |
| 3396 | } |
| 3397 | } |
| 3398 | |
| 3399 | @Override |
| 3400 | public boolean isAssistDataAllowedOnCurrentActivity() { |
| 3401 | int userId; |
| 3402 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3403 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3404 | if (focusedStack == null || focusedStack.isActivityTypeAssistant()) { |
| 3405 | return false; |
| 3406 | } |
| 3407 | |
| 3408 | final ActivityRecord activity = focusedStack.getTopActivity(); |
| 3409 | if (activity == null) { |
| 3410 | return false; |
| 3411 | } |
| 3412 | userId = activity.userId; |
| 3413 | } |
| 3414 | return !DevicePolicyCache.getInstance().getScreenCaptureDisabled(userId); |
| 3415 | } |
| 3416 | |
| 3417 | @Override |
| 3418 | public boolean showAssistFromActivity(IBinder token, Bundle args) { |
| 3419 | long ident = Binder.clearCallingIdentity(); |
| 3420 | try { |
| 3421 | synchronized (mGlobalLock) { |
| 3422 | ActivityRecord caller = ActivityRecord.forTokenLocked(token); |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3423 | ActivityRecord top = getTopDisplayFocusedStack().getTopActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3424 | if (top != caller) { |
| 3425 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3426 | + " is not current top " + top); |
| 3427 | return false; |
| 3428 | } |
| 3429 | if (!top.nowVisible) { |
| 3430 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3431 | + " is not visible"); |
| 3432 | return false; |
| 3433 | } |
| 3434 | } |
| 3435 | return mAssistUtils.showSessionForActiveService(args, SHOW_SOURCE_APPLICATION, null, |
| 3436 | token); |
| 3437 | } finally { |
| 3438 | Binder.restoreCallingIdentity(ident); |
| 3439 | } |
| 3440 | } |
| 3441 | |
| 3442 | @Override |
| 3443 | public boolean isRootVoiceInteraction(IBinder token) { |
| 3444 | synchronized (mGlobalLock) { |
| 3445 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3446 | if (r == null) { |
| 3447 | return false; |
| 3448 | } |
| 3449 | return r.rootVoiceInteraction; |
| 3450 | } |
| 3451 | } |
| 3452 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3453 | private void onLocalVoiceInteractionStartedLocked(IBinder activity, |
| 3454 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 3455 | ActivityRecord activityToCallback = ActivityRecord.forTokenLocked(activity); |
| 3456 | if (activityToCallback == null) return; |
| 3457 | activityToCallback.setVoiceSessionLocked(voiceSession); |
| 3458 | |
| 3459 | // Inform the activity |
| 3460 | try { |
| 3461 | activityToCallback.app.getThread().scheduleLocalVoiceInteractionStarted(activity, |
| 3462 | voiceInteractor); |
| 3463 | long token = Binder.clearCallingIdentity(); |
| 3464 | try { |
| 3465 | startRunningVoiceLocked(voiceSession, activityToCallback.appInfo.uid); |
| 3466 | } finally { |
| 3467 | Binder.restoreCallingIdentity(token); |
| 3468 | } |
| 3469 | // TODO: VI Should we cache the activity so that it's easier to find later |
| 3470 | // rather than scan through all the stacks and activities? |
| 3471 | } catch (RemoteException re) { |
| 3472 | activityToCallback.clearVoiceSessionLocked(); |
| 3473 | // TODO: VI Should this terminate the voice session? |
| 3474 | } |
| 3475 | } |
| 3476 | |
| 3477 | private void startRunningVoiceLocked(IVoiceInteractionSession session, int targetUid) { |
| 3478 | Slog.d(TAG, "<<< startRunningVoiceLocked()"); |
| 3479 | mVoiceWakeLock.setWorkSource(new WorkSource(targetUid)); |
| 3480 | if (mRunningVoice == null || mRunningVoice.asBinder() != session.asBinder()) { |
| 3481 | boolean wasRunningVoice = mRunningVoice != null; |
| 3482 | mRunningVoice = session; |
| 3483 | if (!wasRunningVoice) { |
| 3484 | mVoiceWakeLock.acquire(); |
| 3485 | updateSleepIfNeededLocked(); |
| 3486 | } |
| 3487 | } |
| 3488 | } |
| 3489 | |
| 3490 | void finishRunningVoiceLocked() { |
| 3491 | if (mRunningVoice != null) { |
| 3492 | mRunningVoice = null; |
| 3493 | mVoiceWakeLock.release(); |
| 3494 | updateSleepIfNeededLocked(); |
| 3495 | } |
| 3496 | } |
| 3497 | |
| 3498 | @Override |
| 3499 | public void setVoiceKeepAwake(IVoiceInteractionSession session, boolean keepAwake) { |
| 3500 | synchronized (mGlobalLock) { |
| 3501 | if (mRunningVoice != null && mRunningVoice.asBinder() == session.asBinder()) { |
| 3502 | if (keepAwake) { |
| 3503 | mVoiceWakeLock.acquire(); |
| 3504 | } else { |
| 3505 | mVoiceWakeLock.release(); |
| 3506 | } |
| 3507 | } |
| 3508 | } |
| 3509 | } |
| 3510 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3511 | @Override |
| 3512 | public ComponentName getActivityClassForToken(IBinder token) { |
| 3513 | synchronized (mGlobalLock) { |
| 3514 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3515 | if (r == null) { |
| 3516 | return null; |
| 3517 | } |
| 3518 | return r.intent.getComponent(); |
| 3519 | } |
| 3520 | } |
| 3521 | |
| 3522 | @Override |
| 3523 | public String getPackageForToken(IBinder token) { |
| 3524 | synchronized (mGlobalLock) { |
| 3525 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3526 | if (r == null) { |
| 3527 | return null; |
| 3528 | } |
| 3529 | return r.packageName; |
| 3530 | } |
| 3531 | } |
| 3532 | |
| 3533 | @Override |
| 3534 | public void showLockTaskEscapeMessage(IBinder token) { |
| 3535 | synchronized (mGlobalLock) { |
| 3536 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3537 | if (r == null) { |
| 3538 | return; |
| 3539 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3540 | getLockTaskController().showLockTaskToast(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3541 | } |
| 3542 | } |
| 3543 | |
| 3544 | @Override |
| 3545 | public void keyguardGoingAway(int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3546 | enforceNotIsolatedCaller("keyguardGoingAway"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3547 | final long token = Binder.clearCallingIdentity(); |
| 3548 | try { |
| 3549 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3550 | mKeyguardController.keyguardGoingAway(flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3551 | } |
| 3552 | } finally { |
| 3553 | Binder.restoreCallingIdentity(token); |
| 3554 | } |
| 3555 | } |
| 3556 | |
| 3557 | /** |
| 3558 | * Try to place task to provided position. The final position might be different depending on |
| 3559 | * current user and stacks state. The task will be moved to target stack if it's currently in |
| 3560 | * different stack. |
| 3561 | */ |
| 3562 | @Override |
| 3563 | public void positionTaskInStack(int taskId, int stackId, int position) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3564 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "positionTaskInStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3565 | synchronized (mGlobalLock) { |
| 3566 | long ident = Binder.clearCallingIdentity(); |
| 3567 | try { |
| 3568 | if (DEBUG_STACK) Slog.d(TAG_STACK, "positionTaskInStack: positioning task=" |
| 3569 | + taskId + " in stackId=" + stackId + " at position=" + position); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3570 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3571 | if (task == null) { |
| 3572 | throw new IllegalArgumentException("positionTaskInStack: no task for id=" |
| 3573 | + taskId); |
| 3574 | } |
| 3575 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3576 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3577 | |
| 3578 | if (stack == null) { |
| 3579 | throw new IllegalArgumentException("positionTaskInStack: no stack for id=" |
| 3580 | + stackId); |
| 3581 | } |
| 3582 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3583 | throw new IllegalArgumentException("positionTaskInStack: Attempt to change" |
| 3584 | + " the position of task " + taskId + " in/to non-standard stack"); |
| 3585 | } |
| 3586 | |
| 3587 | // TODO: Have the callers of this API call a separate reparent method if that is |
| 3588 | // what they intended to do vs. having this method also do reparenting. |
| 3589 | if (task.getStack() == stack) { |
| 3590 | // Change position in current stack. |
| 3591 | stack.positionChildAt(task, position); |
| 3592 | } else { |
| 3593 | // Reparent to new stack. |
| 3594 | task.reparent(stack, position, REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, |
| 3595 | !DEFER_RESUME, "positionTaskInStack"); |
| 3596 | } |
| 3597 | } finally { |
| 3598 | Binder.restoreCallingIdentity(ident); |
| 3599 | } |
| 3600 | } |
| 3601 | } |
| 3602 | |
| 3603 | @Override |
| 3604 | public void reportSizeConfigurations(IBinder token, int[] horizontalSizeConfiguration, |
| 3605 | int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { |
| 3606 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Report configuration: " + token + " " |
| 3607 | + horizontalSizeConfiguration + " " + verticalSizeConfigurations); |
| 3608 | synchronized (mGlobalLock) { |
| 3609 | ActivityRecord record = ActivityRecord.isInStackLocked(token); |
| 3610 | if (record == null) { |
| 3611 | throw new IllegalArgumentException("reportSizeConfigurations: ActivityRecord not " |
| 3612 | + "found for: " + token); |
| 3613 | } |
| 3614 | record.setSizeConfigurations(horizontalSizeConfiguration, |
| 3615 | verticalSizeConfigurations, smallestSizeConfigurations); |
| 3616 | } |
| 3617 | } |
| 3618 | |
| 3619 | /** |
| 3620 | * Dismisses split-screen multi-window mode. |
| 3621 | * @param toTop If true the current primary split-screen stack will be placed or left on top. |
| 3622 | */ |
| 3623 | @Override |
| 3624 | public void dismissSplitScreenMode(boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3625 | enforceCallerIsRecentsOrHasPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3626 | MANAGE_ACTIVITY_STACKS, "dismissSplitScreenMode()"); |
| 3627 | final long ident = Binder.clearCallingIdentity(); |
| 3628 | try { |
| 3629 | synchronized (mGlobalLock) { |
| 3630 | final ActivityStack stack = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3631 | mRootActivityContainer.getDefaultDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3632 | if (stack == null) { |
| 3633 | Slog.w(TAG, "dismissSplitScreenMode: primary split-screen stack not found."); |
| 3634 | return; |
| 3635 | } |
| 3636 | |
| 3637 | if (toTop) { |
| 3638 | // Caller wants the current split-screen primary stack to be the top stack after |
| 3639 | // it goes fullscreen, so move it to the front. |
| 3640 | stack.moveToFront("dismissSplitScreenMode"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3641 | } else if (mRootActivityContainer.isTopDisplayFocusedStack(stack)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3642 | // In this case the current split-screen primary stack shouldn't be the top |
| 3643 | // stack after it goes fullscreen, but it current has focus, so we move the |
| 3644 | // focus to the top-most split-screen secondary stack next to it. |
| 3645 | final ActivityStack otherStack = stack.getDisplay().getTopStackInWindowingMode( |
| 3646 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 3647 | if (otherStack != null) { |
| 3648 | otherStack.moveToFront("dismissSplitScreenMode_other"); |
| 3649 | } |
| 3650 | } |
| 3651 | |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 3652 | stack.setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3653 | } |
| 3654 | } finally { |
| 3655 | Binder.restoreCallingIdentity(ident); |
| 3656 | } |
| 3657 | } |
| 3658 | |
| 3659 | /** |
| 3660 | * Dismisses Pip |
| 3661 | * @param animate True if the dismissal should be animated. |
| 3662 | * @param animationDuration The duration of the resize animation in milliseconds or -1 if the |
| 3663 | * default animation duration should be used. |
| 3664 | */ |
| 3665 | @Override |
| 3666 | public void dismissPip(boolean animate, int animationDuration) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3667 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "dismissPip()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3668 | final long ident = Binder.clearCallingIdentity(); |
| 3669 | try { |
| 3670 | synchronized (mGlobalLock) { |
| 3671 | final PinnedActivityStack stack = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3672 | mRootActivityContainer.getDefaultDisplay().getPinnedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3673 | if (stack == null) { |
| 3674 | Slog.w(TAG, "dismissPip: pinned stack not found."); |
| 3675 | return; |
| 3676 | } |
| 3677 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 3678 | throw new IllegalArgumentException("Stack: " + stack |
| 3679 | + " doesn't support animated resize."); |
| 3680 | } |
| 3681 | if (animate) { |
| 3682 | stack.animateResizePinnedStack(null /* sourceHintBounds */, |
| 3683 | null /* destBounds */, animationDuration, false /* fromFullscreen */); |
| 3684 | } else { |
| 3685 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, true /* onTop */); |
| 3686 | } |
| 3687 | } |
| 3688 | } finally { |
| 3689 | Binder.restoreCallingIdentity(ident); |
| 3690 | } |
| 3691 | } |
| 3692 | |
| 3693 | @Override |
| 3694 | public void suppressResizeConfigChanges(boolean suppress) throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3695 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "suppressResizeConfigChanges()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3696 | synchronized (mGlobalLock) { |
| 3697 | mSuppressResizeConfigChanges = suppress; |
| 3698 | } |
| 3699 | } |
| 3700 | |
| 3701 | /** |
| 3702 | * NOTE: For the pinned stack, this method is usually called after the bounds animation has |
| 3703 | * animated the stack to the fullscreen, but can also be called if we are relaunching an |
| 3704 | * activity and clearing the task at the same time. |
| 3705 | */ |
| 3706 | @Override |
| 3707 | // TODO: API should just be about changing windowing modes... |
| 3708 | public void moveTasksToFullscreenStack(int fromStackId, boolean onTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3709 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3710 | "moveTasksToFullscreenStack()"); |
| 3711 | synchronized (mGlobalLock) { |
| 3712 | final long origId = Binder.clearCallingIdentity(); |
| 3713 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3714 | final ActivityStack stack = mRootActivityContainer.getStack(fromStackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3715 | if (stack != null){ |
| 3716 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3717 | throw new IllegalArgumentException( |
| 3718 | "You can't move tasks from non-standard stacks."); |
| 3719 | } |
| 3720 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, onTop); |
| 3721 | } |
| 3722 | } finally { |
| 3723 | Binder.restoreCallingIdentity(origId); |
| 3724 | } |
| 3725 | } |
| 3726 | } |
| 3727 | |
| 3728 | /** |
| 3729 | * Moves the top activity in the input stackId to the pinned stack. |
| 3730 | * |
| 3731 | * @param stackId Id of stack to move the top activity to pinned stack. |
| 3732 | * @param bounds Bounds to use for pinned stack. |
| 3733 | * |
| 3734 | * @return True if the top activity of the input stack was successfully moved to the pinned |
| 3735 | * stack. |
| 3736 | */ |
| 3737 | @Override |
| 3738 | public boolean moveTopActivityToPinnedStack(int stackId, Rect bounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3739 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3740 | "moveTopActivityToPinnedStack()"); |
| 3741 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3742 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3743 | throw new IllegalStateException("moveTopActivityToPinnedStack:" |
| 3744 | + "Device doesn't support picture-in-picture mode"); |
| 3745 | } |
| 3746 | |
| 3747 | long ident = Binder.clearCallingIdentity(); |
| 3748 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3749 | return mRootActivityContainer.moveTopStackActivityToPinnedStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3750 | } finally { |
| 3751 | Binder.restoreCallingIdentity(ident); |
| 3752 | } |
| 3753 | } |
| 3754 | } |
| 3755 | |
| 3756 | @Override |
| 3757 | public boolean isInMultiWindowMode(IBinder token) { |
| 3758 | final long origId = Binder.clearCallingIdentity(); |
| 3759 | try { |
| 3760 | synchronized (mGlobalLock) { |
| 3761 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3762 | if (r == null) { |
| 3763 | return false; |
| 3764 | } |
| 3765 | // An activity is consider to be in multi-window mode if its task isn't fullscreen. |
| 3766 | return r.inMultiWindowMode(); |
| 3767 | } |
| 3768 | } finally { |
| 3769 | Binder.restoreCallingIdentity(origId); |
| 3770 | } |
| 3771 | } |
| 3772 | |
| 3773 | @Override |
| 3774 | public boolean isInPictureInPictureMode(IBinder token) { |
| 3775 | final long origId = Binder.clearCallingIdentity(); |
| 3776 | try { |
| 3777 | synchronized (mGlobalLock) { |
| 3778 | return isInPictureInPictureMode(ActivityRecord.forTokenLocked(token)); |
| 3779 | } |
| 3780 | } finally { |
| 3781 | Binder.restoreCallingIdentity(origId); |
| 3782 | } |
| 3783 | } |
| 3784 | |
| 3785 | private boolean isInPictureInPictureMode(ActivityRecord r) { |
| 3786 | if (r == null || r.getStack() == null || !r.inPinnedWindowingMode() |
| 3787 | || r.getStack().isInStackLocked(r) == null) { |
| 3788 | return false; |
| 3789 | } |
| 3790 | |
| 3791 | // If we are animating to fullscreen then we have already dispatched the PIP mode |
| 3792 | // changed, so we should reflect that check here as well. |
| 3793 | final PinnedActivityStack stack = r.getStack(); |
| 3794 | final PinnedStackWindowController windowController = stack.getWindowContainerController(); |
| 3795 | return !windowController.isAnimatingBoundsToFullscreen(); |
| 3796 | } |
| 3797 | |
| 3798 | @Override |
| 3799 | public boolean enterPictureInPictureMode(IBinder token, final PictureInPictureParams params) { |
| 3800 | final long origId = Binder.clearCallingIdentity(); |
| 3801 | try { |
| 3802 | synchronized (mGlobalLock) { |
| 3803 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 3804 | "enterPictureInPictureMode", token, params); |
| 3805 | |
| 3806 | // If the activity is already in picture in picture mode, then just return early |
| 3807 | if (isInPictureInPictureMode(r)) { |
| 3808 | return true; |
| 3809 | } |
| 3810 | |
| 3811 | // Activity supports picture-in-picture, now check that we can enter PiP at this |
| 3812 | // point, if it is |
| 3813 | if (!r.checkEnterPictureInPictureState("enterPictureInPictureMode", |
| 3814 | false /* beforeStopping */)) { |
| 3815 | return false; |
| 3816 | } |
| 3817 | |
| 3818 | final Runnable enterPipRunnable = () -> { |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 3819 | synchronized (mGlobalLock) { |
| 3820 | // Only update the saved args from the args that are set |
| 3821 | r.pictureInPictureArgs.copyOnlySet(params); |
| 3822 | final float aspectRatio = r.pictureInPictureArgs.getAspectRatio(); |
| 3823 | final List<RemoteAction> actions = r.pictureInPictureArgs.getActions(); |
| 3824 | // Adjust the source bounds by the insets for the transition down |
| 3825 | final Rect sourceBounds = new Rect( |
| 3826 | r.pictureInPictureArgs.getSourceRectHint()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3827 | mRootActivityContainer.moveActivityToPinnedStack( |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 3828 | r, sourceBounds, aspectRatio, "enterPictureInPictureMode"); |
| 3829 | final PinnedActivityStack stack = r.getStack(); |
| 3830 | stack.setPictureInPictureAspectRatio(aspectRatio); |
| 3831 | stack.setPictureInPictureActions(actions); |
| 3832 | MetricsLoggerWrapper.logPictureInPictureEnter(mContext, r.appInfo.uid, |
| 3833 | r.shortComponentName, r.supportsEnterPipOnTaskSwitch); |
| 3834 | logPictureInPictureArgs(params); |
| 3835 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3836 | }; |
| 3837 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3838 | if (isKeyguardLocked()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3839 | // If the keyguard is showing or occluded, then try and dismiss it before |
| 3840 | // entering picture-in-picture (this will prompt the user to authenticate if the |
| 3841 | // device is currently locked). |
| 3842 | dismissKeyguard(token, new KeyguardDismissCallback() { |
| 3843 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3844 | public void onDismissSucceeded() { |
| 3845 | mH.post(enterPipRunnable); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3846 | } |
| 3847 | }, null /* message */); |
| 3848 | } else { |
| 3849 | // Enter picture in picture immediately otherwise |
| 3850 | enterPipRunnable.run(); |
| 3851 | } |
| 3852 | return true; |
| 3853 | } |
| 3854 | } finally { |
| 3855 | Binder.restoreCallingIdentity(origId); |
| 3856 | } |
| 3857 | } |
| 3858 | |
| 3859 | @Override |
| 3860 | public void setPictureInPictureParams(IBinder token, final PictureInPictureParams params) { |
| 3861 | final long origId = Binder.clearCallingIdentity(); |
| 3862 | try { |
| 3863 | synchronized (mGlobalLock) { |
| 3864 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 3865 | "setPictureInPictureParams", token, params); |
| 3866 | |
| 3867 | // Only update the saved args from the args that are set |
| 3868 | r.pictureInPictureArgs.copyOnlySet(params); |
| 3869 | if (r.inPinnedWindowingMode()) { |
| 3870 | // If the activity is already in picture-in-picture, update the pinned stack now |
| 3871 | // if it is not already expanding to fullscreen. Otherwise, the arguments will |
| 3872 | // be used the next time the activity enters PiP |
| 3873 | final PinnedActivityStack stack = r.getStack(); |
| 3874 | if (!stack.isAnimatingBoundsToFullscreen()) { |
| 3875 | stack.setPictureInPictureAspectRatio( |
| 3876 | r.pictureInPictureArgs.getAspectRatio()); |
| 3877 | stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions()); |
| 3878 | } |
| 3879 | } |
| 3880 | logPictureInPictureArgs(params); |
| 3881 | } |
| 3882 | } finally { |
| 3883 | Binder.restoreCallingIdentity(origId); |
| 3884 | } |
| 3885 | } |
| 3886 | |
| 3887 | @Override |
| 3888 | public int getMaxNumPictureInPictureActions(IBinder token) { |
| 3889 | // Currently, this is a static constant, but later, we may change this to be dependent on |
| 3890 | // the context of the activity |
| 3891 | return 3; |
| 3892 | } |
| 3893 | |
| 3894 | private void logPictureInPictureArgs(PictureInPictureParams params) { |
| 3895 | if (params.hasSetActions()) { |
| 3896 | MetricsLogger.histogram(mContext, "tron_varz_picture_in_picture_actions_count", |
| 3897 | params.getActions().size()); |
| 3898 | } |
| 3899 | if (params.hasSetAspectRatio()) { |
| 3900 | LogMaker lm = new LogMaker(MetricsEvent.ACTION_PICTURE_IN_PICTURE_ASPECT_RATIO_CHANGED); |
| 3901 | lm.addTaggedData(MetricsEvent.PICTURE_IN_PICTURE_ASPECT_RATIO, params.getAspectRatio()); |
| 3902 | MetricsLogger.action(lm); |
| 3903 | } |
| 3904 | } |
| 3905 | |
| 3906 | /** |
| 3907 | * Checks the state of the system and the activity associated with the given {@param token} to |
| 3908 | * verify that picture-in-picture is supported for that activity. |
| 3909 | * |
| 3910 | * @return the activity record for the given {@param token} if all the checks pass. |
| 3911 | */ |
| 3912 | private ActivityRecord ensureValidPictureInPictureActivityParamsLocked(String caller, |
| 3913 | IBinder token, PictureInPictureParams params) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3914 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3915 | throw new IllegalStateException(caller |
| 3916 | + ": Device doesn't support picture-in-picture mode."); |
| 3917 | } |
| 3918 | |
| 3919 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3920 | if (r == null) { |
| 3921 | throw new IllegalStateException(caller |
| 3922 | + ": Can't find activity for token=" + token); |
| 3923 | } |
| 3924 | |
| 3925 | if (!r.supportsPictureInPicture()) { |
| 3926 | throw new IllegalStateException(caller |
| 3927 | + ": Current activity does not support picture-in-picture."); |
| 3928 | } |
| 3929 | |
| 3930 | if (params.hasSetAspectRatio() |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3931 | && !mWindowManager.isValidPictureInPictureAspectRatio(r.getStack().mDisplayId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3932 | params.getAspectRatio())) { |
| 3933 | final float minAspectRatio = mContext.getResources().getFloat( |
| 3934 | com.android.internal.R.dimen.config_pictureInPictureMinAspectRatio); |
| 3935 | final float maxAspectRatio = mContext.getResources().getFloat( |
| 3936 | com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio); |
| 3937 | throw new IllegalArgumentException(String.format(caller |
| 3938 | + ": Aspect ratio is too extreme (must be between %f and %f).", |
| 3939 | minAspectRatio, maxAspectRatio)); |
| 3940 | } |
| 3941 | |
| 3942 | // Truncate the number of actions if necessary |
| 3943 | params.truncateActions(getMaxNumPictureInPictureActions(token)); |
| 3944 | |
| 3945 | return r; |
| 3946 | } |
| 3947 | |
| 3948 | @Override |
| 3949 | public IBinder getUriPermissionOwnerForActivity(IBinder activityToken) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3950 | enforceNotIsolatedCaller("getUriPermissionOwnerForActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3951 | synchronized (mGlobalLock) { |
| 3952 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 3953 | if (r == null) { |
| 3954 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 3955 | + activityToken); |
| 3956 | } |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 3957 | return r.getUriPermissionsLocked().getExternalToken(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3958 | } |
| 3959 | } |
| 3960 | |
| 3961 | @Override |
| 3962 | public void resizeDockedStack(Rect dockedBounds, Rect tempDockedTaskBounds, |
| 3963 | Rect tempDockedTaskInsetBounds, |
| 3964 | Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3965 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeDockedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3966 | long ident = Binder.clearCallingIdentity(); |
| 3967 | try { |
| 3968 | synchronized (mGlobalLock) { |
| 3969 | mStackSupervisor.resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, |
| 3970 | tempDockedTaskInsetBounds, tempOtherTaskBounds, tempOtherTaskInsetBounds, |
| 3971 | PRESERVE_WINDOWS); |
| 3972 | } |
| 3973 | } finally { |
| 3974 | Binder.restoreCallingIdentity(ident); |
| 3975 | } |
| 3976 | } |
| 3977 | |
| 3978 | @Override |
| 3979 | public void setSplitScreenResizing(boolean resizing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3980 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setSplitScreenResizing()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3981 | final long ident = Binder.clearCallingIdentity(); |
| 3982 | try { |
| 3983 | synchronized (mGlobalLock) { |
| 3984 | mStackSupervisor.setSplitScreenResizing(resizing); |
| 3985 | } |
| 3986 | } finally { |
| 3987 | Binder.restoreCallingIdentity(ident); |
| 3988 | } |
| 3989 | } |
| 3990 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3991 | /** |
| 3992 | * Check that we have the features required for VR-related API calls, and throw an exception if |
| 3993 | * not. |
| 3994 | */ |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 3995 | public void enforceSystemHasVrFeature() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3996 | if (!mContext.getPackageManager().hasSystemFeature( |
| 3997 | PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE)) { |
| 3998 | throw new UnsupportedOperationException("VR mode not supported on this device!"); |
| 3999 | } |
| 4000 | } |
| 4001 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4002 | @Override |
| 4003 | public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4004 | enforceSystemHasVrFeature(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4005 | |
| 4006 | final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class); |
| 4007 | |
| 4008 | ActivityRecord r; |
| 4009 | synchronized (mGlobalLock) { |
| 4010 | r = ActivityRecord.isInStackLocked(token); |
| 4011 | } |
| 4012 | |
| 4013 | if (r == null) { |
| 4014 | throw new IllegalArgumentException(); |
| 4015 | } |
| 4016 | |
| 4017 | int err; |
| 4018 | if ((err = vrService.hasVrPackage(packageName, r.userId)) != |
| 4019 | VrManagerInternal.NO_ERROR) { |
| 4020 | return err; |
| 4021 | } |
| 4022 | |
| 4023 | // Clear the binder calling uid since this path may call moveToTask(). |
| 4024 | final long callingId = Binder.clearCallingIdentity(); |
| 4025 | try { |
| 4026 | synchronized (mGlobalLock) { |
| 4027 | r.requestedVrComponent = (enabled) ? packageName : null; |
| 4028 | |
| 4029 | // Update associated state if this activity is currently focused |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 4030 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4031 | applyUpdateVrModeLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4032 | } |
| 4033 | return 0; |
| 4034 | } |
| 4035 | } finally { |
| 4036 | Binder.restoreCallingIdentity(callingId); |
| 4037 | } |
| 4038 | } |
| 4039 | |
| 4040 | @Override |
| 4041 | public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) { |
| 4042 | Slog.i(TAG, "Activity tried to startLocalVoiceInteraction"); |
| 4043 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4044 | ActivityRecord activity = getTopDisplayFocusedStack().getTopActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4045 | if (ActivityRecord.forTokenLocked(callingActivity) != activity) { |
| 4046 | throw new SecurityException("Only focused activity can call startVoiceInteraction"); |
| 4047 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4048 | if (mRunningVoice != null || activity.getTask().voiceSession != null |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4049 | || activity.voiceSession != null) { |
| 4050 | Slog.w(TAG, "Already in a voice interaction, cannot start new voice interaction"); |
| 4051 | return; |
| 4052 | } |
| 4053 | if (activity.pendingVoiceInteractionStart) { |
| 4054 | Slog.w(TAG, "Pending start of voice interaction already."); |
| 4055 | return; |
| 4056 | } |
| 4057 | activity.pendingVoiceInteractionStart = true; |
| 4058 | } |
| 4059 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4060 | .startLocalVoiceInteraction(callingActivity, options); |
| 4061 | } |
| 4062 | |
| 4063 | @Override |
| 4064 | public void stopLocalVoiceInteraction(IBinder callingActivity) { |
| 4065 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4066 | .stopLocalVoiceInteraction(callingActivity); |
| 4067 | } |
| 4068 | |
| 4069 | @Override |
| 4070 | public boolean supportsLocalVoiceInteraction() { |
| 4071 | return LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4072 | .supportsLocalVoiceInteraction(); |
| 4073 | } |
| 4074 | |
| 4075 | /** Notifies all listeners when the pinned stack animation starts. */ |
| 4076 | @Override |
| 4077 | public void notifyPinnedStackAnimationStarted() { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4078 | mTaskChangeNotificationController.notifyPinnedStackAnimationStarted(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | /** Notifies all listeners when the pinned stack animation ends. */ |
| 4082 | @Override |
| 4083 | public void notifyPinnedStackAnimationEnded() { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4084 | mTaskChangeNotificationController.notifyPinnedStackAnimationEnded(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4085 | } |
| 4086 | |
| 4087 | @Override |
| 4088 | public void resizePinnedStack(Rect pinnedBounds, Rect tempPinnedTaskBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4089 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizePinnedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4090 | final long ident = Binder.clearCallingIdentity(); |
| 4091 | try { |
| 4092 | synchronized (mGlobalLock) { |
| 4093 | mStackSupervisor.resizePinnedStackLocked(pinnedBounds, tempPinnedTaskBounds); |
| 4094 | } |
| 4095 | } finally { |
| 4096 | Binder.restoreCallingIdentity(ident); |
| 4097 | } |
| 4098 | } |
| 4099 | |
| 4100 | @Override |
| 4101 | public boolean updateDisplayOverrideConfiguration(Configuration values, int displayId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4102 | mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateDisplayOverrideConfiguration()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4103 | |
| 4104 | synchronized (mGlobalLock) { |
| 4105 | // Check if display is initialized in AM. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4106 | if (!mRootActivityContainer.isDisplayAdded(displayId)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4107 | // Call might come when display is not yet added or has already been removed. |
| 4108 | if (DEBUG_CONFIGURATION) { |
| 4109 | Slog.w(TAG, "Trying to update display configuration for non-existing displayId=" |
| 4110 | + displayId); |
| 4111 | } |
| 4112 | return false; |
| 4113 | } |
| 4114 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4115 | if (values == null && mWindowManager != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4116 | // sentinel: fetch the current configuration from the window manager |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4117 | values = mWindowManager.computeNewConfiguration(displayId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4118 | } |
| 4119 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4120 | if (mWindowManager != null) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4121 | final Message msg = PooledLambda.obtainMessage( |
| 4122 | ActivityManagerInternal::updateOomLevelsForDisplay, mAmInternal, displayId); |
| 4123 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4124 | } |
| 4125 | |
| 4126 | final long origId = Binder.clearCallingIdentity(); |
| 4127 | try { |
| 4128 | if (values != null) { |
| 4129 | Settings.System.clearConfiguration(values); |
| 4130 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4131 | updateDisplayOverrideConfigurationLocked(values, null /* starting */, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4132 | false /* deferResume */, displayId, mTmpUpdateConfigurationResult); |
| 4133 | return mTmpUpdateConfigurationResult.changes != 0; |
| 4134 | } finally { |
| 4135 | Binder.restoreCallingIdentity(origId); |
| 4136 | } |
| 4137 | } |
| 4138 | } |
| 4139 | |
| 4140 | @Override |
| 4141 | public boolean updateConfiguration(Configuration values) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4142 | mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateConfiguration()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4143 | |
| 4144 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4145 | if (values == null && mWindowManager != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4146 | // sentinel: fetch the current configuration from the window manager |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4147 | values = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4148 | } |
| 4149 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4150 | if (mWindowManager != null) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4151 | final Message msg = PooledLambda.obtainMessage( |
| 4152 | ActivityManagerInternal::updateOomLevelsForDisplay, mAmInternal, |
| 4153 | DEFAULT_DISPLAY); |
| 4154 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4155 | } |
| 4156 | |
| 4157 | final long origId = Binder.clearCallingIdentity(); |
| 4158 | try { |
| 4159 | if (values != null) { |
| 4160 | Settings.System.clearConfiguration(values); |
| 4161 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4162 | updateConfigurationLocked(values, null, false, false /* persistent */, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4163 | UserHandle.USER_NULL, false /* deferResume */, |
| 4164 | mTmpUpdateConfigurationResult); |
| 4165 | return mTmpUpdateConfigurationResult.changes != 0; |
| 4166 | } finally { |
| 4167 | Binder.restoreCallingIdentity(origId); |
| 4168 | } |
| 4169 | } |
| 4170 | } |
| 4171 | |
| 4172 | @Override |
| 4173 | public void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback, |
| 4174 | CharSequence message) { |
| 4175 | if (message != null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4176 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4177 | Manifest.permission.SHOW_KEYGUARD_MESSAGE, "dismissKeyguard()"); |
| 4178 | } |
| 4179 | final long callingId = Binder.clearCallingIdentity(); |
| 4180 | try { |
| 4181 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4182 | mKeyguardController.dismissKeyguard(token, callback, message); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4183 | } |
| 4184 | } finally { |
| 4185 | Binder.restoreCallingIdentity(callingId); |
| 4186 | } |
| 4187 | } |
| 4188 | |
| 4189 | @Override |
| 4190 | public void cancelTaskWindowTransition(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4191 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4192 | "cancelTaskWindowTransition()"); |
| 4193 | final long ident = Binder.clearCallingIdentity(); |
| 4194 | try { |
| 4195 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4196 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4197 | MATCH_TASK_IN_STACKS_ONLY); |
| 4198 | if (task == null) { |
| 4199 | Slog.w(TAG, "cancelTaskWindowTransition: taskId=" + taskId + " not found"); |
| 4200 | return; |
| 4201 | } |
| 4202 | task.cancelWindowTransition(); |
| 4203 | } |
| 4204 | } finally { |
| 4205 | Binder.restoreCallingIdentity(ident); |
| 4206 | } |
| 4207 | } |
| 4208 | |
| 4209 | @Override |
| 4210 | public ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4211 | enforceCallerIsRecentsOrHasPermission(READ_FRAME_BUFFER, "getTaskSnapshot()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4212 | final long ident = Binder.clearCallingIdentity(); |
| 4213 | try { |
| 4214 | final TaskRecord task; |
| 4215 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4216 | task = mRootActivityContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4217 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 4218 | if (task == null) { |
| 4219 | Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found"); |
| 4220 | return null; |
| 4221 | } |
| 4222 | } |
| 4223 | // Don't call this while holding the lock as this operation might hit the disk. |
| 4224 | return task.getSnapshot(reducedResolution); |
| 4225 | } finally { |
| 4226 | Binder.restoreCallingIdentity(ident); |
| 4227 | } |
| 4228 | } |
| 4229 | |
| 4230 | @Override |
| 4231 | public void setDisablePreviewScreenshots(IBinder token, boolean disable) { |
| 4232 | synchronized (mGlobalLock) { |
| 4233 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4234 | if (r == null) { |
| 4235 | Slog.w(TAG, "setDisablePreviewScreenshots: Unable to find activity for token=" |
| 4236 | + token); |
| 4237 | return; |
| 4238 | } |
| 4239 | final long origId = Binder.clearCallingIdentity(); |
| 4240 | try { |
| 4241 | r.setDisablePreviewScreenshots(disable); |
| 4242 | } finally { |
| 4243 | Binder.restoreCallingIdentity(origId); |
| 4244 | } |
| 4245 | } |
| 4246 | } |
| 4247 | |
| 4248 | /** Return the user id of the last resumed activity. */ |
| 4249 | @Override |
| 4250 | public @UserIdInt |
| 4251 | int getLastResumedActivityUserId() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4252 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4253 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, "getLastResumedActivityUserId()"); |
| 4254 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4255 | if (mLastResumedActivity == null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4256 | return getCurrentUserId(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4257 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4258 | return mLastResumedActivity.userId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4259 | } |
| 4260 | } |
| 4261 | |
| 4262 | @Override |
| 4263 | public void updateLockTaskFeatures(int userId, int flags) { |
| 4264 | final int callingUid = Binder.getCallingUid(); |
| 4265 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4266 | mAmInternal.enforceCallingPermission(android.Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4267 | "updateLockTaskFeatures()"); |
| 4268 | } |
| 4269 | synchronized (mGlobalLock) { |
| 4270 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Allowing features " + userId + ":0x" + |
| 4271 | Integer.toHexString(flags)); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 4272 | getLockTaskController().updateLockTaskFeatures(userId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4273 | } |
| 4274 | } |
| 4275 | |
| 4276 | @Override |
| 4277 | public void setShowWhenLocked(IBinder token, boolean showWhenLocked) { |
| 4278 | synchronized (mGlobalLock) { |
| 4279 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4280 | if (r == null) { |
| 4281 | return; |
| 4282 | } |
| 4283 | final long origId = Binder.clearCallingIdentity(); |
| 4284 | try { |
| 4285 | r.setShowWhenLocked(showWhenLocked); |
| 4286 | } finally { |
| 4287 | Binder.restoreCallingIdentity(origId); |
| 4288 | } |
| 4289 | } |
| 4290 | } |
| 4291 | |
| 4292 | @Override |
| 4293 | public void setTurnScreenOn(IBinder token, boolean turnScreenOn) { |
| 4294 | synchronized (mGlobalLock) { |
| 4295 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4296 | if (r == null) { |
| 4297 | return; |
| 4298 | } |
| 4299 | final long origId = Binder.clearCallingIdentity(); |
| 4300 | try { |
| 4301 | r.setTurnScreenOn(turnScreenOn); |
| 4302 | } finally { |
| 4303 | Binder.restoreCallingIdentity(origId); |
| 4304 | } |
| 4305 | } |
| 4306 | } |
| 4307 | |
| 4308 | @Override |
| 4309 | public void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4310 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4311 | "registerRemoteAnimations"); |
| 4312 | definition.setCallingPid(Binder.getCallingPid()); |
| 4313 | synchronized (mGlobalLock) { |
| 4314 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4315 | if (r == null) { |
| 4316 | return; |
| 4317 | } |
| 4318 | final long origId = Binder.clearCallingIdentity(); |
| 4319 | try { |
| 4320 | r.registerRemoteAnimations(definition); |
| 4321 | } finally { |
| 4322 | Binder.restoreCallingIdentity(origId); |
| 4323 | } |
| 4324 | } |
| 4325 | } |
| 4326 | |
| 4327 | @Override |
| 4328 | public void registerRemoteAnimationForNextActivityStart(String packageName, |
| 4329 | RemoteAnimationAdapter adapter) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4330 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4331 | "registerRemoteAnimationForNextActivityStart"); |
| 4332 | adapter.setCallingPid(Binder.getCallingPid()); |
| 4333 | synchronized (mGlobalLock) { |
| 4334 | final long origId = Binder.clearCallingIdentity(); |
| 4335 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4336 | getActivityStartController().registerRemoteAnimationForNextActivityStart( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4337 | packageName, adapter); |
| 4338 | } finally { |
| 4339 | Binder.restoreCallingIdentity(origId); |
| 4340 | } |
| 4341 | } |
| 4342 | } |
| 4343 | |
| 4344 | /** @see android.app.ActivityManager#alwaysShowUnsupportedCompileSdkWarning */ |
| 4345 | @Override |
| 4346 | public void alwaysShowUnsupportedCompileSdkWarning(ComponentName activity) { |
| 4347 | synchronized (mGlobalLock) { |
| 4348 | final long origId = Binder.clearCallingIdentity(); |
| 4349 | try { |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 4350 | mAppWarnings.alwaysShowUnsupportedCompileSdkWarning(activity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4351 | } finally { |
| 4352 | Binder.restoreCallingIdentity(origId); |
| 4353 | } |
| 4354 | } |
| 4355 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 4356 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4357 | @Override |
| 4358 | public void setVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4359 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4360 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4361 | final int pid = Binder.getCallingPid(); |
| 4362 | final WindowProcessController wpc = mPidMap.get(pid); |
| 4363 | mVrController.setVrThreadLocked(tid, pid, wpc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4364 | } |
| 4365 | } |
| 4366 | |
| 4367 | @Override |
| 4368 | public void setPersistentVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4369 | if (checkCallingPermission(Manifest.permission.RESTRICTED_VR_ACCESS) |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4370 | != PERMISSION_GRANTED) { |
| 4371 | final String msg = "Permission Denial: setPersistentVrThread() from pid=" |
| 4372 | + Binder.getCallingPid() |
| 4373 | + ", uid=" + Binder.getCallingUid() |
| 4374 | + " requires " + Manifest.permission.RESTRICTED_VR_ACCESS; |
| 4375 | Slog.w(TAG, msg); |
| 4376 | throw new SecurityException(msg); |
| 4377 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4378 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4379 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4380 | final int pid = Binder.getCallingPid(); |
| 4381 | final WindowProcessController proc = mPidMap.get(pid); |
| 4382 | mVrController.setPersistentVrThreadLocked(tid, pid, proc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4383 | } |
| 4384 | } |
| 4385 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4386 | @Override |
| 4387 | public void stopAppSwitches() { |
| 4388 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "stopAppSwitches"); |
| 4389 | synchronized (mGlobalLock) { |
| 4390 | mAppSwitchesAllowedTime = SystemClock.uptimeMillis() + APP_SWITCH_DELAY_TIME; |
| 4391 | mDidAppSwitch = false; |
| 4392 | getActivityStartController().schedulePendingActivityLaunches(APP_SWITCH_DELAY_TIME); |
| 4393 | } |
| 4394 | } |
| 4395 | |
| 4396 | @Override |
| 4397 | public void resumeAppSwitches() { |
| 4398 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "resumeAppSwitches"); |
| 4399 | synchronized (mGlobalLock) { |
| 4400 | // Note that we don't execute any pending app switches... we will |
| 4401 | // let those wait until either the timeout, or the next start |
| 4402 | // activity request. |
| 4403 | mAppSwitchesAllowedTime = 0; |
| 4404 | } |
| 4405 | } |
| 4406 | |
| 4407 | void onStartActivitySetDidAppSwitch() { |
| 4408 | if (mDidAppSwitch) { |
| 4409 | // This is the second allowed switch since we stopped switches, so now just generally |
| 4410 | // allow switches. Use case: |
| 4411 | // - user presses home (switches disabled, switch to home, mDidAppSwitch now true); |
| 4412 | // - user taps a home icon (coming from home so allowed, we hit here and now allow |
| 4413 | // anyone to switch again). |
| 4414 | mAppSwitchesAllowedTime = 0; |
| 4415 | } else { |
| 4416 | mDidAppSwitch = true; |
| 4417 | } |
| 4418 | } |
| 4419 | |
| 4420 | /** @return whether the system should disable UI modes incompatible with VR mode. */ |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4421 | boolean shouldDisableNonVrUiLocked() { |
| 4422 | return mVrController.shouldDisableNonVrUiLocked(); |
| 4423 | } |
| 4424 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4425 | private void applyUpdateVrModeLocked(ActivityRecord r) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4426 | // VR apps are expected to run in a main display. If an app is turning on VR for |
| 4427 | // itself, but lives in a dynamic stack, then make sure that it is moved to the main |
| 4428 | // fullscreen stack before enabling VR Mode. |
| 4429 | // TODO: The goal of this code is to keep the VR app on the main display. When the |
| 4430 | // stack implementation changes in the future, keep in mind that the use of the fullscreen |
| 4431 | // stack is a means to move the activity to the main display and a moveActivityToDisplay() |
| 4432 | // option would be a better choice here. |
| 4433 | if (r.requestedVrComponent != null && r.getDisplayId() != DEFAULT_DISPLAY) { |
| 4434 | Slog.i(TAG, "Moving " + r.shortComponentName + " from stack " + r.getStackId() |
| 4435 | + " to main stack for VR"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4436 | final ActivityStack stack = mRootActivityContainer.getDefaultDisplay().getOrCreateStack( |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4437 | WINDOWING_MODE_FULLSCREEN, r.getActivityType(), true /* toTop */); |
| 4438 | moveTaskToStack(r.getTask().taskId, stack.mStackId, true /* toTop */); |
| 4439 | } |
| 4440 | mH.post(() -> { |
| 4441 | if (!mVrController.onVrModeChanged(r)) { |
| 4442 | return; |
| 4443 | } |
| 4444 | synchronized (mGlobalLock) { |
| 4445 | final boolean disableNonVrUi = mVrController.shouldDisableNonVrUiLocked(); |
| 4446 | mWindowManager.disableNonVrUi(disableNonVrUi); |
| 4447 | if (disableNonVrUi) { |
| 4448 | // If we are in a VR mode where Picture-in-Picture mode is unsupported, |
| 4449 | // then remove the pinned stack. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4450 | mRootActivityContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4451 | } |
| 4452 | } |
| 4453 | }); |
| 4454 | } |
| 4455 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4456 | @Override |
| 4457 | public int getPackageScreenCompatMode(String packageName) { |
| 4458 | enforceNotIsolatedCaller("getPackageScreenCompatMode"); |
| 4459 | synchronized (mGlobalLock) { |
| 4460 | return mCompatModePackages.getPackageScreenCompatModeLocked(packageName); |
| 4461 | } |
| 4462 | } |
| 4463 | |
| 4464 | @Override |
| 4465 | public void setPackageScreenCompatMode(String packageName, int mode) { |
| 4466 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4467 | "setPackageScreenCompatMode"); |
| 4468 | synchronized (mGlobalLock) { |
| 4469 | mCompatModePackages.setPackageScreenCompatModeLocked(packageName, mode); |
| 4470 | } |
| 4471 | } |
| 4472 | |
| 4473 | @Override |
| 4474 | public boolean getPackageAskScreenCompat(String packageName) { |
| 4475 | enforceNotIsolatedCaller("getPackageAskScreenCompat"); |
| 4476 | synchronized (mGlobalLock) { |
| 4477 | return mCompatModePackages.getPackageAskCompatModeLocked(packageName); |
| 4478 | } |
| 4479 | } |
| 4480 | |
| 4481 | @Override |
| 4482 | public void setPackageAskScreenCompat(String packageName, boolean ask) { |
| 4483 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4484 | "setPackageAskScreenCompat"); |
| 4485 | synchronized (mGlobalLock) { |
| 4486 | mCompatModePackages.setPackageAskCompatModeLocked(packageName, ask); |
| 4487 | } |
| 4488 | } |
| 4489 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 4490 | public static String relaunchReasonToString(int relaunchReason) { |
| 4491 | switch (relaunchReason) { |
| 4492 | case RELAUNCH_REASON_WINDOWING_MODE_RESIZE: |
| 4493 | return "window_resize"; |
| 4494 | case RELAUNCH_REASON_FREE_RESIZE: |
| 4495 | return "free_resize"; |
| 4496 | default: |
| 4497 | return null; |
| 4498 | } |
| 4499 | } |
| 4500 | |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4501 | ActivityStack getTopDisplayFocusedStack() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4502 | return mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4503 | } |
| 4504 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4505 | /** Pokes the task persister. */ |
| 4506 | void notifyTaskPersisterLocked(TaskRecord task, boolean flush) { |
| 4507 | mRecentTasks.notifyTaskPersisterLocked(task, flush); |
| 4508 | } |
| 4509 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4510 | boolean isKeyguardLocked() { |
| 4511 | return mKeyguardController.isKeyguardLocked(); |
| 4512 | } |
| 4513 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4514 | void dumpLastANRLocked(PrintWriter pw) { |
| 4515 | pw.println("ACTIVITY MANAGER LAST ANR (dumpsys activity lastanr)"); |
| 4516 | if (mLastANRState == null) { |
| 4517 | pw.println(" <no ANR has occurred since boot>"); |
| 4518 | } else { |
| 4519 | pw.println(mLastANRState); |
| 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | void dumpLastANRTracesLocked(PrintWriter pw) { |
| 4524 | pw.println("ACTIVITY MANAGER LAST ANR TRACES (dumpsys activity lastanr-traces)"); |
| 4525 | |
| 4526 | final File[] files = new File(ANR_TRACE_DIR).listFiles(); |
| 4527 | if (ArrayUtils.isEmpty(files)) { |
| 4528 | pw.println(" <no ANR has occurred since boot>"); |
| 4529 | return; |
| 4530 | } |
| 4531 | // Find the latest file. |
| 4532 | File latest = null; |
| 4533 | for (File f : files) { |
| 4534 | if ((latest == null) || (latest.lastModified() < f.lastModified())) { |
| 4535 | latest = f; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4536 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4537 | } |
| 4538 | pw.print("File: "); |
| 4539 | pw.print(latest.getName()); |
| 4540 | pw.println(); |
| 4541 | try (BufferedReader in = new BufferedReader(new FileReader(latest))) { |
| 4542 | String line; |
| 4543 | while ((line = in.readLine()) != null) { |
| 4544 | pw.println(line); |
| 4545 | } |
| 4546 | } catch (IOException e) { |
| 4547 | pw.print("Unable to read: "); |
| 4548 | pw.print(e); |
| 4549 | pw.println(); |
| 4550 | } |
| 4551 | } |
| 4552 | |
| 4553 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4554 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 4555 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage, |
| 4556 | "ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)"); |
| 4557 | } |
| 4558 | |
| 4559 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4560 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage, String header) { |
| 4561 | pw.println(header); |
| 4562 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4563 | boolean printedAnything = mRootActivityContainer.dumpActivities(fd, pw, dumpAll, dumpClient, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4564 | dumpPackage); |
| 4565 | boolean needSep = printedAnything; |
| 4566 | |
| 4567 | boolean printed = ActivityStackSupervisor.printThisActivity(pw, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4568 | mRootActivityContainer.getTopResumedActivity(), dumpPackage, needSep, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4569 | " ResumedActivity: "); |
| 4570 | if (printed) { |
| 4571 | printedAnything = true; |
| 4572 | needSep = false; |
| 4573 | } |
| 4574 | |
| 4575 | if (dumpPackage == null) { |
| 4576 | if (needSep) { |
| 4577 | pw.println(); |
| 4578 | } |
| 4579 | printedAnything = true; |
| 4580 | mStackSupervisor.dump(pw, " "); |
| 4581 | } |
| 4582 | |
| 4583 | if (!printedAnything) { |
| 4584 | pw.println(" (nothing)"); |
| 4585 | } |
| 4586 | } |
| 4587 | |
| 4588 | void dumpActivityContainersLocked(PrintWriter pw) { |
| 4589 | pw.println("ACTIVITY MANAGER STARTER (dumpsys activity containers)"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4590 | mRootActivityContainer.dumpChildrenNames(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4591 | pw.println(" "); |
| 4592 | } |
| 4593 | |
| 4594 | void dumpActivityStarterLocked(PrintWriter pw, String dumpPackage) { |
| 4595 | pw.println("ACTIVITY MANAGER STARTER (dumpsys activity starter)"); |
| 4596 | getActivityStartController().dump(pw, "", dumpPackage); |
| 4597 | } |
| 4598 | |
| 4599 | /** |
| 4600 | * There are three things that cmd can be: |
| 4601 | * - a flattened component name that matches an existing activity |
| 4602 | * - the cmd arg isn't the flattened component name of an existing activity: |
| 4603 | * dump all activity whose component contains the cmd as a substring |
| 4604 | * - A hex number of the ActivityRecord object instance. |
| 4605 | * |
| 4606 | * @param dumpVisibleStacksOnly dump activity with {@param name} only if in a visible stack |
| 4607 | * @param dumpFocusedStackOnly dump activity with {@param name} only if in the focused stack |
| 4608 | */ |
| 4609 | protected boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, String[] args, |
| 4610 | int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, boolean dumpFocusedStackOnly) { |
| 4611 | ArrayList<ActivityRecord> activities; |
| 4612 | |
| 4613 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4614 | activities = mRootActivityContainer.getDumpActivities(name, dumpVisibleStacksOnly, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4615 | dumpFocusedStackOnly); |
| 4616 | } |
| 4617 | |
| 4618 | if (activities.size() <= 0) { |
| 4619 | return false; |
| 4620 | } |
| 4621 | |
| 4622 | String[] newArgs = new String[args.length - opti]; |
| 4623 | System.arraycopy(args, opti, newArgs, 0, args.length - opti); |
| 4624 | |
| 4625 | TaskRecord lastTask = null; |
| 4626 | boolean needSep = false; |
| 4627 | for (int i = activities.size() - 1; i >= 0; i--) { |
| 4628 | ActivityRecord r = activities.get(i); |
| 4629 | if (needSep) { |
| 4630 | pw.println(); |
| 4631 | } |
| 4632 | needSep = true; |
| 4633 | synchronized (mGlobalLock) { |
| 4634 | final TaskRecord task = r.getTask(); |
| 4635 | if (lastTask != task) { |
| 4636 | lastTask = task; |
| 4637 | pw.print("TASK "); pw.print(lastTask.affinity); |
| 4638 | pw.print(" id="); pw.print(lastTask.taskId); |
| 4639 | pw.print(" userId="); pw.println(lastTask.userId); |
| 4640 | if (dumpAll) { |
| 4641 | lastTask.dump(pw, " "); |
| 4642 | } |
| 4643 | } |
| 4644 | } |
| 4645 | dumpActivity(" ", fd, pw, activities.get(i), newArgs, dumpAll); |
| 4646 | } |
| 4647 | return true; |
| 4648 | } |
| 4649 | |
| 4650 | /** |
| 4651 | * Invokes IApplicationThread.dumpActivity() on the thread of the specified activity if |
| 4652 | * there is a thread associated with the activity. |
| 4653 | */ |
| 4654 | private void dumpActivity(String prefix, FileDescriptor fd, PrintWriter pw, |
| 4655 | final ActivityRecord r, String[] args, boolean dumpAll) { |
| 4656 | String innerPrefix = prefix + " "; |
| 4657 | synchronized (mGlobalLock) { |
| 4658 | pw.print(prefix); pw.print("ACTIVITY "); pw.print(r.shortComponentName); |
| 4659 | pw.print(" "); pw.print(Integer.toHexString(System.identityHashCode(r))); |
| 4660 | pw.print(" pid="); |
| 4661 | if (r.hasProcess()) pw.println(r.app.getPid()); |
| 4662 | else pw.println("(not running)"); |
| 4663 | if (dumpAll) { |
| 4664 | r.dump(pw, innerPrefix); |
| 4665 | } |
| 4666 | } |
| 4667 | if (r.attachedToProcess()) { |
| 4668 | // flush anything that is already in the PrintWriter since the thread is going |
| 4669 | // to write to the file descriptor directly |
| 4670 | pw.flush(); |
| 4671 | try { |
| 4672 | TransferPipe tp = new TransferPipe(); |
| 4673 | try { |
| 4674 | r.app.getThread().dumpActivity(tp.getWriteFd(), |
| 4675 | r.appToken, innerPrefix, args); |
| 4676 | tp.go(fd); |
| 4677 | } finally { |
| 4678 | tp.kill(); |
| 4679 | } |
| 4680 | } catch (IOException e) { |
| 4681 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 4682 | } catch (RemoteException e) { |
| 4683 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 4684 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4685 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4686 | } |
| 4687 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4688 | void writeSleepStateToProto(ProtoOutputStream proto) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4689 | for (ActivityTaskManagerInternal.SleepToken st : mRootActivityContainer.mSleepTokens) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4690 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEP_TOKENS, |
| 4691 | st.toString()); |
| 4692 | } |
| 4693 | |
| 4694 | if (mRunningVoice != null) { |
| 4695 | final long vrToken = proto.start( |
| 4696 | ActivityManagerServiceDumpProcessesProto.RUNNING_VOICE); |
| 4697 | proto.write(ActivityManagerServiceDumpProcessesProto.Voice.SESSION, |
| 4698 | mRunningVoice.toString()); |
| 4699 | mVoiceWakeLock.writeToProto( |
| 4700 | proto, ActivityManagerServiceDumpProcessesProto.Voice.WAKELOCK); |
| 4701 | proto.end(vrToken); |
| 4702 | } |
| 4703 | |
| 4704 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEPING, mSleeping); |
| 4705 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SHUTTING_DOWN, |
| 4706 | mShuttingDown); |
| 4707 | mVrController.writeToProto(proto, ActivityManagerServiceDumpProcessesProto.VR_CONTROLLER); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4708 | } |
| 4709 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4710 | int getCurrentUserId() { |
| 4711 | return mAmInternal.getCurrentUserId(); |
| 4712 | } |
| 4713 | |
| 4714 | private void enforceNotIsolatedCaller(String caller) { |
| 4715 | if (UserHandle.isIsolated(Binder.getCallingUid())) { |
| 4716 | throw new SecurityException("Isolated process not allowed to call " + caller); |
| 4717 | } |
| 4718 | } |
| 4719 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4720 | public Configuration getConfiguration() { |
| 4721 | Configuration ci; |
| 4722 | synchronized(mGlobalLock) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 4723 | ci = new Configuration(getGlobalConfigurationForCallingPid()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4724 | ci.userSetLocale = false; |
| 4725 | } |
| 4726 | return ci; |
| 4727 | } |
| 4728 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4729 | /** |
| 4730 | * Current global configuration information. Contains general settings for the entire system, |
| 4731 | * also corresponds to the merged configuration of the default display. |
| 4732 | */ |
| 4733 | Configuration getGlobalConfiguration() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4734 | return mRootActivityContainer.getConfiguration(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 4738 | boolean initLocale) { |
| 4739 | return updateConfigurationLocked(values, starting, initLocale, false /* deferResume */); |
| 4740 | } |
| 4741 | |
| 4742 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 4743 | boolean initLocale, boolean deferResume) { |
| 4744 | // pass UserHandle.USER_NULL as userId because we don't persist configuration for any user |
| 4745 | return updateConfigurationLocked(values, starting, initLocale, false /* persistent */, |
| 4746 | UserHandle.USER_NULL, deferResume); |
| 4747 | } |
| 4748 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 4749 | public void updatePersistentConfiguration(Configuration values, @UserIdInt int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4750 | final long origId = Binder.clearCallingIdentity(); |
| 4751 | try { |
| 4752 | synchronized (mGlobalLock) { |
| 4753 | updateConfigurationLocked(values, null, false, true, userId, |
| 4754 | false /* deferResume */); |
| 4755 | } |
| 4756 | } finally { |
| 4757 | Binder.restoreCallingIdentity(origId); |
| 4758 | } |
| 4759 | } |
| 4760 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4761 | private boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 4762 | boolean initLocale, boolean persistent, int userId, boolean deferResume) { |
| 4763 | return updateConfigurationLocked(values, starting, initLocale, persistent, userId, |
| 4764 | deferResume, null /* result */); |
| 4765 | } |
| 4766 | |
| 4767 | /** |
| 4768 | * Do either or both things: (1) change the current configuration, and (2) |
| 4769 | * make sure the given activity is running with the (now) current |
| 4770 | * configuration. Returns true if the activity has been left running, or |
| 4771 | * false if <var>starting</var> is being destroyed to match the new |
| 4772 | * configuration. |
| 4773 | * |
| 4774 | * @param userId is only used when persistent parameter is set to true to persist configuration |
| 4775 | * for that particular user |
| 4776 | */ |
| 4777 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 4778 | boolean initLocale, boolean persistent, int userId, boolean deferResume, |
| 4779 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 4780 | int changes = 0; |
| 4781 | boolean kept = true; |
| 4782 | |
| 4783 | if (mWindowManager != null) { |
| 4784 | mWindowManager.deferSurfaceLayout(); |
| 4785 | } |
| 4786 | try { |
| 4787 | if (values != null) { |
| 4788 | changes = updateGlobalConfigurationLocked(values, initLocale, persistent, userId, |
| 4789 | deferResume); |
| 4790 | } |
| 4791 | |
| 4792 | kept = ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 4793 | } finally { |
| 4794 | if (mWindowManager != null) { |
| 4795 | mWindowManager.continueSurfaceLayout(); |
| 4796 | } |
| 4797 | } |
| 4798 | |
| 4799 | if (result != null) { |
| 4800 | result.changes = changes; |
| 4801 | result.activityRelaunched = !kept; |
| 4802 | } |
| 4803 | return kept; |
| 4804 | } |
| 4805 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4806 | /** Update default (global) configuration and notify listeners about changes. */ |
| 4807 | private int updateGlobalConfigurationLocked(@NonNull Configuration values, boolean initLocale, |
| 4808 | boolean persistent, int userId, boolean deferResume) { |
| 4809 | mTempConfig.setTo(getGlobalConfiguration()); |
| 4810 | final int changes = mTempConfig.updateFrom(values); |
| 4811 | if (changes == 0) { |
| 4812 | // Since calling to Activity.setRequestedOrientation leads to freezing the window with |
| 4813 | // setting WindowManagerService.mWaitingForConfig to true, it is important that we call |
| 4814 | // performDisplayOverrideConfigUpdate in order to send the new display configuration |
| 4815 | // (even if there are no actual changes) to unfreeze the window. |
| 4816 | performDisplayOverrideConfigUpdate(values, deferResume, DEFAULT_DISPLAY); |
| 4817 | return 0; |
| 4818 | } |
| 4819 | |
| 4820 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.i(TAG_CONFIGURATION, |
| 4821 | "Updating global configuration to: " + values); |
| 4822 | |
| 4823 | EventLog.writeEvent(EventLogTags.CONFIGURATION_CHANGED, changes); |
| 4824 | StatsLog.write(StatsLog.RESOURCE_CONFIGURATION_CHANGED, |
| 4825 | values.colorMode, |
| 4826 | values.densityDpi, |
| 4827 | values.fontScale, |
| 4828 | values.hardKeyboardHidden, |
| 4829 | values.keyboard, |
| 4830 | values.keyboardHidden, |
| 4831 | values.mcc, |
| 4832 | values.mnc, |
| 4833 | values.navigation, |
| 4834 | values.navigationHidden, |
| 4835 | values.orientation, |
| 4836 | values.screenHeightDp, |
| 4837 | values.screenLayout, |
| 4838 | values.screenWidthDp, |
| 4839 | values.smallestScreenWidthDp, |
| 4840 | values.touchscreen, |
| 4841 | values.uiMode); |
| 4842 | |
| 4843 | |
| 4844 | if (!initLocale && !values.getLocales().isEmpty() && values.userSetLocale) { |
| 4845 | final LocaleList locales = values.getLocales(); |
| 4846 | int bestLocaleIndex = 0; |
| 4847 | if (locales.size() > 1) { |
| 4848 | if (mSupportedSystemLocales == null) { |
| 4849 | mSupportedSystemLocales = Resources.getSystem().getAssets().getLocales(); |
| 4850 | } |
| 4851 | bestLocaleIndex = Math.max(0, locales.getFirstMatchIndex(mSupportedSystemLocales)); |
| 4852 | } |
| 4853 | SystemProperties.set("persist.sys.locale", |
| 4854 | locales.get(bestLocaleIndex).toLanguageTag()); |
| 4855 | LocaleList.setDefault(locales, bestLocaleIndex); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4856 | |
| 4857 | final Message m = PooledLambda.obtainMessage( |
| 4858 | ActivityTaskManagerService::sendLocaleToMountDaemonMsg, this, |
| 4859 | locales.get(bestLocaleIndex)); |
| 4860 | mH.sendMessage(m); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4861 | } |
| 4862 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 4863 | mTempConfig.seq = increaseConfigurationSeqLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4864 | |
| 4865 | // Update stored global config and notify everyone about the change. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4866 | mRootActivityContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4867 | |
| 4868 | Slog.i(TAG, "Config changes=" + Integer.toHexString(changes) + " " + mTempConfig); |
| 4869 | // TODO(multi-display): Update UsageEvents#Event to include displayId. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4870 | mUsageStatsInternal.reportConfigurationChange(mTempConfig, mAmInternal.getCurrentUserId()); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4871 | |
| 4872 | // 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] | 4873 | updateShouldShowDialogsLocked(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4874 | |
| 4875 | AttributeCache ac = AttributeCache.instance(); |
| 4876 | if (ac != null) { |
| 4877 | ac.updateConfiguration(mTempConfig); |
| 4878 | } |
| 4879 | |
| 4880 | // Make sure all resources in our process are updated right now, so that anyone who is going |
| 4881 | // to retrieve resource values after we return will be sure to get the new ones. This is |
| 4882 | // especially important during boot, where the first config change needs to guarantee all |
| 4883 | // resources have that config before following boot code is executed. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4884 | mSystemThread.applyConfigurationToResources(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4885 | |
| 4886 | // We need another copy of global config because we're scheduling some calls instead of |
| 4887 | // running them in place. We need to be sure that object we send will be handled unchanged. |
| 4888 | final Configuration configCopy = new Configuration(mTempConfig); |
| 4889 | if (persistent && Settings.System.hasInterestingConfigurationChanges(changes)) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4890 | final Message msg = PooledLambda.obtainMessage( |
| 4891 | ActivityTaskManagerService::sendPutConfigurationForUserMsg, |
| 4892 | this, userId, configCopy); |
| 4893 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4894 | } |
| 4895 | |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 4896 | for (int i = mPidMap.size() - 1; i >= 0; i--) { |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 4897 | final int pid = mPidMap.keyAt(i); |
| 4898 | final WindowProcessController app = mPidMap.get(pid); |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 4899 | if (DEBUG_CONFIGURATION) { |
| 4900 | Slog.v(TAG_CONFIGURATION, "Update process config of " |
| 4901 | + app.mName + " to new config " + configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4902 | } |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 4903 | app.onConfigurationChanged(configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4904 | } |
| 4905 | |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 4906 | final Message msg = PooledLambda.obtainMessage( |
| 4907 | ActivityManagerInternal::broadcastGlobalConfigurationChanged, |
| 4908 | mAmInternal, changes, initLocale); |
| 4909 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4910 | |
| 4911 | // Override configuration of the default display duplicates global config, so we need to |
| 4912 | // update it also. This will also notify WindowManager about changes. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4913 | performDisplayOverrideConfigUpdate(mRootActivityContainer.getConfiguration(), deferResume, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4914 | DEFAULT_DISPLAY); |
| 4915 | |
| 4916 | return changes; |
| 4917 | } |
| 4918 | |
| 4919 | boolean updateDisplayOverrideConfigurationLocked(Configuration values, ActivityRecord starting, |
| 4920 | boolean deferResume, int displayId) { |
| 4921 | return updateDisplayOverrideConfigurationLocked(values, starting, deferResume /* deferResume */, |
| 4922 | displayId, null /* result */); |
| 4923 | } |
| 4924 | |
| 4925 | /** |
| 4926 | * Updates override configuration specific for the selected display. If no config is provided, |
| 4927 | * new one will be computed in WM based on current display info. |
| 4928 | */ |
| 4929 | boolean updateDisplayOverrideConfigurationLocked(Configuration values, |
| 4930 | ActivityRecord starting, boolean deferResume, int displayId, |
| 4931 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 4932 | int changes = 0; |
| 4933 | boolean kept = true; |
| 4934 | |
| 4935 | if (mWindowManager != null) { |
| 4936 | mWindowManager.deferSurfaceLayout(); |
| 4937 | } |
| 4938 | try { |
| 4939 | if (values != null) { |
| 4940 | if (displayId == DEFAULT_DISPLAY) { |
| 4941 | // Override configuration of the default display duplicates global config, so |
| 4942 | // we're calling global config update instead for default display. It will also |
| 4943 | // apply the correct override config. |
| 4944 | changes = updateGlobalConfigurationLocked(values, false /* initLocale */, |
| 4945 | false /* persistent */, UserHandle.USER_NULL /* userId */, deferResume); |
| 4946 | } else { |
| 4947 | changes = performDisplayOverrideConfigUpdate(values, deferResume, displayId); |
| 4948 | } |
| 4949 | } |
| 4950 | |
| 4951 | kept = ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 4952 | } finally { |
| 4953 | if (mWindowManager != null) { |
| 4954 | mWindowManager.continueSurfaceLayout(); |
| 4955 | } |
| 4956 | } |
| 4957 | |
| 4958 | if (result != null) { |
| 4959 | result.changes = changes; |
| 4960 | result.activityRelaunched = !kept; |
| 4961 | } |
| 4962 | return kept; |
| 4963 | } |
| 4964 | |
| 4965 | private int performDisplayOverrideConfigUpdate(Configuration values, boolean deferResume, |
| 4966 | int displayId) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4967 | mTempConfig.setTo(mRootActivityContainer.getDisplayOverrideConfiguration(displayId)); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4968 | final int changes = mTempConfig.updateFrom(values); |
| 4969 | if (changes != 0) { |
| 4970 | Slog.i(TAG, "Override config changes=" + Integer.toHexString(changes) + " " |
| 4971 | + mTempConfig + " for displayId=" + displayId); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4972 | mRootActivityContainer.setDisplayOverrideConfiguration(mTempConfig, displayId); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4973 | |
| 4974 | final boolean isDensityChange = (changes & ActivityInfo.CONFIG_DENSITY) != 0; |
| 4975 | if (isDensityChange && displayId == DEFAULT_DISPLAY) { |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 4976 | mAppWarnings.onDensityChanged(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4977 | |
Wale Ogunwale | 5c91870 | 2018-10-18 11:06:33 -0700 | [diff] [blame] | 4978 | // Post message to start process to avoid possible deadlock of calling into AMS with |
| 4979 | // the ATMS lock held. |
| 4980 | final Message msg = PooledLambda.obtainMessage( |
| 4981 | ActivityManagerInternal::killAllBackgroundProcessesExcept, mAmInternal, |
| 4982 | N, ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE); |
| 4983 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4984 | } |
| 4985 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4986 | return changes; |
| 4987 | } |
| 4988 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4989 | private void updateEventDispatchingLocked(boolean booted) { |
| 4990 | mWindowManager.setEventDispatching(booted && !mShuttingDown); |
| 4991 | } |
| 4992 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4993 | private void sendPutConfigurationForUserMsg(int userId, Configuration config) { |
| 4994 | final ContentResolver resolver = mContext.getContentResolver(); |
| 4995 | Settings.System.putConfigurationForUser(resolver, config, userId); |
| 4996 | } |
| 4997 | |
| 4998 | private void sendLocaleToMountDaemonMsg(Locale l) { |
| 4999 | try { |
| 5000 | IBinder service = ServiceManager.getService("mount"); |
| 5001 | IStorageManager storageManager = IStorageManager.Stub.asInterface(service); |
| 5002 | Log.d(TAG, "Storing locale " + l.toLanguageTag() + " for decryption UI"); |
| 5003 | storageManager.setField(StorageManager.SYSTEM_LOCALE_KEY, l.toLanguageTag()); |
| 5004 | } catch (RemoteException e) { |
| 5005 | Log.e(TAG, "Error storing locale for decryption UI", e); |
| 5006 | } |
| 5007 | } |
| 5008 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5009 | private void expireStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5010 | mStartActivitySources.remove(permissionToken); |
| 5011 | mExpiredStartAsCallerTokens.add(permissionToken); |
| 5012 | } |
| 5013 | |
| 5014 | private void forgetStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5015 | mExpiredStartAsCallerTokens.remove(permissionToken); |
| 5016 | } |
| 5017 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5018 | boolean isActivityStartsLoggingEnabled() { |
| 5019 | return mAmInternal.isActivityStartsLoggingEnabled(); |
| 5020 | } |
| 5021 | |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 5022 | boolean isBackgroundActivityStartsEnabled() { |
| 5023 | return mAmInternal.isBackgroundActivityStartsEnabled(); |
| 5024 | } |
| 5025 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5026 | void enableScreenAfterBoot(boolean booted) { |
| 5027 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_ENABLE_SCREEN, |
| 5028 | SystemClock.uptimeMillis()); |
| 5029 | mWindowManager.enableScreenAfterBoot(); |
| 5030 | |
| 5031 | synchronized (mGlobalLock) { |
| 5032 | updateEventDispatchingLocked(booted); |
| 5033 | } |
| 5034 | } |
| 5035 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5036 | static long getInputDispatchingTimeoutLocked(ActivityRecord r) { |
| 5037 | if (r == null || !r.hasProcess()) { |
| 5038 | return KEY_DISPATCHING_TIMEOUT_MS; |
| 5039 | } |
| 5040 | return getInputDispatchingTimeoutLocked(r.app); |
| 5041 | } |
| 5042 | |
| 5043 | private static long getInputDispatchingTimeoutLocked(WindowProcessController r) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 5044 | return r != null ? r.getInputDispatchingTimeout() : KEY_DISPATCHING_TIMEOUT_MS; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5045 | } |
| 5046 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5047 | /** |
| 5048 | * Decide based on the configuration whether we should show the ANR, |
| 5049 | * crash, etc dialogs. The idea is that if there is no affordance to |
| 5050 | * press the on-screen buttons, or the user experience would be more |
| 5051 | * greatly impacted than the crash itself, we shouldn't show the dialog. |
| 5052 | * |
| 5053 | * A thought: SystemUI might also want to get told about this, the Power |
| 5054 | * dialog / global actions also might want different behaviors. |
| 5055 | */ |
| 5056 | private void updateShouldShowDialogsLocked(Configuration config) { |
| 5057 | final boolean inputMethodExists = !(config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 5058 | && config.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH |
| 5059 | && config.navigation == Configuration.NAVIGATION_NONAV); |
| 5060 | int modeType = config.uiMode & Configuration.UI_MODE_TYPE_MASK; |
| 5061 | final boolean uiModeSupportsDialogs = (modeType != Configuration.UI_MODE_TYPE_CAR |
| 5062 | && !(modeType == Configuration.UI_MODE_TYPE_WATCH && Build.IS_USER) |
| 5063 | && modeType != Configuration.UI_MODE_TYPE_TELEVISION |
| 5064 | && modeType != Configuration.UI_MODE_TYPE_VR_HEADSET); |
| 5065 | final boolean hideDialogsSet = Settings.Global.getInt(mContext.getContentResolver(), |
| 5066 | HIDE_ERROR_DIALOGS, 0) != 0; |
| 5067 | mShowDialogs = inputMethodExists && uiModeSupportsDialogs && !hideDialogsSet; |
| 5068 | } |
| 5069 | |
| 5070 | private void updateFontScaleIfNeeded(@UserIdInt int userId) { |
| 5071 | final float scaleFactor = Settings.System.getFloatForUser(mContext.getContentResolver(), |
| 5072 | FONT_SCALE, 1.0f, userId); |
| 5073 | |
| 5074 | synchronized (this) { |
| 5075 | if (getGlobalConfiguration().fontScale == scaleFactor) { |
| 5076 | return; |
| 5077 | } |
| 5078 | |
| 5079 | final Configuration configuration |
| 5080 | = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
| 5081 | configuration.fontScale = scaleFactor; |
| 5082 | updatePersistentConfiguration(configuration, userId); |
| 5083 | } |
| 5084 | } |
| 5085 | |
| 5086 | // Actually is sleeping or shutting down or whatever else in the future |
| 5087 | // is an inactive state. |
| 5088 | boolean isSleepingOrShuttingDownLocked() { |
| 5089 | return isSleepingLocked() || mShuttingDown; |
| 5090 | } |
| 5091 | |
| 5092 | boolean isSleepingLocked() { |
| 5093 | return mSleeping; |
| 5094 | } |
| 5095 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5096 | /** Update AMS states when an activity is resumed. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5097 | void setResumedActivityUncheckLocked(ActivityRecord r, String reason) { |
| 5098 | final TaskRecord task = r.getTask(); |
| 5099 | if (task.isActivityTypeStandard()) { |
| 5100 | if (mCurAppTimeTracker != r.appTimeTracker) { |
| 5101 | // We are switching app tracking. Complete the current one. |
| 5102 | if (mCurAppTimeTracker != null) { |
| 5103 | mCurAppTimeTracker.stop(); |
| 5104 | mH.obtainMessage( |
| 5105 | REPORT_TIME_TRACKER_MSG, mCurAppTimeTracker).sendToTarget(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5106 | mRootActivityContainer.clearOtherAppTimeTrackers(r.appTimeTracker); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5107 | mCurAppTimeTracker = null; |
| 5108 | } |
| 5109 | if (r.appTimeTracker != null) { |
| 5110 | mCurAppTimeTracker = r.appTimeTracker; |
| 5111 | startTimeTrackingFocusedActivityLocked(); |
| 5112 | } |
| 5113 | } else { |
| 5114 | startTimeTrackingFocusedActivityLocked(); |
| 5115 | } |
| 5116 | } else { |
| 5117 | r.appTimeTracker = null; |
| 5118 | } |
| 5119 | // TODO: VI Maybe r.task.voiceInteractor || r.voiceInteractor != null |
| 5120 | // TODO: Probably not, because we don't want to resume voice on switching |
| 5121 | // back to this activity |
| 5122 | if (task.voiceInteractor != null) { |
| 5123 | startRunningVoiceLocked(task.voiceSession, r.info.applicationInfo.uid); |
| 5124 | } else { |
| 5125 | finishRunningVoiceLocked(); |
| 5126 | |
| 5127 | if (mLastResumedActivity != null) { |
| 5128 | final IVoiceInteractionSession session; |
| 5129 | |
| 5130 | final TaskRecord lastResumedActivityTask = mLastResumedActivity.getTask(); |
| 5131 | if (lastResumedActivityTask != null |
| 5132 | && lastResumedActivityTask.voiceSession != null) { |
| 5133 | session = lastResumedActivityTask.voiceSession; |
| 5134 | } else { |
| 5135 | session = mLastResumedActivity.voiceSession; |
| 5136 | } |
| 5137 | |
| 5138 | if (session != null) { |
| 5139 | // We had been in a voice interaction session, but now focused has |
| 5140 | // move to something different. Just finish the session, we can't |
| 5141 | // return to it and retain the proper state and synchronization with |
| 5142 | // the voice interaction service. |
| 5143 | finishVoiceTask(session); |
| 5144 | } |
| 5145 | } |
| 5146 | } |
| 5147 | |
| 5148 | if (mLastResumedActivity != null && r.userId != mLastResumedActivity.userId) { |
| 5149 | mAmInternal.sendForegroundProfileChanged(r.userId); |
| 5150 | } |
| 5151 | updateResumedAppTrace(r); |
| 5152 | mLastResumedActivity = r; |
| 5153 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 5154 | r.getDisplay().setFocusedApp(r, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5155 | |
| 5156 | applyUpdateLockStateLocked(r); |
| 5157 | applyUpdateVrModeLocked(r); |
| 5158 | |
| 5159 | EventLogTags.writeAmSetResumedActivity( |
| 5160 | r == null ? -1 : r.userId, |
| 5161 | r == null ? "NULL" : r.shortComponentName, |
| 5162 | reason); |
| 5163 | } |
| 5164 | |
| 5165 | ActivityTaskManagerInternal.SleepToken acquireSleepToken(String tag, int displayId) { |
| 5166 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5167 | final ActivityTaskManagerInternal.SleepToken token = |
| 5168 | mRootActivityContainer.createSleepToken(tag, displayId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5169 | updateSleepIfNeededLocked(); |
| 5170 | return token; |
| 5171 | } |
| 5172 | } |
| 5173 | |
| 5174 | void updateSleepIfNeededLocked() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5175 | final boolean shouldSleep = !mRootActivityContainer.hasAwakeDisplay(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5176 | final boolean wasSleeping = mSleeping; |
| 5177 | boolean updateOomAdj = false; |
| 5178 | |
| 5179 | if (!shouldSleep) { |
| 5180 | // If wasSleeping is true, we need to wake up activity manager state from when |
| 5181 | // we started sleeping. In either case, we need to apply the sleep tokens, which |
| 5182 | // will wake up stacks or put them to sleep as appropriate. |
| 5183 | if (wasSleeping) { |
| 5184 | mSleeping = false; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 5185 | StatsLog.write(StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5186 | StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__AWAKE); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5187 | startTimeTrackingFocusedActivityLocked(); |
| 5188 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
| 5189 | mStackSupervisor.comeOutOfSleepIfNeededLocked(); |
| 5190 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5191 | mRootActivityContainer.applySleepTokens(true /* applyToStacks */); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5192 | if (wasSleeping) { |
| 5193 | updateOomAdj = true; |
| 5194 | } |
| 5195 | } else if (!mSleeping && shouldSleep) { |
| 5196 | mSleeping = true; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 5197 | StatsLog.write(StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5198 | StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__ASLEEP); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5199 | if (mCurAppTimeTracker != null) { |
| 5200 | mCurAppTimeTracker.stop(); |
| 5201 | } |
| 5202 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP_SLEEPING; |
| 5203 | mStackSupervisor.goingToSleepLocked(); |
| 5204 | updateResumedAppTrace(null /* resumed */); |
| 5205 | updateOomAdj = true; |
| 5206 | } |
| 5207 | if (updateOomAdj) { |
| 5208 | mH.post(mAmInternal::updateOomAdj); |
| 5209 | } |
| 5210 | } |
| 5211 | |
| 5212 | void updateOomAdj() { |
| 5213 | mH.post(mAmInternal::updateOomAdj); |
| 5214 | } |
| 5215 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5216 | void updateCpuStats() { |
| 5217 | mH.post(mAmInternal::updateCpuStats); |
| 5218 | } |
| 5219 | |
| 5220 | void updateUsageStats(ActivityRecord component, boolean resumed) { |
| 5221 | final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::updateUsageStats, |
| 5222 | mAmInternal, component.realActivity, component.app.mUid, component.userId, resumed); |
| 5223 | mH.sendMessage(m); |
| 5224 | } |
| 5225 | |
| 5226 | void setBooting(boolean booting) { |
| 5227 | mAmInternal.setBooting(booting); |
| 5228 | } |
| 5229 | |
| 5230 | boolean isBooting() { |
| 5231 | return mAmInternal.isBooting(); |
| 5232 | } |
| 5233 | |
| 5234 | void setBooted(boolean booted) { |
| 5235 | mAmInternal.setBooted(booted); |
| 5236 | } |
| 5237 | |
| 5238 | boolean isBooted() { |
| 5239 | return mAmInternal.isBooted(); |
| 5240 | } |
| 5241 | |
| 5242 | void postFinishBooting(boolean finishBooting, boolean enableScreen) { |
| 5243 | mH.post(() -> { |
| 5244 | if (finishBooting) { |
| 5245 | mAmInternal.finishBooting(); |
| 5246 | } |
| 5247 | if (enableScreen) { |
| 5248 | mInternal.enableScreenAfterBoot(isBooted()); |
| 5249 | } |
| 5250 | }); |
| 5251 | } |
| 5252 | |
| 5253 | void setHeavyWeightProcess(ActivityRecord root) { |
| 5254 | mHeavyWeightProcess = root.app; |
| 5255 | final Message m = PooledLambda.obtainMessage( |
| 5256 | ActivityTaskManagerService::postHeavyWeightProcessNotification, this, |
| 5257 | root.app, root.intent, root.userId); |
| 5258 | mH.sendMessage(m); |
| 5259 | } |
| 5260 | |
| 5261 | void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
| 5262 | if (mHeavyWeightProcess == null || mHeavyWeightProcess != proc) { |
| 5263 | return; |
| 5264 | } |
| 5265 | |
| 5266 | mHeavyWeightProcess = null; |
| 5267 | final Message m = PooledLambda.obtainMessage( |
| 5268 | ActivityTaskManagerService::cancelHeavyWeightProcessNotification, this, |
| 5269 | proc.mUserId); |
| 5270 | mH.sendMessage(m); |
| 5271 | } |
| 5272 | |
| 5273 | private void cancelHeavyWeightProcessNotification(int userId) { |
| 5274 | final INotificationManager inm = NotificationManager.getService(); |
| 5275 | if (inm == null) { |
| 5276 | return; |
| 5277 | } |
| 5278 | try { |
| 5279 | inm.cancelNotificationWithTag("android", null, |
| 5280 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, userId); |
| 5281 | } catch (RuntimeException e) { |
| 5282 | Slog.w(TAG, "Error canceling notification for service", e); |
| 5283 | } catch (RemoteException e) { |
| 5284 | } |
| 5285 | |
| 5286 | } |
| 5287 | |
| 5288 | private void postHeavyWeightProcessNotification( |
| 5289 | WindowProcessController proc, Intent intent, int userId) { |
| 5290 | if (proc == null) { |
| 5291 | return; |
| 5292 | } |
| 5293 | |
| 5294 | final INotificationManager inm = NotificationManager.getService(); |
| 5295 | if (inm == null) { |
| 5296 | return; |
| 5297 | } |
| 5298 | |
| 5299 | try { |
| 5300 | Context context = mContext.createPackageContext(proc.mInfo.packageName, 0); |
| 5301 | String text = mContext.getString(R.string.heavy_weight_notification, |
| 5302 | context.getApplicationInfo().loadLabel(context.getPackageManager())); |
| 5303 | Notification notification = |
| 5304 | new Notification.Builder(context, |
| 5305 | SystemNotificationChannels.HEAVY_WEIGHT_APP) |
| 5306 | .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) |
| 5307 | .setWhen(0) |
| 5308 | .setOngoing(true) |
| 5309 | .setTicker(text) |
| 5310 | .setColor(mContext.getColor( |
| 5311 | com.android.internal.R.color.system_notification_accent_color)) |
| 5312 | .setContentTitle(text) |
| 5313 | .setContentText( |
| 5314 | mContext.getText(R.string.heavy_weight_notification_detail)) |
| 5315 | .setContentIntent(PendingIntent.getActivityAsUser(mContext, 0, |
| 5316 | intent, PendingIntent.FLAG_CANCEL_CURRENT, null, |
| 5317 | new UserHandle(userId))) |
| 5318 | .build(); |
| 5319 | try { |
| 5320 | inm.enqueueNotificationWithTag("android", "android", null, |
| 5321 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, notification, userId); |
| 5322 | } catch (RuntimeException e) { |
| 5323 | Slog.w(TAG, "Error showing notification for heavy-weight app", e); |
| 5324 | } catch (RemoteException e) { |
| 5325 | } |
| 5326 | } catch (PackageManager.NameNotFoundException e) { |
| 5327 | Slog.w(TAG, "Unable to create context for heavy notification", e); |
| 5328 | } |
| 5329 | |
| 5330 | } |
| 5331 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5332 | IIntentSender getIntentSenderLocked(int type, String packageName, int callingUid, int userId, |
| 5333 | IBinder token, String resultWho, int requestCode, Intent[] intents, |
| 5334 | String[] resolvedTypes, int flags, Bundle bOptions) { |
| 5335 | |
| 5336 | ActivityRecord activity = null; |
| 5337 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5338 | activity = ActivityRecord.isInStackLocked(token); |
| 5339 | if (activity == null) { |
| 5340 | Slog.w(TAG, "Failed createPendingResult: activity " + token + " not in any stack"); |
| 5341 | return null; |
| 5342 | } |
| 5343 | if (activity.finishing) { |
| 5344 | Slog.w(TAG, "Failed createPendingResult: activity " + activity + " is finishing"); |
| 5345 | return null; |
| 5346 | } |
| 5347 | } |
| 5348 | |
| 5349 | final PendingIntentRecord rec = mPendingIntentController.getIntentSender(type, packageName, |
| 5350 | callingUid, userId, token, resultWho, requestCode, intents, resolvedTypes, flags, |
| 5351 | bOptions); |
| 5352 | final boolean noCreate = (flags & PendingIntent.FLAG_NO_CREATE) != 0; |
| 5353 | if (noCreate) { |
| 5354 | return rec; |
| 5355 | } |
| 5356 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5357 | if (activity.pendingResults == null) { |
| 5358 | activity.pendingResults = new HashSet<>(); |
| 5359 | } |
| 5360 | activity.pendingResults.add(rec.ref); |
| 5361 | } |
| 5362 | return rec; |
| 5363 | } |
| 5364 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 5365 | // 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] | 5366 | private void startTimeTrackingFocusedActivityLocked() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5367 | final ActivityRecord resumedActivity = mRootActivityContainer.getTopResumedActivity(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5368 | if (!mSleeping && mCurAppTimeTracker != null && resumedActivity != null) { |
| 5369 | mCurAppTimeTracker.start(resumedActivity.packageName); |
| 5370 | } |
| 5371 | } |
| 5372 | |
| 5373 | private void updateResumedAppTrace(@Nullable ActivityRecord resumed) { |
| 5374 | if (mTracedResumedActivity != null) { |
| 5375 | Trace.asyncTraceEnd(TRACE_TAG_ACTIVITY_MANAGER, |
| 5376 | constructResumedTraceName(mTracedResumedActivity.packageName), 0); |
| 5377 | } |
| 5378 | if (resumed != null) { |
| 5379 | Trace.asyncTraceBegin(TRACE_TAG_ACTIVITY_MANAGER, |
| 5380 | constructResumedTraceName(resumed.packageName), 0); |
| 5381 | } |
| 5382 | mTracedResumedActivity = resumed; |
| 5383 | } |
| 5384 | |
| 5385 | private String constructResumedTraceName(String packageName) { |
| 5386 | return "focused app: " + packageName; |
| 5387 | } |
| 5388 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5389 | /** Applies latest configuration and/or visibility updates if needed. */ |
| 5390 | private boolean ensureConfigAndVisibilityAfterUpdate(ActivityRecord starting, int changes) { |
| 5391 | boolean kept = true; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5392 | final ActivityStack mainStack = mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5393 | // mainStack is null during startup. |
| 5394 | if (mainStack != null) { |
| 5395 | if (changes != 0 && starting == null) { |
| 5396 | // If the configuration changed, and the caller is not already |
| 5397 | // in the process of starting an activity, then find the top |
| 5398 | // activity to check if its configuration needs to change. |
| 5399 | starting = mainStack.topRunningActivityLocked(); |
| 5400 | } |
| 5401 | |
| 5402 | if (starting != null) { |
| 5403 | kept = starting.ensureActivityConfiguration(changes, |
| 5404 | false /* preserveWindow */); |
| 5405 | // And we need to make sure at this point that all other activities |
| 5406 | // are made visible with the correct configuration. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5407 | mRootActivityContainer.ensureActivitiesVisible(starting, changes, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5408 | !PRESERVE_WINDOWS); |
| 5409 | } |
| 5410 | } |
| 5411 | |
| 5412 | return kept; |
| 5413 | } |
| 5414 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5415 | void scheduleAppGcsLocked() { |
| 5416 | mH.post(() -> mAmInternal.scheduleAppGcs()); |
| 5417 | } |
| 5418 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5419 | CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) { |
| 5420 | return mCompatModePackages.compatibilityInfoForPackageLocked(ai); |
| 5421 | } |
| 5422 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5423 | /** |
| 5424 | * Returns the PackageManager. Used by classes hosted by {@link ActivityTaskManagerService}. The |
| 5425 | * PackageManager could be unavailable at construction time and therefore needs to be accessed |
| 5426 | * on demand. |
| 5427 | */ |
| 5428 | IPackageManager getPackageManager() { |
| 5429 | return AppGlobals.getPackageManager(); |
| 5430 | } |
| 5431 | |
| 5432 | PackageManagerInternal getPackageManagerInternalLocked() { |
| 5433 | if (mPmInternal == null) { |
| 5434 | mPmInternal = LocalServices.getService(PackageManagerInternal.class); |
| 5435 | } |
| 5436 | return mPmInternal; |
| 5437 | } |
| 5438 | |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 5439 | AppWarnings getAppWarningsLocked() { |
| 5440 | return mAppWarnings; |
| 5441 | } |
| 5442 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5443 | Intent getHomeIntent() { |
| 5444 | Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null); |
| 5445 | intent.setComponent(mTopComponent); |
| 5446 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5447 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5448 | intent.addCategory(Intent.CATEGORY_HOME); |
| 5449 | } |
| 5450 | return intent; |
| 5451 | } |
| 5452 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5453 | ApplicationInfo getAppInfoForUser(ApplicationInfo info, int userId) { |
| 5454 | if (info == null) return null; |
| 5455 | ApplicationInfo newInfo = new ApplicationInfo(info); |
| 5456 | newInfo.initForUser(userId); |
| 5457 | return newInfo; |
| 5458 | } |
| 5459 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 5460 | WindowProcessController getProcessController(String processName, int uid) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5461 | if (uid == SYSTEM_UID) { |
| 5462 | // The system gets to run in any process. If there are multiple processes with the same |
| 5463 | // uid, just pick the first (this should never happen). |
| 5464 | final SparseArray<WindowProcessController> procs = |
| 5465 | mProcessNames.getMap().get(processName); |
| 5466 | if (procs == null) return null; |
| 5467 | final int procCount = procs.size(); |
| 5468 | for (int i = 0; i < procCount; i++) { |
| 5469 | final int procUid = procs.keyAt(i); |
| 5470 | if (UserHandle.isApp(procUid) || !UserHandle.isSameUser(procUid, uid)) { |
| 5471 | // Don't use an app process or different user process for system component. |
| 5472 | continue; |
| 5473 | } |
| 5474 | return procs.valueAt(i); |
| 5475 | } |
| 5476 | } |
| 5477 | |
| 5478 | return mProcessNames.get(processName, uid); |
| 5479 | } |
| 5480 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5481 | WindowProcessController getProcessController(IApplicationThread thread) { |
| 5482 | if (thread == null) { |
| 5483 | return null; |
| 5484 | } |
| 5485 | |
| 5486 | final IBinder threadBinder = thread.asBinder(); |
| 5487 | final ArrayMap<String, SparseArray<WindowProcessController>> pmap = mProcessNames.getMap(); |
| 5488 | for (int i = pmap.size()-1; i >= 0; i--) { |
| 5489 | final SparseArray<WindowProcessController> procs = pmap.valueAt(i); |
| 5490 | for (int j = procs.size() - 1; j >= 0; j--) { |
| 5491 | final WindowProcessController proc = procs.valueAt(j); |
| 5492 | if (proc.hasThread() && proc.getThread().asBinder() == threadBinder) { |
| 5493 | return proc; |
| 5494 | } |
| 5495 | } |
| 5496 | } |
| 5497 | |
| 5498 | return null; |
| 5499 | } |
| 5500 | |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 5501 | int getUidStateLocked(int uid) { |
| 5502 | return mActiveUids.get(uid, PROCESS_STATE_NONEXISTENT); |
| 5503 | } |
| 5504 | |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 5505 | /** |
| 5506 | * @return whitelist tag for a uid from mPendingTempWhitelist, null if not currently on |
| 5507 | * the whitelist |
| 5508 | */ |
| 5509 | String getPendingTempWhitelistTagForUidLocked(int uid) { |
| 5510 | return mPendingTempWhitelist.get(uid); |
| 5511 | } |
| 5512 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5513 | void logAppTooSlow(WindowProcessController app, long startTime, String msg) { |
| 5514 | if (true || Build.IS_USER) { |
| 5515 | return; |
| 5516 | } |
| 5517 | |
| 5518 | StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 5519 | StrictMode.allowThreadDiskWrites(); |
| 5520 | try { |
| 5521 | File tracesDir = new File("/data/anr"); |
| 5522 | File tracesFile = null; |
| 5523 | try { |
| 5524 | tracesFile = File.createTempFile("app_slow", null, tracesDir); |
| 5525 | |
| 5526 | StringBuilder sb = new StringBuilder(); |
| 5527 | Time tobj = new Time(); |
| 5528 | tobj.set(System.currentTimeMillis()); |
| 5529 | sb.append(tobj.format("%Y-%m-%d %H:%M:%S")); |
| 5530 | sb.append(": "); |
| 5531 | TimeUtils.formatDuration(SystemClock.uptimeMillis()-startTime, sb); |
| 5532 | sb.append(" since "); |
| 5533 | sb.append(msg); |
| 5534 | FileOutputStream fos = new FileOutputStream(tracesFile); |
| 5535 | fos.write(sb.toString().getBytes()); |
| 5536 | if (app == null) { |
| 5537 | fos.write("\n*** No application process!".getBytes()); |
| 5538 | } |
| 5539 | fos.close(); |
| 5540 | FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1); // -rw-rw-rw- |
| 5541 | } catch (IOException e) { |
| 5542 | Slog.w(TAG, "Unable to prepare slow app traces file: " + tracesFile, e); |
| 5543 | return; |
| 5544 | } |
| 5545 | |
| 5546 | if (app != null && app.getPid() > 0) { |
| 5547 | ArrayList<Integer> firstPids = new ArrayList<Integer>(); |
| 5548 | firstPids.add(app.getPid()); |
| 5549 | dumpStackTraces(tracesFile.getAbsolutePath(), firstPids, null, null); |
| 5550 | } |
| 5551 | |
| 5552 | File lastTracesFile = null; |
| 5553 | File curTracesFile = null; |
| 5554 | for (int i=9; i>=0; i--) { |
| 5555 | String name = String.format(Locale.US, "slow%02d.txt", i); |
| 5556 | curTracesFile = new File(tracesDir, name); |
| 5557 | if (curTracesFile.exists()) { |
| 5558 | if (lastTracesFile != null) { |
| 5559 | curTracesFile.renameTo(lastTracesFile); |
| 5560 | } else { |
| 5561 | curTracesFile.delete(); |
| 5562 | } |
| 5563 | } |
| 5564 | lastTracesFile = curTracesFile; |
| 5565 | } |
| 5566 | tracesFile.renameTo(curTracesFile); |
| 5567 | } finally { |
| 5568 | StrictMode.setThreadPolicy(oldPolicy); |
| 5569 | } |
| 5570 | } |
| 5571 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5572 | final class H extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5573 | static final int REPORT_TIME_TRACKER_MSG = 1; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5574 | |
| 5575 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 5576 | static final int FIRST_ACTIVITY_STACK_MSG = 100; |
| 5577 | static final int FIRST_SUPERVISOR_STACK_MSG = 200; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5578 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 5579 | public H() { |
| 5580 | super(DisplayThread.get().getLooper()); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5581 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5582 | |
| 5583 | @Override |
| 5584 | public void handleMessage(Message msg) { |
| 5585 | switch (msg.what) { |
| 5586 | case REPORT_TIME_TRACKER_MSG: { |
| 5587 | AppTimeTracker tracker = (AppTimeTracker) msg.obj; |
| 5588 | tracker.deliverResult(mContext); |
| 5589 | } break; |
| 5590 | } |
| 5591 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5592 | } |
| 5593 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5594 | final class UiHandler extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5595 | static final int DISMISS_DIALOG_UI_MSG = 1; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5596 | |
| 5597 | public UiHandler() { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 5598 | super(UiThread.get().getLooper(), null, true); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5599 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5600 | |
| 5601 | @Override |
| 5602 | public void handleMessage(Message msg) { |
| 5603 | switch (msg.what) { |
| 5604 | case DISMISS_DIALOG_UI_MSG: { |
| 5605 | final Dialog d = (Dialog) msg.obj; |
| 5606 | d.dismiss(); |
| 5607 | break; |
| 5608 | } |
| 5609 | } |
| 5610 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5611 | } |
| 5612 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5613 | final class LocalService extends ActivityTaskManagerInternal { |
| 5614 | @Override |
| 5615 | public SleepToken acquireSleepToken(String tag, int displayId) { |
| 5616 | Preconditions.checkNotNull(tag); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5617 | return ActivityTaskManagerService.this.acquireSleepToken(tag, displayId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5618 | } |
| 5619 | |
| 5620 | @Override |
| 5621 | public ComponentName getHomeActivityForUser(int userId) { |
| 5622 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5623 | final ActivityRecord homeActivity = |
| 5624 | mRootActivityContainer.getDefaultDisplayHomeActivityForUser(userId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5625 | return homeActivity == null ? null : homeActivity.realActivity; |
| 5626 | } |
| 5627 | } |
| 5628 | |
| 5629 | @Override |
| 5630 | public void onLocalVoiceInteractionStarted(IBinder activity, |
| 5631 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 5632 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5633 | onLocalVoiceInteractionStartedLocked(activity, voiceSession, voiceInteractor); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5634 | } |
| 5635 | } |
| 5636 | |
| 5637 | @Override |
| 5638 | public void notifyAppTransitionStarting(SparseIntArray reasons, long timestamp) { |
| 5639 | synchronized (mGlobalLock) { |
| 5640 | mStackSupervisor.getActivityMetricsLogger().notifyTransitionStarting( |
| 5641 | reasons, timestamp); |
| 5642 | } |
| 5643 | } |
| 5644 | |
| 5645 | @Override |
| 5646 | public void notifyAppTransitionFinished() { |
| 5647 | synchronized (mGlobalLock) { |
| 5648 | mStackSupervisor.notifyAppTransitionDone(); |
| 5649 | } |
| 5650 | } |
| 5651 | |
| 5652 | @Override |
| 5653 | public void notifyAppTransitionCancelled() { |
| 5654 | synchronized (mGlobalLock) { |
| 5655 | mStackSupervisor.notifyAppTransitionDone(); |
| 5656 | } |
| 5657 | } |
| 5658 | |
| 5659 | @Override |
| 5660 | public List<IBinder> getTopVisibleActivities() { |
| 5661 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5662 | return mRootActivityContainer.getTopVisibleActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5663 | } |
| 5664 | } |
| 5665 | |
| 5666 | @Override |
| 5667 | public void notifyDockedStackMinimizedChanged(boolean minimized) { |
| 5668 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5669 | mRootActivityContainer.setDockedStackMinimized(minimized); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5670 | } |
| 5671 | } |
| 5672 | |
| 5673 | @Override |
| 5674 | public int startActivitiesAsPackage(String packageName, int userId, Intent[] intents, |
| 5675 | Bundle bOptions) { |
| 5676 | Preconditions.checkNotNull(intents, "intents"); |
| 5677 | final String[] resolvedTypes = new String[intents.length]; |
| 5678 | |
| 5679 | // UID of the package on user userId. |
| 5680 | // "= 0" is needed because otherwise catch(RemoteException) would make it look like |
| 5681 | // packageUid may not be initialized. |
| 5682 | int packageUid = 0; |
| 5683 | final long ident = Binder.clearCallingIdentity(); |
| 5684 | |
| 5685 | try { |
| 5686 | for (int i = 0; i < intents.length; i++) { |
| 5687 | resolvedTypes[i] = |
| 5688 | intents[i].resolveTypeIfNeeded(mContext.getContentResolver()); |
| 5689 | } |
| 5690 | |
| 5691 | packageUid = AppGlobals.getPackageManager().getPackageUid( |
| 5692 | packageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId); |
| 5693 | } catch (RemoteException e) { |
| 5694 | // Shouldn't happen. |
| 5695 | } finally { |
| 5696 | Binder.restoreCallingIdentity(ident); |
| 5697 | } |
| 5698 | |
| 5699 | synchronized (mGlobalLock) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 5700 | return getActivityStartController().startActivitiesInPackage( |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5701 | packageUid, packageName, |
| 5702 | intents, resolvedTypes, null /* resultTo */, |
| 5703 | SafeActivityOptions.fromBundle(bOptions), userId, |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 5704 | false /* validateIncomingUser */, null /* originatingPendingIntent */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5705 | } |
| 5706 | } |
| 5707 | |
| 5708 | @Override |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5709 | public int startActivitiesInPackage(int uid, String callingPackage, Intent[] intents, |
| 5710 | String[] resolvedTypes, IBinder resultTo, SafeActivityOptions options, int userId, |
| 5711 | boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent) { |
| 5712 | synchronized (mGlobalLock) { |
| 5713 | return getActivityStartController().startActivitiesInPackage(uid, callingPackage, |
| 5714 | intents, resolvedTypes, resultTo, options, userId, validateIncomingUser, |
| 5715 | originatingPendingIntent); |
| 5716 | } |
| 5717 | } |
| 5718 | |
| 5719 | @Override |
| 5720 | public int startActivityInPackage(int uid, int realCallingPid, int realCallingUid, |
| 5721 | String callingPackage, Intent intent, String resolvedType, IBinder resultTo, |
| 5722 | String resultWho, int requestCode, int startFlags, SafeActivityOptions options, |
| 5723 | int userId, TaskRecord inTask, String reason, boolean validateIncomingUser, |
| 5724 | PendingIntentRecord originatingPendingIntent) { |
| 5725 | synchronized (mGlobalLock) { |
| 5726 | return getActivityStartController().startActivityInPackage(uid, realCallingPid, |
| 5727 | realCallingUid, callingPackage, intent, resolvedType, resultTo, resultWho, |
| 5728 | requestCode, startFlags, options, userId, inTask, reason, |
| 5729 | validateIncomingUser, originatingPendingIntent); |
| 5730 | } |
| 5731 | } |
| 5732 | |
| 5733 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5734 | public int startActivityAsUser(IApplicationThread caller, String callerPacakge, |
| 5735 | Intent intent, Bundle options, int userId) { |
| 5736 | return ActivityTaskManagerService.this.startActivityAsUser( |
| 5737 | caller, callerPacakge, intent, |
| 5738 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 5739 | null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, options, userId, |
| 5740 | false /*validateIncomingUser*/); |
| 5741 | } |
| 5742 | |
| 5743 | @Override |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5744 | public void notifyKeyguardFlagsChanged(@Nullable Runnable callback, int displayId) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5745 | synchronized (mGlobalLock) { |
| 5746 | |
| 5747 | // We might change the visibilities here, so prepare an empty app transition which |
| 5748 | // might be overridden later if we actually change visibilities. |
lumark | 52ea28e | 2018-11-09 17:30:47 +0800 | [diff] [blame] | 5749 | final ActivityDisplay activityDisplay = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5750 | mRootActivityContainer.getActivityDisplay(displayId); |
lumark | 52ea28e | 2018-11-09 17:30:47 +0800 | [diff] [blame] | 5751 | if (activityDisplay == null) { |
| 5752 | return; |
| 5753 | } |
| 5754 | final DisplayWindowController dwc = activityDisplay.getWindowContainerController(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5755 | final boolean wasTransitionSet = dwc.getPendingAppTransition() != TRANSIT_NONE; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5756 | if (!wasTransitionSet) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5757 | dwc.prepareAppTransition(TRANSIT_NONE, false /* alwaysKeepCurrent */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5758 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5759 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5760 | |
| 5761 | // If there was a transition set already we don't want to interfere with it as we |
| 5762 | // might be starting it too early. |
| 5763 | if (!wasTransitionSet) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5764 | dwc.executeAppTransition(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5765 | } |
| 5766 | } |
| 5767 | if (callback != null) { |
| 5768 | callback.run(); |
| 5769 | } |
| 5770 | } |
| 5771 | |
| 5772 | @Override |
| 5773 | public void notifyKeyguardTrustedChanged() { |
| 5774 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5775 | if (mKeyguardController.isKeyguardShowing(DEFAULT_DISPLAY)) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5776 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5777 | } |
| 5778 | } |
| 5779 | } |
| 5780 | |
| 5781 | /** |
| 5782 | * Called after virtual display Id is updated by |
| 5783 | * {@link com.android.server.vr.Vr2dDisplay} with a specific |
| 5784 | * {@param vrVr2dDisplayId}. |
| 5785 | */ |
| 5786 | @Override |
| 5787 | public void setVr2dDisplayId(int vr2dDisplayId) { |
| 5788 | if (DEBUG_STACK) Slog.d(TAG, "setVr2dDisplayId called for: " + vr2dDisplayId); |
| 5789 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5790 | mVr2dDisplayId = vr2dDisplayId; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5791 | } |
| 5792 | } |
| 5793 | |
| 5794 | @Override |
| 5795 | public void setFocusedActivity(IBinder token) { |
| 5796 | synchronized (mGlobalLock) { |
| 5797 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 5798 | if (r == null) { |
| 5799 | throw new IllegalArgumentException( |
| 5800 | "setFocusedActivity: No activity record matching token=" + token); |
| 5801 | } |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 5802 | if (r.moveFocusableActivityToTop("setFocusedActivity")) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5803 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5804 | } |
| 5805 | } |
| 5806 | } |
| 5807 | |
| 5808 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5809 | public void registerScreenObserver(ScreenObserver observer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5810 | mScreenObservers.add(observer); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | @Override |
| 5814 | public boolean isCallerRecents(int callingUid) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 5815 | return getRecentTasks().isCallerRecents(callingUid); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5816 | } |
| 5817 | |
| 5818 | @Override |
| 5819 | public boolean isRecentsComponentHomeActivity(int userId) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 5820 | return getRecentTasks().isRecentsComponentHomeActivity(userId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5821 | } |
| 5822 | |
| 5823 | @Override |
| 5824 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
| 5825 | ActivityTaskManagerService.this.cancelRecentsAnimation(restoreHomeStackPosition); |
| 5826 | } |
| 5827 | |
| 5828 | @Override |
| 5829 | public void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5830 | ActivityTaskManagerService.this.enforceCallerIsRecentsOrHasPermission(permission, func); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5831 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5832 | |
| 5833 | @Override |
| 5834 | public void notifyActiveVoiceInteractionServiceChanged(ComponentName component) { |
| 5835 | synchronized (mGlobalLock) { |
| 5836 | mActiveVoiceInteractionServiceComponent = component; |
| 5837 | } |
| 5838 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5839 | |
| 5840 | @Override |
| 5841 | public void setAllowAppSwitches(@NonNull String type, int uid, int userId) { |
| 5842 | if (!mAmInternal.isUserRunning(userId, ActivityManager.FLAG_OR_STOPPED)) { |
| 5843 | return; |
| 5844 | } |
| 5845 | synchronized (mGlobalLock) { |
| 5846 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(userId); |
| 5847 | if (types == null) { |
| 5848 | if (uid < 0) { |
| 5849 | return; |
| 5850 | } |
| 5851 | types = new ArrayMap<>(); |
| 5852 | mAllowAppSwitchUids.put(userId, types); |
| 5853 | } |
| 5854 | if (uid < 0) { |
| 5855 | types.remove(type); |
| 5856 | } else { |
| 5857 | types.put(type, uid); |
| 5858 | } |
| 5859 | } |
| 5860 | } |
| 5861 | |
| 5862 | @Override |
| 5863 | public void onUserStopped(int userId) { |
| 5864 | synchronized (mGlobalLock) { |
| 5865 | getRecentTasks().unloadUserDataFromMemoryLocked(userId); |
| 5866 | mAllowAppSwitchUids.remove(userId); |
| 5867 | } |
| 5868 | } |
| 5869 | |
| 5870 | @Override |
| 5871 | public boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 5872 | synchronized (mGlobalLock) { |
| 5873 | return ActivityTaskManagerService.this.isGetTasksAllowed( |
| 5874 | caller, callingPid, callingUid); |
| 5875 | } |
| 5876 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5877 | |
| 5878 | @Override |
| 5879 | public void onProcessAdded(WindowProcessController proc) { |
| 5880 | synchronized (mGlobalLock) { |
| 5881 | mProcessNames.put(proc.mName, proc.mUid, proc); |
| 5882 | } |
| 5883 | } |
| 5884 | |
| 5885 | @Override |
| 5886 | public void onProcessRemoved(String name, int uid) { |
| 5887 | synchronized (mGlobalLock) { |
| 5888 | mProcessNames.remove(name, uid); |
| 5889 | } |
| 5890 | } |
| 5891 | |
| 5892 | @Override |
| 5893 | public void onCleanUpApplicationRecord(WindowProcessController proc) { |
| 5894 | synchronized (mGlobalLock) { |
| 5895 | if (proc == mHomeProcess) { |
| 5896 | mHomeProcess = null; |
| 5897 | } |
| 5898 | if (proc == mPreviousProcess) { |
| 5899 | mPreviousProcess = null; |
| 5900 | } |
| 5901 | } |
| 5902 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5903 | |
| 5904 | @Override |
| 5905 | public int getTopProcessState() { |
| 5906 | synchronized (mGlobalLock) { |
| 5907 | return mTopProcessState; |
| 5908 | } |
| 5909 | } |
| 5910 | |
| 5911 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5912 | public boolean isHeavyWeightProcess(WindowProcessController proc) { |
| 5913 | synchronized (mGlobalLock) { |
| 5914 | return proc == mHeavyWeightProcess; |
| 5915 | } |
| 5916 | } |
| 5917 | |
| 5918 | @Override |
| 5919 | public void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
| 5920 | synchronized (mGlobalLock) { |
| 5921 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals(proc); |
| 5922 | } |
| 5923 | } |
| 5924 | |
| 5925 | @Override |
| 5926 | public void finishHeavyWeightApp() { |
| 5927 | synchronized (mGlobalLock) { |
Sudheer Shanka | ee1da27 | 2018-10-20 20:11:44 -0700 | [diff] [blame] | 5928 | if (mHeavyWeightProcess != null) { |
| 5929 | mHeavyWeightProcess.finishActivities(); |
| 5930 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5931 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals( |
| 5932 | mHeavyWeightProcess); |
| 5933 | } |
| 5934 | } |
| 5935 | |
| 5936 | @Override |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5937 | public boolean isSleeping() { |
| 5938 | synchronized (mGlobalLock) { |
| 5939 | return isSleepingLocked(); |
| 5940 | } |
| 5941 | } |
| 5942 | |
| 5943 | @Override |
| 5944 | public boolean isShuttingDown() { |
| 5945 | synchronized (mGlobalLock) { |
| 5946 | return mShuttingDown; |
| 5947 | } |
| 5948 | } |
| 5949 | |
| 5950 | @Override |
| 5951 | public boolean shuttingDown(boolean booted, int timeout) { |
| 5952 | synchronized (mGlobalLock) { |
| 5953 | mShuttingDown = true; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5954 | mRootActivityContainer.prepareForShutdown(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5955 | updateEventDispatchingLocked(booted); |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 5956 | notifyTaskPersisterLocked(null, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5957 | return mStackSupervisor.shutdownLocked(timeout); |
| 5958 | } |
| 5959 | } |
| 5960 | |
| 5961 | @Override |
| 5962 | public void enableScreenAfterBoot(boolean booted) { |
| 5963 | synchronized (mGlobalLock) { |
| 5964 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_ENABLE_SCREEN, |
| 5965 | SystemClock.uptimeMillis()); |
| 5966 | mWindowManager.enableScreenAfterBoot(); |
| 5967 | updateEventDispatchingLocked(booted); |
| 5968 | } |
| 5969 | } |
| 5970 | |
| 5971 | @Override |
| 5972 | public boolean showStrictModeViolationDialog() { |
| 5973 | synchronized (mGlobalLock) { |
| 5974 | return mShowDialogs && !mSleeping && !mShuttingDown; |
| 5975 | } |
| 5976 | } |
| 5977 | |
| 5978 | @Override |
| 5979 | public void showSystemReadyErrorDialogsIfNeeded() { |
| 5980 | synchronized (mGlobalLock) { |
| 5981 | try { |
| 5982 | if (AppGlobals.getPackageManager().hasSystemUidErrors()) { |
| 5983 | Slog.e(TAG, "UIDs on the system are inconsistent, you need to wipe your" |
| 5984 | + " data partition or your device will be unstable."); |
| 5985 | mUiHandler.post(() -> { |
| 5986 | if (mShowDialogs) { |
| 5987 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 5988 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 5989 | d.setCancelable(false); |
| 5990 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 5991 | d.setMessage(mUiContext.getText(R.string.system_error_wipe_data)); |
| 5992 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 5993 | mUiContext.getText(R.string.ok), |
| 5994 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 5995 | d.show(); |
| 5996 | } |
| 5997 | }); |
| 5998 | } |
| 5999 | } catch (RemoteException e) { |
| 6000 | } |
| 6001 | |
| 6002 | if (!Build.isBuildConsistent()) { |
| 6003 | Slog.e(TAG, "Build fingerprint is not consistent, warning user"); |
| 6004 | mUiHandler.post(() -> { |
| 6005 | if (mShowDialogs) { |
| 6006 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6007 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6008 | d.setCancelable(false); |
| 6009 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6010 | d.setMessage(mUiContext.getText(R.string.system_error_manufacturer)); |
| 6011 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6012 | mUiContext.getText(R.string.ok), |
| 6013 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6014 | d.show(); |
| 6015 | } |
| 6016 | }); |
| 6017 | } |
| 6018 | } |
| 6019 | } |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6020 | |
| 6021 | @Override |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6022 | public void onProcessMapped(int pid, WindowProcessController proc) { |
| 6023 | synchronized (mGlobalLock) { |
| 6024 | mPidMap.put(pid, proc); |
| 6025 | } |
| 6026 | } |
| 6027 | |
| 6028 | @Override |
| 6029 | public void onProcessUnMapped(int pid) { |
| 6030 | synchronized (mGlobalLock) { |
| 6031 | mPidMap.remove(pid); |
| 6032 | } |
| 6033 | } |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6034 | |
| 6035 | @Override |
| 6036 | public void onPackageDataCleared(String name) { |
| 6037 | synchronized (mGlobalLock) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6038 | mCompatModePackages.handlePackageDataClearedLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6039 | mAppWarnings.onPackageDataCleared(name); |
| 6040 | } |
| 6041 | } |
| 6042 | |
| 6043 | @Override |
| 6044 | public void onPackageUninstalled(String name) { |
| 6045 | synchronized (mGlobalLock) { |
| 6046 | mAppWarnings.onPackageUninstalled(name); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6047 | mCompatModePackages.handlePackageUninstalledLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6048 | } |
| 6049 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6050 | |
| 6051 | @Override |
| 6052 | public void onPackageAdded(String name, boolean replacing) { |
| 6053 | synchronized (mGlobalLock) { |
| 6054 | mCompatModePackages.handlePackageAddedLocked(name, replacing); |
| 6055 | } |
| 6056 | } |
| 6057 | |
| 6058 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6059 | public void onPackageReplaced(ApplicationInfo aInfo) { |
| 6060 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6061 | mRootActivityContainer.updateActivityApplicationInfo(aInfo); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6062 | } |
| 6063 | } |
| 6064 | |
| 6065 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6066 | public CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai) { |
| 6067 | synchronized (mGlobalLock) { |
| 6068 | return compatibilityInfoForPackageLocked(ai); |
| 6069 | } |
| 6070 | } |
| 6071 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6072 | /** |
| 6073 | * Set the corresponding display information for the process global configuration. To be |
| 6074 | * called when we need to show IME on a different display. |
| 6075 | * |
| 6076 | * @param pid The process id associated with the IME window. |
| 6077 | * @param displayId The ID of the display showing the IME. |
| 6078 | */ |
| 6079 | @Override |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6080 | public void onImeWindowSetOnDisplay(final int pid, final int displayId) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6081 | if (pid == MY_PID || pid < 0) { |
| 6082 | if (DEBUG_CONFIGURATION) { |
| 6083 | Slog.w(TAG, |
| 6084 | "Trying to update display configuration for system/invalid process."); |
| 6085 | } |
| 6086 | return; |
| 6087 | } |
| 6088 | mH.post(() -> { |
| 6089 | synchronized (mGlobalLock) { |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6090 | final ActivityDisplay activityDisplay = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6091 | mRootActivityContainer.getActivityDisplay(displayId); |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6092 | if (activityDisplay == null) { |
| 6093 | // Call might come when display is not yet added or has been removed. |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6094 | if (DEBUG_CONFIGURATION) { |
| 6095 | Slog.w(TAG, "Trying to update display configuration for non-existing " |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6096 | + "displayId=" + displayId); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6097 | } |
| 6098 | return; |
| 6099 | } |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6100 | final WindowProcessController process = mPidMap.get(pid); |
| 6101 | if (process == null) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6102 | if (DEBUG_CONFIGURATION) { |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6103 | Slog.w(TAG, "Trying to update display configuration for invalid " |
| 6104 | + "process, pid=" + pid); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6105 | } |
| 6106 | return; |
| 6107 | } |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6108 | process.registerDisplayConfigurationListenerLocked(activityDisplay); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6109 | } |
| 6110 | }); |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6111 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6112 | } |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6113 | |
| 6114 | @Override |
| 6115 | public void sendActivityResult(int callingUid, IBinder activityToken, String resultWho, |
| 6116 | int requestCode, int resultCode, Intent data) { |
| 6117 | synchronized (mGlobalLock) { |
| 6118 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 6119 | if (r != null && r.getStack() != null) { |
| 6120 | r.getStack().sendActivityResultLocked(callingUid, r, resultWho, requestCode, |
| 6121 | resultCode, data); |
| 6122 | } |
| 6123 | } |
| 6124 | } |
| 6125 | |
| 6126 | @Override |
| 6127 | public void clearPendingResultForActivity(IBinder activityToken, |
| 6128 | WeakReference<PendingIntentRecord> pir) { |
| 6129 | synchronized (mGlobalLock) { |
| 6130 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 6131 | if (r != null && r.pendingResults != null) { |
| 6132 | r.pendingResults.remove(pir); |
| 6133 | } |
| 6134 | } |
| 6135 | } |
| 6136 | |
| 6137 | @Override |
| 6138 | public IIntentSender getIntentSender(int type, String packageName, |
| 6139 | int callingUid, int userId, IBinder token, String resultWho, |
| 6140 | int requestCode, Intent[] intents, String[] resolvedTypes, int flags, |
| 6141 | Bundle bOptions) { |
| 6142 | synchronized (mGlobalLock) { |
| 6143 | return getIntentSenderLocked(type, packageName, callingUid, userId, token, |
| 6144 | resultWho, requestCode, intents, resolvedTypes, flags, bOptions); |
| 6145 | } |
| 6146 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 6147 | |
| 6148 | @Override |
| 6149 | public ActivityServiceConnectionsHolder getServiceConnectionsHolder(IBinder token) { |
| 6150 | synchronized (mGlobalLock) { |
| 6151 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 6152 | if (r == null) { |
| 6153 | return null; |
| 6154 | } |
| 6155 | if (r.mServiceConnectionsHolder == null) { |
| 6156 | r.mServiceConnectionsHolder = new ActivityServiceConnectionsHolder( |
| 6157 | ActivityTaskManagerService.this, r); |
| 6158 | } |
| 6159 | |
| 6160 | return r.mServiceConnectionsHolder; |
| 6161 | } |
| 6162 | } |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6163 | |
| 6164 | @Override |
| 6165 | public Intent getHomeIntent() { |
| 6166 | synchronized (mGlobalLock) { |
| 6167 | return ActivityTaskManagerService.this.getHomeIntent(); |
| 6168 | } |
| 6169 | } |
| 6170 | |
| 6171 | @Override |
| 6172 | public boolean startHomeActivity(int userId, String reason) { |
| 6173 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6174 | return mRootActivityContainer.startHomeOnDisplay(userId, reason, DEFAULT_DISPLAY); |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6175 | } |
| 6176 | } |
| 6177 | |
| 6178 | @Override |
| 6179 | public boolean startHomeOnAllDisplays(int userId, String reason) { |
| 6180 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6181 | return mRootActivityContainer.startHomeOnAllDisplays(userId, reason); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6182 | } |
| 6183 | } |
| 6184 | |
| 6185 | @Override |
| 6186 | public boolean isFactoryTestProcess(WindowProcessController wpc) { |
| 6187 | synchronized (mGlobalLock) { |
| 6188 | if (mFactoryTest == FACTORY_TEST_OFF) { |
| 6189 | return false; |
| 6190 | } |
| 6191 | if (mFactoryTest == FACTORY_TEST_LOW_LEVEL && mTopComponent != null |
| 6192 | && wpc.mName.equals(mTopComponent.getPackageName())) { |
| 6193 | return true; |
| 6194 | } |
| 6195 | return mFactoryTest == FACTORY_TEST_HIGH_LEVEL |
| 6196 | && (wpc.mInfo.flags & FLAG_FACTORY_TEST) != 0; |
| 6197 | } |
| 6198 | } |
| 6199 | |
| 6200 | @Override |
| 6201 | public void updateTopComponentForFactoryTest() { |
| 6202 | synchronized (mGlobalLock) { |
| 6203 | if (mFactoryTest != FACTORY_TEST_LOW_LEVEL) { |
| 6204 | return; |
| 6205 | } |
| 6206 | final ResolveInfo ri = mContext.getPackageManager() |
| 6207 | .resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST), STOCK_PM_FLAGS); |
| 6208 | final CharSequence errorMsg; |
| 6209 | if (ri != null) { |
| 6210 | final ActivityInfo ai = ri.activityInfo; |
| 6211 | final ApplicationInfo app = ai.applicationInfo; |
| 6212 | if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 6213 | mTopAction = Intent.ACTION_FACTORY_TEST; |
| 6214 | mTopData = null; |
| 6215 | mTopComponent = new ComponentName(app.packageName, ai.name); |
| 6216 | errorMsg = null; |
| 6217 | } else { |
| 6218 | errorMsg = mContext.getResources().getText( |
| 6219 | com.android.internal.R.string.factorytest_not_system); |
| 6220 | } |
| 6221 | } else { |
| 6222 | errorMsg = mContext.getResources().getText( |
| 6223 | com.android.internal.R.string.factorytest_no_action); |
| 6224 | } |
| 6225 | if (errorMsg == null) { |
| 6226 | return; |
| 6227 | } |
| 6228 | |
| 6229 | mTopAction = null; |
| 6230 | mTopData = null; |
| 6231 | mTopComponent = null; |
| 6232 | mUiHandler.post(() -> { |
| 6233 | Dialog d = new FactoryErrorDialog(mUiContext, errorMsg); |
| 6234 | d.show(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 6235 | mAmInternal.ensureBootCompleted(); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6236 | }); |
| 6237 | } |
| 6238 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6239 | |
| 6240 | @Override |
| 6241 | public void handleAppDied(WindowProcessController wpc, boolean restarting, |
| 6242 | Runnable finishInstrumentationCallback) { |
| 6243 | synchronized (mGlobalLock) { |
| 6244 | // Remove this application's activities from active lists. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6245 | boolean hasVisibleActivities = mRootActivityContainer.handleAppDied(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6246 | |
| 6247 | wpc.clearRecentTasks(); |
| 6248 | wpc.clearActivities(); |
| 6249 | |
| 6250 | if (wpc.isInstrumenting()) { |
| 6251 | finishInstrumentationCallback.run(); |
| 6252 | } |
| 6253 | |
| 6254 | mWindowManager.deferSurfaceLayout(); |
| 6255 | try { |
| 6256 | if (!restarting && hasVisibleActivities |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6257 | && !mRootActivityContainer.resumeFocusedStacksTopActivities()) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6258 | // If there was nothing to resume, and we are not already restarting this |
| 6259 | // process, but there is a visible activity that is hosted by the process... |
| 6260 | // then make sure all visible activities are running, taking care of |
| 6261 | // restarting this process. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6262 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6263 | } |
| 6264 | } finally { |
| 6265 | mWindowManager.continueSurfaceLayout(); |
| 6266 | } |
| 6267 | } |
| 6268 | } |
| 6269 | |
| 6270 | @Override |
| 6271 | public void closeSystemDialogs(String reason) { |
| 6272 | enforceNotIsolatedCaller("closeSystemDialogs"); |
| 6273 | |
| 6274 | final int pid = Binder.getCallingPid(); |
| 6275 | final int uid = Binder.getCallingUid(); |
| 6276 | final long origId = Binder.clearCallingIdentity(); |
| 6277 | try { |
| 6278 | synchronized (mGlobalLock) { |
| 6279 | // Only allow this from foreground processes, so that background |
| 6280 | // applications can't abuse it to prevent system UI from being shown. |
| 6281 | if (uid >= FIRST_APPLICATION_UID) { |
| 6282 | final WindowProcessController proc = mPidMap.get(pid); |
| 6283 | if (!proc.isPerceptible()) { |
| 6284 | Slog.w(TAG, "Ignoring closeSystemDialogs " + reason |
| 6285 | + " from background process " + proc); |
| 6286 | return; |
| 6287 | } |
| 6288 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6289 | mWindowManager.closeSystemDialogs(reason); |
| 6290 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6291 | mRootActivityContainer.closeSystemDialogs(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6292 | } |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 6293 | // Call into AM outside the synchronized block. |
| 6294 | mAmInternal.broadcastCloseSystemDialogs(reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6295 | } finally { |
| 6296 | Binder.restoreCallingIdentity(origId); |
| 6297 | } |
| 6298 | } |
| 6299 | |
| 6300 | @Override |
| 6301 | public void cleanupDisabledPackageComponents( |
| 6302 | String packageName, Set<String> disabledClasses, int userId, boolean booted) { |
| 6303 | synchronized (mGlobalLock) { |
| 6304 | // Clean-up disabled activities. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6305 | if (mRootActivityContainer.finishDisabledPackageActivities( |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6306 | packageName, disabledClasses, true, false, userId) && booted) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6307 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6308 | mStackSupervisor.scheduleIdleLocked(); |
| 6309 | } |
| 6310 | |
| 6311 | // Clean-up disabled tasks |
| 6312 | getRecentTasks().cleanupDisabledPackageTasksLocked( |
| 6313 | packageName, disabledClasses, userId); |
| 6314 | } |
| 6315 | } |
| 6316 | |
| 6317 | @Override |
| 6318 | public boolean onForceStopPackage(String packageName, boolean doit, boolean evenPersistent, |
| 6319 | int userId) { |
| 6320 | synchronized (mGlobalLock) { |
| 6321 | |
| 6322 | boolean didSomething = |
| 6323 | getActivityStartController().clearPendingActivityLaunches(packageName); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6324 | didSomething |= mRootActivityContainer.finishDisabledPackageActivities(packageName, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6325 | null, doit, evenPersistent, userId); |
| 6326 | return didSomething; |
| 6327 | } |
| 6328 | } |
| 6329 | |
| 6330 | @Override |
| 6331 | public void resumeTopActivities(boolean scheduleIdle) { |
| 6332 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6333 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6334 | if (scheduleIdle) { |
| 6335 | mStackSupervisor.scheduleIdleLocked(); |
| 6336 | } |
| 6337 | } |
| 6338 | } |
| 6339 | |
| 6340 | @Override |
| 6341 | public void preBindApplication(WindowProcessController wpc) { |
| 6342 | synchronized (mGlobalLock) { |
| 6343 | mStackSupervisor.getActivityMetricsLogger().notifyBindApplication(wpc.mInfo); |
| 6344 | } |
| 6345 | } |
| 6346 | |
| 6347 | @Override |
| 6348 | public boolean attachApplication(WindowProcessController wpc) throws RemoteException { |
| 6349 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6350 | return mRootActivityContainer.attachApplication(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6351 | } |
| 6352 | } |
| 6353 | |
| 6354 | @Override |
| 6355 | public void notifyLockedProfile(@UserIdInt int userId, int currentUserId) { |
| 6356 | try { |
| 6357 | if (!AppGlobals.getPackageManager().isUidPrivileged(Binder.getCallingUid())) { |
| 6358 | throw new SecurityException("Only privileged app can call notifyLockedProfile"); |
| 6359 | } |
| 6360 | } catch (RemoteException ex) { |
| 6361 | throw new SecurityException("Fail to check is caller a privileged app", ex); |
| 6362 | } |
| 6363 | |
| 6364 | synchronized (mGlobalLock) { |
| 6365 | final long ident = Binder.clearCallingIdentity(); |
| 6366 | try { |
| 6367 | if (mAmInternal.shouldConfirmCredentials(userId)) { |
| 6368 | if (mKeyguardController.isKeyguardLocked()) { |
| 6369 | // Showing launcher to avoid user entering credential twice. |
| 6370 | startHomeActivity(currentUserId, "notifyLockedProfile"); |
| 6371 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6372 | mRootActivityContainer.lockAllProfileTasks(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6373 | } |
| 6374 | } finally { |
| 6375 | Binder.restoreCallingIdentity(ident); |
| 6376 | } |
| 6377 | } |
| 6378 | } |
| 6379 | |
| 6380 | @Override |
| 6381 | public void startConfirmDeviceCredentialIntent(Intent intent, Bundle options) { |
| 6382 | mAmInternal.enforceCallingPermission( |
| 6383 | MANAGE_ACTIVITY_STACKS, "startConfirmDeviceCredentialIntent"); |
| 6384 | |
| 6385 | synchronized (mGlobalLock) { |
| 6386 | final long ident = Binder.clearCallingIdentity(); |
| 6387 | try { |
| 6388 | intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | |
| 6389 | FLAG_ACTIVITY_TASK_ON_HOME); |
| 6390 | ActivityOptions activityOptions = options != null |
| 6391 | ? new ActivityOptions(options) : ActivityOptions.makeBasic(); |
Martijn Coenen | 2a5c839 | 2018-10-01 10:17:06 +0200 | [diff] [blame] | 6392 | final ActivityRecord homeActivity = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6393 | mRootActivityContainer.getDefaultDisplayHomeActivity(); |
Martijn Coenen | 2a5c839 | 2018-10-01 10:17:06 +0200 | [diff] [blame] | 6394 | if (homeActivity != null) { |
| 6395 | activityOptions.setLaunchTaskId(homeActivity.getTask().taskId); |
| 6396 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6397 | mContext.startActivityAsUser(intent, activityOptions.toBundle(), |
| 6398 | UserHandle.CURRENT); |
| 6399 | } finally { |
| 6400 | Binder.restoreCallingIdentity(ident); |
| 6401 | } |
| 6402 | } |
| 6403 | } |
| 6404 | |
| 6405 | @Override |
| 6406 | public void writeActivitiesToProto(ProtoOutputStream proto) { |
| 6407 | synchronized (mGlobalLock) { |
| 6408 | // The output proto of "activity --proto activities" |
| 6409 | // is ActivityManagerServiceDumpActivitiesProto |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6410 | mRootActivityContainer.writeToProto(proto, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6411 | ActivityManagerServiceDumpActivitiesProto.ACTIVITY_STACK_SUPERVISOR); |
| 6412 | } |
| 6413 | } |
| 6414 | |
| 6415 | @Override |
| 6416 | public void saveANRState(String reason) { |
| 6417 | synchronized (mGlobalLock) { |
| 6418 | final StringWriter sw = new StringWriter(); |
| 6419 | final PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
| 6420 | pw.println(" ANR time: " + DateFormat.getDateTimeInstance().format(new Date())); |
| 6421 | if (reason != null) { |
| 6422 | pw.println(" Reason: " + reason); |
| 6423 | } |
| 6424 | pw.println(); |
| 6425 | getActivityStartController().dump(pw, " ", null); |
| 6426 | pw.println(); |
| 6427 | pw.println("-------------------------------------------------------------------------------"); |
| 6428 | dumpActivitiesLocked(null /* fd */, pw, null /* args */, 0 /* opti */, |
| 6429 | true /* dumpAll */, false /* dumpClient */, null /* dumpPackage */, |
| 6430 | "" /* header */); |
| 6431 | pw.println(); |
| 6432 | pw.close(); |
| 6433 | |
| 6434 | mLastANRState = sw.toString(); |
| 6435 | } |
| 6436 | } |
| 6437 | |
| 6438 | @Override |
| 6439 | public void clearSavedANRState() { |
| 6440 | synchronized (mGlobalLock) { |
| 6441 | mLastANRState = null; |
| 6442 | } |
| 6443 | } |
| 6444 | |
| 6445 | @Override |
| 6446 | public void dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args, int opti, |
| 6447 | boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 6448 | synchronized (mGlobalLock) { |
| 6449 | if (DUMP_ACTIVITIES_CMD.equals(cmd) || DUMP_ACTIVITIES_SHORT_CMD.equals(cmd)) { |
| 6450 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage); |
| 6451 | } else if (DUMP_LASTANR_CMD.equals(cmd)) { |
| 6452 | dumpLastANRLocked(pw); |
| 6453 | } else if (DUMP_LASTANR_TRACES_CMD.equals(cmd)) { |
| 6454 | dumpLastANRTracesLocked(pw); |
| 6455 | } else if (DUMP_STARTER_CMD.equals(cmd)) { |
| 6456 | dumpActivityStarterLocked(pw, dumpPackage); |
| 6457 | } else if (DUMP_CONTAINERS_CMD.equals(cmd)) { |
| 6458 | dumpActivityContainersLocked(pw); |
| 6459 | } else if (DUMP_RECENTS_CMD.equals(cmd) || DUMP_RECENTS_SHORT_CMD.equals(cmd)) { |
| 6460 | if (getRecentTasks() != null) { |
| 6461 | getRecentTasks().dump(pw, dumpAll, dumpPackage); |
| 6462 | } |
| 6463 | } |
| 6464 | } |
| 6465 | } |
| 6466 | |
| 6467 | @Override |
| 6468 | public boolean dumpForProcesses(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 6469 | String dumpPackage, int dumpAppId, boolean needSep, boolean testPssMode, |
| 6470 | int wakefulness) { |
| 6471 | synchronized (mGlobalLock) { |
| 6472 | if (mHomeProcess != null && (dumpPackage == null |
| 6473 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
| 6474 | if (needSep) { |
| 6475 | pw.println(); |
| 6476 | needSep = false; |
| 6477 | } |
| 6478 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 6479 | } |
| 6480 | if (mPreviousProcess != null && (dumpPackage == null |
| 6481 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 6482 | if (needSep) { |
| 6483 | pw.println(); |
| 6484 | needSep = false; |
| 6485 | } |
| 6486 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 6487 | } |
| 6488 | if (dumpAll && (mPreviousProcess == null || dumpPackage == null |
| 6489 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 6490 | StringBuilder sb = new StringBuilder(128); |
| 6491 | sb.append(" mPreviousProcessVisibleTime: "); |
| 6492 | TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb); |
| 6493 | pw.println(sb); |
| 6494 | } |
| 6495 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 6496 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
| 6497 | if (needSep) { |
| 6498 | pw.println(); |
| 6499 | needSep = false; |
| 6500 | } |
| 6501 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 6502 | } |
| 6503 | if (dumpPackage == null) { |
| 6504 | pw.println(" mGlobalConfiguration: " + getGlobalConfiguration()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6505 | mRootActivityContainer.dumpDisplayConfigs(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6506 | } |
| 6507 | if (dumpAll) { |
| 6508 | if (dumpPackage == null) { |
| 6509 | pw.println(" mConfigWillChange: " |
| 6510 | + getTopDisplayFocusedStack().mConfigWillChange); |
| 6511 | } |
| 6512 | if (mCompatModePackages.getPackages().size() > 0) { |
| 6513 | boolean printed = false; |
| 6514 | for (Map.Entry<String, Integer> entry |
| 6515 | : mCompatModePackages.getPackages().entrySet()) { |
| 6516 | String pkg = entry.getKey(); |
| 6517 | int mode = entry.getValue(); |
| 6518 | if (dumpPackage != null && !dumpPackage.equals(pkg)) { |
| 6519 | continue; |
| 6520 | } |
| 6521 | if (!printed) { |
| 6522 | pw.println(" mScreenCompatPackages:"); |
| 6523 | printed = true; |
| 6524 | } |
| 6525 | pw.println(" " + pkg + ": " + mode); |
| 6526 | } |
| 6527 | } |
| 6528 | } |
| 6529 | |
| 6530 | if (dumpPackage == null) { |
| 6531 | pw.println(" mWakefulness=" |
| 6532 | + PowerManagerInternal.wakefulnessToString(wakefulness)); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6533 | pw.println(" mSleepTokens=" + mRootActivityContainer.mSleepTokens); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6534 | if (mRunningVoice != null) { |
| 6535 | pw.println(" mRunningVoice=" + mRunningVoice); |
| 6536 | pw.println(" mVoiceWakeLock" + mVoiceWakeLock); |
| 6537 | } |
| 6538 | pw.println(" mSleeping=" + mSleeping); |
| 6539 | pw.println(" mShuttingDown=" + mShuttingDown + " mTestPssMode=" + testPssMode); |
| 6540 | pw.println(" mVrController=" + mVrController); |
| 6541 | } |
| 6542 | if (mCurAppTimeTracker != null) { |
| 6543 | mCurAppTimeTracker.dumpWithHeader(pw, " ", true); |
| 6544 | } |
| 6545 | if (mAllowAppSwitchUids.size() > 0) { |
| 6546 | boolean printed = false; |
| 6547 | for (int i = 0; i < mAllowAppSwitchUids.size(); i++) { |
| 6548 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.valueAt(i); |
| 6549 | for (int j = 0; j < types.size(); j++) { |
| 6550 | if (dumpPackage == null || |
| 6551 | UserHandle.getAppId(types.valueAt(j).intValue()) == dumpAppId) { |
| 6552 | if (needSep) { |
| 6553 | pw.println(); |
| 6554 | needSep = false; |
| 6555 | } |
| 6556 | if (!printed) { |
| 6557 | pw.println(" mAllowAppSwitchUids:"); |
| 6558 | printed = true; |
| 6559 | } |
| 6560 | pw.print(" User "); |
| 6561 | pw.print(mAllowAppSwitchUids.keyAt(i)); |
| 6562 | pw.print(": Type "); |
| 6563 | pw.print(types.keyAt(j)); |
| 6564 | pw.print(" = "); |
| 6565 | UserHandle.formatUid(pw, types.valueAt(j).intValue()); |
| 6566 | pw.println(); |
| 6567 | } |
| 6568 | } |
| 6569 | } |
| 6570 | } |
| 6571 | if (dumpPackage == null) { |
| 6572 | if (mController != null) { |
| 6573 | pw.println(" mController=" + mController |
| 6574 | + " mControllerIsAMonkey=" + mControllerIsAMonkey); |
| 6575 | } |
| 6576 | pw.println(" mGoingToSleep=" + mStackSupervisor.mGoingToSleep); |
| 6577 | pw.println(" mLaunchingActivity=" + mStackSupervisor.mLaunchingActivity); |
| 6578 | } |
| 6579 | |
| 6580 | return needSep; |
| 6581 | } |
| 6582 | } |
| 6583 | |
| 6584 | @Override |
| 6585 | public void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage) { |
| 6586 | synchronized (mGlobalLock) { |
| 6587 | if (dumpPackage == null) { |
| 6588 | getGlobalConfiguration().writeToProto(proto, GLOBAL_CONFIGURATION); |
| 6589 | proto.write(CONFIG_WILL_CHANGE, getTopDisplayFocusedStack().mConfigWillChange); |
| 6590 | writeSleepStateToProto(proto); |
| 6591 | if (mController != null) { |
| 6592 | final long token = proto.start(CONTROLLER); |
| 6593 | proto.write(CONTROLLER, mController.toString()); |
| 6594 | proto.write(IS_A_MONKEY, mControllerIsAMonkey); |
| 6595 | proto.end(token); |
| 6596 | } |
| 6597 | mStackSupervisor.mGoingToSleep.writeToProto(proto, GOING_TO_SLEEP); |
| 6598 | mStackSupervisor.mLaunchingActivity.writeToProto(proto, LAUNCHING_ACTIVITY); |
| 6599 | } |
| 6600 | |
| 6601 | if (mHomeProcess != null && (dumpPackage == null |
| 6602 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 6603 | mHomeProcess.writeToProto(proto, HOME_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6604 | } |
| 6605 | |
| 6606 | if (mPreviousProcess != null && (dumpPackage == null |
| 6607 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 6608 | mPreviousProcess.writeToProto(proto, PREVIOUS_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6609 | proto.write(PREVIOUS_PROC_VISIBLE_TIME_MS, mPreviousProcessVisibleTime); |
| 6610 | } |
| 6611 | |
| 6612 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 6613 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 6614 | mHeavyWeightProcess.writeToProto(proto, HEAVY_WEIGHT_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6615 | } |
| 6616 | |
| 6617 | for (Map.Entry<String, Integer> entry |
| 6618 | : mCompatModePackages.getPackages().entrySet()) { |
| 6619 | String pkg = entry.getKey(); |
| 6620 | int mode = entry.getValue(); |
| 6621 | if (dumpPackage == null || dumpPackage.equals(pkg)) { |
| 6622 | long compatToken = proto.start(SCREEN_COMPAT_PACKAGES); |
| 6623 | proto.write(PACKAGE, pkg); |
| 6624 | proto.write(MODE, mode); |
| 6625 | proto.end(compatToken); |
| 6626 | } |
| 6627 | } |
| 6628 | |
| 6629 | if (mCurAppTimeTracker != null) { |
| 6630 | mCurAppTimeTracker.writeToProto(proto, CURRENT_TRACKER, true); |
| 6631 | } |
| 6632 | |
| 6633 | } |
| 6634 | } |
| 6635 | |
| 6636 | @Override |
| 6637 | public boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, |
| 6638 | String[] args, int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, |
| 6639 | boolean dumpFocusedStackOnly) { |
| 6640 | synchronized (mGlobalLock) { |
| 6641 | return ActivityTaskManagerService.this.dumpActivity(fd, pw, name, args, opti, |
| 6642 | dumpAll, dumpVisibleStacksOnly, dumpFocusedStackOnly); |
| 6643 | } |
| 6644 | } |
| 6645 | |
| 6646 | @Override |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 6647 | public void dumpForOom(PrintWriter pw) { |
| 6648 | synchronized (mGlobalLock) { |
| 6649 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 6650 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 6651 | if (mHeavyWeightProcess != null) { |
| 6652 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 6653 | } |
| 6654 | } |
| 6655 | } |
| 6656 | |
| 6657 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6658 | public boolean canGcNow() { |
| 6659 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6660 | return isSleeping() || mRootActivityContainer.allResumedActivitiesIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6661 | } |
| 6662 | } |
| 6663 | |
| 6664 | @Override |
| 6665 | public WindowProcessController getTopApp() { |
| 6666 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6667 | final ActivityRecord top = mRootActivityContainer.getTopResumedActivity(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6668 | return top != null ? top.app : null; |
| 6669 | } |
| 6670 | } |
| 6671 | |
| 6672 | @Override |
| 6673 | public void rankTaskLayersIfNeeded() { |
| 6674 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6675 | if (mRootActivityContainer != null) { |
| 6676 | mRootActivityContainer.rankTaskLayersIfNeeded(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6677 | } |
| 6678 | } |
| 6679 | } |
| 6680 | |
| 6681 | @Override |
| 6682 | public void scheduleDestroyAllActivities(String reason) { |
| 6683 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6684 | mRootActivityContainer.scheduleDestroyAllActivities(null, reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6685 | } |
| 6686 | } |
| 6687 | |
| 6688 | @Override |
| 6689 | public void removeUser(int userId) { |
| 6690 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6691 | mRootActivityContainer.removeUser(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6692 | } |
| 6693 | } |
| 6694 | |
| 6695 | @Override |
| 6696 | public boolean switchUser(int userId, UserState userState) { |
| 6697 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6698 | return mRootActivityContainer.switchUser(userId, userState); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6699 | } |
| 6700 | } |
| 6701 | |
| 6702 | @Override |
| 6703 | public void onHandleAppCrash(WindowProcessController wpc) { |
| 6704 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6705 | mRootActivityContainer.handleAppCrash(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6706 | } |
| 6707 | } |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 6708 | |
| 6709 | @Override |
| 6710 | public int finishTopCrashedActivities(WindowProcessController crashedApp, String reason) { |
| 6711 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6712 | return mRootActivityContainer.finishTopCrashedActivities(crashedApp, reason); |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 6713 | } |
| 6714 | } |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 6715 | |
| 6716 | @Override |
| 6717 | public void onUidActive(int uid, int procState) { |
| 6718 | synchronized (mGlobalLock) { |
| 6719 | mActiveUids.put(uid, procState); |
| 6720 | } |
| 6721 | } |
| 6722 | |
| 6723 | @Override |
| 6724 | public void onUidInactive(int uid) { |
| 6725 | synchronized (mGlobalLock) { |
| 6726 | mActiveUids.remove(uid); |
| 6727 | } |
| 6728 | } |
| 6729 | |
| 6730 | @Override |
| 6731 | public void onActiveUidsCleared() { |
| 6732 | synchronized (mGlobalLock) { |
| 6733 | mActiveUids.clear(); |
| 6734 | } |
| 6735 | } |
| 6736 | |
| 6737 | @Override |
| 6738 | public void onUidProcStateChanged(int uid, int procState) { |
| 6739 | synchronized (mGlobalLock) { |
| 6740 | if (mActiveUids.get(uid) != null) { |
| 6741 | mActiveUids.put(uid, procState); |
| 6742 | } |
| 6743 | } |
| 6744 | } |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 6745 | |
| 6746 | @Override |
| 6747 | public void onUidAddedToPendingTempWhitelist(int uid, String tag) { |
| 6748 | synchronized (mGlobalLock) { |
| 6749 | mPendingTempWhitelist.put(uid, tag); |
| 6750 | } |
| 6751 | } |
| 6752 | |
| 6753 | @Override |
| 6754 | public void onUidRemovedFromPendingTempWhitelist(int uid) { |
| 6755 | synchronized (mGlobalLock) { |
| 6756 | mPendingTempWhitelist.remove(uid); |
| 6757 | } |
| 6758 | } |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 6759 | |
| 6760 | @Override |
| 6761 | public boolean handleAppCrashInActivityController(String processName, int pid, |
| 6762 | String shortMsg, String longMsg, long timeMillis, String stackTrace, |
| 6763 | Runnable killCrashingAppCallback) { |
| 6764 | synchronized (mGlobalLock) { |
| 6765 | if (mController == null) { |
| 6766 | return false; |
| 6767 | } |
| 6768 | |
| 6769 | try { |
| 6770 | if (!mController.appCrashed(processName, pid, shortMsg, longMsg, timeMillis, |
| 6771 | stackTrace)) { |
| 6772 | killCrashingAppCallback.run(); |
| 6773 | return true; |
| 6774 | } |
| 6775 | } catch (RemoteException e) { |
| 6776 | mController = null; |
| 6777 | Watchdog.getInstance().setActivityController(null); |
| 6778 | } |
| 6779 | return false; |
| 6780 | } |
| 6781 | } |
Wale Ogunwale | d7889f5 | 2018-10-25 11:03:20 -0700 | [diff] [blame] | 6782 | |
| 6783 | @Override |
| 6784 | public void removeRecentTasksByPackageName(String packageName, int userId) { |
| 6785 | synchronized (mGlobalLock) { |
| 6786 | mRecentTasks.removeTasksByPackageName(packageName, userId); |
| 6787 | } |
| 6788 | } |
| 6789 | |
| 6790 | @Override |
| 6791 | public void cleanupRecentTasksForUser(int userId) { |
| 6792 | synchronized (mGlobalLock) { |
| 6793 | mRecentTasks.cleanupLocked(userId); |
| 6794 | } |
| 6795 | } |
| 6796 | |
| 6797 | @Override |
| 6798 | public void loadRecentTasksForUser(int userId) { |
| 6799 | synchronized (mGlobalLock) { |
| 6800 | mRecentTasks.loadUserRecentsLocked(userId); |
| 6801 | } |
| 6802 | } |
| 6803 | |
| 6804 | @Override |
| 6805 | public void onPackagesSuspendedChanged(String[] packages, boolean suspended, int userId) { |
| 6806 | synchronized (mGlobalLock) { |
| 6807 | mRecentTasks.onPackagesSuspendedChanged(packages, suspended, userId); |
| 6808 | } |
| 6809 | } |
| 6810 | |
| 6811 | @Override |
| 6812 | public void flushRecentTasks() { |
| 6813 | mRecentTasks.flush(); |
| 6814 | } |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 6815 | |
| 6816 | @Override |
| 6817 | public WindowProcessController getHomeProcess() { |
| 6818 | synchronized (mGlobalLock) { |
| 6819 | return mHomeProcess; |
| 6820 | } |
| 6821 | } |
| 6822 | |
| 6823 | @Override |
| 6824 | public WindowProcessController getPreviousProcess() { |
| 6825 | synchronized (mGlobalLock) { |
| 6826 | return mPreviousProcess; |
| 6827 | } |
| 6828 | } |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 6829 | |
| 6830 | @Override |
| 6831 | public void clearLockedTasks(String reason) { |
| 6832 | synchronized (mGlobalLock) { |
| 6833 | getLockTaskController().clearLockedTasks(reason); |
| 6834 | } |
| 6835 | } |
| 6836 | |
| 6837 | @Override |
| 6838 | public void updateUserConfiguration() { |
| 6839 | synchronized (mGlobalLock) { |
| 6840 | final Configuration configuration = new Configuration(getGlobalConfiguration()); |
| 6841 | final int currentUserId = mAmInternal.getCurrentUserId(); |
| 6842 | Settings.System.adjustConfigurationForUser(mContext.getContentResolver(), |
| 6843 | configuration, currentUserId, Settings.System.canWrite(mContext)); |
| 6844 | updateConfigurationLocked(configuration, null /* starting */, |
| 6845 | false /* initLocale */, false /* persistent */, currentUserId, |
| 6846 | false /* deferResume */); |
| 6847 | } |
| 6848 | } |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 6849 | |
| 6850 | @Override |
| 6851 | public boolean canShowErrorDialogs() { |
| 6852 | synchronized (mGlobalLock) { |
| 6853 | return mShowDialogs && !mSleeping && !mShuttingDown |
| 6854 | && !mKeyguardController.isKeyguardOrAodShowing(DEFAULT_DISPLAY) |
| 6855 | && !hasUserRestriction(UserManager.DISALLOW_SYSTEM_ERROR_DIALOGS, |
| 6856 | mAmInternal.getCurrentUserId()) |
| 6857 | && !(UserManager.isDeviceInDemoMode(mContext) |
| 6858 | && mAmInternal.getCurrentUser().isDemo()); |
| 6859 | } |
| 6860 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 6861 | |
| 6862 | @Override |
| 6863 | public void setProfileApp(String profileApp) { |
| 6864 | synchronized (mGlobalLock) { |
| 6865 | mProfileApp = profileApp; |
| 6866 | } |
| 6867 | } |
| 6868 | |
| 6869 | @Override |
| 6870 | public void setProfileProc(WindowProcessController wpc) { |
| 6871 | synchronized (mGlobalLock) { |
| 6872 | mProfileProc = wpc; |
| 6873 | } |
| 6874 | } |
| 6875 | |
| 6876 | @Override |
| 6877 | public void setProfilerInfo(ProfilerInfo profilerInfo) { |
| 6878 | synchronized (mGlobalLock) { |
| 6879 | mProfilerInfo = profilerInfo; |
| 6880 | } |
| 6881 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6882 | } |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 6883 | } |