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; |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 193 | import android.os.Looper; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 194 | import android.os.Message; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 195 | import android.os.PersistableBundle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 196 | import android.os.PowerManager; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 197 | import android.os.PowerManagerInternal; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 198 | import android.os.RemoteException; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 199 | import android.os.ServiceManager; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 200 | import android.os.StrictMode; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 201 | import android.os.SystemClock; |
| 202 | import android.os.SystemProperties; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 203 | import android.os.Trace; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 204 | import android.os.UpdateLock; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 205 | import android.os.UserHandle; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 206 | import android.os.UserManager; |
| 207 | import android.os.WorkSource; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 208 | import android.os.storage.IStorageManager; |
| 209 | import android.os.storage.StorageManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 210 | import android.provider.Settings; |
| 211 | import android.service.voice.IVoiceInteractionSession; |
| 212 | import android.service.voice.VoiceInteractionManagerInternal; |
| 213 | import android.telecom.TelecomManager; |
| 214 | import android.text.TextUtils; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 215 | import android.text.format.Time; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 216 | import android.util.ArrayMap; |
| 217 | import android.util.EventLog; |
| 218 | import android.util.Log; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 219 | import android.util.Slog; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 220 | import android.util.SparseArray; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 221 | import android.util.SparseIntArray; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 222 | import android.util.StatsLog; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 223 | import android.util.TimeUtils; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 224 | import android.util.proto.ProtoOutputStream; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 225 | import android.view.IRecentsAnimationRunner; |
| 226 | import android.view.RemoteAnimationAdapter; |
| 227 | import android.view.RemoteAnimationDefinition; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 228 | import android.view.WindowManager; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 229 | |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 230 | import com.android.internal.R; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 231 | import com.android.internal.annotations.VisibleForTesting; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 232 | import com.android.internal.app.AssistUtils; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 233 | import com.android.internal.app.IAppOpsService; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 234 | import com.android.internal.app.IVoiceInteractor; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 235 | import com.android.internal.app.ProcessMap; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 236 | import com.android.internal.logging.MetricsLogger; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 237 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 238 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
| 239 | import com.android.internal.notification.SystemNotificationChannels; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 240 | import com.android.internal.os.TransferPipe; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 241 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 242 | import com.android.internal.policy.IKeyguardDismissCallback; |
| 243 | import com.android.internal.policy.KeyguardDismissCallback; |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 244 | import com.android.internal.util.ArrayUtils; |
| 245 | import com.android.internal.util.FastPrintWriter; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 246 | import com.android.internal.util.Preconditions; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 247 | import com.android.internal.util.function.pooled.PooledLambda; |
Evan Rosky | 4505b35 | 2018-09-06 11:20:40 -0700 | [diff] [blame] | 248 | import com.android.server.AppOpsService; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 249 | import com.android.server.AttributeCache; |
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 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 756 | public void initialize(IntentFirewall intentFirewall, PendingIntentController intentController, |
| 757 | Looper looper) { |
| 758 | mH = new H(looper); |
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 |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1445 | final TaskRecord tr = r.getTaskRecord(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 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. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1460 | final ActivityRecord next = r.getActivityStack().topRunningActivityLocked(token, 0); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 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. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1522 | final TaskRecord task = r.getTaskRecord(); |
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 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1825 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 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) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1833 | r.getActivityStack().convertActivityToTranslucent(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 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) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1850 | r.getActivityStack().notifyActivityDrawnLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 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) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1970 | return srec.getActivityStack().shouldUpRecreateTaskLocked(srec, destAffinity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 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) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1983 | return r.getActivityStack().navigateUpToLocked( |
| 1984 | r, destIntent, resultCode, resultData); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1985 | } |
| 1986 | return false; |
| 1987 | } |
| 1988 | } |
| 1989 | |
| 1990 | /** |
| 1991 | * Attempts to move a task backwards in z-order (the order of activities within the task is |
| 1992 | * unchanged). |
| 1993 | * |
| 1994 | * There are several possible results of this call: |
| 1995 | * - if the task is locked, then we will show the lock toast |
| 1996 | * - if there is a task behind the provided task, then that task is made visible and resumed as |
| 1997 | * this task is moved to the back |
| 1998 | * - otherwise, if there are no other tasks in the stack: |
| 1999 | * - if this task is in the pinned stack, then we remove the stack completely, which will |
| 2000 | * have the effect of moving the task to the top or bottom of the fullscreen stack |
| 2001 | * (depending on whether it is visible) |
| 2002 | * - otherwise, we simply return home and hide this task |
| 2003 | * |
| 2004 | * @param token A reference to the activity we wish to move |
| 2005 | * @param nonRoot If false then this only works if the activity is the root |
| 2006 | * of a task; if true it will work for any activity in a task. |
| 2007 | * @return Returns true if the move completed, false if not. |
| 2008 | */ |
| 2009 | @Override |
| 2010 | public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2011 | enforceNotIsolatedCaller("moveActivityTaskToBack"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2012 | synchronized (mGlobalLock) { |
| 2013 | final long origId = Binder.clearCallingIdentity(); |
| 2014 | try { |
| 2015 | int taskId = ActivityRecord.getTaskForActivityLocked(token, !nonRoot); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2016 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2017 | if (task != null) { |
| 2018 | return ActivityRecord.getStackLocked(token).moveTaskToBackLocked(taskId); |
| 2019 | } |
| 2020 | } finally { |
| 2021 | Binder.restoreCallingIdentity(origId); |
| 2022 | } |
| 2023 | } |
| 2024 | return false; |
| 2025 | } |
| 2026 | |
| 2027 | @Override |
| 2028 | public Rect getTaskBounds(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2029 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getTaskBounds()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2030 | long ident = Binder.clearCallingIdentity(); |
| 2031 | Rect rect = new Rect(); |
| 2032 | try { |
| 2033 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2034 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2035 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2036 | if (task == null) { |
| 2037 | Slog.w(TAG, "getTaskBounds: taskId=" + taskId + " not found"); |
| 2038 | return rect; |
| 2039 | } |
| 2040 | if (task.getStack() != null) { |
| 2041 | // Return the bounds from window manager since it will be adjusted for various |
| 2042 | // things like the presense of a docked stack for tasks that aren't resizeable. |
| 2043 | task.getWindowContainerBounds(rect); |
| 2044 | } else { |
| 2045 | // Task isn't in window manager yet since it isn't associated with a stack. |
| 2046 | // Return the persist value from activity manager |
| 2047 | if (!task.matchParentBounds()) { |
| 2048 | rect.set(task.getBounds()); |
| 2049 | } else if (task.mLastNonFullscreenBounds != null) { |
| 2050 | rect.set(task.mLastNonFullscreenBounds); |
| 2051 | } |
| 2052 | } |
| 2053 | } |
| 2054 | } finally { |
| 2055 | Binder.restoreCallingIdentity(ident); |
| 2056 | } |
| 2057 | return rect; |
| 2058 | } |
| 2059 | |
| 2060 | @Override |
| 2061 | public ActivityManager.TaskDescription getTaskDescription(int id) { |
| 2062 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2063 | enforceCallerIsRecentsOrHasPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2064 | MANAGE_ACTIVITY_STACKS, "getTaskDescription()"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2065 | final TaskRecord tr = mRootActivityContainer.anyTaskForId(id, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2066 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2067 | if (tr != null) { |
| 2068 | return tr.lastTaskDescription; |
| 2069 | } |
| 2070 | } |
| 2071 | return null; |
| 2072 | } |
| 2073 | |
| 2074 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2075 | public void setTaskWindowingMode(int taskId, int windowingMode, boolean toTop) { |
| 2076 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 2077 | setTaskWindowingModeSplitScreenPrimary(taskId, SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, |
| 2078 | toTop, ANIMATE, null /* initialBounds */, true /* showRecents */); |
| 2079 | return; |
| 2080 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2081 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setTaskWindowingMode()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2082 | synchronized (mGlobalLock) { |
| 2083 | final long ident = Binder.clearCallingIdentity(); |
| 2084 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2085 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2086 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2087 | if (task == null) { |
| 2088 | Slog.w(TAG, "setTaskWindowingMode: No task for id=" + taskId); |
| 2089 | return; |
| 2090 | } |
| 2091 | |
| 2092 | if (DEBUG_STACK) Slog.d(TAG_STACK, "setTaskWindowingMode: moving task=" + taskId |
| 2093 | + " to windowingMode=" + windowingMode + " toTop=" + toTop); |
| 2094 | |
| 2095 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2096 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2097 | + " non-standard task " + taskId + " to windowing mode=" |
| 2098 | + windowingMode); |
| 2099 | } |
| 2100 | |
| 2101 | final ActivityStack stack = task.getStack(); |
| 2102 | if (toTop) { |
| 2103 | stack.moveToFront("setTaskWindowingMode", task); |
| 2104 | } |
| 2105 | stack.setWindowingMode(windowingMode); |
| 2106 | } finally { |
| 2107 | Binder.restoreCallingIdentity(ident); |
| 2108 | } |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2113 | public String getCallingPackage(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2114 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2115 | ActivityRecord r = getCallingRecordLocked(token); |
| 2116 | return r != null ? r.info.packageName : null; |
| 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | @Override |
| 2121 | public ComponentName getCallingActivity(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2122 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2123 | ActivityRecord r = getCallingRecordLocked(token); |
| 2124 | return r != null ? r.intent.getComponent() : null; |
| 2125 | } |
| 2126 | } |
| 2127 | |
| 2128 | private ActivityRecord getCallingRecordLocked(IBinder token) { |
| 2129 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2130 | if (r == null) { |
| 2131 | return null; |
| 2132 | } |
| 2133 | return r.resultTo; |
| 2134 | } |
| 2135 | |
| 2136 | @Override |
| 2137 | public void unhandledBack() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2138 | mAmInternal.enforceCallingPermission(android.Manifest.permission.FORCE_BACK, "unhandledBack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2139 | |
| 2140 | synchronized (mGlobalLock) { |
| 2141 | final long origId = Binder.clearCallingIdentity(); |
| 2142 | try { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2143 | getTopDisplayFocusedStack().unhandledBackLocked(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2144 | } finally { |
| 2145 | Binder.restoreCallingIdentity(origId); |
| 2146 | } |
| 2147 | } |
| 2148 | } |
| 2149 | |
| 2150 | /** |
| 2151 | * TODO: Add mController hook |
| 2152 | */ |
| 2153 | @Override |
| 2154 | public void moveTaskToFront(int taskId, int flags, Bundle bOptions) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2155 | mAmInternal.enforceCallingPermission(android.Manifest.permission.REORDER_TASKS, "moveTaskToFront()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2156 | |
| 2157 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToFront: moving taskId=" + taskId); |
| 2158 | synchronized (mGlobalLock) { |
| 2159 | moveTaskToFrontLocked(taskId, flags, SafeActivityOptions.fromBundle(bOptions), |
| 2160 | false /* fromRecents */); |
| 2161 | } |
| 2162 | } |
| 2163 | |
| 2164 | void moveTaskToFrontLocked(int taskId, int flags, SafeActivityOptions options, |
| 2165 | boolean fromRecents) { |
| 2166 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2167 | if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(), |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2168 | Binder.getCallingUid(), -1, -1, "Task to front")) { |
| 2169 | SafeActivityOptions.abort(options); |
| 2170 | return; |
| 2171 | } |
| 2172 | final long origId = Binder.clearCallingIdentity(); |
| 2173 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2174 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2175 | if (task == null) { |
| 2176 | Slog.d(TAG, "Could not find task for id: "+ taskId); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2177 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2178 | return; |
| 2179 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2180 | if (getLockTaskController().isLockTaskModeViolation(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2181 | Slog.e(TAG, "moveTaskToFront: Attempt to violate Lock Task Mode"); |
Winson Chung | d024368 | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 2182 | SafeActivityOptions.abort(options); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2183 | return; |
| 2184 | } |
| 2185 | ActivityOptions realOptions = options != null |
| 2186 | ? options.getOptions(mStackSupervisor) |
| 2187 | : null; |
| 2188 | mStackSupervisor.findTaskToMoveToFront(task, flags, realOptions, "moveTaskToFront", |
| 2189 | false /* forceNonResizable */); |
| 2190 | |
| 2191 | final ActivityRecord topActivity = task.getTopActivity(); |
| 2192 | if (topActivity != null) { |
| 2193 | |
| 2194 | // We are reshowing a task, use a starting window to hide the initial draw delay |
| 2195 | // so the transition can start earlier. |
| 2196 | topActivity.showStartingWindow(null /* prev */, false /* newTask */, |
| 2197 | true /* taskSwitch */, fromRecents); |
| 2198 | } |
| 2199 | } finally { |
| 2200 | Binder.restoreCallingIdentity(origId); |
| 2201 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2202 | } |
| 2203 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2204 | boolean checkAppSwitchAllowedLocked(int sourcePid, int sourceUid, |
| 2205 | int callingPid, int callingUid, String name) { |
| 2206 | if (mAppSwitchesAllowedTime < SystemClock.uptimeMillis()) { |
| 2207 | return true; |
| 2208 | } |
| 2209 | |
| 2210 | if (getRecentTasks().isCallerRecents(sourceUid)) { |
| 2211 | return true; |
| 2212 | } |
| 2213 | |
| 2214 | int perm = checkComponentPermission(STOP_APP_SWITCHES, sourcePid, sourceUid, -1, true); |
| 2215 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2216 | return true; |
| 2217 | } |
| 2218 | if (checkAllowAppSwitchUid(sourceUid)) { |
| 2219 | return true; |
| 2220 | } |
| 2221 | |
| 2222 | // If the actual IPC caller is different from the logical source, then |
| 2223 | // also see if they are allowed to control app switches. |
| 2224 | if (callingUid != -1 && callingUid != sourceUid) { |
| 2225 | perm = checkComponentPermission(STOP_APP_SWITCHES, callingPid, callingUid, -1, true); |
| 2226 | if (perm == PackageManager.PERMISSION_GRANTED) { |
| 2227 | return true; |
| 2228 | } |
| 2229 | if (checkAllowAppSwitchUid(callingUid)) { |
| 2230 | return true; |
| 2231 | } |
| 2232 | } |
| 2233 | |
| 2234 | Slog.w(TAG, name + " request from " + sourceUid + " stopped"); |
| 2235 | return false; |
| 2236 | } |
| 2237 | |
| 2238 | private boolean checkAllowAppSwitchUid(int uid) { |
| 2239 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(UserHandle.getUserId(uid)); |
| 2240 | if (types != null) { |
| 2241 | for (int i = types.size() - 1; i >= 0; i--) { |
| 2242 | if (types.valueAt(i).intValue() == uid) { |
| 2243 | return true; |
| 2244 | } |
| 2245 | } |
| 2246 | } |
| 2247 | return false; |
| 2248 | } |
| 2249 | |
| 2250 | @Override |
| 2251 | public void setActivityController(IActivityController controller, boolean imAMonkey) { |
| 2252 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER, |
| 2253 | "setActivityController()"); |
| 2254 | synchronized (mGlobalLock) { |
| 2255 | mController = controller; |
| 2256 | mControllerIsAMonkey = imAMonkey; |
| 2257 | Watchdog.getInstance().setActivityController(controller); |
| 2258 | } |
| 2259 | } |
| 2260 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 2261 | public boolean isControllerAMonkey() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2262 | synchronized (mGlobalLock) { |
| 2263 | return mController != null && mControllerIsAMonkey; |
| 2264 | } |
| 2265 | } |
| 2266 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2267 | @Override |
| 2268 | public int getTaskForActivity(IBinder token, boolean onlyRoot) { |
| 2269 | synchronized (mGlobalLock) { |
| 2270 | return ActivityRecord.getTaskForActivityLocked(token, onlyRoot); |
| 2271 | } |
| 2272 | } |
| 2273 | |
| 2274 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2275 | public List<ActivityManager.RunningTaskInfo> getTasks(int maxNum) { |
| 2276 | return getFilteredTasks(maxNum, ACTIVITY_TYPE_UNDEFINED, WINDOWING_MODE_UNDEFINED); |
| 2277 | } |
| 2278 | |
| 2279 | @Override |
| 2280 | public List<ActivityManager.RunningTaskInfo> getFilteredTasks(int maxNum, |
| 2281 | @WindowConfiguration.ActivityType int ignoreActivityType, |
| 2282 | @WindowConfiguration.WindowingMode int ignoreWindowingMode) { |
| 2283 | final int callingUid = Binder.getCallingUid(); |
| 2284 | ArrayList<ActivityManager.RunningTaskInfo> list = new ArrayList<>(); |
| 2285 | |
| 2286 | synchronized (mGlobalLock) { |
| 2287 | if (DEBUG_ALL) Slog.v(TAG, "getTasks: max=" + maxNum); |
| 2288 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2289 | final boolean allowed = isGetTasksAllowed("getTasks", Binder.getCallingPid(), |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2290 | callingUid); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2291 | mRootActivityContainer.getRunningTasks(maxNum, list, ignoreActivityType, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2292 | ignoreWindowingMode, callingUid, allowed); |
| 2293 | } |
| 2294 | |
| 2295 | return list; |
| 2296 | } |
| 2297 | |
| 2298 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2299 | public final void finishSubActivity(IBinder token, String resultWho, int requestCode) { |
| 2300 | synchronized (mGlobalLock) { |
| 2301 | final long origId = Binder.clearCallingIdentity(); |
| 2302 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2303 | if (r != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2304 | r.getActivityStack().finishSubActivityLocked(r, resultWho, requestCode); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2305 | } |
| 2306 | Binder.restoreCallingIdentity(origId); |
| 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | @Override |
| 2311 | public boolean willActivityBeVisible(IBinder token) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2312 | synchronized (mGlobalLock) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2313 | ActivityStack stack = ActivityRecord.getStackLocked(token); |
| 2314 | if (stack != null) { |
| 2315 | return stack.willActivityBeVisibleLocked(token); |
| 2316 | } |
| 2317 | return false; |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | @Override |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2322 | public void moveTaskToStack(int taskId, int stackId, boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2323 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "moveTaskToStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2324 | synchronized (mGlobalLock) { |
| 2325 | final long ident = Binder.clearCallingIdentity(); |
| 2326 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2327 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2328 | if (task == null) { |
| 2329 | Slog.w(TAG, "moveTaskToStack: No task for id=" + taskId); |
| 2330 | return; |
| 2331 | } |
| 2332 | |
| 2333 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveTaskToStack: moving task=" + taskId |
| 2334 | + " to stackId=" + stackId + " toTop=" + toTop); |
| 2335 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2336 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2337 | if (stack == null) { |
| 2338 | throw new IllegalStateException( |
| 2339 | "moveTaskToStack: No stack for stackId=" + stackId); |
| 2340 | } |
| 2341 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 2342 | throw new IllegalArgumentException("moveTaskToStack: Attempt to move task " |
| 2343 | + taskId + " to stack " + stackId); |
| 2344 | } |
| 2345 | if (stack.inSplitScreenPrimaryWindowingMode()) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2346 | mWindowManager.setDockedStackCreateState( |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2347 | SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */); |
| 2348 | } |
| 2349 | task.reparent(stack, toTop, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, !DEFER_RESUME, |
| 2350 | "moveTaskToStack"); |
| 2351 | } finally { |
| 2352 | Binder.restoreCallingIdentity(ident); |
| 2353 | } |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | @Override |
| 2358 | public void resizeStack(int stackId, Rect destBounds, boolean allowResizeInDockedMode, |
| 2359 | boolean preserveWindows, boolean animate, int animationDuration) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2360 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeStack()"); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2361 | |
| 2362 | final long ident = Binder.clearCallingIdentity(); |
| 2363 | try { |
| 2364 | synchronized (mGlobalLock) { |
| 2365 | if (animate) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2366 | final PinnedActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2367 | if (stack == null) { |
| 2368 | Slog.w(TAG, "resizeStack: stackId " + stackId + " not found."); |
| 2369 | return; |
| 2370 | } |
| 2371 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 2372 | throw new IllegalArgumentException("Stack: " + stackId |
| 2373 | + " doesn't support animated resize."); |
| 2374 | } |
| 2375 | stack.animateResizePinnedStack(null /* sourceHintBounds */, destBounds, |
| 2376 | animationDuration, false /* fromFullscreen */); |
| 2377 | } else { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2378 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2379 | if (stack == null) { |
| 2380 | Slog.w(TAG, "resizeStack: stackId " + stackId + " not found."); |
| 2381 | return; |
| 2382 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2383 | mRootActivityContainer.resizeStack(stack, destBounds, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2384 | null /* tempTaskBounds */, null /* tempTaskInsetBounds */, |
| 2385 | preserveWindows, allowResizeInDockedMode, !DEFER_RESUME); |
| 2386 | } |
| 2387 | } |
| 2388 | } finally { |
| 2389 | Binder.restoreCallingIdentity(ident); |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | /** |
| 2394 | * Moves the specified task to the primary-split-screen stack. |
| 2395 | * |
| 2396 | * @param taskId Id of task to move. |
| 2397 | * @param createMode The mode the primary split screen stack should be created in if it doesn't |
| 2398 | * exist already. See |
| 2399 | * {@link android.app.ActivityTaskManager#SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT} |
| 2400 | * and |
| 2401 | * {@link android.app.ActivityTaskManager#SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT} |
| 2402 | * @param toTop If the task and stack should be moved to the top. |
| 2403 | * @param animate Whether we should play an animation for the moving the task. |
| 2404 | * @param initialBounds If the primary stack gets created, it will use these bounds for the |
| 2405 | * stack. Pass {@code null} to use default bounds. |
| 2406 | * @param showRecents If the recents activity should be shown on the other side of the task |
| 2407 | * going into split-screen mode. |
| 2408 | */ |
| 2409 | @Override |
| 2410 | public boolean setTaskWindowingModeSplitScreenPrimary(int taskId, int createMode, |
| 2411 | boolean toTop, boolean animate, Rect initialBounds, boolean showRecents) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2412 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2413 | "setTaskWindowingModeSplitScreenPrimary()"); |
| 2414 | synchronized (mGlobalLock) { |
| 2415 | final long ident = Binder.clearCallingIdentity(); |
| 2416 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2417 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2418 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2419 | if (task == null) { |
| 2420 | Slog.w(TAG, "setTaskWindowingModeSplitScreenPrimary: No task for id=" + taskId); |
| 2421 | return false; |
| 2422 | } |
| 2423 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
| 2424 | "setTaskWindowingModeSplitScreenPrimary: moving task=" + taskId |
| 2425 | + " to createMode=" + createMode + " toTop=" + toTop); |
| 2426 | if (!task.isActivityTypeStandardOrUndefined()) { |
| 2427 | throw new IllegalArgumentException("setTaskWindowingMode: Attempt to move" |
| 2428 | + " non-standard task " + taskId + " to split-screen windowing mode"); |
| 2429 | } |
| 2430 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2431 | mWindowManager.setDockedStackCreateState(createMode, initialBounds); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2432 | final int windowingMode = task.getWindowingMode(); |
| 2433 | final ActivityStack stack = task.getStack(); |
| 2434 | if (toTop) { |
| 2435 | stack.moveToFront("setTaskWindowingModeSplitScreenPrimary", task); |
| 2436 | } |
| 2437 | stack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, animate, showRecents, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 2438 | false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */, |
| 2439 | false /* creating */); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2440 | return windowingMode != task.getWindowingMode(); |
| 2441 | } finally { |
| 2442 | Binder.restoreCallingIdentity(ident); |
| 2443 | } |
| 2444 | } |
| 2445 | } |
| 2446 | |
| 2447 | /** |
| 2448 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 2449 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 2450 | */ |
| 2451 | @Override |
| 2452 | public void removeStacksInWindowingModes(int[] windowingModes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2453 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2454 | "removeStacksInWindowingModes()"); |
| 2455 | |
| 2456 | synchronized (mGlobalLock) { |
| 2457 | final long ident = Binder.clearCallingIdentity(); |
| 2458 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2459 | mRootActivityContainer.removeStacksInWindowingModes(windowingModes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2460 | } finally { |
| 2461 | Binder.restoreCallingIdentity(ident); |
| 2462 | } |
| 2463 | } |
| 2464 | } |
| 2465 | |
| 2466 | @Override |
| 2467 | public void removeStacksWithActivityTypes(int[] activityTypes) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2468 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2469 | "removeStacksWithActivityTypes()"); |
| 2470 | |
| 2471 | synchronized (mGlobalLock) { |
| 2472 | final long ident = Binder.clearCallingIdentity(); |
| 2473 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2474 | mRootActivityContainer.removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 2475 | } finally { |
| 2476 | Binder.restoreCallingIdentity(ident); |
| 2477 | } |
| 2478 | } |
| 2479 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2480 | |
| 2481 | @Override |
| 2482 | public ParceledListSlice<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags, |
| 2483 | int userId) { |
| 2484 | final int callingUid = Binder.getCallingUid(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2485 | userId = handleIncomingUser(Binder.getCallingPid(), callingUid, userId, "getRecentTasks"); |
| 2486 | final boolean allowed = isGetTasksAllowed("getRecentTasks", Binder.getCallingPid(), |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2487 | callingUid); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2488 | final boolean detailed = checkGetTasksPermission( |
| 2489 | android.Manifest.permission.GET_DETAILED_TASKS, Binder.getCallingPid(), |
| 2490 | UserHandle.getAppId(callingUid)) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2491 | == PackageManager.PERMISSION_GRANTED; |
| 2492 | |
| 2493 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 2494 | return mRecentTasks.getRecentTasks(maxNum, flags, allowed, detailed, userId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2495 | callingUid); |
| 2496 | } |
| 2497 | } |
| 2498 | |
| 2499 | @Override |
| 2500 | public List<ActivityManager.StackInfo> getAllStackInfos() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2501 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2502 | long ident = Binder.clearCallingIdentity(); |
| 2503 | try { |
| 2504 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2505 | return mRootActivityContainer.getAllStackInfos(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2506 | } |
| 2507 | } finally { |
| 2508 | Binder.restoreCallingIdentity(ident); |
| 2509 | } |
| 2510 | } |
| 2511 | |
| 2512 | @Override |
| 2513 | public ActivityManager.StackInfo getStackInfo(int windowingMode, int activityType) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2514 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2515 | long ident = Binder.clearCallingIdentity(); |
| 2516 | try { |
| 2517 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2518 | return mRootActivityContainer.getStackInfo(windowingMode, activityType); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2519 | } |
| 2520 | } finally { |
| 2521 | Binder.restoreCallingIdentity(ident); |
| 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | @Override |
| 2526 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2527 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "cancelRecentsAnimation()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2528 | final long callingUid = Binder.getCallingUid(); |
| 2529 | final long origId = Binder.clearCallingIdentity(); |
| 2530 | try { |
| 2531 | synchronized (mGlobalLock) { |
| 2532 | // Cancel the recents animation synchronously (do not hold the WM lock) |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2533 | mWindowManager.cancelRecentsAnimationSynchronously(restoreHomeStackPosition |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2534 | ? REORDER_MOVE_TO_ORIGINAL_POSITION |
| 2535 | : REORDER_KEEP_IN_PLACE, "cancelRecentsAnimation/uid=" + callingUid); |
| 2536 | } |
| 2537 | } finally { |
| 2538 | Binder.restoreCallingIdentity(origId); |
| 2539 | } |
| 2540 | } |
| 2541 | |
| 2542 | @Override |
| 2543 | public void startLockTaskModeByToken(IBinder token) { |
| 2544 | synchronized (mGlobalLock) { |
| 2545 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2546 | if (r == null) { |
| 2547 | return; |
| 2548 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2549 | startLockTaskModeLocked(r.getTaskRecord(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2550 | } |
| 2551 | } |
| 2552 | |
| 2553 | @Override |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2554 | public void startSystemLockTaskMode(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2555 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "startSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2556 | // This makes inner call to look as if it was initiated by system. |
| 2557 | long ident = Binder.clearCallingIdentity(); |
| 2558 | try { |
| 2559 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2560 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2561 | MATCH_TASK_IN_STACKS_ONLY); |
| 2562 | if (task == null) { |
| 2563 | return; |
| 2564 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2565 | |
| 2566 | // When starting lock task mode the stack must be in front and focused |
| 2567 | task.getStack().moveToFront("startSystemLockTaskMode"); |
| 2568 | startLockTaskModeLocked(task, true /* isSystemCaller */); |
| 2569 | } |
| 2570 | } finally { |
| 2571 | Binder.restoreCallingIdentity(ident); |
| 2572 | } |
| 2573 | } |
| 2574 | |
| 2575 | @Override |
| 2576 | public void stopLockTaskModeByToken(IBinder token) { |
| 2577 | synchronized (mGlobalLock) { |
| 2578 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 2579 | if (r == null) { |
| 2580 | return; |
| 2581 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2582 | stopLockTaskModeInternal(r.getTaskRecord(), false /* isSystemCaller */); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2583 | } |
| 2584 | } |
| 2585 | |
| 2586 | /** |
| 2587 | * This API should be called by SystemUI only when user perform certain action to dismiss |
| 2588 | * lock task mode. We should only dismiss pinned lock task mode in this case. |
| 2589 | */ |
| 2590 | @Override |
| 2591 | public void stopSystemLockTaskMode() throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2592 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "stopSystemLockTaskMode"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2593 | stopLockTaskModeInternal(null, true /* isSystemCaller */); |
| 2594 | } |
| 2595 | |
| 2596 | private void startLockTaskModeLocked(@Nullable TaskRecord task, boolean isSystemCaller) { |
| 2597 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "startLockTaskModeLocked: " + task); |
| 2598 | if (task == null || task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) { |
| 2599 | return; |
| 2600 | } |
| 2601 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2602 | final ActivityStack stack = mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2603 | if (stack == null || task != stack.topTask()) { |
| 2604 | throw new IllegalArgumentException("Invalid task, not in foreground"); |
| 2605 | } |
| 2606 | |
| 2607 | // {@code isSystemCaller} is used to distinguish whether this request is initiated by the |
| 2608 | // system or a specific app. |
| 2609 | // * System-initiated requests will only start the pinned mode (screen pinning) |
| 2610 | // * App-initiated requests |
| 2611 | // - will put the device in fully locked mode (LockTask), if the app is whitelisted |
| 2612 | // - will start the pinned mode, otherwise |
| 2613 | final int callingUid = Binder.getCallingUid(); |
| 2614 | long ident = Binder.clearCallingIdentity(); |
| 2615 | try { |
| 2616 | // When a task is locked, dismiss the pinned stack if it exists |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2617 | mRootActivityContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2618 | |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2619 | getLockTaskController().startLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2620 | } finally { |
| 2621 | Binder.restoreCallingIdentity(ident); |
| 2622 | } |
| 2623 | } |
| 2624 | |
| 2625 | private void stopLockTaskModeInternal(@Nullable TaskRecord task, boolean isSystemCaller) { |
| 2626 | final int callingUid = Binder.getCallingUid(); |
| 2627 | long ident = Binder.clearCallingIdentity(); |
| 2628 | try { |
| 2629 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2630 | getLockTaskController().stopLockTaskMode(task, isSystemCaller, callingUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2631 | } |
| 2632 | // Launch in-call UI if a call is ongoing. This is necessary to allow stopping the lock |
| 2633 | // task and jumping straight into a call in the case of emergency call back. |
| 2634 | TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
| 2635 | if (tm != null) { |
| 2636 | tm.showInCallScreen(false); |
| 2637 | } |
| 2638 | } finally { |
| 2639 | Binder.restoreCallingIdentity(ident); |
| 2640 | } |
| 2641 | } |
| 2642 | |
| 2643 | @Override |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 2644 | public void updateLockTaskPackages(int userId, String[] packages) { |
| 2645 | final int callingUid = Binder.getCallingUid(); |
| 2646 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
| 2647 | mAmInternal.enforceCallingPermission(Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
| 2648 | "updateLockTaskPackages()"); |
| 2649 | } |
| 2650 | synchronized (this) { |
| 2651 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Whitelisting " + userId + ":" |
| 2652 | + Arrays.toString(packages)); |
| 2653 | getLockTaskController().updateLockTaskPackages(userId, packages); |
| 2654 | } |
| 2655 | } |
| 2656 | |
| 2657 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2658 | public boolean isInLockTaskMode() { |
| 2659 | return getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
| 2660 | } |
| 2661 | |
| 2662 | @Override |
| 2663 | public int getLockTaskModeState() { |
| 2664 | synchronized (mGlobalLock) { |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 2665 | return getLockTaskController().getLockTaskModeState(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2666 | } |
| 2667 | } |
| 2668 | |
| 2669 | @Override |
| 2670 | public void setTaskDescription(IBinder token, ActivityManager.TaskDescription td) { |
| 2671 | synchronized (mGlobalLock) { |
| 2672 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2673 | if (r != null) { |
| 2674 | r.setTaskDescription(td); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2675 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2676 | task.updateTaskDescription(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2677 | mTaskChangeNotificationController.notifyTaskDescriptionChanged(task.taskId, td); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2678 | } |
| 2679 | } |
| 2680 | } |
| 2681 | |
| 2682 | @Override |
| 2683 | public Bundle getActivityOptions(IBinder token) { |
| 2684 | final long origId = Binder.clearCallingIdentity(); |
| 2685 | try { |
| 2686 | synchronized (mGlobalLock) { |
| 2687 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2688 | if (r != null) { |
| 2689 | final ActivityOptions activityOptions = r.takeOptionsLocked(); |
| 2690 | return activityOptions == null ? null : activityOptions.toBundle(); |
| 2691 | } |
| 2692 | return null; |
| 2693 | } |
| 2694 | } finally { |
| 2695 | Binder.restoreCallingIdentity(origId); |
| 2696 | } |
| 2697 | } |
| 2698 | |
| 2699 | @Override |
| 2700 | public List<IBinder> getAppTasks(String callingPackage) { |
| 2701 | int callingUid = Binder.getCallingUid(); |
| 2702 | long ident = Binder.clearCallingIdentity(); |
| 2703 | try { |
| 2704 | synchronized (mGlobalLock) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 2705 | return mRecentTasks.getAppTasksList(callingUid, callingPackage); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2706 | } |
| 2707 | } finally { |
| 2708 | Binder.restoreCallingIdentity(ident); |
| 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | @Override |
| 2713 | public void finishVoiceTask(IVoiceInteractionSession session) { |
| 2714 | synchronized (mGlobalLock) { |
| 2715 | final long origId = Binder.clearCallingIdentity(); |
| 2716 | try { |
| 2717 | // TODO: VI Consider treating local voice interactions and voice tasks |
| 2718 | // differently here |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2719 | mRootActivityContainer.finishVoiceTask(session); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2720 | } finally { |
| 2721 | Binder.restoreCallingIdentity(origId); |
| 2722 | } |
| 2723 | } |
| 2724 | |
| 2725 | } |
| 2726 | |
| 2727 | @Override |
| 2728 | public boolean isTopOfTask(IBinder token) { |
| 2729 | synchronized (mGlobalLock) { |
| 2730 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2731 | return r != null && r.getTaskRecord().getTopActivity() == r; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2732 | } |
| 2733 | } |
| 2734 | |
| 2735 | @Override |
| 2736 | public void notifyLaunchTaskBehindComplete(IBinder token) { |
| 2737 | mStackSupervisor.scheduleLaunchTaskBehindComplete(token); |
| 2738 | } |
| 2739 | |
| 2740 | @Override |
| 2741 | public void notifyEnterAnimationComplete(IBinder token) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2742 | mH.post(() -> { |
| 2743 | synchronized (mGlobalLock) { |
| 2744 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2745 | if (r != null && r.attachedToProcess()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2746 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2747 | r.app.getThread().scheduleEnterAnimationComplete(r.appToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 2748 | } catch (RemoteException e) { |
| 2749 | } |
| 2750 | } |
| 2751 | } |
| 2752 | |
| 2753 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | /** Called from an app when assist data is ready. */ |
| 2757 | @Override |
| 2758 | public void reportAssistContextExtras(IBinder token, Bundle extras, AssistStructure structure, |
| 2759 | AssistContent content, Uri referrer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2760 | PendingAssistExtras pae = (PendingAssistExtras) token; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2761 | synchronized (pae) { |
| 2762 | pae.result = extras; |
| 2763 | pae.structure = structure; |
| 2764 | pae.content = content; |
| 2765 | if (referrer != null) { |
| 2766 | pae.extras.putParcelable(Intent.EXTRA_REFERRER, referrer); |
| 2767 | } |
| 2768 | if (structure != null) { |
Winson Chung | 48b2565 | 2018-10-22 14:04:30 -0700 | [diff] [blame] | 2769 | // Pre-fill the task/activity component for all assist data receivers |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2770 | structure.setTaskId(pae.activity.getTaskRecord().taskId); |
| 2771 | structure.setActivityComponent(pae.activity.mActivityComponent); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2772 | structure.setHomeActivity(pae.isHome); |
| 2773 | } |
| 2774 | pae.haveResult = true; |
| 2775 | pae.notifyAll(); |
| 2776 | if (pae.intent == null && pae.receiver == null) { |
| 2777 | // Caller is just waiting for the result. |
| 2778 | return; |
| 2779 | } |
| 2780 | } |
| 2781 | // We are now ready to launch the assist activity. |
| 2782 | IAssistDataReceiver sendReceiver = null; |
| 2783 | Bundle sendBundle = null; |
| 2784 | synchronized (mGlobalLock) { |
| 2785 | buildAssistBundleLocked(pae, extras); |
| 2786 | boolean exists = mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2787 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2788 | if (!exists) { |
| 2789 | // Timed out. |
| 2790 | return; |
| 2791 | } |
| 2792 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2793 | if ((sendReceiver = pae.receiver) != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2794 | // Caller wants result sent back to them. |
| 2795 | sendBundle = new Bundle(); |
| 2796 | sendBundle.putBundle(ASSIST_KEY_DATA, pae.extras); |
| 2797 | sendBundle.putParcelable(ASSIST_KEY_STRUCTURE, pae.structure); |
| 2798 | sendBundle.putParcelable(ASSIST_KEY_CONTENT, pae.content); |
| 2799 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 2800 | } |
| 2801 | } |
| 2802 | if (sendReceiver != null) { |
| 2803 | try { |
| 2804 | sendReceiver.onHandleAssistData(sendBundle); |
| 2805 | } catch (RemoteException e) { |
| 2806 | } |
| 2807 | return; |
| 2808 | } |
| 2809 | |
| 2810 | final long ident = Binder.clearCallingIdentity(); |
| 2811 | try { |
| 2812 | if (TextUtils.equals(pae.intent.getAction(), |
| 2813 | android.service.voice.VoiceInteractionService.SERVICE_INTERFACE)) { |
| 2814 | pae.intent.putExtras(pae.extras); |
| 2815 | mContext.startServiceAsUser(pae.intent, new UserHandle(pae.userHandle)); |
| 2816 | } else { |
| 2817 | pae.intent.replaceExtras(pae.extras); |
| 2818 | pae.intent.setFlags(FLAG_ACTIVITY_NEW_TASK |
| 2819 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 2820 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 2821 | mInternal.closeSystemDialogs("assist"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2822 | |
| 2823 | try { |
| 2824 | mContext.startActivityAsUser(pae.intent, new UserHandle(pae.userHandle)); |
| 2825 | } catch (ActivityNotFoundException e) { |
| 2826 | Slog.w(TAG, "No activity to handle assist action.", e); |
| 2827 | } |
| 2828 | } |
| 2829 | } finally { |
| 2830 | Binder.restoreCallingIdentity(ident); |
| 2831 | } |
| 2832 | } |
| 2833 | |
| 2834 | @Override |
| 2835 | public int addAppTask(IBinder activityToken, Intent intent, |
| 2836 | ActivityManager.TaskDescription description, Bitmap thumbnail) throws RemoteException { |
| 2837 | final int callingUid = Binder.getCallingUid(); |
| 2838 | final long callingIdent = Binder.clearCallingIdentity(); |
| 2839 | |
| 2840 | try { |
| 2841 | synchronized (mGlobalLock) { |
| 2842 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 2843 | if (r == null) { |
| 2844 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 2845 | + activityToken); |
| 2846 | } |
| 2847 | ComponentName comp = intent.getComponent(); |
| 2848 | if (comp == null) { |
| 2849 | throw new IllegalArgumentException("Intent " + intent |
| 2850 | + " must specify explicit component"); |
| 2851 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2852 | if (thumbnail.getWidth() != mThumbnailWidth |
| 2853 | || thumbnail.getHeight() != mThumbnailHeight) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2854 | throw new IllegalArgumentException("Bad thumbnail size: got " |
| 2855 | + thumbnail.getWidth() + "x" + thumbnail.getHeight() + ", require " |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2856 | + mThumbnailWidth + "x" + mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2857 | } |
| 2858 | if (intent.getSelector() != null) { |
| 2859 | intent.setSelector(null); |
| 2860 | } |
| 2861 | if (intent.getSourceBounds() != null) { |
| 2862 | intent.setSourceBounds(null); |
| 2863 | } |
| 2864 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) { |
| 2865 | if ((intent.getFlags()&Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) == 0) { |
| 2866 | // The caller has added this as an auto-remove task... that makes no |
| 2867 | // sense, so turn off auto-remove. |
| 2868 | intent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS); |
| 2869 | } |
| 2870 | } |
| 2871 | final ActivityInfo ainfo = AppGlobals.getPackageManager().getActivityInfo(comp, |
| 2872 | STOCK_PM_FLAGS, UserHandle.getUserId(callingUid)); |
| 2873 | if (ainfo.applicationInfo.uid != callingUid) { |
| 2874 | throw new SecurityException( |
| 2875 | "Can't add task for another application: target uid=" |
| 2876 | + ainfo.applicationInfo.uid + ", calling uid=" + callingUid); |
| 2877 | } |
| 2878 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2879 | final ActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2880 | final TaskRecord task = stack.createTaskRecord( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2881 | mStackSupervisor.getNextTaskIdForUserLocked(r.mUserId), ainfo, intent, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2882 | null /* voiceSession */, null /* voiceInteractor */, !ON_TOP); |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 2883 | if (!mRecentTasks.addToBottom(task)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2884 | // The app has too many tasks already and we can't add any more |
| 2885 | stack.removeTask(task, "addAppTask", REMOVE_TASK_MODE_DESTROYING); |
| 2886 | return INVALID_TASK_ID; |
| 2887 | } |
| 2888 | task.lastTaskDescription.copyFrom(description); |
| 2889 | |
| 2890 | // TODO: Send the thumbnail to WM to store it. |
| 2891 | |
| 2892 | return task.taskId; |
| 2893 | } |
| 2894 | } finally { |
| 2895 | Binder.restoreCallingIdentity(callingIdent); |
| 2896 | } |
| 2897 | } |
| 2898 | |
| 2899 | @Override |
| 2900 | public Point getAppTaskThumbnailSize() { |
| 2901 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2902 | return new Point(mThumbnailWidth, mThumbnailHeight); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2903 | } |
| 2904 | } |
| 2905 | |
| 2906 | @Override |
| 2907 | public void setTaskResizeable(int taskId, int resizeableMode) { |
| 2908 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2909 | final TaskRecord task = mRootActivityContainer.anyTaskForId( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2910 | taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 2911 | if (task == null) { |
| 2912 | Slog.w(TAG, "setTaskResizeable: taskId=" + taskId + " not found"); |
| 2913 | return; |
| 2914 | } |
| 2915 | task.setResizeMode(resizeableMode); |
| 2916 | } |
| 2917 | } |
| 2918 | |
| 2919 | @Override |
| 2920 | public void resizeTask(int taskId, Rect bounds, int resizeMode) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2921 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "resizeTask()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2922 | long ident = Binder.clearCallingIdentity(); |
| 2923 | try { |
| 2924 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2925 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Riddle Hsu | 090ac6f | 2018-10-31 12:55:29 +0800 | [diff] [blame] | 2926 | MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2927 | if (task == null) { |
| 2928 | Slog.w(TAG, "resizeTask: taskId=" + taskId + " not found"); |
| 2929 | return; |
| 2930 | } |
| 2931 | // Place the task in the right stack if it isn't there already based on |
| 2932 | // the requested bounds. |
| 2933 | // The stack transition logic is: |
| 2934 | // - a null bounds on a freeform task moves that task to fullscreen |
| 2935 | // - a non-null bounds on a non-freeform (fullscreen OR docked) task moves |
| 2936 | // that task to freeform |
| 2937 | // - otherwise the task is not moved |
| 2938 | ActivityStack stack = task.getStack(); |
| 2939 | if (!task.getWindowConfiguration().canResizeTask()) { |
| 2940 | throw new IllegalArgumentException("resizeTask not allowed on task=" + task); |
| 2941 | } |
| 2942 | if (bounds == null && stack.getWindowingMode() == WINDOWING_MODE_FREEFORM) { |
| 2943 | stack = stack.getDisplay().getOrCreateStack( |
| 2944 | WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), ON_TOP); |
| 2945 | } else if (bounds != null && stack.getWindowingMode() != WINDOWING_MODE_FREEFORM) { |
| 2946 | stack = stack.getDisplay().getOrCreateStack( |
| 2947 | WINDOWING_MODE_FREEFORM, stack.getActivityType(), ON_TOP); |
| 2948 | } |
| 2949 | |
| 2950 | // Reparent the task to the right stack if necessary |
| 2951 | boolean preserveWindow = (resizeMode & RESIZE_MODE_PRESERVE_WINDOW) != 0; |
| 2952 | if (stack != task.getStack()) { |
| 2953 | // Defer resume until the task is resized below |
| 2954 | task.reparent(stack, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, ANIMATE, |
| 2955 | DEFER_RESUME, "resizeTask"); |
| 2956 | preserveWindow = false; |
| 2957 | } |
| 2958 | |
| 2959 | // After reparenting (which only resizes the task to the stack bounds), resize the |
| 2960 | // task to the actual bounds provided |
| 2961 | task.resize(bounds, resizeMode, preserveWindow, !DEFER_RESUME); |
| 2962 | } |
| 2963 | } finally { |
| 2964 | Binder.restoreCallingIdentity(ident); |
| 2965 | } |
| 2966 | } |
| 2967 | |
| 2968 | @Override |
| 2969 | public boolean releaseActivityInstance(IBinder token) { |
| 2970 | synchronized (mGlobalLock) { |
| 2971 | final long origId = Binder.clearCallingIdentity(); |
| 2972 | try { |
| 2973 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2974 | if (r == null) { |
| 2975 | return false; |
| 2976 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2977 | return r.getActivityStack().safelyDestroyActivityLocked(r, "app-req"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2978 | } finally { |
| 2979 | Binder.restoreCallingIdentity(origId); |
| 2980 | } |
| 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | @Override |
| 2985 | public void releaseSomeActivities(IApplicationThread appInt) { |
| 2986 | synchronized (mGlobalLock) { |
| 2987 | final long origId = Binder.clearCallingIdentity(); |
| 2988 | try { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 2989 | final WindowProcessController app = getProcessController(appInt); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2990 | mRootActivityContainer.releaseSomeActivitiesLocked(app, "low-mem"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 2991 | } finally { |
| 2992 | Binder.restoreCallingIdentity(origId); |
| 2993 | } |
| 2994 | } |
| 2995 | } |
| 2996 | |
| 2997 | @Override |
| 2998 | public void setLockScreenShown(boolean keyguardShowing, boolean aodShowing, |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 2999 | int[] secondaryDisplaysShowing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3000 | if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER) |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3001 | != PackageManager.PERMISSION_GRANTED) { |
| 3002 | throw new SecurityException("Requires permission " |
| 3003 | + android.Manifest.permission.DEVICE_POWER); |
| 3004 | } |
| 3005 | |
| 3006 | synchronized (mGlobalLock) { |
| 3007 | long ident = Binder.clearCallingIdentity(); |
| 3008 | if (mKeyguardShown != keyguardShowing) { |
| 3009 | mKeyguardShown = keyguardShowing; |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3010 | final Message msg = PooledLambda.obtainMessage( |
| 3011 | ActivityManagerInternal::reportCurKeyguardUsageEvent, mAmInternal, |
| 3012 | keyguardShowing); |
| 3013 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3014 | } |
| 3015 | try { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3016 | mKeyguardController.setKeyguardShown(keyguardShowing, aodShowing, |
wilsonshih | e7903ea | 2018-09-26 16:17:59 +0800 | [diff] [blame] | 3017 | secondaryDisplaysShowing); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3018 | } finally { |
| 3019 | Binder.restoreCallingIdentity(ident); |
| 3020 | } |
| 3021 | } |
| 3022 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3023 | mH.post(() -> { |
| 3024 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3025 | mScreenObservers.get(i).onKeyguardStateChanged(keyguardShowing); |
| 3026 | } |
| 3027 | }); |
| 3028 | } |
| 3029 | |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 3030 | public void onScreenAwakeChanged(boolean isAwake) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3031 | mH.post(() -> { |
| 3032 | for (int i = mScreenObservers.size() - 1; i >= 0; i--) { |
| 3033 | mScreenObservers.get(i).onAwakeStateChanged(isAwake); |
| 3034 | } |
| 3035 | }); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | @Override |
| 3039 | public Bitmap getTaskDescriptionIcon(String filePath, int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3040 | userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 3041 | userId, "getTaskDescriptionIcon"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3042 | |
| 3043 | final File passedIconFile = new File(filePath); |
| 3044 | final File legitIconFile = new File(TaskPersister.getUserImagesDir(userId), |
| 3045 | passedIconFile.getName()); |
| 3046 | if (!legitIconFile.getPath().equals(filePath) |
| 3047 | || !filePath.contains(ActivityRecord.ACTIVITY_ICON_SUFFIX)) { |
| 3048 | throw new IllegalArgumentException("Bad file path: " + filePath |
| 3049 | + " passed for userId " + userId); |
| 3050 | } |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 3051 | return mRecentTasks.getTaskDescriptionIcon(filePath); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3055 | public void startInPlaceAnimationOnFrontMostApplication(Bundle opts) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3056 | final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(opts); |
| 3057 | final ActivityOptions activityOptions = safeOptions != null |
| 3058 | ? safeOptions.getOptions(mStackSupervisor) |
| 3059 | : null; |
| 3060 | if (activityOptions == null |
| 3061 | || activityOptions.getAnimationType() != ActivityOptions.ANIM_CUSTOM_IN_PLACE |
| 3062 | || activityOptions.getCustomInPlaceResId() == 0) { |
| 3063 | throw new IllegalArgumentException("Expected in-place ActivityOption " + |
| 3064 | "with valid animation"); |
| 3065 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3066 | // Get top display of front most application. |
| 3067 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
| 3068 | if (focusedStack != null) { |
| 3069 | final DisplayWindowController dwc = |
| 3070 | focusedStack.getDisplay().getWindowContainerController(); |
| 3071 | dwc.prepareAppTransition(TRANSIT_TASK_IN_PLACE, false); |
| 3072 | dwc.overridePendingAppTransitionInPlace(activityOptions.getPackageName(), |
| 3073 | activityOptions.getCustomInPlaceResId()); |
| 3074 | dwc.executeAppTransition(); |
| 3075 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | @Override |
| 3079 | public void removeStack(int stackId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3080 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "removeStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3081 | synchronized (mGlobalLock) { |
| 3082 | final long ident = Binder.clearCallingIdentity(); |
| 3083 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3084 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3085 | if (stack == null) { |
| 3086 | Slog.w(TAG, "removeStack: No stack with id=" + stackId); |
| 3087 | return; |
| 3088 | } |
| 3089 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3090 | throw new IllegalArgumentException( |
| 3091 | "Removing non-standard stack is not allowed."); |
| 3092 | } |
| 3093 | mStackSupervisor.removeStack(stack); |
| 3094 | } finally { |
| 3095 | Binder.restoreCallingIdentity(ident); |
| 3096 | } |
| 3097 | } |
| 3098 | } |
| 3099 | |
| 3100 | @Override |
| 3101 | public void moveStackToDisplay(int stackId, int displayId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3102 | mAmInternal.enforceCallingPermission(INTERNAL_SYSTEM_WINDOW, "moveStackToDisplay()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3103 | |
| 3104 | synchronized (mGlobalLock) { |
| 3105 | final long ident = Binder.clearCallingIdentity(); |
| 3106 | try { |
| 3107 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveStackToDisplay: moving stackId=" + stackId |
| 3108 | + " to displayId=" + displayId); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3109 | mRootActivityContainer.moveStackToDisplay(stackId, displayId, ON_TOP); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3110 | } finally { |
| 3111 | Binder.restoreCallingIdentity(ident); |
| 3112 | } |
| 3113 | } |
| 3114 | } |
| 3115 | |
| 3116 | @Override |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3117 | public void exitFreeformMode(IBinder token) { |
| 3118 | synchronized (mGlobalLock) { |
| 3119 | long ident = Binder.clearCallingIdentity(); |
| 3120 | try { |
| 3121 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3122 | if (r == null) { |
| 3123 | throw new IllegalArgumentException( |
| 3124 | "exitFreeformMode: No activity record matching token=" + token); |
| 3125 | } |
| 3126 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3127 | final ActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3128 | if (stack == null || !stack.inFreeformWindowingMode()) { |
| 3129 | throw new IllegalStateException( |
| 3130 | "exitFreeformMode: You can only go fullscreen from freeform."); |
| 3131 | } |
| 3132 | |
| 3133 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 3134 | } finally { |
| 3135 | Binder.restoreCallingIdentity(ident); |
| 3136 | } |
| 3137 | } |
| 3138 | } |
| 3139 | |
| 3140 | /** Sets the task stack listener that gets callbacks when a task stack changes. */ |
| 3141 | @Override |
| 3142 | public void registerTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3143 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3144 | "registerTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3145 | mTaskChangeNotificationController.registerTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | /** Unregister a task stack listener so that it stops receiving callbacks. */ |
| 3149 | @Override |
| 3150 | public void unregisterTaskStackListener(ITaskStackListener listener) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3151 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3152 | "unregisterTaskStackListener()"); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3153 | mTaskChangeNotificationController.unregisterTaskStackListener(listener); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3154 | } |
| 3155 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3156 | @Override |
| 3157 | public boolean requestAssistContextExtras(int requestType, IAssistDataReceiver receiver, |
| 3158 | Bundle receiverExtras, IBinder activityToken, boolean focused, boolean newSessionId) { |
| 3159 | return enqueueAssistContext(requestType, null, null, receiver, receiverExtras, |
| 3160 | activityToken, focused, newSessionId, UserHandle.getCallingUserId(), null, |
| 3161 | PENDING_ASSIST_EXTRAS_LONG_TIMEOUT, 0) != null; |
| 3162 | } |
| 3163 | |
| 3164 | @Override |
| 3165 | public boolean requestAutofillData(IAssistDataReceiver receiver, Bundle receiverExtras, |
| 3166 | IBinder activityToken, int flags) { |
| 3167 | return enqueueAssistContext(ActivityManager.ASSIST_CONTEXT_AUTOFILL, null, null, |
| 3168 | receiver, receiverExtras, activityToken, true, true, UserHandle.getCallingUserId(), |
| 3169 | null, PENDING_AUTOFILL_ASSIST_STRUCTURE_TIMEOUT, flags) != null; |
| 3170 | } |
| 3171 | |
| 3172 | @Override |
| 3173 | public boolean launchAssistIntent(Intent intent, int requestType, String hint, int userHandle, |
| 3174 | Bundle args) { |
| 3175 | return enqueueAssistContext(requestType, intent, hint, null, null, null, |
| 3176 | true /* focused */, true /* newSessionId */, userHandle, args, |
| 3177 | PENDING_ASSIST_EXTRAS_TIMEOUT, 0) != null; |
| 3178 | } |
| 3179 | |
| 3180 | @Override |
| 3181 | public Bundle getAssistContextExtras(int requestType) { |
| 3182 | PendingAssistExtras pae = enqueueAssistContext(requestType, null, null, null, |
| 3183 | null, null, true /* focused */, true /* newSessionId */, |
| 3184 | UserHandle.getCallingUserId(), null, PENDING_ASSIST_EXTRAS_TIMEOUT, 0); |
| 3185 | if (pae == null) { |
| 3186 | return null; |
| 3187 | } |
| 3188 | synchronized (pae) { |
| 3189 | while (!pae.haveResult) { |
| 3190 | try { |
| 3191 | pae.wait(); |
| 3192 | } catch (InterruptedException e) { |
| 3193 | } |
| 3194 | } |
| 3195 | } |
| 3196 | synchronized (mGlobalLock) { |
| 3197 | buildAssistBundleLocked(pae, pae.result); |
| 3198 | mPendingAssistExtras.remove(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3199 | mUiHandler.removeCallbacks(pae); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3200 | } |
| 3201 | return pae.extras; |
| 3202 | } |
| 3203 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3204 | /** |
| 3205 | * Binder IPC calls go through the public entry point. |
| 3206 | * This can be called with or without the global lock held. |
| 3207 | */ |
| 3208 | private static int checkCallingPermission(String permission) { |
| 3209 | return checkPermission( |
| 3210 | permission, Binder.getCallingPid(), UserHandle.getAppId(Binder.getCallingUid())); |
| 3211 | } |
| 3212 | |
| 3213 | /** This can be called with or without the global lock held. */ |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3214 | private void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3215 | if (!getRecentTasks().isCallerRecents(Binder.getCallingUid())) { |
| 3216 | mAmInternal.enforceCallingPermission(permission, func); |
| 3217 | } |
| 3218 | } |
| 3219 | |
| 3220 | @VisibleForTesting |
| 3221 | int checkGetTasksPermission(String permission, int pid, int uid) { |
| 3222 | return checkPermission(permission, pid, uid); |
| 3223 | } |
| 3224 | |
| 3225 | static int checkPermission(String permission, int pid, int uid) { |
| 3226 | if (permission == null) { |
| 3227 | return PackageManager.PERMISSION_DENIED; |
| 3228 | } |
| 3229 | return checkComponentPermission(permission, pid, uid, -1, true); |
| 3230 | } |
| 3231 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 3232 | public static int checkComponentPermission(String permission, int pid, int uid, |
| 3233 | int owningUid, boolean exported) { |
| 3234 | return ActivityManagerService.checkComponentPermission( |
| 3235 | permission, pid, uid, owningUid, exported); |
| 3236 | } |
| 3237 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3238 | boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 3239 | if (getRecentTasks().isCallerRecents(callingUid)) { |
| 3240 | // Always allow the recents component to get tasks |
| 3241 | return true; |
| 3242 | } |
| 3243 | |
| 3244 | boolean allowed = checkGetTasksPermission(android.Manifest.permission.REAL_GET_TASKS, |
| 3245 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED; |
| 3246 | if (!allowed) { |
| 3247 | if (checkGetTasksPermission(android.Manifest.permission.GET_TASKS, |
| 3248 | callingPid, callingUid) == PackageManager.PERMISSION_GRANTED) { |
| 3249 | // Temporary compatibility: some existing apps on the system image may |
| 3250 | // still be requesting the old permission and not switched to the new |
| 3251 | // one; if so, we'll still allow them full access. This means we need |
| 3252 | // to see if they are holding the old permission and are a system app. |
| 3253 | try { |
| 3254 | if (AppGlobals.getPackageManager().isUidPrivileged(callingUid)) { |
| 3255 | allowed = true; |
| 3256 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3257 | + " is using old GET_TASKS but privileged; allowing"); |
| 3258 | } |
| 3259 | } catch (RemoteException e) { |
| 3260 | } |
| 3261 | } |
| 3262 | if (DEBUG_TASKS) Slog.w(TAG, caller + ": caller " + callingUid |
| 3263 | + " does not hold REAL_GET_TASKS; limiting output"); |
| 3264 | } |
| 3265 | return allowed; |
| 3266 | } |
| 3267 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3268 | private PendingAssistExtras enqueueAssistContext(int requestType, Intent intent, String hint, |
| 3269 | IAssistDataReceiver receiver, Bundle receiverExtras, IBinder activityToken, |
| 3270 | boolean focused, boolean newSessionId, int userHandle, Bundle args, long timeout, |
| 3271 | int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3272 | mAmInternal.enforceCallingPermission(android.Manifest.permission.GET_TOP_ACTIVITY_INFO, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3273 | "enqueueAssistContext()"); |
| 3274 | |
| 3275 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3276 | ActivityRecord activity = getTopDisplayFocusedStack().getTopActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3277 | if (activity == null) { |
| 3278 | Slog.w(TAG, "getAssistContextExtras failed: no top activity"); |
| 3279 | return null; |
| 3280 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3281 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3282 | Slog.w(TAG, "getAssistContextExtras failed: no process for " + activity); |
| 3283 | return null; |
| 3284 | } |
| 3285 | if (focused) { |
| 3286 | if (activityToken != null) { |
| 3287 | ActivityRecord caller = ActivityRecord.forTokenLocked(activityToken); |
| 3288 | if (activity != caller) { |
| 3289 | Slog.w(TAG, "enqueueAssistContext failed: caller " + caller |
| 3290 | + " is not current top " + activity); |
| 3291 | return null; |
| 3292 | } |
| 3293 | } |
| 3294 | } else { |
| 3295 | activity = ActivityRecord.forTokenLocked(activityToken); |
| 3296 | if (activity == null) { |
| 3297 | Slog.w(TAG, "enqueueAssistContext failed: activity for token=" + activityToken |
| 3298 | + " couldn't be found"); |
| 3299 | return null; |
| 3300 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3301 | if (!activity.attachedToProcess()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3302 | Slog.w(TAG, "enqueueAssistContext failed: no process for " + activity); |
| 3303 | return null; |
| 3304 | } |
| 3305 | } |
| 3306 | |
| 3307 | PendingAssistExtras pae; |
| 3308 | Bundle extras = new Bundle(); |
| 3309 | if (args != null) { |
| 3310 | extras.putAll(args); |
| 3311 | } |
| 3312 | extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3313 | extras.putInt(Intent.EXTRA_ASSIST_UID, activity.app.mUid); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3314 | |
| 3315 | pae = new PendingAssistExtras(activity, extras, intent, hint, receiver, receiverExtras, |
| 3316 | userHandle); |
| 3317 | pae.isHome = activity.isActivityTypeHome(); |
| 3318 | |
| 3319 | // Increment the sessionId if necessary |
| 3320 | if (newSessionId) { |
| 3321 | mViSessionId++; |
| 3322 | } |
| 3323 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3324 | activity.app.getThread().requestAssistContextExtras(activity.appToken, pae, |
| 3325 | requestType, mViSessionId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3326 | mPendingAssistExtras.add(pae); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3327 | mUiHandler.postDelayed(pae, timeout); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3328 | } catch (RemoteException e) { |
| 3329 | Slog.w(TAG, "getAssistContextExtras failed: crash calling " + activity); |
| 3330 | return null; |
| 3331 | } |
| 3332 | return pae; |
| 3333 | } |
| 3334 | } |
| 3335 | |
| 3336 | private void buildAssistBundleLocked(PendingAssistExtras pae, Bundle result) { |
| 3337 | if (result != null) { |
| 3338 | pae.extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, result); |
| 3339 | } |
| 3340 | if (pae.hint != null) { |
| 3341 | pae.extras.putBoolean(pae.hint, true); |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | private void pendingAssistExtrasTimedOut(PendingAssistExtras pae) { |
| 3346 | IAssistDataReceiver receiver; |
| 3347 | synchronized (mGlobalLock) { |
| 3348 | mPendingAssistExtras.remove(pae); |
| 3349 | receiver = pae.receiver; |
| 3350 | } |
| 3351 | if (receiver != null) { |
| 3352 | // Caller wants result sent back to them. |
| 3353 | Bundle sendBundle = new Bundle(); |
| 3354 | // At least return the receiver extras |
| 3355 | sendBundle.putBundle(ASSIST_KEY_RECEIVER_EXTRAS, pae.receiverExtras); |
| 3356 | try { |
| 3357 | pae.receiver.onHandleAssistData(sendBundle); |
| 3358 | } catch (RemoteException e) { |
| 3359 | } |
| 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | public class PendingAssistExtras extends Binder implements Runnable { |
| 3364 | public final ActivityRecord activity; |
| 3365 | public boolean isHome; |
| 3366 | public final Bundle extras; |
| 3367 | public final Intent intent; |
| 3368 | public final String hint; |
| 3369 | public final IAssistDataReceiver receiver; |
| 3370 | public final int userHandle; |
| 3371 | public boolean haveResult = false; |
| 3372 | public Bundle result = null; |
| 3373 | public AssistStructure structure = null; |
| 3374 | public AssistContent content = null; |
| 3375 | public Bundle receiverExtras; |
| 3376 | |
| 3377 | public PendingAssistExtras(ActivityRecord _activity, Bundle _extras, Intent _intent, |
| 3378 | String _hint, IAssistDataReceiver _receiver, Bundle _receiverExtras, |
| 3379 | int _userHandle) { |
| 3380 | activity = _activity; |
| 3381 | extras = _extras; |
| 3382 | intent = _intent; |
| 3383 | hint = _hint; |
| 3384 | receiver = _receiver; |
| 3385 | receiverExtras = _receiverExtras; |
| 3386 | userHandle = _userHandle; |
| 3387 | } |
| 3388 | |
| 3389 | @Override |
| 3390 | public void run() { |
| 3391 | Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from " + activity); |
| 3392 | synchronized (this) { |
| 3393 | haveResult = true; |
| 3394 | notifyAll(); |
| 3395 | } |
| 3396 | pendingAssistExtrasTimedOut(this); |
| 3397 | } |
| 3398 | } |
| 3399 | |
| 3400 | @Override |
| 3401 | public boolean isAssistDataAllowedOnCurrentActivity() { |
| 3402 | int userId; |
| 3403 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3404 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3405 | if (focusedStack == null || focusedStack.isActivityTypeAssistant()) { |
| 3406 | return false; |
| 3407 | } |
| 3408 | |
| 3409 | final ActivityRecord activity = focusedStack.getTopActivity(); |
| 3410 | if (activity == null) { |
| 3411 | return false; |
| 3412 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3413 | userId = activity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3414 | } |
| 3415 | return !DevicePolicyCache.getInstance().getScreenCaptureDisabled(userId); |
| 3416 | } |
| 3417 | |
| 3418 | @Override |
| 3419 | public boolean showAssistFromActivity(IBinder token, Bundle args) { |
| 3420 | long ident = Binder.clearCallingIdentity(); |
| 3421 | try { |
| 3422 | synchronized (mGlobalLock) { |
| 3423 | ActivityRecord caller = ActivityRecord.forTokenLocked(token); |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3424 | ActivityRecord top = getTopDisplayFocusedStack().getTopActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3425 | if (top != caller) { |
| 3426 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3427 | + " is not current top " + top); |
| 3428 | return false; |
| 3429 | } |
| 3430 | if (!top.nowVisible) { |
| 3431 | Slog.w(TAG, "showAssistFromActivity failed: caller " + caller |
| 3432 | + " is not visible"); |
| 3433 | return false; |
| 3434 | } |
| 3435 | } |
| 3436 | return mAssistUtils.showSessionForActiveService(args, SHOW_SOURCE_APPLICATION, null, |
| 3437 | token); |
| 3438 | } finally { |
| 3439 | Binder.restoreCallingIdentity(ident); |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | @Override |
| 3444 | public boolean isRootVoiceInteraction(IBinder token) { |
| 3445 | synchronized (mGlobalLock) { |
| 3446 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3447 | if (r == null) { |
| 3448 | return false; |
| 3449 | } |
| 3450 | return r.rootVoiceInteraction; |
| 3451 | } |
| 3452 | } |
| 3453 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3454 | private void onLocalVoiceInteractionStartedLocked(IBinder activity, |
| 3455 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 3456 | ActivityRecord activityToCallback = ActivityRecord.forTokenLocked(activity); |
| 3457 | if (activityToCallback == null) return; |
| 3458 | activityToCallback.setVoiceSessionLocked(voiceSession); |
| 3459 | |
| 3460 | // Inform the activity |
| 3461 | try { |
| 3462 | activityToCallback.app.getThread().scheduleLocalVoiceInteractionStarted(activity, |
| 3463 | voiceInteractor); |
| 3464 | long token = Binder.clearCallingIdentity(); |
| 3465 | try { |
| 3466 | startRunningVoiceLocked(voiceSession, activityToCallback.appInfo.uid); |
| 3467 | } finally { |
| 3468 | Binder.restoreCallingIdentity(token); |
| 3469 | } |
| 3470 | // TODO: VI Should we cache the activity so that it's easier to find later |
| 3471 | // rather than scan through all the stacks and activities? |
| 3472 | } catch (RemoteException re) { |
| 3473 | activityToCallback.clearVoiceSessionLocked(); |
| 3474 | // TODO: VI Should this terminate the voice session? |
| 3475 | } |
| 3476 | } |
| 3477 | |
| 3478 | private void startRunningVoiceLocked(IVoiceInteractionSession session, int targetUid) { |
| 3479 | Slog.d(TAG, "<<< startRunningVoiceLocked()"); |
| 3480 | mVoiceWakeLock.setWorkSource(new WorkSource(targetUid)); |
| 3481 | if (mRunningVoice == null || mRunningVoice.asBinder() != session.asBinder()) { |
| 3482 | boolean wasRunningVoice = mRunningVoice != null; |
| 3483 | mRunningVoice = session; |
| 3484 | if (!wasRunningVoice) { |
| 3485 | mVoiceWakeLock.acquire(); |
| 3486 | updateSleepIfNeededLocked(); |
| 3487 | } |
| 3488 | } |
| 3489 | } |
| 3490 | |
| 3491 | void finishRunningVoiceLocked() { |
| 3492 | if (mRunningVoice != null) { |
| 3493 | mRunningVoice = null; |
| 3494 | mVoiceWakeLock.release(); |
| 3495 | updateSleepIfNeededLocked(); |
| 3496 | } |
| 3497 | } |
| 3498 | |
| 3499 | @Override |
| 3500 | public void setVoiceKeepAwake(IVoiceInteractionSession session, boolean keepAwake) { |
| 3501 | synchronized (mGlobalLock) { |
| 3502 | if (mRunningVoice != null && mRunningVoice.asBinder() == session.asBinder()) { |
| 3503 | if (keepAwake) { |
| 3504 | mVoiceWakeLock.acquire(); |
| 3505 | } else { |
| 3506 | mVoiceWakeLock.release(); |
| 3507 | } |
| 3508 | } |
| 3509 | } |
| 3510 | } |
| 3511 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3512 | @Override |
| 3513 | public ComponentName getActivityClassForToken(IBinder token) { |
| 3514 | synchronized (mGlobalLock) { |
| 3515 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3516 | if (r == null) { |
| 3517 | return null; |
| 3518 | } |
| 3519 | return r.intent.getComponent(); |
| 3520 | } |
| 3521 | } |
| 3522 | |
| 3523 | @Override |
| 3524 | public String getPackageForToken(IBinder token) { |
| 3525 | synchronized (mGlobalLock) { |
| 3526 | ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3527 | if (r == null) { |
| 3528 | return null; |
| 3529 | } |
| 3530 | return r.packageName; |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | @Override |
| 3535 | public void showLockTaskEscapeMessage(IBinder token) { |
| 3536 | synchronized (mGlobalLock) { |
| 3537 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3538 | if (r == null) { |
| 3539 | return; |
| 3540 | } |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 3541 | getLockTaskController().showLockTaskToast(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3542 | } |
| 3543 | } |
| 3544 | |
| 3545 | @Override |
| 3546 | public void keyguardGoingAway(int flags) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3547 | enforceNotIsolatedCaller("keyguardGoingAway"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3548 | final long token = Binder.clearCallingIdentity(); |
| 3549 | try { |
| 3550 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3551 | mKeyguardController.keyguardGoingAway(flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3552 | } |
| 3553 | } finally { |
| 3554 | Binder.restoreCallingIdentity(token); |
| 3555 | } |
| 3556 | } |
| 3557 | |
| 3558 | /** |
| 3559 | * Try to place task to provided position. The final position might be different depending on |
| 3560 | * current user and stacks state. The task will be moved to target stack if it's currently in |
| 3561 | * different stack. |
| 3562 | */ |
| 3563 | @Override |
| 3564 | public void positionTaskInStack(int taskId, int stackId, int position) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3565 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "positionTaskInStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3566 | synchronized (mGlobalLock) { |
| 3567 | long ident = Binder.clearCallingIdentity(); |
| 3568 | try { |
| 3569 | if (DEBUG_STACK) Slog.d(TAG_STACK, "positionTaskInStack: positioning task=" |
| 3570 | + taskId + " in stackId=" + stackId + " at position=" + position); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3571 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3572 | if (task == null) { |
| 3573 | throw new IllegalArgumentException("positionTaskInStack: no task for id=" |
| 3574 | + taskId); |
| 3575 | } |
| 3576 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3577 | final ActivityStack stack = mRootActivityContainer.getStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3578 | |
| 3579 | if (stack == null) { |
| 3580 | throw new IllegalArgumentException("positionTaskInStack: no stack for id=" |
| 3581 | + stackId); |
| 3582 | } |
| 3583 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3584 | throw new IllegalArgumentException("positionTaskInStack: Attempt to change" |
| 3585 | + " the position of task " + taskId + " in/to non-standard stack"); |
| 3586 | } |
| 3587 | |
| 3588 | // TODO: Have the callers of this API call a separate reparent method if that is |
| 3589 | // what they intended to do vs. having this method also do reparenting. |
| 3590 | if (task.getStack() == stack) { |
| 3591 | // Change position in current stack. |
| 3592 | stack.positionChildAt(task, position); |
| 3593 | } else { |
| 3594 | // Reparent to new stack. |
| 3595 | task.reparent(stack, position, REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, |
| 3596 | !DEFER_RESUME, "positionTaskInStack"); |
| 3597 | } |
| 3598 | } finally { |
| 3599 | Binder.restoreCallingIdentity(ident); |
| 3600 | } |
| 3601 | } |
| 3602 | } |
| 3603 | |
| 3604 | @Override |
| 3605 | public void reportSizeConfigurations(IBinder token, int[] horizontalSizeConfiguration, |
| 3606 | int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) { |
| 3607 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Report configuration: " + token + " " |
| 3608 | + horizontalSizeConfiguration + " " + verticalSizeConfigurations); |
| 3609 | synchronized (mGlobalLock) { |
| 3610 | ActivityRecord record = ActivityRecord.isInStackLocked(token); |
| 3611 | if (record == null) { |
| 3612 | throw new IllegalArgumentException("reportSizeConfigurations: ActivityRecord not " |
| 3613 | + "found for: " + token); |
| 3614 | } |
| 3615 | record.setSizeConfigurations(horizontalSizeConfiguration, |
| 3616 | verticalSizeConfigurations, smallestSizeConfigurations); |
| 3617 | } |
| 3618 | } |
| 3619 | |
| 3620 | /** |
| 3621 | * Dismisses split-screen multi-window mode. |
| 3622 | * @param toTop If true the current primary split-screen stack will be placed or left on top. |
| 3623 | */ |
| 3624 | @Override |
| 3625 | public void dismissSplitScreenMode(boolean toTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3626 | enforceCallerIsRecentsOrHasPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3627 | MANAGE_ACTIVITY_STACKS, "dismissSplitScreenMode()"); |
| 3628 | final long ident = Binder.clearCallingIdentity(); |
| 3629 | try { |
| 3630 | synchronized (mGlobalLock) { |
| 3631 | final ActivityStack stack = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3632 | mRootActivityContainer.getDefaultDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3633 | if (stack == null) { |
| 3634 | Slog.w(TAG, "dismissSplitScreenMode: primary split-screen stack not found."); |
| 3635 | return; |
| 3636 | } |
| 3637 | |
| 3638 | if (toTop) { |
| 3639 | // Caller wants the current split-screen primary stack to be the top stack after |
| 3640 | // it goes fullscreen, so move it to the front. |
| 3641 | stack.moveToFront("dismissSplitScreenMode"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3642 | } else if (mRootActivityContainer.isTopDisplayFocusedStack(stack)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3643 | // In this case the current split-screen primary stack shouldn't be the top |
| 3644 | // stack after it goes fullscreen, but it current has focus, so we move the |
| 3645 | // focus to the top-most split-screen secondary stack next to it. |
| 3646 | final ActivityStack otherStack = stack.getDisplay().getTopStackInWindowingMode( |
| 3647 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 3648 | if (otherStack != null) { |
| 3649 | otherStack.moveToFront("dismissSplitScreenMode_other"); |
| 3650 | } |
| 3651 | } |
| 3652 | |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 3653 | stack.setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3654 | } |
| 3655 | } finally { |
| 3656 | Binder.restoreCallingIdentity(ident); |
| 3657 | } |
| 3658 | } |
| 3659 | |
| 3660 | /** |
| 3661 | * Dismisses Pip |
| 3662 | * @param animate True if the dismissal should be animated. |
| 3663 | * @param animationDuration The duration of the resize animation in milliseconds or -1 if the |
| 3664 | * default animation duration should be used. |
| 3665 | */ |
| 3666 | @Override |
| 3667 | public void dismissPip(boolean animate, int animationDuration) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3668 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "dismissPip()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3669 | final long ident = Binder.clearCallingIdentity(); |
| 3670 | try { |
| 3671 | synchronized (mGlobalLock) { |
| 3672 | final PinnedActivityStack stack = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3673 | mRootActivityContainer.getDefaultDisplay().getPinnedStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3674 | if (stack == null) { |
| 3675 | Slog.w(TAG, "dismissPip: pinned stack not found."); |
| 3676 | return; |
| 3677 | } |
| 3678 | if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) { |
| 3679 | throw new IllegalArgumentException("Stack: " + stack |
| 3680 | + " doesn't support animated resize."); |
| 3681 | } |
| 3682 | if (animate) { |
| 3683 | stack.animateResizePinnedStack(null /* sourceHintBounds */, |
| 3684 | null /* destBounds */, animationDuration, false /* fromFullscreen */); |
| 3685 | } else { |
| 3686 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, true /* onTop */); |
| 3687 | } |
| 3688 | } |
| 3689 | } finally { |
| 3690 | Binder.restoreCallingIdentity(ident); |
| 3691 | } |
| 3692 | } |
| 3693 | |
| 3694 | @Override |
| 3695 | public void suppressResizeConfigChanges(boolean suppress) throws RemoteException { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3696 | mAmInternal.enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "suppressResizeConfigChanges()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3697 | synchronized (mGlobalLock) { |
| 3698 | mSuppressResizeConfigChanges = suppress; |
| 3699 | } |
| 3700 | } |
| 3701 | |
| 3702 | /** |
| 3703 | * NOTE: For the pinned stack, this method is usually called after the bounds animation has |
| 3704 | * animated the stack to the fullscreen, but can also be called if we are relaunching an |
| 3705 | * activity and clearing the task at the same time. |
| 3706 | */ |
| 3707 | @Override |
| 3708 | // TODO: API should just be about changing windowing modes... |
| 3709 | public void moveTasksToFullscreenStack(int fromStackId, boolean onTop) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3710 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3711 | "moveTasksToFullscreenStack()"); |
| 3712 | synchronized (mGlobalLock) { |
| 3713 | final long origId = Binder.clearCallingIdentity(); |
| 3714 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3715 | final ActivityStack stack = mRootActivityContainer.getStack(fromStackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3716 | if (stack != null){ |
| 3717 | if (!stack.isActivityTypeStandardOrUndefined()) { |
| 3718 | throw new IllegalArgumentException( |
| 3719 | "You can't move tasks from non-standard stacks."); |
| 3720 | } |
| 3721 | mStackSupervisor.moveTasksToFullscreenStackLocked(stack, onTop); |
| 3722 | } |
| 3723 | } finally { |
| 3724 | Binder.restoreCallingIdentity(origId); |
| 3725 | } |
| 3726 | } |
| 3727 | } |
| 3728 | |
| 3729 | /** |
| 3730 | * Moves the top activity in the input stackId to the pinned stack. |
| 3731 | * |
| 3732 | * @param stackId Id of stack to move the top activity to pinned stack. |
| 3733 | * @param bounds Bounds to use for pinned stack. |
| 3734 | * |
| 3735 | * @return True if the top activity of the input stack was successfully moved to the pinned |
| 3736 | * stack. |
| 3737 | */ |
| 3738 | @Override |
| 3739 | public boolean moveTopActivityToPinnedStack(int stackId, Rect bounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3740 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3741 | "moveTopActivityToPinnedStack()"); |
| 3742 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3743 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3744 | throw new IllegalStateException("moveTopActivityToPinnedStack:" |
| 3745 | + "Device doesn't support picture-in-picture mode"); |
| 3746 | } |
| 3747 | |
| 3748 | long ident = Binder.clearCallingIdentity(); |
| 3749 | try { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3750 | return mRootActivityContainer.moveTopStackActivityToPinnedStack(stackId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3751 | } finally { |
| 3752 | Binder.restoreCallingIdentity(ident); |
| 3753 | } |
| 3754 | } |
| 3755 | } |
| 3756 | |
| 3757 | @Override |
| 3758 | public boolean isInMultiWindowMode(IBinder token) { |
| 3759 | final long origId = Binder.clearCallingIdentity(); |
| 3760 | try { |
| 3761 | synchronized (mGlobalLock) { |
| 3762 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 3763 | if (r == null) { |
| 3764 | return false; |
| 3765 | } |
| 3766 | // An activity is consider to be in multi-window mode if its task isn't fullscreen. |
| 3767 | return r.inMultiWindowMode(); |
| 3768 | } |
| 3769 | } finally { |
| 3770 | Binder.restoreCallingIdentity(origId); |
| 3771 | } |
| 3772 | } |
| 3773 | |
| 3774 | @Override |
| 3775 | public boolean isInPictureInPictureMode(IBinder token) { |
| 3776 | final long origId = Binder.clearCallingIdentity(); |
| 3777 | try { |
| 3778 | synchronized (mGlobalLock) { |
| 3779 | return isInPictureInPictureMode(ActivityRecord.forTokenLocked(token)); |
| 3780 | } |
| 3781 | } finally { |
| 3782 | Binder.restoreCallingIdentity(origId); |
| 3783 | } |
| 3784 | } |
| 3785 | |
| 3786 | private boolean isInPictureInPictureMode(ActivityRecord r) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3787 | if (r == null || r.getActivityStack() == null || !r.inPinnedWindowingMode() |
| 3788 | || r.getActivityStack().isInStackLocked(r) == null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3789 | return false; |
| 3790 | } |
| 3791 | |
| 3792 | // If we are animating to fullscreen then we have already dispatched the PIP mode |
| 3793 | // changed, so we should reflect that check here as well. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3794 | final PinnedActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3795 | final PinnedStackWindowController windowController = stack.getWindowContainerController(); |
| 3796 | return !windowController.isAnimatingBoundsToFullscreen(); |
| 3797 | } |
| 3798 | |
| 3799 | @Override |
| 3800 | public boolean enterPictureInPictureMode(IBinder token, final PictureInPictureParams params) { |
| 3801 | final long origId = Binder.clearCallingIdentity(); |
| 3802 | try { |
| 3803 | synchronized (mGlobalLock) { |
| 3804 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 3805 | "enterPictureInPictureMode", token, params); |
| 3806 | |
| 3807 | // If the activity is already in picture in picture mode, then just return early |
| 3808 | if (isInPictureInPictureMode(r)) { |
| 3809 | return true; |
| 3810 | } |
| 3811 | |
| 3812 | // Activity supports picture-in-picture, now check that we can enter PiP at this |
| 3813 | // point, if it is |
| 3814 | if (!r.checkEnterPictureInPictureState("enterPictureInPictureMode", |
| 3815 | false /* beforeStopping */)) { |
| 3816 | return false; |
| 3817 | } |
| 3818 | |
| 3819 | final Runnable enterPipRunnable = () -> { |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 3820 | synchronized (mGlobalLock) { |
| 3821 | // Only update the saved args from the args that are set |
| 3822 | r.pictureInPictureArgs.copyOnlySet(params); |
| 3823 | final float aspectRatio = r.pictureInPictureArgs.getAspectRatio(); |
| 3824 | final List<RemoteAction> actions = r.pictureInPictureArgs.getActions(); |
| 3825 | // Adjust the source bounds by the insets for the transition down |
| 3826 | final Rect sourceBounds = new Rect( |
| 3827 | r.pictureInPictureArgs.getSourceRectHint()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3828 | mRootActivityContainer.moveActivityToPinnedStack( |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 3829 | r, sourceBounds, aspectRatio, "enterPictureInPictureMode"); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3830 | final PinnedActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | f276a6f | 2018-06-15 08:26:07 -0700 | [diff] [blame] | 3831 | stack.setPictureInPictureAspectRatio(aspectRatio); |
| 3832 | stack.setPictureInPictureActions(actions); |
| 3833 | MetricsLoggerWrapper.logPictureInPictureEnter(mContext, r.appInfo.uid, |
| 3834 | r.shortComponentName, r.supportsEnterPipOnTaskSwitch); |
| 3835 | logPictureInPictureArgs(params); |
| 3836 | } |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3837 | }; |
| 3838 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 3839 | if (isKeyguardLocked()) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3840 | // If the keyguard is showing or occluded, then try and dismiss it before |
| 3841 | // entering picture-in-picture (this will prompt the user to authenticate if the |
| 3842 | // device is currently locked). |
| 3843 | dismissKeyguard(token, new KeyguardDismissCallback() { |
| 3844 | @Override |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3845 | public void onDismissSucceeded() { |
| 3846 | mH.post(enterPipRunnable); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3847 | } |
| 3848 | }, null /* message */); |
| 3849 | } else { |
| 3850 | // Enter picture in picture immediately otherwise |
| 3851 | enterPipRunnable.run(); |
| 3852 | } |
| 3853 | return true; |
| 3854 | } |
| 3855 | } finally { |
| 3856 | Binder.restoreCallingIdentity(origId); |
| 3857 | } |
| 3858 | } |
| 3859 | |
| 3860 | @Override |
| 3861 | public void setPictureInPictureParams(IBinder token, final PictureInPictureParams params) { |
| 3862 | final long origId = Binder.clearCallingIdentity(); |
| 3863 | try { |
| 3864 | synchronized (mGlobalLock) { |
| 3865 | final ActivityRecord r = ensureValidPictureInPictureActivityParamsLocked( |
| 3866 | "setPictureInPictureParams", token, params); |
| 3867 | |
| 3868 | // Only update the saved args from the args that are set |
| 3869 | r.pictureInPictureArgs.copyOnlySet(params); |
| 3870 | if (r.inPinnedWindowingMode()) { |
| 3871 | // If the activity is already in picture-in-picture, update the pinned stack now |
| 3872 | // if it is not already expanding to fullscreen. Otherwise, the arguments will |
| 3873 | // be used the next time the activity enters PiP |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3874 | final PinnedActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3875 | if (!stack.isAnimatingBoundsToFullscreen()) { |
| 3876 | stack.setPictureInPictureAspectRatio( |
| 3877 | r.pictureInPictureArgs.getAspectRatio()); |
| 3878 | stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions()); |
| 3879 | } |
| 3880 | } |
| 3881 | logPictureInPictureArgs(params); |
| 3882 | } |
| 3883 | } finally { |
| 3884 | Binder.restoreCallingIdentity(origId); |
| 3885 | } |
| 3886 | } |
| 3887 | |
| 3888 | @Override |
| 3889 | public int getMaxNumPictureInPictureActions(IBinder token) { |
| 3890 | // Currently, this is a static constant, but later, we may change this to be dependent on |
| 3891 | // the context of the activity |
| 3892 | return 3; |
| 3893 | } |
| 3894 | |
| 3895 | private void logPictureInPictureArgs(PictureInPictureParams params) { |
| 3896 | if (params.hasSetActions()) { |
| 3897 | MetricsLogger.histogram(mContext, "tron_varz_picture_in_picture_actions_count", |
| 3898 | params.getActions().size()); |
| 3899 | } |
| 3900 | if (params.hasSetAspectRatio()) { |
| 3901 | LogMaker lm = new LogMaker(MetricsEvent.ACTION_PICTURE_IN_PICTURE_ASPECT_RATIO_CHANGED); |
| 3902 | lm.addTaggedData(MetricsEvent.PICTURE_IN_PICTURE_ASPECT_RATIO, params.getAspectRatio()); |
| 3903 | MetricsLogger.action(lm); |
| 3904 | } |
| 3905 | } |
| 3906 | |
| 3907 | /** |
| 3908 | * Checks the state of the system and the activity associated with the given {@param token} to |
| 3909 | * verify that picture-in-picture is supported for that activity. |
| 3910 | * |
| 3911 | * @return the activity record for the given {@param token} if all the checks pass. |
| 3912 | */ |
| 3913 | private ActivityRecord ensureValidPictureInPictureActivityParamsLocked(String caller, |
| 3914 | IBinder token, PictureInPictureParams params) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3915 | if (!mSupportsPictureInPicture) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3916 | throw new IllegalStateException(caller |
| 3917 | + ": Device doesn't support picture-in-picture mode."); |
| 3918 | } |
| 3919 | |
| 3920 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 3921 | if (r == null) { |
| 3922 | throw new IllegalStateException(caller |
| 3923 | + ": Can't find activity for token=" + token); |
| 3924 | } |
| 3925 | |
| 3926 | if (!r.supportsPictureInPicture()) { |
| 3927 | throw new IllegalStateException(caller |
| 3928 | + ": Current activity does not support picture-in-picture."); |
| 3929 | } |
| 3930 | |
| 3931 | if (params.hasSetAspectRatio() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3932 | && !mWindowManager.isValidPictureInPictureAspectRatio( |
| 3933 | r.getActivityStack().mDisplayId, params.getAspectRatio())) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3934 | final float minAspectRatio = mContext.getResources().getFloat( |
| 3935 | com.android.internal.R.dimen.config_pictureInPictureMinAspectRatio); |
| 3936 | final float maxAspectRatio = mContext.getResources().getFloat( |
| 3937 | com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio); |
| 3938 | throw new IllegalArgumentException(String.format(caller |
| 3939 | + ": Aspect ratio is too extreme (must be between %f and %f).", |
| 3940 | minAspectRatio, maxAspectRatio)); |
| 3941 | } |
| 3942 | |
| 3943 | // Truncate the number of actions if necessary |
| 3944 | params.truncateActions(getMaxNumPictureInPictureActions(token)); |
| 3945 | |
| 3946 | return r; |
| 3947 | } |
| 3948 | |
| 3949 | @Override |
| 3950 | public IBinder getUriPermissionOwnerForActivity(IBinder activityToken) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3951 | enforceNotIsolatedCaller("getUriPermissionOwnerForActivity"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3952 | synchronized (mGlobalLock) { |
| 3953 | ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 3954 | if (r == null) { |
| 3955 | throw new IllegalArgumentException("Activity does not exist; token=" |
| 3956 | + activityToken); |
| 3957 | } |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 3958 | return r.getUriPermissionsLocked().getExternalToken(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3959 | } |
| 3960 | } |
| 3961 | |
| 3962 | @Override |
| 3963 | public void resizeDockedStack(Rect dockedBounds, Rect tempDockedTaskBounds, |
| 3964 | Rect tempDockedTaskInsetBounds, |
| 3965 | Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3966 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizeDockedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3967 | long ident = Binder.clearCallingIdentity(); |
| 3968 | try { |
| 3969 | synchronized (mGlobalLock) { |
| 3970 | mStackSupervisor.resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, |
| 3971 | tempDockedTaskInsetBounds, tempOtherTaskBounds, tempOtherTaskInsetBounds, |
| 3972 | PRESERVE_WINDOWS); |
| 3973 | } |
| 3974 | } finally { |
| 3975 | Binder.restoreCallingIdentity(ident); |
| 3976 | } |
| 3977 | } |
| 3978 | |
| 3979 | @Override |
| 3980 | public void setSplitScreenResizing(boolean resizing) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3981 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "setSplitScreenResizing()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3982 | final long ident = Binder.clearCallingIdentity(); |
| 3983 | try { |
| 3984 | synchronized (mGlobalLock) { |
| 3985 | mStackSupervisor.setSplitScreenResizing(resizing); |
| 3986 | } |
| 3987 | } finally { |
| 3988 | Binder.restoreCallingIdentity(ident); |
| 3989 | } |
| 3990 | } |
| 3991 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3992 | /** |
| 3993 | * Check that we have the features required for VR-related API calls, and throw an exception if |
| 3994 | * not. |
| 3995 | */ |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 3996 | public void enforceSystemHasVrFeature() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3997 | if (!mContext.getPackageManager().hasSystemFeature( |
| 3998 | PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE)) { |
| 3999 | throw new UnsupportedOperationException("VR mode not supported on this device!"); |
| 4000 | } |
| 4001 | } |
| 4002 | |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4003 | @Override |
| 4004 | public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4005 | enforceSystemHasVrFeature(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4006 | |
| 4007 | final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class); |
| 4008 | |
| 4009 | ActivityRecord r; |
| 4010 | synchronized (mGlobalLock) { |
| 4011 | r = ActivityRecord.isInStackLocked(token); |
| 4012 | } |
| 4013 | |
| 4014 | if (r == null) { |
| 4015 | throw new IllegalArgumentException(); |
| 4016 | } |
| 4017 | |
| 4018 | int err; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4019 | if ((err = vrService.hasVrPackage(packageName, r.mUserId)) != |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4020 | VrManagerInternal.NO_ERROR) { |
| 4021 | return err; |
| 4022 | } |
| 4023 | |
| 4024 | // Clear the binder calling uid since this path may call moveToTask(). |
| 4025 | final long callingId = Binder.clearCallingIdentity(); |
| 4026 | try { |
| 4027 | synchronized (mGlobalLock) { |
| 4028 | r.requestedVrComponent = (enabled) ? packageName : null; |
| 4029 | |
| 4030 | // Update associated state if this activity is currently focused |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 4031 | if (r.isResumedActivityOnDisplay()) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4032 | applyUpdateVrModeLocked(r); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4033 | } |
| 4034 | return 0; |
| 4035 | } |
| 4036 | } finally { |
| 4037 | Binder.restoreCallingIdentity(callingId); |
| 4038 | } |
| 4039 | } |
| 4040 | |
| 4041 | @Override |
| 4042 | public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) { |
| 4043 | Slog.i(TAG, "Activity tried to startLocalVoiceInteraction"); |
| 4044 | synchronized (mGlobalLock) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4045 | ActivityRecord activity = getTopDisplayFocusedStack().getTopActivity(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4046 | if (ActivityRecord.forTokenLocked(callingActivity) != activity) { |
| 4047 | throw new SecurityException("Only focused activity can call startVoiceInteraction"); |
| 4048 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4049 | if (mRunningVoice != null || activity.getTaskRecord().voiceSession != null |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4050 | || activity.voiceSession != null) { |
| 4051 | Slog.w(TAG, "Already in a voice interaction, cannot start new voice interaction"); |
| 4052 | return; |
| 4053 | } |
| 4054 | if (activity.pendingVoiceInteractionStart) { |
| 4055 | Slog.w(TAG, "Pending start of voice interaction already."); |
| 4056 | return; |
| 4057 | } |
| 4058 | activity.pendingVoiceInteractionStart = true; |
| 4059 | } |
| 4060 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4061 | .startLocalVoiceInteraction(callingActivity, options); |
| 4062 | } |
| 4063 | |
| 4064 | @Override |
| 4065 | public void stopLocalVoiceInteraction(IBinder callingActivity) { |
| 4066 | LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4067 | .stopLocalVoiceInteraction(callingActivity); |
| 4068 | } |
| 4069 | |
| 4070 | @Override |
| 4071 | public boolean supportsLocalVoiceInteraction() { |
| 4072 | return LocalServices.getService(VoiceInteractionManagerInternal.class) |
| 4073 | .supportsLocalVoiceInteraction(); |
| 4074 | } |
| 4075 | |
| 4076 | /** Notifies all listeners when the pinned stack animation starts. */ |
| 4077 | @Override |
| 4078 | public void notifyPinnedStackAnimationStarted() { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4079 | mTaskChangeNotificationController.notifyPinnedStackAnimationStarted(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4080 | } |
| 4081 | |
| 4082 | /** Notifies all listeners when the pinned stack animation ends. */ |
| 4083 | @Override |
| 4084 | public void notifyPinnedStackAnimationEnded() { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4085 | mTaskChangeNotificationController.notifyPinnedStackAnimationEnded(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | @Override |
| 4089 | public void resizePinnedStack(Rect pinnedBounds, Rect tempPinnedTaskBounds) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4090 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizePinnedStack()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4091 | final long ident = Binder.clearCallingIdentity(); |
| 4092 | try { |
| 4093 | synchronized (mGlobalLock) { |
| 4094 | mStackSupervisor.resizePinnedStackLocked(pinnedBounds, tempPinnedTaskBounds); |
| 4095 | } |
| 4096 | } finally { |
| 4097 | Binder.restoreCallingIdentity(ident); |
| 4098 | } |
| 4099 | } |
| 4100 | |
| 4101 | @Override |
| 4102 | public boolean updateDisplayOverrideConfiguration(Configuration values, int displayId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4103 | mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateDisplayOverrideConfiguration()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4104 | |
| 4105 | synchronized (mGlobalLock) { |
| 4106 | // Check if display is initialized in AM. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4107 | if (!mRootActivityContainer.isDisplayAdded(displayId)) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4108 | // Call might come when display is not yet added or has already been removed. |
| 4109 | if (DEBUG_CONFIGURATION) { |
| 4110 | Slog.w(TAG, "Trying to update display configuration for non-existing displayId=" |
| 4111 | + displayId); |
| 4112 | } |
| 4113 | return false; |
| 4114 | } |
| 4115 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4116 | if (values == null && mWindowManager != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4117 | // sentinel: fetch the current configuration from the window manager |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4118 | values = mWindowManager.computeNewConfiguration(displayId); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4119 | } |
| 4120 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4121 | if (mWindowManager != null) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4122 | final Message msg = PooledLambda.obtainMessage( |
| 4123 | ActivityManagerInternal::updateOomLevelsForDisplay, mAmInternal, displayId); |
| 4124 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | final long origId = Binder.clearCallingIdentity(); |
| 4128 | try { |
| 4129 | if (values != null) { |
| 4130 | Settings.System.clearConfiguration(values); |
| 4131 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4132 | updateDisplayOverrideConfigurationLocked(values, null /* starting */, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4133 | false /* deferResume */, displayId, mTmpUpdateConfigurationResult); |
| 4134 | return mTmpUpdateConfigurationResult.changes != 0; |
| 4135 | } finally { |
| 4136 | Binder.restoreCallingIdentity(origId); |
| 4137 | } |
| 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | @Override |
| 4142 | public boolean updateConfiguration(Configuration values) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4143 | mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateConfiguration()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4144 | |
| 4145 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4146 | if (values == null && mWindowManager != null) { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4147 | // sentinel: fetch the current configuration from the window manager |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4148 | values = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4149 | } |
| 4150 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4151 | if (mWindowManager != null) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4152 | final Message msg = PooledLambda.obtainMessage( |
| 4153 | ActivityManagerInternal::updateOomLevelsForDisplay, mAmInternal, |
| 4154 | DEFAULT_DISPLAY); |
| 4155 | mH.sendMessage(msg); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | final long origId = Binder.clearCallingIdentity(); |
| 4159 | try { |
| 4160 | if (values != null) { |
| 4161 | Settings.System.clearConfiguration(values); |
| 4162 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4163 | updateConfigurationLocked(values, null, false, false /* persistent */, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4164 | UserHandle.USER_NULL, false /* deferResume */, |
| 4165 | mTmpUpdateConfigurationResult); |
| 4166 | return mTmpUpdateConfigurationResult.changes != 0; |
| 4167 | } finally { |
| 4168 | Binder.restoreCallingIdentity(origId); |
| 4169 | } |
| 4170 | } |
| 4171 | } |
| 4172 | |
| 4173 | @Override |
| 4174 | public void dismissKeyguard(IBinder token, IKeyguardDismissCallback callback, |
| 4175 | CharSequence message) { |
| 4176 | if (message != null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4177 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4178 | Manifest.permission.SHOW_KEYGUARD_MESSAGE, "dismissKeyguard()"); |
| 4179 | } |
| 4180 | final long callingId = Binder.clearCallingIdentity(); |
| 4181 | try { |
| 4182 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4183 | mKeyguardController.dismissKeyguard(token, callback, message); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4184 | } |
| 4185 | } finally { |
| 4186 | Binder.restoreCallingIdentity(callingId); |
| 4187 | } |
| 4188 | } |
| 4189 | |
| 4190 | @Override |
| 4191 | public void cancelTaskWindowTransition(int taskId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4192 | enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4193 | "cancelTaskWindowTransition()"); |
| 4194 | final long ident = Binder.clearCallingIdentity(); |
| 4195 | try { |
| 4196 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4197 | final TaskRecord task = mRootActivityContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4198 | MATCH_TASK_IN_STACKS_ONLY); |
| 4199 | if (task == null) { |
| 4200 | Slog.w(TAG, "cancelTaskWindowTransition: taskId=" + taskId + " not found"); |
| 4201 | return; |
| 4202 | } |
| 4203 | task.cancelWindowTransition(); |
| 4204 | } |
| 4205 | } finally { |
| 4206 | Binder.restoreCallingIdentity(ident); |
| 4207 | } |
| 4208 | } |
| 4209 | |
| 4210 | @Override |
| 4211 | public ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4212 | enforceCallerIsRecentsOrHasPermission(READ_FRAME_BUFFER, "getTaskSnapshot()"); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4213 | final long ident = Binder.clearCallingIdentity(); |
| 4214 | try { |
| 4215 | final TaskRecord task; |
| 4216 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4217 | task = mRootActivityContainer.anyTaskForId(taskId, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4218 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
| 4219 | if (task == null) { |
| 4220 | Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found"); |
| 4221 | return null; |
| 4222 | } |
| 4223 | } |
| 4224 | // Don't call this while holding the lock as this operation might hit the disk. |
| 4225 | return task.getSnapshot(reducedResolution); |
| 4226 | } finally { |
| 4227 | Binder.restoreCallingIdentity(ident); |
| 4228 | } |
| 4229 | } |
| 4230 | |
| 4231 | @Override |
| 4232 | public void setDisablePreviewScreenshots(IBinder token, boolean disable) { |
| 4233 | synchronized (mGlobalLock) { |
| 4234 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4235 | if (r == null) { |
| 4236 | Slog.w(TAG, "setDisablePreviewScreenshots: Unable to find activity for token=" |
| 4237 | + token); |
| 4238 | return; |
| 4239 | } |
| 4240 | final long origId = Binder.clearCallingIdentity(); |
| 4241 | try { |
| 4242 | r.setDisablePreviewScreenshots(disable); |
| 4243 | } finally { |
| 4244 | Binder.restoreCallingIdentity(origId); |
| 4245 | } |
| 4246 | } |
| 4247 | } |
| 4248 | |
| 4249 | /** Return the user id of the last resumed activity. */ |
| 4250 | @Override |
| 4251 | public @UserIdInt |
| 4252 | int getLastResumedActivityUserId() { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4253 | mAmInternal.enforceCallingPermission( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4254 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, "getLastResumedActivityUserId()"); |
| 4255 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4256 | if (mLastResumedActivity == null) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4257 | return getCurrentUserId(); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4258 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4259 | return mLastResumedActivity.mUserId; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4260 | } |
| 4261 | } |
| 4262 | |
| 4263 | @Override |
| 4264 | public void updateLockTaskFeatures(int userId, int flags) { |
| 4265 | final int callingUid = Binder.getCallingUid(); |
| 4266 | if (callingUid != 0 && callingUid != SYSTEM_UID) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4267 | mAmInternal.enforceCallingPermission(android.Manifest.permission.UPDATE_LOCK_TASK_PACKAGES, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4268 | "updateLockTaskFeatures()"); |
| 4269 | } |
| 4270 | synchronized (mGlobalLock) { |
| 4271 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Allowing features " + userId + ":0x" + |
| 4272 | Integer.toHexString(flags)); |
Wale Ogunwale | d95c06b | 2018-05-08 10:35:38 -0700 | [diff] [blame] | 4273 | getLockTaskController().updateLockTaskFeatures(userId, flags); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4274 | } |
| 4275 | } |
| 4276 | |
| 4277 | @Override |
| 4278 | public void setShowWhenLocked(IBinder token, boolean showWhenLocked) { |
| 4279 | synchronized (mGlobalLock) { |
| 4280 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4281 | if (r == null) { |
| 4282 | return; |
| 4283 | } |
| 4284 | final long origId = Binder.clearCallingIdentity(); |
| 4285 | try { |
| 4286 | r.setShowWhenLocked(showWhenLocked); |
| 4287 | } finally { |
| 4288 | Binder.restoreCallingIdentity(origId); |
| 4289 | } |
| 4290 | } |
| 4291 | } |
| 4292 | |
| 4293 | @Override |
| 4294 | public void setTurnScreenOn(IBinder token, boolean turnScreenOn) { |
| 4295 | synchronized (mGlobalLock) { |
| 4296 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4297 | if (r == null) { |
| 4298 | return; |
| 4299 | } |
| 4300 | final long origId = Binder.clearCallingIdentity(); |
| 4301 | try { |
| 4302 | r.setTurnScreenOn(turnScreenOn); |
| 4303 | } finally { |
| 4304 | Binder.restoreCallingIdentity(origId); |
| 4305 | } |
| 4306 | } |
| 4307 | } |
| 4308 | |
| 4309 | @Override |
| 4310 | public void registerRemoteAnimations(IBinder token, RemoteAnimationDefinition definition) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4311 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4312 | "registerRemoteAnimations"); |
| 4313 | definition.setCallingPid(Binder.getCallingPid()); |
| 4314 | synchronized (mGlobalLock) { |
| 4315 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4316 | if (r == null) { |
| 4317 | return; |
| 4318 | } |
| 4319 | final long origId = Binder.clearCallingIdentity(); |
| 4320 | try { |
| 4321 | r.registerRemoteAnimations(definition); |
| 4322 | } finally { |
| 4323 | Binder.restoreCallingIdentity(origId); |
| 4324 | } |
| 4325 | } |
| 4326 | } |
| 4327 | |
| 4328 | @Override |
| 4329 | public void registerRemoteAnimationForNextActivityStart(String packageName, |
| 4330 | RemoteAnimationAdapter adapter) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4331 | mAmInternal.enforceCallingPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS, |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4332 | "registerRemoteAnimationForNextActivityStart"); |
| 4333 | adapter.setCallingPid(Binder.getCallingPid()); |
| 4334 | synchronized (mGlobalLock) { |
| 4335 | final long origId = Binder.clearCallingIdentity(); |
| 4336 | try { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4337 | getActivityStartController().registerRemoteAnimationForNextActivityStart( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4338 | packageName, adapter); |
| 4339 | } finally { |
| 4340 | Binder.restoreCallingIdentity(origId); |
| 4341 | } |
| 4342 | } |
| 4343 | } |
| 4344 | |
| 4345 | /** @see android.app.ActivityManager#alwaysShowUnsupportedCompileSdkWarning */ |
| 4346 | @Override |
| 4347 | public void alwaysShowUnsupportedCompileSdkWarning(ComponentName activity) { |
| 4348 | synchronized (mGlobalLock) { |
| 4349 | final long origId = Binder.clearCallingIdentity(); |
| 4350 | try { |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 4351 | mAppWarnings.alwaysShowUnsupportedCompileSdkWarning(activity); |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 4352 | } finally { |
| 4353 | Binder.restoreCallingIdentity(origId); |
| 4354 | } |
| 4355 | } |
| 4356 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 4357 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4358 | @Override |
| 4359 | public void setVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4360 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4361 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4362 | final int pid = Binder.getCallingPid(); |
| 4363 | final WindowProcessController wpc = mPidMap.get(pid); |
| 4364 | mVrController.setVrThreadLocked(tid, pid, wpc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4365 | } |
| 4366 | } |
| 4367 | |
| 4368 | @Override |
| 4369 | public void setPersistentVrThread(int tid) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4370 | if (checkCallingPermission(Manifest.permission.RESTRICTED_VR_ACCESS) |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4371 | != PERMISSION_GRANTED) { |
| 4372 | final String msg = "Permission Denial: setPersistentVrThread() from pid=" |
| 4373 | + Binder.getCallingPid() |
| 4374 | + ", uid=" + Binder.getCallingUid() |
| 4375 | + " requires " + Manifest.permission.RESTRICTED_VR_ACCESS; |
| 4376 | Slog.w(TAG, msg); |
| 4377 | throw new SecurityException(msg); |
| 4378 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4379 | enforceSystemHasVrFeature(); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4380 | synchronized (mGlobalLock) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4381 | final int pid = Binder.getCallingPid(); |
| 4382 | final WindowProcessController proc = mPidMap.get(pid); |
| 4383 | mVrController.setPersistentVrThreadLocked(tid, pid, proc); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4384 | } |
| 4385 | } |
| 4386 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4387 | @Override |
| 4388 | public void stopAppSwitches() { |
| 4389 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "stopAppSwitches"); |
| 4390 | synchronized (mGlobalLock) { |
| 4391 | mAppSwitchesAllowedTime = SystemClock.uptimeMillis() + APP_SWITCH_DELAY_TIME; |
| 4392 | mDidAppSwitch = false; |
| 4393 | getActivityStartController().schedulePendingActivityLaunches(APP_SWITCH_DELAY_TIME); |
| 4394 | } |
| 4395 | } |
| 4396 | |
| 4397 | @Override |
| 4398 | public void resumeAppSwitches() { |
| 4399 | enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "resumeAppSwitches"); |
| 4400 | synchronized (mGlobalLock) { |
| 4401 | // Note that we don't execute any pending app switches... we will |
| 4402 | // let those wait until either the timeout, or the next start |
| 4403 | // activity request. |
| 4404 | mAppSwitchesAllowedTime = 0; |
| 4405 | } |
| 4406 | } |
| 4407 | |
| 4408 | void onStartActivitySetDidAppSwitch() { |
| 4409 | if (mDidAppSwitch) { |
| 4410 | // This is the second allowed switch since we stopped switches, so now just generally |
| 4411 | // allow switches. Use case: |
| 4412 | // - user presses home (switches disabled, switch to home, mDidAppSwitch now true); |
| 4413 | // - user taps a home icon (coming from home so allowed, we hit here and now allow |
| 4414 | // anyone to switch again). |
| 4415 | mAppSwitchesAllowedTime = 0; |
| 4416 | } else { |
| 4417 | mDidAppSwitch = true; |
| 4418 | } |
| 4419 | } |
| 4420 | |
| 4421 | /** @return whether the system should disable UI modes incompatible with VR mode. */ |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4422 | boolean shouldDisableNonVrUiLocked() { |
| 4423 | return mVrController.shouldDisableNonVrUiLocked(); |
| 4424 | } |
| 4425 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4426 | private void applyUpdateVrModeLocked(ActivityRecord r) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4427 | // VR apps are expected to run in a main display. If an app is turning on VR for |
| 4428 | // itself, but lives in a dynamic stack, then make sure that it is moved to the main |
| 4429 | // fullscreen stack before enabling VR Mode. |
| 4430 | // TODO: The goal of this code is to keep the VR app on the main display. When the |
| 4431 | // stack implementation changes in the future, keep in mind that the use of the fullscreen |
| 4432 | // stack is a means to move the activity to the main display and a moveActivityToDisplay() |
| 4433 | // option would be a better choice here. |
| 4434 | if (r.requestedVrComponent != null && r.getDisplayId() != DEFAULT_DISPLAY) { |
| 4435 | Slog.i(TAG, "Moving " + r.shortComponentName + " from stack " + r.getStackId() |
| 4436 | + " to main stack for VR"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4437 | final ActivityStack stack = mRootActivityContainer.getDefaultDisplay().getOrCreateStack( |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4438 | WINDOWING_MODE_FULLSCREEN, r.getActivityType(), true /* toTop */); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4439 | moveTaskToStack(r.getTaskRecord().taskId, stack.mStackId, true /* toTop */); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4440 | } |
| 4441 | mH.post(() -> { |
| 4442 | if (!mVrController.onVrModeChanged(r)) { |
| 4443 | return; |
| 4444 | } |
| 4445 | synchronized (mGlobalLock) { |
| 4446 | final boolean disableNonVrUi = mVrController.shouldDisableNonVrUiLocked(); |
| 4447 | mWindowManager.disableNonVrUi(disableNonVrUi); |
| 4448 | if (disableNonVrUi) { |
| 4449 | // If we are in a VR mode where Picture-in-Picture mode is unsupported, |
| 4450 | // then remove the pinned stack. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4451 | mRootActivityContainer.removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4452 | } |
| 4453 | } |
| 4454 | }); |
| 4455 | } |
| 4456 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4457 | @Override |
| 4458 | public int getPackageScreenCompatMode(String packageName) { |
| 4459 | enforceNotIsolatedCaller("getPackageScreenCompatMode"); |
| 4460 | synchronized (mGlobalLock) { |
| 4461 | return mCompatModePackages.getPackageScreenCompatModeLocked(packageName); |
| 4462 | } |
| 4463 | } |
| 4464 | |
| 4465 | @Override |
| 4466 | public void setPackageScreenCompatMode(String packageName, int mode) { |
| 4467 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4468 | "setPackageScreenCompatMode"); |
| 4469 | synchronized (mGlobalLock) { |
| 4470 | mCompatModePackages.setPackageScreenCompatModeLocked(packageName, mode); |
| 4471 | } |
| 4472 | } |
| 4473 | |
| 4474 | @Override |
| 4475 | public boolean getPackageAskScreenCompat(String packageName) { |
| 4476 | enforceNotIsolatedCaller("getPackageAskScreenCompat"); |
| 4477 | synchronized (mGlobalLock) { |
| 4478 | return mCompatModePackages.getPackageAskCompatModeLocked(packageName); |
| 4479 | } |
| 4480 | } |
| 4481 | |
| 4482 | @Override |
| 4483 | public void setPackageAskScreenCompat(String packageName, boolean ask) { |
| 4484 | mAmInternal.enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY, |
| 4485 | "setPackageAskScreenCompat"); |
| 4486 | synchronized (mGlobalLock) { |
| 4487 | mCompatModePackages.setPackageAskCompatModeLocked(packageName, ask); |
| 4488 | } |
| 4489 | } |
| 4490 | |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 4491 | public static String relaunchReasonToString(int relaunchReason) { |
| 4492 | switch (relaunchReason) { |
| 4493 | case RELAUNCH_REASON_WINDOWING_MODE_RESIZE: |
| 4494 | return "window_resize"; |
| 4495 | case RELAUNCH_REASON_FREE_RESIZE: |
| 4496 | return "free_resize"; |
| 4497 | default: |
| 4498 | return null; |
| 4499 | } |
| 4500 | } |
| 4501 | |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4502 | ActivityStack getTopDisplayFocusedStack() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4503 | return mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4504 | } |
| 4505 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4506 | /** Pokes the task persister. */ |
| 4507 | void notifyTaskPersisterLocked(TaskRecord task, boolean flush) { |
| 4508 | mRecentTasks.notifyTaskPersisterLocked(task, flush); |
| 4509 | } |
| 4510 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4511 | boolean isKeyguardLocked() { |
| 4512 | return mKeyguardController.isKeyguardLocked(); |
| 4513 | } |
| 4514 | |
Garfield Tan | 0154863 | 2018-11-27 10:15:48 -0800 | [diff] [blame] | 4515 | /** |
| 4516 | * Clears launch params for the given package. |
| 4517 | * @param packageNames the names of the packages of which the launch params are to be cleared |
| 4518 | */ |
| 4519 | @Override |
| 4520 | public void clearLaunchParamsForPackages(List<String> packageNames) { |
| 4521 | mAmInternal.enforceCallingPermission(Manifest.permission.MANAGE_ACTIVITY_STACKS, |
| 4522 | "clearLaunchParamsForPackages"); |
| 4523 | synchronized (mGlobalLock) { |
| 4524 | for (int i = 0; i < packageNames.size(); ++i) { |
| 4525 | mStackSupervisor.mLaunchParamsPersister.removeRecordForPackage(packageNames.get(i)); |
| 4526 | } |
| 4527 | } |
| 4528 | } |
| 4529 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4530 | void dumpLastANRLocked(PrintWriter pw) { |
| 4531 | pw.println("ACTIVITY MANAGER LAST ANR (dumpsys activity lastanr)"); |
| 4532 | if (mLastANRState == null) { |
| 4533 | pw.println(" <no ANR has occurred since boot>"); |
| 4534 | } else { |
| 4535 | pw.println(mLastANRState); |
| 4536 | } |
| 4537 | } |
| 4538 | |
| 4539 | void dumpLastANRTracesLocked(PrintWriter pw) { |
| 4540 | pw.println("ACTIVITY MANAGER LAST ANR TRACES (dumpsys activity lastanr-traces)"); |
| 4541 | |
| 4542 | final File[] files = new File(ANR_TRACE_DIR).listFiles(); |
| 4543 | if (ArrayUtils.isEmpty(files)) { |
| 4544 | pw.println(" <no ANR has occurred since boot>"); |
| 4545 | return; |
| 4546 | } |
| 4547 | // Find the latest file. |
| 4548 | File latest = null; |
| 4549 | for (File f : files) { |
| 4550 | if ((latest == null) || (latest.lastModified() < f.lastModified())) { |
| 4551 | latest = f; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4552 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4553 | } |
| 4554 | pw.print("File: "); |
| 4555 | pw.print(latest.getName()); |
| 4556 | pw.println(); |
| 4557 | try (BufferedReader in = new BufferedReader(new FileReader(latest))) { |
| 4558 | String line; |
| 4559 | while ((line = in.readLine()) != null) { |
| 4560 | pw.println(line); |
| 4561 | } |
| 4562 | } catch (IOException e) { |
| 4563 | pw.print("Unable to read: "); |
| 4564 | pw.print(e); |
| 4565 | pw.println(); |
| 4566 | } |
| 4567 | } |
| 4568 | |
| 4569 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4570 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 4571 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage, |
| 4572 | "ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)"); |
| 4573 | } |
| 4574 | |
| 4575 | void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args, |
| 4576 | int opti, boolean dumpAll, boolean dumpClient, String dumpPackage, String header) { |
| 4577 | pw.println(header); |
| 4578 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4579 | boolean printedAnything = mRootActivityContainer.dumpActivities(fd, pw, dumpAll, dumpClient, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4580 | dumpPackage); |
| 4581 | boolean needSep = printedAnything; |
| 4582 | |
| 4583 | boolean printed = ActivityStackSupervisor.printThisActivity(pw, |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4584 | mRootActivityContainer.getTopResumedActivity(), dumpPackage, needSep, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4585 | " ResumedActivity: "); |
| 4586 | if (printed) { |
| 4587 | printedAnything = true; |
| 4588 | needSep = false; |
| 4589 | } |
| 4590 | |
| 4591 | if (dumpPackage == null) { |
| 4592 | if (needSep) { |
| 4593 | pw.println(); |
| 4594 | } |
| 4595 | printedAnything = true; |
| 4596 | mStackSupervisor.dump(pw, " "); |
| 4597 | } |
| 4598 | |
| 4599 | if (!printedAnything) { |
| 4600 | pw.println(" (nothing)"); |
| 4601 | } |
| 4602 | } |
| 4603 | |
| 4604 | void dumpActivityContainersLocked(PrintWriter pw) { |
| 4605 | pw.println("ACTIVITY MANAGER STARTER (dumpsys activity containers)"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4606 | mRootActivityContainer.dumpChildrenNames(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4607 | pw.println(" "); |
| 4608 | } |
| 4609 | |
| 4610 | void dumpActivityStarterLocked(PrintWriter pw, String dumpPackage) { |
| 4611 | pw.println("ACTIVITY MANAGER STARTER (dumpsys activity starter)"); |
| 4612 | getActivityStartController().dump(pw, "", dumpPackage); |
| 4613 | } |
| 4614 | |
| 4615 | /** |
| 4616 | * There are three things that cmd can be: |
| 4617 | * - a flattened component name that matches an existing activity |
| 4618 | * - the cmd arg isn't the flattened component name of an existing activity: |
| 4619 | * dump all activity whose component contains the cmd as a substring |
| 4620 | * - A hex number of the ActivityRecord object instance. |
| 4621 | * |
| 4622 | * @param dumpVisibleStacksOnly dump activity with {@param name} only if in a visible stack |
| 4623 | * @param dumpFocusedStackOnly dump activity with {@param name} only if in the focused stack |
| 4624 | */ |
| 4625 | protected boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, String[] args, |
| 4626 | int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, boolean dumpFocusedStackOnly) { |
| 4627 | ArrayList<ActivityRecord> activities; |
| 4628 | |
| 4629 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4630 | activities = mRootActivityContainer.getDumpActivities(name, dumpVisibleStacksOnly, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4631 | dumpFocusedStackOnly); |
| 4632 | } |
| 4633 | |
| 4634 | if (activities.size() <= 0) { |
| 4635 | return false; |
| 4636 | } |
| 4637 | |
| 4638 | String[] newArgs = new String[args.length - opti]; |
| 4639 | System.arraycopy(args, opti, newArgs, 0, args.length - opti); |
| 4640 | |
| 4641 | TaskRecord lastTask = null; |
| 4642 | boolean needSep = false; |
| 4643 | for (int i = activities.size() - 1; i >= 0; i--) { |
| 4644 | ActivityRecord r = activities.get(i); |
| 4645 | if (needSep) { |
| 4646 | pw.println(); |
| 4647 | } |
| 4648 | needSep = true; |
| 4649 | synchronized (mGlobalLock) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4650 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 4651 | if (lastTask != task) { |
| 4652 | lastTask = task; |
| 4653 | pw.print("TASK "); pw.print(lastTask.affinity); |
| 4654 | pw.print(" id="); pw.print(lastTask.taskId); |
| 4655 | pw.print(" userId="); pw.println(lastTask.userId); |
| 4656 | if (dumpAll) { |
| 4657 | lastTask.dump(pw, " "); |
| 4658 | } |
| 4659 | } |
| 4660 | } |
| 4661 | dumpActivity(" ", fd, pw, activities.get(i), newArgs, dumpAll); |
| 4662 | } |
| 4663 | return true; |
| 4664 | } |
| 4665 | |
| 4666 | /** |
| 4667 | * Invokes IApplicationThread.dumpActivity() on the thread of the specified activity if |
| 4668 | * there is a thread associated with the activity. |
| 4669 | */ |
| 4670 | private void dumpActivity(String prefix, FileDescriptor fd, PrintWriter pw, |
| 4671 | final ActivityRecord r, String[] args, boolean dumpAll) { |
| 4672 | String innerPrefix = prefix + " "; |
| 4673 | synchronized (mGlobalLock) { |
| 4674 | pw.print(prefix); pw.print("ACTIVITY "); pw.print(r.shortComponentName); |
| 4675 | pw.print(" "); pw.print(Integer.toHexString(System.identityHashCode(r))); |
| 4676 | pw.print(" pid="); |
| 4677 | if (r.hasProcess()) pw.println(r.app.getPid()); |
| 4678 | else pw.println("(not running)"); |
| 4679 | if (dumpAll) { |
| 4680 | r.dump(pw, innerPrefix); |
| 4681 | } |
| 4682 | } |
| 4683 | if (r.attachedToProcess()) { |
| 4684 | // flush anything that is already in the PrintWriter since the thread is going |
| 4685 | // to write to the file descriptor directly |
| 4686 | pw.flush(); |
| 4687 | try { |
| 4688 | TransferPipe tp = new TransferPipe(); |
| 4689 | try { |
| 4690 | r.app.getThread().dumpActivity(tp.getWriteFd(), |
| 4691 | r.appToken, innerPrefix, args); |
| 4692 | tp.go(fd); |
| 4693 | } finally { |
| 4694 | tp.kill(); |
| 4695 | } |
| 4696 | } catch (IOException e) { |
| 4697 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 4698 | } catch (RemoteException e) { |
| 4699 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 4700 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4701 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4702 | } |
| 4703 | |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame^] | 4704 | private void writeSleepStateToProto(ProtoOutputStream proto, int wakeFullness, |
| 4705 | boolean testPssMode) { |
| 4706 | final long sleepToken = proto.start(ActivityManagerServiceDumpProcessesProto.SLEEP_STATUS); |
| 4707 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.WAKEFULNESS, |
| 4708 | PowerManagerInternal.wakefulnessToProtoEnum(wakeFullness)); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4709 | for (ActivityTaskManagerInternal.SleepToken st : mRootActivityContainer.mSleepTokens) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4710 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEP_TOKENS, |
| 4711 | st.toString()); |
| 4712 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4713 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEPING, mSleeping); |
| 4714 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SHUTTING_DOWN, |
| 4715 | mShuttingDown); |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame^] | 4716 | proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.TEST_PSS_MODE, |
| 4717 | testPssMode); |
| 4718 | proto.end(sleepToken); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 4719 | } |
| 4720 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4721 | int getCurrentUserId() { |
| 4722 | return mAmInternal.getCurrentUserId(); |
| 4723 | } |
| 4724 | |
| 4725 | private void enforceNotIsolatedCaller(String caller) { |
| 4726 | if (UserHandle.isIsolated(Binder.getCallingUid())) { |
| 4727 | throw new SecurityException("Isolated process not allowed to call " + caller); |
| 4728 | } |
| 4729 | } |
| 4730 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4731 | public Configuration getConfiguration() { |
| 4732 | Configuration ci; |
| 4733 | synchronized(mGlobalLock) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 4734 | ci = new Configuration(getGlobalConfigurationForCallingPid()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4735 | ci.userSetLocale = false; |
| 4736 | } |
| 4737 | return ci; |
| 4738 | } |
| 4739 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4740 | /** |
| 4741 | * Current global configuration information. Contains general settings for the entire system, |
| 4742 | * also corresponds to the merged configuration of the default display. |
| 4743 | */ |
| 4744 | Configuration getGlobalConfiguration() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4745 | return mRootActivityContainer.getConfiguration(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 4749 | boolean initLocale) { |
| 4750 | return updateConfigurationLocked(values, starting, initLocale, false /* deferResume */); |
| 4751 | } |
| 4752 | |
| 4753 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 4754 | boolean initLocale, boolean deferResume) { |
| 4755 | // pass UserHandle.USER_NULL as userId because we don't persist configuration for any user |
| 4756 | return updateConfigurationLocked(values, starting, initLocale, false /* persistent */, |
| 4757 | UserHandle.USER_NULL, deferResume); |
| 4758 | } |
| 4759 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 4760 | public void updatePersistentConfiguration(Configuration values, @UserIdInt int userId) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4761 | final long origId = Binder.clearCallingIdentity(); |
| 4762 | try { |
| 4763 | synchronized (mGlobalLock) { |
| 4764 | updateConfigurationLocked(values, null, false, true, userId, |
| 4765 | false /* deferResume */); |
| 4766 | } |
| 4767 | } finally { |
| 4768 | Binder.restoreCallingIdentity(origId); |
| 4769 | } |
| 4770 | } |
| 4771 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4772 | private boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 4773 | boolean initLocale, boolean persistent, int userId, boolean deferResume) { |
| 4774 | return updateConfigurationLocked(values, starting, initLocale, persistent, userId, |
| 4775 | deferResume, null /* result */); |
| 4776 | } |
| 4777 | |
| 4778 | /** |
| 4779 | * Do either or both things: (1) change the current configuration, and (2) |
| 4780 | * make sure the given activity is running with the (now) current |
| 4781 | * configuration. Returns true if the activity has been left running, or |
| 4782 | * false if <var>starting</var> is being destroyed to match the new |
| 4783 | * configuration. |
| 4784 | * |
| 4785 | * @param userId is only used when persistent parameter is set to true to persist configuration |
| 4786 | * for that particular user |
| 4787 | */ |
| 4788 | boolean updateConfigurationLocked(Configuration values, ActivityRecord starting, |
| 4789 | boolean initLocale, boolean persistent, int userId, boolean deferResume, |
| 4790 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 4791 | int changes = 0; |
| 4792 | boolean kept = true; |
| 4793 | |
| 4794 | if (mWindowManager != null) { |
| 4795 | mWindowManager.deferSurfaceLayout(); |
| 4796 | } |
| 4797 | try { |
| 4798 | if (values != null) { |
| 4799 | changes = updateGlobalConfigurationLocked(values, initLocale, persistent, userId, |
| 4800 | deferResume); |
| 4801 | } |
| 4802 | |
| 4803 | kept = ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 4804 | } finally { |
| 4805 | if (mWindowManager != null) { |
| 4806 | mWindowManager.continueSurfaceLayout(); |
| 4807 | } |
| 4808 | } |
| 4809 | |
| 4810 | if (result != null) { |
| 4811 | result.changes = changes; |
| 4812 | result.activityRelaunched = !kept; |
| 4813 | } |
| 4814 | return kept; |
| 4815 | } |
| 4816 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4817 | /** Update default (global) configuration and notify listeners about changes. */ |
| 4818 | private int updateGlobalConfigurationLocked(@NonNull Configuration values, boolean initLocale, |
| 4819 | boolean persistent, int userId, boolean deferResume) { |
| 4820 | mTempConfig.setTo(getGlobalConfiguration()); |
| 4821 | final int changes = mTempConfig.updateFrom(values); |
| 4822 | if (changes == 0) { |
| 4823 | // Since calling to Activity.setRequestedOrientation leads to freezing the window with |
| 4824 | // setting WindowManagerService.mWaitingForConfig to true, it is important that we call |
| 4825 | // performDisplayOverrideConfigUpdate in order to send the new display configuration |
| 4826 | // (even if there are no actual changes) to unfreeze the window. |
| 4827 | performDisplayOverrideConfigUpdate(values, deferResume, DEFAULT_DISPLAY); |
| 4828 | return 0; |
| 4829 | } |
| 4830 | |
| 4831 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.i(TAG_CONFIGURATION, |
| 4832 | "Updating global configuration to: " + values); |
| 4833 | |
| 4834 | EventLog.writeEvent(EventLogTags.CONFIGURATION_CHANGED, changes); |
| 4835 | StatsLog.write(StatsLog.RESOURCE_CONFIGURATION_CHANGED, |
| 4836 | values.colorMode, |
| 4837 | values.densityDpi, |
| 4838 | values.fontScale, |
| 4839 | values.hardKeyboardHidden, |
| 4840 | values.keyboard, |
| 4841 | values.keyboardHidden, |
| 4842 | values.mcc, |
| 4843 | values.mnc, |
| 4844 | values.navigation, |
| 4845 | values.navigationHidden, |
| 4846 | values.orientation, |
| 4847 | values.screenHeightDp, |
| 4848 | values.screenLayout, |
| 4849 | values.screenWidthDp, |
| 4850 | values.smallestScreenWidthDp, |
| 4851 | values.touchscreen, |
| 4852 | values.uiMode); |
| 4853 | |
| 4854 | |
| 4855 | if (!initLocale && !values.getLocales().isEmpty() && values.userSetLocale) { |
| 4856 | final LocaleList locales = values.getLocales(); |
| 4857 | int bestLocaleIndex = 0; |
| 4858 | if (locales.size() > 1) { |
| 4859 | if (mSupportedSystemLocales == null) { |
| 4860 | mSupportedSystemLocales = Resources.getSystem().getAssets().getLocales(); |
| 4861 | } |
| 4862 | bestLocaleIndex = Math.max(0, locales.getFirstMatchIndex(mSupportedSystemLocales)); |
| 4863 | } |
| 4864 | SystemProperties.set("persist.sys.locale", |
| 4865 | locales.get(bestLocaleIndex).toLanguageTag()); |
| 4866 | LocaleList.setDefault(locales, bestLocaleIndex); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4867 | |
| 4868 | final Message m = PooledLambda.obtainMessage( |
| 4869 | ActivityTaskManagerService::sendLocaleToMountDaemonMsg, this, |
| 4870 | locales.get(bestLocaleIndex)); |
| 4871 | mH.sendMessage(m); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4872 | } |
| 4873 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 4874 | mTempConfig.seq = increaseConfigurationSeqLocked(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4875 | |
| 4876 | // Update stored global config and notify everyone about the change. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4877 | mRootActivityContainer.onConfigurationChanged(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4878 | |
| 4879 | Slog.i(TAG, "Config changes=" + Integer.toHexString(changes) + " " + mTempConfig); |
| 4880 | // TODO(multi-display): Update UsageEvents#Event to include displayId. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4881 | mUsageStatsInternal.reportConfigurationChange(mTempConfig, mAmInternal.getCurrentUserId()); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4882 | |
| 4883 | // 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] | 4884 | updateShouldShowDialogsLocked(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4885 | |
| 4886 | AttributeCache ac = AttributeCache.instance(); |
| 4887 | if (ac != null) { |
| 4888 | ac.updateConfiguration(mTempConfig); |
| 4889 | } |
| 4890 | |
| 4891 | // Make sure all resources in our process are updated right now, so that anyone who is going |
| 4892 | // to retrieve resource values after we return will be sure to get the new ones. This is |
| 4893 | // especially important during boot, where the first config change needs to guarantee all |
| 4894 | // resources have that config before following boot code is executed. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4895 | mSystemThread.applyConfigurationToResources(mTempConfig); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4896 | |
| 4897 | // We need another copy of global config because we're scheduling some calls instead of |
| 4898 | // running them in place. We need to be sure that object we send will be handled unchanged. |
| 4899 | final Configuration configCopy = new Configuration(mTempConfig); |
| 4900 | if (persistent && Settings.System.hasInterestingConfigurationChanges(changes)) { |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 4901 | final Message msg = PooledLambda.obtainMessage( |
| 4902 | ActivityTaskManagerService::sendPutConfigurationForUserMsg, |
| 4903 | this, userId, configCopy); |
| 4904 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4905 | } |
| 4906 | |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 4907 | for (int i = mPidMap.size() - 1; i >= 0; i--) { |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 4908 | final int pid = mPidMap.keyAt(i); |
| 4909 | final WindowProcessController app = mPidMap.get(pid); |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 4910 | if (DEBUG_CONFIGURATION) { |
| 4911 | Slog.v(TAG_CONFIGURATION, "Update process config of " |
| 4912 | + app.mName + " to new config " + configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4913 | } |
Yunfan Chen | 34fcc7a | 2018-10-11 16:26:09 -0700 | [diff] [blame] | 4914 | app.onConfigurationChanged(configCopy); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4915 | } |
| 4916 | |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 4917 | final Message msg = PooledLambda.obtainMessage( |
| 4918 | ActivityManagerInternal::broadcastGlobalConfigurationChanged, |
| 4919 | mAmInternal, changes, initLocale); |
| 4920 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4921 | |
| 4922 | // Override configuration of the default display duplicates global config, so we need to |
| 4923 | // update it also. This will also notify WindowManager about changes. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4924 | performDisplayOverrideConfigUpdate(mRootActivityContainer.getConfiguration(), deferResume, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4925 | DEFAULT_DISPLAY); |
| 4926 | |
| 4927 | return changes; |
| 4928 | } |
| 4929 | |
| 4930 | boolean updateDisplayOverrideConfigurationLocked(Configuration values, ActivityRecord starting, |
| 4931 | boolean deferResume, int displayId) { |
| 4932 | return updateDisplayOverrideConfigurationLocked(values, starting, deferResume /* deferResume */, |
| 4933 | displayId, null /* result */); |
| 4934 | } |
| 4935 | |
| 4936 | /** |
| 4937 | * Updates override configuration specific for the selected display. If no config is provided, |
| 4938 | * new one will be computed in WM based on current display info. |
| 4939 | */ |
| 4940 | boolean updateDisplayOverrideConfigurationLocked(Configuration values, |
| 4941 | ActivityRecord starting, boolean deferResume, int displayId, |
| 4942 | ActivityTaskManagerService.UpdateConfigurationResult result) { |
| 4943 | int changes = 0; |
| 4944 | boolean kept = true; |
| 4945 | |
| 4946 | if (mWindowManager != null) { |
| 4947 | mWindowManager.deferSurfaceLayout(); |
| 4948 | } |
| 4949 | try { |
| 4950 | if (values != null) { |
| 4951 | if (displayId == DEFAULT_DISPLAY) { |
| 4952 | // Override configuration of the default display duplicates global config, so |
| 4953 | // we're calling global config update instead for default display. It will also |
| 4954 | // apply the correct override config. |
| 4955 | changes = updateGlobalConfigurationLocked(values, false /* initLocale */, |
| 4956 | false /* persistent */, UserHandle.USER_NULL /* userId */, deferResume); |
| 4957 | } else { |
| 4958 | changes = performDisplayOverrideConfigUpdate(values, deferResume, displayId); |
| 4959 | } |
| 4960 | } |
| 4961 | |
| 4962 | kept = ensureConfigAndVisibilityAfterUpdate(starting, changes); |
| 4963 | } finally { |
| 4964 | if (mWindowManager != null) { |
| 4965 | mWindowManager.continueSurfaceLayout(); |
| 4966 | } |
| 4967 | } |
| 4968 | |
| 4969 | if (result != null) { |
| 4970 | result.changes = changes; |
| 4971 | result.activityRelaunched = !kept; |
| 4972 | } |
| 4973 | return kept; |
| 4974 | } |
| 4975 | |
| 4976 | private int performDisplayOverrideConfigUpdate(Configuration values, boolean deferResume, |
| 4977 | int displayId) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4978 | mTempConfig.setTo(mRootActivityContainer.getDisplayOverrideConfiguration(displayId)); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4979 | final int changes = mTempConfig.updateFrom(values); |
| 4980 | if (changes != 0) { |
| 4981 | Slog.i(TAG, "Override config changes=" + Integer.toHexString(changes) + " " |
| 4982 | + mTempConfig + " for displayId=" + displayId); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4983 | mRootActivityContainer.setDisplayOverrideConfiguration(mTempConfig, displayId); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4984 | |
| 4985 | final boolean isDensityChange = (changes & ActivityInfo.CONFIG_DENSITY) != 0; |
| 4986 | if (isDensityChange && displayId == DEFAULT_DISPLAY) { |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 4987 | mAppWarnings.onDensityChanged(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4988 | |
Wale Ogunwale | 5c91870 | 2018-10-18 11:06:33 -0700 | [diff] [blame] | 4989 | // Post message to start process to avoid possible deadlock of calling into AMS with |
| 4990 | // the ATMS lock held. |
| 4991 | final Message msg = PooledLambda.obtainMessage( |
| 4992 | ActivityManagerInternal::killAllBackgroundProcessesExcept, mAmInternal, |
| 4993 | N, ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE); |
| 4994 | mH.sendMessage(msg); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4995 | } |
| 4996 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4997 | return changes; |
| 4998 | } |
| 4999 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5000 | private void updateEventDispatchingLocked(boolean booted) { |
| 5001 | mWindowManager.setEventDispatching(booted && !mShuttingDown); |
| 5002 | } |
| 5003 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5004 | private void sendPutConfigurationForUserMsg(int userId, Configuration config) { |
| 5005 | final ContentResolver resolver = mContext.getContentResolver(); |
| 5006 | Settings.System.putConfigurationForUser(resolver, config, userId); |
| 5007 | } |
| 5008 | |
| 5009 | private void sendLocaleToMountDaemonMsg(Locale l) { |
| 5010 | try { |
| 5011 | IBinder service = ServiceManager.getService("mount"); |
| 5012 | IStorageManager storageManager = IStorageManager.Stub.asInterface(service); |
| 5013 | Log.d(TAG, "Storing locale " + l.toLanguageTag() + " for decryption UI"); |
| 5014 | storageManager.setField(StorageManager.SYSTEM_LOCALE_KEY, l.toLanguageTag()); |
| 5015 | } catch (RemoteException e) { |
| 5016 | Log.e(TAG, "Error storing locale for decryption UI", e); |
| 5017 | } |
| 5018 | } |
| 5019 | |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5020 | private void expireStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5021 | mStartActivitySources.remove(permissionToken); |
| 5022 | mExpiredStartAsCallerTokens.add(permissionToken); |
| 5023 | } |
| 5024 | |
| 5025 | private void forgetStartAsCallerTokenMsg(IBinder permissionToken) { |
| 5026 | mExpiredStartAsCallerTokens.remove(permissionToken); |
| 5027 | } |
| 5028 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5029 | boolean isActivityStartsLoggingEnabled() { |
| 5030 | return mAmInternal.isActivityStartsLoggingEnabled(); |
| 5031 | } |
| 5032 | |
Michal Karpinski | 8596ded | 2018-11-14 14:43:48 +0000 | [diff] [blame] | 5033 | boolean isBackgroundActivityStartsEnabled() { |
| 5034 | return mAmInternal.isBackgroundActivityStartsEnabled(); |
| 5035 | } |
| 5036 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5037 | void enableScreenAfterBoot(boolean booted) { |
| 5038 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_ENABLE_SCREEN, |
| 5039 | SystemClock.uptimeMillis()); |
| 5040 | mWindowManager.enableScreenAfterBoot(); |
| 5041 | |
| 5042 | synchronized (mGlobalLock) { |
| 5043 | updateEventDispatchingLocked(booted); |
| 5044 | } |
| 5045 | } |
| 5046 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5047 | static long getInputDispatchingTimeoutLocked(ActivityRecord r) { |
| 5048 | if (r == null || !r.hasProcess()) { |
| 5049 | return KEY_DISPATCHING_TIMEOUT_MS; |
| 5050 | } |
| 5051 | return getInputDispatchingTimeoutLocked(r.app); |
| 5052 | } |
| 5053 | |
| 5054 | private static long getInputDispatchingTimeoutLocked(WindowProcessController r) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 5055 | return r != null ? r.getInputDispatchingTimeout() : KEY_DISPATCHING_TIMEOUT_MS; |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5056 | } |
| 5057 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5058 | /** |
| 5059 | * Decide based on the configuration whether we should show the ANR, |
| 5060 | * crash, etc dialogs. The idea is that if there is no affordance to |
| 5061 | * press the on-screen buttons, or the user experience would be more |
| 5062 | * greatly impacted than the crash itself, we shouldn't show the dialog. |
| 5063 | * |
| 5064 | * A thought: SystemUI might also want to get told about this, the Power |
| 5065 | * dialog / global actions also might want different behaviors. |
| 5066 | */ |
| 5067 | private void updateShouldShowDialogsLocked(Configuration config) { |
| 5068 | final boolean inputMethodExists = !(config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 5069 | && config.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH |
| 5070 | && config.navigation == Configuration.NAVIGATION_NONAV); |
| 5071 | int modeType = config.uiMode & Configuration.UI_MODE_TYPE_MASK; |
| 5072 | final boolean uiModeSupportsDialogs = (modeType != Configuration.UI_MODE_TYPE_CAR |
| 5073 | && !(modeType == Configuration.UI_MODE_TYPE_WATCH && Build.IS_USER) |
| 5074 | && modeType != Configuration.UI_MODE_TYPE_TELEVISION |
| 5075 | && modeType != Configuration.UI_MODE_TYPE_VR_HEADSET); |
| 5076 | final boolean hideDialogsSet = Settings.Global.getInt(mContext.getContentResolver(), |
| 5077 | HIDE_ERROR_DIALOGS, 0) != 0; |
| 5078 | mShowDialogs = inputMethodExists && uiModeSupportsDialogs && !hideDialogsSet; |
| 5079 | } |
| 5080 | |
| 5081 | private void updateFontScaleIfNeeded(@UserIdInt int userId) { |
| 5082 | final float scaleFactor = Settings.System.getFloatForUser(mContext.getContentResolver(), |
| 5083 | FONT_SCALE, 1.0f, userId); |
| 5084 | |
| 5085 | synchronized (this) { |
| 5086 | if (getGlobalConfiguration().fontScale == scaleFactor) { |
| 5087 | return; |
| 5088 | } |
| 5089 | |
| 5090 | final Configuration configuration |
| 5091 | = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY); |
| 5092 | configuration.fontScale = scaleFactor; |
| 5093 | updatePersistentConfiguration(configuration, userId); |
| 5094 | } |
| 5095 | } |
| 5096 | |
| 5097 | // Actually is sleeping or shutting down or whatever else in the future |
| 5098 | // is an inactive state. |
| 5099 | boolean isSleepingOrShuttingDownLocked() { |
| 5100 | return isSleepingLocked() || mShuttingDown; |
| 5101 | } |
| 5102 | |
| 5103 | boolean isSleepingLocked() { |
| 5104 | return mSleeping; |
| 5105 | } |
| 5106 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5107 | /** Update AMS states when an activity is resumed. */ |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5108 | void setResumedActivityUncheckLocked(ActivityRecord r, String reason) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5109 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5110 | if (task.isActivityTypeStandard()) { |
| 5111 | if (mCurAppTimeTracker != r.appTimeTracker) { |
| 5112 | // We are switching app tracking. Complete the current one. |
| 5113 | if (mCurAppTimeTracker != null) { |
| 5114 | mCurAppTimeTracker.stop(); |
| 5115 | mH.obtainMessage( |
| 5116 | REPORT_TIME_TRACKER_MSG, mCurAppTimeTracker).sendToTarget(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5117 | mRootActivityContainer.clearOtherAppTimeTrackers(r.appTimeTracker); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5118 | mCurAppTimeTracker = null; |
| 5119 | } |
| 5120 | if (r.appTimeTracker != null) { |
| 5121 | mCurAppTimeTracker = r.appTimeTracker; |
| 5122 | startTimeTrackingFocusedActivityLocked(); |
| 5123 | } |
| 5124 | } else { |
| 5125 | startTimeTrackingFocusedActivityLocked(); |
| 5126 | } |
| 5127 | } else { |
| 5128 | r.appTimeTracker = null; |
| 5129 | } |
| 5130 | // TODO: VI Maybe r.task.voiceInteractor || r.voiceInteractor != null |
| 5131 | // TODO: Probably not, because we don't want to resume voice on switching |
| 5132 | // back to this activity |
| 5133 | if (task.voiceInteractor != null) { |
| 5134 | startRunningVoiceLocked(task.voiceSession, r.info.applicationInfo.uid); |
| 5135 | } else { |
| 5136 | finishRunningVoiceLocked(); |
| 5137 | |
| 5138 | if (mLastResumedActivity != null) { |
| 5139 | final IVoiceInteractionSession session; |
| 5140 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5141 | final TaskRecord lastResumedActivityTask = mLastResumedActivity.getTaskRecord(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5142 | if (lastResumedActivityTask != null |
| 5143 | && lastResumedActivityTask.voiceSession != null) { |
| 5144 | session = lastResumedActivityTask.voiceSession; |
| 5145 | } else { |
| 5146 | session = mLastResumedActivity.voiceSession; |
| 5147 | } |
| 5148 | |
| 5149 | if (session != null) { |
| 5150 | // We had been in a voice interaction session, but now focused has |
| 5151 | // move to something different. Just finish the session, we can't |
| 5152 | // return to it and retain the proper state and synchronization with |
| 5153 | // the voice interaction service. |
| 5154 | finishVoiceTask(session); |
| 5155 | } |
| 5156 | } |
| 5157 | } |
| 5158 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5159 | if (mLastResumedActivity != null && r.mUserId != mLastResumedActivity.mUserId) { |
| 5160 | mAmInternal.sendForegroundProfileChanged(r.mUserId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5161 | } |
| 5162 | updateResumedAppTrace(r); |
| 5163 | mLastResumedActivity = r; |
| 5164 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 5165 | r.getDisplay().setFocusedApp(r, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5166 | |
| 5167 | applyUpdateLockStateLocked(r); |
| 5168 | applyUpdateVrModeLocked(r); |
| 5169 | |
| 5170 | EventLogTags.writeAmSetResumedActivity( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5171 | r == null ? -1 : r.mUserId, |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5172 | r == null ? "NULL" : r.shortComponentName, |
| 5173 | reason); |
| 5174 | } |
| 5175 | |
| 5176 | ActivityTaskManagerInternal.SleepToken acquireSleepToken(String tag, int displayId) { |
| 5177 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5178 | final ActivityTaskManagerInternal.SleepToken token = |
| 5179 | mRootActivityContainer.createSleepToken(tag, displayId); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5180 | updateSleepIfNeededLocked(); |
| 5181 | return token; |
| 5182 | } |
| 5183 | } |
| 5184 | |
| 5185 | void updateSleepIfNeededLocked() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5186 | final boolean shouldSleep = !mRootActivityContainer.hasAwakeDisplay(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5187 | final boolean wasSleeping = mSleeping; |
| 5188 | boolean updateOomAdj = false; |
| 5189 | |
| 5190 | if (!shouldSleep) { |
| 5191 | // If wasSleeping is true, we need to wake up activity manager state from when |
| 5192 | // we started sleeping. In either case, we need to apply the sleep tokens, which |
| 5193 | // will wake up stacks or put them to sleep as appropriate. |
| 5194 | if (wasSleeping) { |
| 5195 | mSleeping = false; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 5196 | StatsLog.write(StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5197 | StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__AWAKE); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5198 | startTimeTrackingFocusedActivityLocked(); |
| 5199 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP; |
| 5200 | mStackSupervisor.comeOutOfSleepIfNeededLocked(); |
| 5201 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5202 | mRootActivityContainer.applySleepTokens(true /* applyToStacks */); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5203 | if (wasSleeping) { |
| 5204 | updateOomAdj = true; |
| 5205 | } |
| 5206 | } else if (!mSleeping && shouldSleep) { |
| 5207 | mSleeping = true; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 5208 | StatsLog.write(StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED, |
| 5209 | StatsLog.ACTIVITY_MANAGER_SLEEP_STATE_CHANGED__STATE__ASLEEP); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5210 | if (mCurAppTimeTracker != null) { |
| 5211 | mCurAppTimeTracker.stop(); |
| 5212 | } |
| 5213 | mTopProcessState = ActivityManager.PROCESS_STATE_TOP_SLEEPING; |
| 5214 | mStackSupervisor.goingToSleepLocked(); |
| 5215 | updateResumedAppTrace(null /* resumed */); |
| 5216 | updateOomAdj = true; |
| 5217 | } |
| 5218 | if (updateOomAdj) { |
| 5219 | mH.post(mAmInternal::updateOomAdj); |
| 5220 | } |
| 5221 | } |
| 5222 | |
| 5223 | void updateOomAdj() { |
| 5224 | mH.post(mAmInternal::updateOomAdj); |
| 5225 | } |
| 5226 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5227 | void updateCpuStats() { |
| 5228 | mH.post(mAmInternal::updateCpuStats); |
| 5229 | } |
| 5230 | |
| 5231 | void updateUsageStats(ActivityRecord component, boolean resumed) { |
| 5232 | final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::updateUsageStats, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5233 | mAmInternal, component.mActivityComponent, component.app.mUid, component.mUserId, |
| 5234 | resumed); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5235 | mH.sendMessage(m); |
| 5236 | } |
| 5237 | |
| 5238 | void setBooting(boolean booting) { |
| 5239 | mAmInternal.setBooting(booting); |
| 5240 | } |
| 5241 | |
| 5242 | boolean isBooting() { |
| 5243 | return mAmInternal.isBooting(); |
| 5244 | } |
| 5245 | |
| 5246 | void setBooted(boolean booted) { |
| 5247 | mAmInternal.setBooted(booted); |
| 5248 | } |
| 5249 | |
| 5250 | boolean isBooted() { |
| 5251 | return mAmInternal.isBooted(); |
| 5252 | } |
| 5253 | |
| 5254 | void postFinishBooting(boolean finishBooting, boolean enableScreen) { |
| 5255 | mH.post(() -> { |
| 5256 | if (finishBooting) { |
| 5257 | mAmInternal.finishBooting(); |
| 5258 | } |
| 5259 | if (enableScreen) { |
| 5260 | mInternal.enableScreenAfterBoot(isBooted()); |
| 5261 | } |
| 5262 | }); |
| 5263 | } |
| 5264 | |
| 5265 | void setHeavyWeightProcess(ActivityRecord root) { |
| 5266 | mHeavyWeightProcess = root.app; |
| 5267 | final Message m = PooledLambda.obtainMessage( |
| 5268 | ActivityTaskManagerService::postHeavyWeightProcessNotification, this, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5269 | root.app, root.intent, root.mUserId); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5270 | mH.sendMessage(m); |
| 5271 | } |
| 5272 | |
| 5273 | void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
| 5274 | if (mHeavyWeightProcess == null || mHeavyWeightProcess != proc) { |
| 5275 | return; |
| 5276 | } |
| 5277 | |
| 5278 | mHeavyWeightProcess = null; |
| 5279 | final Message m = PooledLambda.obtainMessage( |
| 5280 | ActivityTaskManagerService::cancelHeavyWeightProcessNotification, this, |
| 5281 | proc.mUserId); |
| 5282 | mH.sendMessage(m); |
| 5283 | } |
| 5284 | |
| 5285 | private void cancelHeavyWeightProcessNotification(int userId) { |
| 5286 | final INotificationManager inm = NotificationManager.getService(); |
| 5287 | if (inm == null) { |
| 5288 | return; |
| 5289 | } |
| 5290 | try { |
| 5291 | inm.cancelNotificationWithTag("android", null, |
| 5292 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, userId); |
| 5293 | } catch (RuntimeException e) { |
| 5294 | Slog.w(TAG, "Error canceling notification for service", e); |
| 5295 | } catch (RemoteException e) { |
| 5296 | } |
| 5297 | |
| 5298 | } |
| 5299 | |
| 5300 | private void postHeavyWeightProcessNotification( |
| 5301 | WindowProcessController proc, Intent intent, int userId) { |
| 5302 | if (proc == null) { |
| 5303 | return; |
| 5304 | } |
| 5305 | |
| 5306 | final INotificationManager inm = NotificationManager.getService(); |
| 5307 | if (inm == null) { |
| 5308 | return; |
| 5309 | } |
| 5310 | |
| 5311 | try { |
| 5312 | Context context = mContext.createPackageContext(proc.mInfo.packageName, 0); |
| 5313 | String text = mContext.getString(R.string.heavy_weight_notification, |
| 5314 | context.getApplicationInfo().loadLabel(context.getPackageManager())); |
| 5315 | Notification notification = |
| 5316 | new Notification.Builder(context, |
| 5317 | SystemNotificationChannels.HEAVY_WEIGHT_APP) |
| 5318 | .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) |
| 5319 | .setWhen(0) |
| 5320 | .setOngoing(true) |
| 5321 | .setTicker(text) |
| 5322 | .setColor(mContext.getColor( |
| 5323 | com.android.internal.R.color.system_notification_accent_color)) |
| 5324 | .setContentTitle(text) |
| 5325 | .setContentText( |
| 5326 | mContext.getText(R.string.heavy_weight_notification_detail)) |
| 5327 | .setContentIntent(PendingIntent.getActivityAsUser(mContext, 0, |
| 5328 | intent, PendingIntent.FLAG_CANCEL_CURRENT, null, |
| 5329 | new UserHandle(userId))) |
| 5330 | .build(); |
| 5331 | try { |
| 5332 | inm.enqueueNotificationWithTag("android", "android", null, |
| 5333 | SystemMessage.NOTE_HEAVY_WEIGHT_NOTIFICATION, notification, userId); |
| 5334 | } catch (RuntimeException e) { |
| 5335 | Slog.w(TAG, "Error showing notification for heavy-weight app", e); |
| 5336 | } catch (RemoteException e) { |
| 5337 | } |
| 5338 | } catch (PackageManager.NameNotFoundException e) { |
| 5339 | Slog.w(TAG, "Unable to create context for heavy notification", e); |
| 5340 | } |
| 5341 | |
| 5342 | } |
| 5343 | |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5344 | IIntentSender getIntentSenderLocked(int type, String packageName, int callingUid, int userId, |
| 5345 | IBinder token, String resultWho, int requestCode, Intent[] intents, |
| 5346 | String[] resolvedTypes, int flags, Bundle bOptions) { |
| 5347 | |
| 5348 | ActivityRecord activity = null; |
| 5349 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5350 | activity = ActivityRecord.isInStackLocked(token); |
| 5351 | if (activity == null) { |
| 5352 | Slog.w(TAG, "Failed createPendingResult: activity " + token + " not in any stack"); |
| 5353 | return null; |
| 5354 | } |
| 5355 | if (activity.finishing) { |
| 5356 | Slog.w(TAG, "Failed createPendingResult: activity " + activity + " is finishing"); |
| 5357 | return null; |
| 5358 | } |
| 5359 | } |
| 5360 | |
| 5361 | final PendingIntentRecord rec = mPendingIntentController.getIntentSender(type, packageName, |
| 5362 | callingUid, userId, token, resultWho, requestCode, intents, resolvedTypes, flags, |
| 5363 | bOptions); |
| 5364 | final boolean noCreate = (flags & PendingIntent.FLAG_NO_CREATE) != 0; |
| 5365 | if (noCreate) { |
| 5366 | return rec; |
| 5367 | } |
| 5368 | if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) { |
| 5369 | if (activity.pendingResults == null) { |
| 5370 | activity.pendingResults = new HashSet<>(); |
| 5371 | } |
| 5372 | activity.pendingResults.add(rec.ref); |
| 5373 | } |
| 5374 | return rec; |
| 5375 | } |
| 5376 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 5377 | // 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] | 5378 | private void startTimeTrackingFocusedActivityLocked() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5379 | final ActivityRecord resumedActivity = mRootActivityContainer.getTopResumedActivity(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5380 | if (!mSleeping && mCurAppTimeTracker != null && resumedActivity != null) { |
| 5381 | mCurAppTimeTracker.start(resumedActivity.packageName); |
| 5382 | } |
| 5383 | } |
| 5384 | |
| 5385 | private void updateResumedAppTrace(@Nullable ActivityRecord resumed) { |
| 5386 | if (mTracedResumedActivity != null) { |
| 5387 | Trace.asyncTraceEnd(TRACE_TAG_ACTIVITY_MANAGER, |
| 5388 | constructResumedTraceName(mTracedResumedActivity.packageName), 0); |
| 5389 | } |
| 5390 | if (resumed != null) { |
| 5391 | Trace.asyncTraceBegin(TRACE_TAG_ACTIVITY_MANAGER, |
| 5392 | constructResumedTraceName(resumed.packageName), 0); |
| 5393 | } |
| 5394 | mTracedResumedActivity = resumed; |
| 5395 | } |
| 5396 | |
| 5397 | private String constructResumedTraceName(String packageName) { |
| 5398 | return "focused app: " + packageName; |
| 5399 | } |
| 5400 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5401 | /** Applies latest configuration and/or visibility updates if needed. */ |
| 5402 | private boolean ensureConfigAndVisibilityAfterUpdate(ActivityRecord starting, int changes) { |
| 5403 | boolean kept = true; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5404 | final ActivityStack mainStack = mRootActivityContainer.getTopDisplayFocusedStack(); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5405 | // mainStack is null during startup. |
| 5406 | if (mainStack != null) { |
| 5407 | if (changes != 0 && starting == null) { |
| 5408 | // If the configuration changed, and the caller is not already |
| 5409 | // in the process of starting an activity, then find the top |
| 5410 | // activity to check if its configuration needs to change. |
| 5411 | starting = mainStack.topRunningActivityLocked(); |
| 5412 | } |
| 5413 | |
| 5414 | if (starting != null) { |
| 5415 | kept = starting.ensureActivityConfiguration(changes, |
| 5416 | false /* preserveWindow */); |
| 5417 | // And we need to make sure at this point that all other activities |
| 5418 | // are made visible with the correct configuration. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5419 | mRootActivityContainer.ensureActivitiesVisible(starting, changes, |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5420 | !PRESERVE_WINDOWS); |
| 5421 | } |
| 5422 | } |
| 5423 | |
| 5424 | return kept; |
| 5425 | } |
| 5426 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5427 | void scheduleAppGcsLocked() { |
| 5428 | mH.post(() -> mAmInternal.scheduleAppGcs()); |
| 5429 | } |
| 5430 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5431 | CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) { |
| 5432 | return mCompatModePackages.compatibilityInfoForPackageLocked(ai); |
| 5433 | } |
| 5434 | |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 5435 | /** |
| 5436 | * Returns the PackageManager. Used by classes hosted by {@link ActivityTaskManagerService}. The |
| 5437 | * PackageManager could be unavailable at construction time and therefore needs to be accessed |
| 5438 | * on demand. |
| 5439 | */ |
| 5440 | IPackageManager getPackageManager() { |
| 5441 | return AppGlobals.getPackageManager(); |
| 5442 | } |
| 5443 | |
| 5444 | PackageManagerInternal getPackageManagerInternalLocked() { |
| 5445 | if (mPmInternal == null) { |
| 5446 | mPmInternal = LocalServices.getService(PackageManagerInternal.class); |
| 5447 | } |
| 5448 | return mPmInternal; |
| 5449 | } |
| 5450 | |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 5451 | AppWarnings getAppWarningsLocked() { |
| 5452 | return mAppWarnings; |
| 5453 | } |
| 5454 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5455 | Intent getHomeIntent() { |
| 5456 | Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null); |
| 5457 | intent.setComponent(mTopComponent); |
| 5458 | intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); |
| 5459 | if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) { |
| 5460 | intent.addCategory(Intent.CATEGORY_HOME); |
| 5461 | } |
| 5462 | return intent; |
| 5463 | } |
| 5464 | |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5465 | ApplicationInfo getAppInfoForUser(ApplicationInfo info, int userId) { |
| 5466 | if (info == null) return null; |
| 5467 | ApplicationInfo newInfo = new ApplicationInfo(info); |
| 5468 | newInfo.initForUser(userId); |
| 5469 | return newInfo; |
| 5470 | } |
| 5471 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 5472 | WindowProcessController getProcessController(String processName, int uid) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 5473 | if (uid == SYSTEM_UID) { |
| 5474 | // The system gets to run in any process. If there are multiple processes with the same |
| 5475 | // uid, just pick the first (this should never happen). |
| 5476 | final SparseArray<WindowProcessController> procs = |
| 5477 | mProcessNames.getMap().get(processName); |
| 5478 | if (procs == null) return null; |
| 5479 | final int procCount = procs.size(); |
| 5480 | for (int i = 0; i < procCount; i++) { |
| 5481 | final int procUid = procs.keyAt(i); |
| 5482 | if (UserHandle.isApp(procUid) || !UserHandle.isSameUser(procUid, uid)) { |
| 5483 | // Don't use an app process or different user process for system component. |
| 5484 | continue; |
| 5485 | } |
| 5486 | return procs.valueAt(i); |
| 5487 | } |
| 5488 | } |
| 5489 | |
| 5490 | return mProcessNames.get(processName, uid); |
| 5491 | } |
| 5492 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 5493 | WindowProcessController getProcessController(IApplicationThread thread) { |
| 5494 | if (thread == null) { |
| 5495 | return null; |
| 5496 | } |
| 5497 | |
| 5498 | final IBinder threadBinder = thread.asBinder(); |
| 5499 | final ArrayMap<String, SparseArray<WindowProcessController>> pmap = mProcessNames.getMap(); |
| 5500 | for (int i = pmap.size()-1; i >= 0; i--) { |
| 5501 | final SparseArray<WindowProcessController> procs = pmap.valueAt(i); |
| 5502 | for (int j = procs.size() - 1; j >= 0; j--) { |
| 5503 | final WindowProcessController proc = procs.valueAt(j); |
| 5504 | if (proc.hasThread() && proc.getThread().asBinder() == threadBinder) { |
| 5505 | return proc; |
| 5506 | } |
| 5507 | } |
| 5508 | } |
| 5509 | |
| 5510 | return null; |
| 5511 | } |
| 5512 | |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 5513 | int getUidStateLocked(int uid) { |
| 5514 | return mActiveUids.get(uid, PROCESS_STATE_NONEXISTENT); |
| 5515 | } |
| 5516 | |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 5517 | /** |
| 5518 | * @return whitelist tag for a uid from mPendingTempWhitelist, null if not currently on |
| 5519 | * the whitelist |
| 5520 | */ |
| 5521 | String getPendingTempWhitelistTagForUidLocked(int uid) { |
| 5522 | return mPendingTempWhitelist.get(uid); |
| 5523 | } |
| 5524 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5525 | void logAppTooSlow(WindowProcessController app, long startTime, String msg) { |
| 5526 | if (true || Build.IS_USER) { |
| 5527 | return; |
| 5528 | } |
| 5529 | |
| 5530 | StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 5531 | StrictMode.allowThreadDiskWrites(); |
| 5532 | try { |
| 5533 | File tracesDir = new File("/data/anr"); |
| 5534 | File tracesFile = null; |
| 5535 | try { |
| 5536 | tracesFile = File.createTempFile("app_slow", null, tracesDir); |
| 5537 | |
| 5538 | StringBuilder sb = new StringBuilder(); |
| 5539 | Time tobj = new Time(); |
| 5540 | tobj.set(System.currentTimeMillis()); |
| 5541 | sb.append(tobj.format("%Y-%m-%d %H:%M:%S")); |
| 5542 | sb.append(": "); |
| 5543 | TimeUtils.formatDuration(SystemClock.uptimeMillis()-startTime, sb); |
| 5544 | sb.append(" since "); |
| 5545 | sb.append(msg); |
| 5546 | FileOutputStream fos = new FileOutputStream(tracesFile); |
| 5547 | fos.write(sb.toString().getBytes()); |
| 5548 | if (app == null) { |
| 5549 | fos.write("\n*** No application process!".getBytes()); |
| 5550 | } |
| 5551 | fos.close(); |
| 5552 | FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1); // -rw-rw-rw- |
| 5553 | } catch (IOException e) { |
| 5554 | Slog.w(TAG, "Unable to prepare slow app traces file: " + tracesFile, e); |
| 5555 | return; |
| 5556 | } |
| 5557 | |
| 5558 | if (app != null && app.getPid() > 0) { |
| 5559 | ArrayList<Integer> firstPids = new ArrayList<Integer>(); |
| 5560 | firstPids.add(app.getPid()); |
| 5561 | dumpStackTraces(tracesFile.getAbsolutePath(), firstPids, null, null); |
| 5562 | } |
| 5563 | |
| 5564 | File lastTracesFile = null; |
| 5565 | File curTracesFile = null; |
| 5566 | for (int i=9; i>=0; i--) { |
| 5567 | String name = String.format(Locale.US, "slow%02d.txt", i); |
| 5568 | curTracesFile = new File(tracesDir, name); |
| 5569 | if (curTracesFile.exists()) { |
| 5570 | if (lastTracesFile != null) { |
| 5571 | curTracesFile.renameTo(lastTracesFile); |
| 5572 | } else { |
| 5573 | curTracesFile.delete(); |
| 5574 | } |
| 5575 | } |
| 5576 | lastTracesFile = curTracesFile; |
| 5577 | } |
| 5578 | tracesFile.renameTo(curTracesFile); |
| 5579 | } finally { |
| 5580 | StrictMode.setThreadPolicy(oldPolicy); |
| 5581 | } |
| 5582 | } |
| 5583 | |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5584 | final class H extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5585 | static final int REPORT_TIME_TRACKER_MSG = 1; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 5586 | |
| 5587 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 5588 | static final int FIRST_ACTIVITY_STACK_MSG = 100; |
| 5589 | static final int FIRST_SUPERVISOR_STACK_MSG = 200; |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5590 | |
Riddle Hsu | d93a6c4 | 2018-11-29 21:50:06 +0800 | [diff] [blame] | 5591 | H(Looper looper) { |
| 5592 | super(looper); |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5593 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5594 | |
| 5595 | @Override |
| 5596 | public void handleMessage(Message msg) { |
| 5597 | switch (msg.what) { |
| 5598 | case REPORT_TIME_TRACKER_MSG: { |
| 5599 | AppTimeTracker tracker = (AppTimeTracker) msg.obj; |
| 5600 | tracker.deliverResult(mContext); |
| 5601 | } break; |
| 5602 | } |
| 5603 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5604 | } |
| 5605 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5606 | final class UiHandler extends Handler { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5607 | static final int DISMISS_DIALOG_UI_MSG = 1; |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5608 | |
| 5609 | public UiHandler() { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 5610 | super(UiThread.get().getLooper(), null, true); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5611 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5612 | |
| 5613 | @Override |
| 5614 | public void handleMessage(Message msg) { |
| 5615 | switch (msg.what) { |
| 5616 | case DISMISS_DIALOG_UI_MSG: { |
| 5617 | final Dialog d = (Dialog) msg.obj; |
| 5618 | d.dismiss(); |
| 5619 | break; |
| 5620 | } |
| 5621 | } |
| 5622 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5623 | } |
| 5624 | |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5625 | final class LocalService extends ActivityTaskManagerInternal { |
| 5626 | @Override |
| 5627 | public SleepToken acquireSleepToken(String tag, int displayId) { |
| 5628 | Preconditions.checkNotNull(tag); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5629 | return ActivityTaskManagerService.this.acquireSleepToken(tag, displayId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5630 | } |
| 5631 | |
| 5632 | @Override |
| 5633 | public ComponentName getHomeActivityForUser(int userId) { |
| 5634 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5635 | final ActivityRecord homeActivity = |
| 5636 | mRootActivityContainer.getDefaultDisplayHomeActivityForUser(userId); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5637 | return homeActivity == null ? null : homeActivity.mActivityComponent; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5638 | } |
| 5639 | } |
| 5640 | |
| 5641 | @Override |
| 5642 | public void onLocalVoiceInteractionStarted(IBinder activity, |
| 5643 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) { |
| 5644 | synchronized (mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5645 | onLocalVoiceInteractionStartedLocked(activity, voiceSession, voiceInteractor); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5646 | } |
| 5647 | } |
| 5648 | |
| 5649 | @Override |
| 5650 | public void notifyAppTransitionStarting(SparseIntArray reasons, long timestamp) { |
| 5651 | synchronized (mGlobalLock) { |
| 5652 | mStackSupervisor.getActivityMetricsLogger().notifyTransitionStarting( |
| 5653 | reasons, timestamp); |
| 5654 | } |
| 5655 | } |
| 5656 | |
| 5657 | @Override |
| 5658 | public void notifyAppTransitionFinished() { |
| 5659 | synchronized (mGlobalLock) { |
| 5660 | mStackSupervisor.notifyAppTransitionDone(); |
| 5661 | } |
| 5662 | } |
| 5663 | |
| 5664 | @Override |
| 5665 | public void notifyAppTransitionCancelled() { |
| 5666 | synchronized (mGlobalLock) { |
| 5667 | mStackSupervisor.notifyAppTransitionDone(); |
| 5668 | } |
| 5669 | } |
| 5670 | |
| 5671 | @Override |
| 5672 | public List<IBinder> getTopVisibleActivities() { |
| 5673 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5674 | return mRootActivityContainer.getTopVisibleActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5675 | } |
| 5676 | } |
| 5677 | |
| 5678 | @Override |
| 5679 | public void notifyDockedStackMinimizedChanged(boolean minimized) { |
| 5680 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5681 | mRootActivityContainer.setDockedStackMinimized(minimized); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5682 | } |
| 5683 | } |
| 5684 | |
| 5685 | @Override |
| 5686 | public int startActivitiesAsPackage(String packageName, int userId, Intent[] intents, |
| 5687 | Bundle bOptions) { |
| 5688 | Preconditions.checkNotNull(intents, "intents"); |
| 5689 | final String[] resolvedTypes = new String[intents.length]; |
| 5690 | |
| 5691 | // UID of the package on user userId. |
| 5692 | // "= 0" is needed because otherwise catch(RemoteException) would make it look like |
| 5693 | // packageUid may not be initialized. |
| 5694 | int packageUid = 0; |
| 5695 | final long ident = Binder.clearCallingIdentity(); |
| 5696 | |
| 5697 | try { |
| 5698 | for (int i = 0; i < intents.length; i++) { |
| 5699 | resolvedTypes[i] = |
| 5700 | intents[i].resolveTypeIfNeeded(mContext.getContentResolver()); |
| 5701 | } |
| 5702 | |
| 5703 | packageUid = AppGlobals.getPackageManager().getPackageUid( |
| 5704 | packageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId); |
| 5705 | } catch (RemoteException e) { |
| 5706 | // Shouldn't happen. |
| 5707 | } finally { |
| 5708 | Binder.restoreCallingIdentity(ident); |
| 5709 | } |
| 5710 | |
| 5711 | synchronized (mGlobalLock) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 5712 | return getActivityStartController().startActivitiesInPackage( |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5713 | packageUid, packageName, |
| 5714 | intents, resolvedTypes, null /* resultTo */, |
| 5715 | SafeActivityOptions.fromBundle(bOptions), userId, |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 5716 | false /* validateIncomingUser */, null /* originatingPendingIntent */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5717 | } |
| 5718 | } |
| 5719 | |
| 5720 | @Override |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 5721 | public int startActivitiesInPackage(int uid, String callingPackage, Intent[] intents, |
| 5722 | String[] resolvedTypes, IBinder resultTo, SafeActivityOptions options, int userId, |
| 5723 | boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent) { |
| 5724 | synchronized (mGlobalLock) { |
| 5725 | return getActivityStartController().startActivitiesInPackage(uid, callingPackage, |
| 5726 | intents, resolvedTypes, resultTo, options, userId, validateIncomingUser, |
| 5727 | originatingPendingIntent); |
| 5728 | } |
| 5729 | } |
| 5730 | |
| 5731 | @Override |
| 5732 | public int startActivityInPackage(int uid, int realCallingPid, int realCallingUid, |
| 5733 | String callingPackage, Intent intent, String resolvedType, IBinder resultTo, |
| 5734 | String resultWho, int requestCode, int startFlags, SafeActivityOptions options, |
| 5735 | int userId, TaskRecord inTask, String reason, boolean validateIncomingUser, |
| 5736 | PendingIntentRecord originatingPendingIntent) { |
| 5737 | synchronized (mGlobalLock) { |
| 5738 | return getActivityStartController().startActivityInPackage(uid, realCallingPid, |
| 5739 | realCallingUid, callingPackage, intent, resolvedType, resultTo, resultWho, |
| 5740 | requestCode, startFlags, options, userId, inTask, reason, |
| 5741 | validateIncomingUser, originatingPendingIntent); |
| 5742 | } |
| 5743 | } |
| 5744 | |
| 5745 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5746 | public int startActivityAsUser(IApplicationThread caller, String callerPacakge, |
| 5747 | Intent intent, Bundle options, int userId) { |
| 5748 | return ActivityTaskManagerService.this.startActivityAsUser( |
| 5749 | caller, callerPacakge, intent, |
| 5750 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 5751 | null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, options, userId, |
| 5752 | false /*validateIncomingUser*/); |
| 5753 | } |
| 5754 | |
| 5755 | @Override |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5756 | public void notifyKeyguardFlagsChanged(@Nullable Runnable callback, int displayId) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5757 | synchronized (mGlobalLock) { |
| 5758 | |
| 5759 | // We might change the visibilities here, so prepare an empty app transition which |
| 5760 | // might be overridden later if we actually change visibilities. |
lumark | 52ea28e | 2018-11-09 17:30:47 +0800 | [diff] [blame] | 5761 | final ActivityDisplay activityDisplay = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5762 | mRootActivityContainer.getActivityDisplay(displayId); |
lumark | 52ea28e | 2018-11-09 17:30:47 +0800 | [diff] [blame] | 5763 | if (activityDisplay == null) { |
| 5764 | return; |
| 5765 | } |
| 5766 | final DisplayWindowController dwc = activityDisplay.getWindowContainerController(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5767 | final boolean wasTransitionSet = dwc.getPendingAppTransition() != TRANSIT_NONE; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5768 | if (!wasTransitionSet) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5769 | dwc.prepareAppTransition(TRANSIT_NONE, false /* alwaysKeepCurrent */); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5770 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5771 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5772 | |
| 5773 | // If there was a transition set already we don't want to interfere with it as we |
| 5774 | // might be starting it too early. |
| 5775 | if (!wasTransitionSet) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5776 | dwc.executeAppTransition(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5777 | } |
| 5778 | } |
| 5779 | if (callback != null) { |
| 5780 | callback.run(); |
| 5781 | } |
| 5782 | } |
| 5783 | |
| 5784 | @Override |
| 5785 | public void notifyKeyguardTrustedChanged() { |
| 5786 | synchronized (mGlobalLock) { |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5787 | if (mKeyguardController.isKeyguardShowing(DEFAULT_DISPLAY)) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5788 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5789 | } |
| 5790 | } |
| 5791 | } |
| 5792 | |
| 5793 | /** |
| 5794 | * Called after virtual display Id is updated by |
| 5795 | * {@link com.android.server.vr.Vr2dDisplay} with a specific |
| 5796 | * {@param vrVr2dDisplayId}. |
| 5797 | */ |
| 5798 | @Override |
| 5799 | public void setVr2dDisplayId(int vr2dDisplayId) { |
| 5800 | if (DEBUG_STACK) Slog.d(TAG, "setVr2dDisplayId called for: " + vr2dDisplayId); |
| 5801 | synchronized (mGlobalLock) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5802 | mVr2dDisplayId = vr2dDisplayId; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5803 | } |
| 5804 | } |
| 5805 | |
| 5806 | @Override |
| 5807 | public void setFocusedActivity(IBinder token) { |
| 5808 | synchronized (mGlobalLock) { |
| 5809 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 5810 | if (r == null) { |
| 5811 | throw new IllegalArgumentException( |
| 5812 | "setFocusedActivity: No activity record matching token=" + token); |
| 5813 | } |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 5814 | if (r.moveFocusableActivityToTop("setFocusedActivity")) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5815 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5816 | } |
| 5817 | } |
| 5818 | } |
| 5819 | |
| 5820 | @Override |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5821 | public void registerScreenObserver(ScreenObserver observer) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5822 | mScreenObservers.add(observer); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5823 | } |
| 5824 | |
| 5825 | @Override |
| 5826 | public boolean isCallerRecents(int callingUid) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 5827 | return getRecentTasks().isCallerRecents(callingUid); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5828 | } |
| 5829 | |
| 5830 | @Override |
| 5831 | public boolean isRecentsComponentHomeActivity(int userId) { |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 5832 | return getRecentTasks().isRecentsComponentHomeActivity(userId); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5833 | } |
| 5834 | |
| 5835 | @Override |
| 5836 | public void cancelRecentsAnimation(boolean restoreHomeStackPosition) { |
| 5837 | ActivityTaskManagerService.this.cancelRecentsAnimation(restoreHomeStackPosition); |
| 5838 | } |
| 5839 | |
| 5840 | @Override |
| 5841 | public void enforceCallerIsRecentsOrHasPermission(String permission, String func) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5842 | ActivityTaskManagerService.this.enforceCallerIsRecentsOrHasPermission(permission, func); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 5843 | } |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 5844 | |
| 5845 | @Override |
| 5846 | public void notifyActiveVoiceInteractionServiceChanged(ComponentName component) { |
| 5847 | synchronized (mGlobalLock) { |
| 5848 | mActiveVoiceInteractionServiceComponent = component; |
| 5849 | } |
| 5850 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 5851 | |
| 5852 | @Override |
| 5853 | public void setAllowAppSwitches(@NonNull String type, int uid, int userId) { |
| 5854 | if (!mAmInternal.isUserRunning(userId, ActivityManager.FLAG_OR_STOPPED)) { |
| 5855 | return; |
| 5856 | } |
| 5857 | synchronized (mGlobalLock) { |
| 5858 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.get(userId); |
| 5859 | if (types == null) { |
| 5860 | if (uid < 0) { |
| 5861 | return; |
| 5862 | } |
| 5863 | types = new ArrayMap<>(); |
| 5864 | mAllowAppSwitchUids.put(userId, types); |
| 5865 | } |
| 5866 | if (uid < 0) { |
| 5867 | types.remove(type); |
| 5868 | } else { |
| 5869 | types.put(type, uid); |
| 5870 | } |
| 5871 | } |
| 5872 | } |
| 5873 | |
| 5874 | @Override |
| 5875 | public void onUserStopped(int userId) { |
| 5876 | synchronized (mGlobalLock) { |
| 5877 | getRecentTasks().unloadUserDataFromMemoryLocked(userId); |
| 5878 | mAllowAppSwitchUids.remove(userId); |
| 5879 | } |
| 5880 | } |
| 5881 | |
| 5882 | @Override |
| 5883 | public boolean isGetTasksAllowed(String caller, int callingPid, int callingUid) { |
| 5884 | synchronized (mGlobalLock) { |
| 5885 | return ActivityTaskManagerService.this.isGetTasksAllowed( |
| 5886 | caller, callingPid, callingUid); |
| 5887 | } |
| 5888 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5889 | |
| 5890 | @Override |
| 5891 | public void onProcessAdded(WindowProcessController proc) { |
| 5892 | synchronized (mGlobalLock) { |
| 5893 | mProcessNames.put(proc.mName, proc.mUid, proc); |
| 5894 | } |
| 5895 | } |
| 5896 | |
| 5897 | @Override |
| 5898 | public void onProcessRemoved(String name, int uid) { |
| 5899 | synchronized (mGlobalLock) { |
| 5900 | mProcessNames.remove(name, uid); |
| 5901 | } |
| 5902 | } |
| 5903 | |
| 5904 | @Override |
| 5905 | public void onCleanUpApplicationRecord(WindowProcessController proc) { |
| 5906 | synchronized (mGlobalLock) { |
| 5907 | if (proc == mHomeProcess) { |
| 5908 | mHomeProcess = null; |
| 5909 | } |
| 5910 | if (proc == mPreviousProcess) { |
| 5911 | mPreviousProcess = null; |
| 5912 | } |
| 5913 | } |
| 5914 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5915 | |
| 5916 | @Override |
| 5917 | public int getTopProcessState() { |
| 5918 | synchronized (mGlobalLock) { |
| 5919 | return mTopProcessState; |
| 5920 | } |
| 5921 | } |
| 5922 | |
| 5923 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5924 | public boolean isHeavyWeightProcess(WindowProcessController proc) { |
| 5925 | synchronized (mGlobalLock) { |
| 5926 | return proc == mHeavyWeightProcess; |
| 5927 | } |
| 5928 | } |
| 5929 | |
| 5930 | @Override |
| 5931 | public void clearHeavyWeightProcessIfEquals(WindowProcessController proc) { |
| 5932 | synchronized (mGlobalLock) { |
| 5933 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals(proc); |
| 5934 | } |
| 5935 | } |
| 5936 | |
| 5937 | @Override |
| 5938 | public void finishHeavyWeightApp() { |
| 5939 | synchronized (mGlobalLock) { |
Sudheer Shanka | ee1da27 | 2018-10-20 20:11:44 -0700 | [diff] [blame] | 5940 | if (mHeavyWeightProcess != null) { |
| 5941 | mHeavyWeightProcess.finishActivities(); |
| 5942 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 5943 | ActivityTaskManagerService.this.clearHeavyWeightProcessIfEquals( |
| 5944 | mHeavyWeightProcess); |
| 5945 | } |
| 5946 | } |
| 5947 | |
| 5948 | @Override |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5949 | public boolean isSleeping() { |
| 5950 | synchronized (mGlobalLock) { |
| 5951 | return isSleepingLocked(); |
| 5952 | } |
| 5953 | } |
| 5954 | |
| 5955 | @Override |
| 5956 | public boolean isShuttingDown() { |
| 5957 | synchronized (mGlobalLock) { |
| 5958 | return mShuttingDown; |
| 5959 | } |
| 5960 | } |
| 5961 | |
| 5962 | @Override |
| 5963 | public boolean shuttingDown(boolean booted, int timeout) { |
| 5964 | synchronized (mGlobalLock) { |
| 5965 | mShuttingDown = true; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5966 | mRootActivityContainer.prepareForShutdown(); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5967 | updateEventDispatchingLocked(booted); |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 5968 | notifyTaskPersisterLocked(null, true); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5969 | return mStackSupervisor.shutdownLocked(timeout); |
| 5970 | } |
| 5971 | } |
| 5972 | |
| 5973 | @Override |
| 5974 | public void enableScreenAfterBoot(boolean booted) { |
| 5975 | synchronized (mGlobalLock) { |
| 5976 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_ENABLE_SCREEN, |
| 5977 | SystemClock.uptimeMillis()); |
| 5978 | mWindowManager.enableScreenAfterBoot(); |
| 5979 | updateEventDispatchingLocked(booted); |
| 5980 | } |
| 5981 | } |
| 5982 | |
| 5983 | @Override |
| 5984 | public boolean showStrictModeViolationDialog() { |
| 5985 | synchronized (mGlobalLock) { |
| 5986 | return mShowDialogs && !mSleeping && !mShuttingDown; |
| 5987 | } |
| 5988 | } |
| 5989 | |
| 5990 | @Override |
| 5991 | public void showSystemReadyErrorDialogsIfNeeded() { |
| 5992 | synchronized (mGlobalLock) { |
| 5993 | try { |
| 5994 | if (AppGlobals.getPackageManager().hasSystemUidErrors()) { |
| 5995 | Slog.e(TAG, "UIDs on the system are inconsistent, you need to wipe your" |
| 5996 | + " data partition or your device will be unstable."); |
| 5997 | mUiHandler.post(() -> { |
| 5998 | if (mShowDialogs) { |
| 5999 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6000 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6001 | d.setCancelable(false); |
| 6002 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6003 | d.setMessage(mUiContext.getText(R.string.system_error_wipe_data)); |
| 6004 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6005 | mUiContext.getText(R.string.ok), |
| 6006 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6007 | d.show(); |
| 6008 | } |
| 6009 | }); |
| 6010 | } |
| 6011 | } catch (RemoteException e) { |
| 6012 | } |
| 6013 | |
| 6014 | if (!Build.isBuildConsistent()) { |
| 6015 | Slog.e(TAG, "Build fingerprint is not consistent, warning user"); |
| 6016 | mUiHandler.post(() -> { |
| 6017 | if (mShowDialogs) { |
| 6018 | AlertDialog d = new BaseErrorDialog(mUiContext); |
| 6019 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 6020 | d.setCancelable(false); |
| 6021 | d.setTitle(mUiContext.getText(R.string.android_system_label)); |
| 6022 | d.setMessage(mUiContext.getText(R.string.system_error_manufacturer)); |
| 6023 | d.setButton(DialogInterface.BUTTON_POSITIVE, |
| 6024 | mUiContext.getText(R.string.ok), |
| 6025 | mUiHandler.obtainMessage(DISMISS_DIALOG_UI_MSG, d)); |
| 6026 | d.show(); |
| 6027 | } |
| 6028 | }); |
| 6029 | } |
| 6030 | } |
| 6031 | } |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6032 | |
| 6033 | @Override |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 6034 | public void onProcessMapped(int pid, WindowProcessController proc) { |
| 6035 | synchronized (mGlobalLock) { |
| 6036 | mPidMap.put(pid, proc); |
| 6037 | } |
| 6038 | } |
| 6039 | |
| 6040 | @Override |
| 6041 | public void onProcessUnMapped(int pid) { |
| 6042 | synchronized (mGlobalLock) { |
| 6043 | mPidMap.remove(pid); |
| 6044 | } |
| 6045 | } |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6046 | |
| 6047 | @Override |
| 6048 | public void onPackageDataCleared(String name) { |
| 6049 | synchronized (mGlobalLock) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6050 | mCompatModePackages.handlePackageDataClearedLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6051 | mAppWarnings.onPackageDataCleared(name); |
| 6052 | } |
| 6053 | } |
| 6054 | |
| 6055 | @Override |
| 6056 | public void onPackageUninstalled(String name) { |
| 6057 | synchronized (mGlobalLock) { |
| 6058 | mAppWarnings.onPackageUninstalled(name); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6059 | mCompatModePackages.handlePackageUninstalledLocked(name); |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 6060 | } |
| 6061 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6062 | |
| 6063 | @Override |
| 6064 | public void onPackageAdded(String name, boolean replacing) { |
| 6065 | synchronized (mGlobalLock) { |
| 6066 | mCompatModePackages.handlePackageAddedLocked(name, replacing); |
| 6067 | } |
| 6068 | } |
| 6069 | |
| 6070 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6071 | public void onPackageReplaced(ApplicationInfo aInfo) { |
| 6072 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6073 | mRootActivityContainer.updateActivityApplicationInfo(aInfo); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6074 | } |
| 6075 | } |
| 6076 | |
| 6077 | @Override |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 6078 | public CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai) { |
| 6079 | synchronized (mGlobalLock) { |
| 6080 | return compatibilityInfoForPackageLocked(ai); |
| 6081 | } |
| 6082 | } |
| 6083 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6084 | /** |
| 6085 | * Set the corresponding display information for the process global configuration. To be |
| 6086 | * called when we need to show IME on a different display. |
| 6087 | * |
| 6088 | * @param pid The process id associated with the IME window. |
| 6089 | * @param displayId The ID of the display showing the IME. |
| 6090 | */ |
| 6091 | @Override |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6092 | public void onImeWindowSetOnDisplay(final int pid, final int displayId) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6093 | if (pid == MY_PID || pid < 0) { |
| 6094 | if (DEBUG_CONFIGURATION) { |
| 6095 | Slog.w(TAG, |
| 6096 | "Trying to update display configuration for system/invalid process."); |
| 6097 | } |
| 6098 | return; |
| 6099 | } |
| 6100 | mH.post(() -> { |
| 6101 | synchronized (mGlobalLock) { |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6102 | final ActivityDisplay activityDisplay = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6103 | mRootActivityContainer.getActivityDisplay(displayId); |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6104 | if (activityDisplay == null) { |
| 6105 | // 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] | 6106 | if (DEBUG_CONFIGURATION) { |
| 6107 | Slog.w(TAG, "Trying to update display configuration for non-existing " |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6108 | + "displayId=" + displayId); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6109 | } |
| 6110 | return; |
| 6111 | } |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6112 | final WindowProcessController process = mPidMap.get(pid); |
| 6113 | if (process == null) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6114 | if (DEBUG_CONFIGURATION) { |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6115 | Slog.w(TAG, "Trying to update display configuration for invalid " |
| 6116 | + "process, pid=" + pid); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6117 | } |
| 6118 | return; |
| 6119 | } |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6120 | process.registerDisplayConfigurationListenerLocked(activityDisplay); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6121 | } |
| 6122 | }); |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 6123 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 6124 | } |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6125 | |
| 6126 | @Override |
| 6127 | public void sendActivityResult(int callingUid, IBinder activityToken, String resultWho, |
| 6128 | int requestCode, int resultCode, Intent data) { |
| 6129 | synchronized (mGlobalLock) { |
| 6130 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 6131 | if (r != null && r.getActivityStack() != null) { |
| 6132 | r.getActivityStack().sendActivityResultLocked(callingUid, r, resultWho, |
| 6133 | requestCode, resultCode, data); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 6134 | } |
| 6135 | } |
| 6136 | } |
| 6137 | |
| 6138 | @Override |
| 6139 | public void clearPendingResultForActivity(IBinder activityToken, |
| 6140 | WeakReference<PendingIntentRecord> pir) { |
| 6141 | synchronized (mGlobalLock) { |
| 6142 | final ActivityRecord r = ActivityRecord.isInStackLocked(activityToken); |
| 6143 | if (r != null && r.pendingResults != null) { |
| 6144 | r.pendingResults.remove(pir); |
| 6145 | } |
| 6146 | } |
| 6147 | } |
| 6148 | |
| 6149 | @Override |
| 6150 | public IIntentSender getIntentSender(int type, String packageName, |
| 6151 | int callingUid, int userId, IBinder token, String resultWho, |
| 6152 | int requestCode, Intent[] intents, String[] resolvedTypes, int flags, |
| 6153 | Bundle bOptions) { |
| 6154 | synchronized (mGlobalLock) { |
| 6155 | return getIntentSenderLocked(type, packageName, callingUid, userId, token, |
| 6156 | resultWho, requestCode, intents, resolvedTypes, flags, bOptions); |
| 6157 | } |
| 6158 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 6159 | |
| 6160 | @Override |
| 6161 | public ActivityServiceConnectionsHolder getServiceConnectionsHolder(IBinder token) { |
| 6162 | synchronized (mGlobalLock) { |
| 6163 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 6164 | if (r == null) { |
| 6165 | return null; |
| 6166 | } |
| 6167 | if (r.mServiceConnectionsHolder == null) { |
| 6168 | r.mServiceConnectionsHolder = new ActivityServiceConnectionsHolder( |
| 6169 | ActivityTaskManagerService.this, r); |
| 6170 | } |
| 6171 | |
| 6172 | return r.mServiceConnectionsHolder; |
| 6173 | } |
| 6174 | } |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6175 | |
| 6176 | @Override |
| 6177 | public Intent getHomeIntent() { |
| 6178 | synchronized (mGlobalLock) { |
| 6179 | return ActivityTaskManagerService.this.getHomeIntent(); |
| 6180 | } |
| 6181 | } |
| 6182 | |
| 6183 | @Override |
| 6184 | public boolean startHomeActivity(int userId, String reason) { |
| 6185 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6186 | return mRootActivityContainer.startHomeOnDisplay(userId, reason, DEFAULT_DISPLAY); |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 6187 | } |
| 6188 | } |
| 6189 | |
| 6190 | @Override |
| 6191 | public boolean startHomeOnAllDisplays(int userId, String reason) { |
| 6192 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6193 | return mRootActivityContainer.startHomeOnAllDisplays(userId, reason); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6194 | } |
| 6195 | } |
| 6196 | |
| 6197 | @Override |
| 6198 | public boolean isFactoryTestProcess(WindowProcessController wpc) { |
| 6199 | synchronized (mGlobalLock) { |
| 6200 | if (mFactoryTest == FACTORY_TEST_OFF) { |
| 6201 | return false; |
| 6202 | } |
| 6203 | if (mFactoryTest == FACTORY_TEST_LOW_LEVEL && mTopComponent != null |
| 6204 | && wpc.mName.equals(mTopComponent.getPackageName())) { |
| 6205 | return true; |
| 6206 | } |
| 6207 | return mFactoryTest == FACTORY_TEST_HIGH_LEVEL |
| 6208 | && (wpc.mInfo.flags & FLAG_FACTORY_TEST) != 0; |
| 6209 | } |
| 6210 | } |
| 6211 | |
| 6212 | @Override |
| 6213 | public void updateTopComponentForFactoryTest() { |
| 6214 | synchronized (mGlobalLock) { |
| 6215 | if (mFactoryTest != FACTORY_TEST_LOW_LEVEL) { |
| 6216 | return; |
| 6217 | } |
| 6218 | final ResolveInfo ri = mContext.getPackageManager() |
| 6219 | .resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST), STOCK_PM_FLAGS); |
| 6220 | final CharSequence errorMsg; |
| 6221 | if (ri != null) { |
| 6222 | final ActivityInfo ai = ri.activityInfo; |
| 6223 | final ApplicationInfo app = ai.applicationInfo; |
| 6224 | if ((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 6225 | mTopAction = Intent.ACTION_FACTORY_TEST; |
| 6226 | mTopData = null; |
| 6227 | mTopComponent = new ComponentName(app.packageName, ai.name); |
| 6228 | errorMsg = null; |
| 6229 | } else { |
| 6230 | errorMsg = mContext.getResources().getText( |
| 6231 | com.android.internal.R.string.factorytest_not_system); |
| 6232 | } |
| 6233 | } else { |
| 6234 | errorMsg = mContext.getResources().getText( |
| 6235 | com.android.internal.R.string.factorytest_no_action); |
| 6236 | } |
| 6237 | if (errorMsg == null) { |
| 6238 | return; |
| 6239 | } |
| 6240 | |
| 6241 | mTopAction = null; |
| 6242 | mTopData = null; |
| 6243 | mTopComponent = null; |
| 6244 | mUiHandler.post(() -> { |
| 6245 | Dialog d = new FactoryErrorDialog(mUiContext, errorMsg); |
| 6246 | d.show(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 6247 | mAmInternal.ensureBootCompleted(); |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 6248 | }); |
| 6249 | } |
| 6250 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6251 | |
| 6252 | @Override |
| 6253 | public void handleAppDied(WindowProcessController wpc, boolean restarting, |
| 6254 | Runnable finishInstrumentationCallback) { |
| 6255 | synchronized (mGlobalLock) { |
| 6256 | // Remove this application's activities from active lists. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6257 | boolean hasVisibleActivities = mRootActivityContainer.handleAppDied(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6258 | |
| 6259 | wpc.clearRecentTasks(); |
| 6260 | wpc.clearActivities(); |
| 6261 | |
| 6262 | if (wpc.isInstrumenting()) { |
| 6263 | finishInstrumentationCallback.run(); |
| 6264 | } |
| 6265 | |
| 6266 | mWindowManager.deferSurfaceLayout(); |
| 6267 | try { |
| 6268 | if (!restarting && hasVisibleActivities |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6269 | && !mRootActivityContainer.resumeFocusedStacksTopActivities()) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6270 | // If there was nothing to resume, and we are not already restarting this |
| 6271 | // process, but there is a visible activity that is hosted by the process... |
| 6272 | // then make sure all visible activities are running, taking care of |
| 6273 | // restarting this process. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6274 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6275 | } |
| 6276 | } finally { |
| 6277 | mWindowManager.continueSurfaceLayout(); |
| 6278 | } |
| 6279 | } |
| 6280 | } |
| 6281 | |
| 6282 | @Override |
| 6283 | public void closeSystemDialogs(String reason) { |
| 6284 | enforceNotIsolatedCaller("closeSystemDialogs"); |
| 6285 | |
| 6286 | final int pid = Binder.getCallingPid(); |
| 6287 | final int uid = Binder.getCallingUid(); |
| 6288 | final long origId = Binder.clearCallingIdentity(); |
| 6289 | try { |
| 6290 | synchronized (mGlobalLock) { |
| 6291 | // Only allow this from foreground processes, so that background |
| 6292 | // applications can't abuse it to prevent system UI from being shown. |
| 6293 | if (uid >= FIRST_APPLICATION_UID) { |
| 6294 | final WindowProcessController proc = mPidMap.get(pid); |
| 6295 | if (!proc.isPerceptible()) { |
| 6296 | Slog.w(TAG, "Ignoring closeSystemDialogs " + reason |
| 6297 | + " from background process " + proc); |
| 6298 | return; |
| 6299 | } |
| 6300 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6301 | mWindowManager.closeSystemDialogs(reason); |
| 6302 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6303 | mRootActivityContainer.closeSystemDialogs(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6304 | } |
Wale Ogunwale | 2ea36d4 | 2018-10-18 10:27:31 -0700 | [diff] [blame] | 6305 | // Call into AM outside the synchronized block. |
| 6306 | mAmInternal.broadcastCloseSystemDialogs(reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6307 | } finally { |
| 6308 | Binder.restoreCallingIdentity(origId); |
| 6309 | } |
| 6310 | } |
| 6311 | |
| 6312 | @Override |
| 6313 | public void cleanupDisabledPackageComponents( |
| 6314 | String packageName, Set<String> disabledClasses, int userId, boolean booted) { |
| 6315 | synchronized (mGlobalLock) { |
| 6316 | // Clean-up disabled activities. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6317 | if (mRootActivityContainer.finishDisabledPackageActivities( |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6318 | packageName, disabledClasses, true, false, userId) && booted) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6319 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6320 | mStackSupervisor.scheduleIdleLocked(); |
| 6321 | } |
| 6322 | |
| 6323 | // Clean-up disabled tasks |
| 6324 | getRecentTasks().cleanupDisabledPackageTasksLocked( |
| 6325 | packageName, disabledClasses, userId); |
| 6326 | } |
| 6327 | } |
| 6328 | |
| 6329 | @Override |
| 6330 | public boolean onForceStopPackage(String packageName, boolean doit, boolean evenPersistent, |
| 6331 | int userId) { |
| 6332 | synchronized (mGlobalLock) { |
| 6333 | |
| 6334 | boolean didSomething = |
| 6335 | getActivityStartController().clearPendingActivityLaunches(packageName); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6336 | didSomething |= mRootActivityContainer.finishDisabledPackageActivities(packageName, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6337 | null, doit, evenPersistent, userId); |
| 6338 | return didSomething; |
| 6339 | } |
| 6340 | } |
| 6341 | |
| 6342 | @Override |
| 6343 | public void resumeTopActivities(boolean scheduleIdle) { |
| 6344 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6345 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6346 | if (scheduleIdle) { |
| 6347 | mStackSupervisor.scheduleIdleLocked(); |
| 6348 | } |
| 6349 | } |
| 6350 | } |
| 6351 | |
| 6352 | @Override |
| 6353 | public void preBindApplication(WindowProcessController wpc) { |
| 6354 | synchronized (mGlobalLock) { |
| 6355 | mStackSupervisor.getActivityMetricsLogger().notifyBindApplication(wpc.mInfo); |
| 6356 | } |
| 6357 | } |
| 6358 | |
| 6359 | @Override |
| 6360 | public boolean attachApplication(WindowProcessController wpc) throws RemoteException { |
| 6361 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6362 | return mRootActivityContainer.attachApplication(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6363 | } |
| 6364 | } |
| 6365 | |
| 6366 | @Override |
| 6367 | public void notifyLockedProfile(@UserIdInt int userId, int currentUserId) { |
| 6368 | try { |
| 6369 | if (!AppGlobals.getPackageManager().isUidPrivileged(Binder.getCallingUid())) { |
| 6370 | throw new SecurityException("Only privileged app can call notifyLockedProfile"); |
| 6371 | } |
| 6372 | } catch (RemoteException ex) { |
| 6373 | throw new SecurityException("Fail to check is caller a privileged app", ex); |
| 6374 | } |
| 6375 | |
| 6376 | synchronized (mGlobalLock) { |
| 6377 | final long ident = Binder.clearCallingIdentity(); |
| 6378 | try { |
| 6379 | if (mAmInternal.shouldConfirmCredentials(userId)) { |
| 6380 | if (mKeyguardController.isKeyguardLocked()) { |
| 6381 | // Showing launcher to avoid user entering credential twice. |
| 6382 | startHomeActivity(currentUserId, "notifyLockedProfile"); |
| 6383 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6384 | mRootActivityContainer.lockAllProfileTasks(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6385 | } |
| 6386 | } finally { |
| 6387 | Binder.restoreCallingIdentity(ident); |
| 6388 | } |
| 6389 | } |
| 6390 | } |
| 6391 | |
| 6392 | @Override |
| 6393 | public void startConfirmDeviceCredentialIntent(Intent intent, Bundle options) { |
| 6394 | mAmInternal.enforceCallingPermission( |
| 6395 | MANAGE_ACTIVITY_STACKS, "startConfirmDeviceCredentialIntent"); |
| 6396 | |
| 6397 | synchronized (mGlobalLock) { |
| 6398 | final long ident = Binder.clearCallingIdentity(); |
| 6399 | try { |
| 6400 | intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | |
| 6401 | FLAG_ACTIVITY_TASK_ON_HOME); |
| 6402 | ActivityOptions activityOptions = options != null |
| 6403 | ? new ActivityOptions(options) : ActivityOptions.makeBasic(); |
Martijn Coenen | 2a5c839 | 2018-10-01 10:17:06 +0200 | [diff] [blame] | 6404 | final ActivityRecord homeActivity = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6405 | mRootActivityContainer.getDefaultDisplayHomeActivity(); |
Martijn Coenen | 2a5c839 | 2018-10-01 10:17:06 +0200 | [diff] [blame] | 6406 | if (homeActivity != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 6407 | activityOptions.setLaunchTaskId(homeActivity.getTaskRecord().taskId); |
Martijn Coenen | 2a5c839 | 2018-10-01 10:17:06 +0200 | [diff] [blame] | 6408 | } |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6409 | mContext.startActivityAsUser(intent, activityOptions.toBundle(), |
| 6410 | UserHandle.CURRENT); |
| 6411 | } finally { |
| 6412 | Binder.restoreCallingIdentity(ident); |
| 6413 | } |
| 6414 | } |
| 6415 | } |
| 6416 | |
| 6417 | @Override |
| 6418 | public void writeActivitiesToProto(ProtoOutputStream proto) { |
| 6419 | synchronized (mGlobalLock) { |
| 6420 | // The output proto of "activity --proto activities" |
| 6421 | // is ActivityManagerServiceDumpActivitiesProto |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6422 | mRootActivityContainer.writeToProto(proto, |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6423 | ActivityManagerServiceDumpActivitiesProto.ACTIVITY_STACK_SUPERVISOR); |
| 6424 | } |
| 6425 | } |
| 6426 | |
| 6427 | @Override |
| 6428 | public void saveANRState(String reason) { |
| 6429 | synchronized (mGlobalLock) { |
| 6430 | final StringWriter sw = new StringWriter(); |
| 6431 | final PrintWriter pw = new FastPrintWriter(sw, false, 1024); |
| 6432 | pw.println(" ANR time: " + DateFormat.getDateTimeInstance().format(new Date())); |
| 6433 | if (reason != null) { |
| 6434 | pw.println(" Reason: " + reason); |
| 6435 | } |
| 6436 | pw.println(); |
| 6437 | getActivityStartController().dump(pw, " ", null); |
| 6438 | pw.println(); |
| 6439 | pw.println("-------------------------------------------------------------------------------"); |
| 6440 | dumpActivitiesLocked(null /* fd */, pw, null /* args */, 0 /* opti */, |
| 6441 | true /* dumpAll */, false /* dumpClient */, null /* dumpPackage */, |
| 6442 | "" /* header */); |
| 6443 | pw.println(); |
| 6444 | pw.close(); |
| 6445 | |
| 6446 | mLastANRState = sw.toString(); |
| 6447 | } |
| 6448 | } |
| 6449 | |
| 6450 | @Override |
| 6451 | public void clearSavedANRState() { |
| 6452 | synchronized (mGlobalLock) { |
| 6453 | mLastANRState = null; |
| 6454 | } |
| 6455 | } |
| 6456 | |
| 6457 | @Override |
| 6458 | public void dump(String cmd, FileDescriptor fd, PrintWriter pw, String[] args, int opti, |
| 6459 | boolean dumpAll, boolean dumpClient, String dumpPackage) { |
| 6460 | synchronized (mGlobalLock) { |
| 6461 | if (DUMP_ACTIVITIES_CMD.equals(cmd) || DUMP_ACTIVITIES_SHORT_CMD.equals(cmd)) { |
| 6462 | dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage); |
| 6463 | } else if (DUMP_LASTANR_CMD.equals(cmd)) { |
| 6464 | dumpLastANRLocked(pw); |
| 6465 | } else if (DUMP_LASTANR_TRACES_CMD.equals(cmd)) { |
| 6466 | dumpLastANRTracesLocked(pw); |
| 6467 | } else if (DUMP_STARTER_CMD.equals(cmd)) { |
| 6468 | dumpActivityStarterLocked(pw, dumpPackage); |
| 6469 | } else if (DUMP_CONTAINERS_CMD.equals(cmd)) { |
| 6470 | dumpActivityContainersLocked(pw); |
| 6471 | } else if (DUMP_RECENTS_CMD.equals(cmd) || DUMP_RECENTS_SHORT_CMD.equals(cmd)) { |
| 6472 | if (getRecentTasks() != null) { |
| 6473 | getRecentTasks().dump(pw, dumpAll, dumpPackage); |
| 6474 | } |
| 6475 | } |
| 6476 | } |
| 6477 | } |
| 6478 | |
| 6479 | @Override |
| 6480 | public boolean dumpForProcesses(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 6481 | String dumpPackage, int dumpAppId, boolean needSep, boolean testPssMode, |
| 6482 | int wakefulness) { |
| 6483 | synchronized (mGlobalLock) { |
| 6484 | if (mHomeProcess != null && (dumpPackage == null |
| 6485 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
| 6486 | if (needSep) { |
| 6487 | pw.println(); |
| 6488 | needSep = false; |
| 6489 | } |
| 6490 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 6491 | } |
| 6492 | if (mPreviousProcess != null && (dumpPackage == null |
| 6493 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 6494 | if (needSep) { |
| 6495 | pw.println(); |
| 6496 | needSep = false; |
| 6497 | } |
| 6498 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 6499 | } |
| 6500 | if (dumpAll && (mPreviousProcess == null || dumpPackage == null |
| 6501 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
| 6502 | StringBuilder sb = new StringBuilder(128); |
| 6503 | sb.append(" mPreviousProcessVisibleTime: "); |
| 6504 | TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb); |
| 6505 | pw.println(sb); |
| 6506 | } |
| 6507 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 6508 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
| 6509 | if (needSep) { |
| 6510 | pw.println(); |
| 6511 | needSep = false; |
| 6512 | } |
| 6513 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 6514 | } |
| 6515 | if (dumpPackage == null) { |
| 6516 | pw.println(" mGlobalConfiguration: " + getGlobalConfiguration()); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6517 | mRootActivityContainer.dumpDisplayConfigs(pw, " "); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6518 | } |
| 6519 | if (dumpAll) { |
| 6520 | if (dumpPackage == null) { |
| 6521 | pw.println(" mConfigWillChange: " |
| 6522 | + getTopDisplayFocusedStack().mConfigWillChange); |
| 6523 | } |
| 6524 | if (mCompatModePackages.getPackages().size() > 0) { |
| 6525 | boolean printed = false; |
| 6526 | for (Map.Entry<String, Integer> entry |
| 6527 | : mCompatModePackages.getPackages().entrySet()) { |
| 6528 | String pkg = entry.getKey(); |
| 6529 | int mode = entry.getValue(); |
| 6530 | if (dumpPackage != null && !dumpPackage.equals(pkg)) { |
| 6531 | continue; |
| 6532 | } |
| 6533 | if (!printed) { |
| 6534 | pw.println(" mScreenCompatPackages:"); |
| 6535 | printed = true; |
| 6536 | } |
| 6537 | pw.println(" " + pkg + ": " + mode); |
| 6538 | } |
| 6539 | } |
| 6540 | } |
| 6541 | |
| 6542 | if (dumpPackage == null) { |
| 6543 | pw.println(" mWakefulness=" |
| 6544 | + PowerManagerInternal.wakefulnessToString(wakefulness)); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6545 | pw.println(" mSleepTokens=" + mRootActivityContainer.mSleepTokens); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6546 | if (mRunningVoice != null) { |
| 6547 | pw.println(" mRunningVoice=" + mRunningVoice); |
| 6548 | pw.println(" mVoiceWakeLock" + mVoiceWakeLock); |
| 6549 | } |
| 6550 | pw.println(" mSleeping=" + mSleeping); |
| 6551 | pw.println(" mShuttingDown=" + mShuttingDown + " mTestPssMode=" + testPssMode); |
| 6552 | pw.println(" mVrController=" + mVrController); |
| 6553 | } |
| 6554 | if (mCurAppTimeTracker != null) { |
| 6555 | mCurAppTimeTracker.dumpWithHeader(pw, " ", true); |
| 6556 | } |
| 6557 | if (mAllowAppSwitchUids.size() > 0) { |
| 6558 | boolean printed = false; |
| 6559 | for (int i = 0; i < mAllowAppSwitchUids.size(); i++) { |
| 6560 | ArrayMap<String, Integer> types = mAllowAppSwitchUids.valueAt(i); |
| 6561 | for (int j = 0; j < types.size(); j++) { |
| 6562 | if (dumpPackage == null || |
| 6563 | UserHandle.getAppId(types.valueAt(j).intValue()) == dumpAppId) { |
| 6564 | if (needSep) { |
| 6565 | pw.println(); |
| 6566 | needSep = false; |
| 6567 | } |
| 6568 | if (!printed) { |
| 6569 | pw.println(" mAllowAppSwitchUids:"); |
| 6570 | printed = true; |
| 6571 | } |
| 6572 | pw.print(" User "); |
| 6573 | pw.print(mAllowAppSwitchUids.keyAt(i)); |
| 6574 | pw.print(": Type "); |
| 6575 | pw.print(types.keyAt(j)); |
| 6576 | pw.print(" = "); |
| 6577 | UserHandle.formatUid(pw, types.valueAt(j).intValue()); |
| 6578 | pw.println(); |
| 6579 | } |
| 6580 | } |
| 6581 | } |
| 6582 | } |
| 6583 | if (dumpPackage == null) { |
| 6584 | if (mController != null) { |
| 6585 | pw.println(" mController=" + mController |
| 6586 | + " mControllerIsAMonkey=" + mControllerIsAMonkey); |
| 6587 | } |
| 6588 | pw.println(" mGoingToSleep=" + mStackSupervisor.mGoingToSleep); |
| 6589 | pw.println(" mLaunchingActivity=" + mStackSupervisor.mLaunchingActivity); |
| 6590 | } |
| 6591 | |
| 6592 | return needSep; |
| 6593 | } |
| 6594 | } |
| 6595 | |
| 6596 | @Override |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame^] | 6597 | public void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage, |
| 6598 | int wakeFullness, boolean testPssMode) { |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6599 | synchronized (mGlobalLock) { |
| 6600 | if (dumpPackage == null) { |
| 6601 | getGlobalConfiguration().writeToProto(proto, GLOBAL_CONFIGURATION); |
| 6602 | proto.write(CONFIG_WILL_CHANGE, getTopDisplayFocusedStack().mConfigWillChange); |
sanryhuang | 498e77e | 2018-12-06 14:57:01 +0800 | [diff] [blame^] | 6603 | writeSleepStateToProto(proto, wakeFullness, testPssMode); |
| 6604 | if (mRunningVoice != null) { |
| 6605 | final long vrToken = proto.start( |
| 6606 | ActivityManagerServiceDumpProcessesProto.RUNNING_VOICE); |
| 6607 | proto.write(ActivityManagerServiceDumpProcessesProto.Voice.SESSION, |
| 6608 | mRunningVoice.toString()); |
| 6609 | mVoiceWakeLock.writeToProto( |
| 6610 | proto, ActivityManagerServiceDumpProcessesProto.Voice.WAKELOCK); |
| 6611 | proto.end(vrToken); |
| 6612 | } |
| 6613 | mVrController.writeToProto(proto, |
| 6614 | ActivityManagerServiceDumpProcessesProto.VR_CONTROLLER); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6615 | if (mController != null) { |
| 6616 | final long token = proto.start(CONTROLLER); |
| 6617 | proto.write(CONTROLLER, mController.toString()); |
| 6618 | proto.write(IS_A_MONKEY, mControllerIsAMonkey); |
| 6619 | proto.end(token); |
| 6620 | } |
| 6621 | mStackSupervisor.mGoingToSleep.writeToProto(proto, GOING_TO_SLEEP); |
| 6622 | mStackSupervisor.mLaunchingActivity.writeToProto(proto, LAUNCHING_ACTIVITY); |
| 6623 | } |
| 6624 | |
| 6625 | if (mHomeProcess != null && (dumpPackage == null |
| 6626 | || mHomeProcess.mPkgList.contains(dumpPackage))) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 6627 | mHomeProcess.writeToProto(proto, HOME_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6628 | } |
| 6629 | |
| 6630 | if (mPreviousProcess != null && (dumpPackage == null |
| 6631 | || mPreviousProcess.mPkgList.contains(dumpPackage))) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 6632 | mPreviousProcess.writeToProto(proto, PREVIOUS_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6633 | proto.write(PREVIOUS_PROC_VISIBLE_TIME_MS, mPreviousProcessVisibleTime); |
| 6634 | } |
| 6635 | |
| 6636 | if (mHeavyWeightProcess != null && (dumpPackage == null |
| 6637 | || mHeavyWeightProcess.mPkgList.contains(dumpPackage))) { |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 6638 | mHeavyWeightProcess.writeToProto(proto, HEAVY_WEIGHT_PROC); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6639 | } |
| 6640 | |
| 6641 | for (Map.Entry<String, Integer> entry |
| 6642 | : mCompatModePackages.getPackages().entrySet()) { |
| 6643 | String pkg = entry.getKey(); |
| 6644 | int mode = entry.getValue(); |
| 6645 | if (dumpPackage == null || dumpPackage.equals(pkg)) { |
| 6646 | long compatToken = proto.start(SCREEN_COMPAT_PACKAGES); |
| 6647 | proto.write(PACKAGE, pkg); |
| 6648 | proto.write(MODE, mode); |
| 6649 | proto.end(compatToken); |
| 6650 | } |
| 6651 | } |
| 6652 | |
| 6653 | if (mCurAppTimeTracker != null) { |
| 6654 | mCurAppTimeTracker.writeToProto(proto, CURRENT_TRACKER, true); |
| 6655 | } |
| 6656 | |
| 6657 | } |
| 6658 | } |
| 6659 | |
| 6660 | @Override |
| 6661 | public boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, |
| 6662 | String[] args, int opti, boolean dumpAll, boolean dumpVisibleStacksOnly, |
| 6663 | boolean dumpFocusedStackOnly) { |
| 6664 | synchronized (mGlobalLock) { |
| 6665 | return ActivityTaskManagerService.this.dumpActivity(fd, pw, name, args, opti, |
| 6666 | dumpAll, dumpVisibleStacksOnly, dumpFocusedStackOnly); |
| 6667 | } |
| 6668 | } |
| 6669 | |
| 6670 | @Override |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 6671 | public void dumpForOom(PrintWriter pw) { |
| 6672 | synchronized (mGlobalLock) { |
| 6673 | pw.println(" mHomeProcess: " + mHomeProcess); |
| 6674 | pw.println(" mPreviousProcess: " + mPreviousProcess); |
| 6675 | if (mHeavyWeightProcess != null) { |
| 6676 | pw.println(" mHeavyWeightProcess: " + mHeavyWeightProcess); |
| 6677 | } |
| 6678 | } |
| 6679 | } |
| 6680 | |
| 6681 | @Override |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6682 | public boolean canGcNow() { |
| 6683 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6684 | return isSleeping() || mRootActivityContainer.allResumedActivitiesIdle(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6685 | } |
| 6686 | } |
| 6687 | |
| 6688 | @Override |
| 6689 | public WindowProcessController getTopApp() { |
| 6690 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6691 | final ActivityRecord top = mRootActivityContainer.getTopResumedActivity(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6692 | return top != null ? top.app : null; |
| 6693 | } |
| 6694 | } |
| 6695 | |
| 6696 | @Override |
| 6697 | public void rankTaskLayersIfNeeded() { |
| 6698 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6699 | if (mRootActivityContainer != null) { |
| 6700 | mRootActivityContainer.rankTaskLayersIfNeeded(); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6701 | } |
| 6702 | } |
| 6703 | } |
| 6704 | |
| 6705 | @Override |
| 6706 | public void scheduleDestroyAllActivities(String reason) { |
| 6707 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6708 | mRootActivityContainer.scheduleDestroyAllActivities(null, reason); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6709 | } |
| 6710 | } |
| 6711 | |
| 6712 | @Override |
| 6713 | public void removeUser(int userId) { |
| 6714 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6715 | mRootActivityContainer.removeUser(userId); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6716 | } |
| 6717 | } |
| 6718 | |
| 6719 | @Override |
| 6720 | public boolean switchUser(int userId, UserState userState) { |
| 6721 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6722 | return mRootActivityContainer.switchUser(userId, userState); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6723 | } |
| 6724 | } |
| 6725 | |
| 6726 | @Override |
| 6727 | public void onHandleAppCrash(WindowProcessController wpc) { |
| 6728 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6729 | mRootActivityContainer.handleAppCrash(wpc); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 6730 | } |
| 6731 | } |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 6732 | |
| 6733 | @Override |
| 6734 | public int finishTopCrashedActivities(WindowProcessController crashedApp, String reason) { |
| 6735 | synchronized (mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 6736 | return mRootActivityContainer.finishTopCrashedActivities(crashedApp, reason); |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 6737 | } |
| 6738 | } |
Wale Ogunwale | bff2df4 | 2018-10-18 17:09:19 -0700 | [diff] [blame] | 6739 | |
| 6740 | @Override |
| 6741 | public void onUidActive(int uid, int procState) { |
| 6742 | synchronized (mGlobalLock) { |
| 6743 | mActiveUids.put(uid, procState); |
| 6744 | } |
| 6745 | } |
| 6746 | |
| 6747 | @Override |
| 6748 | public void onUidInactive(int uid) { |
| 6749 | synchronized (mGlobalLock) { |
| 6750 | mActiveUids.remove(uid); |
| 6751 | } |
| 6752 | } |
| 6753 | |
| 6754 | @Override |
| 6755 | public void onActiveUidsCleared() { |
| 6756 | synchronized (mGlobalLock) { |
| 6757 | mActiveUids.clear(); |
| 6758 | } |
| 6759 | } |
| 6760 | |
| 6761 | @Override |
| 6762 | public void onUidProcStateChanged(int uid, int procState) { |
| 6763 | synchronized (mGlobalLock) { |
| 6764 | if (mActiveUids.get(uid) != null) { |
| 6765 | mActiveUids.put(uid, procState); |
| 6766 | } |
| 6767 | } |
| 6768 | } |
Wale Ogunwale | 9de1944 | 2018-10-18 19:05:03 -0700 | [diff] [blame] | 6769 | |
| 6770 | @Override |
| 6771 | public void onUidAddedToPendingTempWhitelist(int uid, String tag) { |
| 6772 | synchronized (mGlobalLock) { |
| 6773 | mPendingTempWhitelist.put(uid, tag); |
| 6774 | } |
| 6775 | } |
| 6776 | |
| 6777 | @Override |
| 6778 | public void onUidRemovedFromPendingTempWhitelist(int uid) { |
| 6779 | synchronized (mGlobalLock) { |
| 6780 | mPendingTempWhitelist.remove(uid); |
| 6781 | } |
| 6782 | } |
Wale Ogunwale | e217229 | 2018-10-25 10:11:10 -0700 | [diff] [blame] | 6783 | |
| 6784 | @Override |
| 6785 | public boolean handleAppCrashInActivityController(String processName, int pid, |
| 6786 | String shortMsg, String longMsg, long timeMillis, String stackTrace, |
| 6787 | Runnable killCrashingAppCallback) { |
| 6788 | synchronized (mGlobalLock) { |
| 6789 | if (mController == null) { |
| 6790 | return false; |
| 6791 | } |
| 6792 | |
| 6793 | try { |
| 6794 | if (!mController.appCrashed(processName, pid, shortMsg, longMsg, timeMillis, |
| 6795 | stackTrace)) { |
| 6796 | killCrashingAppCallback.run(); |
| 6797 | return true; |
| 6798 | } |
| 6799 | } catch (RemoteException e) { |
| 6800 | mController = null; |
| 6801 | Watchdog.getInstance().setActivityController(null); |
| 6802 | } |
| 6803 | return false; |
| 6804 | } |
| 6805 | } |
Wale Ogunwale | d7889f5 | 2018-10-25 11:03:20 -0700 | [diff] [blame] | 6806 | |
| 6807 | @Override |
| 6808 | public void removeRecentTasksByPackageName(String packageName, int userId) { |
| 6809 | synchronized (mGlobalLock) { |
| 6810 | mRecentTasks.removeTasksByPackageName(packageName, userId); |
| 6811 | } |
| 6812 | } |
| 6813 | |
| 6814 | @Override |
| 6815 | public void cleanupRecentTasksForUser(int userId) { |
| 6816 | synchronized (mGlobalLock) { |
| 6817 | mRecentTasks.cleanupLocked(userId); |
| 6818 | } |
| 6819 | } |
| 6820 | |
| 6821 | @Override |
| 6822 | public void loadRecentTasksForUser(int userId) { |
| 6823 | synchronized (mGlobalLock) { |
| 6824 | mRecentTasks.loadUserRecentsLocked(userId); |
| 6825 | } |
| 6826 | } |
| 6827 | |
| 6828 | @Override |
| 6829 | public void onPackagesSuspendedChanged(String[] packages, boolean suspended, int userId) { |
| 6830 | synchronized (mGlobalLock) { |
| 6831 | mRecentTasks.onPackagesSuspendedChanged(packages, suspended, userId); |
| 6832 | } |
| 6833 | } |
| 6834 | |
| 6835 | @Override |
| 6836 | public void flushRecentTasks() { |
| 6837 | mRecentTasks.flush(); |
| 6838 | } |
Wale Ogunwale | d4d67d0 | 2018-10-25 18:09:39 -0700 | [diff] [blame] | 6839 | |
| 6840 | @Override |
| 6841 | public WindowProcessController getHomeProcess() { |
| 6842 | synchronized (mGlobalLock) { |
| 6843 | return mHomeProcess; |
| 6844 | } |
| 6845 | } |
| 6846 | |
| 6847 | @Override |
| 6848 | public WindowProcessController getPreviousProcess() { |
| 6849 | synchronized (mGlobalLock) { |
| 6850 | return mPreviousProcess; |
| 6851 | } |
| 6852 | } |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 6853 | |
| 6854 | @Override |
| 6855 | public void clearLockedTasks(String reason) { |
| 6856 | synchronized (mGlobalLock) { |
| 6857 | getLockTaskController().clearLockedTasks(reason); |
| 6858 | } |
| 6859 | } |
| 6860 | |
| 6861 | @Override |
| 6862 | public void updateUserConfiguration() { |
| 6863 | synchronized (mGlobalLock) { |
| 6864 | final Configuration configuration = new Configuration(getGlobalConfiguration()); |
| 6865 | final int currentUserId = mAmInternal.getCurrentUserId(); |
| 6866 | Settings.System.adjustConfigurationForUser(mContext.getContentResolver(), |
| 6867 | configuration, currentUserId, Settings.System.canWrite(mContext)); |
| 6868 | updateConfigurationLocked(configuration, null /* starting */, |
| 6869 | false /* initLocale */, false /* persistent */, currentUserId, |
| 6870 | false /* deferResume */); |
| 6871 | } |
| 6872 | } |
Wale Ogunwale | 387b34c | 2018-10-25 19:59:40 -0700 | [diff] [blame] | 6873 | |
| 6874 | @Override |
| 6875 | public boolean canShowErrorDialogs() { |
| 6876 | synchronized (mGlobalLock) { |
| 6877 | return mShowDialogs && !mSleeping && !mShuttingDown |
| 6878 | && !mKeyguardController.isKeyguardOrAodShowing(DEFAULT_DISPLAY) |
| 6879 | && !hasUserRestriction(UserManager.DISALLOW_SYSTEM_ERROR_DIALOGS, |
| 6880 | mAmInternal.getCurrentUserId()) |
| 6881 | && !(UserManager.isDeviceInDemoMode(mContext) |
| 6882 | && mAmInternal.getCurrentUser().isDemo()); |
| 6883 | } |
| 6884 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 6885 | |
| 6886 | @Override |
| 6887 | public void setProfileApp(String profileApp) { |
| 6888 | synchronized (mGlobalLock) { |
| 6889 | mProfileApp = profileApp; |
| 6890 | } |
| 6891 | } |
| 6892 | |
| 6893 | @Override |
| 6894 | public void setProfileProc(WindowProcessController wpc) { |
| 6895 | synchronized (mGlobalLock) { |
| 6896 | mProfileProc = wpc; |
| 6897 | } |
| 6898 | } |
| 6899 | |
| 6900 | @Override |
| 6901 | public void setProfilerInfo(ProfilerInfo profilerInfo) { |
| 6902 | synchronized (mGlobalLock) { |
| 6903 | mProfilerInfo = profilerInfo; |
| 6904 | } |
| 6905 | } |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 6906 | |
| 6907 | @Override |
| 6908 | public ActivityMetricsLaunchObserverRegistry getLaunchObserverRegistry() { |
| 6909 | synchronized (mGlobalLock) { |
| 6910 | return mStackSupervisor.getActivityMetricsLogger().getLaunchObserverRegistry(); |
| 6911 | } |
| 6912 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 6913 | } |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 6914 | } |