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