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 | |
| 19 | import android.app.ActivityManager; |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 20 | import android.app.ActivityManagerNative; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 21 | import android.app.ActivityOptions; |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 22 | import android.app.AppGlobals; |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 23 | import android.app.IActivityContainer; |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 24 | import android.app.IActivityManager; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 25 | import android.app.ITaskStackListener; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 26 | import android.app.SearchManager; |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 27 | import android.appwidget.AppWidgetHost; |
| 28 | import android.appwidget.AppWidgetManager; |
| 29 | import android.appwidget.AppWidgetProviderInfo; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 30 | import android.content.ComponentName; |
Jason Monk | 56e09b4 | 2014-07-18 10:29:14 -0400 | [diff] [blame] | 31 | import android.content.ContentResolver; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
| 34 | import android.content.pm.ActivityInfo; |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 35 | import android.content.pm.IPackageManager; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 37 | import android.content.pm.ResolveInfo; |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 38 | import android.content.res.Resources; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 39 | import android.graphics.Bitmap; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 40 | import android.graphics.BitmapFactory; |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 41 | import android.graphics.Canvas; |
| 42 | import android.graphics.Color; |
| 43 | import android.graphics.Paint; |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 44 | import android.graphics.Point; |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 45 | import android.graphics.PorterDuff; |
| 46 | import android.graphics.PorterDuffXfermode; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 47 | import android.graphics.Rect; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 48 | import android.graphics.drawable.ColorDrawable; |
| 49 | import android.graphics.drawable.Drawable; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 50 | import android.os.Bundle; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 51 | import android.os.ParcelFileDescriptor; |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 52 | import android.os.RemoteException; |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 53 | import android.os.SystemProperties; |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 54 | import android.os.UserHandle; |
Jason Monk | 56e09b4 | 2014-07-18 10:29:14 -0400 | [diff] [blame] | 55 | import android.provider.Settings; |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 56 | import android.util.Log; |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 57 | import android.util.Pair; |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 58 | import android.util.SparseArray; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 59 | import android.view.Display; |
| 60 | import android.view.DisplayInfo; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 61 | import android.view.SurfaceControl; |
| 62 | import android.view.WindowManager; |
Winson Chung | ee44595 | 2014-09-09 16:12:59 +0200 | [diff] [blame] | 63 | import android.view.accessibility.AccessibilityManager; |
Winson Chung | 4e96eb7 | 2014-09-17 15:16:09 +0200 | [diff] [blame] | 64 | import com.android.systemui.R; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 65 | import com.android.systemui.recents.Constants; |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 66 | import com.android.systemui.recents.Recents; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 67 | |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 68 | import java.io.IOException; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 69 | import java.util.ArrayList; |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 70 | import java.util.Collections; |
| 71 | import java.util.Comparator; |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 72 | import java.util.Iterator; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 73 | import java.util.List; |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame] | 74 | import java.util.Random; |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 75 | import java.util.concurrent.atomic.AtomicBoolean; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * Acts as a shim around the real system services that we need to access data from, and provides |
| 79 | * a point of injection when testing UI. |
| 80 | */ |
| 81 | public class SystemServicesProxy { |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 82 | final static String TAG = "SystemServicesProxy"; |
| 83 | |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 84 | final static BitmapFactory.Options sBitmapOptions; |
| 85 | |
Winson Chung | ee44595 | 2014-09-09 16:12:59 +0200 | [diff] [blame] | 86 | AccessibilityManager mAccm; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 87 | ActivityManager mAm; |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 88 | IActivityManager mIam; |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 89 | AppWidgetManager mAwm; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 90 | PackageManager mPm; |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 91 | IPackageManager mIpm; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 92 | SearchManager mSm; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 93 | WindowManager mWm; |
| 94 | Display mDisplay; |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 95 | String mRecentsPackage; |
Winson Chung | da5b84c | 2014-05-05 12:06:28 -0700 | [diff] [blame] | 96 | ComponentName mAssistComponent; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 97 | |
| 98 | Bitmap mDummyIcon; |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 99 | int mDummyThumbnailWidth; |
| 100 | int mDummyThumbnailHeight; |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 101 | Paint mBgProtectionPaint; |
| 102 | Canvas mBgProtectionCanvas; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 103 | |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 104 | static { |
| 105 | sBitmapOptions = new BitmapFactory.Options(); |
| 106 | sBitmapOptions.inMutable = true; |
| 107 | } |
| 108 | |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 109 | /** Private constructor */ |
| 110 | public SystemServicesProxy(Context context) { |
Winson Chung | ee44595 | 2014-09-09 16:12:59 +0200 | [diff] [blame] | 111 | mAccm = AccessibilityManager.getInstance(context); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 112 | mAm = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 113 | mIam = ActivityManagerNative.getDefault(); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 114 | mAwm = AppWidgetManager.getInstance(context); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 115 | mPm = context.getPackageManager(); |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 116 | mIpm = AppGlobals.getPackageManager(); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 117 | mSm = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 118 | mWm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
| 119 | mDisplay = mWm.getDefaultDisplay(); |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 120 | mRecentsPackage = context.getPackageName(); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 121 | |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 122 | // Get the dummy thumbnail width/heights |
| 123 | Resources res = context.getResources(); |
| 124 | int wId = com.android.internal.R.dimen.thumbnail_width; |
| 125 | int hId = com.android.internal.R.dimen.thumbnail_height; |
| 126 | mDummyThumbnailWidth = res.getDimensionPixelSize(wId); |
| 127 | mDummyThumbnailHeight = res.getDimensionPixelSize(hId); |
| 128 | |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 129 | // Create the protection paints |
| 130 | mBgProtectionPaint = new Paint(); |
| 131 | mBgProtectionPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP)); |
| 132 | mBgProtectionPaint.setColor(0xFFffffff); |
| 133 | mBgProtectionCanvas = new Canvas(); |
| 134 | |
Winson Chung | da5b84c | 2014-05-05 12:06:28 -0700 | [diff] [blame] | 135 | // Resolve the assist intent |
| 136 | Intent assist = mSm.getAssistIntent(context, false); |
| 137 | if (assist != null) { |
| 138 | mAssistComponent = assist.getComponent(); |
| 139 | } |
| 140 | |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 141 | if (Constants.DebugFlags.App.EnableSystemServicesProxy) { |
| 142 | // Create a dummy icon |
Winson Chung | 2f2ca08 | 2014-04-03 18:05:29 -0700 | [diff] [blame] | 143 | mDummyIcon = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 144 | mDummyIcon.eraseColor(0xFF999999); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
| 148 | /** Returns a list of the recents tasks */ |
Winson Chung | 9cb5c4e | 2014-09-29 13:16:05 -0700 | [diff] [blame] | 149 | public List<ActivityManager.RecentTaskInfo> getRecentTasks(int numLatestTasks, int userId, |
| 150 | boolean isTopTaskHome) { |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 151 | if (mAm == null) return null; |
| 152 | |
| 153 | // If we are mocking, then create some recent tasks |
| 154 | if (Constants.DebugFlags.App.EnableSystemServicesProxy) { |
| 155 | ArrayList<ActivityManager.RecentTaskInfo> tasks = |
| 156 | new ArrayList<ActivityManager.RecentTaskInfo>(); |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 157 | int count = Math.min(numLatestTasks, Constants.DebugFlags.App.SystemServicesProxyMockTaskCount); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 158 | for (int i = 0; i < count; i++) { |
| 159 | // Create a dummy component name |
| 160 | int packageIndex = i % Constants.DebugFlags.App.SystemServicesProxyMockPackageCount; |
| 161 | ComponentName cn = new ComponentName("com.android.test" + packageIndex, |
| 162 | "com.android.test" + i + ".Activity"); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 163 | String description = "" + i + " - " + |
| 164 | Long.toString(Math.abs(new Random().nextLong()), 36); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 165 | // Create the recent task info |
| 166 | ActivityManager.RecentTaskInfo rti = new ActivityManager.RecentTaskInfo(); |
| 167 | rti.id = rti.persistentId = i; |
| 168 | rti.baseIntent = new Intent(); |
| 169 | rti.baseIntent.setComponent(cn); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 170 | rti.description = description; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 171 | rti.firstActiveTime = rti.lastActiveTime = i; |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame] | 172 | if (i % 2 == 0) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 173 | rti.taskDescription = new ActivityManager.TaskDescription(description, |
Winson Chung | 10f8139 | 2014-05-20 16:21:31 -0700 | [diff] [blame] | 174 | Bitmap.createBitmap(mDummyIcon), |
| 175 | 0xFF000000 | (0xFFFFFF & new Random().nextInt())); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 176 | } else { |
| 177 | rti.taskDescription = new ActivityManager.TaskDescription(); |
Winson Chung | 5e3e5d8 | 2014-04-02 15:44:55 -0700 | [diff] [blame] | 178 | } |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 179 | tasks.add(rti); |
| 180 | } |
| 181 | return tasks; |
| 182 | } |
| 183 | |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 184 | // Remove home/recents/excluded tasks |
| 185 | int minNumTasksToQuery = 10; |
| 186 | int numTasksToQuery = Math.max(minNumTasksToQuery, numLatestTasks); |
| 187 | List<ActivityManager.RecentTaskInfo> tasks = mAm.getRecentTasksForUser(numTasksToQuery, |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 188 | ActivityManager.RECENT_IGNORE_HOME_STACK_TASKS | |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 189 | ActivityManager.RECENT_IGNORE_UNAVAILABLE | |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 190 | ActivityManager.RECENT_INCLUDE_PROFILES | |
| 191 | ActivityManager.RECENT_WITH_EXCLUDED, userId); |
Winson Chung | 4298b43 | 2014-09-12 15:25:46 +0200 | [diff] [blame] | 192 | |
| 193 | // Break early if we can't get a valid set of tasks |
| 194 | if (tasks == null) { |
| 195 | return new ArrayList<ActivityManager.RecentTaskInfo>(); |
| 196 | } |
| 197 | |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 198 | boolean isFirstValidTask = true; |
| 199 | Iterator<ActivityManager.RecentTaskInfo> iter = tasks.iterator(); |
| 200 | while (iter.hasNext()) { |
| 201 | ActivityManager.RecentTaskInfo t = iter.next(); |
| 202 | |
| 203 | // NOTE: The order of these checks happens in the expected order of the traversal of the |
| 204 | // tasks |
| 205 | |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 206 | // 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] | 207 | // from recents if we are currently in the app. In other words, only remove excluded |
| 208 | // tasks if it is not the first active task. |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 209 | boolean isExcluded = (t.baseIntent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) |
| 210 | == Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; |
Winson Chung | 9cb5c4e | 2014-09-29 13:16:05 -0700 | [diff] [blame] | 211 | if (isExcluded && (isTopTaskHome || !isFirstValidTask)) { |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 212 | iter.remove(); |
| 213 | continue; |
| 214 | } |
| 215 | isFirstValidTask = false; |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | return tasks.subList(0, Math.min(tasks.size(), numLatestTasks)); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /** Returns a list of the running tasks */ |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 222 | private List<ActivityManager.RunningTaskInfo> getRunningTasks(int numTasks) { |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 223 | if (mAm == null) return null; |
| 224 | return mAm.getRunningTasks(numTasks); |
| 225 | } |
| 226 | |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 227 | /** Returns the top task. */ |
| 228 | public ActivityManager.RunningTaskInfo getTopMostTask() { |
| 229 | List<ActivityManager.RunningTaskInfo> tasks = getRunningTasks(1); |
| 230 | if (!tasks.isEmpty()) { |
| 231 | return tasks.get(0); |
| 232 | } |
| 233 | return null; |
| 234 | } |
| 235 | |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 236 | /** Returns a list of all the launcher apps sorted by name. */ |
| 237 | public List<ResolveInfo> getLauncherApps() { |
| 238 | if (mPm == null) return new ArrayList<ResolveInfo>(); |
| 239 | |
| 240 | final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); |
| 241 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
| 242 | List<ResolveInfo> activities = mPm.queryIntentActivities(mainIntent, 0 /* flags */); |
| 243 | Collections.sort(activities, new Comparator<ResolveInfo>() { |
| 244 | @Override |
| 245 | public int compare(ResolveInfo o1, ResolveInfo o2) { |
| 246 | return getActivityLabel(o1.activityInfo).compareTo( |
| 247 | getActivityLabel(o2.activityInfo)); |
| 248 | } |
| 249 | }); |
| 250 | return activities; |
| 251 | } |
| 252 | |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 253 | /** Returns whether the recents is currently running */ |
| 254 | public boolean isRecentsTopMost(ActivityManager.RunningTaskInfo topTask, |
| 255 | AtomicBoolean isHomeTopMost) { |
| 256 | if (topTask != null) { |
| 257 | ComponentName topActivity = topTask.topActivity; |
| 258 | |
| 259 | // Check if the front most activity is recents |
| 260 | if (topActivity.getPackageName().equals(Recents.sRecentsPackage) && |
| 261 | topActivity.getClassName().equals(Recents.sRecentsActivity)) { |
| 262 | if (isHomeTopMost != null) { |
| 263 | isHomeTopMost.set(false); |
| 264 | } |
| 265 | return true; |
| 266 | } |
| 267 | |
| 268 | if (isHomeTopMost != null) { |
| 269 | isHomeTopMost.set(isInHomeStack(topTask.id)); |
| 270 | } |
| 271 | } |
| 272 | return false; |
| 273 | } |
| 274 | |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 275 | /** Create a new stack. */ |
| 276 | public void createNewStack(int displayId, Rect bounds, Intent activity) { |
| 277 | try { |
| 278 | IActivityContainer container = mIam.createStackOnDisplay(displayId); |
| 279 | if (container != null) { |
| 280 | // Resize the stack |
| 281 | resizeStack(container.getStackId(), bounds); |
| 282 | // Start the new activity on that stack |
| 283 | container.startActivity(activity); |
| 284 | } |
| 285 | } catch (RemoteException e) { |
| 286 | e.printStackTrace(); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /** Resizes a stack. */ |
| 291 | public void resizeStack(int stackId, Rect bounds) { |
| 292 | if (mIam == null) return; |
| 293 | |
| 294 | try { |
| 295 | mIam.resizeStack(stackId, bounds); |
| 296 | } catch (RemoteException e) { |
| 297 | e.printStackTrace(); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | /** Returns the stack info for all stacks. */ |
| 302 | public SparseArray<ActivityManager.StackInfo> getAllStackInfos() { |
| 303 | if (mIam == null) return new SparseArray<ActivityManager.StackInfo>(); |
| 304 | |
| 305 | try { |
| 306 | SparseArray<ActivityManager.StackInfo> stacks = |
| 307 | new SparseArray<ActivityManager.StackInfo>(); |
| 308 | List<ActivityManager.StackInfo> infos = mIam.getAllStackInfos(); |
| 309 | int stackCount = infos.size(); |
| 310 | for (int i = 0; i < stackCount; i++) { |
| 311 | ActivityManager.StackInfo info = infos.get(i); |
| 312 | stacks.put(info.stackId, info); |
| 313 | } |
| 314 | return stacks; |
| 315 | } catch (RemoteException e) { |
| 316 | e.printStackTrace(); |
| 317 | return new SparseArray<ActivityManager.StackInfo>(); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | /** Returns the focused stack id. */ |
| 322 | public int getFocusedStack() { |
| 323 | if (mIam == null) return -1; |
| 324 | |
| 325 | try { |
| 326 | return mIam.getFocusedStackId(); |
| 327 | } catch (RemoteException e) { |
| 328 | e.printStackTrace(); |
| 329 | return -1; |
| 330 | } |
| 331 | } |
| 332 | |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 333 | /** Returns whether the specified task is in the home stack */ |
| 334 | public boolean isInHomeStack(int taskId) { |
| 335 | if (mAm == null) return false; |
| 336 | |
| 337 | // If we are mocking, then just return false |
| 338 | if (Constants.DebugFlags.App.EnableSystemServicesProxy) { |
| 339 | return false; |
| 340 | } |
| 341 | |
| 342 | return mAm.isInHomeStack(taskId); |
| 343 | } |
| 344 | |
| 345 | /** Returns the top task thumbnail for the given task id */ |
| 346 | public Bitmap getTaskThumbnail(int taskId) { |
| 347 | if (mAm == null) return null; |
| 348 | |
| 349 | // If we are mocking, then just return a dummy thumbnail |
| 350 | if (Constants.DebugFlags.App.EnableSystemServicesProxy) { |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 351 | Bitmap thumbnail = Bitmap.createBitmap(mDummyThumbnailWidth, mDummyThumbnailHeight, |
| 352 | Bitmap.Config.ARGB_8888); |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 353 | thumbnail.eraseColor(0xff333333); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 354 | return thumbnail; |
| 355 | } |
| 356 | |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 357 | Bitmap thumbnail = SystemServicesProxy.getThumbnail(mAm, taskId); |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 358 | if (thumbnail != null) { |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 359 | thumbnail.setHasAlpha(false); |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 360 | // We use a dumb heuristic for now, if the thumbnail is purely transparent in the top |
| 361 | // left pixel, then assume the whole thumbnail is transparent. Generally, proper |
| 362 | // screenshots are always composed onto a bitmap that has no alpha. |
| 363 | if (Color.alpha(thumbnail.getPixel(0, 0)) == 0) { |
| 364 | mBgProtectionCanvas.setBitmap(thumbnail); |
| 365 | mBgProtectionCanvas.drawRect(0, 0, thumbnail.getWidth(), thumbnail.getHeight(), |
| 366 | mBgProtectionPaint); |
| 367 | mBgProtectionCanvas.setBitmap(null); |
| 368 | Log.e(TAG, "Invalid screenshot detected from getTaskThumbnail()"); |
| 369 | } |
| 370 | } |
| 371 | return thumbnail; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 374 | /** |
| 375 | * Returns a task thumbnail from the activity manager |
| 376 | */ |
| 377 | public static Bitmap getThumbnail(ActivityManager activityManager, int taskId) { |
| 378 | ActivityManager.TaskThumbnail taskThumbnail = activityManager.getTaskThumbnail(taskId); |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 379 | if (taskThumbnail == null) return null; |
| 380 | |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 381 | Bitmap thumbnail = taskThumbnail.mainThumbnail; |
| 382 | ParcelFileDescriptor descriptor = taskThumbnail.thumbnailFileDescriptor; |
| 383 | if (thumbnail == null && descriptor != null) { |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 384 | thumbnail = BitmapFactory.decodeFileDescriptor(descriptor.getFileDescriptor(), |
| 385 | null, sBitmapOptions); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 386 | } |
| 387 | if (descriptor != null) { |
| 388 | try { |
| 389 | descriptor.close(); |
| 390 | } catch (IOException e) { |
| 391 | } |
| 392 | } |
| 393 | return thumbnail; |
| 394 | } |
| 395 | |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 396 | /** Moves a task to the front with the specified activity options. */ |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 397 | public void moveTaskToFront(int taskId, ActivityOptions opts) { |
| 398 | if (mAm == null) return; |
| 399 | if (Constants.DebugFlags.App.EnableSystemServicesProxy) return; |
| 400 | |
| 401 | if (opts != null) { |
| 402 | mAm.moveTaskToFront(taskId, ActivityManager.MOVE_TASK_WITH_HOME, |
| 403 | opts.toBundle()); |
| 404 | } else { |
| 405 | mAm.moveTaskToFront(taskId, ActivityManager.MOVE_TASK_WITH_HOME); |
| 406 | } |
| 407 | } |
| 408 | |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 409 | /** Moves a task to another stack. */ |
| 410 | public void moveTaskToStack(int taskId, int stackId, boolean toTop) { |
| 411 | if (mIam == null) return; |
| 412 | if (Constants.DebugFlags.App.EnableSystemServicesProxy) return; |
| 413 | |
| 414 | try { |
| 415 | mIam.moveTaskToStack(taskId, stackId, toTop); |
| 416 | } catch (RemoteException e) { |
| 417 | e.printStackTrace(); |
| 418 | } |
| 419 | } |
| 420 | |
Wale Ogunwale | d54b578 | 2014-10-23 15:55:23 -0700 | [diff] [blame] | 421 | /** Removes the task */ |
| 422 | public void removeTask(int taskId) { |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 423 | if (mAm == null) return; |
| 424 | if (Constants.DebugFlags.App.EnableSystemServicesProxy) return; |
| 425 | |
Wale Ogunwale | d54b578 | 2014-10-23 15:55:23 -0700 | [diff] [blame] | 426 | // Remove the task. |
| 427 | mAm.removeTask(taskId); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 430 | /** |
| 431 | * Returns the activity info for a given component name. |
Wale Ogunwale | d54b578 | 2014-10-23 15:55:23 -0700 | [diff] [blame] | 432 | * |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 433 | * @param cn The component name of the activity. |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 434 | * @param userId The userId of the user that this is for. |
| 435 | */ |
| 436 | public ActivityInfo getActivityInfo(ComponentName cn, int userId) { |
| 437 | if (mIpm == null) return null; |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame] | 438 | if (Constants.DebugFlags.App.EnableSystemServicesProxy) return new ActivityInfo(); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 439 | |
| 440 | try { |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 441 | return mIpm.getActivityInfo(cn, PackageManager.GET_META_DATA, userId); |
| 442 | } catch (RemoteException e) { |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 443 | e.printStackTrace(); |
| 444 | return null; |
| 445 | } |
| 446 | } |
| 447 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 448 | /** |
| 449 | * Returns the activity info for a given component name. |
| 450 | * |
| 451 | * @param cn The component name of the activity. |
| 452 | */ |
| 453 | public ActivityInfo getActivityInfo(ComponentName cn) { |
| 454 | if (mPm == null) return null; |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame] | 455 | if (Constants.DebugFlags.App.EnableSystemServicesProxy) return new ActivityInfo(); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 456 | |
| 457 | try { |
| 458 | return mPm.getActivityInfo(cn, PackageManager.GET_META_DATA); |
| 459 | } catch (PackageManager.NameNotFoundException e) { |
| 460 | e.printStackTrace(); |
| 461 | return null; |
| 462 | } |
| 463 | } |
| 464 | |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 465 | /** Returns the activity label */ |
| 466 | public String getActivityLabel(ActivityInfo info) { |
| 467 | if (mPm == null) return null; |
| 468 | |
| 469 | // If we are mocking, then return a mock label |
| 470 | if (Constants.DebugFlags.App.EnableSystemServicesProxy) { |
| 471 | return "Recent Task"; |
| 472 | } |
| 473 | |
| 474 | return info.loadLabel(mPm).toString(); |
| 475 | } |
| 476 | |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 477 | /** |
| 478 | * Returns the activity icon for the ActivityInfo for a user, badging if |
| 479 | * necessary. |
| 480 | */ |
| 481 | public Drawable getActivityIcon(ActivityInfo info, int userId) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 482 | if (mPm == null) return null; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 483 | |
| 484 | // If we are mocking, then return a mock label |
| 485 | if (Constants.DebugFlags.App.EnableSystemServicesProxy) { |
Winson Chung | 2f2ca08 | 2014-04-03 18:05:29 -0700 | [diff] [blame] | 486 | return new ColorDrawable(0xFF666666); |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 489 | Drawable icon = info.loadIcon(mPm); |
Robin Lee | 6507f2e | 2014-06-26 14:13:17 +0100 | [diff] [blame] | 490 | return getBadgedIcon(icon, userId); |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * Returns the given icon for a user, badging if necessary. |
| 495 | */ |
| 496 | public Drawable getBadgedIcon(Drawable icon, int userId) { |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 497 | if (userId != UserHandle.myUserId()) { |
Amith Yamasani | fdf169c | 2014-09-07 15:45:57 -0700 | [diff] [blame] | 498 | icon = mPm.getUserBadgedIcon(icon, new UserHandle(userId)); |
Amith Yamasani | 4f0a49e | 2014-04-10 13:48:15 -0700 | [diff] [blame] | 499 | } |
| 500 | return icon; |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 501 | } |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 502 | |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 503 | /** Returns the package name of the home activity. */ |
| 504 | public String getHomeActivityPackageName() { |
| 505 | if (mPm == null) return null; |
| 506 | if (Constants.DebugFlags.App.EnableSystemServicesProxy) return null; |
| 507 | |
| 508 | ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>(); |
| 509 | ComponentName defaultHomeActivity = mPm.getHomeActivities(homeActivities); |
| 510 | if (defaultHomeActivity != null) { |
| 511 | return defaultHomeActivity.getPackageName(); |
| 512 | } else if (homeActivities.size() == 1) { |
| 513 | ResolveInfo info = homeActivities.get(0); |
| 514 | if (info.activityInfo != null) { |
| 515 | return info.activityInfo.packageName; |
| 516 | } |
| 517 | } |
| 518 | return null; |
| 519 | } |
| 520 | |
| 521 | /** |
Winson Chung | 2002cf5 | 2014-12-08 17:26:44 -0800 | [diff] [blame] | 522 | * Returns whether the foreground user is the owner. |
| 523 | */ |
| 524 | public boolean isForegroundUserOwner() { |
| 525 | if (mAm == null) return false; |
| 526 | |
| 527 | return mAm.getCurrentUser() == UserHandle.USER_OWNER; |
| 528 | } |
| 529 | |
| 530 | /** |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 531 | * Resolves and returns the first Recents widget from the same package as the global |
| 532 | * assist activity. |
| 533 | */ |
| 534 | public AppWidgetProviderInfo resolveSearchAppWidget() { |
| 535 | if (mAwm == null) return null; |
| 536 | if (mAssistComponent == null) return null; |
| 537 | |
| 538 | // Find the first Recents widget from the same package as the global assist activity |
| 539 | List<AppWidgetProviderInfo> widgets = mAwm.getInstalledProviders( |
Winson Chung | ee0b121 | 2014-09-04 16:42:53 +0200 | [diff] [blame] | 540 | AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX); |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 541 | for (AppWidgetProviderInfo info : widgets) { |
| 542 | if (info.provider.getPackageName().equals(mAssistComponent.getPackageName())) { |
| 543 | return info; |
| 544 | } |
| 545 | } |
| 546 | return null; |
| 547 | } |
| 548 | |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 549 | /** |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 550 | * Resolves and binds the search app widget that is to appear in the recents. |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 551 | */ |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 552 | public Pair<Integer, AppWidgetProviderInfo> bindSearchAppWidget(AppWidgetHost host) { |
| 553 | if (mAwm == null) return null; |
Winson Chung | da5b84c | 2014-05-05 12:06:28 -0700 | [diff] [blame] | 554 | if (mAssistComponent == null) return null; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 555 | |
Winson Chung | da5b84c | 2014-05-05 12:06:28 -0700 | [diff] [blame] | 556 | // Find the first Recents widget from the same package as the global assist activity |
Winson Chung | bf8871d | 2014-08-28 20:57:16 -0700 | [diff] [blame] | 557 | AppWidgetProviderInfo searchWidgetInfo = resolveSearchAppWidget(); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 558 | |
| 559 | // Return early if there is no search widget |
| 560 | if (searchWidgetInfo == null) return null; |
| 561 | |
| 562 | // Allocate a new widget id and try and bind the app widget (if that fails, then just skip) |
| 563 | int searchWidgetId = host.allocateAppWidgetId(); |
| 564 | Bundle opts = new Bundle(); |
| 565 | opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, |
Winson Chung | ee0b121 | 2014-09-04 16:42:53 +0200 | [diff] [blame] | 566 | AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 567 | if (!mAwm.bindAppWidgetIdIfAllowed(searchWidgetId, searchWidgetInfo.provider, opts)) { |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 568 | host.deleteAppWidgetId(searchWidgetId); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 569 | return null; |
| 570 | } |
| 571 | return new Pair<Integer, AppWidgetProviderInfo>(searchWidgetId, searchWidgetInfo); |
| 572 | } |
| 573 | |
| 574 | /** |
| 575 | * Returns the app widget info for the specified app widget id. |
| 576 | */ |
| 577 | public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) { |
| 578 | if (mAwm == null) return null; |
| 579 | |
| 580 | return mAwm.getAppWidgetInfo(appWidgetId); |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * Destroys the specified app widget. |
| 585 | */ |
| 586 | public void unbindSearchAppWidget(AppWidgetHost host, int appWidgetId) { |
| 587 | if (mAwm == null) return; |
| 588 | |
| 589 | // Delete the app widget |
| 590 | host.deleteAppWidgetId(appWidgetId); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 591 | } |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 592 | |
| 593 | /** |
Winson Chung | ee44595 | 2014-09-09 16:12:59 +0200 | [diff] [blame] | 594 | * Returns whether touch exploration is currently enabled. |
| 595 | */ |
| 596 | public boolean isTouchExplorationEnabled() { |
| 597 | if (mAccm == null) return false; |
| 598 | |
| 599 | return mAccm.isEnabled() && mAccm.isTouchExplorationEnabled(); |
| 600 | } |
| 601 | |
| 602 | /** |
Jason Monk | 56e09b4 | 2014-07-18 10:29:14 -0400 | [diff] [blame] | 603 | * Returns a global setting. |
| 604 | */ |
| 605 | public int getGlobalSetting(Context context, String setting) { |
| 606 | ContentResolver cr = context.getContentResolver(); |
| 607 | return Settings.Global.getInt(cr, setting, 0); |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * Returns a system setting. |
| 612 | */ |
| 613 | public int getSystemSetting(Context context, String setting) { |
| 614 | ContentResolver cr = context.getContentResolver(); |
| 615 | return Settings.System.getInt(cr, setting, 0); |
| 616 | } |
| 617 | |
| 618 | /** |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 619 | * Returns a system property. |
| 620 | */ |
| 621 | public String getSystemProperty(String key) { |
| 622 | return SystemProperties.get(key); |
| 623 | } |
| 624 | |
| 625 | /** |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 626 | * Returns the window rect. |
| 627 | */ |
| 628 | public Rect getWindowRect() { |
| 629 | Rect windowRect = new Rect(); |
| 630 | if (mWm == null) return windowRect; |
| 631 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 632 | Point p = new Point(); |
| 633 | mWm.getDefaultDisplay().getRealSize(p); |
| 634 | windowRect.set(0, 0, p.x, p.y); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 635 | return windowRect; |
| 636 | } |
| 637 | |
| 638 | /** |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 639 | * Takes a screenshot of the current surface. |
| 640 | */ |
| 641 | public Bitmap takeScreenshot() { |
| 642 | DisplayInfo di = new DisplayInfo(); |
| 643 | mDisplay.getDisplayInfo(di); |
| 644 | return SurfaceControl.screenshot(di.getNaturalWidth(), di.getNaturalHeight()); |
| 645 | } |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 646 | |
| 647 | /** |
| 648 | * Takes a screenshot of the current app. |
| 649 | */ |
| 650 | public Bitmap takeAppScreenshot() { |
| 651 | return takeScreenshot(); |
| 652 | } |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 653 | |
Winson Chung | 4e96eb7 | 2014-09-17 15:16:09 +0200 | [diff] [blame] | 654 | /** Starts an activity from recents. */ |
| 655 | public boolean startActivityFromRecents(Context context, int taskId, String taskName, |
| 656 | ActivityOptions options) { |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 657 | if (mIam != null) { |
| 658 | try { |
| 659 | mIam.startActivityFromRecents(taskId, options == null ? null : options.toBundle()); |
Winson Chung | 4e96eb7 | 2014-09-17 15:16:09 +0200 | [diff] [blame] | 660 | return true; |
| 661 | } catch (Exception e) { |
| 662 | Console.logError(context, |
| 663 | context.getString(R.string.recents_launch_error_message, taskName)); |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 664 | } |
| 665 | } |
Winson Chung | 4e96eb7 | 2014-09-17 15:16:09 +0200 | [diff] [blame] | 666 | return false; |
Craig Mautner | dc00cbe | 2014-07-20 17:48:47 -0700 | [diff] [blame] | 667 | } |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 668 | |
| 669 | /** Starts an in-place animation on the front most application windows. */ |
| 670 | public void startInPlaceAnimationOnFrontMostApplication(ActivityOptions opts) { |
| 671 | if (mIam == null) return; |
| 672 | |
| 673 | try { |
| 674 | mIam.startInPlaceAnimationOnFrontMostApplication(opts); |
| 675 | } catch (Exception e) { |
| 676 | e.printStackTrace(); |
| 677 | } |
| 678 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 679 | |
| 680 | /** Registers a task stack listener with the system. */ |
| 681 | public void registerTaskStackListener(ITaskStackListener listener) { |
| 682 | if (mIam == null) return; |
| 683 | |
| 684 | try { |
| 685 | mIam.registerTaskStackListener(listener); |
| 686 | } catch (Exception e) { |
| 687 | e.printStackTrace(); |
| 688 | } |
| 689 | } |
Winson Chung | a10370f | 2014-04-02 12:25:04 -0700 | [diff] [blame] | 690 | } |