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