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