The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Svet Ganov | 019d230 | 2015-05-04 11:07:38 -0700 | [diff] [blame] | 19 | import android.Manifest; |
Michal Karpinski | 3da5c97 | 2015-12-11 18:16:30 +0000 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Svet Ganov | 019d230 | 2015-05-04 11:07:38 -0700 | [diff] [blame] | 23 | import android.annotation.RequiresPermission; |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 24 | import android.annotation.SystemApi; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 25 | import android.annotation.SystemService; |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 26 | import android.annotation.TestApi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.content.ComponentName; |
| 28 | import android.content.Context; |
| 29 | import android.content.Intent; |
Felipe Leme | f3fa0f8 | 2016-01-07 12:08:19 -0800 | [diff] [blame] | 30 | import android.content.UriPermission; |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 31 | import android.content.pm.ActivityInfo; |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 32 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.content.pm.ConfigurationInfo; |
| 34 | import android.content.pm.IPackageDataObserver; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
Felipe Leme | f3fa0f8 | 2016-01-07 12:08:19 -0800 | [diff] [blame] | 36 | import android.content.pm.ParceledListSlice; |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 37 | import android.content.pm.UserInfo; |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 38 | import android.content.res.Configuration; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 39 | import android.content.res.Resources; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.graphics.Bitmap; |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 41 | import android.graphics.Canvas; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 42 | import android.graphics.Color; |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 43 | import android.graphics.GraphicBuffer; |
| 44 | import android.graphics.Matrix; |
| 45 | import android.graphics.Point; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 46 | import android.graphics.Rect; |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 47 | import android.os.BatteryStats; |
| 48 | import android.os.Build; |
| 49 | import android.os.Build.VERSION_CODES; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 50 | import android.os.Bundle; |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 51 | import android.os.Debug; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.os.Handler; |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 53 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.os.Parcel; |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 55 | import android.os.ParcelFileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.os.Parcelable; |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 57 | import android.os.Process; |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 58 | import android.os.RemoteException; |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 59 | import android.os.ServiceManager; |
Dianne Hackborn | 2c6c5e6 | 2009-10-08 17:55:49 -0700 | [diff] [blame] | 60 | import android.os.SystemProperties; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 61 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.text.TextUtils; |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 63 | import android.util.ArrayMap; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 64 | import android.util.DisplayMetrics; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 65 | import android.util.Singleton; |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 66 | import android.util.Size; |
Felipe Leme | f3fa0f8 | 2016-01-07 12:08:19 -0800 | [diff] [blame] | 67 | |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 68 | import com.android.internal.app.procstats.ProcessStats; |
| 69 | import com.android.internal.os.RoSystemProperties; |
| 70 | import com.android.internal.os.TransferPipe; |
| 71 | import com.android.internal.util.FastPrintWriter; |
| 72 | import com.android.server.LocalServices; |
| 73 | |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 74 | import org.xmlpull.v1.XmlSerializer; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 75 | |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 76 | import java.io.FileDescriptor; |
| 77 | import java.io.FileOutputStream; |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 78 | import java.io.IOException; |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 79 | import java.io.PrintWriter; |
Michal Karpinski | 3da5c97 | 2015-12-11 18:16:30 +0000 | [diff] [blame] | 80 | import java.lang.annotation.Retention; |
| 81 | import java.lang.annotation.RetentionPolicy; |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 82 | import java.util.ArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import java.util.List; |
| 84 | |
| 85 | /** |
Dave Friedman | 2a3ebad | 2017-01-04 18:27:26 -0800 | [diff] [blame] | 86 | * <p> |
| 87 | * This class gives information about, and interacts |
| 88 | * with, activities, services, and the containing |
| 89 | * process. |
| 90 | * </p> |
| 91 | * |
| 92 | * <p> |
| 93 | * A number of the methods in this class are for |
| 94 | * debugging or informational purposes and they should |
| 95 | * not be used to affect any runtime behavior of |
| 96 | * your app. These methods are called out as such in |
| 97 | * the method level documentation. |
| 98 | * </p> |
| 99 | * |
| 100 | *<p> |
| 101 | * Most application developers should not have the need to |
| 102 | * use this class, most of whose methods are for specialized |
| 103 | * use cases. However, a few methods are more broadly applicable. |
| 104 | * For instance, {@link android.app.ActivityManager#isLowRamDevice() isLowRamDevice()} |
| 105 | * enables your app to detect whether it is running on a low-memory device, |
| 106 | * and behave accordingly. |
| 107 | * {@link android.app.ActivityManager#clearApplicationUserData() clearApplicationUserData()} |
| 108 | * is for apps with reset-data functionality. |
| 109 | * </p> |
| 110 | * |
| 111 | * <p> |
| 112 | * In some special use cases, where an app interacts with |
| 113 | * its Task stack, the app may use the |
| 114 | * {@link android.app.ActivityManager.AppTask} and |
| 115 | * {@link android.app.ActivityManager.RecentTaskInfo} inner |
| 116 | * classes. However, in general, the methods in this class should |
| 117 | * be used for testing and debugging purposes only. |
| 118 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 120 | @SystemService(Context.ACTIVITY_SERVICE) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | public class ActivityManager { |
| 122 | private static String TAG = "ActivityManager"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 124 | private static int gMaxRecentTasks = -1; |
| 125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | private final Context mContext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 128 | private static volatile boolean sSystemReady = false; |
| 129 | |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 130 | |
| 131 | private static final int FIRST_START_FATAL_ERROR_CODE = -100; |
| 132 | private static final int LAST_START_FATAL_ERROR_CODE = -1; |
| 133 | private static final int FIRST_START_SUCCESS_CODE = 0; |
| 134 | private static final int LAST_START_SUCCESS_CODE = 99; |
| 135 | private static final int FIRST_START_NON_FATAL_ERROR_CODE = 100; |
| 136 | private static final int LAST_START_NON_FATAL_ERROR_CODE = 199; |
| 137 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 138 | /** |
| 139 | * System property to enable task snapshots. |
| 140 | * @hide |
| 141 | */ |
| 142 | public final static boolean ENABLE_TASK_SNAPSHOTS; |
| 143 | |
| 144 | static { |
Robert Carr | a35e5de | 2017-03-03 17:04:54 -0800 | [diff] [blame] | 145 | ENABLE_TASK_SNAPSHOTS = SystemProperties.getBoolean("persist.enable_task_snapshots", true); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 146 | } |
| 147 | |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 148 | static final class UidObserver extends IUidObserver.Stub { |
| 149 | final OnUidImportanceListener mListener; |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 150 | final Context mContext; |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 151 | |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 152 | UidObserver(OnUidImportanceListener listener, Context clientContext) { |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 153 | mListener = listener; |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 154 | mContext = clientContext; |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Override |
Sudheer Shanka | 8025580 | 2017-03-04 14:48:53 -0800 | [diff] [blame] | 158 | public void onUidStateChanged(int uid, int procState, long procStateSeq) { |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 159 | mListener.onUidImportance(uid, RunningAppProcessInfo.procStateToImportanceForClient( |
| 160 | procState, mContext)); |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | @Override |
Dianne Hackborn | e07641d | 2016-11-09 15:07:23 -0800 | [diff] [blame] | 164 | public void onUidGone(int uid, boolean disabled) { |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 165 | mListener.onUidImportance(uid, RunningAppProcessInfo.IMPORTANCE_GONE); |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void onUidActive(int uid) { |
| 170 | } |
| 171 | |
| 172 | @Override |
Dianne Hackborn | e07641d | 2016-11-09 15:07:23 -0800 | [diff] [blame] | 173 | public void onUidIdle(int uid, boolean disabled) { |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 174 | } |
Dianne Hackborn | 3e99f65 | 2017-07-05 16:33:56 -0700 | [diff] [blame] | 175 | |
| 176 | @Override public void onUidCachedChanged(int uid, boolean cached) { |
| 177 | } |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | final ArrayMap<OnUidImportanceListener, UidObserver> mImportanceListeners = new ArrayMap<>(); |
| 181 | |
Felipe Leme | dc7af96 | 2016-01-22 18:27:03 -0800 | [diff] [blame] | 182 | /** |
| 183 | * Defines acceptable types of bugreports. |
| 184 | * @hide |
| 185 | */ |
Michal Karpinski | 3da5c97 | 2015-12-11 18:16:30 +0000 | [diff] [blame] | 186 | @Retention(RetentionPolicy.SOURCE) |
| 187 | @IntDef({ |
| 188 | BUGREPORT_OPTION_FULL, |
| 189 | BUGREPORT_OPTION_INTERACTIVE, |
Wei Liu | 967fc8d | 2016-07-08 11:44:20 -0700 | [diff] [blame] | 190 | BUGREPORT_OPTION_REMOTE, |
Felipe Leme | 9606c3b | 2017-01-05 14:57:12 -0800 | [diff] [blame] | 191 | BUGREPORT_OPTION_WEAR, |
| 192 | BUGREPORT_OPTION_TELEPHONY |
Michal Karpinski | 3da5c97 | 2015-12-11 18:16:30 +0000 | [diff] [blame] | 193 | }) |
Michal Karpinski | 3da5c97 | 2015-12-11 18:16:30 +0000 | [diff] [blame] | 194 | public @interface BugreportMode {} |
| 195 | /** |
| 196 | * Takes a bugreport without user interference (and hence causing less |
| 197 | * interference to the system), but includes all sections. |
| 198 | * @hide |
| 199 | */ |
| 200 | public static final int BUGREPORT_OPTION_FULL = 0; |
| 201 | /** |
| 202 | * Allows user to monitor progress and enter additional data; might not include all |
| 203 | * sections. |
| 204 | * @hide |
| 205 | */ |
| 206 | public static final int BUGREPORT_OPTION_INTERACTIVE = 1; |
| 207 | /** |
| 208 | * Takes a bugreport requested remotely by administrator of the Device Owner app, |
| 209 | * not the device's user. |
| 210 | * @hide |
| 211 | */ |
| 212 | public static final int BUGREPORT_OPTION_REMOTE = 2; |
Wei Liu | 967fc8d | 2016-07-08 11:44:20 -0700 | [diff] [blame] | 213 | /** |
| 214 | * Takes a bugreport on a wearable device. |
| 215 | * @hide |
| 216 | */ |
| 217 | public static final int BUGREPORT_OPTION_WEAR = 3; |
Michal Karpinski | 3da5c97 | 2015-12-11 18:16:30 +0000 | [diff] [blame] | 218 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 219 | /** |
Felipe Leme | 9606c3b | 2017-01-05 14:57:12 -0800 | [diff] [blame] | 220 | * Takes a lightweight version of bugreport that only includes a few, urgent sections |
| 221 | * used to report telephony bugs. |
| 222 | * @hide |
| 223 | */ |
| 224 | public static final int BUGREPORT_OPTION_TELEPHONY = 4; |
| 225 | |
| 226 | /** |
Scott Main | cc2195b | 2013-10-16 13:57:46 -0700 | [diff] [blame] | 227 | * <a href="{@docRoot}guide/topics/manifest/meta-data-element.html">{@code |
Neil Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 228 | * <meta-data>}</a> name for a 'home' Activity that declares a package that is to be |
Christopher Tate | bd413f6 | 2013-09-18 18:31:59 -0700 | [diff] [blame] | 229 | * uninstalled in lieu of the declaring one. The package named here must be |
Neil Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 230 | * signed with the same certificate as the one declaring the {@code <meta-data>}. |
Christopher Tate | bd413f6 | 2013-09-18 18:31:59 -0700 | [diff] [blame] | 231 | */ |
| 232 | public static final String META_HOME_ALTERNATE = "android.app.home.alternate"; |
| 233 | |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 234 | // NOTE: Before adding a new start result, please reference the defined ranges to ensure the |
| 235 | // result is properly categorized. |
| 236 | |
Christopher Tate | bd413f6 | 2013-09-18 18:31:59 -0700 | [diff] [blame] | 237 | /** |
Amith Yamasani | 4244978 | 2016-04-19 11:45:51 -0700 | [diff] [blame] | 238 | * Result for IActivityManager.startVoiceActivity: active session is currently hidden. |
| 239 | * @hide |
| 240 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 241 | public static final int START_VOICE_HIDDEN_SESSION = FIRST_START_FATAL_ERROR_CODE; |
Amith Yamasani | 4244978 | 2016-04-19 11:45:51 -0700 | [diff] [blame] | 242 | |
| 243 | /** |
| 244 | * Result for IActivityManager.startVoiceActivity: active session does not match |
| 245 | * the requesting token. |
| 246 | * @hide |
| 247 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 248 | public static final int START_VOICE_NOT_ACTIVE_SESSION = FIRST_START_FATAL_ERROR_CODE + 1; |
Amith Yamasani | 4244978 | 2016-04-19 11:45:51 -0700 | [diff] [blame] | 249 | |
| 250 | /** |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 251 | * Result for IActivityManager.startActivity: trying to start a background user |
| 252 | * activity that shouldn't be displayed for all users. |
| 253 | * @hide |
| 254 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 255 | public static final int START_NOT_CURRENT_USER_ACTIVITY = FIRST_START_FATAL_ERROR_CODE + 2; |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 256 | |
| 257 | /** |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 258 | * Result for IActivityManager.startActivity: trying to start an activity under voice |
| 259 | * control when that activity does not support the VOICE category. |
| 260 | * @hide |
| 261 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 262 | public static final int START_NOT_VOICE_COMPATIBLE = FIRST_START_FATAL_ERROR_CODE + 3; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 263 | |
| 264 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 265 | * Result for IActivityManager.startActivity: an error where the |
| 266 | * start had to be canceled. |
| 267 | * @hide |
| 268 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 269 | public static final int START_CANCELED = FIRST_START_FATAL_ERROR_CODE + 4; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 270 | |
| 271 | /** |
| 272 | * Result for IActivityManager.startActivity: an error where the |
| 273 | * thing being started is not an activity. |
| 274 | * @hide |
| 275 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 276 | public static final int START_NOT_ACTIVITY = FIRST_START_FATAL_ERROR_CODE + 5; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 277 | |
| 278 | /** |
| 279 | * Result for IActivityManager.startActivity: an error where the |
| 280 | * caller does not have permission to start the activity. |
| 281 | * @hide |
| 282 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 283 | public static final int START_PERMISSION_DENIED = FIRST_START_FATAL_ERROR_CODE + 6; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 284 | |
| 285 | /** |
| 286 | * Result for IActivityManager.startActivity: an error where the |
| 287 | * caller has requested both to forward a result and to receive |
| 288 | * a result. |
| 289 | * @hide |
| 290 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 291 | public static final int START_FORWARD_AND_REQUEST_CONFLICT = FIRST_START_FATAL_ERROR_CODE + 7; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 292 | |
| 293 | /** |
| 294 | * Result for IActivityManager.startActivity: an error where the |
| 295 | * requested class is not found. |
| 296 | * @hide |
| 297 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 298 | public static final int START_CLASS_NOT_FOUND = FIRST_START_FATAL_ERROR_CODE + 8; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 299 | |
| 300 | /** |
| 301 | * Result for IActivityManager.startActivity: an error where the |
| 302 | * given Intent could not be resolved to an activity. |
| 303 | * @hide |
| 304 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 305 | public static final int START_INTENT_NOT_RESOLVED = FIRST_START_FATAL_ERROR_CODE + 9; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 306 | |
| 307 | /** |
Winson Chung | fc3ec4c | 2017-06-01 15:35:48 -0700 | [diff] [blame] | 308 | * Result for IActivityManager.startAssistantActivity: active session is currently hidden. |
| 309 | * @hide |
| 310 | */ |
| 311 | public static final int START_ASSISTANT_HIDDEN_SESSION = FIRST_START_FATAL_ERROR_CODE + 10; |
| 312 | |
| 313 | /** |
| 314 | * Result for IActivityManager.startAssistantActivity: active session does not match |
| 315 | * the requesting token. |
| 316 | * @hide |
| 317 | */ |
| 318 | public static final int START_ASSISTANT_NOT_ACTIVE_SESSION = FIRST_START_FATAL_ERROR_CODE + 11; |
| 319 | |
| 320 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 321 | * Result for IActivityManaqer.startActivity: the activity was started |
| 322 | * successfully as normal. |
| 323 | * @hide |
| 324 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 325 | public static final int START_SUCCESS = FIRST_START_SUCCESS_CODE; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 326 | |
| 327 | /** |
| 328 | * Result for IActivityManaqer.startActivity: the caller asked that the Intent not |
| 329 | * be executed if it is the recipient, and that is indeed the case. |
| 330 | * @hide |
| 331 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 332 | public static final int START_RETURN_INTENT_TO_CALLER = FIRST_START_SUCCESS_CODE + 1; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 333 | |
| 334 | /** |
| 335 | * Result for IActivityManaqer.startActivity: activity wasn't really started, but |
| 336 | * a task was simply brought to the foreground. |
| 337 | * @hide |
| 338 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 339 | public static final int START_TASK_TO_FRONT = FIRST_START_SUCCESS_CODE + 2; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 340 | |
| 341 | /** |
| 342 | * Result for IActivityManaqer.startActivity: activity wasn't really started, but |
| 343 | * the given Intent was given to the existing top activity. |
| 344 | * @hide |
| 345 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 346 | public static final int START_DELIVERED_TO_TOP = FIRST_START_SUCCESS_CODE + 3; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 347 | |
| 348 | /** |
| 349 | * Result for IActivityManaqer.startActivity: request was canceled because |
| 350 | * app switches are temporarily canceled to ensure the user's last request |
| 351 | * (such as pressing home) is performed. |
| 352 | * @hide |
| 353 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 354 | public static final int START_SWITCHES_CANCELED = FIRST_START_NON_FATAL_ERROR_CODE; |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 355 | |
| 356 | /** |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 357 | * Result for IActivityManaqer.startActivity: a new activity was attempted to be started |
| 358 | * while in Lock Task Mode. |
| 359 | * @hide |
| 360 | */ |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 361 | public static final int START_RETURN_LOCK_TASK_MODE_VIOLATION = |
| 362 | FIRST_START_NON_FATAL_ERROR_CODE + 1; |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 363 | |
| 364 | /** |
Bryce Lee | f9d4954 | 2017-06-26 16:27:32 -0700 | [diff] [blame] | 365 | * Result for IActivityManaqer.startActivity: a new activity start was aborted. Never returned |
| 366 | * externally. |
| 367 | * @hide |
| 368 | */ |
| 369 | public static final int START_ABORTED = FIRST_START_NON_FATAL_ERROR_CODE + 2; |
| 370 | |
| 371 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 372 | * Flag for IActivityManaqer.startActivity: do special start mode where |
| 373 | * a new activity is launched only if it is needed. |
| 374 | * @hide |
| 375 | */ |
| 376 | public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0; |
| 377 | |
| 378 | /** |
| 379 | * Flag for IActivityManaqer.startActivity: launch the app for |
| 380 | * debugging. |
| 381 | * @hide |
| 382 | */ |
| 383 | public static final int START_FLAG_DEBUG = 1<<1; |
| 384 | |
| 385 | /** |
| 386 | * Flag for IActivityManaqer.startActivity: launch the app for |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 387 | * allocation tracking. |
| 388 | * @hide |
| 389 | */ |
Pablo Ceballos | a4d4e82 | 2015-10-05 10:27:52 -0700 | [diff] [blame] | 390 | public static final int START_FLAG_TRACK_ALLOCATION = 1<<2; |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 391 | |
| 392 | /** |
Tamas Berghammer | df6cb28 | 2016-01-29 12:07:00 +0000 | [diff] [blame] | 393 | * Flag for IActivityManaqer.startActivity: launch the app with |
| 394 | * native debugging support. |
| 395 | * @hide |
| 396 | */ |
| 397 | public static final int START_FLAG_NATIVE_DEBUGGING = 1<<3; |
| 398 | |
| 399 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 400 | * Result for IActivityManaqer.broadcastIntent: success! |
| 401 | * @hide |
| 402 | */ |
| 403 | public static final int BROADCAST_SUCCESS = 0; |
| 404 | |
| 405 | /** |
| 406 | * Result for IActivityManaqer.broadcastIntent: attempt to broadcast |
| 407 | * a sticky intent without appropriate permission. |
| 408 | * @hide |
| 409 | */ |
| 410 | public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1; |
| 411 | |
| 412 | /** |
Amith Yamasani | 83b6ef0 | 2014-11-07 15:34:04 -0800 | [diff] [blame] | 413 | * Result for IActivityManager.broadcastIntent: trying to send a broadcast |
| 414 | * to a stopped user. Fail. |
| 415 | * @hide |
| 416 | */ |
| 417 | public static final int BROADCAST_FAILED_USER_STOPPED = -2; |
| 418 | |
| 419 | /** |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 420 | * Type for IActivityManaqer.getIntentSender: this PendingIntent is |
| 421 | * for a sendBroadcast operation. |
| 422 | * @hide |
| 423 | */ |
| 424 | public static final int INTENT_SENDER_BROADCAST = 1; |
| 425 | |
| 426 | /** |
| 427 | * Type for IActivityManaqer.getIntentSender: this PendingIntent is |
| 428 | * for a startActivity operation. |
| 429 | * @hide |
| 430 | */ |
| 431 | public static final int INTENT_SENDER_ACTIVITY = 2; |
| 432 | |
| 433 | /** |
| 434 | * Type for IActivityManaqer.getIntentSender: this PendingIntent is |
| 435 | * for an activity result operation. |
| 436 | * @hide |
| 437 | */ |
| 438 | public static final int INTENT_SENDER_ACTIVITY_RESULT = 3; |
| 439 | |
| 440 | /** |
| 441 | * Type for IActivityManaqer.getIntentSender: this PendingIntent is |
| 442 | * for a startService operation. |
| 443 | * @hide |
| 444 | */ |
| 445 | public static final int INTENT_SENDER_SERVICE = 4; |
| 446 | |
Christopher Tate | 08992ac | 2017-03-21 11:37:06 -0700 | [diff] [blame] | 447 | /** |
| 448 | * Type for IActivityManaqer.getIntentSender: this PendingIntent is |
| 449 | * for a startForegroundService operation. |
| 450 | * @hide |
| 451 | */ |
| 452 | public static final int INTENT_SENDER_FOREGROUND_SERVICE = 5; |
| 453 | |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 454 | /** @hide User operation call: success! */ |
| 455 | public static final int USER_OP_SUCCESS = 0; |
| 456 | |
| 457 | /** @hide User operation call: given user id is not known. */ |
| 458 | public static final int USER_OP_UNKNOWN_USER = -1; |
| 459 | |
| 460 | /** @hide User operation call: given user id is the current user, can't be stopped. */ |
| 461 | public static final int USER_OP_IS_CURRENT = -2; |
| 462 | |
Fyodor Kupolov | 9cbfc9e | 2015-10-07 15:52:33 -0700 | [diff] [blame] | 463 | /** @hide User operation call: system user can't be stopped. */ |
| 464 | public static final int USER_OP_ERROR_IS_SYSTEM = -3; |
| 465 | |
| 466 | /** @hide User operation call: one of related users cannot be stopped. */ |
| 467 | public static final int USER_OP_ERROR_RELATED_USERS_CANNOT_STOP = -4; |
| 468 | |
Dianne Hackborn | 5614bf5 | 2016-11-07 17:26:41 -0800 | [diff] [blame] | 469 | /** @hide Not a real process state. */ |
| 470 | public static final int PROCESS_STATE_UNKNOWN = -1; |
Ruben Brunk | a27eef4 | 2015-01-28 15:04:16 -0800 | [diff] [blame] | 471 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 472 | /** @hide Process is a persistent system process. */ |
| 473 | public static final int PROCESS_STATE_PERSISTENT = 0; |
| 474 | |
| 475 | /** @hide Process is a persistent system process and is doing UI. */ |
| 476 | public static final int PROCESS_STATE_PERSISTENT_UI = 1; |
| 477 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 478 | /** @hide Process is hosting the current top activities. Note that this covers |
| 479 | * all activities that are visible to the user. */ |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 480 | public static final int PROCESS_STATE_TOP = 2; |
| 481 | |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 482 | /** @hide Process is hosting a foreground service due to a system binding. */ |
| 483 | public static final int PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 3; |
| 484 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 485 | /** @hide Process is hosting a foreground service. */ |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 486 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 4; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 487 | |
| 488 | /** @hide Same as {@link #PROCESS_STATE_TOP} but while device is sleeping. */ |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 489 | public static final int PROCESS_STATE_TOP_SLEEPING = 5; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 490 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 491 | /** @hide Process is important to the user, and something they are aware of. */ |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 492 | public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 6; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 493 | |
| 494 | /** @hide Process is important to the user, but not something they are aware of. */ |
Dianne Hackborn | ab4bb9d | 2015-06-05 18:08:37 -0700 | [diff] [blame] | 495 | public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 7; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 496 | |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 497 | /** @hide Process is in the background transient so we will try to keep running. */ |
| 498 | public static final int PROCESS_STATE_TRANSIENT_BACKGROUND = 8; |
| 499 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 500 | /** @hide Process is in the background running a backup/restore operation. */ |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 501 | public static final int PROCESS_STATE_BACKUP = 9; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 502 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 503 | /** @hide Process is in the background, but it can't restore its state so we want |
| 504 | * to try to avoid killing it. */ |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 505 | public static final int PROCESS_STATE_HEAVY_WEIGHT = 10; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 506 | |
| 507 | /** @hide Process is in the background running a service. Unlike oom_adj, this level |
| 508 | * is used for both the normal running in background state and the executing |
| 509 | * operations state. */ |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 510 | public static final int PROCESS_STATE_SERVICE = 11; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 511 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 512 | /** @hide Process is in the background running a receiver. Note that from the |
| 513 | * perspective of oom_adj receivers run at a higher foreground level, but for our |
| 514 | * prioritization here that is not necessary and putting them below services means |
| 515 | * many fewer changes in some process states as they receive broadcasts. */ |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 516 | public static final int PROCESS_STATE_RECEIVER = 12; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 517 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 518 | /** @hide Process is in the background but hosts the home activity. */ |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 519 | public static final int PROCESS_STATE_HOME = 13; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 520 | |
| 521 | /** @hide Process is in the background but hosts the last shown activity. */ |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 522 | public static final int PROCESS_STATE_LAST_ACTIVITY = 14; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 523 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 524 | /** @hide Process is being cached for later use and contains activities. */ |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 525 | public static final int PROCESS_STATE_CACHED_ACTIVITY = 15; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 526 | |
| 527 | /** @hide Process is being cached for later use and is a client of another cached |
| 528 | * process that contains activities. */ |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 529 | public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 16; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 530 | |
| 531 | /** @hide Process is being cached for later use and is empty. */ |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 532 | public static final int PROCESS_STATE_CACHED_EMPTY = 17; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 533 | |
Dianne Hackborn | 5614bf5 | 2016-11-07 17:26:41 -0800 | [diff] [blame] | 534 | /** @hide Process does not exist. */ |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 535 | public static final int PROCESS_STATE_NONEXISTENT = 18; |
Dianne Hackborn | 5614bf5 | 2016-11-07 17:26:41 -0800 | [diff] [blame] | 536 | |
Joe Onorato | 05c9ecc | 2016-03-30 15:13:46 -0700 | [diff] [blame] | 537 | /** @hide The lowest process state number */ |
Dianne Hackborn | 5614bf5 | 2016-11-07 17:26:41 -0800 | [diff] [blame] | 538 | public static final int MIN_PROCESS_STATE = PROCESS_STATE_PERSISTENT; |
Joe Onorato | 05c9ecc | 2016-03-30 15:13:46 -0700 | [diff] [blame] | 539 | |
| 540 | /** @hide The highest process state number */ |
Dianne Hackborn | 5614bf5 | 2016-11-07 17:26:41 -0800 | [diff] [blame] | 541 | public static final int MAX_PROCESS_STATE = PROCESS_STATE_NONEXISTENT; |
Joe Onorato | 05c9ecc | 2016-03-30 15:13:46 -0700 | [diff] [blame] | 542 | |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 543 | /** @hide Should this process state be considered a background state? */ |
| 544 | public static final boolean isProcStateBackground(int procState) { |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 545 | return procState >= PROCESS_STATE_TRANSIENT_BACKGROUND; |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 548 | /** @hide requestType for assist context: only basic information. */ |
| 549 | public static final int ASSIST_CONTEXT_BASIC = 0; |
| 550 | |
| 551 | /** @hide requestType for assist context: generate full AssistStructure. */ |
| 552 | public static final int ASSIST_CONTEXT_FULL = 1; |
| 553 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 554 | /** @hide requestType for assist context: generate full AssistStructure for autofill. */ |
| 555 | public static final int ASSIST_CONTEXT_AUTOFILL = 2; |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 556 | |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 557 | /** @hide Flag for registerUidObserver: report changes in process state. */ |
| 558 | public static final int UID_OBSERVER_PROCSTATE = 1<<0; |
| 559 | |
| 560 | /** @hide Flag for registerUidObserver: report uid gone. */ |
| 561 | public static final int UID_OBSERVER_GONE = 1<<1; |
| 562 | |
| 563 | /** @hide Flag for registerUidObserver: report uid has become idle. */ |
| 564 | public static final int UID_OBSERVER_IDLE = 1<<2; |
| 565 | |
| 566 | /** @hide Flag for registerUidObserver: report uid has become active. */ |
| 567 | public static final int UID_OBSERVER_ACTIVE = 1<<3; |
| 568 | |
Dianne Hackborn | 3e99f65 | 2017-07-05 16:33:56 -0700 | [diff] [blame] | 569 | /** @hide Flag for registerUidObserver: report uid cached state has changed. */ |
| 570 | public static final int UID_OBSERVER_CACHED = 1<<4; |
| 571 | |
Dianne Hackborn | c3af19a | 2017-01-20 17:00:44 -0800 | [diff] [blame] | 572 | /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: normal free-to-run operation. */ |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 573 | public static final int APP_START_MODE_NORMAL = 0; |
| 574 | |
Dianne Hackborn | c3af19a | 2017-01-20 17:00:44 -0800 | [diff] [blame] | 575 | /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later. */ |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 576 | public static final int APP_START_MODE_DELAYED = 1; |
| 577 | |
Dianne Hackborn | c3af19a | 2017-01-20 17:00:44 -0800 | [diff] [blame] | 578 | /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later, with |
Dianne Hackborn | 85e3564 | 2017-01-12 15:10:57 -0800 | [diff] [blame] | 579 | * rigid errors (throwing exception). */ |
| 580 | public static final int APP_START_MODE_DELAYED_RIGID = 2; |
| 581 | |
Dianne Hackborn | c3af19a | 2017-01-20 17:00:44 -0800 | [diff] [blame] | 582 | /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: disable/cancel pending |
Dianne Hackborn | 85e3564 | 2017-01-12 15:10:57 -0800 | [diff] [blame] | 583 | * launches; this is the mode for ephemeral apps. */ |
| 584 | public static final int APP_START_MODE_DISABLED = 3; |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 585 | |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 586 | /** |
| 587 | * Lock task mode is not active. |
| 588 | */ |
| 589 | public static final int LOCK_TASK_MODE_NONE = 0; |
| 590 | |
| 591 | /** |
| 592 | * Full lock task mode is active. |
| 593 | */ |
| 594 | public static final int LOCK_TASK_MODE_LOCKED = 1; |
| 595 | |
| 596 | /** |
| 597 | * App pinning mode is active. |
| 598 | */ |
| 599 | public static final int LOCK_TASK_MODE_PINNED = 2; |
| 600 | |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 601 | Point mAppTaskThumbnailSize; |
| 602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | /*package*/ ActivityManager(Context context, Handler handler) { |
| 604 | mContext = context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | /** |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 608 | * Returns whether the launch was successful. |
| 609 | * @hide |
| 610 | */ |
| 611 | public static final boolean isStartResultSuccessful(int result) { |
| 612 | return FIRST_START_SUCCESS_CODE <= result && result <= LAST_START_SUCCESS_CODE; |
| 613 | } |
| 614 | |
| 615 | /** |
| 616 | * Returns whether the launch result was a fatal error. |
| 617 | * @hide |
| 618 | */ |
| 619 | public static final boolean isStartResultFatalError(int result) { |
| 620 | return FIRST_START_FATAL_ERROR_CODE <= result && result <= LAST_START_FATAL_ERROR_CODE; |
| 621 | } |
| 622 | |
| 623 | /** |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 624 | * Screen compatibility mode: the application most always run in |
| 625 | * compatibility mode. |
| 626 | * @hide |
| 627 | */ |
| 628 | public static final int COMPAT_MODE_ALWAYS = -1; |
| 629 | |
| 630 | /** |
| 631 | * Screen compatibility mode: the application can never run in |
| 632 | * compatibility mode. |
| 633 | * @hide |
| 634 | */ |
| 635 | public static final int COMPAT_MODE_NEVER = -2; |
| 636 | |
| 637 | /** |
| 638 | * Screen compatibility mode: unknown. |
| 639 | * @hide |
| 640 | */ |
| 641 | public static final int COMPAT_MODE_UNKNOWN = -3; |
| 642 | |
| 643 | /** |
| 644 | * Screen compatibility mode: the application currently has compatibility |
| 645 | * mode disabled. |
| 646 | * @hide |
| 647 | */ |
| 648 | public static final int COMPAT_MODE_DISABLED = 0; |
| 649 | |
| 650 | /** |
| 651 | * Screen compatibility mode: the application currently has compatibility |
| 652 | * mode enabled. |
| 653 | * @hide |
| 654 | */ |
| 655 | public static final int COMPAT_MODE_ENABLED = 1; |
| 656 | |
| 657 | /** |
| 658 | * Screen compatibility mode: request to toggle the application's |
| 659 | * compatibility mode. |
| 660 | * @hide |
| 661 | */ |
| 662 | public static final int COMPAT_MODE_TOGGLE = 2; |
| 663 | |
Marc Hittinger | 17fb596 | 2017-04-05 15:34:38 -0700 | [diff] [blame] | 664 | private static final boolean DEVELOPMENT_FORCE_LOW_RAM = |
| 665 | SystemProperties.getBoolean("debug.force_low_ram", false); |
| 666 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 667 | /** @hide */ |
| 668 | public static class StackId { |
| 669 | /** Invalid stack ID. */ |
| 670 | public static final int INVALID_STACK_ID = -1; |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 671 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 672 | /** First static stack ID. */ |
| 673 | public static final int FIRST_STATIC_STACK_ID = 0; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 674 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 675 | /** Home activity stack ID. */ |
| 676 | public static final int HOME_STACK_ID = FIRST_STATIC_STACK_ID; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 677 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 678 | /** ID of stack where fullscreen activities are normally launched into. */ |
| 679 | public static final int FULLSCREEN_WORKSPACE_STACK_ID = 1; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 680 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 681 | /** ID of stack where freeform/resized activities are normally launched into. */ |
| 682 | public static final int FREEFORM_WORKSPACE_STACK_ID = FULLSCREEN_WORKSPACE_STACK_ID + 1; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 683 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 684 | /** ID of stack that occupies a dedicated region of the screen. */ |
| 685 | public static final int DOCKED_STACK_ID = FREEFORM_WORKSPACE_STACK_ID + 1; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 686 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 687 | /** ID of stack that always on top (always visible) when it exist. */ |
| 688 | public static final int PINNED_STACK_ID = DOCKED_STACK_ID + 1; |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 689 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 690 | /** ID of stack that contains the Recents activity. */ |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 691 | public static final int RECENTS_STACK_ID = PINNED_STACK_ID + 1; |
| 692 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 693 | /** ID of stack that contains activities launched by the assistant. */ |
| 694 | public static final int ASSISTANT_STACK_ID = RECENTS_STACK_ID + 1; |
| 695 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 696 | /** Last static stack stack ID. */ |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 697 | public static final int LAST_STATIC_STACK_ID = ASSISTANT_STACK_ID; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 698 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 699 | /** Start of ID range used by stacks that are created dynamically. */ |
| 700 | public static final int FIRST_DYNAMIC_STACK_ID = LAST_STATIC_STACK_ID + 1; |
| 701 | |
| 702 | public static boolean isStaticStack(int stackId) { |
| 703 | return stackId >= FIRST_STATIC_STACK_ID && stackId <= LAST_STATIC_STACK_ID; |
| 704 | } |
| 705 | |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 706 | public static boolean isDynamicStack(int stackId) { |
| 707 | return stackId >= FIRST_DYNAMIC_STACK_ID; |
| 708 | } |
| 709 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 710 | /** |
| 711 | * Returns true if the activities contained in the input stack display a shadow around |
| 712 | * their border. |
| 713 | */ |
| 714 | public static boolean hasWindowShadow(int stackId) { |
| 715 | return stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == PINNED_STACK_ID; |
| 716 | } |
| 717 | |
| 718 | /** |
| 719 | * Returns true if the activities contained in the input stack display a decor view. |
| 720 | */ |
| 721 | public static boolean hasWindowDecor(int stackId) { |
| 722 | return stackId == FREEFORM_WORKSPACE_STACK_ID; |
| 723 | } |
| 724 | |
| 725 | /** |
| 726 | * Returns true if the tasks contained in the stack can be resized independently of the |
| 727 | * stack. |
| 728 | */ |
| 729 | public static boolean isTaskResizeAllowed(int stackId) { |
| 730 | return stackId == FREEFORM_WORKSPACE_STACK_ID; |
| 731 | } |
| 732 | |
Wale Ogunwale | 807d882 | 2015-12-15 17:05:09 -0800 | [diff] [blame] | 733 | /** Returns true if the task bounds should persist across power cycles. */ |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 734 | public static boolean persistTaskBounds(int stackId) { |
Wale Ogunwale | 807d882 | 2015-12-15 17:05:09 -0800 | [diff] [blame] | 735 | return stackId == FREEFORM_WORKSPACE_STACK_ID; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | /** |
| 739 | * Returns true if dynamic stacks are allowed to be visible behind the input stack. |
| 740 | */ |
| 741 | public static boolean isDynamicStacksVisibleBehindAllowed(int stackId) { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 742 | return stackId == PINNED_STACK_ID || stackId == ASSISTANT_STACK_ID; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Returns true if we try to maintain focus in the current stack when the top activity |
| 747 | * finishes. |
| 748 | */ |
| 749 | public static boolean keepFocusInStackIfPossible(int stackId) { |
| 750 | return stackId == FREEFORM_WORKSPACE_STACK_ID |
| 751 | || stackId == DOCKED_STACK_ID || stackId == PINNED_STACK_ID; |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * Returns true if Stack size is affected by the docked stack changing size. |
| 756 | */ |
| 757 | public static boolean isResizeableByDockedStack(int stackId) { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 758 | return isStaticStack(stackId) && stackId != DOCKED_STACK_ID |
| 759 | && stackId != PINNED_STACK_ID && stackId != ASSISTANT_STACK_ID; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | /** |
| 763 | * Returns true if the size of tasks in the input stack are affected by the docked stack |
| 764 | * changing size. |
| 765 | */ |
| 766 | public static boolean isTaskResizeableByDockedStack(int stackId) { |
| 767 | return isStaticStack(stackId) && stackId != FREEFORM_WORKSPACE_STACK_ID |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 768 | && stackId != DOCKED_STACK_ID && stackId != PINNED_STACK_ID |
| 769 | && stackId != ASSISTANT_STACK_ID; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /** |
Winson Chung | 2af04b3 | 2017-01-24 16:21:13 -0800 | [diff] [blame] | 773 | * Returns true if the input stack is affected by drag resizing. |
| 774 | */ |
| 775 | public static boolean isStackAffectedByDragResizing(int stackId) { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 776 | return isStaticStack(stackId) && stackId != PINNED_STACK_ID |
| 777 | && stackId != ASSISTANT_STACK_ID; |
Winson Chung | 2af04b3 | 2017-01-24 16:21:13 -0800 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | /** |
Jorim Jaggi | e909802 | 2016-01-27 19:29:40 -0800 | [diff] [blame] | 781 | * Returns true if the windows of tasks being moved to the target stack from the source |
| 782 | * stack should be replaced, meaning that window manager will keep the old window around |
| 783 | * until the new is ready. |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 784 | */ |
Jorim Jaggi | e909802 | 2016-01-27 19:29:40 -0800 | [diff] [blame] | 785 | public static boolean replaceWindowsOnTaskMove(int sourceStackId, int targetStackId) { |
| 786 | return sourceStackId == FREEFORM_WORKSPACE_STACK_ID |
| 787 | || targetStackId == FREEFORM_WORKSPACE_STACK_ID; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 788 | } |
Filip Gruszczynski | 96daf32 | 2015-11-18 18:01:27 -0800 | [diff] [blame] | 789 | |
| 790 | /** |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 791 | * Return whether a stackId is a stack containing floating windows. Floating windows |
| 792 | * are laid out differently as they are allowed to extend past the display bounds |
| 793 | * without overscan insets. |
| 794 | */ |
| 795 | public static boolean tasksAreFloating(int stackId) { |
| 796 | return stackId == FREEFORM_WORKSPACE_STACK_ID |
| 797 | || stackId == PINNED_STACK_ID; |
| 798 | } |
| 799 | |
| 800 | /** |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 801 | * Return whether a stackId is a stack that be a backdrop to a translucent activity. These |
| 802 | * are generally fullscreen stacks. |
| 803 | */ |
| 804 | public static boolean isBackdropToTranslucentActivity(int stackId) { |
| 805 | return stackId == FULLSCREEN_WORKSPACE_STACK_ID |
| 806 | || stackId == ASSISTANT_STACK_ID; |
| 807 | } |
| 808 | |
| 809 | /** |
Filip Gruszczynski | 96daf32 | 2015-11-18 18:01:27 -0800 | [diff] [blame] | 810 | * Returns true if animation specs should be constructed for app transition that moves |
| 811 | * the task to the specified stack. |
| 812 | */ |
| 813 | public static boolean useAnimationSpecForAppTransition(int stackId) { |
Jorim Jaggi | 8a5c640 | 2016-02-12 16:55:18 -0800 | [diff] [blame] | 814 | // TODO: INVALID_STACK_ID is also animated because we don't persist stack id's across |
| 815 | // reboots. |
Filip Gruszczynski | 96daf32 | 2015-11-18 18:01:27 -0800 | [diff] [blame] | 816 | return stackId == FREEFORM_WORKSPACE_STACK_ID |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 817 | || stackId == FULLSCREEN_WORKSPACE_STACK_ID |
| 818 | || stackId == ASSISTANT_STACK_ID |
| 819 | || stackId == DOCKED_STACK_ID |
Jorim Jaggi | 8a5c640 | 2016-02-12 16:55:18 -0800 | [diff] [blame] | 820 | || stackId == INVALID_STACK_ID; |
Filip Gruszczynski | 96daf32 | 2015-11-18 18:01:27 -0800 | [diff] [blame] | 821 | } |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 822 | |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 823 | /** |
| 824 | * Returns true if the windows in the stack can receive input keys. |
| 825 | */ |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 826 | public static boolean canReceiveKeys(int stackId) { |
| 827 | return stackId != PINNED_STACK_ID; |
| 828 | } |
Filip Gruszczynski | 114d5ca | 2015-12-04 09:05:00 -0800 | [diff] [blame] | 829 | |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 830 | /** |
| 831 | * Returns true if the stack can be visible above lockscreen. |
| 832 | */ |
| 833 | public static boolean isAllowedOverLockscreen(int stackId) { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 834 | return stackId == HOME_STACK_ID || stackId == FULLSCREEN_WORKSPACE_STACK_ID || |
| 835 | stackId == ASSISTANT_STACK_ID; |
| 836 | } |
| 837 | |
| 838 | /** |
| 839 | * Returns true if activities from stasks in the given {@param stackId} are allowed to |
| 840 | * enter picture-in-picture. |
| 841 | */ |
| 842 | public static boolean isAllowedToEnterPictureInPicture(int stackId) { |
| 843 | return stackId != HOME_STACK_ID && stackId != ASSISTANT_STACK_ID && |
| 844 | stackId != RECENTS_STACK_ID; |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 845 | } |
| 846 | |
Filip Gruszczynski | 114d5ca | 2015-12-04 09:05:00 -0800 | [diff] [blame] | 847 | public static boolean isAlwaysOnTop(int stackId) { |
| 848 | return stackId == PINNED_STACK_ID; |
| 849 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 850 | |
| 851 | /** |
| 852 | * Returns true if the top task in the task is allowed to return home when finished and |
| 853 | * there are other tasks in the stack. |
| 854 | */ |
| 855 | public static boolean allowTopTaskToReturnHome(int stackId) { |
| 856 | return stackId != PINNED_STACK_ID; |
| 857 | } |
Wale Ogunwale | cacfaa2 | 2016-01-15 11:26:08 -0800 | [diff] [blame] | 858 | |
| 859 | /** |
| 860 | * Returns true if the stack should be resized to match the bounds specified by |
| 861 | * {@link ActivityOptions#setLaunchBounds} when launching an activity into the stack. |
| 862 | */ |
| 863 | public static boolean resizeStackWithLaunchBounds(int stackId) { |
| 864 | return stackId == PINNED_STACK_ID; |
| 865 | } |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 866 | |
| 867 | /** |
| 868 | * Returns true if any visible windows belonging to apps in this stack should be kept on |
| 869 | * screen when the app is killed due to something like the low memory killer. |
| 870 | */ |
| 871 | public static boolean keepVisibleDeadAppWindowOnScreen(int stackId) { |
| 872 | return stackId != PINNED_STACK_ID; |
| 873 | } |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 874 | |
| 875 | /** |
| 876 | * Returns true if the backdrop on the client side should match the frame of the window. |
| 877 | * Returns false, if the backdrop should be fullscreen. |
| 878 | */ |
| 879 | public static boolean useWindowFrameForBackdrop(int stackId) { |
| 880 | return stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == PINNED_STACK_ID; |
| 881 | } |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 882 | |
| 883 | /** |
| 884 | * Returns true if a window from the specified stack with {@param stackId} are normally |
| 885 | * fullscreen, i. e. they can become the top opaque fullscreen window, meaning that it |
| 886 | * controls system bars, lockscreen occluded/dismissing state, screen rotation animation, |
| 887 | * etc. |
| 888 | */ |
| 889 | public static boolean normallyFullscreenWindows(int stackId) { |
| 890 | return stackId != PINNED_STACK_ID && stackId != FREEFORM_WORKSPACE_STACK_ID |
| 891 | && stackId != DOCKED_STACK_ID; |
| 892 | } |
Wale Ogunwale | fb1c864 | 2016-03-02 08:28:08 -0800 | [diff] [blame] | 893 | |
| 894 | /** |
| 895 | * Returns true if the input stack id should only be present on a device that supports |
| 896 | * multi-window mode. |
| 897 | * @see android.app.ActivityManager#supportsMultiWindow |
| 898 | */ |
| 899 | public static boolean isMultiWindowStack(int stackId) { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 900 | return stackId == PINNED_STACK_ID || stackId == FREEFORM_WORKSPACE_STACK_ID |
| 901 | || stackId == DOCKED_STACK_ID; |
Wale Ogunwale | fb1c864 | 2016-03-02 08:28:08 -0800 | [diff] [blame] | 902 | } |
Wale Ogunwale | 43896cf | 2016-04-16 10:54:30 -0700 | [diff] [blame] | 903 | |
| 904 | /** |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 905 | * Returns true if the input {@param stackId} is HOME_STACK_ID or RECENTS_STACK_ID |
| 906 | */ |
| 907 | public static boolean isHomeOrRecentsStack(int stackId) { |
| 908 | return stackId == HOME_STACK_ID || stackId == RECENTS_STACK_ID; |
| 909 | } |
| 910 | |
| 911 | /** |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 912 | * Returns true if this stack may be scaled without resizing, and windows within may need |
| 913 | * to be configured as such. |
Robert Carr | 1b5ea72 | 2016-04-20 13:23:28 -0700 | [diff] [blame] | 914 | */ |
| 915 | public static boolean windowsAreScaleable(int stackId) { |
| 916 | return stackId == PINNED_STACK_ID; |
| 917 | } |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 918 | |
| 919 | /** |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 920 | * Returns true if windows in this stack should be given move animations by default. |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 921 | */ |
| 922 | public static boolean hasMovementAnimations(int stackId) { |
| 923 | return stackId != PINNED_STACK_ID; |
| 924 | } |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 925 | |
| 926 | /** Returns true if the input stack and its content can affect the device orientation. */ |
| 927 | public static boolean canSpecifyOrientation(int stackId) { |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 928 | return stackId == HOME_STACK_ID |
| 929 | || stackId == RECENTS_STACK_ID |
| 930 | || stackId == FULLSCREEN_WORKSPACE_STACK_ID |
| 931 | || stackId == ASSISTANT_STACK_ID |
| 932 | || isDynamicStack(stackId); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 933 | } |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 934 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 935 | |
Wale Ogunwale | 59a73ca | 2015-09-14 12:54:50 -0700 | [diff] [blame] | 936 | /** |
| 937 | * Input parameter to {@link android.app.IActivityManager#moveTaskToDockedStack} which |
| 938 | * specifies the position of the created docked stack at the top half of the screen if |
| 939 | * in portrait mode or at the left half of the screen if in landscape mode. |
| 940 | * @hide |
| 941 | */ |
| 942 | public static final int DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT = 0; |
| 943 | |
| 944 | /** |
| 945 | * Input parameter to {@link android.app.IActivityManager#moveTaskToDockedStack} which |
| 946 | * specifies the position of the created docked stack at the bottom half of the screen if |
| 947 | * in portrait mode or at the right half of the screen if in landscape mode. |
| 948 | * @hide |
| 949 | */ |
| 950 | public static final int DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT = 1; |
| 951 | |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 952 | /** |
| 953 | * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates |
Chong Zhang | 6de2ae8 | 2015-09-30 18:25:21 -0700 | [diff] [blame] | 954 | * that the resize doesn't need to preserve the window, and can be skipped if bounds |
| 955 | * is unchanged. This mode is used by window manager in most cases. |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 956 | * @hide |
| 957 | */ |
| 958 | public static final int RESIZE_MODE_SYSTEM = 0; |
| 959 | |
| 960 | /** |
| 961 | * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates |
Chong Zhang | 6de2ae8 | 2015-09-30 18:25:21 -0700 | [diff] [blame] | 962 | * that the resize should preserve the window if possible. |
Wale Ogunwale | 1ed0d89 | 2015-09-28 13:27:44 -0700 | [diff] [blame] | 963 | * @hide |
| 964 | */ |
Chong Zhang | 6de2ae8 | 2015-09-30 18:25:21 -0700 | [diff] [blame] | 965 | public static final int RESIZE_MODE_PRESERVE_WINDOW = (0x1 << 0); |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 966 | |
| 967 | /** |
| 968 | * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates |
| 969 | * that the resize should be performed even if the bounds appears unchanged. |
| 970 | * @hide |
| 971 | */ |
Chong Zhang | 6de2ae8 | 2015-09-30 18:25:21 -0700 | [diff] [blame] | 972 | public static final int RESIZE_MODE_FORCED = (0x1 << 1); |
| 973 | |
| 974 | /** |
| 975 | * Input parameter to {@link android.app.IActivityManager#resizeTask} used by window |
| 976 | * manager during a screen rotation. |
| 977 | * @hide |
| 978 | */ |
| 979 | public static final int RESIZE_MODE_SYSTEM_SCREEN_ROTATION = RESIZE_MODE_PRESERVE_WINDOW; |
| 980 | |
| 981 | /** |
| 982 | * Input parameter to {@link android.app.IActivityManager#resizeTask} used when the |
| 983 | * resize is due to a drag action. |
| 984 | * @hide |
| 985 | */ |
| 986 | public static final int RESIZE_MODE_USER = RESIZE_MODE_PRESERVE_WINDOW; |
| 987 | |
| 988 | /** |
| 989 | * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates |
| 990 | * that the resize should preserve the window if possible, and should not be skipped |
| 991 | * even if the bounds is unchanged. Usually used to force a resizing when a drag action |
| 992 | * is ending. |
| 993 | * @hide |
| 994 | */ |
| 995 | public static final int RESIZE_MODE_USER_FORCED = |
| 996 | RESIZE_MODE_PRESERVE_WINDOW | RESIZE_MODE_FORCED; |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 997 | |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 998 | /** @hide */ |
| 999 | public int getFrontActivityScreenCompatMode() { |
| 1000 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1001 | return getService().getFrontActivityScreenCompatMode(); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 1002 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1003 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 1004 | } |
| 1005 | } |
| 1006 | |
Dianne Hackborn | df9799f | 2011-05-12 15:16:33 -0700 | [diff] [blame] | 1007 | /** @hide */ |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 1008 | public void setFrontActivityScreenCompatMode(int mode) { |
| 1009 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1010 | getService().setFrontActivityScreenCompatMode(mode); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 1011 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1012 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | |
Dianne Hackborn | df9799f | 2011-05-12 15:16:33 -0700 | [diff] [blame] | 1016 | /** @hide */ |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 1017 | public int getPackageScreenCompatMode(String packageName) { |
| 1018 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1019 | return getService().getPackageScreenCompatMode(packageName); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 1020 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1021 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 1022 | } |
| 1023 | } |
| 1024 | |
Dianne Hackborn | df9799f | 2011-05-12 15:16:33 -0700 | [diff] [blame] | 1025 | /** @hide */ |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 1026 | public void setPackageScreenCompatMode(String packageName, int mode) { |
| 1027 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1028 | getService().setPackageScreenCompatMode(packageName, mode); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 1029 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1030 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 1031 | } |
| 1032 | } |
| 1033 | |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 1034 | /** @hide */ |
| 1035 | public boolean getPackageAskScreenCompat(String packageName) { |
| 1036 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1037 | return getService().getPackageAskScreenCompat(packageName); |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 1038 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1039 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | /** @hide */ |
| 1044 | public void setPackageAskScreenCompat(String packageName, boolean ask) { |
| 1045 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1046 | getService().setPackageAskScreenCompat(packageName, ask); |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 1047 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1048 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 36cd41f | 2011-05-25 21:00:46 -0700 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | |
Dianne Hackborn | 0f1de9a | 2011-05-11 17:34:49 -0700 | [diff] [blame] | 1052 | /** |
Dianne Hackborn | 2c6c5e6 | 2009-10-08 17:55:49 -0700 | [diff] [blame] | 1053 | * Return the approximate per-application memory class of the current |
| 1054 | * device. This gives you an idea of how hard a memory limit you should |
| 1055 | * impose on your application to let the overall system work best. The |
| 1056 | * returned value is in megabytes; the baseline Android memory class is |
| 1057 | * 16 (which happens to be the Java heap limit of those devices); some |
| 1058 | * device with more memory may return 24 or even higher numbers. |
| 1059 | */ |
| 1060 | public int getMemoryClass() { |
| 1061 | return staticGetMemoryClass(); |
| 1062 | } |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 1063 | |
Dianne Hackborn | 2c6c5e6 | 2009-10-08 17:55:49 -0700 | [diff] [blame] | 1064 | /** @hide */ |
| 1065 | static public int staticGetMemoryClass() { |
| 1066 | // Really brain dead right now -- just take this from the configured |
| 1067 | // vm heap size, and assume it is in megabytes and thus ends with "m". |
Dianne Hackborn | 7ad33c8 | 2011-03-08 15:53:25 -0800 | [diff] [blame] | 1068 | String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", ""); |
Dianne Hackborn | de39851 | 2011-01-18 18:45:21 -0800 | [diff] [blame] | 1069 | if (vmHeapSize != null && !"".equals(vmHeapSize)) { |
| 1070 | return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1)); |
| 1071 | } |
| 1072 | return staticGetLargeMemoryClass(); |
Dianne Hackborn | 4e24aac | 2010-12-23 11:43:46 -0800 | [diff] [blame] | 1073 | } |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 1074 | |
Dianne Hackborn | 4e24aac | 2010-12-23 11:43:46 -0800 | [diff] [blame] | 1075 | /** |
| 1076 | * Return the approximate per-application memory class of the current |
| 1077 | * device when an application is running with a large heap. This is the |
| 1078 | * space available for memory-intensive applications; most applications |
| 1079 | * should not need this amount of memory, and should instead stay with the |
| 1080 | * {@link #getMemoryClass()} limit. The returned value is in megabytes. |
| 1081 | * This may be the same size as {@link #getMemoryClass()} on memory |
| 1082 | * constrained devices, or it may be significantly larger on devices with |
| 1083 | * a large amount of available RAM. |
Dianne Hackborn | 3b81bc1 | 2011-01-15 11:50:52 -0800 | [diff] [blame] | 1084 | * |
| 1085 | * <p>The is the size of the application's Dalvik heap if it has |
| 1086 | * specified <code>android:largeHeap="true"</code> in its manifest. |
Dianne Hackborn | 4e24aac | 2010-12-23 11:43:46 -0800 | [diff] [blame] | 1087 | */ |
| 1088 | public int getLargeMemoryClass() { |
| 1089 | return staticGetLargeMemoryClass(); |
| 1090 | } |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 1091 | |
Dianne Hackborn | 4e24aac | 2010-12-23 11:43:46 -0800 | [diff] [blame] | 1092 | /** @hide */ |
| 1093 | static public int staticGetLargeMemoryClass() { |
| 1094 | // Really brain dead right now -- just take this from the configured |
| 1095 | // vm heap size, and assume it is in megabytes and thus ends with "m". |
Dianne Hackborn | 2c6c5e6 | 2009-10-08 17:55:49 -0700 | [diff] [blame] | 1096 | String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m"); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1097 | return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length() - 1)); |
Dianne Hackborn | 2c6c5e6 | 2009-10-08 17:55:49 -0700 | [diff] [blame] | 1098 | } |
Dianne Hackborn | b4e1249 | 2013-06-26 15:08:19 -0700 | [diff] [blame] | 1099 | |
| 1100 | /** |
| 1101 | * Returns true if this is a low-RAM device. Exactly whether a device is low-RAM |
| 1102 | * is ultimately up to the device configuration, but currently it generally means |
Greg Kaiser | e2c459e | 2017-10-26 10:36:37 -0700 | [diff] [blame] | 1103 | * something with 1GB or less of RAM. This is mostly intended to be used by apps |
| 1104 | * to determine whether they should turn off certain features that require more RAM. |
Dianne Hackborn | b4e1249 | 2013-06-26 15:08:19 -0700 | [diff] [blame] | 1105 | */ |
| 1106 | public boolean isLowRamDevice() { |
| 1107 | return isLowRamDeviceStatic(); |
| 1108 | } |
| 1109 | |
| 1110 | /** @hide */ |
| 1111 | public static boolean isLowRamDeviceStatic() { |
Marc Hittinger | 17fb596 | 2017-04-05 15:34:38 -0700 | [diff] [blame] | 1112 | return RoSystemProperties.CONFIG_LOW_RAM || |
| 1113 | (Build.IS_DEBUGGABLE && DEVELOPMENT_FORCE_LOW_RAM); |
Dianne Hackborn | b4e1249 | 2013-06-26 15:08:19 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
Dianne Hackborn | 2c6c5e6 | 2009-10-08 17:55:49 -0700 | [diff] [blame] | 1116 | /** |
Michael Kwan | 15eb998 | 2017-04-14 12:34:46 -0700 | [diff] [blame] | 1117 | * Returns true if this is a small battery device. Exactly whether a device is considered to be |
| 1118 | * small battery is ultimately up to the device configuration, but currently it generally means |
| 1119 | * something in the class of a device with 1000 mAh or less. This is mostly intended to be used |
| 1120 | * to determine whether certain features should be altered to account for a drastically smaller |
| 1121 | * battery. |
| 1122 | * @hide |
| 1123 | */ |
| 1124 | public static boolean isSmallBatteryDevice() { |
| 1125 | return RoSystemProperties.CONFIG_SMALL_BATTERY; |
| 1126 | } |
| 1127 | |
| 1128 | /** |
Dianne Hackborn | b375632 | 2011-08-12 13:58:13 -0700 | [diff] [blame] | 1129 | * Used by persistent processes to determine if they are running on a |
| 1130 | * higher-end device so should be okay using hardware drawing acceleration |
| 1131 | * (which tends to consume a lot more RAM). |
| 1132 | * @hide |
| 1133 | */ |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1134 | static public boolean isHighEndGfx() { |
Dianne Hackborn | b4e1249 | 2013-06-26 15:08:19 -0700 | [diff] [blame] | 1135 | return !isLowRamDeviceStatic() && |
| 1136 | !Resources.getSystem().getBoolean(com.android.internal.R.bool.config_avoidGfxAccel); |
Dianne Hackborn | 49d228b3 | 2011-08-24 17:37:31 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | /** |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1140 | * Return the maximum number of recents entries that we will maintain and show. |
| 1141 | * @hide |
| 1142 | */ |
| 1143 | static public int getMaxRecentTasksStatic() { |
| 1144 | if (gMaxRecentTasks < 0) { |
Winson | 7c40291 | 2016-05-10 13:59:36 -0700 | [diff] [blame] | 1145 | return gMaxRecentTasks = isLowRamDeviceStatic() ? 36 : 48; |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 1146 | } |
| 1147 | return gMaxRecentTasks; |
| 1148 | } |
| 1149 | |
| 1150 | /** |
| 1151 | * Return the default limit on the number of recents that an app can make. |
| 1152 | * @hide |
| 1153 | */ |
| 1154 | static public int getDefaultAppRecentsLimitStatic() { |
| 1155 | return getMaxRecentTasksStatic() / 6; |
| 1156 | } |
| 1157 | |
| 1158 | /** |
| 1159 | * Return the maximum limit on the number of recents that an app can make. |
| 1160 | * @hide |
| 1161 | */ |
| 1162 | static public int getMaxAppRecentsLimitStatic() { |
| 1163 | return getMaxRecentTasksStatic() / 2; |
| 1164 | } |
| 1165 | |
| 1166 | /** |
Wale Ogunwale | fb1c864 | 2016-03-02 08:28:08 -0800 | [diff] [blame] | 1167 | * Returns true if the system supports at least one form of multi-window. |
| 1168 | * E.g. freeform, split-screen, picture-in-picture. |
| 1169 | * @hide |
| 1170 | */ |
Erik Wolsheimer | 9be3a06 | 2017-05-31 14:59:57 -0700 | [diff] [blame] | 1171 | static public boolean supportsMultiWindow(Context context) { |
| 1172 | // On watches, multi-window is used to present essential system UI, and thus it must be |
| 1173 | // supported regardless of device memory characteristics. |
| 1174 | boolean isWatch = context.getPackageManager().hasSystemFeature( |
| 1175 | PackageManager.FEATURE_WATCH); |
| 1176 | return (!isLowRamDeviceStatic() || isWatch) |
Wale Ogunwale | fb1c864 | 2016-03-02 08:28:08 -0800 | [diff] [blame] | 1177 | && Resources.getSystem().getBoolean( |
| 1178 | com.android.internal.R.bool.config_supportsMultiWindow); |
| 1179 | } |
| 1180 | |
| 1181 | /** |
Matthew Ng | 626e0cc | 2016-12-07 17:25:53 -0800 | [diff] [blame] | 1182 | * Returns true if the system supports split screen multi-window. |
| 1183 | * @hide |
| 1184 | */ |
Erik Wolsheimer | 9be3a06 | 2017-05-31 14:59:57 -0700 | [diff] [blame] | 1185 | static public boolean supportsSplitScreenMultiWindow(Context context) { |
| 1186 | return supportsMultiWindow(context) |
Matthew Ng | 626e0cc | 2016-12-07 17:25:53 -0800 | [diff] [blame] | 1187 | && Resources.getSystem().getBoolean( |
| 1188 | com.android.internal.R.bool.config_supportsSplitScreenMultiWindow); |
| 1189 | } |
| 1190 | |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 1191 | /** @removed */ |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 1192 | @Deprecated |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 1193 | public static int getMaxNumPictureInPictureActions() { |
Winson Chung | 709904f | 2017-04-25 11:00:48 -0700 | [diff] [blame] | 1194 | return 3; |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | /** |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 1198 | * Information you can set and retrieve about the current activity within the recent task list. |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1199 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1200 | public static class TaskDescription implements Parcelable { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1201 | /** @hide */ |
| 1202 | public static final String ATTR_TASKDESCRIPTION_PREFIX = "task_description_"; |
| 1203 | private static final String ATTR_TASKDESCRIPTIONLABEL = |
| 1204 | ATTR_TASKDESCRIPTION_PREFIX + "label"; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1205 | private static final String ATTR_TASKDESCRIPTIONCOLOR_PRIMARY = |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1206 | ATTR_TASKDESCRIPTION_PREFIX + "color"; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1207 | private static final String ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND = |
| 1208 | ATTR_TASKDESCRIPTION_PREFIX + "colorBackground"; |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1209 | private static final String ATTR_TASKDESCRIPTIONICONFILENAME = |
| 1210 | ATTR_TASKDESCRIPTION_PREFIX + "icon_filename"; |
| 1211 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1212 | private String mLabel; |
| 1213 | private Bitmap mIcon; |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1214 | private String mIconFilename; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1215 | private int mColorPrimary; |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1216 | private int mColorBackground; |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1217 | private int mStatusBarColor; |
| 1218 | private int mNavigationBarColor; |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1219 | |
| 1220 | /** |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1221 | * Creates the TaskDescription to the specified values. |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1222 | * |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1223 | * @param label A label and description of the current state of this task. |
| 1224 | * @param icon An icon that represents the current state of this task. |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1225 | * @param colorPrimary A color to override the theme's primary color. This color must be |
| 1226 | * opaque. |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1227 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1228 | public TaskDescription(String label, Bitmap icon, int colorPrimary) { |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1229 | this(label, icon, null, colorPrimary, 0, 0, 0); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1230 | if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) { |
| 1231 | throw new RuntimeException("A TaskDescription's primary color should be opaque"); |
| 1232 | } |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1235 | /** |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1236 | * Creates the TaskDescription to the specified values. |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1237 | * |
| 1238 | * @param label A label and description of the current state of this activity. |
| 1239 | * @param icon An icon that represents the current state of this activity. |
| 1240 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1241 | public TaskDescription(String label, Bitmap icon) { |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1242 | this(label, icon, null, 0, 0, 0, 0); |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | /** |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1246 | * Creates the TaskDescription to the specified values. |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1247 | * |
| 1248 | * @param label A label and description of the current state of this activity. |
| 1249 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1250 | public TaskDescription(String label) { |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1251 | this(label, null, null, 0, 0, 0, 0); |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1252 | } |
| 1253 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1254 | /** |
| 1255 | * Creates an empty TaskDescription. |
| 1256 | */ |
| 1257 | public TaskDescription() { |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1258 | this(null, null, null, 0, 0, 0, 0); |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | /** @hide */ |
| 1262 | public TaskDescription(String label, Bitmap icon, String iconFilename, int colorPrimary, |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1263 | int colorBackground, int statusBarColor, int navigationBarColor) { |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1264 | mLabel = label; |
| 1265 | mIcon = icon; |
| 1266 | mIconFilename = iconFilename; |
| 1267 | mColorPrimary = colorPrimary; |
| 1268 | mColorBackground = colorBackground; |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1269 | mStatusBarColor = statusBarColor; |
| 1270 | mNavigationBarColor = navigationBarColor; |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1273 | /** |
| 1274 | * Creates a copy of another TaskDescription. |
| 1275 | */ |
| 1276 | public TaskDescription(TaskDescription td) { |
Winson | b640315 | 2016-02-23 13:32:09 -0800 | [diff] [blame] | 1277 | copyFrom(td); |
| 1278 | } |
| 1279 | |
| 1280 | /** |
| 1281 | * Copies this the values from another TaskDescription. |
| 1282 | * @hide |
| 1283 | */ |
| 1284 | public void copyFrom(TaskDescription other) { |
| 1285 | mLabel = other.mLabel; |
| 1286 | mIcon = other.mIcon; |
| 1287 | mIconFilename = other.mIconFilename; |
| 1288 | mColorPrimary = other.mColorPrimary; |
| 1289 | mColorBackground = other.mColorBackground; |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1290 | mStatusBarColor = other.mStatusBarColor; |
| 1291 | mNavigationBarColor = other.mNavigationBarColor; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
Jorim Jaggi | f4156ea | 2017-04-10 18:39:04 -0700 | [diff] [blame] | 1294 | /** |
| 1295 | * Copies this the values from another TaskDescription, but preserves the hidden fields |
| 1296 | * if they weren't set on {@code other} |
| 1297 | * @hide |
| 1298 | */ |
| 1299 | public void copyFromPreserveHiddenFields(TaskDescription other) { |
| 1300 | mLabel = other.mLabel; |
| 1301 | mIcon = other.mIcon; |
| 1302 | mIconFilename = other.mIconFilename; |
| 1303 | mColorPrimary = other.mColorPrimary; |
| 1304 | if (other.mColorBackground != 0) { |
| 1305 | mColorBackground = other.mColorBackground; |
| 1306 | } |
| 1307 | if (other.mStatusBarColor != 0) { |
| 1308 | mStatusBarColor = other.mStatusBarColor; |
| 1309 | } |
| 1310 | if (other.mNavigationBarColor != 0) { |
| 1311 | mNavigationBarColor = other.mNavigationBarColor; |
| 1312 | } |
| 1313 | } |
| 1314 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1315 | private TaskDescription(Parcel source) { |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1316 | readFromParcel(source); |
| 1317 | } |
| 1318 | |
| 1319 | /** |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 1320 | * Sets the label for this task description. |
| 1321 | * @hide |
| 1322 | */ |
| 1323 | public void setLabel(String label) { |
| 1324 | mLabel = label; |
| 1325 | } |
| 1326 | |
| 1327 | /** |
| 1328 | * Sets the primary color for this task description. |
| 1329 | * @hide |
| 1330 | */ |
| 1331 | public void setPrimaryColor(int primaryColor) { |
Winson Chung | ae12dae | 2014-09-29 14:21:26 -0700 | [diff] [blame] | 1332 | // Ensure that the given color is valid |
| 1333 | if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) { |
| 1334 | throw new RuntimeException("A TaskDescription's primary color should be opaque"); |
| 1335 | } |
| 1336 | mColorPrimary = primaryColor; |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | /** |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1340 | * Sets the background color for this task description. |
| 1341 | * @hide |
| 1342 | */ |
| 1343 | public void setBackgroundColor(int backgroundColor) { |
| 1344 | // Ensure that the given color is valid |
| 1345 | if ((backgroundColor != 0) && (Color.alpha(backgroundColor) != 255)) { |
| 1346 | throw new RuntimeException("A TaskDescription's background color should be opaque"); |
| 1347 | } |
| 1348 | mColorBackground = backgroundColor; |
| 1349 | } |
| 1350 | |
| 1351 | /** |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1352 | * @hide |
| 1353 | */ |
| 1354 | public void setStatusBarColor(int statusBarColor) { |
| 1355 | mStatusBarColor = statusBarColor; |
| 1356 | } |
| 1357 | |
| 1358 | /** |
| 1359 | * @hide |
| 1360 | */ |
| 1361 | public void setNavigationBarColor(int navigationBarColor) { |
| 1362 | mNavigationBarColor = navigationBarColor; |
| 1363 | } |
| 1364 | |
| 1365 | /** |
Winson Chung | 2cb86c7 | 2014-06-25 12:03:30 -0700 | [diff] [blame] | 1366 | * Sets the icon for this task description. |
| 1367 | * @hide |
| 1368 | */ |
| 1369 | public void setIcon(Bitmap icon) { |
| 1370 | mIcon = icon; |
| 1371 | } |
| 1372 | |
| 1373 | /** |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1374 | * Moves the icon bitmap reference from an actual Bitmap to a file containing the |
| 1375 | * bitmap. |
| 1376 | * @hide |
| 1377 | */ |
| 1378 | public void setIconFilename(String iconFilename) { |
| 1379 | mIconFilename = iconFilename; |
| 1380 | mIcon = null; |
| 1381 | } |
| 1382 | |
| 1383 | /** |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1384 | * @return The label and description of the current state of this task. |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1385 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1386 | public String getLabel() { |
| 1387 | return mLabel; |
| 1388 | } |
| 1389 | |
| 1390 | /** |
| 1391 | * @return The icon that represents the current state of this task. |
| 1392 | */ |
| 1393 | public Bitmap getIcon() { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1394 | if (mIcon != null) { |
| 1395 | return mIcon; |
| 1396 | } |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 1397 | return loadTaskDescriptionIcon(mIconFilename, UserHandle.myUserId()); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | /** @hide */ |
| 1401 | public String getIconFilename() { |
| 1402 | return mIconFilename; |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
Jorim Jaggi | bdd4b20 | 2014-09-26 18:29:07 +0200 | [diff] [blame] | 1405 | /** @hide */ |
| 1406 | public Bitmap getInMemoryIcon() { |
| 1407 | return mIcon; |
| 1408 | } |
| 1409 | |
| 1410 | /** @hide */ |
Suprabh Shukla | 2359314 | 2015-11-03 17:31:15 -0800 | [diff] [blame] | 1411 | public static Bitmap loadTaskDescriptionIcon(String iconFilename, int userId) { |
Jorim Jaggi | bdd4b20 | 2014-09-26 18:29:07 +0200 | [diff] [blame] | 1412 | if (iconFilename != null) { |
| 1413 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1414 | return getService().getTaskDescriptionIcon(iconFilename, |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1415 | userId); |
Jorim Jaggi | bdd4b20 | 2014-09-26 18:29:07 +0200 | [diff] [blame] | 1416 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1417 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | bdd4b20 | 2014-09-26 18:29:07 +0200 | [diff] [blame] | 1418 | } |
| 1419 | } |
| 1420 | return null; |
| 1421 | } |
| 1422 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1423 | /** |
| 1424 | * @return The color override on the theme's primary color. |
| 1425 | */ |
| 1426 | public int getPrimaryColor() { |
| 1427 | return mColorPrimary; |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1430 | /** |
| 1431 | * @return The background color. |
| 1432 | * @hide |
| 1433 | */ |
| 1434 | public int getBackgroundColor() { |
| 1435 | return mColorBackground; |
| 1436 | } |
| 1437 | |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1438 | /** |
| 1439 | * @hide |
| 1440 | */ |
| 1441 | public int getStatusBarColor() { |
| 1442 | return mStatusBarColor; |
| 1443 | } |
| 1444 | |
| 1445 | /** |
| 1446 | * @hide |
| 1447 | */ |
| 1448 | public int getNavigationBarColor() { |
| 1449 | return mNavigationBarColor; |
| 1450 | } |
| 1451 | |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1452 | /** @hide */ |
| 1453 | public void saveToXml(XmlSerializer out) throws IOException { |
| 1454 | if (mLabel != null) { |
| 1455 | out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel); |
| 1456 | } |
| 1457 | if (mColorPrimary != 0) { |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1458 | out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_PRIMARY, |
| 1459 | Integer.toHexString(mColorPrimary)); |
| 1460 | } |
| 1461 | if (mColorBackground != 0) { |
| 1462 | out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND, |
| 1463 | Integer.toHexString(mColorBackground)); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1464 | } |
| 1465 | if (mIconFilename != null) { |
| 1466 | out.attribute(null, ATTR_TASKDESCRIPTIONICONFILENAME, mIconFilename); |
| 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | /** @hide */ |
| 1471 | public void restoreFromXml(String attrName, String attrValue) { |
| 1472 | if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) { |
| 1473 | setLabel(attrValue); |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1474 | } else if (ATTR_TASKDESCRIPTIONCOLOR_PRIMARY.equals(attrName)) { |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1475 | setPrimaryColor((int) Long.parseLong(attrValue, 16)); |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1476 | } else if (ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND.equals(attrName)) { |
| 1477 | setBackgroundColor((int) Long.parseLong(attrValue, 16)); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1478 | } else if (ATTR_TASKDESCRIPTIONICONFILENAME.equals(attrName)) { |
| 1479 | setIconFilename(attrValue); |
| 1480 | } |
| 1481 | } |
| 1482 | |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1483 | @Override |
| 1484 | public int describeContents() { |
| 1485 | return 0; |
| 1486 | } |
| 1487 | |
| 1488 | @Override |
| 1489 | public void writeToParcel(Parcel dest, int flags) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1490 | if (mLabel == null) { |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1491 | dest.writeInt(0); |
| 1492 | } else { |
| 1493 | dest.writeInt(1); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1494 | dest.writeString(mLabel); |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1495 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1496 | if (mIcon == null) { |
| 1497 | dest.writeInt(0); |
| 1498 | } else { |
| 1499 | dest.writeInt(1); |
| 1500 | mIcon.writeToParcel(dest, 0); |
| 1501 | } |
| 1502 | dest.writeInt(mColorPrimary); |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1503 | dest.writeInt(mColorBackground); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1504 | dest.writeInt(mStatusBarColor); |
| 1505 | dest.writeInt(mNavigationBarColor); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1506 | if (mIconFilename == null) { |
| 1507 | dest.writeInt(0); |
| 1508 | } else { |
| 1509 | dest.writeInt(1); |
| 1510 | dest.writeString(mIconFilename); |
| 1511 | } |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | public void readFromParcel(Parcel source) { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1515 | mLabel = source.readInt() > 0 ? source.readString() : null; |
| 1516 | mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null; |
| 1517 | mColorPrimary = source.readInt(); |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1518 | mColorBackground = source.readInt(); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1519 | mStatusBarColor = source.readInt(); |
| 1520 | mNavigationBarColor = source.readInt(); |
Craig Mautner | 648f69b | 2014-09-18 14:16:26 -0700 | [diff] [blame] | 1521 | mIconFilename = source.readInt() > 0 ? source.readString() : null; |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1524 | public static final Creator<TaskDescription> CREATOR |
| 1525 | = new Creator<TaskDescription>() { |
| 1526 | public TaskDescription createFromParcel(Parcel source) { |
| 1527 | return new TaskDescription(source); |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1528 | } |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1529 | public TaskDescription[] newArray(int size) { |
| 1530 | return new TaskDescription[size]; |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1531 | } |
| 1532 | }; |
| 1533 | |
| 1534 | @Override |
| 1535 | public String toString() { |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1536 | return "TaskDescription Label: " + mLabel + " Icon: " + mIcon + |
Winson Chung | 1af8eda | 2016-02-05 17:55:56 +0000 | [diff] [blame] | 1537 | " IconFilename: " + mIconFilename + " colorPrimary: " + mColorPrimary + |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 1538 | " colorBackground: " + mColorBackground + |
| 1539 | " statusBarColor: " + mColorBackground + |
| 1540 | " navigationBarColor: " + mNavigationBarColor; |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | * Information you can retrieve about tasks that the user has most recently |
| 1546 | * started or visited. |
| 1547 | */ |
| 1548 | public static class RecentTaskInfo implements Parcelable { |
| 1549 | /** |
| 1550 | * If this task is currently running, this is the identifier for it. |
| 1551 | * If it is not running, this will be -1. |
| 1552 | */ |
| 1553 | public int id; |
| 1554 | |
| 1555 | /** |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 1556 | * The true identifier of this task, valid even if it is not running. |
| 1557 | */ |
| 1558 | public int persistentId; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 1559 | |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 1560 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1561 | * The original Intent used to launch the task. You can use this |
| 1562 | * Intent to re-launch the task (if it is no longer running) or bring |
| 1563 | * the current task to the front. |
| 1564 | */ |
| 1565 | public Intent baseIntent; |
| 1566 | |
| 1567 | /** |
| 1568 | * If this task was started from an alias, this is the actual |
| 1569 | * activity component that was initially started; the component of |
| 1570 | * the baseIntent in this case is the name of the actual activity |
| 1571 | * implementation that the alias referred to. Otherwise, this is null. |
| 1572 | */ |
| 1573 | public ComponentName origActivity; |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 1574 | |
| 1575 | /** |
James Cook | 4d0ef04 | 2015-07-09 14:28:23 -0700 | [diff] [blame] | 1576 | * The actual activity component that started the task. |
| 1577 | * @hide |
| 1578 | */ |
| 1579 | @Nullable |
| 1580 | public ComponentName realActivity; |
| 1581 | |
| 1582 | /** |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 1583 | * Description of the task's last state. |
| 1584 | */ |
| 1585 | public CharSequence description; |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 1586 | |
| 1587 | /** |
| 1588 | * The id of the ActivityStack this Task was on most recently. |
Craig Mautner | 2703052 | 2013-08-26 12:25:36 -0700 | [diff] [blame] | 1589 | * @hide |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 1590 | */ |
| 1591 | public int stackId; |
| 1592 | |
Kenny Guy | 82326a9 | 2014-03-17 17:16:06 +0000 | [diff] [blame] | 1593 | /** |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 1594 | * The id of the user the task was running as. |
Kenny Guy | 82326a9 | 2014-03-17 17:16:06 +0000 | [diff] [blame] | 1595 | * @hide |
| 1596 | */ |
| 1597 | public int userId; |
| 1598 | |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 1599 | /** |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 1600 | * The first time this task was active. |
| 1601 | * @hide |
| 1602 | */ |
| 1603 | public long firstActiveTime; |
| 1604 | |
| 1605 | /** |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 1606 | * The last time this task was active. |
| 1607 | * @hide |
| 1608 | */ |
| 1609 | public long lastActiveTime; |
| 1610 | |
| 1611 | /** |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1612 | * The recent activity values for the highest activity in the stack to have set the values. |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1613 | * {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}. |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 1614 | */ |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1615 | public TaskDescription taskDescription; |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 1616 | |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 1617 | /** |
| 1618 | * Task affiliation for grouping with other tasks. |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 1619 | */ |
| 1620 | public int affiliatedTaskId; |
| 1621 | |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 1622 | /** |
| 1623 | * Task affiliation color of the source task with the affiliated task id. |
| 1624 | * |
| 1625 | * @hide |
| 1626 | */ |
| 1627 | public int affiliatedTaskColor; |
| 1628 | |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 1629 | /** |
| 1630 | * The component launched as the first activity in the task. |
| 1631 | * This can be considered the "application" of this task. |
| 1632 | */ |
| 1633 | public ComponentName baseActivity; |
| 1634 | |
| 1635 | /** |
| 1636 | * The activity component at the top of the history stack of the task. |
| 1637 | * This is what the user is currently doing. |
| 1638 | */ |
| 1639 | public ComponentName topActivity; |
| 1640 | |
| 1641 | /** |
| 1642 | * Number of activities in this task. |
| 1643 | */ |
| 1644 | public int numActivities; |
| 1645 | |
Winson | 2dd7694 | 2015-11-02 09:20:01 -0800 | [diff] [blame] | 1646 | /** |
| 1647 | * The bounds of the task. |
| 1648 | * @hide |
| 1649 | */ |
| 1650 | public Rect bounds; |
| 1651 | |
Wale Ogunwale | 21b6058 | 2016-01-27 12:34:16 -0800 | [diff] [blame] | 1652 | /** |
| 1653 | * True if the task can go in the docked stack. |
| 1654 | * @hide |
| 1655 | */ |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1656 | public boolean supportsSplitScreenMultiWindow; |
Wale Ogunwale | 21b6058 | 2016-01-27 12:34:16 -0800 | [diff] [blame] | 1657 | |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 1658 | /** |
| 1659 | * The resize mode of the task. See {@link ActivityInfo#resizeMode}. |
| 1660 | * @hide |
| 1661 | */ |
| 1662 | public int resizeMode; |
| 1663 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1664 | public RecentTaskInfo() { |
| 1665 | } |
| 1666 | |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 1667 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1668 | public int describeContents() { |
| 1669 | return 0; |
| 1670 | } |
| 1671 | |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 1672 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1673 | public void writeToParcel(Parcel dest, int flags) { |
| 1674 | dest.writeInt(id); |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 1675 | dest.writeInt(persistentId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1676 | if (baseIntent != null) { |
| 1677 | dest.writeInt(1); |
| 1678 | baseIntent.writeToParcel(dest, 0); |
| 1679 | } else { |
| 1680 | dest.writeInt(0); |
| 1681 | } |
| 1682 | ComponentName.writeToParcel(origActivity, dest); |
James Cook | 4d0ef04 | 2015-07-09 14:28:23 -0700 | [diff] [blame] | 1683 | ComponentName.writeToParcel(realActivity, dest); |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 1684 | TextUtils.writeToParcel(description, dest, |
| 1685 | Parcelable.PARCELABLE_WRITE_RETURN_VALUE); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1686 | if (taskDescription != null) { |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 1687 | dest.writeInt(1); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1688 | taskDescription.writeToParcel(dest, 0); |
Winson Chung | 03a9bae | 2014-05-02 09:56:12 -0700 | [diff] [blame] | 1689 | } else { |
| 1690 | dest.writeInt(0); |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 1691 | } |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 1692 | dest.writeInt(stackId); |
Kenny Guy | 82326a9 | 2014-03-17 17:16:06 +0000 | [diff] [blame] | 1693 | dest.writeInt(userId); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 1694 | dest.writeLong(firstActiveTime); |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 1695 | dest.writeLong(lastActiveTime); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 1696 | dest.writeInt(affiliatedTaskId); |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 1697 | dest.writeInt(affiliatedTaskColor); |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 1698 | ComponentName.writeToParcel(baseActivity, dest); |
| 1699 | ComponentName.writeToParcel(topActivity, dest); |
| 1700 | dest.writeInt(numActivities); |
Winson | 2dd7694 | 2015-11-02 09:20:01 -0800 | [diff] [blame] | 1701 | if (bounds != null) { |
| 1702 | dest.writeInt(1); |
| 1703 | bounds.writeToParcel(dest, 0); |
| 1704 | } else { |
| 1705 | dest.writeInt(0); |
| 1706 | } |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1707 | dest.writeInt(supportsSplitScreenMultiWindow ? 1 : 0); |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 1708 | dest.writeInt(resizeMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | public void readFromParcel(Parcel source) { |
| 1712 | id = source.readInt(); |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 1713 | persistentId = source.readInt(); |
Craig Mautner | 688b510 | 2014-03-27 16:55:03 -0700 | [diff] [blame] | 1714 | baseIntent = source.readInt() > 0 ? Intent.CREATOR.createFromParcel(source) : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1715 | origActivity = ComponentName.readFromParcel(source); |
James Cook | 4d0ef04 | 2015-07-09 14:28:23 -0700 | [diff] [blame] | 1716 | realActivity = ComponentName.readFromParcel(source); |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 1717 | description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
Winson Chung | a449dc0 | 2014-05-16 11:15:04 -0700 | [diff] [blame] | 1718 | taskDescription = source.readInt() > 0 ? |
| 1719 | TaskDescription.CREATOR.createFromParcel(source) : null; |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 1720 | stackId = source.readInt(); |
Kenny Guy | 82326a9 | 2014-03-17 17:16:06 +0000 | [diff] [blame] | 1721 | userId = source.readInt(); |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 1722 | firstActiveTime = source.readLong(); |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 1723 | lastActiveTime = source.readLong(); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 1724 | affiliatedTaskId = source.readInt(); |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 1725 | affiliatedTaskColor = source.readInt(); |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 1726 | baseActivity = ComponentName.readFromParcel(source); |
| 1727 | topActivity = ComponentName.readFromParcel(source); |
| 1728 | numActivities = source.readInt(); |
Winson | 2dd7694 | 2015-11-02 09:20:01 -0800 | [diff] [blame] | 1729 | bounds = source.readInt() > 0 ? |
| 1730 | Rect.CREATOR.createFromParcel(source) : null; |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1731 | supportsSplitScreenMultiWindow = source.readInt() == 1; |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 1732 | resizeMode = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1733 | } |
Craig Mautner | 6d90fed | 2013-05-22 15:03:10 -0700 | [diff] [blame] | 1734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1735 | public static final Creator<RecentTaskInfo> CREATOR |
| 1736 | = new Creator<RecentTaskInfo>() { |
| 1737 | public RecentTaskInfo createFromParcel(Parcel source) { |
| 1738 | return new RecentTaskInfo(source); |
| 1739 | } |
| 1740 | public RecentTaskInfo[] newArray(int size) { |
| 1741 | return new RecentTaskInfo[size]; |
| 1742 | } |
| 1743 | }; |
| 1744 | |
| 1745 | private RecentTaskInfo(Parcel source) { |
| 1746 | readFromParcel(source); |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | /** |
| 1751 | * Flag for use with {@link #getRecentTasks}: return all tasks, even those |
| 1752 | * that have set their |
| 1753 | * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag. |
| 1754 | */ |
| 1755 | public static final int RECENT_WITH_EXCLUDED = 0x0001; |
Kenny Guy | 82326a9 | 2014-03-17 17:16:06 +0000 | [diff] [blame] | 1756 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1757 | /** |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 1758 | * Provides a list that does not contain any |
Dianne Hackborn | 53d9264d | 2010-04-13 12:49:14 -0700 | [diff] [blame] | 1759 | * recent tasks that currently are not available to the user. |
| 1760 | */ |
| 1761 | public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002; |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 1762 | |
| 1763 | /** |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1764 | * Provides a list that contains recent tasks for all |
| 1765 | * profiles of a user. |
Kenny Guy | 82326a9 | 2014-03-17 17:16:06 +0000 | [diff] [blame] | 1766 | * @hide |
| 1767 | */ |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1768 | public static final int RECENT_INCLUDE_PROFILES = 0x0004; |
Kenny Guy | 82326a9 | 2014-03-17 17:16:06 +0000 | [diff] [blame] | 1769 | |
| 1770 | /** |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1771 | * Ignores all tasks that are on the home stack. |
| 1772 | * @hide |
| 1773 | */ |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 1774 | public static final int RECENT_IGNORE_HOME_AND_RECENTS_STACK_TASKS = 0x0008; |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1775 | |
| 1776 | /** |
Wale Ogunwale | 64ae08a | 2016-03-28 08:15:27 -0700 | [diff] [blame] | 1777 | * Ignores the top task in the docked stack. |
Winson Chung | 0583d3d | 2015-12-18 10:03:12 -0500 | [diff] [blame] | 1778 | * @hide |
| 1779 | */ |
Wale Ogunwale | 64ae08a | 2016-03-28 08:15:27 -0700 | [diff] [blame] | 1780 | public static final int RECENT_INGORE_DOCKED_STACK_TOP_TASK = 0x0010; |
Winson Chung | 0583d3d | 2015-12-18 10:03:12 -0500 | [diff] [blame] | 1781 | |
| 1782 | /** |
| 1783 | * Ignores all tasks that are on the pinned stack. |
| 1784 | * @hide |
| 1785 | */ |
| 1786 | public static final int RECENT_INGORE_PINNED_STACK_TASKS = 0x0020; |
| 1787 | |
| 1788 | /** |
Dianne Hackborn | a25a8b2 | 2014-05-30 12:30:35 -0700 | [diff] [blame] | 1789 | * <p></p>Return a list of the tasks that the user has recently launched, with |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1790 | * the most recent being first and older ones after in order. |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 1791 | * |
| 1792 | * <p><b>Note: this method is only intended for debugging and presenting |
| 1793 | * task management user interfaces</b>. This should never be used for |
| 1794 | * core logic in an application, such as deciding between different |
| 1795 | * behaviors based on the information found here. Such uses are |
| 1796 | * <em>not</em> supported, and will likely break in the future. For |
| 1797 | * example, if multiple applications can be actively running at the |
| 1798 | * same time, assumptions made about the meaning of the data here for |
| 1799 | * purposes of control flow will be incorrect.</p> |
| 1800 | * |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 1801 | * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method is |
Dianne Hackborn | 2d7576b | 2014-10-03 16:26:04 -0700 | [diff] [blame] | 1802 | * no longer available to third party applications: the introduction of |
Dianne Hackborn | a25a8b2 | 2014-05-30 12:30:35 -0700 | [diff] [blame] | 1803 | * document-centric recents means |
| 1804 | * it can leak personal information to the caller. For backwards compatibility, |
| 1805 | * it will still return a small subset of its data: at least the caller's |
| 1806 | * own tasks (though see {@link #getAppTasks()} for the correct supported |
| 1807 | * way to retrieve that information), and possibly some other tasks |
| 1808 | * such as home that are known to not be sensitive. |
| 1809 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1810 | * @param maxNum The maximum number of entries to return in the list. The |
| 1811 | * actual number returned may be smaller, depending on how many tasks the |
| 1812 | * user has started and the maximum number the system can remember. |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 1813 | * @param flags Information about what to return. May be any combination |
Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 1814 | * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}. |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 1815 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1816 | * @return Returns a list of RecentTaskInfo records describing each of |
| 1817 | * the recent tasks. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1818 | */ |
Dianne Hackborn | a25a8b2 | 2014-05-30 12:30:35 -0700 | [diff] [blame] | 1819 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1820 | public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags) |
| 1821 | throws SecurityException { |
| 1822 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1823 | return getService().getRecentTasks(maxNum, |
Jeff Sharkey | 479212c | 2016-06-29 16:00:55 -0600 | [diff] [blame] | 1824 | flags, UserHandle.myUserId()).getList(); |
Amith Yamasani | 8264408 | 2012-08-03 13:09:11 -0700 | [diff] [blame] | 1825 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1826 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 8264408 | 2012-08-03 13:09:11 -0700 | [diff] [blame] | 1827 | } |
| 1828 | } |
| 1829 | |
| 1830 | /** |
| 1831 | * Same as {@link #getRecentTasks(int, int)} but returns the recent tasks for a |
| 1832 | * specific user. It requires holding |
| 1833 | * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission. |
| 1834 | * @param maxNum The maximum number of entries to return in the list. The |
| 1835 | * actual number returned may be smaller, depending on how many tasks the |
| 1836 | * user has started and the maximum number the system can remember. |
| 1837 | * @param flags Information about what to return. May be any combination |
| 1838 | * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}. |
| 1839 | * |
| 1840 | * @return Returns a list of RecentTaskInfo records describing each of |
Vadim Tryshev | 3560575 | 2015-08-31 13:28:08 -0700 | [diff] [blame] | 1841 | * the recent tasks. Most recently activated tasks go first. |
Amith Yamasani | 8264408 | 2012-08-03 13:09:11 -0700 | [diff] [blame] | 1842 | * |
Amith Yamasani | 8264408 | 2012-08-03 13:09:11 -0700 | [diff] [blame] | 1843 | * @hide |
| 1844 | */ |
| 1845 | public List<RecentTaskInfo> getRecentTasksForUser(int maxNum, int flags, int userId) |
| 1846 | throws SecurityException { |
| 1847 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1848 | return getService().getRecentTasks(maxNum, |
Jeff Sharkey | 479212c | 2016-06-29 16:00:55 -0600 | [diff] [blame] | 1849 | flags, userId).getList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1850 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1851 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | /** |
| 1856 | * Information you can retrieve about a particular task that is currently |
| 1857 | * "running" in the system. Note that a running task does not mean the |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 1858 | * given task actually has a process it is actively running in; it simply |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1859 | * means that the user has gone to it and never closed it, but currently |
| 1860 | * the system may have killed its process and is only holding on to its |
| 1861 | * last state in order to restart it when the user returns. |
| 1862 | */ |
| 1863 | public static class RunningTaskInfo implements Parcelable { |
| 1864 | /** |
| 1865 | * A unique identifier for this task. |
| 1866 | */ |
| 1867 | public int id; |
| 1868 | |
| 1869 | /** |
Winson | 5510f6c | 2015-10-27 12:11:26 -0700 | [diff] [blame] | 1870 | * The stack that currently contains this task. |
| 1871 | * @hide |
| 1872 | */ |
| 1873 | public int stackId; |
| 1874 | |
| 1875 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1876 | * The component launched as the first activity in the task. This can |
| 1877 | * be considered the "application" of this task. |
| 1878 | */ |
| 1879 | public ComponentName baseActivity; |
| 1880 | |
| 1881 | /** |
| 1882 | * The activity component at the top of the history stack of the task. |
| 1883 | * This is what the user is currently doing. |
| 1884 | */ |
| 1885 | public ComponentName topActivity; |
| 1886 | |
| 1887 | /** |
Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 1888 | * Thumbnail representation of the task's current state. Currently |
| 1889 | * always null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1890 | */ |
| 1891 | public Bitmap thumbnail; |
| 1892 | |
| 1893 | /** |
| 1894 | * Description of the task's current state. |
| 1895 | */ |
| 1896 | public CharSequence description; |
| 1897 | |
| 1898 | /** |
| 1899 | * Number of activities in this task. |
| 1900 | */ |
| 1901 | public int numActivities; |
| 1902 | |
| 1903 | /** |
| 1904 | * Number of activities that are currently running (not stopped |
| 1905 | * and persisted) in this task. |
| 1906 | */ |
| 1907 | public int numRunning; |
| 1908 | |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 1909 | /** |
| 1910 | * Last time task was run. For sorting. |
| 1911 | * @hide |
| 1912 | */ |
| 1913 | public long lastActiveTime; |
| 1914 | |
Wale Ogunwale | 21b6058 | 2016-01-27 12:34:16 -0800 | [diff] [blame] | 1915 | /** |
| 1916 | * True if the task can go in the docked stack. |
| 1917 | * @hide |
| 1918 | */ |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1919 | public boolean supportsSplitScreenMultiWindow; |
Wale Ogunwale | 21b6058 | 2016-01-27 12:34:16 -0800 | [diff] [blame] | 1920 | |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 1921 | /** |
| 1922 | * The resize mode of the task. See {@link ActivityInfo#resizeMode}. |
| 1923 | * @hide |
| 1924 | */ |
| 1925 | public int resizeMode; |
| 1926 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1927 | public RunningTaskInfo() { |
| 1928 | } |
| 1929 | |
| 1930 | public int describeContents() { |
| 1931 | return 0; |
| 1932 | } |
| 1933 | |
| 1934 | public void writeToParcel(Parcel dest, int flags) { |
| 1935 | dest.writeInt(id); |
Winson | 5510f6c | 2015-10-27 12:11:26 -0700 | [diff] [blame] | 1936 | dest.writeInt(stackId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1937 | ComponentName.writeToParcel(baseActivity, dest); |
| 1938 | ComponentName.writeToParcel(topActivity, dest); |
| 1939 | if (thumbnail != null) { |
| 1940 | dest.writeInt(1); |
| 1941 | thumbnail.writeToParcel(dest, 0); |
| 1942 | } else { |
| 1943 | dest.writeInt(0); |
| 1944 | } |
| 1945 | TextUtils.writeToParcel(description, dest, |
| 1946 | Parcelable.PARCELABLE_WRITE_RETURN_VALUE); |
| 1947 | dest.writeInt(numActivities); |
| 1948 | dest.writeInt(numRunning); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1949 | dest.writeInt(supportsSplitScreenMultiWindow ? 1 : 0); |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 1950 | dest.writeInt(resizeMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | public void readFromParcel(Parcel source) { |
| 1954 | id = source.readInt(); |
Winson | 5510f6c | 2015-10-27 12:11:26 -0700 | [diff] [blame] | 1955 | stackId = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1956 | baseActivity = ComponentName.readFromParcel(source); |
| 1957 | topActivity = ComponentName.readFromParcel(source); |
| 1958 | if (source.readInt() != 0) { |
| 1959 | thumbnail = Bitmap.CREATOR.createFromParcel(source); |
| 1960 | } else { |
| 1961 | thumbnail = null; |
| 1962 | } |
| 1963 | description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 1964 | numActivities = source.readInt(); |
| 1965 | numRunning = source.readInt(); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 1966 | supportsSplitScreenMultiWindow = source.readInt() != 0; |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 1967 | resizeMode = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1968 | } |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 1969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1970 | public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() { |
| 1971 | public RunningTaskInfo createFromParcel(Parcel source) { |
| 1972 | return new RunningTaskInfo(source); |
| 1973 | } |
| 1974 | public RunningTaskInfo[] newArray(int size) { |
| 1975 | return new RunningTaskInfo[size]; |
| 1976 | } |
| 1977 | }; |
| 1978 | |
| 1979 | private RunningTaskInfo(Parcel source) { |
| 1980 | readFromParcel(source); |
| 1981 | } |
| 1982 | } |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 1983 | |
| 1984 | /** |
| 1985 | * Get the list of tasks associated with the calling application. |
| 1986 | * |
| 1987 | * @return The list of tasks associated with the application making this call. |
| 1988 | * @throws SecurityException |
| 1989 | */ |
| 1990 | public List<ActivityManager.AppTask> getAppTasks() { |
| 1991 | ArrayList<AppTask> tasks = new ArrayList<AppTask>(); |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 1992 | List<IBinder> appTasks; |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 1993 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1994 | appTasks = getService().getAppTasks(mContext.getPackageName()); |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 1995 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1996 | throw e.rethrowFromSystemServer(); |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 1997 | } |
| 1998 | int numAppTasks = appTasks.size(); |
| 1999 | for (int i = 0; i < numAppTasks; i++) { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 2000 | tasks.add(new AppTask(IAppTask.Stub.asInterface(appTasks.get(i)))); |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 2001 | } |
| 2002 | return tasks; |
| 2003 | } |
| 2004 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2005 | /** |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 2006 | * Return the current design dimensions for {@link AppTask} thumbnails, for use |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2007 | * with {@link #addAppTask}. |
| 2008 | */ |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 2009 | public Size getAppTaskThumbnailSize() { |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2010 | synchronized (this) { |
| 2011 | ensureAppTaskThumbnailSizeLocked(); |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 2012 | return new Size(mAppTaskThumbnailSize.x, mAppTaskThumbnailSize.y); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | private void ensureAppTaskThumbnailSizeLocked() { |
| 2017 | if (mAppTaskThumbnailSize == null) { |
| 2018 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2019 | mAppTaskThumbnailSize = getService().getAppTaskThumbnailSize(); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2020 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2021 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2022 | } |
| 2023 | } |
| 2024 | } |
| 2025 | |
| 2026 | /** |
| 2027 | * Add a new {@link AppTask} for the calling application. This will create a new |
| 2028 | * recents entry that is added to the <b>end</b> of all existing recents. |
| 2029 | * |
| 2030 | * @param activity The activity that is adding the entry. This is used to help determine |
| 2031 | * the context that the new recents entry will be in. |
| 2032 | * @param intent The Intent that describes the recents entry. This is the same Intent that |
| 2033 | * you would have used to launch the activity for it. In generally you will want to set |
| 2034 | * both {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} and |
| 2035 | * {@link Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}; the latter is required since this recents |
| 2036 | * entry will exist without an activity, so it doesn't make sense to not retain it when |
| 2037 | * its activity disappears. The given Intent here also must have an explicit ComponentName |
| 2038 | * set on it. |
| 2039 | * @param description Optional additional description information. |
| 2040 | * @param thumbnail Thumbnail to use for the recents entry. Should be the size given by |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 2041 | * {@link #getAppTaskThumbnailSize()}. If the bitmap is not that exact size, it will be |
| 2042 | * recreated in your process, probably in a way you don't like, before the recents entry |
| 2043 | * is added. |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2044 | * |
| 2045 | * @return Returns the task id of the newly added app task, or -1 if the add failed. The |
| 2046 | * most likely cause of failure is that there is no more room for more tasks for your app. |
| 2047 | */ |
| 2048 | public int addAppTask(@NonNull Activity activity, @NonNull Intent intent, |
| 2049 | @Nullable TaskDescription description, @NonNull Bitmap thumbnail) { |
| 2050 | Point size; |
| 2051 | synchronized (this) { |
| 2052 | ensureAppTaskThumbnailSizeLocked(); |
| 2053 | size = mAppTaskThumbnailSize; |
| 2054 | } |
| 2055 | final int tw = thumbnail.getWidth(); |
| 2056 | final int th = thumbnail.getHeight(); |
| 2057 | if (tw != size.x || th != size.y) { |
| 2058 | Bitmap bm = Bitmap.createBitmap(size.x, size.y, thumbnail.getConfig()); |
| 2059 | |
| 2060 | // Use ScaleType.CENTER_CROP, except we leave the top edge at the top. |
| 2061 | float scale; |
| 2062 | float dx = 0, dy = 0; |
| 2063 | if (tw * size.x > size.y * th) { |
| 2064 | scale = (float) size.x / (float) th; |
| 2065 | dx = (size.y - tw * scale) * 0.5f; |
| 2066 | } else { |
| 2067 | scale = (float) size.y / (float) tw; |
| 2068 | dy = (size.x - th * scale) * 0.5f; |
| 2069 | } |
| 2070 | Matrix matrix = new Matrix(); |
| 2071 | matrix.setScale(scale, scale); |
| 2072 | matrix.postTranslate((int) (dx + 0.5f), 0); |
| 2073 | |
| 2074 | Canvas canvas = new Canvas(bm); |
| 2075 | canvas.drawBitmap(thumbnail, matrix, null); |
| 2076 | canvas.setBitmap(null); |
| 2077 | |
| 2078 | thumbnail = bm; |
| 2079 | } |
| 2080 | if (description == null) { |
| 2081 | description = new TaskDescription(); |
| 2082 | } |
| 2083 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2084 | return getService().addAppTask(activity.getActivityToken(), |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2085 | intent, description, thumbnail); |
| 2086 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2087 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 2088 | } |
| 2089 | } |
| 2090 | |
| 2091 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2092 | * Return a list of the tasks that are currently running, with |
| 2093 | * the most recent being first and older ones after in order. Note that |
| 2094 | * "running" does not mean any of the task's code is currently loaded or |
| 2095 | * activity -- the task may have been frozen by the system, so that it |
| 2096 | * can be restarted in its previous state when next brought to the |
| 2097 | * foreground. |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 2098 | * |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 2099 | * <p><b>Note: this method is only intended for debugging and presenting |
| 2100 | * task management user interfaces</b>. This should never be used for |
| 2101 | * core logic in an application, such as deciding between different |
| 2102 | * behaviors based on the information found here. Such uses are |
| 2103 | * <em>not</em> supported, and will likely break in the future. For |
| 2104 | * example, if multiple applications can be actively running at the |
| 2105 | * same time, assumptions made about the meaning of the data here for |
| 2106 | * purposes of control flow will be incorrect.</p> |
| 2107 | * |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 2108 | * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method |
Dianne Hackborn | a25a8b2 | 2014-05-30 12:30:35 -0700 | [diff] [blame] | 2109 | * is no longer available to third party |
| 2110 | * applications: the introduction of document-centric recents means |
| 2111 | * it can leak person information to the caller. For backwards compatibility, |
Jonathan Dormody | 3571939 | 2017-11-09 16:53:14 -0700 | [diff] [blame] | 2112 | * it will still return a small subset of its data: at least the caller's |
Dianne Hackborn | a25a8b2 | 2014-05-30 12:30:35 -0700 | [diff] [blame] | 2113 | * own tasks, and possibly some other tasks |
| 2114 | * such as home that are known to not be sensitive. |
| 2115 | * |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 2116 | * @param maxNum The maximum number of entries to return in the list. The |
| 2117 | * actual number returned may be smaller, depending on how many tasks the |
| 2118 | * user has started. |
| 2119 | * |
| 2120 | * @return Returns a list of RunningTaskInfo records describing each of |
| 2121 | * the running tasks. |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 2122 | */ |
Dianne Hackborn | a25a8b2 | 2014-05-30 12:30:35 -0700 | [diff] [blame] | 2123 | @Deprecated |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 2124 | public List<RunningTaskInfo> getRunningTasks(int maxNum) |
| 2125 | throws SecurityException { |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 2126 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2127 | return getService().getTasks(maxNum, 0); |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 2128 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2129 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 2130 | } |
Jim Miller | 0b2a6d0 | 2010-07-13 18:01:29 -0700 | [diff] [blame] | 2131 | } |
| 2132 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 2133 | /** |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 2134 | * Completely remove the given task. |
| 2135 | * |
| 2136 | * @param taskId Identifier of the task to be removed. |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 2137 | * @return Returns true if the given task was found and removed. |
| 2138 | * |
| 2139 | * @hide |
| 2140 | */ |
Wale Ogunwale | d54b578 | 2014-10-23 15:55:23 -0700 | [diff] [blame] | 2141 | public boolean removeTask(int taskId) throws SecurityException { |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 2142 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2143 | return getService().removeTask(taskId); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 2144 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2145 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 2146 | } |
| 2147 | } |
| 2148 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 2149 | /** |
| 2150 | * Metadata related to the {@link TaskThumbnail}. |
| 2151 | * |
| 2152 | * @hide |
| 2153 | */ |
| 2154 | public static class TaskThumbnailInfo implements Parcelable { |
| 2155 | /** @hide */ |
| 2156 | public static final String ATTR_TASK_THUMBNAILINFO_PREFIX = "task_thumbnailinfo_"; |
| 2157 | private static final String ATTR_TASK_WIDTH = |
| 2158 | ATTR_TASK_THUMBNAILINFO_PREFIX + "task_width"; |
| 2159 | private static final String ATTR_TASK_HEIGHT = |
| 2160 | ATTR_TASK_THUMBNAILINFO_PREFIX + "task_height"; |
| 2161 | private static final String ATTR_SCREEN_ORIENTATION = |
| 2162 | ATTR_TASK_THUMBNAILINFO_PREFIX + "screen_orientation"; |
| 2163 | |
| 2164 | public int taskWidth; |
| 2165 | public int taskHeight; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 2166 | public int screenOrientation = Configuration.ORIENTATION_UNDEFINED; |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 2167 | |
| 2168 | public TaskThumbnailInfo() { |
| 2169 | // Do nothing |
| 2170 | } |
| 2171 | |
| 2172 | private TaskThumbnailInfo(Parcel source) { |
| 2173 | readFromParcel(source); |
| 2174 | } |
| 2175 | |
Winson | c6a2da0 | 2015-11-11 18:11:59 -0800 | [diff] [blame] | 2176 | /** |
| 2177 | * Resets this info state to the initial state. |
| 2178 | * @hide |
| 2179 | */ |
| 2180 | public void reset() { |
| 2181 | taskWidth = 0; |
| 2182 | taskHeight = 0; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 2183 | screenOrientation = Configuration.ORIENTATION_UNDEFINED; |
| 2184 | } |
| 2185 | |
| 2186 | /** |
| 2187 | * Copies from another ThumbnailInfo. |
| 2188 | */ |
| 2189 | public void copyFrom(TaskThumbnailInfo o) { |
| 2190 | taskWidth = o.taskWidth; |
| 2191 | taskHeight = o.taskHeight; |
| 2192 | screenOrientation = o.screenOrientation; |
Winson | c6a2da0 | 2015-11-11 18:11:59 -0800 | [diff] [blame] | 2193 | } |
| 2194 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 2195 | /** @hide */ |
| 2196 | public void saveToXml(XmlSerializer out) throws IOException { |
| 2197 | out.attribute(null, ATTR_TASK_WIDTH, Integer.toString(taskWidth)); |
| 2198 | out.attribute(null, ATTR_TASK_HEIGHT, Integer.toString(taskHeight)); |
| 2199 | out.attribute(null, ATTR_SCREEN_ORIENTATION, Integer.toString(screenOrientation)); |
| 2200 | } |
| 2201 | |
| 2202 | /** @hide */ |
| 2203 | public void restoreFromXml(String attrName, String attrValue) { |
| 2204 | if (ATTR_TASK_WIDTH.equals(attrName)) { |
| 2205 | taskWidth = Integer.parseInt(attrValue); |
| 2206 | } else if (ATTR_TASK_HEIGHT.equals(attrName)) { |
| 2207 | taskHeight = Integer.parseInt(attrValue); |
| 2208 | } else if (ATTR_SCREEN_ORIENTATION.equals(attrName)) { |
| 2209 | screenOrientation = Integer.parseInt(attrValue); |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | public int describeContents() { |
| 2214 | return 0; |
| 2215 | } |
| 2216 | |
| 2217 | public void writeToParcel(Parcel dest, int flags) { |
| 2218 | dest.writeInt(taskWidth); |
| 2219 | dest.writeInt(taskHeight); |
| 2220 | dest.writeInt(screenOrientation); |
| 2221 | } |
| 2222 | |
| 2223 | public void readFromParcel(Parcel source) { |
| 2224 | taskWidth = source.readInt(); |
| 2225 | taskHeight = source.readInt(); |
| 2226 | screenOrientation = source.readInt(); |
| 2227 | } |
| 2228 | |
| 2229 | public static final Creator<TaskThumbnailInfo> CREATOR = new Creator<TaskThumbnailInfo>() { |
| 2230 | public TaskThumbnailInfo createFromParcel(Parcel source) { |
| 2231 | return new TaskThumbnailInfo(source); |
| 2232 | } |
| 2233 | public TaskThumbnailInfo[] newArray(int size) { |
| 2234 | return new TaskThumbnailInfo[size]; |
| 2235 | } |
| 2236 | }; |
| 2237 | } |
| 2238 | |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 2239 | /** @hide */ |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 2240 | public static class TaskThumbnail implements Parcelable { |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2241 | public Bitmap mainThumbnail; |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 2242 | public ParcelFileDescriptor thumbnailFileDescriptor; |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 2243 | public TaskThumbnailInfo thumbnailInfo; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2244 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 2245 | public TaskThumbnail() { |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2246 | } |
| 2247 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 2248 | private TaskThumbnail(Parcel source) { |
| 2249 | readFromParcel(source); |
| 2250 | } |
| 2251 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2252 | public int describeContents() { |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 2253 | if (thumbnailFileDescriptor != null) { |
| 2254 | return thumbnailFileDescriptor.describeContents(); |
| 2255 | } |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2256 | return 0; |
| 2257 | } |
| 2258 | |
| 2259 | public void writeToParcel(Parcel dest, int flags) { |
| 2260 | if (mainThumbnail != null) { |
| 2261 | dest.writeInt(1); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 2262 | mainThumbnail.writeToParcel(dest, flags); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2263 | } else { |
| 2264 | dest.writeInt(0); |
| 2265 | } |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 2266 | if (thumbnailFileDescriptor != null) { |
| 2267 | dest.writeInt(1); |
Dianne Hackborn | 852975d | 2014-08-22 17:42:43 -0700 | [diff] [blame] | 2268 | thumbnailFileDescriptor.writeToParcel(dest, flags); |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 2269 | } else { |
| 2270 | dest.writeInt(0); |
| 2271 | } |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 2272 | if (thumbnailInfo != null) { |
| 2273 | dest.writeInt(1); |
| 2274 | thumbnailInfo.writeToParcel(dest, flags); |
| 2275 | } else { |
| 2276 | dest.writeInt(0); |
| 2277 | } |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | public void readFromParcel(Parcel source) { |
| 2281 | if (source.readInt() != 0) { |
| 2282 | mainThumbnail = Bitmap.CREATOR.createFromParcel(source); |
| 2283 | } else { |
| 2284 | mainThumbnail = null; |
| 2285 | } |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 2286 | if (source.readInt() != 0) { |
| 2287 | thumbnailFileDescriptor = ParcelFileDescriptor.CREATOR.createFromParcel(source); |
| 2288 | } else { |
| 2289 | thumbnailFileDescriptor = null; |
| 2290 | } |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 2291 | if (source.readInt() != 0) { |
| 2292 | thumbnailInfo = TaskThumbnailInfo.CREATOR.createFromParcel(source); |
| 2293 | } else { |
| 2294 | thumbnailInfo = null; |
| 2295 | } |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2296 | } |
| 2297 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 2298 | public static final Creator<TaskThumbnail> CREATOR = new Creator<TaskThumbnail>() { |
| 2299 | public TaskThumbnail createFromParcel(Parcel source) { |
| 2300 | return new TaskThumbnail(source); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2301 | } |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 2302 | public TaskThumbnail[] newArray(int size) { |
| 2303 | return new TaskThumbnail[size]; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2304 | } |
| 2305 | }; |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 2308 | /** |
| 2309 | * Represents a task snapshot. |
| 2310 | * @hide |
| 2311 | */ |
| 2312 | public static class TaskSnapshot implements Parcelable { |
| 2313 | |
| 2314 | private final GraphicBuffer mSnapshot; |
| 2315 | private final int mOrientation; |
| 2316 | private final Rect mContentInsets; |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 2317 | private final boolean mReducedResolution; |
| 2318 | private final float mScale; |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 2319 | |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 2320 | public TaskSnapshot(GraphicBuffer snapshot, int orientation, Rect contentInsets, |
| 2321 | boolean reducedResolution, float scale) { |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 2322 | mSnapshot = snapshot; |
| 2323 | mOrientation = orientation; |
| 2324 | mContentInsets = new Rect(contentInsets); |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 2325 | mReducedResolution = reducedResolution; |
| 2326 | mScale = scale; |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | private TaskSnapshot(Parcel source) { |
| 2330 | mSnapshot = source.readParcelable(null /* classLoader */); |
| 2331 | mOrientation = source.readInt(); |
| 2332 | mContentInsets = source.readParcelable(null /* classLoader */); |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 2333 | mReducedResolution = source.readBoolean(); |
| 2334 | mScale = source.readFloat(); |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 2335 | } |
| 2336 | |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 2337 | /** |
| 2338 | * @return The graphic buffer representing the screenshot. |
| 2339 | */ |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 2340 | public GraphicBuffer getSnapshot() { |
| 2341 | return mSnapshot; |
| 2342 | } |
| 2343 | |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 2344 | /** |
| 2345 | * @return The screen orientation the screenshot was taken in. |
| 2346 | */ |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 2347 | public int getOrientation() { |
| 2348 | return mOrientation; |
| 2349 | } |
| 2350 | |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 2351 | /** |
| 2352 | * @return The system/content insets on the snapshot. These can be clipped off in order to |
| 2353 | * remove any areas behind system bars in the snapshot. |
| 2354 | */ |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 2355 | public Rect getContentInsets() { |
| 2356 | return mContentInsets; |
| 2357 | } |
| 2358 | |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 2359 | /** |
| 2360 | * @return Whether this snapshot is a down-sampled version of the full resolution. |
| 2361 | */ |
| 2362 | public boolean isReducedResolution() { |
| 2363 | return mReducedResolution; |
| 2364 | } |
| 2365 | |
| 2366 | /** |
| 2367 | * @return The scale this snapshot was taken in. |
| 2368 | */ |
| 2369 | public float getScale() { |
| 2370 | return mScale; |
| 2371 | } |
| 2372 | |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 2373 | @Override |
| 2374 | public int describeContents() { |
| 2375 | return 0; |
| 2376 | } |
| 2377 | |
| 2378 | @Override |
| 2379 | public void writeToParcel(Parcel dest, int flags) { |
| 2380 | dest.writeParcelable(mSnapshot, 0); |
| 2381 | dest.writeInt(mOrientation); |
| 2382 | dest.writeParcelable(mContentInsets, 0); |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 2383 | dest.writeBoolean(mReducedResolution); |
| 2384 | dest.writeFloat(mScale); |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 2385 | } |
| 2386 | |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 2387 | @Override |
| 2388 | public String toString() { |
| 2389 | return "TaskSnapshot{mSnapshot=" + mSnapshot + " mOrientation=" + mOrientation |
Jorim Jaggi | 35e3f53 | 2017-03-17 17:06:50 +0100 | [diff] [blame] | 2390 | + " mContentInsets=" + mContentInsets.toShortString() |
| 2391 | + " mReducedResolution=" + mReducedResolution + " mScale=" + mScale; |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 2392 | } |
| 2393 | |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 2394 | public static final Creator<TaskSnapshot> CREATOR = new Creator<TaskSnapshot>() { |
| 2395 | public TaskSnapshot createFromParcel(Parcel source) { |
| 2396 | return new TaskSnapshot(source); |
| 2397 | } |
| 2398 | public TaskSnapshot[] newArray(int size) { |
| 2399 | return new TaskSnapshot[size]; |
| 2400 | } |
| 2401 | }; |
| 2402 | } |
| 2403 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2404 | /** @hide */ |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 2405 | public TaskThumbnail getTaskThumbnail(int id) throws SecurityException { |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 2406 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2407 | return getService().getTaskThumbnail(id); |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 2408 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2409 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 2410 | } |
| 2411 | } |
| 2412 | |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 2413 | /** @hide */ |
| 2414 | @IntDef(flag = true, prefix = { "MOVE_TASK_" }, value = { |
| 2415 | MOVE_TASK_WITH_HOME, |
| 2416 | MOVE_TASK_NO_USER_ACTION, |
| 2417 | }) |
| 2418 | @Retention(RetentionPolicy.SOURCE) |
| 2419 | public @interface MoveTaskFlags {} |
| 2420 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2421 | /** |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 2422 | * Flag for {@link #moveTaskToFront(int, int)}: also move the "home" |
| 2423 | * activity along with the task, so it is positioned immediately behind |
| 2424 | * the task. |
| 2425 | */ |
| 2426 | public static final int MOVE_TASK_WITH_HOME = 0x00000001; |
| 2427 | |
| 2428 | /** |
Dianne Hackborn | d94df45 | 2011-02-16 18:53:31 -0800 | [diff] [blame] | 2429 | * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a |
| 2430 | * user-instigated action, so the current activity will not receive a |
| 2431 | * hint that the user is leaving. |
| 2432 | */ |
| 2433 | public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002; |
| 2434 | |
| 2435 | /** |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2436 | * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)} |
| 2437 | * with a null options argument. |
| 2438 | * |
| 2439 | * @param taskId The identifier of the task to be moved, as found in |
| 2440 | * {@link RunningTaskInfo} or {@link RecentTaskInfo}. |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 2441 | * @param flags Additional operational flags. |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2442 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 2443 | @RequiresPermission(android.Manifest.permission.REORDER_TASKS) |
| 2444 | public void moveTaskToFront(int taskId, @MoveTaskFlags int flags) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2445 | moveTaskToFront(taskId, flags, null); |
| 2446 | } |
| 2447 | |
| 2448 | /** |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 2449 | * Ask that the task associated with a given task ID be moved to the |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 2450 | * front of the stack, so it is now visible to the user. |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 2451 | * |
| 2452 | * @param taskId The identifier of the task to be moved, as found in |
| 2453 | * {@link RunningTaskInfo} or {@link RecentTaskInfo}. |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 2454 | * @param flags Additional operational flags. |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2455 | * @param options Additional options for the operation, either null or |
| 2456 | * as per {@link Context#startActivity(Intent, android.os.Bundle) |
| 2457 | * Context.startActivity(Intent, Bundle)}. |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 2458 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 2459 | @RequiresPermission(android.Manifest.permission.REORDER_TASKS) |
| 2460 | public void moveTaskToFront(int taskId, @MoveTaskFlags int flags, Bundle options) { |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 2461 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2462 | getService().moveTaskToFront(taskId, flags, options); |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 2463 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2464 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 2465 | } |
| 2466 | } |
| 2467 | |
| 2468 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2469 | * Information you can retrieve about a particular Service that is |
| 2470 | * currently running in the system. |
| 2471 | */ |
| 2472 | public static class RunningServiceInfo implements Parcelable { |
| 2473 | /** |
| 2474 | * The service component. |
| 2475 | */ |
| 2476 | public ComponentName service; |
| 2477 | |
| 2478 | /** |
| 2479 | * If non-zero, this is the process the service is running in. |
| 2480 | */ |
| 2481 | public int pid; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2482 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2483 | /** |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 2484 | * The UID that owns this service. |
| 2485 | */ |
| 2486 | public int uid; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2487 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 2488 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2489 | * The name of the process this service runs in. |
| 2490 | */ |
| 2491 | public String process; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2493 | /** |
| 2494 | * Set to true if the service has asked to run as a foreground process. |
| 2495 | */ |
| 2496 | public boolean foreground; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2497 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2498 | /** |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 2499 | * The time when the service was first made active, either by someone |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2500 | * starting or binding to it. This |
| 2501 | * is in units of {@link android.os.SystemClock#elapsedRealtime()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | */ |
| 2503 | public long activeSince; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2504 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2505 | /** |
| 2506 | * Set to true if this service has been explicitly started. |
| 2507 | */ |
| 2508 | public boolean started; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2510 | /** |
| 2511 | * Number of clients connected to the service. |
| 2512 | */ |
| 2513 | public int clientCount; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2515 | /** |
| 2516 | * Number of times the service's process has crashed while the service |
| 2517 | * is running. |
| 2518 | */ |
| 2519 | public int crashCount; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2520 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2521 | /** |
| 2522 | * The time when there was last activity in the service (either |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2523 | * explicit requests to start it or clients binding to it). This |
| 2524 | * is in units of {@link android.os.SystemClock#uptimeMillis()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | */ |
| 2526 | public long lastActivityTime; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2528 | /** |
| 2529 | * If non-zero, this service is not currently running, but scheduled to |
| 2530 | * restart at the given time. |
| 2531 | */ |
| 2532 | public long restarting; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2533 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 2534 | /** |
| 2535 | * Bit for {@link #flags}: set if this service has been |
| 2536 | * explicitly started. |
| 2537 | */ |
| 2538 | public static final int FLAG_STARTED = 1<<0; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2539 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 2540 | /** |
| 2541 | * Bit for {@link #flags}: set if the service has asked to |
| 2542 | * run as a foreground process. |
| 2543 | */ |
| 2544 | public static final int FLAG_FOREGROUND = 1<<1; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2545 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 2546 | /** |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 2547 | * Bit for {@link #flags}: set if the service is running in a |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 2548 | * core system process. |
| 2549 | */ |
| 2550 | public static final int FLAG_SYSTEM_PROCESS = 1<<2; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2551 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 2552 | /** |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 2553 | * Bit for {@link #flags}: set if the service is running in a |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 2554 | * persistent process. |
| 2555 | */ |
| 2556 | public static final int FLAG_PERSISTENT_PROCESS = 1<<3; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2557 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 2558 | /** |
| 2559 | * Running flags. |
| 2560 | */ |
| 2561 | public int flags; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2562 | |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2563 | /** |
| 2564 | * For special services that are bound to by system code, this is |
| 2565 | * the package that holds the binding. |
| 2566 | */ |
| 2567 | public String clientPackage; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2568 | |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2569 | /** |
| 2570 | * For special services that are bound to by system code, this is |
| 2571 | * a string resource providing a user-visible label for who the |
| 2572 | * client is. |
| 2573 | */ |
| 2574 | public int clientLabel; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2575 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2576 | public RunningServiceInfo() { |
| 2577 | } |
| 2578 | |
| 2579 | public int describeContents() { |
| 2580 | return 0; |
| 2581 | } |
| 2582 | |
| 2583 | public void writeToParcel(Parcel dest, int flags) { |
| 2584 | ComponentName.writeToParcel(service, dest); |
| 2585 | dest.writeInt(pid); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 2586 | dest.writeInt(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2587 | dest.writeString(process); |
| 2588 | dest.writeInt(foreground ? 1 : 0); |
| 2589 | dest.writeLong(activeSince); |
| 2590 | dest.writeInt(started ? 1 : 0); |
| 2591 | dest.writeInt(clientCount); |
| 2592 | dest.writeInt(crashCount); |
| 2593 | dest.writeLong(lastActivityTime); |
| 2594 | dest.writeLong(restarting); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 2595 | dest.writeInt(this.flags); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2596 | dest.writeString(clientPackage); |
| 2597 | dest.writeInt(clientLabel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2598 | } |
| 2599 | |
| 2600 | public void readFromParcel(Parcel source) { |
| 2601 | service = ComponentName.readFromParcel(source); |
| 2602 | pid = source.readInt(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 2603 | uid = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2604 | process = source.readString(); |
| 2605 | foreground = source.readInt() != 0; |
| 2606 | activeSince = source.readLong(); |
| 2607 | started = source.readInt() != 0; |
| 2608 | clientCount = source.readInt(); |
| 2609 | crashCount = source.readInt(); |
| 2610 | lastActivityTime = source.readLong(); |
| 2611 | restarting = source.readLong(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 2612 | flags = source.readInt(); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2613 | clientPackage = source.readString(); |
| 2614 | clientLabel = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2615 | } |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() { |
| 2618 | public RunningServiceInfo createFromParcel(Parcel source) { |
| 2619 | return new RunningServiceInfo(source); |
| 2620 | } |
| 2621 | public RunningServiceInfo[] newArray(int size) { |
| 2622 | return new RunningServiceInfo[size]; |
| 2623 | } |
| 2624 | }; |
| 2625 | |
| 2626 | private RunningServiceInfo(Parcel source) { |
| 2627 | readFromParcel(source); |
| 2628 | } |
| 2629 | } |
| 2630 | |
| 2631 | /** |
| 2632 | * Return a list of the services that are currently running. |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 2633 | * |
| 2634 | * <p><b>Note: this method is only intended for debugging or implementing |
| 2635 | * service management type user interfaces.</b></p> |
| 2636 | * |
Bryce Lee | f17e1d1a4 | 2017-04-17 15:52:50 -0700 | [diff] [blame] | 2637 | * @deprecated As of {@link android.os.Build.VERSION_CODES#O}, this method |
| 2638 | * is no longer available to third party applications. For backwards compatibility, |
| 2639 | * it will still return the caller's own services. |
| 2640 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2641 | * @param maxNum The maximum number of entries to return in the list. The |
| 2642 | * actual number returned may be smaller, depending on how many services |
| 2643 | * are running. |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2644 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2645 | * @return Returns a list of RunningServiceInfo records describing each of |
| 2646 | * the running tasks. |
| 2647 | */ |
Bryce Lee | f17e1d1a4 | 2017-04-17 15:52:50 -0700 | [diff] [blame] | 2648 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2649 | public List<RunningServiceInfo> getRunningServices(int maxNum) |
| 2650 | throws SecurityException { |
| 2651 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2652 | return getService() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2653 | .getServices(maxNum, 0); |
| 2654 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2655 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2656 | } |
| 2657 | } |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2658 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | /** |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2660 | * Returns a PendingIntent you can start to show a control panel for the |
| 2661 | * given running service. If the service does not have a control panel, |
| 2662 | * null is returned. |
| 2663 | */ |
| 2664 | public PendingIntent getRunningServiceControlPanel(ComponentName service) |
| 2665 | throws SecurityException { |
| 2666 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2667 | return getService() |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2668 | .getRunningServiceControlPanel(service); |
| 2669 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2670 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2671 | } |
| 2672 | } |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2673 | |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2674 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2675 | * Information you can retrieve about the available memory through |
| 2676 | * {@link ActivityManager#getMemoryInfo}. |
| 2677 | */ |
| 2678 | public static class MemoryInfo implements Parcelable { |
| 2679 | /** |
Dianne Hackborn | 59325eb | 2012-05-09 18:45:20 -0700 | [diff] [blame] | 2680 | * The available memory on the system. This number should not |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2681 | * be considered absolute: due to the nature of the kernel, a significant |
| 2682 | * portion of this memory is actually in use and needed for the overall |
| 2683 | * system to run well. |
| 2684 | */ |
| 2685 | public long availMem; |
Dianne Hackborn | 59325eb | 2012-05-09 18:45:20 -0700 | [diff] [blame] | 2686 | |
| 2687 | /** |
| 2688 | * The total memory accessible by the kernel. This is basically the |
| 2689 | * RAM size of the device, not including below-kernel fixed allocations |
| 2690 | * like DMA buffers, RAM for the baseband CPU, etc. |
| 2691 | */ |
| 2692 | public long totalMem; |
| 2693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2694 | /** |
| 2695 | * The threshold of {@link #availMem} at which we consider memory to be |
| 2696 | * low and start killing background services and other non-extraneous |
| 2697 | * processes. |
| 2698 | */ |
| 2699 | public long threshold; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2700 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2701 | /** |
| 2702 | * Set to true if the system considers itself to currently be in a low |
| 2703 | * memory situation. |
| 2704 | */ |
| 2705 | public boolean lowMemory; |
| 2706 | |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 2707 | /** @hide */ |
| 2708 | public long hiddenAppThreshold; |
| 2709 | /** @hide */ |
| 2710 | public long secondaryServerThreshold; |
| 2711 | /** @hide */ |
| 2712 | public long visibleAppThreshold; |
| 2713 | /** @hide */ |
| 2714 | public long foregroundAppThreshold; |
| 2715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2716 | public MemoryInfo() { |
| 2717 | } |
| 2718 | |
| 2719 | public int describeContents() { |
| 2720 | return 0; |
| 2721 | } |
| 2722 | |
| 2723 | public void writeToParcel(Parcel dest, int flags) { |
| 2724 | dest.writeLong(availMem); |
Dianne Hackborn | 59325eb | 2012-05-09 18:45:20 -0700 | [diff] [blame] | 2725 | dest.writeLong(totalMem); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2726 | dest.writeLong(threshold); |
| 2727 | dest.writeInt(lowMemory ? 1 : 0); |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 2728 | dest.writeLong(hiddenAppThreshold); |
| 2729 | dest.writeLong(secondaryServerThreshold); |
| 2730 | dest.writeLong(visibleAppThreshold); |
| 2731 | dest.writeLong(foregroundAppThreshold); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2732 | } |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2733 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2734 | public void readFromParcel(Parcel source) { |
| 2735 | availMem = source.readLong(); |
Dianne Hackborn | 59325eb | 2012-05-09 18:45:20 -0700 | [diff] [blame] | 2736 | totalMem = source.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2737 | threshold = source.readLong(); |
| 2738 | lowMemory = source.readInt() != 0; |
Dianne Hackborn | 7d60842 | 2011-08-07 16:24:18 -0700 | [diff] [blame] | 2739 | hiddenAppThreshold = source.readLong(); |
| 2740 | secondaryServerThreshold = source.readLong(); |
| 2741 | visibleAppThreshold = source.readLong(); |
| 2742 | foregroundAppThreshold = source.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | public static final Creator<MemoryInfo> CREATOR |
| 2746 | = new Creator<MemoryInfo>() { |
| 2747 | public MemoryInfo createFromParcel(Parcel source) { |
| 2748 | return new MemoryInfo(source); |
| 2749 | } |
| 2750 | public MemoryInfo[] newArray(int size) { |
| 2751 | return new MemoryInfo[size]; |
| 2752 | } |
| 2753 | }; |
| 2754 | |
| 2755 | private MemoryInfo(Parcel source) { |
| 2756 | readFromParcel(source); |
| 2757 | } |
| 2758 | } |
| 2759 | |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 2760 | /** |
| 2761 | * Return general information about the memory state of the system. This |
| 2762 | * can be used to help decide how to manage your own memory, though note |
| 2763 | * that polling is not recommended and |
| 2764 | * {@link android.content.ComponentCallbacks2#onTrimMemory(int) |
| 2765 | * ComponentCallbacks2.onTrimMemory(int)} is the preferred way to do this. |
| 2766 | * Also see {@link #getMyMemoryState} for how to retrieve the current trim |
| 2767 | * level of your process as needed, which gives a better hint for how to |
| 2768 | * manage its memory. |
| 2769 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2770 | public void getMemoryInfo(MemoryInfo outInfo) { |
| 2771 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2772 | getService().getMemoryInfo(outInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2773 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2774 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2775 | } |
| 2776 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2777 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 2778 | /** |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2779 | * Information you can retrieve about an ActivityStack in the system. |
| 2780 | * @hide |
| 2781 | */ |
| 2782 | public static class StackInfo implements Parcelable { |
| 2783 | public int stackId; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 2784 | public Rect bounds = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2785 | public int[] taskIds; |
| 2786 | public String[] taskNames; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2787 | public Rect[] taskBounds; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 2788 | public int[] taskUserIds; |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 2789 | public ComponentName topActivity; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 2790 | public int displayId; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 2791 | public int userId; |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 2792 | public boolean visible; |
Winson | 529c8e4 | 2016-05-17 11:08:40 -0700 | [diff] [blame] | 2793 | // Index of the stack in the display's stack list, can be used for comparison of stack order |
| 2794 | public int position; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2795 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2796 | @Override |
| 2797 | public int describeContents() { |
| 2798 | return 0; |
| 2799 | } |
| 2800 | |
| 2801 | @Override |
| 2802 | public void writeToParcel(Parcel dest, int flags) { |
| 2803 | dest.writeInt(stackId); |
| 2804 | dest.writeInt(bounds.left); |
| 2805 | dest.writeInt(bounds.top); |
| 2806 | dest.writeInt(bounds.right); |
| 2807 | dest.writeInt(bounds.bottom); |
| 2808 | dest.writeIntArray(taskIds); |
| 2809 | dest.writeStringArray(taskNames); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2810 | final int boundsCount = taskBounds == null ? 0 : taskBounds.length; |
| 2811 | dest.writeInt(boundsCount); |
| 2812 | for (int i = 0; i < boundsCount; i++) { |
| 2813 | dest.writeInt(taskBounds[i].left); |
| 2814 | dest.writeInt(taskBounds[i].top); |
| 2815 | dest.writeInt(taskBounds[i].right); |
| 2816 | dest.writeInt(taskBounds[i].bottom); |
| 2817 | } |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 2818 | dest.writeIntArray(taskUserIds); |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 2819 | dest.writeInt(displayId); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 2820 | dest.writeInt(userId); |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 2821 | dest.writeInt(visible ? 1 : 0); |
Winson | 529c8e4 | 2016-05-17 11:08:40 -0700 | [diff] [blame] | 2822 | dest.writeInt(position); |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 2823 | if (topActivity != null) { |
| 2824 | dest.writeInt(1); |
| 2825 | topActivity.writeToParcel(dest, 0); |
| 2826 | } else { |
| 2827 | dest.writeInt(0); |
| 2828 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | public void readFromParcel(Parcel source) { |
| 2832 | stackId = source.readInt(); |
| 2833 | bounds = new Rect( |
| 2834 | source.readInt(), source.readInt(), source.readInt(), source.readInt()); |
| 2835 | taskIds = source.createIntArray(); |
| 2836 | taskNames = source.createStringArray(); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2837 | final int boundsCount = source.readInt(); |
| 2838 | if (boundsCount > 0) { |
| 2839 | taskBounds = new Rect[boundsCount]; |
| 2840 | for (int i = 0; i < boundsCount; i++) { |
| 2841 | taskBounds[i] = new Rect(); |
| 2842 | taskBounds[i].set( |
| 2843 | source.readInt(), source.readInt(), source.readInt(), source.readInt()); |
| 2844 | } |
| 2845 | } else { |
| 2846 | taskBounds = null; |
| 2847 | } |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 2848 | taskUserIds = source.createIntArray(); |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 2849 | displayId = source.readInt(); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 2850 | userId = source.readInt(); |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 2851 | visible = source.readInt() > 0; |
Winson | 529c8e4 | 2016-05-17 11:08:40 -0700 | [diff] [blame] | 2852 | position = source.readInt(); |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 2853 | if (source.readInt() > 0) { |
| 2854 | topActivity = ComponentName.readFromParcel(source); |
| 2855 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | public static final Creator<StackInfo> CREATOR = new Creator<StackInfo>() { |
| 2859 | @Override |
| 2860 | public StackInfo createFromParcel(Parcel source) { |
| 2861 | return new StackInfo(source); |
| 2862 | } |
| 2863 | @Override |
| 2864 | public StackInfo[] newArray(int size) { |
| 2865 | return new StackInfo[size]; |
| 2866 | } |
| 2867 | }; |
| 2868 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 2869 | public StackInfo() { |
| 2870 | } |
| 2871 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2872 | private StackInfo(Parcel source) { |
| 2873 | readFromParcel(source); |
| 2874 | } |
| 2875 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 2876 | public String toString(String prefix) { |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2877 | StringBuilder sb = new StringBuilder(256); |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 2878 | sb.append(prefix); sb.append("Stack id="); sb.append(stackId); |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 2879 | sb.append(" bounds="); sb.append(bounds.toShortString()); |
| 2880 | sb.append(" displayId="); sb.append(displayId); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 2881 | sb.append(" userId="); sb.append(userId); |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 2882 | sb.append("\n"); |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 2883 | prefix = prefix + " "; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2884 | for (int i = 0; i < taskIds.length; ++i) { |
| 2885 | sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2886 | sb.append(": "); sb.append(taskNames[i]); |
| 2887 | if (taskBounds != null) { |
| 2888 | sb.append(" bounds="); sb.append(taskBounds[i].toShortString()); |
| 2889 | } |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 2890 | sb.append(" userId=").append(taskUserIds[i]); |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 2891 | sb.append(" visible=").append(visible); |
| 2892 | if (topActivity != null) { |
| 2893 | sb.append(" topActivity=").append(topActivity); |
| 2894 | } |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2895 | sb.append("\n"); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2896 | } |
| 2897 | return sb.toString(); |
| 2898 | } |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 2899 | |
| 2900 | @Override |
| 2901 | public String toString() { |
| 2902 | return toString(""); |
| 2903 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2904 | } |
| 2905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | /** |
| 2907 | * @hide |
| 2908 | */ |
Svet Ganov | f935a70 | 2017-08-22 12:15:58 -0700 | [diff] [blame] | 2909 | @RequiresPermission(anyOf={Manifest.permission.CLEAR_APP_USER_DATA, |
| 2910 | Manifest.permission.ACCESS_INSTANT_APPS}) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2911 | public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) { |
| 2912 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2913 | return getService().clearApplicationUserData(packageName, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 2914 | observer, UserHandle.myUserId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2915 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2916 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2917 | } |
| 2918 | } |
Christopher Tate | a366424 | 2013-06-26 15:00:18 -0700 | [diff] [blame] | 2919 | |
| 2920 | /** |
| 2921 | * Permits an application to erase its own data from disk. This is equivalent to |
Dianne Hackborn | ebc15ef | 2013-10-09 17:36:57 -0700 | [diff] [blame] | 2922 | * the user choosing to clear the app's data from within the device settings UI. It |
| 2923 | * erases all dynamic data associated with the app -- its private data and data in its |
| 2924 | * private area on external storage -- but does not remove the installed application |
| 2925 | * itself, nor any OBB files. |
Christopher Tate | a366424 | 2013-06-26 15:00:18 -0700 | [diff] [blame] | 2926 | * |
| 2927 | * @return {@code true} if the application successfully requested that the application's |
| 2928 | * data be erased; {@code false} otherwise. |
| 2929 | */ |
| 2930 | public boolean clearApplicationUserData() { |
| 2931 | return clearApplicationUserData(mContext.getPackageName(), null); |
| 2932 | } |
| 2933 | |
Felipe Leme | f3fa0f8 | 2016-01-07 12:08:19 -0800 | [diff] [blame] | 2934 | |
| 2935 | /** |
| 2936 | * Permits an application to get the persistent URI permissions granted to another. |
| 2937 | * |
| 2938 | * <p>Typically called by Settings. |
| 2939 | * |
| 2940 | * @param packageName application to look for the granted permissions |
| 2941 | * @return list of granted URI permissions |
| 2942 | * |
| 2943 | * @hide |
| 2944 | */ |
| 2945 | public ParceledListSlice<UriPermission> getGrantedUriPermissions(String packageName) { |
| 2946 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2947 | return getService().getGrantedUriPermissions(packageName, |
Felipe Leme | f3fa0f8 | 2016-01-07 12:08:19 -0800 | [diff] [blame] | 2948 | UserHandle.myUserId()); |
| 2949 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2950 | throw e.rethrowFromSystemServer(); |
Felipe Leme | f3fa0f8 | 2016-01-07 12:08:19 -0800 | [diff] [blame] | 2951 | } |
| 2952 | } |
| 2953 | |
| 2954 | /** |
| 2955 | * Permits an application to clear the persistent URI permissions granted to another. |
| 2956 | * |
| 2957 | * <p>Typically called by Settings. |
| 2958 | * |
| 2959 | * @param packageName application to clear its granted permissions |
| 2960 | * |
| 2961 | * @hide |
| 2962 | */ |
| 2963 | public void clearGrantedUriPermissions(String packageName) { |
| 2964 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 2965 | getService().clearGrantedUriPermissions(packageName, |
Felipe Leme | f3fa0f8 | 2016-01-07 12:08:19 -0800 | [diff] [blame] | 2966 | UserHandle.myUserId()); |
| 2967 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 2968 | throw e.rethrowFromSystemServer(); |
Felipe Leme | f3fa0f8 | 2016-01-07 12:08:19 -0800 | [diff] [blame] | 2969 | } |
| 2970 | } |
| 2971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2972 | /** |
| 2973 | * Information you can retrieve about any processes that are in an error condition. |
| 2974 | */ |
| 2975 | public static class ProcessErrorStateInfo implements Parcelable { |
| 2976 | /** |
| 2977 | * Condition codes |
| 2978 | */ |
| 2979 | public static final int NO_ERROR = 0; |
| 2980 | public static final int CRASHED = 1; |
| 2981 | public static final int NOT_RESPONDING = 2; |
| 2982 | |
| 2983 | /** |
| 2984 | * The condition that the process is in. |
| 2985 | */ |
| 2986 | public int condition; |
| 2987 | |
| 2988 | /** |
| 2989 | * The process name in which the crash or error occurred. |
| 2990 | */ |
| 2991 | public String processName; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 2992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2993 | /** |
| 2994 | * The pid of this process; 0 if none |
| 2995 | */ |
| 2996 | public int pid; |
| 2997 | |
| 2998 | /** |
| 2999 | * The kernel user-ID that has been assigned to this process; |
| 3000 | * currently this is not a unique ID (multiple applications can have |
| 3001 | * the same uid). |
| 3002 | */ |
| 3003 | public int uid; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3004 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3005 | /** |
Dan Egnor | 60d8762 | 2009-12-16 16:32:58 -0800 | [diff] [blame] | 3006 | * The activity name associated with the error, if known. May be null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3007 | */ |
| 3008 | public String tag; |
| 3009 | |
| 3010 | /** |
| 3011 | * A short message describing the error condition. |
| 3012 | */ |
| 3013 | public String shortMsg; |
| 3014 | |
| 3015 | /** |
| 3016 | * A long message describing the error condition. |
| 3017 | */ |
| 3018 | public String longMsg; |
| 3019 | |
| 3020 | /** |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 3021 | * The stack trace where the error originated. May be null. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3022 | */ |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 3023 | public String stackTrace; |
| 3024 | |
| 3025 | /** |
| 3026 | * to be deprecated: This value will always be null. |
| 3027 | */ |
| 3028 | public byte[] crashData = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3029 | |
| 3030 | public ProcessErrorStateInfo() { |
| 3031 | } |
| 3032 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 3033 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3034 | public int describeContents() { |
| 3035 | return 0; |
| 3036 | } |
| 3037 | |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 3038 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3039 | public void writeToParcel(Parcel dest, int flags) { |
| 3040 | dest.writeInt(condition); |
| 3041 | dest.writeString(processName); |
| 3042 | dest.writeInt(pid); |
| 3043 | dest.writeInt(uid); |
| 3044 | dest.writeString(tag); |
| 3045 | dest.writeString(shortMsg); |
| 3046 | dest.writeString(longMsg); |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 3047 | dest.writeString(stackTrace); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3048 | } |
Craig Mautner | 5ff1210 | 2013-05-24 12:50:15 -0700 | [diff] [blame] | 3049 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3050 | public void readFromParcel(Parcel source) { |
| 3051 | condition = source.readInt(); |
| 3052 | processName = source.readString(); |
| 3053 | pid = source.readInt(); |
| 3054 | uid = source.readInt(); |
| 3055 | tag = source.readString(); |
| 3056 | shortMsg = source.readString(); |
| 3057 | longMsg = source.readString(); |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 3058 | stackTrace = source.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3059 | } |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3060 | |
| 3061 | public static final Creator<ProcessErrorStateInfo> CREATOR = |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3062 | new Creator<ProcessErrorStateInfo>() { |
| 3063 | public ProcessErrorStateInfo createFromParcel(Parcel source) { |
| 3064 | return new ProcessErrorStateInfo(source); |
| 3065 | } |
| 3066 | public ProcessErrorStateInfo[] newArray(int size) { |
| 3067 | return new ProcessErrorStateInfo[size]; |
| 3068 | } |
| 3069 | }; |
| 3070 | |
| 3071 | private ProcessErrorStateInfo(Parcel source) { |
| 3072 | readFromParcel(source); |
| 3073 | } |
| 3074 | } |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3076 | /** |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3077 | * Returns a list of any processes that are currently in an error condition. The result |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3078 | * will be null if all processes are running properly at this time. |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3079 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3080 | * @return Returns a list of ProcessErrorStateInfo records, or null if there are no |
| 3081 | * current error conditions (it will not return an empty list). This list ordering is not |
| 3082 | * specified. |
| 3083 | */ |
| 3084 | public List<ProcessErrorStateInfo> getProcessesInErrorState() { |
| 3085 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3086 | return getService().getProcessesInErrorState(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3087 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3088 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3089 | } |
| 3090 | } |
| 3091 | |
| 3092 | /** |
| 3093 | * Information you can retrieve about a running process. |
| 3094 | */ |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3095 | public static class RunningAppProcessInfo implements Parcelable { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3096 | /** |
| 3097 | * The name of the process that this object is associated with |
| 3098 | */ |
| 3099 | public String processName; |
| 3100 | |
| 3101 | /** |
| 3102 | * The pid of this process; 0 if none |
| 3103 | */ |
| 3104 | public int pid; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3105 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 3106 | /** |
| 3107 | * The user id of this process. |
| 3108 | */ |
| 3109 | public int uid; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3110 | |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 3111 | /** |
| 3112 | * All packages that have been loaded into the process. |
| 3113 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3114 | public String pkgList[]; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3116 | /** |
Dianne Hackborn | 482566e | 2010-09-03 12:51:28 -0700 | [diff] [blame] | 3117 | * Constant for {@link #flags}: this is an app that is unable to |
| 3118 | * correctly save its state when going to the background, |
| 3119 | * so it can not be killed while in the background. |
| 3120 | * @hide |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 3121 | */ |
Dianne Hackborn | 482566e | 2010-09-03 12:51:28 -0700 | [diff] [blame] | 3122 | public static final int FLAG_CANT_SAVE_STATE = 1<<0; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3123 | |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 3124 | /** |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 3125 | * Constant for {@link #flags}: this process is associated with a |
| 3126 | * persistent system app. |
| 3127 | * @hide |
| 3128 | */ |
| 3129 | public static final int FLAG_PERSISTENT = 1<<1; |
| 3130 | |
| 3131 | /** |
Dianne Hackborn | 0c38049 | 2012-08-20 17:23:30 -0700 | [diff] [blame] | 3132 | * Constant for {@link #flags}: this process is associated with a |
| 3133 | * persistent system app. |
| 3134 | * @hide |
| 3135 | */ |
| 3136 | public static final int FLAG_HAS_ACTIVITIES = 1<<2; |
| 3137 | |
| 3138 | /** |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 3139 | * Flags of information. May be any of |
Dianne Hackborn | 482566e | 2010-09-03 12:51:28 -0700 | [diff] [blame] | 3140 | * {@link #FLAG_CANT_SAVE_STATE}. |
| 3141 | * @hide |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 3142 | */ |
| 3143 | public int flags; |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 3144 | |
| 3145 | /** |
| 3146 | * Last memory trim level reported to the process: corresponds to |
| 3147 | * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int) |
| 3148 | * ComponentCallbacks2.onTrimMemory(int)}. |
| 3149 | */ |
| 3150 | public int lastTrimLevel; |
| 3151 | |
Jeff Sharkey | 910e081 | 2017-04-21 16:29:27 -0600 | [diff] [blame] | 3152 | /** @hide */ |
| 3153 | @IntDef(prefix = { "IMPORTANCE_" }, value = { |
| 3154 | IMPORTANCE_FOREGROUND, |
| 3155 | IMPORTANCE_FOREGROUND_SERVICE, |
| 3156 | IMPORTANCE_TOP_SLEEPING, |
| 3157 | IMPORTANCE_VISIBLE, |
| 3158 | IMPORTANCE_PERCEPTIBLE, |
| 3159 | IMPORTANCE_CANT_SAVE_STATE, |
| 3160 | IMPORTANCE_SERVICE, |
| 3161 | IMPORTANCE_CACHED, |
| 3162 | IMPORTANCE_GONE, |
| 3163 | }) |
| 3164 | @Retention(RetentionPolicy.SOURCE) |
| 3165 | public @interface Importance {} |
| 3166 | |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 3167 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3168 | * Constant for {@link #importance}: This process is running the |
| 3169 | * foreground UI; that is, it is the thing currently at the top of the screen |
| 3170 | * that the user is interacting with. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3171 | */ |
| 3172 | public static final int IMPORTANCE_FOREGROUND = 100; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3174 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3175 | * Constant for {@link #importance}: This process is running a foreground |
| 3176 | * service, for example to perform music playback even while the user is |
| 3177 | * not immediately in the app. This generally indicates that the process |
| 3178 | * is doing something the user actively cares about. |
| 3179 | */ |
| 3180 | public static final int IMPORTANCE_FOREGROUND_SERVICE = 125; |
| 3181 | |
| 3182 | /** |
| 3183 | * Constant for {@link #importance}: This process is running the foreground |
| 3184 | * UI, but the device is asleep so it is not visible to the user. This means |
| 3185 | * the user is not really aware of the process, because they can not see or |
| 3186 | * interact with it, but it is quite important because it what they expect to |
| 3187 | * return to once unlocking the device. |
| 3188 | */ |
| 3189 | public static final int IMPORTANCE_TOP_SLEEPING = 150; |
| 3190 | |
| 3191 | /** |
| 3192 | * Constant for {@link #importance}: This process is running something |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3193 | * that is actively visible to the user, though not in the immediate |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3194 | * foreground. This may be running a window that is behind the current |
| 3195 | * foreground (so paused and with its state saved, not interacting with |
| 3196 | * the user, but visible to them to some degree); it may also be running |
| 3197 | * other services under the system's control that it inconsiders important. |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 3198 | */ |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3199 | public static final int IMPORTANCE_VISIBLE = 200; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3200 | |
Dianne Hackborn | 860755f | 2010-06-03 18:47:52 -0700 | [diff] [blame] | 3201 | /** |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 3202 | * Constant for {@link #importance}: {@link #IMPORTANCE_PERCEPTIBLE} had this wrong value |
| 3203 | * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK, |
| 3204 | * the value of {@link #IMPORTANCE_PERCEPTIBLE} has been fixed. |
| 3205 | * |
Makoto Onuki | e92f794 | 2017-04-26 14:38:18 -0700 | [diff] [blame] | 3206 | * <p>The system will return this value instead of {@link #IMPORTANCE_PERCEPTIBLE} |
| 3207 | * on Android versions below {@link Build.VERSION_CODES#O}. |
| 3208 | * |
| 3209 | * <p>On Android version {@link Build.VERSION_CODES#O} and later, this value will still be |
| 3210 | * returned for apps with the target API level below {@link Build.VERSION_CODES#O}. |
| 3211 | * For apps targeting version {@link Build.VERSION_CODES#O} and later, |
| 3212 | * the correct value {@link #IMPORTANCE_PERCEPTIBLE} will be returned. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3213 | */ |
Makoto Onuki | e92f794 | 2017-04-26 14:38:18 -0700 | [diff] [blame] | 3214 | public static final int IMPORTANCE_PERCEPTIBLE_PRE_26 = 130; |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 3215 | |
| 3216 | /** |
| 3217 | * Constant for {@link #importance}: This process is not something the user |
| 3218 | * is directly aware of, but is otherwise perceptible to them to some degree. |
| 3219 | */ |
| 3220 | public static final int IMPORTANCE_PERCEPTIBLE = 230; |
| 3221 | |
| 3222 | /** |
| 3223 | * Constant for {@link #importance}: {@link #IMPORTANCE_CANT_SAVE_STATE} had |
| 3224 | * this wrong value |
| 3225 | * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK, |
| 3226 | * the value of {@link #IMPORTANCE_CANT_SAVE_STATE} has been fixed. |
| 3227 | * |
Makoto Onuki | e92f794 | 2017-04-26 14:38:18 -0700 | [diff] [blame] | 3228 | * <p>The system will return this value instead of {@link #IMPORTANCE_CANT_SAVE_STATE} |
| 3229 | * on Android versions below {@link Build.VERSION_CODES#O}. |
| 3230 | * |
| 3231 | * <p>On Android version {@link Build.VERSION_CODES#O} after, this value will still be |
| 3232 | * returned for apps with the target API level below {@link Build.VERSION_CODES#O}. |
| 3233 | * For apps targeting version {@link Build.VERSION_CODES#O} and later, |
| 3234 | * the correct value {@link #IMPORTANCE_CANT_SAVE_STATE} will be returned. |
| 3235 | * |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 3236 | * @hide |
| 3237 | */ |
Makoto Onuki | e92f794 | 2017-04-26 14:38:18 -0700 | [diff] [blame] | 3238 | public static final int IMPORTANCE_CANT_SAVE_STATE_PRE_26 = 170; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3239 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3240 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3241 | * Constant for {@link #importance}: This process is running an |
Dianne Hackborn | 5383f50 | 2010-10-22 12:59:20 -0700 | [diff] [blame] | 3242 | * application that can not save its state, and thus can't be killed |
| 3243 | * while in the background. |
| 3244 | * @hide |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3245 | */ |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 3246 | public static final int IMPORTANCE_CANT_SAVE_STATE= 270; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3248 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3249 | * Constant for {@link #importance}: This process is contains services |
| 3250 | * that should remain running. These are background services apps have |
| 3251 | * started, not something the user is aware of, so they may be killed by |
| 3252 | * the system relatively freely (though it is generally desired that they |
| 3253 | * stay running as long as they want to). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | */ |
| 3255 | public static final int IMPORTANCE_SERVICE = 300; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3256 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3257 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3258 | * Constant for {@link #importance}: This process process contains |
Dianne Hackborn | 45e69d6 | 2017-03-01 16:02:15 -0800 | [diff] [blame] | 3259 | * cached code that is expendable, not actively running any app components |
| 3260 | * we care about. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3261 | */ |
Dianne Hackborn | 45e69d6 | 2017-03-01 16:02:15 -0800 | [diff] [blame] | 3262 | public static final int IMPORTANCE_CACHED = 400; |
| 3263 | |
| 3264 | /** |
| 3265 | * @deprecated Renamed to {@link #IMPORTANCE_CACHED}. |
| 3266 | */ |
| 3267 | public static final int IMPORTANCE_BACKGROUND = IMPORTANCE_CACHED; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3268 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3269 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3270 | * Constant for {@link #importance}: This process is empty of any |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3271 | * actively running code. |
Dianne Hackborn | 45e69d6 | 2017-03-01 16:02:15 -0800 | [diff] [blame] | 3272 | * @deprecated This value is no longer reported, use {@link #IMPORTANCE_CACHED} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3273 | */ |
Dianne Hackborn | 45e69d6 | 2017-03-01 16:02:15 -0800 | [diff] [blame] | 3274 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3275 | public static final int IMPORTANCE_EMPTY = 500; |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 3276 | |
| 3277 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3278 | * Constant for {@link #importance}: This process does not exist. |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 3279 | */ |
| 3280 | public static final int IMPORTANCE_GONE = 1000; |
| 3281 | |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 3282 | /** |
| 3283 | * Convert a proc state to the correspondent IMPORTANCE_* constant. If the return value |
| 3284 | * will be passed to a client, use {@link #procStateToImportanceForClient}. |
| 3285 | * @hide |
| 3286 | */ |
Jeff Sharkey | 910e081 | 2017-04-21 16:29:27 -0600 | [diff] [blame] | 3287 | public static @Importance int procStateToImportance(int procState) { |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3288 | if (procState == PROCESS_STATE_NONEXISTENT) { |
| 3289 | return IMPORTANCE_GONE; |
| 3290 | } else if (procState >= PROCESS_STATE_HOME) { |
Dianne Hackborn | 45e69d6 | 2017-03-01 16:02:15 -0800 | [diff] [blame] | 3291 | return IMPORTANCE_CACHED; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3292 | } else if (procState >= PROCESS_STATE_SERVICE) { |
| 3293 | return IMPORTANCE_SERVICE; |
| 3294 | } else if (procState > PROCESS_STATE_HEAVY_WEIGHT) { |
| 3295 | return IMPORTANCE_CANT_SAVE_STATE; |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 3296 | } else if (procState >= PROCESS_STATE_TRANSIENT_BACKGROUND) { |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3297 | return IMPORTANCE_PERCEPTIBLE; |
| 3298 | } else if (procState >= PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 3299 | return IMPORTANCE_VISIBLE; |
| 3300 | } else if (procState >= PROCESS_STATE_TOP_SLEEPING) { |
| 3301 | return IMPORTANCE_TOP_SLEEPING; |
| 3302 | } else if (procState >= PROCESS_STATE_FOREGROUND_SERVICE) { |
| 3303 | return IMPORTANCE_FOREGROUND_SERVICE; |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 3304 | } else { |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3305 | return IMPORTANCE_FOREGROUND; |
Dianne Hackborn | fee756f | 2014-07-16 17:31:10 -0700 | [diff] [blame] | 3306 | } |
| 3307 | } |
| 3308 | |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 3309 | /** |
| 3310 | * Convert a proc state to the correspondent IMPORTANCE_* constant for a client represented |
| 3311 | * by a given {@link Context}, with converting {@link #IMPORTANCE_PERCEPTIBLE} |
| 3312 | * and {@link #IMPORTANCE_CANT_SAVE_STATE} to the corresponding "wrong" value if the |
| 3313 | * client's target SDK < {@link VERSION_CODES#O}. |
| 3314 | * @hide |
| 3315 | */ |
Jeff Sharkey | 910e081 | 2017-04-21 16:29:27 -0600 | [diff] [blame] | 3316 | public static @Importance int procStateToImportanceForClient(int procState, |
| 3317 | Context clientContext) { |
Makoto Onuki | e92f794 | 2017-04-26 14:38:18 -0700 | [diff] [blame] | 3318 | return procStateToImportanceForTargetSdk(procState, |
| 3319 | clientContext.getApplicationInfo().targetSdkVersion); |
| 3320 | } |
| 3321 | |
| 3322 | /** |
| 3323 | * See {@link #procStateToImportanceForClient}. |
| 3324 | * @hide |
| 3325 | */ |
| 3326 | public static @Importance int procStateToImportanceForTargetSdk(int procState, |
| 3327 | int targetSdkVersion) { |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 3328 | final int importance = procStateToImportance(procState); |
| 3329 | |
| 3330 | // For pre O apps, convert to the old, wrong values. |
Makoto Onuki | e92f794 | 2017-04-26 14:38:18 -0700 | [diff] [blame] | 3331 | if (targetSdkVersion < VERSION_CODES.O) { |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 3332 | switch (importance) { |
| 3333 | case IMPORTANCE_PERCEPTIBLE: |
Makoto Onuki | e92f794 | 2017-04-26 14:38:18 -0700 | [diff] [blame] | 3334 | return IMPORTANCE_PERCEPTIBLE_PRE_26; |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 3335 | case IMPORTANCE_CANT_SAVE_STATE: |
Makoto Onuki | e92f794 | 2017-04-26 14:38:18 -0700 | [diff] [blame] | 3336 | return IMPORTANCE_CANT_SAVE_STATE_PRE_26; |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 3337 | } |
| 3338 | } |
| 3339 | return importance; |
| 3340 | } |
| 3341 | |
Dianne Hackborn | 5614bf5 | 2016-11-07 17:26:41 -0800 | [diff] [blame] | 3342 | /** @hide */ |
Jeff Sharkey | 910e081 | 2017-04-21 16:29:27 -0600 | [diff] [blame] | 3343 | public static int importanceToProcState(@Importance int importance) { |
Dianne Hackborn | 5614bf5 | 2016-11-07 17:26:41 -0800 | [diff] [blame] | 3344 | if (importance == IMPORTANCE_GONE) { |
| 3345 | return PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 45e69d6 | 2017-03-01 16:02:15 -0800 | [diff] [blame] | 3346 | } else if (importance >= IMPORTANCE_CACHED) { |
Dianne Hackborn | 5614bf5 | 2016-11-07 17:26:41 -0800 | [diff] [blame] | 3347 | return PROCESS_STATE_HOME; |
| 3348 | } else if (importance >= IMPORTANCE_SERVICE) { |
| 3349 | return PROCESS_STATE_SERVICE; |
| 3350 | } else if (importance > IMPORTANCE_CANT_SAVE_STATE) { |
| 3351 | return PROCESS_STATE_HEAVY_WEIGHT; |
| 3352 | } else if (importance >= IMPORTANCE_PERCEPTIBLE) { |
Dianne Hackborn | 83b40f6 | 2017-04-26 13:59:47 -0700 | [diff] [blame] | 3353 | return PROCESS_STATE_TRANSIENT_BACKGROUND; |
Dianne Hackborn | 5614bf5 | 2016-11-07 17:26:41 -0800 | [diff] [blame] | 3354 | } else if (importance >= IMPORTANCE_VISIBLE) { |
| 3355 | return PROCESS_STATE_IMPORTANT_FOREGROUND; |
| 3356 | } else if (importance >= IMPORTANCE_TOP_SLEEPING) { |
| 3357 | return PROCESS_STATE_TOP_SLEEPING; |
| 3358 | } else if (importance >= IMPORTANCE_FOREGROUND_SERVICE) { |
| 3359 | return PROCESS_STATE_FOREGROUND_SERVICE; |
| 3360 | } else { |
| 3361 | return PROCESS_STATE_BOUND_FOREGROUND_SERVICE; |
| 3362 | } |
| 3363 | } |
| 3364 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3365 | /** |
Jeff Sharkey | 910e081 | 2017-04-21 16:29:27 -0600 | [diff] [blame] | 3366 | * The relative importance level that the system places on this process. |
| 3367 | * These constants are numbered so that "more important" values are |
| 3368 | * always smaller than "less important" values. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | */ |
Jeff Sharkey | 910e081 | 2017-04-21 16:29:27 -0600 | [diff] [blame] | 3370 | public @Importance int importance; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3372 | /** |
| 3373 | * An additional ordering within a particular {@link #importance} |
| 3374 | * category, providing finer-grained information about the relative |
| 3375 | * utility of processes within a category. This number means nothing |
| 3376 | * except that a smaller values are more recently used (and thus |
| 3377 | * more important). Currently an LRU value is only maintained for |
Dianne Hackborn | 45e69d6 | 2017-03-01 16:02:15 -0800 | [diff] [blame] | 3378 | * the {@link #IMPORTANCE_CACHED} category, though others may |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3379 | * be maintained in the future. |
| 3380 | */ |
| 3381 | public int lru; |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 3382 | |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 3383 | /** |
| 3384 | * Constant for {@link #importanceReasonCode}: nothing special has |
| 3385 | * been specified for the reason for this level. |
| 3386 | */ |
| 3387 | public static final int REASON_UNKNOWN = 0; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3388 | |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 3389 | /** |
| 3390 | * Constant for {@link #importanceReasonCode}: one of the application's |
| 3391 | * content providers is being used by another process. The pid of |
| 3392 | * the client process is in {@link #importanceReasonPid} and the |
| 3393 | * target provider in this process is in |
| 3394 | * {@link #importanceReasonComponent}. |
| 3395 | */ |
| 3396 | public static final int REASON_PROVIDER_IN_USE = 1; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3397 | |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 3398 | /** |
| 3399 | * Constant for {@link #importanceReasonCode}: one of the application's |
| 3400 | * content providers is being used by another process. The pid of |
| 3401 | * the client process is in {@link #importanceReasonPid} and the |
| 3402 | * target provider in this process is in |
| 3403 | * {@link #importanceReasonComponent}. |
| 3404 | */ |
| 3405 | public static final int REASON_SERVICE_IN_USE = 2; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3406 | |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 3407 | /** |
| 3408 | * The reason for {@link #importance}, if any. |
| 3409 | */ |
| 3410 | public int importanceReasonCode; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3411 | |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 3412 | /** |
| 3413 | * For the specified values of {@link #importanceReasonCode}, this |
| 3414 | * is the process ID of the other process that is a client of this |
| 3415 | * process. This will be 0 if no other process is using this one. |
| 3416 | */ |
| 3417 | public int importanceReasonPid; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3418 | |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 3419 | /** |
| 3420 | * For the specified values of {@link #importanceReasonCode}, this |
| 3421 | * is the name of the component that is being used in this process. |
| 3422 | */ |
| 3423 | public ComponentName importanceReasonComponent; |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3424 | |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 3425 | /** |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 3426 | * When {@link #importanceReasonPid} is non-0, this is the importance |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 3427 | * of the other pid. @hide |
| 3428 | */ |
| 3429 | public int importanceReasonImportance; |
| 3430 | |
Dianne Hackborn | 684bf34 | 2014-04-29 17:56:57 -0700 | [diff] [blame] | 3431 | /** |
| 3432 | * Current process state, as per PROCESS_STATE_* constants. |
| 3433 | * @hide |
| 3434 | */ |
| 3435 | public int processState; |
| 3436 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3437 | public RunningAppProcessInfo() { |
| 3438 | importance = IMPORTANCE_FOREGROUND; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 3439 | importanceReasonCode = REASON_UNKNOWN; |
Dianne Hackborn | 684bf34 | 2014-04-29 17:56:57 -0700 | [diff] [blame] | 3440 | processState = PROCESS_STATE_IMPORTANT_FOREGROUND; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3441 | } |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3443 | public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) { |
| 3444 | processName = pProcessName; |
| 3445 | pid = pPid; |
| 3446 | pkgList = pArr; |
| 3447 | } |
| 3448 | |
| 3449 | public int describeContents() { |
| 3450 | return 0; |
| 3451 | } |
| 3452 | |
| 3453 | public void writeToParcel(Parcel dest, int flags) { |
| 3454 | dest.writeString(processName); |
| 3455 | dest.writeInt(pid); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 3456 | dest.writeInt(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3457 | dest.writeStringArray(pkgList); |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 3458 | dest.writeInt(this.flags); |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 3459 | dest.writeInt(lastTrimLevel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | dest.writeInt(importance); |
| 3461 | dest.writeInt(lru); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 3462 | dest.writeInt(importanceReasonCode); |
| 3463 | dest.writeInt(importanceReasonPid); |
| 3464 | ComponentName.writeToParcel(importanceReasonComponent, dest); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 3465 | dest.writeInt(importanceReasonImportance); |
Dianne Hackborn | 684bf34 | 2014-04-29 17:56:57 -0700 | [diff] [blame] | 3466 | dest.writeInt(processState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | public void readFromParcel(Parcel source) { |
| 3470 | processName = source.readString(); |
| 3471 | pid = source.readInt(); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 3472 | uid = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3473 | pkgList = source.readStringArray(); |
Dianne Hackborn | baf42c6 | 2010-06-24 11:23:39 -0700 | [diff] [blame] | 3474 | flags = source.readInt(); |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 3475 | lastTrimLevel = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3476 | importance = source.readInt(); |
| 3477 | lru = source.readInt(); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 3478 | importanceReasonCode = source.readInt(); |
| 3479 | importanceReasonPid = source.readInt(); |
| 3480 | importanceReasonComponent = ComponentName.readFromParcel(source); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 3481 | importanceReasonImportance = source.readInt(); |
Dianne Hackborn | 684bf34 | 2014-04-29 17:56:57 -0700 | [diff] [blame] | 3482 | processState = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3483 | } |
| 3484 | |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3485 | public static final Creator<RunningAppProcessInfo> CREATOR = |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3486 | new Creator<RunningAppProcessInfo>() { |
| 3487 | public RunningAppProcessInfo createFromParcel(Parcel source) { |
| 3488 | return new RunningAppProcessInfo(source); |
| 3489 | } |
| 3490 | public RunningAppProcessInfo[] newArray(int size) { |
| 3491 | return new RunningAppProcessInfo[size]; |
| 3492 | } |
| 3493 | }; |
| 3494 | |
| 3495 | private RunningAppProcessInfo(Parcel source) { |
| 3496 | readFromParcel(source); |
| 3497 | } |
| 3498 | } |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3500 | /** |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 3501 | * Returns a list of application processes installed on external media |
| 3502 | * that are running on the device. |
| 3503 | * |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 3504 | * <p><b>Note: this method is only intended for debugging or building |
| 3505 | * a user-facing process management UI.</b></p> |
| 3506 | * |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 3507 | * @return Returns a list of ApplicationInfo records, or null if none |
| 3508 | * This list ordering is not specified. |
| 3509 | * @hide |
| 3510 | */ |
| 3511 | public List<ApplicationInfo> getRunningExternalApplications() { |
| 3512 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3513 | return getService().getRunningExternalApplications(); |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 3514 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3515 | throw e.rethrowFromSystemServer(); |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 3516 | } |
| 3517 | } |
| 3518 | |
| 3519 | /** |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3520 | * Sets the memory trim mode for a process and schedules a memory trim operation. |
| 3521 | * |
| 3522 | * <p><b>Note: this method is only intended for testing framework.</b></p> |
| 3523 | * |
| 3524 | * @return Returns true if successful. |
| 3525 | * @hide |
| 3526 | */ |
| 3527 | public boolean setProcessMemoryTrimLevel(String process, int userId, int level) { |
| 3528 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3529 | return getService().setProcessMemoryTrimLevel(process, userId, |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3530 | level); |
| 3531 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3532 | throw e.rethrowFromSystemServer(); |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3537 | * Returns a list of application processes that are running on the device. |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 3538 | * |
| 3539 | * <p><b>Note: this method is only intended for debugging or building |
| 3540 | * a user-facing process management UI.</b></p> |
| 3541 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | * @return Returns a list of RunningAppProcessInfo records, or null if there are no |
| 3543 | * running processes (it will not return an empty list). This list ordering is not |
| 3544 | * specified. |
| 3545 | */ |
| 3546 | public List<RunningAppProcessInfo> getRunningAppProcesses() { |
| 3547 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3548 | return getService().getRunningAppProcesses(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3549 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3550 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3551 | } |
| 3552 | } |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 3553 | |
| 3554 | /** |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3555 | * Return the importance of a given package name, based on the processes that are |
| 3556 | * currently running. The return value is one of the importance constants defined |
| 3557 | * in {@link RunningAppProcessInfo}, giving you the highest importance of all the |
| 3558 | * processes that this package has code running inside of. If there are no processes |
| 3559 | * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned. |
Jeff Sharkey | f85ac77 | 2015-05-13 12:52:06 -0700 | [diff] [blame] | 3560 | * @hide |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3561 | */ |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 3562 | @SystemApi @TestApi |
Dianne Hackborn | 9df8f51 | 2016-10-24 17:58:30 -0700 | [diff] [blame] | 3563 | @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS) |
Jeff Sharkey | 910e081 | 2017-04-21 16:29:27 -0600 | [diff] [blame] | 3564 | public @RunningAppProcessInfo.Importance int getPackageImportance(String packageName) { |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3565 | try { |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 3566 | int procState = getService().getPackageProcessState(packageName, |
Adam Lesinski | c30454c | 2015-06-24 13:24:35 -0700 | [diff] [blame] | 3567 | mContext.getOpPackageName()); |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 3568 | return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3569 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3570 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3571 | } |
| 3572 | } |
| 3573 | |
| 3574 | /** |
Dianne Hackborn | 83249ec | 2017-04-12 10:54:03 -0700 | [diff] [blame] | 3575 | * Return the importance of a given uid, based on the processes that are |
| 3576 | * currently running. The return value is one of the importance constants defined |
| 3577 | * in {@link RunningAppProcessInfo}, giving you the highest importance of all the |
| 3578 | * processes that this uid has running. If there are no processes |
| 3579 | * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned. |
| 3580 | * @hide |
| 3581 | */ |
| 3582 | @SystemApi @TestApi |
| 3583 | @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS) |
Jeff Sharkey | 910e081 | 2017-04-21 16:29:27 -0600 | [diff] [blame] | 3584 | public @RunningAppProcessInfo.Importance int getUidImportance(int uid) { |
Dianne Hackborn | 83249ec | 2017-04-12 10:54:03 -0700 | [diff] [blame] | 3585 | try { |
| 3586 | int procState = getService().getUidProcessState(uid, |
| 3587 | mContext.getOpPackageName()); |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 3588 | return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext); |
Dianne Hackborn | 83249ec | 2017-04-12 10:54:03 -0700 | [diff] [blame] | 3589 | } catch (RemoteException e) { |
| 3590 | throw e.rethrowFromSystemServer(); |
| 3591 | } |
| 3592 | } |
| 3593 | |
| 3594 | /** |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 3595 | * Callback to get reports about changes to the importance of a uid. Use with |
| 3596 | * {@link #addOnUidImportanceListener}. |
| 3597 | * @hide |
| 3598 | */ |
| 3599 | @SystemApi @TestApi |
| 3600 | public interface OnUidImportanceListener { |
| 3601 | /** |
| 3602 | * The importance if a given uid has changed. Will be one of the importance |
| 3603 | * values in {@link RunningAppProcessInfo}; |
| 3604 | * {@link RunningAppProcessInfo#IMPORTANCE_GONE IMPORTANCE_GONE} will be reported |
| 3605 | * when the uid is no longer running at all. This callback will happen on a thread |
| 3606 | * from a thread pool, not the main UI thread. |
| 3607 | * @param uid The uid whose importance has changed. |
| 3608 | * @param importance The new importance value as per {@link RunningAppProcessInfo}. |
| 3609 | */ |
Jeff Sharkey | 910e081 | 2017-04-21 16:29:27 -0600 | [diff] [blame] | 3610 | void onUidImportance(int uid, @RunningAppProcessInfo.Importance int importance); |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | /** |
| 3614 | * Start monitoring changes to the imoportance of uids running in the system. |
| 3615 | * @param listener The listener callback that will receive change reports. |
| 3616 | * @param importanceCutpoint The level of importance in which the caller is interested |
| 3617 | * in differences. For example, if {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE} |
| 3618 | * is used here, you will receive a call each time a uids importance transitions between |
| 3619 | * being <= {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE} and |
| 3620 | * > {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}. |
| 3621 | * |
| 3622 | * <p>The caller must hold the {@link android.Manifest.permission#PACKAGE_USAGE_STATS} |
| 3623 | * permission to use this feature.</p> |
| 3624 | * |
| 3625 | * @throws IllegalArgumentException If the listener is already registered. |
| 3626 | * @throws SecurityException If the caller does not hold |
| 3627 | * {@link android.Manifest.permission#PACKAGE_USAGE_STATS}. |
| 3628 | * @hide |
| 3629 | */ |
| 3630 | @SystemApi @TestApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 3631 | @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS) |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 3632 | public void addOnUidImportanceListener(OnUidImportanceListener listener, |
Jeff Sharkey | 910e081 | 2017-04-21 16:29:27 -0600 | [diff] [blame] | 3633 | @RunningAppProcessInfo.Importance int importanceCutpoint) { |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 3634 | synchronized (this) { |
| 3635 | if (mImportanceListeners.containsKey(listener)) { |
| 3636 | throw new IllegalArgumentException("Listener already registered: " + listener); |
| 3637 | } |
| 3638 | // TODO: implement the cut point in the system process to avoid IPCs. |
Makoto Onuki | d7e4058 | 2017-04-13 14:54:56 -0700 | [diff] [blame] | 3639 | UidObserver observer = new UidObserver(listener, mContext); |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 3640 | try { |
| 3641 | getService().registerUidObserver(observer, |
Dianne Hackborn | 5614bf5 | 2016-11-07 17:26:41 -0800 | [diff] [blame] | 3642 | UID_OBSERVER_PROCSTATE | UID_OBSERVER_GONE, |
| 3643 | RunningAppProcessInfo.importanceToProcState(importanceCutpoint), |
| 3644 | mContext.getOpPackageName()); |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 3645 | } catch (RemoteException e) { |
| 3646 | throw e.rethrowFromSystemServer(); |
| 3647 | } |
| 3648 | mImportanceListeners.put(listener, observer); |
| 3649 | } |
| 3650 | } |
| 3651 | |
| 3652 | /** |
| 3653 | * Remove an importance listener that was previously registered with |
| 3654 | * {@link #addOnUidImportanceListener}. |
| 3655 | * |
| 3656 | * @throws IllegalArgumentException If the listener is not registered. |
| 3657 | * @hide |
| 3658 | */ |
| 3659 | @SystemApi @TestApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 3660 | @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS) |
Dianne Hackborn | 058f1e4 | 2016-11-02 17:18:35 -0700 | [diff] [blame] | 3661 | public void removeOnUidImportanceListener(OnUidImportanceListener listener) { |
| 3662 | synchronized (this) { |
| 3663 | UidObserver observer = mImportanceListeners.remove(listener); |
| 3664 | if (observer == null) { |
| 3665 | throw new IllegalArgumentException("Listener not registered: " + listener); |
| 3666 | } |
| 3667 | try { |
| 3668 | getService().unregisterUidObserver(observer); |
| 3669 | } catch (RemoteException e) { |
| 3670 | throw e.rethrowFromSystemServer(); |
| 3671 | } |
| 3672 | } |
| 3673 | } |
| 3674 | |
| 3675 | /** |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 3676 | * Return global memory state information for the calling process. This |
| 3677 | * does not fill in all fields of the {@link RunningAppProcessInfo}. The |
| 3678 | * only fields that will be filled in are |
| 3679 | * {@link RunningAppProcessInfo#pid}, |
| 3680 | * {@link RunningAppProcessInfo#uid}, |
| 3681 | * {@link RunningAppProcessInfo#lastTrimLevel}, |
| 3682 | * {@link RunningAppProcessInfo#importance}, |
| 3683 | * {@link RunningAppProcessInfo#lru}, and |
| 3684 | * {@link RunningAppProcessInfo#importanceReasonCode}. |
| 3685 | */ |
| 3686 | static public void getMyMemoryState(RunningAppProcessInfo outState) { |
| 3687 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3688 | getService().getMyMemoryState(outState); |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 3689 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3690 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 27ff913 | 2012-03-06 14:57:58 -0800 | [diff] [blame] | 3691 | } |
| 3692 | } |
| 3693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3694 | /** |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 3695 | * Return information about the memory usage of one or more processes. |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 3696 | * |
| 3697 | * <p><b>Note: this method is only intended for debugging or building |
| 3698 | * a user-facing process management UI.</b></p> |
| 3699 | * |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 3700 | * @param pids The pids of the processes whose memory usage is to be |
| 3701 | * retrieved. |
| 3702 | * @return Returns an array of memory information, one for each |
| 3703 | * requested pid. |
| 3704 | */ |
| 3705 | public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) { |
| 3706 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3707 | return getService().getProcessMemoryInfo(pids); |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 3708 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3709 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 3710 | } |
| 3711 | } |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3712 | |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 3713 | /** |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 3714 | * @deprecated This is now just a wrapper for |
| 3715 | * {@link #killBackgroundProcesses(String)}; the previous behavior here |
| 3716 | * is no longer available to applications because it allows them to |
| 3717 | * break other applications by removing their alarms, stopping their |
| 3718 | * services, etc. |
| 3719 | */ |
| 3720 | @Deprecated |
| 3721 | public void restartPackage(String packageName) { |
| 3722 | killBackgroundProcesses(packageName); |
| 3723 | } |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3724 | |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 3725 | /** |
| 3726 | * Have the system immediately kill all background processes associated |
| 3727 | * with the given package. This is the same as the kernel killing those |
| 3728 | * processes to reclaim memory; the system will take care of restarting |
| 3729 | * these processes in the future as needed. |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3730 | * |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 3731 | * @param packageName The name of the package whose processes are to |
| 3732 | * be killed. |
| 3733 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 3734 | @RequiresPermission(Manifest.permission.KILL_BACKGROUND_PROCESSES) |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 3735 | public void killBackgroundProcesses(String packageName) { |
| 3736 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3737 | getService().killBackgroundProcesses(packageName, |
Dianne Hackborn | 1676c85 | 2012-09-10 14:52:30 -0700 | [diff] [blame] | 3738 | UserHandle.myUserId()); |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 3739 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3740 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 3741 | } |
| 3742 | } |
Svet Ganov | 019d230 | 2015-05-04 11:07:38 -0700 | [diff] [blame] | 3743 | |
| 3744 | /** |
| 3745 | * Kills the specified UID. |
| 3746 | * @param uid The UID to kill. |
| 3747 | * @param reason The reason for the kill. |
| 3748 | * |
| 3749 | * @hide |
| 3750 | */ |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 3751 | @SystemApi |
Svet Ganov | 019d230 | 2015-05-04 11:07:38 -0700 | [diff] [blame] | 3752 | @RequiresPermission(Manifest.permission.KILL_UID) |
| 3753 | public void killUid(int uid, String reason) { |
| 3754 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3755 | getService().killUid(UserHandle.getAppId(uid), |
Svetoslav | aa41add | 2015-08-06 15:03:55 -0700 | [diff] [blame] | 3756 | UserHandle.getUserId(uid), reason); |
Svet Ganov | 019d230 | 2015-05-04 11:07:38 -0700 | [diff] [blame] | 3757 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3758 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 019d230 | 2015-05-04 11:07:38 -0700 | [diff] [blame] | 3759 | } |
| 3760 | } |
| 3761 | |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 3762 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3763 | * Have the system perform a force stop of everything associated with |
| 3764 | * the given application package. All processes that share its uid |
| 3765 | * will be killed, all services it has running stopped, all activities |
| 3766 | * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED} |
| 3767 | * broadcast will be sent, so that any of its registered alarms can |
| 3768 | * be stopped, notifications removed, etc. |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3769 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3770 | * <p>You must hold the permission |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 3771 | * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3772 | * call this method. |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3773 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3774 | * @param packageName The name of the package to be stopped. |
Zoltan Szatmary-Ban | 0bec95d | 2014-09-23 17:27:17 +0100 | [diff] [blame] | 3775 | * @param userId The user for which the running package is to be stopped. |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 3776 | * |
Dianne Hackborn | 03abb81 | 2010-01-04 18:43:19 -0800 | [diff] [blame] | 3777 | * @hide This is not available to third party applications due to |
| 3778 | * it allowing them to break other applications by stopping their |
| 3779 | * services, removing their alarms, etc. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3780 | */ |
Zoltan Szatmary-Ban | 0bec95d | 2014-09-23 17:27:17 +0100 | [diff] [blame] | 3781 | public void forceStopPackageAsUser(String packageName, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3783 | getService().forceStopPackage(packageName, userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3784 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3785 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3786 | } |
| 3787 | } |
Zoltan Szatmary-Ban | 0bec95d | 2014-09-23 17:27:17 +0100 | [diff] [blame] | 3788 | |
| 3789 | /** |
| 3790 | * @see #forceStopPackageAsUser(String, int) |
| 3791 | * @hide |
| 3792 | */ |
Jeff Schumacher | b8cadef | 2017-01-03 13:52:48 -0800 | [diff] [blame] | 3793 | @SystemApi |
| 3794 | @RequiresPermission(Manifest.permission.FORCE_STOP_PACKAGES) |
Zoltan Szatmary-Ban | 0bec95d | 2014-09-23 17:27:17 +0100 | [diff] [blame] | 3795 | public void forceStopPackage(String packageName) { |
| 3796 | forceStopPackageAsUser(packageName, UserHandle.myUserId()); |
| 3797 | } |
| 3798 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3799 | /** |
| 3800 | * Get the device configuration attributes. |
| 3801 | */ |
| 3802 | public ConfigurationInfo getDeviceConfigurationInfo() { |
| 3803 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3804 | return getService().getDeviceConfigurationInfo(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3805 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3806 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3807 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3808 | } |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 3809 | |
| 3810 | /** |
| 3811 | * Get the preferred density of icons for the launcher. This is used when |
| 3812 | * custom drawables are created (e.g., for shortcuts). |
| 3813 | * |
| 3814 | * @return density in terms of DPI |
| 3815 | */ |
| 3816 | public int getLauncherLargeIconDensity() { |
| 3817 | final Resources res = mContext.getResources(); |
| 3818 | final int density = res.getDisplayMetrics().densityDpi; |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 3819 | final int sw = res.getConfiguration().smallestScreenWidthDp; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 3820 | |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 3821 | if (sw < 600) { |
| 3822 | // Smaller than approx 7" tablets, use the regular icon size. |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 3823 | return density; |
| 3824 | } |
| 3825 | |
| 3826 | switch (density) { |
| 3827 | case DisplayMetrics.DENSITY_LOW: |
| 3828 | return DisplayMetrics.DENSITY_MEDIUM; |
| 3829 | case DisplayMetrics.DENSITY_MEDIUM: |
| 3830 | return DisplayMetrics.DENSITY_HIGH; |
Dianne Hackborn | d0356a1 | 2012-04-26 19:03:12 -0700 | [diff] [blame] | 3831 | case DisplayMetrics.DENSITY_TV: |
| 3832 | return DisplayMetrics.DENSITY_XHIGH; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 3833 | case DisplayMetrics.DENSITY_HIGH: |
| 3834 | return DisplayMetrics.DENSITY_XHIGH; |
| 3835 | case DisplayMetrics.DENSITY_XHIGH: |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 3836 | return DisplayMetrics.DENSITY_XXHIGH; |
| 3837 | case DisplayMetrics.DENSITY_XXHIGH: |
| 3838 | return DisplayMetrics.DENSITY_XHIGH * 2; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 3839 | default: |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 3840 | // The density is some abnormal value. Return some other |
| 3841 | // abnormal value that is a reasonable scaling of it. |
Dianne Hackborn | d0356a1 | 2012-04-26 19:03:12 -0700 | [diff] [blame] | 3842 | return (int)((density*1.5f)+.5f); |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 3843 | } |
| 3844 | } |
| 3845 | |
| 3846 | /** |
| 3847 | * Get the preferred launcher icon size. This is used when custom drawables |
| 3848 | * are created (e.g., for shortcuts). |
| 3849 | * |
| 3850 | * @return dimensions of square icons in terms of pixels |
| 3851 | */ |
| 3852 | public int getLauncherLargeIconSize() { |
Craig Mautner | 2fbd754 | 2014-03-21 09:34:07 -0700 | [diff] [blame] | 3853 | return getLauncherLargeIconSizeInner(mContext); |
| 3854 | } |
| 3855 | |
| 3856 | static int getLauncherLargeIconSizeInner(Context context) { |
| 3857 | final Resources res = context.getResources(); |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 3858 | final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size); |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 3859 | final int sw = res.getConfiguration().smallestScreenWidthDp; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 3860 | |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 3861 | if (sw < 600) { |
| 3862 | // Smaller than approx 7" tablets, use the regular icon size. |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 3863 | return size; |
| 3864 | } |
| 3865 | |
| 3866 | final int density = res.getDisplayMetrics().densityDpi; |
| 3867 | |
| 3868 | switch (density) { |
| 3869 | case DisplayMetrics.DENSITY_LOW: |
| 3870 | return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW; |
| 3871 | case DisplayMetrics.DENSITY_MEDIUM: |
| 3872 | return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM; |
Dianne Hackborn | d0356a1 | 2012-04-26 19:03:12 -0700 | [diff] [blame] | 3873 | case DisplayMetrics.DENSITY_TV: |
| 3874 | return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 3875 | case DisplayMetrics.DENSITY_HIGH: |
| 3876 | return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH; |
| 3877 | case DisplayMetrics.DENSITY_XHIGH: |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 3878 | return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH; |
| 3879 | case DisplayMetrics.DENSITY_XXHIGH: |
| 3880 | return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH; |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 3881 | default: |
Dianne Hackborn | d96e3df | 2012-01-25 15:12:23 -0800 | [diff] [blame] | 3882 | // The density is some abnormal value. Return some other |
| 3883 | // abnormal value that is a reasonable scaling of it. |
Dianne Hackborn | d0356a1 | 2012-04-26 19:03:12 -0700 | [diff] [blame] | 3884 | return (int)((size*1.5f) + .5f); |
Kenny Root | 5ef44b7 | 2011-01-26 17:22:20 -0800 | [diff] [blame] | 3885 | } |
| 3886 | } |
| 3887 | |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 3888 | /** |
| 3889 | * Returns "true" if the user interface is currently being messed with |
| 3890 | * by a monkey. |
| 3891 | */ |
| 3892 | public static boolean isUserAMonkey() { |
| 3893 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3894 | return getService().isUserAMonkey(); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 3895 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3896 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 3897 | } |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 3898 | } |
Brett Chabot | 3b4fcbc | 2011-01-09 13:41:02 -0800 | [diff] [blame] | 3899 | |
| 3900 | /** |
| 3901 | * Returns "true" if device is running in a test harness. |
| 3902 | */ |
| 3903 | public static boolean isRunningInTestHarness() { |
| 3904 | return SystemProperties.getBoolean("ro.test_harness", false); |
| 3905 | } |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 3906 | |
| 3907 | /** |
| 3908 | * Returns the launch count of each installed package. |
| 3909 | * |
| 3910 | * @hide |
| 3911 | */ |
Adam Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 3912 | /*public Map<String, Integer> getAllPackageLaunchCounts() { |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 3913 | try { |
| 3914 | IUsageStats usageStatsService = IUsageStats.Stub.asInterface( |
| 3915 | ServiceManager.getService("usagestats")); |
| 3916 | if (usageStatsService == null) { |
| 3917 | return new HashMap<String, Integer>(); |
| 3918 | } |
| 3919 | |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 3920 | UsageStats.PackageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats( |
| 3921 | ActivityThread.currentPackageName()); |
Peter Visontay | bfcda39 | 2011-03-02 18:53:37 +0000 | [diff] [blame] | 3922 | if (allPkgUsageStats == null) { |
| 3923 | return new HashMap<String, Integer>(); |
| 3924 | } |
| 3925 | |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 3926 | Map<String, Integer> launchCounts = new HashMap<String, Integer>(); |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 3927 | for (UsageStats.PackageStats pkgUsageStats : allPkgUsageStats) { |
| 3928 | launchCounts.put(pkgUsageStats.getPackageName(), pkgUsageStats.getLaunchCount()); |
Peter Visontay | 8d224ca | 2011-02-18 16:39:19 +0000 | [diff] [blame] | 3929 | } |
| 3930 | |
| 3931 | return launchCounts; |
| 3932 | } catch (RemoteException e) { |
| 3933 | Log.w(TAG, "Could not query launch counts", e); |
| 3934 | return new HashMap<String, Integer>(); |
| 3935 | } |
Adam Lesinski | 0debc9a | 2014-07-16 19:09:13 -0700 | [diff] [blame] | 3936 | }*/ |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 3937 | |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 3938 | /** @hide */ |
| 3939 | public static int checkComponentPermission(String permission, int uid, |
| 3940 | int owningUid, boolean exported) { |
| 3941 | // Root, system server get to do everything. |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 3942 | final int appId = UserHandle.getAppId(uid); |
| 3943 | if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) { |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 3944 | return PackageManager.PERMISSION_GRANTED; |
| 3945 | } |
| 3946 | // Isolated processes don't get any permissions. |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 3947 | if (UserHandle.isIsolated(uid)) { |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 3948 | return PackageManager.PERMISSION_DENIED; |
| 3949 | } |
| 3950 | // If there is a uid that owns whatever is being accessed, it has |
| 3951 | // blanket access to it regardless of the permissions it requires. |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 3952 | if (owningUid >= 0 && UserHandle.isSameApp(uid, owningUid)) { |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 3953 | return PackageManager.PERMISSION_GRANTED; |
| 3954 | } |
| 3955 | // If the target is not exported, then nobody else can get to it. |
| 3956 | if (!exported) { |
Dianne Hackborn | be4c1d7 | 2013-09-09 09:44:05 -0700 | [diff] [blame] | 3957 | /* |
| 3958 | RuntimeException here = new RuntimeException("here"); |
| 3959 | here.fillInStackTrace(); |
| 3960 | Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid, |
| 3961 | here); |
| 3962 | */ |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 3963 | return PackageManager.PERMISSION_DENIED; |
| 3964 | } |
| 3965 | if (permission == null) { |
| 3966 | return PackageManager.PERMISSION_GRANTED; |
| 3967 | } |
| 3968 | try { |
| 3969 | return AppGlobals.getPackageManager() |
| 3970 | .checkUidPermission(permission, uid); |
| 3971 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3972 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 3973 | } |
Dianne Hackborn | 5320eb8 | 2012-05-18 12:05:04 -0700 | [diff] [blame] | 3974 | } |
| 3975 | |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3976 | /** @hide */ |
| 3977 | public static int checkUidPermission(String permission, int uid) { |
| 3978 | try { |
| 3979 | return AppGlobals.getPackageManager() |
| 3980 | .checkUidPermission(permission, uid); |
| 3981 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 3982 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3983 | } |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 3984 | } |
| 3985 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 3986 | /** |
| 3987 | * @hide |
| 3988 | * Helper for dealing with incoming user arguments to system service calls. |
| 3989 | * Takes care of checking permissions and converting USER_CURRENT to the |
| 3990 | * actual current user. |
| 3991 | * |
| 3992 | * @param callingPid The pid of the incoming call, as per Binder.getCallingPid(). |
| 3993 | * @param callingUid The uid of the incoming call, as per Binder.getCallingUid(). |
| 3994 | * @param userId The user id argument supplied by the caller -- this is the user |
| 3995 | * they want to run as. |
| 3996 | * @param allowAll If true, we will allow USER_ALL. This means you must be prepared |
| 3997 | * to get a USER_ALL returned and deal with it correctly. If false, |
| 3998 | * an exception will be thrown if USER_ALL is supplied. |
| 3999 | * @param requireFull If true, the caller must hold |
| 4000 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} to be able to run as a |
| 4001 | * different user than their current process; otherwise they must hold |
| 4002 | * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}. |
| 4003 | * @param name Optional textual name of the incoming call; only for generating error messages. |
| 4004 | * @param callerPackage Optional package name of caller; only for error messages. |
| 4005 | * |
| 4006 | * @return Returns the user ID that the call should run as. Will always be a concrete |
| 4007 | * user number, unless <var>allowAll</var> is true in which case it could also be |
| 4008 | * USER_ALL. |
| 4009 | */ |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 4010 | public static int handleIncomingUser(int callingPid, int callingUid, int userId, |
| 4011 | boolean allowAll, boolean requireFull, String name, String callerPackage) { |
| 4012 | if (UserHandle.getUserId(callingUid) == userId) { |
| 4013 | return userId; |
| 4014 | } |
| 4015 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4016 | return getService().handleIncomingUser(callingPid, |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 4017 | callingUid, userId, allowAll, requireFull, name, callerPackage); |
| 4018 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4019 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 4020 | } |
| 4021 | } |
| 4022 | |
Amith Yamasani | 0e8d7d6 | 2014-09-03 13:17:28 -0700 | [diff] [blame] | 4023 | /** |
| 4024 | * Gets the userId of the current foreground user. Requires system permissions. |
| 4025 | * @hide |
| 4026 | */ |
| 4027 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 4028 | @RequiresPermission(anyOf = { |
| 4029 | "android.permission.INTERACT_ACROSS_USERS", |
| 4030 | "android.permission.INTERACT_ACROSS_USERS_FULL" |
| 4031 | }) |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 4032 | public static int getCurrentUser() { |
| 4033 | UserInfo ui; |
| 4034 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4035 | ui = getService().getCurrentUser(); |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 4036 | return ui != null ? ui.id : 0; |
| 4037 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4038 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 4039 | } |
| 4040 | } |
| 4041 | |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 4042 | /** |
Stefan Kuhne | 16045c2 | 2015-06-05 07:18:06 -0700 | [diff] [blame] | 4043 | * @param userid the user's id. Zero indicates the default user. |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 4044 | * @hide |
| 4045 | */ |
| 4046 | public boolean switchUser(int userid) { |
| 4047 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4048 | return getService().switchUser(userid); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 4049 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4050 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 4b2e934 | 2011-03-31 12:38:53 -0700 | [diff] [blame] | 4051 | } |
| 4052 | } |
Dianne Hackborn | 5e03e2c | 2012-09-06 14:21:19 -0700 | [diff] [blame] | 4053 | |
Fyodor Kupolov | b5690bc3 | 2016-03-02 17:50:58 -0800 | [diff] [blame] | 4054 | /** |
| 4055 | * Logs out current current foreground user by switching to the system user and stopping the |
| 4056 | * user being switched from. |
| 4057 | * @hide |
| 4058 | */ |
| 4059 | public static void logoutCurrentUser() { |
| 4060 | int currentUser = ActivityManager.getCurrentUser(); |
| 4061 | if (currentUser != UserHandle.USER_SYSTEM) { |
| 4062 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4063 | getService().switchUser(UserHandle.USER_SYSTEM); |
| 4064 | getService().stopUser(currentUser, /* force= */ false, null); |
Fyodor Kupolov | b5690bc3 | 2016-03-02 17:50:58 -0800 | [diff] [blame] | 4065 | } catch (RemoteException e) { |
| 4066 | e.rethrowFromSystemServer(); |
| 4067 | } |
| 4068 | } |
| 4069 | } |
| 4070 | |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4071 | /** {@hide} */ |
| 4072 | public static final int FLAG_OR_STOPPED = 1 << 0; |
| 4073 | /** {@hide} */ |
Jeff Sharkey | 8924e87 | 2015-11-30 12:52:10 -0700 | [diff] [blame] | 4074 | public static final int FLAG_AND_LOCKED = 1 << 1; |
Jeff Sharkey | 0825ab2 | 2015-12-02 13:04:49 -0700 | [diff] [blame] | 4075 | /** {@hide} */ |
| 4076 | public static final int FLAG_AND_UNLOCKED = 1 << 2; |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 4077 | /** {@hide} */ |
| 4078 | public static final int FLAG_AND_UNLOCKING_OR_UNLOCKED = 1 << 3; |
Jeff Sharkey | e17ac15 | 2015-11-06 22:40:29 -0800 | [diff] [blame] | 4079 | |
Dianne Hackborn | 5e03e2c | 2012-09-06 14:21:19 -0700 | [diff] [blame] | 4080 | /** |
| 4081 | * Return whether the given user is actively running. This means that |
| 4082 | * the user is in the "started" state, not "stopped" -- it is currently |
| 4083 | * allowed to run code through scheduled alarms, receiving broadcasts, |
| 4084 | * etc. A started user may be either the current foreground user or a |
| 4085 | * background user; the result here does not distinguish between the two. |
Dianne Hackborn | 5614bf5 | 2016-11-07 17:26:41 -0800 | [diff] [blame] | 4086 | * @param userId the user's id. Zero indicates the default user. |
Dianne Hackborn | 5e03e2c | 2012-09-06 14:21:19 -0700 | [diff] [blame] | 4087 | * @hide |
| 4088 | */ |
Jeff Sharkey | 9d8a104 | 2015-12-03 17:56:20 -0700 | [diff] [blame] | 4089 | public boolean isUserRunning(int userId) { |
Dianne Hackborn | 5e03e2c | 2012-09-06 14:21:19 -0700 | [diff] [blame] | 4090 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4091 | return getService().isUserRunning(userId, 0); |
Jeff Sharkey | 9d8a104 | 2015-12-03 17:56:20 -0700 | [diff] [blame] | 4092 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4093 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 9d8a104 | 2015-12-03 17:56:20 -0700 | [diff] [blame] | 4094 | } |
| 4095 | } |
| 4096 | |
| 4097 | /** {@hide} */ |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 4098 | public boolean isVrModePackageEnabled(ComponentName component) { |
| 4099 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4100 | return getService().isVrModePackageEnabled(component); |
Ruben Brunk | e24b9a6 | 2016-02-16 21:38:24 -0800 | [diff] [blame] | 4101 | } catch (RemoteException e) { |
| 4102 | throw e.rethrowFromSystemServer(); |
| 4103 | } |
| 4104 | } |
| 4105 | |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 4106 | /** |
| 4107 | * Perform a system dump of various state associated with the given application |
| 4108 | * package name. This call blocks while the dump is being performed, so should |
| 4109 | * not be done on a UI thread. The data will be written to the given file |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 4110 | * descriptor as text. |
Dianne Hackborn | ebc15ef | 2013-10-09 17:36:57 -0700 | [diff] [blame] | 4111 | * @param fd The file descriptor that the dump should be written to. The file |
| 4112 | * descriptor is <em>not</em> closed by this function; the caller continues to |
| 4113 | * own it. |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 4114 | * @param packageName The name of the package that is to be dumped. |
| 4115 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 4116 | @RequiresPermission(Manifest.permission.DUMP) |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 4117 | public void dumpPackageState(FileDescriptor fd, String packageName) { |
| 4118 | dumpPackageStateStatic(fd, packageName); |
| 4119 | } |
| 4120 | |
| 4121 | /** |
| 4122 | * @hide |
| 4123 | */ |
| 4124 | public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) { |
| 4125 | FileOutputStream fout = new FileOutputStream(fd); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 4126 | PrintWriter pw = new FastPrintWriter(fout); |
Dianne Hackborn | ab4a81b | 2014-10-09 17:59:38 -0700 | [diff] [blame] | 4127 | dumpService(pw, fd, "package", new String[] { packageName }); |
| 4128 | pw.println(); |
Dianne Hackborn | daa0d5c | 2013-11-06 16:30:29 -0800 | [diff] [blame] | 4129 | dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] { |
| 4130 | "-a", "package", packageName }); |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 4131 | pw.println(); |
Dianne Hackborn | ab4a81b | 2014-10-09 17:59:38 -0700 | [diff] [blame] | 4132 | dumpService(pw, fd, "meminfo", new String[] { "--local", "--package", packageName }); |
Dianne Hackborn | daa0d5c | 2013-11-06 16:30:29 -0800 | [diff] [blame] | 4133 | pw.println(); |
Dianne Hackborn | ab4a81b | 2014-10-09 17:59:38 -0700 | [diff] [blame] | 4134 | dumpService(pw, fd, ProcessStats.SERVICE_NAME, new String[] { packageName }); |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 4135 | pw.println(); |
Dianne Hackborn | 904a857 | 2013-06-28 18:12:31 -0700 | [diff] [blame] | 4136 | dumpService(pw, fd, "usagestats", new String[] { "--packages", packageName }); |
| 4137 | pw.println(); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 4138 | dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName }); |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 4139 | pw.flush(); |
| 4140 | } |
| 4141 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 4142 | /** |
| 4143 | * @hide |
| 4144 | */ |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4145 | public static boolean isSystemReady() { |
| 4146 | if (!sSystemReady) { |
| 4147 | if (ActivityThread.isSystem()) { |
| 4148 | sSystemReady = |
| 4149 | LocalServices.getService(ActivityManagerInternal.class).isSystemReady(); |
| 4150 | } else { |
| 4151 | // Since this is being called from outside system server, system should be |
| 4152 | // ready by now. |
| 4153 | sSystemReady = true; |
| 4154 | } |
| 4155 | } |
| 4156 | return sSystemReady; |
| 4157 | } |
| 4158 | |
| 4159 | /** |
| 4160 | * @hide |
| 4161 | */ |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 4162 | public static void broadcastStickyIntent(Intent intent, int userId) { |
| 4163 | broadcastStickyIntent(intent, AppOpsManager.OP_NONE, userId); |
| 4164 | } |
| 4165 | |
| 4166 | /** |
| 4167 | * Convenience for sending a sticky broadcast. For internal use only. |
| 4168 | * |
| 4169 | * @hide |
| 4170 | */ |
| 4171 | public static void broadcastStickyIntent(Intent intent, int appOp, int userId) { |
| 4172 | try { |
| 4173 | getService().broadcastIntent( |
| 4174 | null, intent, null, null, Activity.RESULT_OK, null, null, |
| 4175 | null /*permission*/, appOp, null, false, true, userId); |
| 4176 | } catch (RemoteException ex) { |
| 4177 | } |
| 4178 | } |
| 4179 | |
| 4180 | /** |
| 4181 | * @hide |
| 4182 | */ |
| 4183 | public static void noteWakeupAlarm(PendingIntent ps, int sourceUid, String sourcePkg, |
| 4184 | String tag) { |
| 4185 | try { |
| 4186 | getService().noteWakeupAlarm((ps != null) ? ps.getTarget() : null, |
| 4187 | sourceUid, sourcePkg, tag); |
| 4188 | } catch (RemoteException ex) { |
| 4189 | } |
| 4190 | } |
| 4191 | |
| 4192 | /** |
| 4193 | * @hide |
| 4194 | */ |
| 4195 | public static void noteAlarmStart(PendingIntent ps, int sourceUid, String tag) { |
| 4196 | try { |
| 4197 | getService().noteAlarmStart((ps != null) ? ps.getTarget() : null, sourceUid, tag); |
| 4198 | } catch (RemoteException ex) { |
| 4199 | } |
| 4200 | } |
| 4201 | |
| 4202 | /** |
| 4203 | * @hide |
| 4204 | */ |
| 4205 | public static void noteAlarmFinish(PendingIntent ps, int sourceUid, String tag) { |
| 4206 | try { |
| 4207 | getService().noteAlarmFinish((ps != null) ? ps.getTarget() : null, sourceUid, tag); |
| 4208 | } catch (RemoteException ex) { |
| 4209 | } |
| 4210 | } |
| 4211 | |
| 4212 | /** |
| 4213 | * @hide |
| 4214 | */ |
| 4215 | public static IActivityManager getService() { |
| 4216 | return IActivityManagerSingleton.get(); |
| 4217 | } |
| 4218 | |
| 4219 | private static final Singleton<IActivityManager> IActivityManagerSingleton = |
| 4220 | new Singleton<IActivityManager>() { |
| 4221 | @Override |
| 4222 | protected IActivityManager create() { |
| 4223 | final IBinder b = ServiceManager.getService(Context.ACTIVITY_SERVICE); |
| 4224 | final IActivityManager am = IActivityManager.Stub.asInterface(b); |
| 4225 | return am; |
| 4226 | } |
| 4227 | }; |
| 4228 | |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 4229 | private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) { |
| 4230 | pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":"); |
| 4231 | IBinder service = ServiceManager.checkService(name); |
| 4232 | if (service == null) { |
| 4233 | pw.println(" (Service not found)"); |
| 4234 | return; |
| 4235 | } |
| 4236 | TransferPipe tp = null; |
| 4237 | try { |
| 4238 | pw.flush(); |
| 4239 | tp = new TransferPipe(); |
| 4240 | tp.setBufferPrefix(" "); |
Dianne Hackborn | daa0d5c | 2013-11-06 16:30:29 -0800 | [diff] [blame] | 4241 | service.dumpAsync(tp.getWriteFd().getFileDescriptor(), args); |
Dianne Hackborn | ab4a81b | 2014-10-09 17:59:38 -0700 | [diff] [blame] | 4242 | tp.go(fd, 10000); |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 4243 | } catch (Throwable e) { |
| 4244 | if (tp != null) { |
| 4245 | tp.kill(); |
| 4246 | } |
| 4247 | pw.println("Failure dumping service:"); |
| 4248 | e.printStackTrace(pw); |
| 4249 | } |
| 4250 | } |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4251 | |
| 4252 | /** |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 4253 | * Request that the system start watching for the calling process to exceed a pss |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 4254 | * size as given here. Once called, the system will look for any occasions where it |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 4255 | * sees the associated process with a larger pss size and, when this happens, automatically |
| 4256 | * pull a heap dump from it and allow the user to share the data. Note that this request |
| 4257 | * continues running even if the process is killed and restarted. To remove the watch, |
| 4258 | * use {@link #clearWatchHeapLimit()}. |
| 4259 | * |
Dianne Hackborn | ece0f4f | 2015-06-11 13:29:01 -0700 | [diff] [blame] | 4260 | * <p>This API only work if the calling process has been marked as |
| 4261 | * {@link ApplicationInfo#FLAG_DEBUGGABLE} or this is running on a debuggable |
| 4262 | * (userdebug or eng) build.</p> |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 4263 | * |
| 4264 | * <p>Callers can optionally implement {@link #ACTION_REPORT_HEAP_LIMIT} to directly |
| 4265 | * handle heap limit reports themselves.</p> |
| 4266 | * |
| 4267 | * @param pssSize The size in bytes to set the limit at. |
| 4268 | */ |
| 4269 | public void setWatchHeapLimit(long pssSize) { |
| 4270 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4271 | getService().setDumpHeapDebugLimit(null, 0, pssSize, |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 4272 | mContext.getPackageName()); |
| 4273 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4274 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 4275 | } |
| 4276 | } |
| 4277 | |
| 4278 | /** |
| 4279 | * Action an app can implement to handle reports from {@link #setWatchHeapLimit(long)}. |
| 4280 | * If your package has an activity handling this action, it will be launched with the |
| 4281 | * heap data provided to it the same way as {@link Intent#ACTION_SEND}. Note that to |
| 4282 | * match the activty must support this action and a MIME type of "*/*". |
| 4283 | */ |
| 4284 | public static final String ACTION_REPORT_HEAP_LIMIT = "android.app.action.REPORT_HEAP_LIMIT"; |
| 4285 | |
| 4286 | /** |
| 4287 | * Clear a heap watch limit previously set by {@link #setWatchHeapLimit(long)}. |
| 4288 | */ |
| 4289 | public void clearWatchHeapLimit() { |
| 4290 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4291 | getService().setDumpHeapDebugLimit(null, 0, 0, null); |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 4292 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4293 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 4294 | } |
| 4295 | } |
| 4296 | |
| 4297 | /** |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4298 | * @hide |
| 4299 | */ |
| 4300 | public void startLockTaskMode(int taskId) { |
| 4301 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4302 | getService().startLockTaskModeById(taskId); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4303 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4304 | throw e.rethrowFromSystemServer(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4305 | } |
| 4306 | } |
| 4307 | |
| 4308 | /** |
| 4309 | * @hide |
| 4310 | */ |
| 4311 | public void stopLockTaskMode() { |
| 4312 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4313 | getService().stopLockTaskMode(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4314 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4315 | throw e.rethrowFromSystemServer(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4316 | } |
| 4317 | } |
| 4318 | |
| 4319 | /** |
Jason Monk | 386c94f | 2014-07-14 16:42:24 -0400 | [diff] [blame] | 4320 | * Return whether currently in lock task mode. When in this mode |
| 4321 | * no new tasks can be created or switched to. |
| 4322 | * |
| 4323 | * @see Activity#startLockTask() |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 4324 | * |
| 4325 | * @deprecated Use {@link #getLockTaskModeState} instead. |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4326 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 4327 | @Deprecated |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4328 | public boolean isInLockTaskMode() { |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 4329 | return getLockTaskModeState() != LOCK_TASK_MODE_NONE; |
| 4330 | } |
| 4331 | |
| 4332 | /** |
| 4333 | * Return the current state of task locking. The three possible outcomes |
| 4334 | * are {@link #LOCK_TASK_MODE_NONE}, {@link #LOCK_TASK_MODE_LOCKED} |
| 4335 | * and {@link #LOCK_TASK_MODE_PINNED}. |
| 4336 | * |
| 4337 | * @see Activity#startLockTask() |
| 4338 | */ |
| 4339 | public int getLockTaskModeState() { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4340 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4341 | return getService().getLockTaskModeState(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4342 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4343 | throw e.rethrowFromSystemServer(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4344 | } |
| 4345 | } |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 4346 | |
| 4347 | /** |
Srinath Sridharan | e535a58 | 2016-06-27 18:13:47 -0700 | [diff] [blame] | 4348 | * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads. Only one |
| 4349 | * thread can be a VR thread in a process at a time, and that thread may be subject to |
| 4350 | * restrictions on the amount of time it can run. |
| 4351 | * |
Craig Donner | dc4796c | 2017-03-08 09:51:47 -0800 | [diff] [blame] | 4352 | * If persistent VR mode is set, whatever thread has been granted aggressive scheduling via this |
| 4353 | * method will return to normal operation, and calling this method will do nothing while |
| 4354 | * persistent VR mode is enabled. |
| 4355 | * |
Srinath Sridharan | e535a58 | 2016-06-27 18:13:47 -0700 | [diff] [blame] | 4356 | * To reset the VR thread for an application, a tid of 0 can be passed. |
| 4357 | * |
| 4358 | * @see android.os.Process#myTid() |
| 4359 | * @param tid tid of the VR thread |
| 4360 | */ |
| 4361 | public static void setVrThread(int tid) { |
| 4362 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 4363 | getService().setVrThread(tid); |
Srinath Sridharan | e535a58 | 2016-06-27 18:13:47 -0700 | [diff] [blame] | 4364 | } catch (RemoteException e) { |
| 4365 | // pass |
| 4366 | } |
| 4367 | } |
| 4368 | |
| 4369 | /** |
Craig Donner | dc4796c | 2017-03-08 09:51:47 -0800 | [diff] [blame] | 4370 | * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads that persist |
Jeff Sharkey | 910e081 | 2017-04-21 16:29:27 -0600 | [diff] [blame] | 4371 | * beyond a single process. Only one thread can be a |
Craig Donner | dc4796c | 2017-03-08 09:51:47 -0800 | [diff] [blame] | 4372 | * persistent VR thread at a time, and that thread may be subject to restrictions on the amount |
| 4373 | * of time it can run. Calling this method will disable aggressive scheduling for non-persistent |
| 4374 | * VR threads set via {@link #setVrThread}. If persistent VR mode is disabled then the |
| 4375 | * persistent VR thread loses its new scheduling priority; this method must be called again to |
| 4376 | * set the persistent thread. |
| 4377 | * |
| 4378 | * To reset the persistent VR thread, a tid of 0 can be passed. |
| 4379 | * |
| 4380 | * @see android.os.Process#myTid() |
| 4381 | * @param tid tid of the VR thread |
| 4382 | * @hide |
| 4383 | */ |
| 4384 | @RequiresPermission(Manifest.permission.RESTRICTED_VR_ACCESS) |
| 4385 | public static void setPersistentVrThread(int tid) { |
| 4386 | try { |
| 4387 | getService().setPersistentVrThread(tid); |
| 4388 | } catch (RemoteException e) { |
| 4389 | // pass |
| 4390 | } |
| 4391 | } |
| 4392 | |
| 4393 | /** |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 4394 | * The AppTask allows you to manage your own application's tasks. |
| 4395 | * See {@link android.app.ActivityManager#getAppTasks()} |
| 4396 | */ |
| 4397 | public static class AppTask { |
| 4398 | private IAppTask mAppTaskImpl; |
| 4399 | |
| 4400 | /** @hide */ |
| 4401 | public AppTask(IAppTask task) { |
| 4402 | mAppTaskImpl = task; |
| 4403 | } |
| 4404 | |
| 4405 | /** |
| 4406 | * Finishes all activities in this task and removes it from the recent tasks list. |
| 4407 | */ |
| 4408 | public void finishAndRemoveTask() { |
| 4409 | try { |
| 4410 | mAppTaskImpl.finishAndRemoveTask(); |
| 4411 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4412 | throw e.rethrowFromSystemServer(); |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 4413 | } |
| 4414 | } |
| 4415 | |
| 4416 | /** |
| 4417 | * Get the RecentTaskInfo associated with this task. |
| 4418 | * |
| 4419 | * @return The RecentTaskInfo for this task, or null if the task no longer exists. |
| 4420 | */ |
| 4421 | public RecentTaskInfo getTaskInfo() { |
| 4422 | try { |
| 4423 | return mAppTaskImpl.getTaskInfo(); |
| 4424 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4425 | throw e.rethrowFromSystemServer(); |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 4426 | } |
| 4427 | } |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 4428 | |
| 4429 | /** |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4430 | * Bring this task to the foreground. If it contains activities, they will be |
| 4431 | * brought to the foreground with it and their instances re-created if needed. |
| 4432 | * If it doesn't contain activities, the root activity of the task will be |
| 4433 | * re-launched. |
| 4434 | */ |
| 4435 | public void moveToFront() { |
| 4436 | try { |
| 4437 | mAppTaskImpl.moveToFront(); |
| 4438 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4439 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4440 | } |
| 4441 | } |
| 4442 | |
| 4443 | /** |
| 4444 | * Start an activity in this task. Brings the task to the foreground. If this task |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 4445 | * is not currently active (that is, its id < 0), then a new activity for the given |
| 4446 | * Intent will be launched as the root of the task and the task brought to the |
| 4447 | * foreground. Otherwise, if this task is currently active and the Intent does not specify |
| 4448 | * an activity to launch in a new task, then a new activity for the given Intent will |
| 4449 | * be launched on top of the task and the task brought to the foreground. If this |
| 4450 | * task is currently active and the Intent specifies {@link Intent#FLAG_ACTIVITY_NEW_TASK} |
| 4451 | * or would otherwise be launched in to a new task, then the activity not launched but |
| 4452 | * this task be brought to the foreground and a new intent delivered to the top |
| 4453 | * activity if appropriate. |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4454 | * |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 4455 | * <p>In other words, you generally want to use an Intent here that does not specify |
| 4456 | * {@link Intent#FLAG_ACTIVITY_NEW_TASK} or {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT}, |
| 4457 | * and let the system do the right thing.</p> |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4458 | * |
| 4459 | * @param intent The Intent describing the new activity to be launched on the task. |
| 4460 | * @param options Optional launch options. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 4461 | * |
| 4462 | * @see Activity#startActivity(android.content.Intent, android.os.Bundle) |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4463 | */ |
| 4464 | public void startActivity(Context context, Intent intent, Bundle options) { |
| 4465 | ActivityThread thread = ActivityThread.currentActivityThread(); |
| 4466 | thread.getInstrumentation().execStartActivityFromAppTask(context, |
| 4467 | thread.getApplicationThread(), mAppTaskImpl, intent, options); |
| 4468 | } |
| 4469 | |
| 4470 | /** |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 4471 | * Modify the {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag in the root |
| 4472 | * Intent of this AppTask. |
| 4473 | * |
| 4474 | * @param exclude If true, {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} will |
| 4475 | * be set; otherwise, it will be cleared. |
| 4476 | */ |
| 4477 | public void setExcludeFromRecents(boolean exclude) { |
| 4478 | try { |
| 4479 | mAppTaskImpl.setExcludeFromRecents(exclude); |
| 4480 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 4481 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | aec68bb | 2014-08-20 15:25:13 -0700 | [diff] [blame] | 4482 | } |
| 4483 | } |
Winson Chung | 1147c40 | 2014-05-14 11:05:00 -0700 | [diff] [blame] | 4484 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4485 | } |