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