Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Matthew Ng | cb7ac67 | 2017-07-21 17:27:42 -0700 | [diff] [blame] | 19 | import static com.android.server.wm.TaskSnapshotPersister.DISABLE_FULL_SIZED_BITMAPS; |
| 20 | import static com.android.server.wm.TaskSnapshotPersister.REDUCED_SCALE; |
Winson Chung | 3e13ef8 | 2017-06-29 12:41:14 -0700 | [diff] [blame] | 21 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 22 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 23 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 24 | import android.annotation.Nullable; |
Jorim Jaggi | 3d73260 | 2017-02-22 17:56:40 +0100 | [diff] [blame] | 25 | import android.app.ActivityManager; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 26 | import android.app.ActivityManager.StackId; |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 27 | import android.app.ActivityManager.TaskSnapshot; |
Keyvan Amiri | e681cec | 2017-06-05 22:48:26 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageManager; |
Jorim Jaggi | 6aead1c | 2017-05-23 15:07:44 +0200 | [diff] [blame] | 29 | import android.graphics.Bitmap; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 30 | import android.graphics.GraphicBuffer; |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 31 | import android.graphics.Rect; |
Jorim Jaggi | f9084ec | 2017-01-16 13:16:59 +0100 | [diff] [blame] | 32 | import android.os.Environment; |
Jorim Jaggi | 51304d7 | 2017-05-17 17:25:32 +0200 | [diff] [blame] | 33 | import android.os.Handler; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 34 | import android.util.ArraySet; |
Winson Chung | 3e13ef8 | 2017-06-29 12:41:14 -0700 | [diff] [blame] | 35 | import android.util.Slog; |
Winson Chung | 9109276 | 2017-05-24 14:08:48 -0700 | [diff] [blame] | 36 | import android.view.DisplayListCanvas; |
| 37 | import android.view.RenderNode; |
| 38 | import android.view.ThreadedRenderer; |
Jorim Jaggi | d635a4a | 2017-05-03 15:21:26 +0200 | [diff] [blame] | 39 | import android.view.WindowManager.LayoutParams; |
Guang Zhu | 09486a3 | 2017-06-06 03:27:44 +0000 | [diff] [blame] | 40 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 41 | import com.android.internal.annotations.VisibleForTesting; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame^] | 42 | import com.android.server.policy.WindowManagerPolicy.ScreenOffListener; |
| 43 | import com.android.server.policy.WindowManagerPolicy.StartingSurface; |
Jorim Jaggi | d635a4a | 2017-05-03 15:21:26 +0200 | [diff] [blame] | 44 | import com.android.server.wm.TaskSnapshotSurface.SystemBarBackgroundPainter; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 45 | |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame^] | 46 | import com.google.android.collect.Sets; |
| 47 | |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 48 | import java.io.PrintWriter; |
| 49 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 50 | /** |
| 51 | * When an app token becomes invisible, we take a snapshot (bitmap) of the corresponding task and |
| 52 | * put it into our cache. Internally we use gralloc buffers to be able to draw them wherever we |
| 53 | * like without any copying. |
| 54 | * <p> |
| 55 | * System applications may retrieve a snapshot to represent the current state of a task, and draw |
| 56 | * them in their own process. |
| 57 | * <p> |
| 58 | * When we task becomes visible again, we show a starting window with the snapshot as the content to |
| 59 | * make app transitions more responsive. |
| 60 | * <p> |
| 61 | * To access this class, acquire the global window manager lock. |
| 62 | */ |
| 63 | class TaskSnapshotController { |
Winson Chung | 3e13ef8 | 2017-06-29 12:41:14 -0700 | [diff] [blame] | 64 | private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskSnapshotController" : TAG_WM; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 65 | |
Jorim Jaggi | 8f4fe6e | 2017-03-14 18:21:40 +0100 | [diff] [blame] | 66 | /** |
| 67 | * Return value for {@link #getSnapshotMode}: We are allowed to take a real screenshot to be |
| 68 | * used as the snapshot. |
| 69 | */ |
| 70 | @VisibleForTesting |
| 71 | static final int SNAPSHOT_MODE_REAL = 0; |
| 72 | |
| 73 | /** |
| 74 | * Return value for {@link #getSnapshotMode}: We are not allowed to take a real screenshot but |
| 75 | * we should try to use the app theme to create a dummy representation of the app. |
| 76 | */ |
| 77 | @VisibleForTesting |
| 78 | static final int SNAPSHOT_MODE_APP_THEME = 1; |
| 79 | |
| 80 | /** |
| 81 | * Return value for {@link #getSnapshotMode}: We aren't allowed to take any snapshot. |
| 82 | */ |
| 83 | @VisibleForTesting |
| 84 | static final int SNAPSHOT_MODE_NONE = 2; |
| 85 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 86 | private final WindowManagerService mService; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 87 | |
Jorim Jaggi | 7361bab | 2017-01-16 17:17:58 +0100 | [diff] [blame] | 88 | private final TaskSnapshotCache mCache; |
Jorim Jaggi | f9084ec | 2017-01-16 13:16:59 +0100 | [diff] [blame] | 89 | private final TaskSnapshotPersister mPersister = new TaskSnapshotPersister( |
| 90 | Environment::getDataSystemCeDirectory); |
| 91 | private final TaskSnapshotLoader mLoader = new TaskSnapshotLoader(mPersister); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 92 | private final ArraySet<Task> mTmpTasks = new ArraySet<>(); |
Jorim Jaggi | 51304d7 | 2017-05-17 17:25:32 +0200 | [diff] [blame] | 93 | private final Handler mHandler = new Handler(); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 94 | |
Keyvan Amiri | e681cec | 2017-06-05 22:48:26 -0700 | [diff] [blame] | 95 | /** |
| 96 | * Flag indicating whether we are running on an Android TV device. |
| 97 | */ |
| 98 | private final boolean mIsRunningOnTv; |
| 99 | |
Juho Ha | f5dd7cc | 2017-06-15 11:38:56 +0900 | [diff] [blame] | 100 | /** |
| 101 | * Flag indicating whether we are running on an IoT device. |
| 102 | */ |
| 103 | private final boolean mIsRunningOnIoT; |
| 104 | |
Matthew Ng | 9537819 | 2017-08-16 11:57:00 -0700 | [diff] [blame] | 105 | /** |
| 106 | * Flag indicating whether we are running on an Android Wear device. |
| 107 | */ |
| 108 | private final boolean mIsRunningOnWear; |
| 109 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 110 | TaskSnapshotController(WindowManagerService service) { |
| 111 | mService = service; |
Jorim Jaggi | 7361bab | 2017-01-16 17:17:58 +0100 | [diff] [blame] | 112 | mCache = new TaskSnapshotCache(mService, mLoader); |
Keyvan Amiri | e681cec | 2017-06-05 22:48:26 -0700 | [diff] [blame] | 113 | mIsRunningOnTv = mService.mContext.getPackageManager().hasSystemFeature( |
| 114 | PackageManager.FEATURE_LEANBACK); |
Juho Ha | f5dd7cc | 2017-06-15 11:38:56 +0900 | [diff] [blame] | 115 | mIsRunningOnIoT = mService.mContext.getPackageManager().hasSystemFeature( |
| 116 | PackageManager.FEATURE_EMBEDDED); |
Matthew Ng | 9537819 | 2017-08-16 11:57:00 -0700 | [diff] [blame] | 117 | mIsRunningOnWear = mService.mContext.getPackageManager().hasSystemFeature( |
| 118 | PackageManager.FEATURE_WATCH); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Jorim Jaggi | f9084ec | 2017-01-16 13:16:59 +0100 | [diff] [blame] | 121 | void systemReady() { |
| 122 | mPersister.start(); |
| 123 | } |
| 124 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 125 | void onTransitionStarting() { |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 126 | handleClosingApps(mService.mClosingApps); |
| 127 | } |
| 128 | |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 129 | /** |
| 130 | * Called when the visibility of an app changes outside of the regular app transition flow. |
| 131 | */ |
| 132 | void notifyAppVisibilityChanged(AppWindowToken appWindowToken, boolean visible) { |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 133 | if (!visible) { |
| 134 | handleClosingApps(Sets.newArraySet(appWindowToken)); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | private void handleClosingApps(ArraySet<AppWindowToken> closingApps) { |
Keyvan Amiri | e681cec | 2017-06-05 22:48:26 -0700 | [diff] [blame] | 139 | if (shouldDisableSnapshots()) { |
Jorim Jaggi | 3d73260 | 2017-02-22 17:56:40 +0100 | [diff] [blame] | 140 | return; |
| 141 | } |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 142 | |
| 143 | // We need to take a snapshot of the task if and only if all activities of the task are |
| 144 | // either closing or hidden. |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 145 | getClosingTasks(closingApps, mTmpTasks); |
Jorim Jaggi | 51304d7 | 2017-05-17 17:25:32 +0200 | [diff] [blame] | 146 | snapshotTasks(mTmpTasks); |
| 147 | |
| 148 | } |
| 149 | |
| 150 | private void snapshotTasks(ArraySet<Task> tasks) { |
| 151 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 152 | final Task task = tasks.valueAt(i); |
Jorim Jaggi | 8f4fe6e | 2017-03-14 18:21:40 +0100 | [diff] [blame] | 153 | final int mode = getSnapshotMode(task); |
| 154 | final TaskSnapshot snapshot; |
| 155 | switch (mode) { |
| 156 | case SNAPSHOT_MODE_NONE: |
| 157 | continue; |
| 158 | case SNAPSHOT_MODE_APP_THEME: |
| 159 | snapshot = drawAppThemeSnapshot(task); |
| 160 | break; |
| 161 | case SNAPSHOT_MODE_REAL: |
| 162 | snapshot = snapshotTask(task); |
| 163 | break; |
| 164 | default: |
| 165 | snapshot = null; |
| 166 | break; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 167 | } |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 168 | if (snapshot != null) { |
Winson Chung | 3e13ef8 | 2017-06-29 12:41:14 -0700 | [diff] [blame] | 169 | final GraphicBuffer buffer = snapshot.getSnapshot(); |
| 170 | if (buffer.getWidth() == 0 || buffer.getHeight() == 0) { |
| 171 | buffer.destroy(); |
| 172 | Slog.e(TAG, "Invalid task snapshot dimensions " + buffer.getWidth() + "x" |
| 173 | + buffer.getHeight()); |
| 174 | } else { |
| 175 | mCache.putSnapshot(task, snapshot); |
| 176 | mPersister.persistSnapshot(task.mTaskId, task.mUserId, snapshot); |
| 177 | if (task.getController() != null) { |
| 178 | task.getController().reportSnapshotChanged(snapshot); |
| 179 | } |
Jorim Jaggi | fb9d78a | 2017-01-05 18:57:12 +0100 | [diff] [blame] | 180 | } |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
Jorim Jaggi | 7361bab | 2017-01-16 17:17:58 +0100 | [diff] [blame] | 185 | /** |
| 186 | * Retrieves a snapshot. If {@param restoreFromDisk} equals {@code true}, DO HOLD THE WINDOW |
| 187 | * MANAGER LOCK WHEN CALLING THIS METHOD! |
| 188 | */ |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 189 | @Nullable TaskSnapshot getSnapshot(int taskId, int userId, boolean restoreFromDisk, |
| 190 | boolean reducedResolution) { |
Matthew Ng | cb7ac67 | 2017-07-21 17:27:42 -0700 | [diff] [blame] | 191 | return mCache.getSnapshot(taskId, userId, restoreFromDisk, reducedResolution |
| 192 | || DISABLE_FULL_SIZED_BITMAPS); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Creates a starting surface for {@param token} with {@param snapshot}. DO NOT HOLD THE WINDOW |
| 197 | * MANAGER LOCK WHEN CALLING THIS METHOD! |
| 198 | */ |
| 199 | StartingSurface createStartingSurface(AppWindowToken token, |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 200 | TaskSnapshot snapshot) { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 201 | return TaskSnapshotSurface.create(mService, token, snapshot); |
| 202 | } |
| 203 | |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 204 | private TaskSnapshot snapshotTask(Task task) { |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 205 | final AppWindowToken top = task.getTopChild(); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 206 | if (top == null) { |
| 207 | return null; |
| 208 | } |
Jorim Jaggi | dd5986e | 2017-04-11 15:50:19 -0700 | [diff] [blame] | 209 | final WindowState mainWindow = top.findMainWindow(); |
| 210 | if (mainWindow == null) { |
| 211 | return null; |
| 212 | } |
Matthew Ng | cb7ac67 | 2017-07-21 17:27:42 -0700 | [diff] [blame] | 213 | final boolean isLowRamDevice = ActivityManager.isLowRamDeviceStatic(); |
| 214 | final float scaleFraction = isLowRamDevice ? REDUCED_SCALE : 1f; |
Jorim Jaggi | 6a7a859 | 2017-01-12 00:44:33 +0100 | [diff] [blame] | 215 | final GraphicBuffer buffer = top.mDisplayContent.screenshotApplicationsToBuffer(top.token, |
Matthew Ng | cb7ac67 | 2017-07-21 17:27:42 -0700 | [diff] [blame] | 216 | -1, -1, false, scaleFraction, false, true); |
Juho Ha | d864b44 | 2017-06-12 20:15:31 +0900 | [diff] [blame] | 217 | if (buffer == null || buffer.getWidth() <= 1 || buffer.getHeight() <= 1) { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 218 | return null; |
| 219 | } |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 220 | return new TaskSnapshot(buffer, top.getConfiguration().orientation, |
Matthew Ng | cb7ac67 | 2017-07-21 17:27:42 -0700 | [diff] [blame] | 221 | minRect(mainWindow.mContentInsets, mainWindow.mStableInsets), |
| 222 | isLowRamDevice /* reduced */, scaleFraction /* scale */); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 223 | } |
| 224 | |
Keyvan Amiri | e681cec | 2017-06-05 22:48:26 -0700 | [diff] [blame] | 225 | private boolean shouldDisableSnapshots() { |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 226 | return mIsRunningOnWear || mIsRunningOnTv || mIsRunningOnIoT; |
Keyvan Amiri | e681cec | 2017-06-05 22:48:26 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 229 | private Rect minRect(Rect rect1, Rect rect2) { |
| 230 | return new Rect(Math.min(rect1.left, rect2.left), |
| 231 | Math.min(rect1.top, rect2.top), |
| 232 | Math.min(rect1.right, rect2.right), |
| 233 | Math.min(rect1.bottom, rect2.bottom)); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Retrieves all closing tasks based on the list of closing apps during an app transition. |
| 238 | */ |
| 239 | @VisibleForTesting |
| 240 | void getClosingTasks(ArraySet<AppWindowToken> closingApps, ArraySet<Task> outClosingTasks) { |
| 241 | outClosingTasks.clear(); |
| 242 | for (int i = closingApps.size() - 1; i >= 0; i--) { |
| 243 | final AppWindowToken atoken = closingApps.valueAt(i); |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 244 | final Task task = atoken.getTask(); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 245 | |
| 246 | // If the task of the app is not visible anymore, it means no other app in that task |
| 247 | // is opening. Thus, the task is closing. |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 248 | if (task != null && !task.isVisible()) { |
| 249 | outClosingTasks.add(task); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | } |
| 253 | |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 254 | @VisibleForTesting |
Jorim Jaggi | 8f4fe6e | 2017-03-14 18:21:40 +0100 | [diff] [blame] | 255 | int getSnapshotMode(Task task) { |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 256 | final AppWindowToken topChild = task.getTopChild(); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 257 | if (!task.isActivityTypeStandardOrUndefined()) { |
Jorim Jaggi | 8f4fe6e | 2017-03-14 18:21:40 +0100 | [diff] [blame] | 258 | return SNAPSHOT_MODE_NONE; |
Jorim Jaggi | d635a4a | 2017-05-03 15:21:26 +0200 | [diff] [blame] | 259 | } else if (topChild != null && topChild.shouldUseAppThemeSnapshot()) { |
Jorim Jaggi | 8f4fe6e | 2017-03-14 18:21:40 +0100 | [diff] [blame] | 260 | return SNAPSHOT_MODE_APP_THEME; |
| 261 | } else { |
| 262 | return SNAPSHOT_MODE_REAL; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * If we are not allowed to take a real screenshot, this attempts to represent the app as best |
| 268 | * as possible by using the theme's window background. |
| 269 | */ |
| 270 | private TaskSnapshot drawAppThemeSnapshot(Task task) { |
| 271 | final AppWindowToken topChild = task.getTopChild(); |
| 272 | if (topChild == null) { |
| 273 | return null; |
| 274 | } |
| 275 | final WindowState mainWindow = topChild.findMainWindow(); |
| 276 | if (mainWindow == null) { |
| 277 | return null; |
| 278 | } |
| 279 | final int color = task.getTaskDescription().getBackgroundColor(); |
Jorim Jaggi | d635a4a | 2017-05-03 15:21:26 +0200 | [diff] [blame] | 280 | final int statusBarColor = task.getTaskDescription().getStatusBarColor(); |
| 281 | final int navigationBarColor = task.getTaskDescription().getNavigationBarColor(); |
Jorim Jaggi | d635a4a | 2017-05-03 15:21:26 +0200 | [diff] [blame] | 282 | final LayoutParams attrs = mainWindow.getAttrs(); |
| 283 | final SystemBarBackgroundPainter decorPainter = new SystemBarBackgroundPainter(attrs.flags, |
| 284 | attrs.privateFlags, attrs.systemUiVisibility, statusBarColor, navigationBarColor); |
Winson Chung | 9109276 | 2017-05-24 14:08:48 -0700 | [diff] [blame] | 285 | final int width = mainWindow.getFrameLw().width(); |
| 286 | final int height = mainWindow.getFrameLw().height(); |
| 287 | |
| 288 | final RenderNode node = RenderNode.create("TaskSnapshotController", null); |
| 289 | node.setLeftTopRightBottom(0, 0, width, height); |
| 290 | node.setClipToBounds(false); |
| 291 | final DisplayListCanvas c = node.start(width, height); |
| 292 | c.drawColor(color); |
Jorim Jaggi | d635a4a | 2017-05-03 15:21:26 +0200 | [diff] [blame] | 293 | decorPainter.setInsets(mainWindow.mContentInsets, mainWindow.mStableInsets); |
| 294 | decorPainter.drawDecors(c, null /* statusBarExcludeFrame */); |
Winson Chung | 9109276 | 2017-05-24 14:08:48 -0700 | [diff] [blame] | 295 | node.end(c); |
| 296 | final Bitmap hwBitmap = ThreadedRenderer.createHardwareBitmap(node, width, height); |
Winson Chung | 6267f99 | 2017-10-06 14:01:10 -0700 | [diff] [blame] | 297 | if (hwBitmap == null) { |
| 298 | return null; |
| 299 | } |
Jorim Jaggi | 6aead1c | 2017-05-23 15:07:44 +0200 | [diff] [blame] | 300 | return new TaskSnapshot(hwBitmap.createGraphicBufferHandle(), |
| 301 | topChild.getConfiguration().orientation, mainWindow.mStableInsets, |
Matthew Ng | 30a7f7c | 2017-09-18 16:29:46 -0700 | [diff] [blame] | 302 | ActivityManager.isLowRamDeviceStatic() /* reduced */, 1.0f /* scale */); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 303 | } |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 304 | |
| 305 | /** |
| 306 | * Called when an {@link AppWindowToken} has been removed. |
| 307 | */ |
| 308 | void onAppRemoved(AppWindowToken wtoken) { |
Jorim Jaggi | 7361bab | 2017-01-16 17:17:58 +0100 | [diff] [blame] | 309 | mCache.onAppRemoved(wtoken); |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /** |
| 313 | * Called when the process of an {@link AppWindowToken} has died. |
| 314 | */ |
| 315 | void onAppDied(AppWindowToken wtoken) { |
Jorim Jaggi | 7361bab | 2017-01-16 17:17:58 +0100 | [diff] [blame] | 316 | mCache.onAppDied(wtoken); |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 317 | } |
| 318 | |
Jorim Jaggi | f9084ec | 2017-01-16 13:16:59 +0100 | [diff] [blame] | 319 | void notifyTaskRemovedFromRecents(int taskId, int userId) { |
Jorim Jaggi | 7361bab | 2017-01-16 17:17:58 +0100 | [diff] [blame] | 320 | mCache.onTaskRemoved(taskId); |
Jorim Jaggi | f9084ec | 2017-01-16 13:16:59 +0100 | [diff] [blame] | 321 | mPersister.onTaskRemovedFromRecents(taskId, userId); |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * See {@link TaskSnapshotPersister#removeObsoleteFiles} |
| 326 | */ |
| 327 | void removeObsoleteTaskFiles(ArraySet<Integer> persistentTaskIds, int[] runningUserIds) { |
| 328 | mPersister.removeObsoleteFiles(persistentTaskIds, runningUserIds); |
| 329 | } |
| 330 | |
Jorim Jaggi | a41b729 | 2017-05-11 23:50:34 +0200 | [diff] [blame] | 331 | /** |
| 332 | * Temporarily pauses/unpauses persisting of task snapshots. |
| 333 | * |
| 334 | * @param paused Whether task snapshot persisting should be paused. |
| 335 | */ |
| 336 | void setPersisterPaused(boolean paused) { |
| 337 | mPersister.setPaused(paused); |
| 338 | } |
| 339 | |
Jorim Jaggi | 51304d7 | 2017-05-17 17:25:32 +0200 | [diff] [blame] | 340 | /** |
| 341 | * Called when screen is being turned off. |
| 342 | */ |
| 343 | void screenTurningOff(ScreenOffListener listener) { |
Keyvan Amiri | e681cec | 2017-06-05 22:48:26 -0700 | [diff] [blame] | 344 | if (shouldDisableSnapshots()) { |
Jorim Jaggi | 51304d7 | 2017-05-17 17:25:32 +0200 | [diff] [blame] | 345 | listener.onScreenOff(); |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | // We can't take a snapshot when screen is off, so take a snapshot now! |
| 350 | mHandler.post(() -> { |
| 351 | try { |
| 352 | synchronized (mService.mWindowMap) { |
| 353 | mTmpTasks.clear(); |
| 354 | mService.mRoot.forAllTasks(task -> { |
| 355 | if (task.isVisible()) { |
| 356 | mTmpTasks.add(task); |
| 357 | } |
| 358 | }); |
| 359 | snapshotTasks(mTmpTasks); |
| 360 | } |
| 361 | } finally { |
| 362 | listener.onScreenOff(); |
| 363 | } |
| 364 | }); |
| 365 | } |
| 366 | |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 367 | void dump(PrintWriter pw, String prefix) { |
| 368 | mCache.dump(pw, prefix); |
| 369 | } |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 370 | } |