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