Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 17 | package com.android.systemui.recents.misc; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 18 | |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 20 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
| 21 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
| 22 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
| 23 | import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT; |
| 24 | |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 25 | import android.app.ActivityManager; |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 26 | import android.app.ActivityManagerNative; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 27 | import android.app.ActivityOptions; |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 28 | import android.app.AppGlobals; |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 29 | import android.app.IActivityManager; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 30 | import android.app.ITaskStackListener; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 31 | import android.content.ComponentName; |
Jason Monk | 56e09b4 | 2014-07-18 10:29:14 -0400 | [diff] [blame] | 32 | import android.content.ContentResolver; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 33 | import android.content.Context; |
| 34 | import android.content.Intent; |
| 35 | import android.content.pm.ActivityInfo; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 36 | import android.content.pm.ApplicationInfo; |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 37 | import android.content.pm.IPackageManager; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 38 | import android.content.pm.PackageManager; |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 39 | import android.content.pm.ResolveInfo; |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 40 | import android.content.res.Configuration; |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 41 | import android.content.res.Resources; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 42 | import android.graphics.Bitmap; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 43 | import android.graphics.BitmapFactory; |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 44 | import android.graphics.Canvas; |
| 45 | import android.graphics.Color; |
| 46 | import android.graphics.Paint; |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 47 | import android.graphics.Point; |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 48 | import android.graphics.PorterDuff; |
| 49 | import android.graphics.PorterDuffXfermode; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 50 | import android.graphics.Rect; |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 51 | import android.graphics.drawable.BitmapDrawable; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 52 | import android.graphics.drawable.ColorDrawable; |
| 53 | import android.graphics.drawable.Drawable; |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 54 | import android.os.Handler; |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 55 | import android.os.IRemoteCallback; |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 56 | import android.os.Looper; |
| 57 | import android.os.Message; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 58 | import android.os.ParcelFileDescriptor; |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 59 | import android.os.RemoteException; |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 60 | import android.os.SystemProperties; |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 61 | import android.os.UserHandle; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 62 | import android.os.UserManager; |
Jason Monk | 56e09b4 | 2014-07-18 10:29:14 -0400 | [diff] [blame] | 63 | import android.provider.Settings; |
Rubin Xu | efb844d | 2015-12-08 20:57:24 +0000 | [diff] [blame] | 64 | import android.util.ArraySet; |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 65 | import android.util.Log; |
Winson Chung | e1e20e1 | 2015-06-02 14:11:49 -0700 | [diff] [blame] | 66 | import android.util.MutableBoolean; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 67 | import android.view.Display; |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 68 | import android.view.IAppTransitionAnimationSpecsFuture; |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 69 | import android.view.IDockedStackListener; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 70 | import android.view.WindowManager; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 71 | import android.view.WindowManager.KeyboardShortcutsReceiver; |
Winson | c28098f | 2015-10-30 14:50:19 -0700 | [diff] [blame] | 72 | import android.view.WindowManagerGlobal; |
Winson Chung | ee44595 | 2014-09-09 16:12:59 +0200 | [diff] [blame] | 73 | import android.view.accessibility.AccessibilityManager; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 74 | |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 75 | import com.android.internal.app.AssistUtils; |
Winson | ab84fc5 | 2015-10-23 11:52:07 -0700 | [diff] [blame] | 76 | import com.android.internal.os.BackgroundThread; |
Winson Chung | 4e96eb7 | 2014-09-17 15:16:09 +0200 | [diff] [blame] | 77 | import com.android.systemui.R; |
Winson | c742f97 | 2015-11-12 11:32:21 -0800 | [diff] [blame] | 78 | import com.android.systemui.recents.RecentsDebugFlags; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 79 | import com.android.systemui.recents.RecentsImpl; |
Sid Soundararajan | 4bdb687 | 2016-03-18 13:42:10 -0700 | [diff] [blame] | 80 | import com.android.systemui.recents.tv.RecentsTvImpl; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 81 | import com.android.systemui.recents.model.ThumbnailData; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 82 | |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 83 | import java.io.IOException; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 84 | import java.util.ArrayList; |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 85 | import java.util.Iterator; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 86 | import java.util.List; |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame] | 87 | import java.util.Random; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * Acts as a shim around the real system services that we need to access data from, and provides |
| 91 | * a point of injection when testing UI. |
| 92 | */ |
| 93 | public class SystemServicesProxy { |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 94 | final static String TAG = "SystemServicesProxy"; |
| 95 | |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 96 | final static BitmapFactory.Options sBitmapOptions; |
Winson Chung | c35e670 | 2015-07-30 18:08:26 -0700 | [diff] [blame] | 97 | static { |
Winson Chung | c35e670 | 2015-07-30 18:08:26 -0700 | [diff] [blame] | 98 | sBitmapOptions = new BitmapFactory.Options(); |
| 99 | sBitmapOptions.inMutable = true; |
| 100 | } |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 101 | |
Jaewan Kim | 7ed7657 | 2016-03-17 18:15:07 +0900 | [diff] [blame] | 102 | final static List<String> sRecentsBlacklist; |
| 103 | static { |
| 104 | sRecentsBlacklist = new ArrayList<>(); |
| 105 | sRecentsBlacklist.add("com.android.systemui.tv.pip.PipOnboardingActivity"); |
| 106 | sRecentsBlacklist.add("com.android.systemui.tv.pip.PipMenuActivity"); |
| 107 | } |
| 108 | |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 109 | private static SystemServicesProxy sSystemServicesProxy; |
| 110 | |
Winson Chung | ee44595 | 2014-09-09 16:12:59 +0200 | [diff] [blame] | 111 | AccessibilityManager mAccm; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 112 | ActivityManager mAm; |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 113 | IActivityManager mIam; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 114 | PackageManager mPm; |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 115 | IPackageManager mIpm; |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 116 | AssistUtils mAssistUtils; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 117 | WindowManager mWm; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 118 | UserManager mUm; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 119 | Display mDisplay; |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 120 | String mRecentsPackage; |
Winson Chung | da5b84c | 2014-05-05 12:06:28 -0700 | [diff] [blame] | 121 | ComponentName mAssistComponent; |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 122 | |
| 123 | boolean mIsSafeMode; |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 124 | boolean mHasFreeformWorkspaceSupport; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 125 | |
| 126 | Bitmap mDummyIcon; |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 127 | int mDummyThumbnailWidth; |
| 128 | int mDummyThumbnailHeight; |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 129 | Paint mBgProtectionPaint; |
| 130 | Canvas mBgProtectionCanvas; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 131 | |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 132 | private final Handler mHandler = new H(); |
| 133 | |
| 134 | /** |
| 135 | * An abstract class to track task stack changes. |
| 136 | * Classes should implement this instead of {@link android.app.ITaskStackListener} |
| 137 | * to reduce IPC calls from system services. These callbacks will be called on the main thread. |
| 138 | */ |
| 139 | public abstract static class TaskStackListener { |
| 140 | public void onTaskStackChanged() { } |
| 141 | public void onActivityPinned() { } |
| 142 | public void onPinnedActivityRestartAttempt() { } |
| 143 | public void onPinnedStackAnimationEnded() { } |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 144 | public void onActivityForcedResizable(String packageName, int taskId) { } |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Implementation of {@link android.app.ITaskStackListener} to listen task stack changes from |
| 149 | * ActivityManagerNative. |
| 150 | * This simply passes callbacks to listeners through {@link H}. |
| 151 | * */ |
| 152 | private ITaskStackListener.Stub mTaskStackListener = new ITaskStackListener.Stub() { |
| 153 | @Override |
| 154 | public void onTaskStackChanged() throws RemoteException { |
| 155 | mHandler.removeMessages(H.ON_TASK_STACK_CHANGED); |
| 156 | mHandler.sendEmptyMessage(H.ON_TASK_STACK_CHANGED); |
| 157 | } |
| 158 | |
| 159 | @Override |
| 160 | public void onActivityPinned() throws RemoteException { |
| 161 | mHandler.removeMessages(H.ON_ACTIVITY_PINNED); |
| 162 | mHandler.sendEmptyMessage(H.ON_ACTIVITY_PINNED); |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public void onPinnedActivityRestartAttempt() throws RemoteException{ |
| 167 | mHandler.removeMessages(H.ON_PINNED_ACTIVITY_RESTART_ATTEMPT); |
| 168 | mHandler.sendEmptyMessage(H.ON_PINNED_ACTIVITY_RESTART_ATTEMPT); |
| 169 | } |
| 170 | |
| 171 | @Override |
| 172 | public void onPinnedStackAnimationEnded() throws RemoteException { |
| 173 | mHandler.removeMessages(H.ON_PINNED_STACK_ANIMATION_ENDED); |
| 174 | mHandler.sendEmptyMessage(H.ON_PINNED_STACK_ANIMATION_ENDED); |
| 175 | } |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 176 | |
| 177 | @Override |
| 178 | public void onActivityForcedResizable(String packageName, int taskId) |
| 179 | throws RemoteException { |
| 180 | mHandler.obtainMessage(H.ON_ACTIVITY_FORCED_RESIZABLE, taskId, 0, packageName) |
| 181 | .sendToTarget(); |
| 182 | } |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | /** |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 186 | * List of {@link TaskStackListener} registered from {@link #registerTaskStackListener}. |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 187 | */ |
| 188 | private List<TaskStackListener> mTaskStackListeners = new ArrayList<>(); |
| 189 | |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 190 | /** Private constructor */ |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 191 | private SystemServicesProxy(Context context) { |
Winson Chung | ee44595 | 2014-09-09 16:12:59 +0200 | [diff] [blame] | 192 | mAccm = AccessibilityManager.getInstance(context); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 193 | mAm = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 194 | mIam = ActivityManagerNative.getDefault(); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 195 | mPm = context.getPackageManager(); |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 196 | mIpm = AppGlobals.getPackageManager(); |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 197 | mAssistUtils = new AssistUtils(context); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 198 | mWm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 199 | mUm = UserManager.get(context); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 200 | mDisplay = mWm.getDefaultDisplay(); |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 201 | mRecentsPackage = context.getPackageName(); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 202 | mHasFreeformWorkspaceSupport = |
Jorim Jaggi | 6f2efd3 | 2015-12-23 12:04:39 +0100 | [diff] [blame] | 203 | mPm.hasSystemFeature(PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT) || |
| 204 | Settings.Global.getInt(context.getContentResolver(), |
| 205 | DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0; |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 206 | mIsSafeMode = mPm.isSafeMode(); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 207 | |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 208 | // Get the dummy thumbnail width/heights |
| 209 | Resources res = context.getResources(); |
| 210 | int wId = com.android.internal.R.dimen.thumbnail_width; |
| 211 | int hId = com.android.internal.R.dimen.thumbnail_height; |
| 212 | mDummyThumbnailWidth = res.getDimensionPixelSize(wId); |
| 213 | mDummyThumbnailHeight = res.getDimensionPixelSize(hId); |
| 214 | |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 215 | // Create the protection paints |
| 216 | mBgProtectionPaint = new Paint(); |
| 217 | mBgProtectionPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP)); |
| 218 | mBgProtectionPaint.setColor(0xFFffffff); |
| 219 | mBgProtectionCanvas = new Canvas(); |
| 220 | |
Winson Chung | da5b84c | 2014-05-05 12:06:28 -0700 | [diff] [blame] | 221 | // Resolve the assist intent |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 222 | mAssistComponent = mAssistUtils.getAssistComponentForUser(UserHandle.myUserId()); |
Winson Chung | da5b84c | 2014-05-05 12:06:28 -0700 | [diff] [blame] | 223 | |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 224 | if (RecentsDebugFlags.Static.EnableMockTasks) { |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 225 | // Create a dummy icon |
Winson Chung | 2f2ca08 | 2014-04-03 18:05:29 -0700 | [diff] [blame] | 226 | mDummyIcon = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 227 | mDummyIcon.eraseColor(0xFF999999); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 231 | /** |
| 232 | * Returns the single instance of the {@link SystemServicesProxy}. |
| 233 | * This should only be called on the main thread. |
| 234 | */ |
| 235 | public static SystemServicesProxy getInstance(Context context) { |
| 236 | if (!Looper.getMainLooper().isCurrentThread()) { |
| 237 | throw new RuntimeException("Must be called on the UI thread"); |
| 238 | } |
| 239 | if (sSystemServicesProxy == null) { |
| 240 | sSystemServicesProxy = new SystemServicesProxy(context); |
| 241 | } |
| 242 | return sSystemServicesProxy; |
| 243 | } |
| 244 | |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 245 | /** Returns a list of the recents tasks */ |
Winson Chung | 9cb5c4e | 2014-09-29 13:16:05 -0700 | [diff] [blame] | 246 | public List<ActivityManager.RecentTaskInfo> getRecentTasks(int numLatestTasks, int userId, |
Rubin Xu | efb844d | 2015-12-08 20:57:24 +0000 | [diff] [blame] | 247 | boolean isTopTaskHome, ArraySet<Integer> quietProfileIds) { |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 248 | if (mAm == null) return null; |
| 249 | |
| 250 | // If we are mocking, then create some recent tasks |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 251 | if (RecentsDebugFlags.Static.EnableMockTasks) { |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 252 | ArrayList<ActivityManager.RecentTaskInfo> tasks = |
| 253 | new ArrayList<ActivityManager.RecentTaskInfo>(); |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 254 | int count = Math.min(numLatestTasks, RecentsDebugFlags.Static.MockTaskCount); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 255 | for (int i = 0; i < count; i++) { |
| 256 | // Create a dummy component name |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 257 | int packageIndex = i % RecentsDebugFlags.Static.MockTasksPackageCount; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 258 | ComponentName cn = new ComponentName("com.android.test" + packageIndex, |
| 259 | "com.android.test" + i + ".Activity"); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 260 | String description = "" + i + " - " + |
| 261 | Long.toString(Math.abs(new Random().nextLong()), 36); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 262 | // Create the recent task info |
| 263 | ActivityManager.RecentTaskInfo rti = new ActivityManager.RecentTaskInfo(); |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 264 | rti.id = rti.persistentId = rti.affiliatedTaskId = i; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 265 | rti.baseIntent = new Intent(); |
| 266 | rti.baseIntent.setComponent(cn); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 267 | rti.description = description; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 268 | rti.firstActiveTime = rti.lastActiveTime = i; |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame] | 269 | if (i % 2 == 0) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 270 | rti.taskDescription = new ActivityManager.TaskDescription(description, |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 271 | Bitmap.createBitmap(mDummyIcon), null, |
| 272 | 0xFF000000 | (0xFFFFFF & new Random().nextInt()), |
Winson Chung | 10f8139 | 2014-05-20 16:21:31 -0700 | [diff] [blame] | 273 | 0xFF000000 | (0xFFFFFF & new Random().nextInt())); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 274 | } else { |
| 275 | rti.taskDescription = new ActivityManager.TaskDescription(); |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame] | 276 | } |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 277 | tasks.add(rti); |
| 278 | } |
| 279 | return tasks; |
| 280 | } |
| 281 | |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 282 | // Remove home/recents/excluded tasks |
| 283 | int minNumTasksToQuery = 10; |
| 284 | int numTasksToQuery = Math.max(minNumTasksToQuery, numLatestTasks); |
| 285 | List<ActivityManager.RecentTaskInfo> tasks = mAm.getRecentTasksForUser(numTasksToQuery, |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 286 | ActivityManager.RECENT_IGNORE_HOME_STACK_TASKS | |
Winson Chung | 0583d3d | 2015-12-18 10:03:12 -0500 | [diff] [blame] | 287 | ActivityManager.RECENT_INGORE_DOCKED_STACK_TASKS | |
| 288 | ActivityManager.RECENT_INGORE_PINNED_STACK_TASKS | |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 289 | ActivityManager.RECENT_IGNORE_UNAVAILABLE | |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 290 | ActivityManager.RECENT_INCLUDE_PROFILES | |
| 291 | ActivityManager.RECENT_WITH_EXCLUDED, userId); |
Winson Chung | 4298b43 | 2014-09-12 15:25:46 +0200 | [diff] [blame] | 292 | |
| 293 | // Break early if we can't get a valid set of tasks |
| 294 | if (tasks == null) { |
Winson Chung | e1e20e1 | 2015-06-02 14:11:49 -0700 | [diff] [blame] | 295 | return new ArrayList<>(); |
Winson Chung | 4298b43 | 2014-09-12 15:25:46 +0200 | [diff] [blame] | 296 | } |
| 297 | |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 298 | boolean isFirstValidTask = true; |
| 299 | Iterator<ActivityManager.RecentTaskInfo> iter = tasks.iterator(); |
| 300 | while (iter.hasNext()) { |
| 301 | ActivityManager.RecentTaskInfo t = iter.next(); |
| 302 | |
| 303 | // NOTE: The order of these checks happens in the expected order of the traversal of the |
| 304 | // tasks |
| 305 | |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 306 | // Check the first non-recents task, include this task even if it is marked as excluded |
Winson Chung | 9cb5c4e | 2014-09-29 13:16:05 -0700 | [diff] [blame] | 307 | // from recents if we are currently in the app. In other words, only remove excluded |
Jaewan Kim | 7ed7657 | 2016-03-17 18:15:07 +0900 | [diff] [blame] | 308 | // tasks if it is not the first active task, and not in the blacklist. |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 309 | boolean isExcluded = (t.baseIntent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) |
| 310 | == Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; |
Jaewan Kim | 7ed7657 | 2016-03-17 18:15:07 +0900 | [diff] [blame] | 311 | boolean isBlackListed = sRecentsBlacklist.contains(t.realActivity.getClassName()); |
Rubin Xu | efb844d | 2015-12-08 20:57:24 +0000 | [diff] [blame] | 312 | // Filter out recent tasks from managed profiles which are in quiet mode. |
| 313 | isExcluded |= quietProfileIds.contains(t.userId); |
Jaewan Kim | 7ed7657 | 2016-03-17 18:15:07 +0900 | [diff] [blame] | 314 | if (isBlackListed || (isExcluded && (isTopTaskHome || !isFirstValidTask))) { |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 315 | iter.remove(); |
| 316 | continue; |
| 317 | } |
| 318 | isFirstValidTask = false; |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | return tasks.subList(0, Math.min(tasks.size(), numLatestTasks)); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /** Returns a list of the running tasks */ |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 325 | private List<ActivityManager.RunningTaskInfo> getRunningTasks(int numTasks) { |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 326 | if (mAm == null) return null; |
| 327 | return mAm.getRunningTasks(numTasks); |
| 328 | } |
| 329 | |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 330 | /** Returns the top task. */ |
| 331 | public ActivityManager.RunningTaskInfo getTopMostTask() { |
| 332 | List<ActivityManager.RunningTaskInfo> tasks = getRunningTasks(1); |
Winson Chung | 65c2940 | 2015-05-27 12:45:20 -0700 | [diff] [blame] | 333 | if (tasks != null && !tasks.isEmpty()) { |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 334 | return tasks.get(0); |
| 335 | } |
| 336 | return null; |
| 337 | } |
| 338 | |
Winson | a5e6b36 | 2015-11-02 17:17:20 -0800 | [diff] [blame] | 339 | /** |
| 340 | * Returns whether this device has freeform workspaces. |
| 341 | */ |
| 342 | public boolean hasFreeformWorkspaceSupport() { |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 343 | return mHasFreeformWorkspaceSupport; |
Winson | a5e6b36 | 2015-11-02 17:17:20 -0800 | [diff] [blame] | 344 | } |
| 345 | |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 346 | /** |
| 347 | * Returns whether this device is in the safe mode. |
| 348 | */ |
| 349 | public boolean isInSafeMode() { |
| 350 | return mIsSafeMode; |
| 351 | } |
| 352 | |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 353 | /** Returns whether the recents is currently running */ |
| 354 | public boolean isRecentsTopMost(ActivityManager.RunningTaskInfo topTask, |
Winson Chung | e1e20e1 | 2015-06-02 14:11:49 -0700 | [diff] [blame] | 355 | MutableBoolean isHomeTopMost) { |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 356 | if (topTask != null) { |
| 357 | ComponentName topActivity = topTask.topActivity; |
| 358 | |
| 359 | // Check if the front most activity is recents |
Sid Soundararajan | b58c46a | 2016-01-26 15:39:27 -0800 | [diff] [blame] | 360 | if ((topActivity.getPackageName().equals(RecentsImpl.RECENTS_PACKAGE) && |
| 361 | (topActivity.getClassName().equals(RecentsImpl.RECENTS_ACTIVITY) || |
Sid Soundararajan | 4bdb687 | 2016-03-18 13:42:10 -0700 | [diff] [blame] | 362 | topActivity.getClassName().equals(RecentsTvImpl.RECENTS_TV_ACTIVITY)))) { |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 363 | if (isHomeTopMost != null) { |
Winson Chung | e1e20e1 | 2015-06-02 14:11:49 -0700 | [diff] [blame] | 364 | isHomeTopMost.value = false; |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 365 | } |
| 366 | return true; |
| 367 | } |
| 368 | |
Winson | 5510f6c | 2015-10-27 12:11:26 -0700 | [diff] [blame] | 369 | // Note, this is only valid because we currently only allow the recents and home |
| 370 | // activities in the home stack |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 371 | if (isHomeTopMost != null) { |
Winson | 5510f6c | 2015-10-27 12:11:26 -0700 | [diff] [blame] | 372 | isHomeTopMost.value = SystemServicesProxy.isHomeStack(topTask.stackId); |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | return false; |
| 376 | } |
| 377 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 378 | /** Get the bounds of a task. */ |
| 379 | public Rect getTaskBounds(int taskId) { |
| 380 | if (mIam == null) return null; |
| 381 | |
| 382 | try { |
| 383 | return mIam.getTaskBounds(taskId); |
| 384 | } catch (RemoteException e) { |
| 385 | e.printStackTrace(); |
| 386 | } |
| 387 | return null; |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Winson | b1bbaed | 2015-09-23 15:45:11 -0700 | [diff] [blame] | 390 | /** |
| 391 | * Resizes the given task to the new bounds. |
| 392 | */ |
| 393 | public void resizeTask(int taskId, Rect bounds) { |
| 394 | if (mIam == null) return; |
| 395 | |
| 396 | try { |
| 397 | mIam.resizeTask(taskId, bounds, ActivityManager.RESIZE_MODE_FORCED); |
| 398 | } catch (RemoteException e) { |
| 399 | e.printStackTrace(); |
| 400 | } |
| 401 | } |
| 402 | |
Jorim Jaggi | 75b2597 | 2015-10-21 14:51:10 +0200 | [diff] [blame] | 403 | /** Docks a task to the side of the screen and starts it. */ |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 404 | public void startTaskInDockedMode(int taskId, int createMode) { |
Winson | b1bbaed | 2015-09-23 15:45:11 -0700 | [diff] [blame] | 405 | if (mIam == null) return; |
| 406 | |
| 407 | try { |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 408 | // TODO: Determine what animation we want for the incoming task |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 409 | final ActivityOptions options = ActivityOptions.makeBasic(); |
Filip Gruszczynski | 90186c6 | 2015-10-26 14:07:00 -0700 | [diff] [blame] | 410 | options.setDockCreateMode(createMode); |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 411 | options.setLaunchStackId(DOCKED_STACK_ID); |
| 412 | mIam.startActivityFromRecents(taskId, options.toBundle()); |
Jorim Jaggi | 75b2597 | 2015-10-21 14:51:10 +0200 | [diff] [blame] | 413 | } catch (RemoteException e) { |
| 414 | e.printStackTrace(); |
| 415 | } |
| 416 | } |
| 417 | |
Jorim Jaggi | 030979c | 2015-11-20 15:14:43 -0800 | [diff] [blame] | 418 | /** Docks an already resumed task to the side of the screen. */ |
Chong Zhang | e4fbd32 | 2016-03-01 14:44:03 -0800 | [diff] [blame] | 419 | public boolean moveTaskToDockedStack(int taskId, int createMode, Rect initialBounds) { |
| 420 | if (mIam == null) { |
| 421 | return false; |
| 422 | } |
Jorim Jaggi | 030979c | 2015-11-20 15:14:43 -0800 | [diff] [blame] | 423 | |
| 424 | try { |
Chong Zhang | e4fbd32 | 2016-03-01 14:44:03 -0800 | [diff] [blame] | 425 | return mIam.moveTaskToDockedStack( |
| 426 | taskId, createMode, true /* onTop */, false /* animate */, initialBounds); |
Jorim Jaggi | 030979c | 2015-11-20 15:14:43 -0800 | [diff] [blame] | 427 | } catch (RemoteException e) { |
| 428 | e.printStackTrace(); |
| 429 | } |
Chong Zhang | e4fbd32 | 2016-03-01 14:44:03 -0800 | [diff] [blame] | 430 | return false; |
Jorim Jaggi | 030979c | 2015-11-20 15:14:43 -0800 | [diff] [blame] | 431 | } |
| 432 | |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 433 | /** Returns the focused stack id. */ |
| 434 | public int getFocusedStack() { |
| 435 | if (mIam == null) return -1; |
| 436 | |
| 437 | try { |
| 438 | return mIam.getFocusedStackId(); |
| 439 | } catch (RemoteException e) { |
| 440 | e.printStackTrace(); |
| 441 | return -1; |
| 442 | } |
| 443 | } |
| 444 | |
Winson | 5510f6c | 2015-10-27 12:11:26 -0700 | [diff] [blame] | 445 | /** |
| 446 | * Returns whether the given stack id is the home stack id. |
| 447 | */ |
| 448 | public static boolean isHomeStack(int stackId) { |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 449 | return stackId == HOME_STACK_ID; |
Winson | 5510f6c | 2015-10-27 12:11:26 -0700 | [diff] [blame] | 450 | } |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 451 | |
Winson | 5510f6c | 2015-10-27 12:11:26 -0700 | [diff] [blame] | 452 | /** |
Sid Soundararajan | b58c46a | 2016-01-26 15:39:27 -0800 | [diff] [blame] | 453 | * Returns whether the given stack id is the pinned stack id. |
| 454 | */ |
| 455 | public static boolean isPinnedStack(int stackId){ |
| 456 | return stackId == PINNED_STACK_ID; |
| 457 | } |
| 458 | |
| 459 | /** |
Winson | 8f0e3a6 | 2015-11-23 09:15:08 -0800 | [diff] [blame] | 460 | * Returns whether the given stack id is the docked stack id. |
| 461 | */ |
| 462 | public static boolean isDockedStack(int stackId) { |
| 463 | return stackId == DOCKED_STACK_ID; |
| 464 | } |
| 465 | |
| 466 | /** |
Winson | 5510f6c | 2015-10-27 12:11:26 -0700 | [diff] [blame] | 467 | * Returns whether the given stack id is the freeform workspace stack id. |
| 468 | */ |
| 469 | public static boolean isFreeformStack(int stackId) { |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 470 | return stackId == FREEFORM_WORKSPACE_STACK_ID; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 473 | /** |
Winson | f391800 | 2016-01-12 15:59:29 -0800 | [diff] [blame] | 474 | * @return whether there are any docked tasks for the current user. |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 475 | */ |
| 476 | public boolean hasDockedTask() { |
| 477 | if (mIam == null) return false; |
| 478 | |
| 479 | ActivityManager.StackInfo stackInfo = null; |
| 480 | try { |
Wale Ogunwale | 7e8184b | 2015-10-05 14:37:03 -0700 | [diff] [blame] | 481 | stackInfo = mIam.getStackInfo(DOCKED_STACK_ID); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 482 | } catch (RemoteException e) { |
| 483 | e.printStackTrace(); |
| 484 | } |
Winson | dcf4826 | 2016-01-25 17:16:58 -0800 | [diff] [blame] | 485 | |
| 486 | if (stackInfo != null) { |
| 487 | int userId = getCurrentUser(); |
| 488 | boolean hasUserTask = false; |
| 489 | for (int i = stackInfo.taskUserIds.length - 1; i >= 0 && !hasUserTask; i--) { |
| 490 | hasUserTask = (stackInfo.taskUserIds[i] == userId); |
| 491 | } |
| 492 | return hasUserTask; |
| 493 | } |
| 494 | return false; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Winson | c28098f | 2015-10-30 14:50:19 -0700 | [diff] [blame] | 497 | /** |
| 498 | * Cancels the current window transtion to/from Recents for the given task id. |
| 499 | */ |
| 500 | public void cancelWindowTransition(int taskId) { |
| 501 | if (mWm == null) return; |
| 502 | |
| 503 | try { |
| 504 | WindowManagerGlobal.getWindowManagerService().cancelTaskWindowTransition(taskId); |
| 505 | } catch (RemoteException e) { |
| 506 | e.printStackTrace(); |
| 507 | } |
| 508 | } |
| 509 | |
Winson | 13d3066 | 2015-11-06 15:30:29 -0800 | [diff] [blame] | 510 | /** |
| 511 | * Cancels the current thumbnail transtion to/from Recents for the given task id. |
| 512 | */ |
| 513 | public void cancelThumbnailTransition(int taskId) { |
| 514 | if (mWm == null) return; |
| 515 | |
| 516 | try { |
| 517 | WindowManagerGlobal.getWindowManagerService().cancelTaskThumbnailTransition(taskId); |
| 518 | } catch (RemoteException e) { |
| 519 | e.printStackTrace(); |
| 520 | } |
| 521 | } |
| 522 | |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 523 | /** Returns the top task thumbnail for the given task id */ |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 524 | public ThumbnailData getTaskThumbnail(int taskId) { |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 525 | if (mAm == null) return null; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 526 | ThumbnailData thumbnailData = new ThumbnailData(); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 527 | |
| 528 | // If we are mocking, then just return a dummy thumbnail |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 529 | if (RecentsDebugFlags.Static.EnableMockTasks) { |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 530 | thumbnailData.thumbnail = Bitmap.createBitmap(mDummyThumbnailWidth, |
| 531 | mDummyThumbnailHeight, Bitmap.Config.ARGB_8888); |
| 532 | thumbnailData.thumbnail.eraseColor(0xff333333); |
| 533 | return thumbnailData; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 536 | getThumbnail(taskId, thumbnailData); |
| 537 | if (thumbnailData.thumbnail != null) { |
| 538 | thumbnailData.thumbnail.setHasAlpha(false); |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 539 | // We use a dumb heuristic for now, if the thumbnail is purely transparent in the top |
| 540 | // left pixel, then assume the whole thumbnail is transparent. Generally, proper |
| 541 | // screenshots are always composed onto a bitmap that has no alpha. |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 542 | if (Color.alpha(thumbnailData.thumbnail.getPixel(0, 0)) == 0) { |
| 543 | mBgProtectionCanvas.setBitmap(thumbnailData.thumbnail); |
| 544 | mBgProtectionCanvas.drawRect(0, 0, thumbnailData.thumbnail.getWidth(), |
| 545 | thumbnailData.thumbnail.getHeight(), mBgProtectionPaint); |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 546 | mBgProtectionCanvas.setBitmap(null); |
| 547 | Log.e(TAG, "Invalid screenshot detected from getTaskThumbnail()"); |
| 548 | } |
| 549 | } |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 550 | return thumbnailData; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 553 | /** |
| 554 | * Returns a task thumbnail from the activity manager |
| 555 | */ |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 556 | public void getThumbnail(int taskId, ThumbnailData thumbnailDataOut) { |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 557 | if (mAm == null) { |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 558 | return; |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | ActivityManager.TaskThumbnail taskThumbnail = mAm.getTaskThumbnail(taskId); |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 562 | if (taskThumbnail == null) { |
| 563 | return; |
| 564 | } |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 565 | |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 566 | Bitmap thumbnail = taskThumbnail.mainThumbnail; |
| 567 | ParcelFileDescriptor descriptor = taskThumbnail.thumbnailFileDescriptor; |
| 568 | if (thumbnail == null && descriptor != null) { |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 569 | thumbnail = BitmapFactory.decodeFileDescriptor(descriptor.getFileDescriptor(), |
| 570 | null, sBitmapOptions); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 571 | } |
| 572 | if (descriptor != null) { |
| 573 | try { |
| 574 | descriptor.close(); |
| 575 | } catch (IOException e) { |
| 576 | } |
| 577 | } |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 578 | thumbnailDataOut.thumbnail = thumbnail; |
| 579 | thumbnailDataOut.thumbnailInfo = taskThumbnail.thumbnailInfo; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 582 | /** |
| 583 | * Moves a task into another stack. |
| 584 | */ |
| 585 | public void moveTaskToStack(int taskId, int stackId) { |
| 586 | if (mIam == null) return; |
| 587 | |
| 588 | try { |
| 589 | mIam.positionTaskInStack(taskId, stackId, 0); |
Winson | 7db704a | 2016-01-07 13:13:52 -0800 | [diff] [blame] | 590 | } catch (RemoteException | IllegalArgumentException e) { |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 591 | e.printStackTrace(); |
| 592 | } |
| 593 | } |
| 594 | |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 595 | /** Moves a task to the front with the specified activity options. */ |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 596 | public void moveTaskToFront(int taskId, ActivityOptions opts) { |
| 597 | if (mAm == null) return; |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 598 | if (RecentsDebugFlags.Static.EnableMockTasks) return; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 599 | |
| 600 | if (opts != null) { |
| 601 | mAm.moveTaskToFront(taskId, ActivityManager.MOVE_TASK_WITH_HOME, |
| 602 | opts.toBundle()); |
| 603 | } else { |
| 604 | mAm.moveTaskToFront(taskId, ActivityManager.MOVE_TASK_WITH_HOME); |
| 605 | } |
| 606 | } |
| 607 | |
Wale Ogunwale | d54b578 | 2014-10-23 15:55:23 -0700 | [diff] [blame] | 608 | /** Removes the task */ |
Winson Chung | c35e670 | 2015-07-30 18:08:26 -0700 | [diff] [blame] | 609 | public void removeTask(final int taskId) { |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 610 | if (mAm == null) return; |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 611 | if (RecentsDebugFlags.Static.EnableMockTasks) return; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 612 | |
Wale Ogunwale | d54b578 | 2014-10-23 15:55:23 -0700 | [diff] [blame] | 613 | // Remove the task. |
Winson | ab84fc5 | 2015-10-23 11:52:07 -0700 | [diff] [blame] | 614 | BackgroundThread.getHandler().post(new Runnable() { |
Winson Chung | c35e670 | 2015-07-30 18:08:26 -0700 | [diff] [blame] | 615 | @Override |
| 616 | public void run() { |
| 617 | mAm.removeTask(taskId); |
| 618 | } |
| 619 | }); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 622 | /** |
Winson | d8b1d63 | 2016-01-04 17:51:18 -0800 | [diff] [blame] | 623 | * Sends a message to close other system windows. |
| 624 | */ |
| 625 | public void sendCloseSystemWindows(String reason) { |
| 626 | if (ActivityManagerNative.isSystemReady()) { |
| 627 | try { |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 628 | mIam.closeSystemDialogs(reason); |
Winson | d8b1d63 | 2016-01-04 17:51:18 -0800 | [diff] [blame] | 629 | } catch (RemoteException e) { |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | /** |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 635 | * Returns the activity info for a given component name. |
Wale Ogunwale | d54b578 | 2014-10-23 15:55:23 -0700 | [diff] [blame] | 636 | * |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 637 | * @param cn The component name of the activity. |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 638 | * @param userId The userId of the user that this is for. |
| 639 | */ |
| 640 | public ActivityInfo getActivityInfo(ComponentName cn, int userId) { |
| 641 | if (mIpm == null) return null; |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 642 | if (RecentsDebugFlags.Static.EnableMockTasks) return new ActivityInfo(); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 643 | |
| 644 | try { |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 645 | return mIpm.getActivityInfo(cn, PackageManager.GET_META_DATA, userId); |
| 646 | } catch (RemoteException e) { |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 647 | e.printStackTrace(); |
| 648 | return null; |
| 649 | } |
| 650 | } |
| 651 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 652 | /** |
| 653 | * Returns the activity info for a given component name. |
| 654 | * |
| 655 | * @param cn The component name of the activity. |
| 656 | */ |
| 657 | public ActivityInfo getActivityInfo(ComponentName cn) { |
| 658 | if (mPm == null) return null; |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 659 | if (RecentsDebugFlags.Static.EnableMockTasks) return new ActivityInfo(); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 660 | |
| 661 | try { |
| 662 | return mPm.getActivityInfo(cn, PackageManager.GET_META_DATA); |
| 663 | } catch (PackageManager.NameNotFoundException e) { |
| 664 | e.printStackTrace(); |
| 665 | return null; |
| 666 | } |
| 667 | } |
| 668 | |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 669 | /** |
| 670 | * Returns the activity label, badging if necessary. |
| 671 | */ |
| 672 | public String getBadgedActivityLabel(ActivityInfo info, int userId) { |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 673 | if (mPm == null) return null; |
| 674 | |
| 675 | // If we are mocking, then return a mock label |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 676 | if (RecentsDebugFlags.Static.EnableMockTasks) { |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 677 | return "Recent Task: " + userId; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 680 | return getBadgedLabel(info.loadLabel(mPm).toString(), userId); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 683 | /** |
| 684 | * Returns the application label, badging if necessary. |
| 685 | */ |
| 686 | public String getBadgedApplicationLabel(ApplicationInfo appInfo, int userId) { |
Benjamin Franz | b7a42fd | 2015-04-23 15:33:32 +0100 | [diff] [blame] | 687 | if (mPm == null) return null; |
| 688 | |
| 689 | // If we are mocking, then return a mock label |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 690 | if (RecentsDebugFlags.Static.EnableMockTasks) { |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 691 | return "Recent Task App: " + userId; |
Benjamin Franz | b7a42fd | 2015-04-23 15:33:32 +0100 | [diff] [blame] | 692 | } |
| 693 | |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 694 | return getBadgedLabel(appInfo.loadLabel(mPm).toString(), userId); |
Benjamin Franz | b7a42fd | 2015-04-23 15:33:32 +0100 | [diff] [blame] | 695 | } |
| 696 | |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 697 | /** |
| 698 | * Returns the content description for a given task, badging it if necessary. The content |
| 699 | * description joins the app and activity labels. |
| 700 | */ |
| 701 | public String getBadgedContentDescription(ActivityInfo info, int userId, Resources res) { |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 702 | // If we are mocking, then return a mock label |
| 703 | if (RecentsDebugFlags.Static.EnableMockTasks) { |
| 704 | return "Recent Task Content Description: " + userId; |
| 705 | } |
| 706 | |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 707 | String activityLabel = info.loadLabel(mPm).toString(); |
| 708 | String applicationLabel = info.applicationInfo.loadLabel(mPm).toString(); |
Benjamin Franz | b7a42fd | 2015-04-23 15:33:32 +0100 | [diff] [blame] | 709 | String badgedApplicationLabel = getBadgedLabel(applicationLabel, userId); |
| 710 | return applicationLabel.equals(activityLabel) ? badgedApplicationLabel |
| 711 | : res.getString(R.string.accessibility_recents_task_header, |
| 712 | badgedApplicationLabel, activityLabel); |
| 713 | } |
| 714 | |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 715 | /** |
| 716 | * Returns the activity icon for the ActivityInfo for a user, badging if |
| 717 | * necessary. |
| 718 | */ |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 719 | public Drawable getBadgedActivityIcon(ActivityInfo info, int userId) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 720 | if (mPm == null) return null; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 721 | |
| 722 | // If we are mocking, then return a mock label |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 723 | if (RecentsDebugFlags.Static.EnableMockTasks) { |
Winson Chung | 2f2ca08 | 2014-04-03 18:05:29 -0700 | [diff] [blame] | 724 | return new ColorDrawable(0xFF666666); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 727 | Drawable icon = info.loadIcon(mPm); |
Robin Lee | 6507f2e | 2014-06-26 14:13:17 +0100 | [diff] [blame] | 728 | return getBadgedIcon(icon, userId); |
| 729 | } |
| 730 | |
| 731 | /** |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 732 | * Returns the application icon for the ApplicationInfo for a user, badging if |
| 733 | * necessary. |
| 734 | */ |
| 735 | public Drawable getBadgedApplicationIcon(ApplicationInfo appInfo, int userId) { |
| 736 | if (mPm == null) return null; |
| 737 | |
| 738 | // If we are mocking, then return a mock label |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 739 | if (RecentsDebugFlags.Static.EnableMockTasks) { |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 740 | return new ColorDrawable(0xFF666666); |
| 741 | } |
| 742 | |
| 743 | Drawable icon = appInfo.loadIcon(mPm); |
| 744 | return getBadgedIcon(icon, userId); |
| 745 | } |
| 746 | |
| 747 | /** |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 748 | * Returns the task description icon, loading and badging it if it necessary. |
| 749 | */ |
| 750 | public Drawable getBadgedTaskDescriptionIcon(ActivityManager.TaskDescription taskDescription, |
| 751 | int userId, Resources res) { |
| 752 | |
| 753 | // If we are mocking, then return a mock label |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 754 | if (RecentsDebugFlags.Static.EnableMockTasks) { |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 755 | return new ColorDrawable(0xFF666666); |
| 756 | } |
| 757 | |
| 758 | Bitmap tdIcon = taskDescription.getInMemoryIcon(); |
| 759 | if (tdIcon == null) { |
| 760 | tdIcon = ActivityManager.TaskDescription.loadTaskDescriptionIcon( |
| 761 | taskDescription.getIconFilename(), userId); |
| 762 | } |
| 763 | if (tdIcon != null) { |
| 764 | return getBadgedIcon(new BitmapDrawable(res, tdIcon), userId); |
| 765 | } |
| 766 | return null; |
| 767 | } |
| 768 | |
| 769 | /** |
Robin Lee | 6507f2e | 2014-06-26 14:13:17 +0100 | [diff] [blame] | 770 | * Returns the given icon for a user, badging if necessary. |
| 771 | */ |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 772 | private Drawable getBadgedIcon(Drawable icon, int userId) { |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 773 | if (userId != UserHandle.myUserId()) { |
Amith Yamasani | fdf169c | 2014-09-07 15:45:57 -0700 | [diff] [blame] | 774 | icon = mPm.getUserBadgedIcon(icon, new UserHandle(userId)); |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 775 | } |
| 776 | return icon; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 777 | } |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 778 | |
Benjamin Franz | b7a42fd | 2015-04-23 15:33:32 +0100 | [diff] [blame] | 779 | /** |
Sid Soundararajan | 1008cc2 | 2016-02-01 11:11:14 -0800 | [diff] [blame] | 780 | * Returns a banner used on TV for the specified Activity. |
| 781 | */ |
| 782 | public Drawable getActivityBanner(ActivityInfo info) { |
| 783 | if (mPm == null) return null; |
| 784 | |
| 785 | // If we are mocking, then return a mock banner |
| 786 | if (RecentsDebugFlags.Static.EnableMockTasks) { |
| 787 | return new ColorDrawable(0xFF666666); |
| 788 | } |
| 789 | |
| 790 | Drawable banner = info.loadBanner(mPm); |
| 791 | return banner; |
| 792 | } |
| 793 | |
| 794 | /** |
| 795 | * Returns a logo used on TV for the specified Activity. |
| 796 | */ |
| 797 | public Drawable getActivityLogo(ActivityInfo info) { |
| 798 | if (mPm == null) return null; |
| 799 | |
| 800 | // If we are mocking, then return a mock logo |
| 801 | if (RecentsDebugFlags.Static.EnableMockTasks) { |
| 802 | return new ColorDrawable(0xFF666666); |
| 803 | } |
| 804 | |
| 805 | Drawable logo = info.loadLogo(mPm); |
| 806 | return logo; |
| 807 | } |
| 808 | |
| 809 | |
| 810 | /** |
Benjamin Franz | b7a42fd | 2015-04-23 15:33:32 +0100 | [diff] [blame] | 811 | * Returns the given label for a user, badging if necessary. |
| 812 | */ |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 813 | private String getBadgedLabel(String label, int userId) { |
Benjamin Franz | b7a42fd | 2015-04-23 15:33:32 +0100 | [diff] [blame] | 814 | if (userId != UserHandle.myUserId()) { |
| 815 | label = mPm.getUserBadgedLabel(label, new UserHandle(userId)).toString(); |
| 816 | } |
| 817 | return label; |
| 818 | } |
| 819 | |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 820 | /** Returns the package name of the home activity. */ |
| 821 | public String getHomeActivityPackageName() { |
| 822 | if (mPm == null) return null; |
Winson | 6e6bd877 | 2016-01-25 10:41:40 -0800 | [diff] [blame] | 823 | if (RecentsDebugFlags.Static.EnableMockTasks) return null; |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 824 | |
Winson | d8b1d63 | 2016-01-04 17:51:18 -0800 | [diff] [blame] | 825 | ArrayList<ResolveInfo> homeActivities = new ArrayList<>(); |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 826 | ComponentName defaultHomeActivity = mPm.getHomeActivities(homeActivities); |
| 827 | if (defaultHomeActivity != null) { |
| 828 | return defaultHomeActivity.getPackageName(); |
| 829 | } else if (homeActivities.size() == 1) { |
| 830 | ResolveInfo info = homeActivities.get(0); |
| 831 | if (info.activityInfo != null) { |
| 832 | return info.activityInfo.packageName; |
| 833 | } |
| 834 | } |
| 835 | return null; |
| 836 | } |
| 837 | |
| 838 | /** |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 839 | * Returns whether the provided {@param userId} represents the system user. |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 840 | */ |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 841 | public boolean isSystemUser(int userId) { |
| 842 | return userId == UserHandle.USER_SYSTEM; |
| 843 | } |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 844 | |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 845 | /** |
| 846 | * Returns the current user id. |
| 847 | */ |
| 848 | public int getCurrentUser() { |
| 849 | if (mAm == null) return 0; |
| 850 | |
| 851 | return mAm.getCurrentUser(); |
| 852 | } |
| 853 | |
| 854 | /** |
| 855 | * Returns the processes user id. |
| 856 | */ |
| 857 | public int getProcessUser() { |
| 858 | if (mUm == null) return 0; |
| 859 | return mUm.getUserHandle(); |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | /** |
Winson Chung | ee44595 | 2014-09-09 16:12:59 +0200 | [diff] [blame] | 863 | * Returns whether touch exploration is currently enabled. |
| 864 | */ |
| 865 | public boolean isTouchExplorationEnabled() { |
| 866 | if (mAccm == null) return false; |
| 867 | |
| 868 | return mAccm.isEnabled() && mAccm.isTouchExplorationEnabled(); |
| 869 | } |
| 870 | |
| 871 | /** |
Winson | e6309aa | 2016-01-08 11:19:21 -0800 | [diff] [blame] | 872 | * Returns whether the current task is in screen-pinning mode. |
| 873 | */ |
| 874 | public boolean isScreenPinningActive() { |
| 875 | if (mIam == null) return false; |
| 876 | |
| 877 | try { |
| 878 | return mIam.isInLockTaskMode(); |
| 879 | } catch (RemoteException e) { |
| 880 | return false; |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | /** |
Jason Monk | 56e09b4 | 2014-07-18 10:29:14 -0400 | [diff] [blame] | 885 | * Returns a global setting. |
| 886 | */ |
| 887 | public int getGlobalSetting(Context context, String setting) { |
| 888 | ContentResolver cr = context.getContentResolver(); |
| 889 | return Settings.Global.getInt(cr, setting, 0); |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * Returns a system setting. |
| 894 | */ |
| 895 | public int getSystemSetting(Context context, String setting) { |
| 896 | ContentResolver cr = context.getContentResolver(); |
| 897 | return Settings.System.getInt(cr, setting, 0); |
| 898 | } |
| 899 | |
| 900 | /** |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 901 | * Returns a system property. |
| 902 | */ |
| 903 | public String getSystemProperty(String key) { |
| 904 | return SystemProperties.get(key); |
| 905 | } |
| 906 | |
| 907 | /** |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 908 | * Returns the smallest width/height. |
| 909 | */ |
| 910 | public int getDeviceSmallestWidth() { |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 911 | if (mDisplay == null) return 0; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 912 | |
| 913 | Point smallestSizeRange = new Point(); |
| 914 | Point largestSizeRange = new Point(); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 915 | mDisplay.getCurrentSizeRange(smallestSizeRange, largestSizeRange); |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 916 | return smallestSizeRange.x; |
| 917 | } |
| 918 | |
| 919 | /** |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 920 | * Returns the current display rect in the current display orientation. |
Winson | b1bbaed | 2015-09-23 15:45:11 -0700 | [diff] [blame] | 921 | */ |
| 922 | public Rect getDisplayRect() { |
| 923 | Rect displayRect = new Rect(); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 924 | if (mDisplay == null) return displayRect; |
Winson | b1bbaed | 2015-09-23 15:45:11 -0700 | [diff] [blame] | 925 | |
| 926 | Point p = new Point(); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 927 | mDisplay.getRealSize(p); |
Winson | b1bbaed | 2015-09-23 15:45:11 -0700 | [diff] [blame] | 928 | displayRect.set(0, 0, p.x, p.y); |
| 929 | return displayRect; |
| 930 | } |
| 931 | |
| 932 | /** |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 933 | * Returns the current display orientation. |
| 934 | */ |
| 935 | public int getDisplayOrientation() { |
| 936 | // Because of multi-window, the configuration orientation does not necessarily reflect the |
| 937 | // orientation of the display, instead we just use the display's real-size. |
| 938 | Rect displayRect = getDisplayRect(); |
| 939 | return displayRect.width() > displayRect.height() |
| 940 | ? Configuration.ORIENTATION_LANDSCAPE |
| 941 | : Configuration.ORIENTATION_PORTRAIT; |
| 942 | } |
| 943 | |
| 944 | /** |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 945 | * Returns the window rect for the RecentsActivity, based on the dimensions of the home stack. |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 946 | */ |
| 947 | public Rect getWindowRect() { |
| 948 | Rect windowRect = new Rect(); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 949 | if (mIam == null) return windowRect; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 950 | |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 951 | try { |
| 952 | // Use the home stack bounds |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 953 | ActivityManager.StackInfo stackInfo = mIam.getStackInfo(HOME_STACK_ID); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 954 | if (stackInfo != null) { |
| 955 | windowRect.set(stackInfo.bounds); |
| 956 | } |
| 957 | } catch (RemoteException e) { |
| 958 | e.printStackTrace(); |
| 959 | } finally { |
| 960 | return windowRect; |
| 961 | } |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 962 | } |
| 963 | |
Winson Chung | 4e96eb7 | 2014-09-17 15:16:09 +0200 | [diff] [blame] | 964 | /** Starts an activity from recents. */ |
| 965 | public boolean startActivityFromRecents(Context context, int taskId, String taskName, |
| 966 | ActivityOptions options) { |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 967 | if (mIam != null) { |
| 968 | try { |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 969 | mIam.startActivityFromRecents(taskId, options == null ? null : options.toBundle()); |
Winson Chung | 4e96eb7 | 2014-09-17 15:16:09 +0200 | [diff] [blame] | 970 | return true; |
| 971 | } catch (Exception e) { |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 972 | Log.e(TAG, context.getString(R.string.recents_launch_error_message, taskName), e); |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 973 | } |
| 974 | } |
Winson Chung | 4e96eb7 | 2014-09-17 15:16:09 +0200 | [diff] [blame] | 975 | return false; |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 976 | } |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 977 | |
| 978 | /** Starts an in-place animation on the front most application windows. */ |
| 979 | public void startInPlaceAnimationOnFrontMostApplication(ActivityOptions opts) { |
| 980 | if (mIam == null) return; |
| 981 | |
| 982 | try { |
| 983 | mIam.startInPlaceAnimationOnFrontMostApplication(opts); |
| 984 | } catch (Exception e) { |
| 985 | e.printStackTrace(); |
| 986 | } |
| 987 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 988 | |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 989 | /** |
| 990 | * Registers a task stack listener with the system. |
| 991 | * This should be called on the main thread. |
| 992 | */ |
| 993 | public void registerTaskStackListener(TaskStackListener listener) { |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 994 | if (mIam == null) return; |
| 995 | |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 996 | mTaskStackListeners.add(listener); |
| 997 | if (mTaskStackListeners.size() == 1) { |
| 998 | // Register mTaskStackListener to IActivityManager only once if needed. |
| 999 | try { |
| 1000 | mIam.registerTaskStackListener(mTaskStackListener); |
| 1001 | } catch (Exception e) { |
| 1002 | Log.w(TAG, "Failed to call registerTaskStackListener", e); |
| 1003 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1004 | } |
| 1005 | } |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 1006 | |
| 1007 | public void endProlongedAnimations() { |
| 1008 | if (mWm == null) { |
| 1009 | return; |
| 1010 | } |
| 1011 | try { |
| 1012 | WindowManagerGlobal.getWindowManagerService().endProlongedAnimations(); |
| 1013 | } catch (Exception e) { |
| 1014 | e.printStackTrace(); |
| 1015 | } |
| 1016 | } |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 1017 | |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 1018 | public void registerDockedStackListener(IDockedStackListener listener) { |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 1019 | if (mWm == null) return; |
| 1020 | |
| 1021 | try { |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 1022 | WindowManagerGlobal.getWindowManagerService().registerDockedStackListener(listener); |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 1023 | } catch (Exception e) { |
| 1024 | e.printStackTrace(); |
| 1025 | } |
| 1026 | } |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 1027 | |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 1028 | /** |
| 1029 | * Calculates the size of the dock divider in the current orientation. |
| 1030 | */ |
| 1031 | public int getDockedDividerSize(Context context) { |
| 1032 | Resources res = context.getResources(); |
| 1033 | int dividerWindowWidth = res.getDimensionPixelSize( |
| 1034 | com.android.internal.R.dimen.docked_stack_divider_thickness); |
| 1035 | int dividerInsets = res.getDimensionPixelSize( |
| 1036 | com.android.internal.R.dimen.docked_stack_divider_insets); |
| 1037 | return dividerWindowWidth - 2 * dividerInsets; |
| 1038 | } |
| 1039 | |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 1040 | public void requestKeyboardShortcuts( |
| 1041 | Context context, KeyboardShortcutsReceiver receiver, int deviceId) { |
| 1042 | mWm.requestAppKeyboardShortcuts(receiver, deviceId); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 1043 | } |
Sid Soundararajan | b58c46a | 2016-01-26 15:39:27 -0800 | [diff] [blame] | 1044 | |
Jorim Jaggi | c6c89a8 | 2016-01-28 17:48:21 -0800 | [diff] [blame] | 1045 | public void getStableInsets(Rect outStableInsets) { |
| 1046 | if (mWm == null) return; |
| 1047 | |
| 1048 | try { |
| 1049 | WindowManagerGlobal.getWindowManagerService().getStableInsets(outStableInsets); |
| 1050 | } catch (Exception e) { |
| 1051 | e.printStackTrace(); |
| 1052 | } |
| 1053 | } |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 1054 | |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 1055 | public void overridePendingAppTransitionMultiThumbFuture( |
| 1056 | IAppTransitionAnimationSpecsFuture future, IRemoteCallback animStartedListener, |
| 1057 | boolean scaleUp) { |
| 1058 | try { |
| 1059 | WindowManagerGlobal.getWindowManagerService() |
| 1060 | .overridePendingAppTransitionMultiThumbFuture(future, animStartedListener, |
| 1061 | scaleUp); |
| 1062 | } catch (RemoteException e) { |
| 1063 | Log.w(TAG, "Failed to override transition: " + e); |
| 1064 | } |
| 1065 | } |
| 1066 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 1067 | /** |
| 1068 | * Returns whether the device has a transposed nav bar (on the right of the screen) in the |
| 1069 | * current display orientation. |
| 1070 | */ |
| 1071 | public boolean hasTransposedNavBar() { |
| 1072 | Rect insets = new Rect(); |
| 1073 | getStableInsets(insets); |
| 1074 | return insets.right > 0; |
| 1075 | } |
| 1076 | |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 1077 | private final class H extends Handler { |
| 1078 | private static final int ON_TASK_STACK_CHANGED = 1; |
| 1079 | private static final int ON_ACTIVITY_PINNED = 2; |
| 1080 | private static final int ON_PINNED_ACTIVITY_RESTART_ATTEMPT = 3; |
| 1081 | private static final int ON_PINNED_STACK_ANIMATION_ENDED = 4; |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1082 | private static final int ON_ACTIVITY_FORCED_RESIZABLE = 5; |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 1083 | |
| 1084 | @Override |
| 1085 | public void handleMessage(Message msg) { |
| 1086 | switch (msg.what) { |
| 1087 | case ON_TASK_STACK_CHANGED: { |
| 1088 | for (int i = mTaskStackListeners.size() - 1; i >= 0; i--) { |
| 1089 | mTaskStackListeners.get(i).onTaskStackChanged(); |
| 1090 | } |
| 1091 | break; |
| 1092 | } |
| 1093 | case ON_ACTIVITY_PINNED: { |
| 1094 | for (int i = mTaskStackListeners.size() - 1; i >= 0; i--) { |
| 1095 | mTaskStackListeners.get(i).onActivityPinned(); |
| 1096 | } |
| 1097 | break; |
| 1098 | } |
| 1099 | case ON_PINNED_ACTIVITY_RESTART_ATTEMPT: { |
| 1100 | for (int i = mTaskStackListeners.size() - 1; i >= 0; i--) { |
| 1101 | mTaskStackListeners.get(i).onPinnedActivityRestartAttempt(); |
| 1102 | } |
| 1103 | break; |
| 1104 | } |
| 1105 | case ON_PINNED_STACK_ANIMATION_ENDED: { |
| 1106 | for (int i = mTaskStackListeners.size() - 1; i >= 0; i--) { |
| 1107 | mTaskStackListeners.get(i).onPinnedStackAnimationEnded(); |
| 1108 | } |
| 1109 | break; |
| 1110 | } |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1111 | case ON_ACTIVITY_FORCED_RESIZABLE: { |
| 1112 | for (int i = mTaskStackListeners.size() - 1; i >= 0; i--) { |
| 1113 | mTaskStackListeners.get(i).onActivityForcedResizable( |
| 1114 | (String) msg.obj, msg.arg1); |
| 1115 | } |
| 1116 | break; |
| 1117 | } |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 1118 | } |
| 1119 | } |
| 1120 | } |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 1121 | } |