ActivityManager.java revision ae12dae13a58695653e6918124ca68cd8dcbf54e
1effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch/* 2effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * Copyright (C) 2007 The Android Open Source Project 3effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * 4010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * Licensed under the Apache License, Version 2.0 (the "License"); 5010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * you may not use this file except in compliance with the License. 6effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * You may obtain a copy of the License at 7010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * 8effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * http://www.apache.org/licenses/LICENSE-2.0 95f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) * 10effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * Unless required by applicable law or agreed to in writing, software 11effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * distributed under the License is distributed on an "AS IS" BASIS, 125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * See the License for the specific language governing permissions and 14effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * limitations under the License. 155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) */ 16effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 17effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochpackage android.app; 18effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 19effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.annotation.NonNull; 20effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.annotation.Nullable; 21effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.annotation.SystemApi; 22effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.graphics.Canvas; 23effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.graphics.Matrix; 246e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)import android.graphics.Point; 25effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.os.BatteryStats; 26effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.os.IBinder; 27effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.os.ParcelFileDescriptor; 28effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 29effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport com.android.internal.app.ProcessStats; 305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)import com.android.internal.os.TransferPipe; 31effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport com.android.internal.util.FastPrintWriter; 32effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 33effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.content.ComponentName; 345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)import android.content.Context; 35effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.content.Intent; 36effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.content.pm.ApplicationInfo; 37effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.content.pm.ConfigurationInfo; 38effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.content.pm.IPackageDataObserver; 39effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.content.pm.PackageManager; 406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)import android.content.pm.UserInfo; 41effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.content.res.Resources; 42effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.graphics.Bitmap; 43effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.graphics.Color; 44effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.graphics.Rect; 45effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.os.Bundle; 46effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.os.Debug; 475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)import android.os.Handler; 48effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.os.Parcel; 49effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.os.Parcelable; 50effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.os.Process; 51effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.os.RemoteException; 52effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.os.ServiceManager; 535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)import android.os.SystemProperties; 54effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.os.UserHandle; 55effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.text.TextUtils; 56effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.util.DisplayMetrics; 57effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.util.Size; 58effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport android.util.Slog; 59effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport org.xmlpull.v1.XmlSerializer; 60effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 61effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport java.io.FileDescriptor; 62effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport java.io.FileOutputStream; 63effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport java.io.IOException; 64effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport java.io.PrintWriter; 65effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport java.util.ArrayList; 66effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochimport java.util.List; 676e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 68effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch/** 69effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * Interact with the overall activities running in the system. 70effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch */ 71effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochpublic class ActivityManager { 72effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch private static String TAG = "ActivityManager"; 73effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch private static boolean localLOGV = false; 74effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 75effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch private static int gMaxRecentTasks = -1; 76effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 77effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch private final Context mContext; 78effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch private final Handler mHandler; 79effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 80effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** 81effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * <a href="{@docRoot}guide/topics/manifest/meta-data-element.html">{@code 82effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * <meta-data>}</a> name for a 'home' Activity that declares a package that is to be 83effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * uninstalled in lieu of the declaring one. The package named here must be 84effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * signed with the same certificate as the one declaring the {@code <meta-data>}. 85effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch */ 86effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final String META_HOME_ALTERNATE = "android.app.home.alternate"; 87effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 88effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** 89effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * Result for IActivityManager.startActivity: trying to start an activity under voice 90effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * control when that activity does not support the VOICE category. 91effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * @hide 92effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch */ 93effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int START_NOT_VOICE_COMPATIBLE = -7; 94effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 95effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** 96effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * Result for IActivityManager.startActivity: an error where the 97effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * start had to be canceled. 98effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * @hide 99cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) */ 100effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int START_CANCELED = -6; 101effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 102effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** 103effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * Result for IActivityManager.startActivity: an error where the 104effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * thing being started is not an activity. 105effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * @hide 106effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch */ 107effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int START_NOT_ACTIVITY = -5; 108effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 109effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** 110effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * Result for IActivityManager.startActivity: an error where the 111effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * caller does not have permission to start the activity. 112effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * @hide 113effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch */ 114effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int START_PERMISSION_DENIED = -4; 1151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /** 1171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * Result for IActivityManager.startActivity: an error where the 1181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * caller has requested both to forward a result and to receive 1191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * a result. 1201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * @hide 1211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci */ 1221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci public static final int START_FORWARD_AND_REQUEST_CONFLICT = -3; 1231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /** 125effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * Result for IActivityManager.startActivity: an error where the 126effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * requested class is not found. 127effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * @hide 128effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch */ 129effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int START_CLASS_NOT_FOUND = -2; 130effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 131effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** 132effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * Result for IActivityManager.startActivity: an error where the 133effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * given Intent could not be resolved to an activity. 134effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * @hide 135effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch */ 136effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int START_INTENT_NOT_RESOLVED = -1; 137effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 138effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** 139010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * Result for IActivityManaqer.startActivity: the activity was started 140010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * successfully as normal. 141010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * @hide 142010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) */ 143010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public static final int START_SUCCESS = 0; 144010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 145010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) /** 146010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * Result for IActivityManaqer.startActivity: the caller asked that the Intent not 147010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * be executed if it is the recipient, and that is indeed the case. 148010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * @hide 149010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) */ 150010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public static final int START_RETURN_INTENT_TO_CALLER = 1; 151010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 152010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) /** 153010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * Result for IActivityManaqer.startActivity: activity wasn't really started, but 154010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * a task was simply brought to the foreground. 155010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * @hide 156010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) */ 157010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public static final int START_TASK_TO_FRONT = 2; 158010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 159010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) /** 160010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * Result for IActivityManaqer.startActivity: activity wasn't really started, but 161010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * the given Intent was given to the existing top activity. 162010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * @hide 163010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) */ 164010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public static final int START_DELIVERED_TO_TOP = 3; 165010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 166010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) /** 167010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * Result for IActivityManaqer.startActivity: request was canceled because 168010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * app switches are temporarily canceled to ensure the user's last request 169010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * (such as pressing home) is performed. 170010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * @hide 171010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) */ 172010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public static final int START_SWITCHES_CANCELED = 4; 173010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 174010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) /** 175010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * Result for IActivityManaqer.startActivity: a new activity was attempted to be started 176010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * while in Lock Task Mode. 177010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * @hide 178010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) */ 179010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public static final int START_RETURN_LOCK_TASK_MODE_VIOLATION = 5; 180010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 181010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) /** 182010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * Flag for IActivityManaqer.startActivity: do special start mode where 183010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * a new activity is launched only if it is needed. 184010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * @hide 185010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) */ 186010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0; 187010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 188010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) /** 189010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * Flag for IActivityManaqer.startActivity: launch the app for 190010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * debugging. 191010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * @hide 192010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) */ 193010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public static final int START_FLAG_DEBUG = 1<<1; 194010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 195010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) /** 196010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * Flag for IActivityManaqer.startActivity: launch the app for 197010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * OpenGL tracing. 198010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * @hide 199010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) */ 200010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public static final int START_FLAG_OPENGL_TRACES = 1<<2; 201010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 202010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) /** 203010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * Result for IActivityManaqer.broadcastIntent: success! 204010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * @hide 205010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) */ 206010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public static final int BROADCAST_SUCCESS = 0; 207010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 208010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) /** 209010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * Result for IActivityManaqer.broadcastIntent: attempt to broadcast 210010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * a sticky intent without appropriate permission. 211010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * @hide 212010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) */ 213010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1; 214010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 215010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) /** 216010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * Type for IActivityManaqer.getIntentSender: this PendingIntent is 217010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * for a sendBroadcast operation. 218010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * @hide 219010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) */ 220010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public static final int INTENT_SENDER_BROADCAST = 1; 221010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 2221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /** 223010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * Type for IActivityManaqer.getIntentSender: this PendingIntent is 224010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * for a startActivity operation. 225010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) * @hide 2261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci */ 2271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci public static final int INTENT_SENDER_ACTIVITY = 2; 2281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 2291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /** 2301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * Type for IActivityManaqer.getIntentSender: this PendingIntent is 2311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * for an activity result operation. 2321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * @hide 2331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci */ 2341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci public static final int INTENT_SENDER_ACTIVITY_RESULT = 3; 2351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 2361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /** 2371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * Type for IActivityManaqer.getIntentSender: this PendingIntent is 2381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * for a startService operation. 2391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * @hide 2401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci */ 2411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci public static final int INTENT_SENDER_SERVICE = 4; 2421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 2431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /** @hide User operation call: success! */ 2441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci public static final int USER_OP_SUCCESS = 0; 2451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 246effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** @hide User operation call: given user id is not known. */ 247effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int USER_OP_UNKNOWN_USER = -1; 248effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 249effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** @hide User operation call: given user id is the current user, can't be stopped. */ 250effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int USER_OP_IS_CURRENT = -2; 251effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 252effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** @hide Process is a persistent system process. */ 253effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int PROCESS_STATE_PERSISTENT = 0; 254effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 255effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** @hide Process is a persistent system process and is doing UI. */ 256effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int PROCESS_STATE_PERSISTENT_UI = 1; 257effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 258effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** @hide Process is hosting the current top activities. Note that this covers 259effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * all activities that are visible to the user. */ 260effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int PROCESS_STATE_TOP = 2; 261effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 262effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** @hide Process is important to the user, and something they are aware of. */ 263effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 3; 264effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 265effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** @hide Process is important to the user, but not something they are aware of. */ 266effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 4; 267effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 268effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** @hide Process is in the background running a backup/restore operation. */ 269effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int PROCESS_STATE_BACKUP = 5; 270effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 271effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** @hide Process is in the background, but it can't restore its state so we want 272effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * to try to avoid killing it. */ 273effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int PROCESS_STATE_HEAVY_WEIGHT = 6; 274effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 275effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** @hide Process is in the background running a service. Unlike oom_adj, this level 276effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * is used for both the normal running in background state and the executing 2775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) * operations state. */ 278effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public static final int PROCESS_STATE_SERVICE = 7; 279effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 280effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch /** @hide Process is in the background running a receiver. Note that from the 281effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch * perspective of oom_adj receivers run at a higher foreground level, but for our 282 * prioritization here that is not necessary and putting them below services means 283 * many fewer changes in some process states as they receive broadcasts. */ 284 public static final int PROCESS_STATE_RECEIVER = 8; 285 286 /** @hide Process is in the background but hosts the home activity. */ 287 public static final int PROCESS_STATE_HOME = 9; 288 289 /** @hide Process is in the background but hosts the last shown activity. */ 290 public static final int PROCESS_STATE_LAST_ACTIVITY = 10; 291 292 /** @hide Process is being cached for later use and contains activities. */ 293 public static final int PROCESS_STATE_CACHED_ACTIVITY = 11; 294 295 /** @hide Process is being cached for later use and is a client of another cached 296 * process that contains activities. */ 297 public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 12; 298 299 /** @hide Process is being cached for later use and is empty. */ 300 public static final int PROCESS_STATE_CACHED_EMPTY = 13; 301 302 Point mAppTaskThumbnailSize; 303 304 /*package*/ ActivityManager(Context context, Handler handler) { 305 mContext = context; 306 mHandler = handler; 307 } 308 309 /** 310 * Screen compatibility mode: the application most always run in 311 * compatibility mode. 312 * @hide 313 */ 314 public static final int COMPAT_MODE_ALWAYS = -1; 315 316 /** 317 * Screen compatibility mode: the application can never run in 318 * compatibility mode. 319 * @hide 320 */ 321 public static final int COMPAT_MODE_NEVER = -2; 322 323 /** 324 * Screen compatibility mode: unknown. 325 * @hide 326 */ 327 public static final int COMPAT_MODE_UNKNOWN = -3; 328 329 /** 330 * Screen compatibility mode: the application currently has compatibility 331 * mode disabled. 332 * @hide 333 */ 334 public static final int COMPAT_MODE_DISABLED = 0; 335 336 /** 337 * Screen compatibility mode: the application currently has compatibility 338 * mode enabled. 339 * @hide 340 */ 341 public static final int COMPAT_MODE_ENABLED = 1; 342 343 /** 344 * Screen compatibility mode: request to toggle the application's 345 * compatibility mode. 346 * @hide 347 */ 348 public static final int COMPAT_MODE_TOGGLE = 2; 349 350 /** @hide */ 351 public int getFrontActivityScreenCompatMode() { 352 try { 353 return ActivityManagerNative.getDefault().getFrontActivityScreenCompatMode(); 354 } catch (RemoteException e) { 355 // System dead, we will be dead too soon! 356 return 0; 357 } 358 } 359 360 /** @hide */ 361 public void setFrontActivityScreenCompatMode(int mode) { 362 try { 363 ActivityManagerNative.getDefault().setFrontActivityScreenCompatMode(mode); 364 } catch (RemoteException e) { 365 // System dead, we will be dead too soon! 366 } 367 } 368 369 /** @hide */ 370 public int getPackageScreenCompatMode(String packageName) { 371 try { 372 return ActivityManagerNative.getDefault().getPackageScreenCompatMode(packageName); 373 } catch (RemoteException e) { 374 // System dead, we will be dead too soon! 375 return 0; 376 } 377 } 378 379 /** @hide */ 380 public void setPackageScreenCompatMode(String packageName, int mode) { 381 try { 382 ActivityManagerNative.getDefault().setPackageScreenCompatMode(packageName, mode); 383 } catch (RemoteException e) { 384 // System dead, we will be dead too soon! 385 } 386 } 387 388 /** @hide */ 389 public boolean getPackageAskScreenCompat(String packageName) { 390 try { 391 return ActivityManagerNative.getDefault().getPackageAskScreenCompat(packageName); 392 } catch (RemoteException e) { 393 // System dead, we will be dead too soon! 394 return false; 395 } 396 } 397 398 /** @hide */ 399 public void setPackageAskScreenCompat(String packageName, boolean ask) { 400 try { 401 ActivityManagerNative.getDefault().setPackageAskScreenCompat(packageName, ask); 402 } catch (RemoteException e) { 403 // System dead, we will be dead too soon! 404 } 405 } 406 407 /** 408 * Return the approximate per-application memory class of the current 409 * device. This gives you an idea of how hard a memory limit you should 410 * impose on your application to let the overall system work best. The 411 * returned value is in megabytes; the baseline Android memory class is 412 * 16 (which happens to be the Java heap limit of those devices); some 413 * device with more memory may return 24 or even higher numbers. 414 */ 415 public int getMemoryClass() { 416 return staticGetMemoryClass(); 417 } 418 419 /** @hide */ 420 static public int staticGetMemoryClass() { 421 // Really brain dead right now -- just take this from the configured 422 // vm heap size, and assume it is in megabytes and thus ends with "m". 423 String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", ""); 424 if (vmHeapSize != null && !"".equals(vmHeapSize)) { 425 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1)); 426 } 427 return staticGetLargeMemoryClass(); 428 } 429 430 /** 431 * Return the approximate per-application memory class of the current 432 * device when an application is running with a large heap. This is the 433 * space available for memory-intensive applications; most applications 434 * should not need this amount of memory, and should instead stay with the 435 * {@link #getMemoryClass()} limit. The returned value is in megabytes. 436 * This may be the same size as {@link #getMemoryClass()} on memory 437 * constrained devices, or it may be significantly larger on devices with 438 * a large amount of available RAM. 439 * 440 * <p>The is the size of the application's Dalvik heap if it has 441 * specified <code>android:largeHeap="true"</code> in its manifest. 442 */ 443 public int getLargeMemoryClass() { 444 return staticGetLargeMemoryClass(); 445 } 446 447 /** @hide */ 448 static public int staticGetLargeMemoryClass() { 449 // Really brain dead right now -- just take this from the configured 450 // vm heap size, and assume it is in megabytes and thus ends with "m". 451 String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m"); 452 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length() - 1)); 453 } 454 455 /** 456 * Returns true if this is a low-RAM device. Exactly whether a device is low-RAM 457 * is ultimately up to the device configuration, but currently it generally means 458 * something in the class of a 512MB device with about a 800x480 or less screen. 459 * This is mostly intended to be used by apps to determine whether they should turn 460 * off certain features that require more RAM. 461 */ 462 public boolean isLowRamDevice() { 463 return isLowRamDeviceStatic(); 464 } 465 466 /** @hide */ 467 public static boolean isLowRamDeviceStatic() { 468 return "true".equals(SystemProperties.get("ro.config.low_ram", "false")); 469 } 470 471 /** 472 * Used by persistent processes to determine if they are running on a 473 * higher-end device so should be okay using hardware drawing acceleration 474 * (which tends to consume a lot more RAM). 475 * @hide 476 */ 477 static public boolean isHighEndGfx() { 478 return !isLowRamDeviceStatic() && 479 !Resources.getSystem().getBoolean(com.android.internal.R.bool.config_avoidGfxAccel); 480 } 481 482 /** 483 * Return the maximum number of recents entries that we will maintain and show. 484 * @hide 485 */ 486 static public int getMaxRecentTasksStatic() { 487 if (gMaxRecentTasks < 0) { 488 return gMaxRecentTasks = isLowRamDeviceStatic() ? 50 : 100; 489 } 490 return gMaxRecentTasks; 491 } 492 493 /** 494 * Return the default limit on the number of recents that an app can make. 495 * @hide 496 */ 497 static public int getDefaultAppRecentsLimitStatic() { 498 return getMaxRecentTasksStatic() / 6; 499 } 500 501 /** 502 * Return the maximum limit on the number of recents that an app can make. 503 * @hide 504 */ 505 static public int getMaxAppRecentsLimitStatic() { 506 return getMaxRecentTasksStatic() / 2; 507 } 508 509 /** 510 * Information you can set and retrieve about the current activity within the recent task list. 511 */ 512 public static class TaskDescription implements Parcelable { 513 /** @hide */ 514 public static final String ATTR_TASKDESCRIPTION_PREFIX = "task_description_"; 515 private static final String ATTR_TASKDESCRIPTIONLABEL = 516 ATTR_TASKDESCRIPTION_PREFIX + "label"; 517 private static final String ATTR_TASKDESCRIPTIONCOLOR = 518 ATTR_TASKDESCRIPTION_PREFIX + "color"; 519 private static final String ATTR_TASKDESCRIPTIONICONFILENAME = 520 ATTR_TASKDESCRIPTION_PREFIX + "icon_filename"; 521 522 private String mLabel; 523 private Bitmap mIcon; 524 private String mIconFilename; 525 private int mColorPrimary; 526 527 /** 528 * Creates the TaskDescription to the specified values. 529 * 530 * @param label A label and description of the current state of this task. 531 * @param icon An icon that represents the current state of this task. 532 * @param colorPrimary A color to override the theme's primary color. This color must be opaque. 533 */ 534 public TaskDescription(String label, Bitmap icon, int colorPrimary) { 535 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) { 536 throw new RuntimeException("A TaskDescription's primary color should be opaque"); 537 } 538 539 mLabel = label; 540 mIcon = icon; 541 mColorPrimary = colorPrimary; 542 } 543 544 /** @hide */ 545 public TaskDescription(String label, int colorPrimary, String iconFilename) { 546 this(label, null, colorPrimary); 547 mIconFilename = iconFilename; 548 } 549 550 /** 551 * Creates the TaskDescription to the specified values. 552 * 553 * @param label A label and description of the current state of this activity. 554 * @param icon An icon that represents the current state of this activity. 555 */ 556 public TaskDescription(String label, Bitmap icon) { 557 this(label, icon, 0); 558 } 559 560 /** 561 * Creates the TaskDescription to the specified values. 562 * 563 * @param label A label and description of the current state of this activity. 564 */ 565 public TaskDescription(String label) { 566 this(label, null, 0); 567 } 568 569 /** 570 * Creates an empty TaskDescription. 571 */ 572 public TaskDescription() { 573 this(null, null, 0); 574 } 575 576 /** 577 * Creates a copy of another TaskDescription. 578 */ 579 public TaskDescription(TaskDescription td) { 580 mLabel = td.mLabel; 581 mIcon = td.mIcon; 582 mColorPrimary = td.mColorPrimary; 583 mIconFilename = td.mIconFilename; 584 } 585 586 private TaskDescription(Parcel source) { 587 readFromParcel(source); 588 } 589 590 /** 591 * Sets the label for this task description. 592 * @hide 593 */ 594 public void setLabel(String label) { 595 mLabel = label; 596 } 597 598 /** 599 * Sets the primary color for this task description. 600 * @hide 601 */ 602 public void setPrimaryColor(int primaryColor) { 603 // Ensure that the given color is valid 604 if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) { 605 throw new RuntimeException("A TaskDescription's primary color should be opaque"); 606 } 607 mColorPrimary = primaryColor; 608 } 609 610 /** 611 * Sets the icon for this task description. 612 * @hide 613 */ 614 public void setIcon(Bitmap icon) { 615 mIcon = icon; 616 } 617 618 /** 619 * Moves the icon bitmap reference from an actual Bitmap to a file containing the 620 * bitmap. 621 * @hide 622 */ 623 public void setIconFilename(String iconFilename) { 624 mIconFilename = iconFilename; 625 mIcon = null; 626 } 627 628 /** 629 * @return The label and description of the current state of this task. 630 */ 631 public String getLabel() { 632 return mLabel; 633 } 634 635 /** 636 * @return The icon that represents the current state of this task. 637 */ 638 public Bitmap getIcon() { 639 if (mIcon != null) { 640 return mIcon; 641 } 642 return loadTaskDescriptionIcon(mIconFilename); 643 } 644 645 /** @hide */ 646 public String getIconFilename() { 647 return mIconFilename; 648 } 649 650 /** @hide */ 651 public Bitmap getInMemoryIcon() { 652 return mIcon; 653 } 654 655 /** @hide */ 656 public static Bitmap loadTaskDescriptionIcon(String iconFilename) { 657 if (iconFilename != null) { 658 try { 659 return ActivityManagerNative.getDefault(). 660 getTaskDescriptionIcon(iconFilename); 661 } catch (RemoteException e) { 662 } 663 } 664 return null; 665 } 666 667 /** 668 * @return The color override on the theme's primary color. 669 */ 670 public int getPrimaryColor() { 671 return mColorPrimary; 672 } 673 674 /** @hide */ 675 public void saveToXml(XmlSerializer out) throws IOException { 676 if (mLabel != null) { 677 out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel); 678 } 679 if (mColorPrimary != 0) { 680 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR, Integer.toHexString(mColorPrimary)); 681 } 682 if (mIconFilename != null) { 683 out.attribute(null, ATTR_TASKDESCRIPTIONICONFILENAME, mIconFilename); 684 } 685 } 686 687 /** @hide */ 688 public void restoreFromXml(String attrName, String attrValue) { 689 if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) { 690 setLabel(attrValue); 691 } else if (ATTR_TASKDESCRIPTIONCOLOR.equals(attrName)) { 692 setPrimaryColor((int) Long.parseLong(attrValue, 16)); 693 } else if (ATTR_TASKDESCRIPTIONICONFILENAME.equals(attrName)) { 694 setIconFilename(attrValue); 695 } 696 } 697 698 @Override 699 public int describeContents() { 700 return 0; 701 } 702 703 @Override 704 public void writeToParcel(Parcel dest, int flags) { 705 if (mLabel == null) { 706 dest.writeInt(0); 707 } else { 708 dest.writeInt(1); 709 dest.writeString(mLabel); 710 } 711 if (mIcon == null) { 712 dest.writeInt(0); 713 } else { 714 dest.writeInt(1); 715 mIcon.writeToParcel(dest, 0); 716 } 717 dest.writeInt(mColorPrimary); 718 if (mIconFilename == null) { 719 dest.writeInt(0); 720 } else { 721 dest.writeInt(1); 722 dest.writeString(mIconFilename); 723 } 724 } 725 726 public void readFromParcel(Parcel source) { 727 mLabel = source.readInt() > 0 ? source.readString() : null; 728 mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null; 729 mColorPrimary = source.readInt(); 730 mIconFilename = source.readInt() > 0 ? source.readString() : null; 731 } 732 733 public static final Creator<TaskDescription> CREATOR 734 = new Creator<TaskDescription>() { 735 public TaskDescription createFromParcel(Parcel source) { 736 return new TaskDescription(source); 737 } 738 public TaskDescription[] newArray(int size) { 739 return new TaskDescription[size]; 740 } 741 }; 742 743 @Override 744 public String toString() { 745 return "TaskDescription Label: " + mLabel + " Icon: " + mIcon + 746 " colorPrimary: " + mColorPrimary; 747 } 748 } 749 750 /** 751 * Information you can retrieve about tasks that the user has most recently 752 * started or visited. 753 */ 754 public static class RecentTaskInfo implements Parcelable { 755 /** 756 * If this task is currently running, this is the identifier for it. 757 * If it is not running, this will be -1. 758 */ 759 public int id; 760 761 /** 762 * The true identifier of this task, valid even if it is not running. 763 */ 764 public int persistentId; 765 766 /** 767 * The original Intent used to launch the task. You can use this 768 * Intent to re-launch the task (if it is no longer running) or bring 769 * the current task to the front. 770 */ 771 public Intent baseIntent; 772 773 /** 774 * If this task was started from an alias, this is the actual 775 * activity component that was initially started; the component of 776 * the baseIntent in this case is the name of the actual activity 777 * implementation that the alias referred to. Otherwise, this is null. 778 */ 779 public ComponentName origActivity; 780 781 /** 782 * Description of the task's last state. 783 */ 784 public CharSequence description; 785 786 /** 787 * The id of the ActivityStack this Task was on most recently. 788 * @hide 789 */ 790 public int stackId; 791 792 /** 793 * The id of the user the task was running as. 794 * @hide 795 */ 796 public int userId; 797 798 /** 799 * The first time this task was active. 800 * @hide 801 */ 802 public long firstActiveTime; 803 804 /** 805 * The last time this task was active. 806 * @hide 807 */ 808 public long lastActiveTime; 809 810 /** 811 * The recent activity values for the highest activity in the stack to have set the values. 812 * {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}. 813 */ 814 public TaskDescription taskDescription; 815 816 /** 817 * Task affiliation for grouping with other tasks. 818 */ 819 public int affiliatedTaskId; 820 821 /** 822 * Task affiliation color of the source task with the affiliated task id. 823 * 824 * @hide 825 */ 826 public int affiliatedTaskColor; 827 828 public RecentTaskInfo() { 829 } 830 831 @Override 832 public int describeContents() { 833 return 0; 834 } 835 836 @Override 837 public void writeToParcel(Parcel dest, int flags) { 838 dest.writeInt(id); 839 dest.writeInt(persistentId); 840 if (baseIntent != null) { 841 dest.writeInt(1); 842 baseIntent.writeToParcel(dest, 0); 843 } else { 844 dest.writeInt(0); 845 } 846 ComponentName.writeToParcel(origActivity, dest); 847 TextUtils.writeToParcel(description, dest, 848 Parcelable.PARCELABLE_WRITE_RETURN_VALUE); 849 if (taskDescription != null) { 850 dest.writeInt(1); 851 taskDescription.writeToParcel(dest, 0); 852 } else { 853 dest.writeInt(0); 854 } 855 dest.writeInt(stackId); 856 dest.writeInt(userId); 857 dest.writeLong(firstActiveTime); 858 dest.writeLong(lastActiveTime); 859 dest.writeInt(affiliatedTaskId); 860 dest.writeInt(affiliatedTaskColor); 861 } 862 863 public void readFromParcel(Parcel source) { 864 id = source.readInt(); 865 persistentId = source.readInt(); 866 baseIntent = source.readInt() > 0 ? Intent.CREATOR.createFromParcel(source) : null; 867 origActivity = ComponentName.readFromParcel(source); 868 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); 869 taskDescription = source.readInt() > 0 ? 870 TaskDescription.CREATOR.createFromParcel(source) : null; 871 stackId = source.readInt(); 872 userId = source.readInt(); 873 firstActiveTime = source.readLong(); 874 lastActiveTime = source.readLong(); 875 affiliatedTaskId = source.readInt(); 876 affiliatedTaskColor = source.readInt(); 877 } 878 879 public static final Creator<RecentTaskInfo> CREATOR 880 = new Creator<RecentTaskInfo>() { 881 public RecentTaskInfo createFromParcel(Parcel source) { 882 return new RecentTaskInfo(source); 883 } 884 public RecentTaskInfo[] newArray(int size) { 885 return new RecentTaskInfo[size]; 886 } 887 }; 888 889 private RecentTaskInfo(Parcel source) { 890 readFromParcel(source); 891 } 892 } 893 894 /** 895 * Flag for use with {@link #getRecentTasks}: return all tasks, even those 896 * that have set their 897 * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag. 898 */ 899 public static final int RECENT_WITH_EXCLUDED = 0x0001; 900 901 /** 902 * Provides a list that does not contain any 903 * recent tasks that currently are not available to the user. 904 */ 905 public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002; 906 907 /** 908 * Provides a list that contains recent tasks for all 909 * profiles of a user. 910 * @hide 911 */ 912 public static final int RECENT_INCLUDE_PROFILES = 0x0004; 913 914 /** 915 * Ignores all tasks that are on the home stack. 916 * @hide 917 */ 918 public static final int RECENT_IGNORE_HOME_STACK_TASKS = 0x0008; 919 920 /** 921 * <p></p>Return a list of the tasks that the user has recently launched, with 922 * the most recent being first and older ones after in order. 923 * 924 * <p><b>Note: this method is only intended for debugging and presenting 925 * task management user interfaces</b>. This should never be used for 926 * core logic in an application, such as deciding between different 927 * behaviors based on the information found here. Such uses are 928 * <em>not</em> supported, and will likely break in the future. For 929 * example, if multiple applications can be actively running at the 930 * same time, assumptions made about the meaning of the data here for 931 * purposes of control flow will be incorrect.</p> 932 * 933 * @deprecated As of {@link android.os.Build.VERSION_CODES#L}, this method is 934 * no longer available to third party applications: as the introduction of 935 * document-centric recents means 936 * it can leak personal information to the caller. For backwards compatibility, 937 * it will still return a small subset of its data: at least the caller's 938 * own tasks (though see {@link #getAppTasks()} for the correct supported 939 * way to retrieve that information), and possibly some other tasks 940 * such as home that are known to not be sensitive. 941 * 942 * @param maxNum The maximum number of entries to return in the list. The 943 * actual number returned may be smaller, depending on how many tasks the 944 * user has started and the maximum number the system can remember. 945 * @param flags Information about what to return. May be any combination 946 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}. 947 * 948 * @return Returns a list of RecentTaskInfo records describing each of 949 * the recent tasks. 950 * 951 * @throws SecurityException Throws SecurityException if the caller does 952 * not hold the {@link android.Manifest.permission#GET_TASKS} permission. 953 */ 954 @Deprecated 955 public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags) 956 throws SecurityException { 957 try { 958 return ActivityManagerNative.getDefault().getRecentTasks(maxNum, 959 flags, UserHandle.myUserId()); 960 } catch (RemoteException e) { 961 // System dead, we will be dead too soon! 962 return null; 963 } 964 } 965 966 /** 967 * Same as {@link #getRecentTasks(int, int)} but returns the recent tasks for a 968 * specific user. It requires holding 969 * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission. 970 * @param maxNum The maximum number of entries to return in the list. The 971 * actual number returned may be smaller, depending on how many tasks the 972 * user has started and the maximum number the system can remember. 973 * @param flags Information about what to return. May be any combination 974 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}. 975 * 976 * @return Returns a list of RecentTaskInfo records describing each of 977 * the recent tasks. 978 * 979 * @throws SecurityException Throws SecurityException if the caller does 980 * not hold the {@link android.Manifest.permission#GET_TASKS} or the 981 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permissions. 982 * @hide 983 */ 984 public List<RecentTaskInfo> getRecentTasksForUser(int maxNum, int flags, int userId) 985 throws SecurityException { 986 try { 987 return ActivityManagerNative.getDefault().getRecentTasks(maxNum, 988 flags, userId); 989 } catch (RemoteException e) { 990 // System dead, we will be dead too soon! 991 return null; 992 } 993 } 994 995 /** 996 * Information you can retrieve about a particular task that is currently 997 * "running" in the system. Note that a running task does not mean the 998 * given task actually has a process it is actively running in; it simply 999 * means that the user has gone to it and never closed it, but currently 1000 * the system may have killed its process and is only holding on to its 1001 * last state in order to restart it when the user returns. 1002 */ 1003 public static class RunningTaskInfo implements Parcelable { 1004 /** 1005 * A unique identifier for this task. 1006 */ 1007 public int id; 1008 1009 /** 1010 * The component launched as the first activity in the task. This can 1011 * be considered the "application" of this task. 1012 */ 1013 public ComponentName baseActivity; 1014 1015 /** 1016 * The activity component at the top of the history stack of the task. 1017 * This is what the user is currently doing. 1018 */ 1019 public ComponentName topActivity; 1020 1021 /** 1022 * Thumbnail representation of the task's current state. Currently 1023 * always null. 1024 */ 1025 public Bitmap thumbnail; 1026 1027 /** 1028 * Description of the task's current state. 1029 */ 1030 public CharSequence description; 1031 1032 /** 1033 * Number of activities in this task. 1034 */ 1035 public int numActivities; 1036 1037 /** 1038 * Number of activities that are currently running (not stopped 1039 * and persisted) in this task. 1040 */ 1041 public int numRunning; 1042 1043 /** 1044 * Last time task was run. For sorting. 1045 * @hide 1046 */ 1047 public long lastActiveTime; 1048 1049 public RunningTaskInfo() { 1050 } 1051 1052 public int describeContents() { 1053 return 0; 1054 } 1055 1056 public void writeToParcel(Parcel dest, int flags) { 1057 dest.writeInt(id); 1058 ComponentName.writeToParcel(baseActivity, dest); 1059 ComponentName.writeToParcel(topActivity, dest); 1060 if (thumbnail != null) { 1061 dest.writeInt(1); 1062 thumbnail.writeToParcel(dest, 0); 1063 } else { 1064 dest.writeInt(0); 1065 } 1066 TextUtils.writeToParcel(description, dest, 1067 Parcelable.PARCELABLE_WRITE_RETURN_VALUE); 1068 dest.writeInt(numActivities); 1069 dest.writeInt(numRunning); 1070 } 1071 1072 public void readFromParcel(Parcel source) { 1073 id = source.readInt(); 1074 baseActivity = ComponentName.readFromParcel(source); 1075 topActivity = ComponentName.readFromParcel(source); 1076 if (source.readInt() != 0) { 1077 thumbnail = Bitmap.CREATOR.createFromParcel(source); 1078 } else { 1079 thumbnail = null; 1080 } 1081 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); 1082 numActivities = source.readInt(); 1083 numRunning = source.readInt(); 1084 } 1085 1086 public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() { 1087 public RunningTaskInfo createFromParcel(Parcel source) { 1088 return new RunningTaskInfo(source); 1089 } 1090 public RunningTaskInfo[] newArray(int size) { 1091 return new RunningTaskInfo[size]; 1092 } 1093 }; 1094 1095 private RunningTaskInfo(Parcel source) { 1096 readFromParcel(source); 1097 } 1098 } 1099 1100 /** 1101 * Get the list of tasks associated with the calling application. 1102 * 1103 * @return The list of tasks associated with the application making this call. 1104 * @throws SecurityException 1105 */ 1106 public List<ActivityManager.AppTask> getAppTasks() { 1107 ArrayList<AppTask> tasks = new ArrayList<AppTask>(); 1108 List<IAppTask> appTasks; 1109 try { 1110 appTasks = ActivityManagerNative.getDefault().getAppTasks(mContext.getPackageName()); 1111 } catch (RemoteException e) { 1112 // System dead, we will be dead too soon! 1113 return null; 1114 } 1115 int numAppTasks = appTasks.size(); 1116 for (int i = 0; i < numAppTasks; i++) { 1117 tasks.add(new AppTask(appTasks.get(i))); 1118 } 1119 return tasks; 1120 } 1121 1122 /** 1123 * Return the current design dimensions for {@link AppTask} thumbnails, for use 1124 * with {@link #addAppTask}. 1125 */ 1126 public Size getAppTaskThumbnailSize() { 1127 synchronized (this) { 1128 ensureAppTaskThumbnailSizeLocked(); 1129 return new Size(mAppTaskThumbnailSize.x, mAppTaskThumbnailSize.y); 1130 } 1131 } 1132 1133 private void ensureAppTaskThumbnailSizeLocked() { 1134 if (mAppTaskThumbnailSize == null) { 1135 try { 1136 mAppTaskThumbnailSize = ActivityManagerNative.getDefault().getAppTaskThumbnailSize(); 1137 } catch (RemoteException e) { 1138 throw new IllegalStateException("System dead?", e); 1139 } 1140 } 1141 } 1142 1143 /** 1144 * Add a new {@link AppTask} for the calling application. This will create a new 1145 * recents entry that is added to the <b>end</b> of all existing recents. 1146 * 1147 * @param activity The activity that is adding the entry. This is used to help determine 1148 * the context that the new recents entry will be in. 1149 * @param intent The Intent that describes the recents entry. This is the same Intent that 1150 * you would have used to launch the activity for it. In generally you will want to set 1151 * both {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} and 1152 * {@link Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}; the latter is required since this recents 1153 * entry will exist without an activity, so it doesn't make sense to not retain it when 1154 * its activity disappears. The given Intent here also must have an explicit ComponentName 1155 * set on it. 1156 * @param description Optional additional description information. 1157 * @param thumbnail Thumbnail to use for the recents entry. Should be the size given by 1158 * {@link #getAppTaskThumbnailSize()}. If the bitmap is not that exact size, it will be 1159 * recreated in your process, probably in a way you don't like, before the recents entry 1160 * is added. 1161 * 1162 * @return Returns the task id of the newly added app task, or -1 if the add failed. The 1163 * most likely cause of failure is that there is no more room for more tasks for your app. 1164 */ 1165 public int addAppTask(@NonNull Activity activity, @NonNull Intent intent, 1166 @Nullable TaskDescription description, @NonNull Bitmap thumbnail) { 1167 Point size; 1168 synchronized (this) { 1169 ensureAppTaskThumbnailSizeLocked(); 1170 size = mAppTaskThumbnailSize; 1171 } 1172 final int tw = thumbnail.getWidth(); 1173 final int th = thumbnail.getHeight(); 1174 if (tw != size.x || th != size.y) { 1175 Bitmap bm = Bitmap.createBitmap(size.x, size.y, thumbnail.getConfig()); 1176 1177 // Use ScaleType.CENTER_CROP, except we leave the top edge at the top. 1178 float scale; 1179 float dx = 0, dy = 0; 1180 if (tw * size.x > size.y * th) { 1181 scale = (float) size.x / (float) th; 1182 dx = (size.y - tw * scale) * 0.5f; 1183 } else { 1184 scale = (float) size.y / (float) tw; 1185 dy = (size.x - th * scale) * 0.5f; 1186 } 1187 Matrix matrix = new Matrix(); 1188 matrix.setScale(scale, scale); 1189 matrix.postTranslate((int) (dx + 0.5f), 0); 1190 1191 Canvas canvas = new Canvas(bm); 1192 canvas.drawBitmap(thumbnail, matrix, null); 1193 canvas.setBitmap(null); 1194 1195 thumbnail = bm; 1196 } 1197 if (description == null) { 1198 description = new TaskDescription(); 1199 } 1200 try { 1201 return ActivityManagerNative.getDefault().addAppTask(activity.getActivityToken(), 1202 intent, description, thumbnail); 1203 } catch (RemoteException e) { 1204 throw new IllegalStateException("System dead?", e); 1205 } 1206 } 1207 1208 /** 1209 * Return a list of the tasks that are currently running, with 1210 * the most recent being first and older ones after in order. Note that 1211 * "running" does not mean any of the task's code is currently loaded or 1212 * activity -- the task may have been frozen by the system, so that it 1213 * can be restarted in its previous state when next brought to the 1214 * foreground. 1215 * 1216 * <p><b>Note: this method is only intended for debugging and presenting 1217 * task management user interfaces</b>. This should never be used for 1218 * core logic in an application, such as deciding between different 1219 * behaviors based on the information found here. Such uses are 1220 * <em>not</em> supported, and will likely break in the future. For 1221 * example, if multiple applications can be actively running at the 1222 * same time, assumptions made about the meaning of the data here for 1223 * purposes of control flow will be incorrect.</p> 1224 * 1225 * @deprecated As of {@link android.os.Build.VERSION_CODES#L}, this method 1226 * is no longer available to third party 1227 * applications: the introduction of document-centric recents means 1228 * it can leak person information to the caller. For backwards compatibility, 1229 * it will still retu rn a small subset of its data: at least the caller's 1230 * own tasks, and possibly some other tasks 1231 * such as home that are known to not be sensitive. 1232 * 1233 * @param maxNum The maximum number of entries to return in the list. The 1234 * actual number returned may be smaller, depending on how many tasks the 1235 * user has started. 1236 * 1237 * @return Returns a list of RunningTaskInfo records describing each of 1238 * the running tasks. 1239 * 1240 * @throws SecurityException Throws SecurityException if the caller does 1241 * not hold the {@link android.Manifest.permission#GET_TASKS} permission. 1242 */ 1243 @Deprecated 1244 public List<RunningTaskInfo> getRunningTasks(int maxNum) 1245 throws SecurityException { 1246 try { 1247 return ActivityManagerNative.getDefault().getTasks(maxNum, 0); 1248 } catch (RemoteException e) { 1249 // System dead, we will be dead too soon! 1250 return null; 1251 } 1252 } 1253 1254 /** 1255 * If set, the process of the root activity of the task will be killed 1256 * as part of removing the task. 1257 * @hide 1258 */ 1259 public static final int REMOVE_TASK_KILL_PROCESS = 0x0001; 1260 1261 /** 1262 * Completely remove the given task. 1263 * 1264 * @param taskId Identifier of the task to be removed. 1265 * @param flags Additional operational flags. May be 0 or 1266 * {@link #REMOVE_TASK_KILL_PROCESS}. 1267 * @return Returns true if the given task was found and removed. 1268 * 1269 * @hide 1270 */ 1271 public boolean removeTask(int taskId, int flags) 1272 throws SecurityException { 1273 try { 1274 return ActivityManagerNative.getDefault().removeTask(taskId, flags); 1275 } catch (RemoteException e) { 1276 // System dead, we will be dead too soon! 1277 return false; 1278 } 1279 } 1280 1281 /** @hide */ 1282 public static class TaskThumbnail implements Parcelable { 1283 public Bitmap mainThumbnail; 1284 public ParcelFileDescriptor thumbnailFileDescriptor; 1285 1286 public TaskThumbnail() { 1287 } 1288 1289 public int describeContents() { 1290 if (thumbnailFileDescriptor != null) { 1291 return thumbnailFileDescriptor.describeContents(); 1292 } 1293 return 0; 1294 } 1295 1296 public void writeToParcel(Parcel dest, int flags) { 1297 if (mainThumbnail != null) { 1298 dest.writeInt(1); 1299 mainThumbnail.writeToParcel(dest, flags); 1300 } else { 1301 dest.writeInt(0); 1302 } 1303 if (thumbnailFileDescriptor != null) { 1304 dest.writeInt(1); 1305 thumbnailFileDescriptor.writeToParcel(dest, flags); 1306 } else { 1307 dest.writeInt(0); 1308 } 1309 } 1310 1311 public void readFromParcel(Parcel source) { 1312 if (source.readInt() != 0) { 1313 mainThumbnail = Bitmap.CREATOR.createFromParcel(source); 1314 } else { 1315 mainThumbnail = null; 1316 } 1317 if (source.readInt() != 0) { 1318 thumbnailFileDescriptor = ParcelFileDescriptor.CREATOR.createFromParcel(source); 1319 } else { 1320 thumbnailFileDescriptor = null; 1321 } 1322 } 1323 1324 public static final Creator<TaskThumbnail> CREATOR = new Creator<TaskThumbnail>() { 1325 public TaskThumbnail createFromParcel(Parcel source) { 1326 return new TaskThumbnail(source); 1327 } 1328 public TaskThumbnail[] newArray(int size) { 1329 return new TaskThumbnail[size]; 1330 } 1331 }; 1332 1333 private TaskThumbnail(Parcel source) { 1334 readFromParcel(source); 1335 } 1336 } 1337 1338 /** @hide */ 1339 public TaskThumbnail getTaskThumbnail(int id) throws SecurityException { 1340 try { 1341 return ActivityManagerNative.getDefault().getTaskThumbnail(id); 1342 } catch (RemoteException e) { 1343 // System dead, we will be dead too soon! 1344 return null; 1345 } 1346 } 1347 1348 /** @hide */ 1349 public boolean isInHomeStack(int taskId) { 1350 try { 1351 return ActivityManagerNative.getDefault().isInHomeStack(taskId); 1352 } catch (RemoteException e) { 1353 // System dead, we will be dead too soon! 1354 return false; 1355 } 1356 } 1357 1358 /** 1359 * Flag for {@link #moveTaskToFront(int, int)}: also move the "home" 1360 * activity along with the task, so it is positioned immediately behind 1361 * the task. 1362 */ 1363 public static final int MOVE_TASK_WITH_HOME = 0x00000001; 1364 1365 /** 1366 * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a 1367 * user-instigated action, so the current activity will not receive a 1368 * hint that the user is leaving. 1369 */ 1370 public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002; 1371 1372 /** 1373 * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)} 1374 * with a null options argument. 1375 * 1376 * @param taskId The identifier of the task to be moved, as found in 1377 * {@link RunningTaskInfo} or {@link RecentTaskInfo}. 1378 * @param flags Additional operational flags, 0 or more of 1379 * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}. 1380 */ 1381 public void moveTaskToFront(int taskId, int flags) { 1382 moveTaskToFront(taskId, flags, null); 1383 } 1384 1385 /** 1386 * Ask that the task associated with a given task ID be moved to the 1387 * front of the stack, so it is now visible to the user. Requires that 1388 * the caller hold permission {@link android.Manifest.permission#REORDER_TASKS} 1389 * or a SecurityException will be thrown. 1390 * 1391 * @param taskId The identifier of the task to be moved, as found in 1392 * {@link RunningTaskInfo} or {@link RecentTaskInfo}. 1393 * @param flags Additional operational flags, 0 or more of 1394 * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}. 1395 * @param options Additional options for the operation, either null or 1396 * as per {@link Context#startActivity(Intent, android.os.Bundle) 1397 * Context.startActivity(Intent, Bundle)}. 1398 */ 1399 public void moveTaskToFront(int taskId, int flags, Bundle options) { 1400 try { 1401 ActivityManagerNative.getDefault().moveTaskToFront(taskId, flags, options); 1402 } catch (RemoteException e) { 1403 // System dead, we will be dead too soon! 1404 } 1405 } 1406 1407 /** 1408 * Information you can retrieve about a particular Service that is 1409 * currently running in the system. 1410 */ 1411 public static class RunningServiceInfo implements Parcelable { 1412 /** 1413 * The service component. 1414 */ 1415 public ComponentName service; 1416 1417 /** 1418 * If non-zero, this is the process the service is running in. 1419 */ 1420 public int pid; 1421 1422 /** 1423 * The UID that owns this service. 1424 */ 1425 public int uid; 1426 1427 /** 1428 * The name of the process this service runs in. 1429 */ 1430 public String process; 1431 1432 /** 1433 * Set to true if the service has asked to run as a foreground process. 1434 */ 1435 public boolean foreground; 1436 1437 /** 1438 * The time when the service was first made active, either by someone 1439 * starting or binding to it. This 1440 * is in units of {@link android.os.SystemClock#elapsedRealtime()}. 1441 */ 1442 public long activeSince; 1443 1444 /** 1445 * Set to true if this service has been explicitly started. 1446 */ 1447 public boolean started; 1448 1449 /** 1450 * Number of clients connected to the service. 1451 */ 1452 public int clientCount; 1453 1454 /** 1455 * Number of times the service's process has crashed while the service 1456 * is running. 1457 */ 1458 public int crashCount; 1459 1460 /** 1461 * The time when there was last activity in the service (either 1462 * explicit requests to start it or clients binding to it). This 1463 * is in units of {@link android.os.SystemClock#uptimeMillis()}. 1464 */ 1465 public long lastActivityTime; 1466 1467 /** 1468 * If non-zero, this service is not currently running, but scheduled to 1469 * restart at the given time. 1470 */ 1471 public long restarting; 1472 1473 /** 1474 * Bit for {@link #flags}: set if this service has been 1475 * explicitly started. 1476 */ 1477 public static final int FLAG_STARTED = 1<<0; 1478 1479 /** 1480 * Bit for {@link #flags}: set if the service has asked to 1481 * run as a foreground process. 1482 */ 1483 public static final int FLAG_FOREGROUND = 1<<1; 1484 1485 /** 1486 * Bit for {@link #flags): set if the service is running in a 1487 * core system process. 1488 */ 1489 public static final int FLAG_SYSTEM_PROCESS = 1<<2; 1490 1491 /** 1492 * Bit for {@link #flags): set if the service is running in a 1493 * persistent process. 1494 */ 1495 public static final int FLAG_PERSISTENT_PROCESS = 1<<3; 1496 1497 /** 1498 * Running flags. 1499 */ 1500 public int flags; 1501 1502 /** 1503 * For special services that are bound to by system code, this is 1504 * the package that holds the binding. 1505 */ 1506 public String clientPackage; 1507 1508 /** 1509 * For special services that are bound to by system code, this is 1510 * a string resource providing a user-visible label for who the 1511 * client is. 1512 */ 1513 public int clientLabel; 1514 1515 public RunningServiceInfo() { 1516 } 1517 1518 public int describeContents() { 1519 return 0; 1520 } 1521 1522 public void writeToParcel(Parcel dest, int flags) { 1523 ComponentName.writeToParcel(service, dest); 1524 dest.writeInt(pid); 1525 dest.writeInt(uid); 1526 dest.writeString(process); 1527 dest.writeInt(foreground ? 1 : 0); 1528 dest.writeLong(activeSince); 1529 dest.writeInt(started ? 1 : 0); 1530 dest.writeInt(clientCount); 1531 dest.writeInt(crashCount); 1532 dest.writeLong(lastActivityTime); 1533 dest.writeLong(restarting); 1534 dest.writeInt(this.flags); 1535 dest.writeString(clientPackage); 1536 dest.writeInt(clientLabel); 1537 } 1538 1539 public void readFromParcel(Parcel source) { 1540 service = ComponentName.readFromParcel(source); 1541 pid = source.readInt(); 1542 uid = source.readInt(); 1543 process = source.readString(); 1544 foreground = source.readInt() != 0; 1545 activeSince = source.readLong(); 1546 started = source.readInt() != 0; 1547 clientCount = source.readInt(); 1548 crashCount = source.readInt(); 1549 lastActivityTime = source.readLong(); 1550 restarting = source.readLong(); 1551 flags = source.readInt(); 1552 clientPackage = source.readString(); 1553 clientLabel = source.readInt(); 1554 } 1555 1556 public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() { 1557 public RunningServiceInfo createFromParcel(Parcel source) { 1558 return new RunningServiceInfo(source); 1559 } 1560 public RunningServiceInfo[] newArray(int size) { 1561 return new RunningServiceInfo[size]; 1562 } 1563 }; 1564 1565 private RunningServiceInfo(Parcel source) { 1566 readFromParcel(source); 1567 } 1568 } 1569 1570 /** 1571 * Return a list of the services that are currently running. 1572 * 1573 * <p><b>Note: this method is only intended for debugging or implementing 1574 * service management type user interfaces.</b></p> 1575 * 1576 * @param maxNum The maximum number of entries to return in the list. The 1577 * actual number returned may be smaller, depending on how many services 1578 * are running. 1579 * 1580 * @return Returns a list of RunningServiceInfo records describing each of 1581 * the running tasks. 1582 */ 1583 public List<RunningServiceInfo> getRunningServices(int maxNum) 1584 throws SecurityException { 1585 try { 1586 return ActivityManagerNative.getDefault() 1587 .getServices(maxNum, 0); 1588 } catch (RemoteException e) { 1589 // System dead, we will be dead too soon! 1590 return null; 1591 } 1592 } 1593 1594 /** 1595 * Returns a PendingIntent you can start to show a control panel for the 1596 * given running service. If the service does not have a control panel, 1597 * null is returned. 1598 */ 1599 public PendingIntent getRunningServiceControlPanel(ComponentName service) 1600 throws SecurityException { 1601 try { 1602 return ActivityManagerNative.getDefault() 1603 .getRunningServiceControlPanel(service); 1604 } catch (RemoteException e) { 1605 // System dead, we will be dead too soon! 1606 return null; 1607 } 1608 } 1609 1610 /** 1611 * Information you can retrieve about the available memory through 1612 * {@link ActivityManager#getMemoryInfo}. 1613 */ 1614 public static class MemoryInfo implements Parcelable { 1615 /** 1616 * The available memory on the system. This number should not 1617 * be considered absolute: due to the nature of the kernel, a significant 1618 * portion of this memory is actually in use and needed for the overall 1619 * system to run well. 1620 */ 1621 public long availMem; 1622 1623 /** 1624 * The total memory accessible by the kernel. This is basically the 1625 * RAM size of the device, not including below-kernel fixed allocations 1626 * like DMA buffers, RAM for the baseband CPU, etc. 1627 */ 1628 public long totalMem; 1629 1630 /** 1631 * The threshold of {@link #availMem} at which we consider memory to be 1632 * low and start killing background services and other non-extraneous 1633 * processes. 1634 */ 1635 public long threshold; 1636 1637 /** 1638 * Set to true if the system considers itself to currently be in a low 1639 * memory situation. 1640 */ 1641 public boolean lowMemory; 1642 1643 /** @hide */ 1644 public long hiddenAppThreshold; 1645 /** @hide */ 1646 public long secondaryServerThreshold; 1647 /** @hide */ 1648 public long visibleAppThreshold; 1649 /** @hide */ 1650 public long foregroundAppThreshold; 1651 1652 public MemoryInfo() { 1653 } 1654 1655 public int describeContents() { 1656 return 0; 1657 } 1658 1659 public void writeToParcel(Parcel dest, int flags) { 1660 dest.writeLong(availMem); 1661 dest.writeLong(totalMem); 1662 dest.writeLong(threshold); 1663 dest.writeInt(lowMemory ? 1 : 0); 1664 dest.writeLong(hiddenAppThreshold); 1665 dest.writeLong(secondaryServerThreshold); 1666 dest.writeLong(visibleAppThreshold); 1667 dest.writeLong(foregroundAppThreshold); 1668 } 1669 1670 public void readFromParcel(Parcel source) { 1671 availMem = source.readLong(); 1672 totalMem = source.readLong(); 1673 threshold = source.readLong(); 1674 lowMemory = source.readInt() != 0; 1675 hiddenAppThreshold = source.readLong(); 1676 secondaryServerThreshold = source.readLong(); 1677 visibleAppThreshold = source.readLong(); 1678 foregroundAppThreshold = source.readLong(); 1679 } 1680 1681 public static final Creator<MemoryInfo> CREATOR 1682 = new Creator<MemoryInfo>() { 1683 public MemoryInfo createFromParcel(Parcel source) { 1684 return new MemoryInfo(source); 1685 } 1686 public MemoryInfo[] newArray(int size) { 1687 return new MemoryInfo[size]; 1688 } 1689 }; 1690 1691 private MemoryInfo(Parcel source) { 1692 readFromParcel(source); 1693 } 1694 } 1695 1696 /** 1697 * Return general information about the memory state of the system. This 1698 * can be used to help decide how to manage your own memory, though note 1699 * that polling is not recommended and 1700 * {@link android.content.ComponentCallbacks2#onTrimMemory(int) 1701 * ComponentCallbacks2.onTrimMemory(int)} is the preferred way to do this. 1702 * Also see {@link #getMyMemoryState} for how to retrieve the current trim 1703 * level of your process as needed, which gives a better hint for how to 1704 * manage its memory. 1705 */ 1706 public void getMemoryInfo(MemoryInfo outInfo) { 1707 try { 1708 ActivityManagerNative.getDefault().getMemoryInfo(outInfo); 1709 } catch (RemoteException e) { 1710 } 1711 } 1712 1713 /** 1714 * Information you can retrieve about an ActivityStack in the system. 1715 * @hide 1716 */ 1717 public static class StackInfo implements Parcelable { 1718 public int stackId; 1719 public Rect bounds = new Rect(); 1720 public int[] taskIds; 1721 public String[] taskNames; 1722 public int displayId; 1723 1724 @Override 1725 public int describeContents() { 1726 return 0; 1727 } 1728 1729 @Override 1730 public void writeToParcel(Parcel dest, int flags) { 1731 dest.writeInt(stackId); 1732 dest.writeInt(bounds.left); 1733 dest.writeInt(bounds.top); 1734 dest.writeInt(bounds.right); 1735 dest.writeInt(bounds.bottom); 1736 dest.writeIntArray(taskIds); 1737 dest.writeStringArray(taskNames); 1738 dest.writeInt(displayId); 1739 } 1740 1741 public void readFromParcel(Parcel source) { 1742 stackId = source.readInt(); 1743 bounds = new Rect( 1744 source.readInt(), source.readInt(), source.readInt(), source.readInt()); 1745 taskIds = source.createIntArray(); 1746 taskNames = source.createStringArray(); 1747 displayId = source.readInt(); 1748 } 1749 1750 public static final Creator<StackInfo> CREATOR = new Creator<StackInfo>() { 1751 @Override 1752 public StackInfo createFromParcel(Parcel source) { 1753 return new StackInfo(source); 1754 } 1755 @Override 1756 public StackInfo[] newArray(int size) { 1757 return new StackInfo[size]; 1758 } 1759 }; 1760 1761 public StackInfo() { 1762 } 1763 1764 private StackInfo(Parcel source) { 1765 readFromParcel(source); 1766 } 1767 1768 public String toString(String prefix) { 1769 StringBuilder sb = new StringBuilder(256); 1770 sb.append(prefix); sb.append("Stack id="); sb.append(stackId); 1771 sb.append(" bounds="); sb.append(bounds.toShortString()); 1772 sb.append(" displayId="); sb.append(displayId); 1773 sb.append("\n"); 1774 prefix = prefix + " "; 1775 for (int i = 0; i < taskIds.length; ++i) { 1776 sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]); 1777 sb.append(": "); sb.append(taskNames[i]); sb.append("\n"); 1778 } 1779 return sb.toString(); 1780 } 1781 1782 @Override 1783 public String toString() { 1784 return toString(""); 1785 } 1786 } 1787 1788 /** 1789 * @hide 1790 */ 1791 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) { 1792 try { 1793 return ActivityManagerNative.getDefault().clearApplicationUserData(packageName, 1794 observer, UserHandle.myUserId()); 1795 } catch (RemoteException e) { 1796 return false; 1797 } 1798 } 1799 1800 /** 1801 * Permits an application to erase its own data from disk. This is equivalent to 1802 * the user choosing to clear the app's data from within the device settings UI. It 1803 * erases all dynamic data associated with the app -- its private data and data in its 1804 * private area on external storage -- but does not remove the installed application 1805 * itself, nor any OBB files. 1806 * 1807 * @return {@code true} if the application successfully requested that the application's 1808 * data be erased; {@code false} otherwise. 1809 */ 1810 public boolean clearApplicationUserData() { 1811 return clearApplicationUserData(mContext.getPackageName(), null); 1812 } 1813 1814 /** 1815 * Information you can retrieve about any processes that are in an error condition. 1816 */ 1817 public static class ProcessErrorStateInfo implements Parcelable { 1818 /** 1819 * Condition codes 1820 */ 1821 public static final int NO_ERROR = 0; 1822 public static final int CRASHED = 1; 1823 public static final int NOT_RESPONDING = 2; 1824 1825 /** 1826 * The condition that the process is in. 1827 */ 1828 public int condition; 1829 1830 /** 1831 * The process name in which the crash or error occurred. 1832 */ 1833 public String processName; 1834 1835 /** 1836 * The pid of this process; 0 if none 1837 */ 1838 public int pid; 1839 1840 /** 1841 * The kernel user-ID that has been assigned to this process; 1842 * currently this is not a unique ID (multiple applications can have 1843 * the same uid). 1844 */ 1845 public int uid; 1846 1847 /** 1848 * The activity name associated with the error, if known. May be null. 1849 */ 1850 public String tag; 1851 1852 /** 1853 * A short message describing the error condition. 1854 */ 1855 public String shortMsg; 1856 1857 /** 1858 * A long message describing the error condition. 1859 */ 1860 public String longMsg; 1861 1862 /** 1863 * The stack trace where the error originated. May be null. 1864 */ 1865 public String stackTrace; 1866 1867 /** 1868 * to be deprecated: This value will always be null. 1869 */ 1870 public byte[] crashData = null; 1871 1872 public ProcessErrorStateInfo() { 1873 } 1874 1875 @Override 1876 public int describeContents() { 1877 return 0; 1878 } 1879 1880 @Override 1881 public void writeToParcel(Parcel dest, int flags) { 1882 dest.writeInt(condition); 1883 dest.writeString(processName); 1884 dest.writeInt(pid); 1885 dest.writeInt(uid); 1886 dest.writeString(tag); 1887 dest.writeString(shortMsg); 1888 dest.writeString(longMsg); 1889 dest.writeString(stackTrace); 1890 } 1891 1892 public void readFromParcel(Parcel source) { 1893 condition = source.readInt(); 1894 processName = source.readString(); 1895 pid = source.readInt(); 1896 uid = source.readInt(); 1897 tag = source.readString(); 1898 shortMsg = source.readString(); 1899 longMsg = source.readString(); 1900 stackTrace = source.readString(); 1901 } 1902 1903 public static final Creator<ProcessErrorStateInfo> CREATOR = 1904 new Creator<ProcessErrorStateInfo>() { 1905 public ProcessErrorStateInfo createFromParcel(Parcel source) { 1906 return new ProcessErrorStateInfo(source); 1907 } 1908 public ProcessErrorStateInfo[] newArray(int size) { 1909 return new ProcessErrorStateInfo[size]; 1910 } 1911 }; 1912 1913 private ProcessErrorStateInfo(Parcel source) { 1914 readFromParcel(source); 1915 } 1916 } 1917 1918 /** 1919 * Returns a list of any processes that are currently in an error condition. The result 1920 * will be null if all processes are running properly at this time. 1921 * 1922 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no 1923 * current error conditions (it will not return an empty list). This list ordering is not 1924 * specified. 1925 */ 1926 public List<ProcessErrorStateInfo> getProcessesInErrorState() { 1927 try { 1928 return ActivityManagerNative.getDefault().getProcessesInErrorState(); 1929 } catch (RemoteException e) { 1930 return null; 1931 } 1932 } 1933 1934 /** 1935 * Information you can retrieve about a running process. 1936 */ 1937 public static class RunningAppProcessInfo implements Parcelable { 1938 /** 1939 * The name of the process that this object is associated with 1940 */ 1941 public String processName; 1942 1943 /** 1944 * The pid of this process; 0 if none 1945 */ 1946 public int pid; 1947 1948 /** 1949 * The user id of this process. 1950 */ 1951 public int uid; 1952 1953 /** 1954 * All packages that have been loaded into the process. 1955 */ 1956 public String pkgList[]; 1957 1958 /** 1959 * Constant for {@link #flags}: this is an app that is unable to 1960 * correctly save its state when going to the background, 1961 * so it can not be killed while in the background. 1962 * @hide 1963 */ 1964 public static final int FLAG_CANT_SAVE_STATE = 1<<0; 1965 1966 /** 1967 * Constant for {@link #flags}: this process is associated with a 1968 * persistent system app. 1969 * @hide 1970 */ 1971 public static final int FLAG_PERSISTENT = 1<<1; 1972 1973 /** 1974 * Constant for {@link #flags}: this process is associated with a 1975 * persistent system app. 1976 * @hide 1977 */ 1978 public static final int FLAG_HAS_ACTIVITIES = 1<<2; 1979 1980 /** 1981 * Flags of information. May be any of 1982 * {@link #FLAG_CANT_SAVE_STATE}. 1983 * @hide 1984 */ 1985 public int flags; 1986 1987 /** 1988 * Last memory trim level reported to the process: corresponds to 1989 * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int) 1990 * ComponentCallbacks2.onTrimMemory(int)}. 1991 */ 1992 public int lastTrimLevel; 1993 1994 /** 1995 * Constant for {@link #importance}: this process is running the 1996 * foreground UI. 1997 */ 1998 public static final int IMPORTANCE_FOREGROUND = 100; 1999 2000 /** 2001 * Constant for {@link #importance}: this process is running something 2002 * that is actively visible to the user, though not in the immediate 2003 * foreground. 2004 */ 2005 public static final int IMPORTANCE_VISIBLE = 200; 2006 2007 /** 2008 * Constant for {@link #importance}: this process is running something 2009 * that is considered to be actively perceptible to the user. An 2010 * example would be an application performing background music playback. 2011 */ 2012 public static final int IMPORTANCE_PERCEPTIBLE = 130; 2013 2014 /** 2015 * Constant for {@link #importance}: this process is running an 2016 * application that can not save its state, and thus can't be killed 2017 * while in the background. 2018 * @hide 2019 */ 2020 public static final int IMPORTANCE_CANT_SAVE_STATE = 170; 2021 2022 /** 2023 * Constant for {@link #importance}: this process is contains services 2024 * that should remain running. 2025 */ 2026 public static final int IMPORTANCE_SERVICE = 300; 2027 2028 /** 2029 * Constant for {@link #importance}: this process process contains 2030 * background code that is expendable. 2031 */ 2032 public static final int IMPORTANCE_BACKGROUND = 400; 2033 2034 /** 2035 * Constant for {@link #importance}: this process is empty of any 2036 * actively running code. 2037 */ 2038 public static final int IMPORTANCE_EMPTY = 500; 2039 2040 /** 2041 * Constant for {@link #importance}: this process does not exist. 2042 */ 2043 public static final int IMPORTANCE_GONE = 1000; 2044 2045 /** @hide */ 2046 public static int procStateToImportance(int procState) { 2047 if (procState >= ActivityManager.PROCESS_STATE_HOME) { 2048 return ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND; 2049 } else if (procState >= ActivityManager.PROCESS_STATE_SERVICE) { 2050 return ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE; 2051 } else if (procState > ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) { 2052 return ActivityManager.RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE; 2053 } else if (procState >= ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND) { 2054 return ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE; 2055 } else if (procState >= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { 2056 return ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE; 2057 } else { 2058 return ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND; 2059 } 2060 } 2061 2062 /** 2063 * The relative importance level that the system places on this 2064 * process. May be one of {@link #IMPORTANCE_FOREGROUND}, 2065 * {@link #IMPORTANCE_VISIBLE}, {@link #IMPORTANCE_SERVICE}, 2066 * {@link #IMPORTANCE_BACKGROUND}, or {@link #IMPORTANCE_EMPTY}. These 2067 * constants are numbered so that "more important" values are always 2068 * smaller than "less important" values. 2069 */ 2070 public int importance; 2071 2072 /** 2073 * An additional ordering within a particular {@link #importance} 2074 * category, providing finer-grained information about the relative 2075 * utility of processes within a category. This number means nothing 2076 * except that a smaller values are more recently used (and thus 2077 * more important). Currently an LRU value is only maintained for 2078 * the {@link #IMPORTANCE_BACKGROUND} category, though others may 2079 * be maintained in the future. 2080 */ 2081 public int lru; 2082 2083 /** 2084 * Constant for {@link #importanceReasonCode}: nothing special has 2085 * been specified for the reason for this level. 2086 */ 2087 public static final int REASON_UNKNOWN = 0; 2088 2089 /** 2090 * Constant for {@link #importanceReasonCode}: one of the application's 2091 * content providers is being used by another process. The pid of 2092 * the client process is in {@link #importanceReasonPid} and the 2093 * target provider in this process is in 2094 * {@link #importanceReasonComponent}. 2095 */ 2096 public static final int REASON_PROVIDER_IN_USE = 1; 2097 2098 /** 2099 * Constant for {@link #importanceReasonCode}: one of the application's 2100 * content providers is being used by another process. The pid of 2101 * the client process is in {@link #importanceReasonPid} and the 2102 * target provider in this process is in 2103 * {@link #importanceReasonComponent}. 2104 */ 2105 public static final int REASON_SERVICE_IN_USE = 2; 2106 2107 /** 2108 * The reason for {@link #importance}, if any. 2109 */ 2110 public int importanceReasonCode; 2111 2112 /** 2113 * For the specified values of {@link #importanceReasonCode}, this 2114 * is the process ID of the other process that is a client of this 2115 * process. This will be 0 if no other process is using this one. 2116 */ 2117 public int importanceReasonPid; 2118 2119 /** 2120 * For the specified values of {@link #importanceReasonCode}, this 2121 * is the name of the component that is being used in this process. 2122 */ 2123 public ComponentName importanceReasonComponent; 2124 2125 /** 2126 * When {@link #importanceReasonPid} is non-0, this is the importance 2127 * of the other pid. @hide 2128 */ 2129 public int importanceReasonImportance; 2130 2131 /** 2132 * Current process state, as per PROCESS_STATE_* constants. 2133 * @hide 2134 */ 2135 public int processState; 2136 2137 public RunningAppProcessInfo() { 2138 importance = IMPORTANCE_FOREGROUND; 2139 importanceReasonCode = REASON_UNKNOWN; 2140 processState = PROCESS_STATE_IMPORTANT_FOREGROUND; 2141 } 2142 2143 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) { 2144 processName = pProcessName; 2145 pid = pPid; 2146 pkgList = pArr; 2147 } 2148 2149 public int describeContents() { 2150 return 0; 2151 } 2152 2153 public void writeToParcel(Parcel dest, int flags) { 2154 dest.writeString(processName); 2155 dest.writeInt(pid); 2156 dest.writeInt(uid); 2157 dest.writeStringArray(pkgList); 2158 dest.writeInt(this.flags); 2159 dest.writeInt(lastTrimLevel); 2160 dest.writeInt(importance); 2161 dest.writeInt(lru); 2162 dest.writeInt(importanceReasonCode); 2163 dest.writeInt(importanceReasonPid); 2164 ComponentName.writeToParcel(importanceReasonComponent, dest); 2165 dest.writeInt(importanceReasonImportance); 2166 dest.writeInt(processState); 2167 } 2168 2169 public void readFromParcel(Parcel source) { 2170 processName = source.readString(); 2171 pid = source.readInt(); 2172 uid = source.readInt(); 2173 pkgList = source.readStringArray(); 2174 flags = source.readInt(); 2175 lastTrimLevel = source.readInt(); 2176 importance = source.readInt(); 2177 lru = source.readInt(); 2178 importanceReasonCode = source.readInt(); 2179 importanceReasonPid = source.readInt(); 2180 importanceReasonComponent = ComponentName.readFromParcel(source); 2181 importanceReasonImportance = source.readInt(); 2182 processState = source.readInt(); 2183 } 2184 2185 public static final Creator<RunningAppProcessInfo> CREATOR = 2186 new Creator<RunningAppProcessInfo>() { 2187 public RunningAppProcessInfo createFromParcel(Parcel source) { 2188 return new RunningAppProcessInfo(source); 2189 } 2190 public RunningAppProcessInfo[] newArray(int size) { 2191 return new RunningAppProcessInfo[size]; 2192 } 2193 }; 2194 2195 private RunningAppProcessInfo(Parcel source) { 2196 readFromParcel(source); 2197 } 2198 } 2199 2200 /** 2201 * Returns a list of application processes installed on external media 2202 * that are running on the device. 2203 * 2204 * <p><b>Note: this method is only intended for debugging or building 2205 * a user-facing process management UI.</b></p> 2206 * 2207 * @return Returns a list of ApplicationInfo records, or null if none 2208 * This list ordering is not specified. 2209 * @hide 2210 */ 2211 public List<ApplicationInfo> getRunningExternalApplications() { 2212 try { 2213 return ActivityManagerNative.getDefault().getRunningExternalApplications(); 2214 } catch (RemoteException e) { 2215 return null; 2216 } 2217 } 2218 2219 /** 2220 * Returns a list of application processes that are running on the device. 2221 * 2222 * <p><b>Note: this method is only intended for debugging or building 2223 * a user-facing process management UI.</b></p> 2224 * 2225 * @return Returns a list of RunningAppProcessInfo records, or null if there are no 2226 * running processes (it will not return an empty list). This list ordering is not 2227 * specified. 2228 */ 2229 public List<RunningAppProcessInfo> getRunningAppProcesses() { 2230 try { 2231 return ActivityManagerNative.getDefault().getRunningAppProcesses(); 2232 } catch (RemoteException e) { 2233 return null; 2234 } 2235 } 2236 2237 /** 2238 * Return global memory state information for the calling process. This 2239 * does not fill in all fields of the {@link RunningAppProcessInfo}. The 2240 * only fields that will be filled in are 2241 * {@link RunningAppProcessInfo#pid}, 2242 * {@link RunningAppProcessInfo#uid}, 2243 * {@link RunningAppProcessInfo#lastTrimLevel}, 2244 * {@link RunningAppProcessInfo#importance}, 2245 * {@link RunningAppProcessInfo#lru}, and 2246 * {@link RunningAppProcessInfo#importanceReasonCode}. 2247 */ 2248 static public void getMyMemoryState(RunningAppProcessInfo outState) { 2249 try { 2250 ActivityManagerNative.getDefault().getMyMemoryState(outState); 2251 } catch (RemoteException e) { 2252 } 2253 } 2254 2255 /** 2256 * Return information about the memory usage of one or more processes. 2257 * 2258 * <p><b>Note: this method is only intended for debugging or building 2259 * a user-facing process management UI.</b></p> 2260 * 2261 * @param pids The pids of the processes whose memory usage is to be 2262 * retrieved. 2263 * @return Returns an array of memory information, one for each 2264 * requested pid. 2265 */ 2266 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) { 2267 try { 2268 return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids); 2269 } catch (RemoteException e) { 2270 return null; 2271 } 2272 } 2273 2274 /** 2275 * @deprecated This is now just a wrapper for 2276 * {@link #killBackgroundProcesses(String)}; the previous behavior here 2277 * is no longer available to applications because it allows them to 2278 * break other applications by removing their alarms, stopping their 2279 * services, etc. 2280 */ 2281 @Deprecated 2282 public void restartPackage(String packageName) { 2283 killBackgroundProcesses(packageName); 2284 } 2285 2286 /** 2287 * Have the system immediately kill all background processes associated 2288 * with the given package. This is the same as the kernel killing those 2289 * processes to reclaim memory; the system will take care of restarting 2290 * these processes in the future as needed. 2291 * 2292 * <p>You must hold the permission 2293 * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to 2294 * call this method. 2295 * 2296 * @param packageName The name of the package whose processes are to 2297 * be killed. 2298 */ 2299 public void killBackgroundProcesses(String packageName) { 2300 try { 2301 ActivityManagerNative.getDefault().killBackgroundProcesses(packageName, 2302 UserHandle.myUserId()); 2303 } catch (RemoteException e) { 2304 } 2305 } 2306 2307 /** 2308 * Have the system perform a force stop of everything associated with 2309 * the given application package. All processes that share its uid 2310 * will be killed, all services it has running stopped, all activities 2311 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED} 2312 * broadcast will be sent, so that any of its registered alarms can 2313 * be stopped, notifications removed, etc. 2314 * 2315 * <p>You must hold the permission 2316 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to 2317 * call this method. 2318 * 2319 * @param packageName The name of the package to be stopped. 2320 * @param userId The user for which the running package is to be stopped. 2321 * 2322 * @hide This is not available to third party applications due to 2323 * it allowing them to break other applications by stopping their 2324 * services, removing their alarms, etc. 2325 */ 2326 public void forceStopPackageAsUser(String packageName, int userId) { 2327 try { 2328 ActivityManagerNative.getDefault().forceStopPackage(packageName, userId); 2329 } catch (RemoteException e) { 2330 } 2331 } 2332 2333 /** 2334 * @see #forceStopPackageAsUser(String, int) 2335 * @hide 2336 */ 2337 public void forceStopPackage(String packageName) { 2338 forceStopPackageAsUser(packageName, UserHandle.myUserId()); 2339 } 2340 2341 /** 2342 * Get the device configuration attributes. 2343 */ 2344 public ConfigurationInfo getDeviceConfigurationInfo() { 2345 try { 2346 return ActivityManagerNative.getDefault().getDeviceConfigurationInfo(); 2347 } catch (RemoteException e) { 2348 } 2349 return null; 2350 } 2351 2352 /** 2353 * Get the preferred density of icons for the launcher. This is used when 2354 * custom drawables are created (e.g., for shortcuts). 2355 * 2356 * @return density in terms of DPI 2357 */ 2358 public int getLauncherLargeIconDensity() { 2359 final Resources res = mContext.getResources(); 2360 final int density = res.getDisplayMetrics().densityDpi; 2361 final int sw = res.getConfiguration().smallestScreenWidthDp; 2362 2363 if (sw < 600) { 2364 // Smaller than approx 7" tablets, use the regular icon size. 2365 return density; 2366 } 2367 2368 switch (density) { 2369 case DisplayMetrics.DENSITY_LOW: 2370 return DisplayMetrics.DENSITY_MEDIUM; 2371 case DisplayMetrics.DENSITY_MEDIUM: 2372 return DisplayMetrics.DENSITY_HIGH; 2373 case DisplayMetrics.DENSITY_TV: 2374 return DisplayMetrics.DENSITY_XHIGH; 2375 case DisplayMetrics.DENSITY_HIGH: 2376 return DisplayMetrics.DENSITY_XHIGH; 2377 case DisplayMetrics.DENSITY_XHIGH: 2378 return DisplayMetrics.DENSITY_XXHIGH; 2379 case DisplayMetrics.DENSITY_XXHIGH: 2380 return DisplayMetrics.DENSITY_XHIGH * 2; 2381 default: 2382 // The density is some abnormal value. Return some other 2383 // abnormal value that is a reasonable scaling of it. 2384 return (int)((density*1.5f)+.5f); 2385 } 2386 } 2387 2388 /** 2389 * Get the preferred launcher icon size. This is used when custom drawables 2390 * are created (e.g., for shortcuts). 2391 * 2392 * @return dimensions of square icons in terms of pixels 2393 */ 2394 public int getLauncherLargeIconSize() { 2395 return getLauncherLargeIconSizeInner(mContext); 2396 } 2397 2398 static int getLauncherLargeIconSizeInner(Context context) { 2399 final Resources res = context.getResources(); 2400 final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size); 2401 final int sw = res.getConfiguration().smallestScreenWidthDp; 2402 2403 if (sw < 600) { 2404 // Smaller than approx 7" tablets, use the regular icon size. 2405 return size; 2406 } 2407 2408 final int density = res.getDisplayMetrics().densityDpi; 2409 2410 switch (density) { 2411 case DisplayMetrics.DENSITY_LOW: 2412 return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW; 2413 case DisplayMetrics.DENSITY_MEDIUM: 2414 return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM; 2415 case DisplayMetrics.DENSITY_TV: 2416 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH; 2417 case DisplayMetrics.DENSITY_HIGH: 2418 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH; 2419 case DisplayMetrics.DENSITY_XHIGH: 2420 return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH; 2421 case DisplayMetrics.DENSITY_XXHIGH: 2422 return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH; 2423 default: 2424 // The density is some abnormal value. Return some other 2425 // abnormal value that is a reasonable scaling of it. 2426 return (int)((size*1.5f) + .5f); 2427 } 2428 } 2429 2430 /** 2431 * Returns "true" if the user interface is currently being messed with 2432 * by a monkey. 2433 */ 2434 public static boolean isUserAMonkey() { 2435 try { 2436 return ActivityManagerNative.getDefault().isUserAMonkey(); 2437 } catch (RemoteException e) { 2438 } 2439 return false; 2440 } 2441 2442 /** 2443 * Returns "true" if device is running in a test harness. 2444 */ 2445 public static boolean isRunningInTestHarness() { 2446 return SystemProperties.getBoolean("ro.test_harness", false); 2447 } 2448 2449 /** 2450 * Returns the launch count of each installed package. 2451 * 2452 * @hide 2453 */ 2454 /*public Map<String, Integer> getAllPackageLaunchCounts() { 2455 try { 2456 IUsageStats usageStatsService = IUsageStats.Stub.asInterface( 2457 ServiceManager.getService("usagestats")); 2458 if (usageStatsService == null) { 2459 return new HashMap<String, Integer>(); 2460 } 2461 2462 UsageStats.PackageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats( 2463 ActivityThread.currentPackageName()); 2464 if (allPkgUsageStats == null) { 2465 return new HashMap<String, Integer>(); 2466 } 2467 2468 Map<String, Integer> launchCounts = new HashMap<String, Integer>(); 2469 for (UsageStats.PackageStats pkgUsageStats : allPkgUsageStats) { 2470 launchCounts.put(pkgUsageStats.getPackageName(), pkgUsageStats.getLaunchCount()); 2471 } 2472 2473 return launchCounts; 2474 } catch (RemoteException e) { 2475 Log.w(TAG, "Could not query launch counts", e); 2476 return new HashMap<String, Integer>(); 2477 } 2478 }*/ 2479 2480 /** @hide */ 2481 public static int checkComponentPermission(String permission, int uid, 2482 int owningUid, boolean exported) { 2483 // Root, system server get to do everything. 2484 if (uid == 0 || uid == Process.SYSTEM_UID) { 2485 return PackageManager.PERMISSION_GRANTED; 2486 } 2487 // Isolated processes don't get any permissions. 2488 if (UserHandle.isIsolated(uid)) { 2489 return PackageManager.PERMISSION_DENIED; 2490 } 2491 // If there is a uid that owns whatever is being accessed, it has 2492 // blanket access to it regardless of the permissions it requires. 2493 if (owningUid >= 0 && UserHandle.isSameApp(uid, owningUid)) { 2494 return PackageManager.PERMISSION_GRANTED; 2495 } 2496 // If the target is not exported, then nobody else can get to it. 2497 if (!exported) { 2498 /* 2499 RuntimeException here = new RuntimeException("here"); 2500 here.fillInStackTrace(); 2501 Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid, 2502 here); 2503 */ 2504 return PackageManager.PERMISSION_DENIED; 2505 } 2506 if (permission == null) { 2507 return PackageManager.PERMISSION_GRANTED; 2508 } 2509 try { 2510 return AppGlobals.getPackageManager() 2511 .checkUidPermission(permission, uid); 2512 } catch (RemoteException e) { 2513 // Should never happen, but if it does... deny! 2514 Slog.e(TAG, "PackageManager is dead?!?", e); 2515 } 2516 return PackageManager.PERMISSION_DENIED; 2517 } 2518 2519 /** @hide */ 2520 public static int checkUidPermission(String permission, int uid) { 2521 try { 2522 return AppGlobals.getPackageManager() 2523 .checkUidPermission(permission, uid); 2524 } catch (RemoteException e) { 2525 // Should never happen, but if it does... deny! 2526 Slog.e(TAG, "PackageManager is dead?!?", e); 2527 } 2528 return PackageManager.PERMISSION_DENIED; 2529 } 2530 2531 /** 2532 * @hide 2533 * Helper for dealing with incoming user arguments to system service calls. 2534 * Takes care of checking permissions and converting USER_CURRENT to the 2535 * actual current user. 2536 * 2537 * @param callingPid The pid of the incoming call, as per Binder.getCallingPid(). 2538 * @param callingUid The uid of the incoming call, as per Binder.getCallingUid(). 2539 * @param userId The user id argument supplied by the caller -- this is the user 2540 * they want to run as. 2541 * @param allowAll If true, we will allow USER_ALL. This means you must be prepared 2542 * to get a USER_ALL returned and deal with it correctly. If false, 2543 * an exception will be thrown if USER_ALL is supplied. 2544 * @param requireFull If true, the caller must hold 2545 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} to be able to run as a 2546 * different user than their current process; otherwise they must hold 2547 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}. 2548 * @param name Optional textual name of the incoming call; only for generating error messages. 2549 * @param callerPackage Optional package name of caller; only for error messages. 2550 * 2551 * @return Returns the user ID that the call should run as. Will always be a concrete 2552 * user number, unless <var>allowAll</var> is true in which case it could also be 2553 * USER_ALL. 2554 */ 2555 public static int handleIncomingUser(int callingPid, int callingUid, int userId, 2556 boolean allowAll, boolean requireFull, String name, String callerPackage) { 2557 if (UserHandle.getUserId(callingUid) == userId) { 2558 return userId; 2559 } 2560 try { 2561 return ActivityManagerNative.getDefault().handleIncomingUser(callingPid, 2562 callingUid, userId, allowAll, requireFull, name, callerPackage); 2563 } catch (RemoteException e) { 2564 throw new SecurityException("Failed calling activity manager", e); 2565 } 2566 } 2567 2568 /** 2569 * Gets the userId of the current foreground user. Requires system permissions. 2570 * @hide 2571 */ 2572 @SystemApi 2573 public static int getCurrentUser() { 2574 UserInfo ui; 2575 try { 2576 ui = ActivityManagerNative.getDefault().getCurrentUser(); 2577 return ui != null ? ui.id : 0; 2578 } catch (RemoteException e) { 2579 return 0; 2580 } 2581 } 2582 2583 /** 2584 * @param userid the user's id. Zero indicates the default user 2585 * @hide 2586 */ 2587 public boolean switchUser(int userid) { 2588 try { 2589 return ActivityManagerNative.getDefault().switchUser(userid); 2590 } catch (RemoteException e) { 2591 return false; 2592 } 2593 } 2594 2595 /** 2596 * Return whether the given user is actively running. This means that 2597 * the user is in the "started" state, not "stopped" -- it is currently 2598 * allowed to run code through scheduled alarms, receiving broadcasts, 2599 * etc. A started user may be either the current foreground user or a 2600 * background user; the result here does not distinguish between the two. 2601 * @param userid the user's id. Zero indicates the default user. 2602 * @hide 2603 */ 2604 public boolean isUserRunning(int userid) { 2605 try { 2606 return ActivityManagerNative.getDefault().isUserRunning(userid, false); 2607 } catch (RemoteException e) { 2608 return false; 2609 } 2610 } 2611 2612 /** 2613 * Perform a system dump of various state associated with the given application 2614 * package name. This call blocks while the dump is being performed, so should 2615 * not be done on a UI thread. The data will be written to the given file 2616 * descriptor as text. An application must hold the 2617 * {@link android.Manifest.permission#DUMP} permission to make this call. 2618 * @param fd The file descriptor that the dump should be written to. The file 2619 * descriptor is <em>not</em> closed by this function; the caller continues to 2620 * own it. 2621 * @param packageName The name of the package that is to be dumped. 2622 */ 2623 public void dumpPackageState(FileDescriptor fd, String packageName) { 2624 dumpPackageStateStatic(fd, packageName); 2625 } 2626 2627 /** 2628 * @hide 2629 */ 2630 public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) { 2631 FileOutputStream fout = new FileOutputStream(fd); 2632 PrintWriter pw = new FastPrintWriter(fout); 2633 dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] { 2634 "-a", "package", packageName }); 2635 pw.println(); 2636 dumpService(pw, fd, "meminfo", new String[] { "--local", packageName }); 2637 pw.println(); 2638 dumpService(pw, fd, ProcessStats.SERVICE_NAME, new String[] { "-a", packageName }); 2639 pw.println(); 2640 dumpService(pw, fd, "usagestats", new String[] { "--packages", packageName }); 2641 pw.println(); 2642 dumpService(pw, fd, "package", new String[] { packageName }); 2643 pw.println(); 2644 dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName }); 2645 pw.flush(); 2646 } 2647 2648 private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) { 2649 pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":"); 2650 IBinder service = ServiceManager.checkService(name); 2651 if (service == null) { 2652 pw.println(" (Service not found)"); 2653 return; 2654 } 2655 TransferPipe tp = null; 2656 try { 2657 pw.flush(); 2658 tp = new TransferPipe(); 2659 tp.setBufferPrefix(" "); 2660 service.dumpAsync(tp.getWriteFd().getFileDescriptor(), args); 2661 tp.go(fd); 2662 } catch (Throwable e) { 2663 if (tp != null) { 2664 tp.kill(); 2665 } 2666 pw.println("Failure dumping service:"); 2667 e.printStackTrace(pw); 2668 } 2669 } 2670 2671 /** 2672 * @hide 2673 */ 2674 public void startLockTaskMode(int taskId) { 2675 try { 2676 ActivityManagerNative.getDefault().startLockTaskMode(taskId); 2677 } catch (RemoteException e) { 2678 } 2679 } 2680 2681 /** 2682 * @hide 2683 */ 2684 public void stopLockTaskMode() { 2685 try { 2686 ActivityManagerNative.getDefault().stopLockTaskMode(); 2687 } catch (RemoteException e) { 2688 } 2689 } 2690 2691 /** 2692 * Return whether currently in lock task mode. When in this mode 2693 * no new tasks can be created or switched to. 2694 * 2695 * @see Activity#startLockTask() 2696 */ 2697 public boolean isInLockTaskMode() { 2698 try { 2699 return ActivityManagerNative.getDefault().isInLockTaskMode(); 2700 } catch (RemoteException e) { 2701 return false; 2702 } 2703 } 2704 2705 /** 2706 * The AppTask allows you to manage your own application's tasks. 2707 * See {@link android.app.ActivityManager#getAppTasks()} 2708 */ 2709 public static class AppTask { 2710 private IAppTask mAppTaskImpl; 2711 2712 /** @hide */ 2713 public AppTask(IAppTask task) { 2714 mAppTaskImpl = task; 2715 } 2716 2717 /** 2718 * Finishes all activities in this task and removes it from the recent tasks list. 2719 */ 2720 public void finishAndRemoveTask() { 2721 try { 2722 mAppTaskImpl.finishAndRemoveTask(); 2723 } catch (RemoteException e) { 2724 Slog.e(TAG, "Invalid AppTask", e); 2725 } 2726 } 2727 2728 /** 2729 * Get the RecentTaskInfo associated with this task. 2730 * 2731 * @return The RecentTaskInfo for this task, or null if the task no longer exists. 2732 */ 2733 public RecentTaskInfo getTaskInfo() { 2734 try { 2735 return mAppTaskImpl.getTaskInfo(); 2736 } catch (RemoteException e) { 2737 Slog.e(TAG, "Invalid AppTask", e); 2738 return null; 2739 } 2740 } 2741 2742 /** 2743 * Bring this task to the foreground. If it contains activities, they will be 2744 * brought to the foreground with it and their instances re-created if needed. 2745 * If it doesn't contain activities, the root activity of the task will be 2746 * re-launched. 2747 */ 2748 public void moveToFront() { 2749 try { 2750 mAppTaskImpl.moveToFront(); 2751 } catch (RemoteException e) { 2752 Slog.e(TAG, "Invalid AppTask", e); 2753 } 2754 } 2755 2756 /** 2757 * Start an activity in this task. Brings the task to the foreground. If this task 2758 * is not currently active (that is, its id < 0), then a new activity for the given 2759 * Intent will be launched as the root of the task and the task brought to the 2760 * foreground. Otherwise, if this task is currently active and the Intent does not specify 2761 * an activity to launch in a new task, then a new activity for the given Intent will 2762 * be launched on top of the task and the task brought to the foreground. If this 2763 * task is currently active and the Intent specifies {@link Intent#FLAG_ACTIVITY_NEW_TASK} 2764 * or would otherwise be launched in to a new task, then the activity not launched but 2765 * this task be brought to the foreground and a new intent delivered to the top 2766 * activity if appropriate. 2767 * 2768 * <p>In other words, you generally want to use an Intent here that does not specify 2769 * {@link Intent#FLAG_ACTIVITY_NEW_TASK} or {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT}, 2770 * and let the system do the right thing.</p> 2771 * 2772 * @param intent The Intent describing the new activity to be launched on the task. 2773 * @param options Optional launch options. 2774 * 2775 * @see Activity#startActivity(android.content.Intent, android.os.Bundle) 2776 */ 2777 public void startActivity(Context context, Intent intent, Bundle options) { 2778 ActivityThread thread = ActivityThread.currentActivityThread(); 2779 thread.getInstrumentation().execStartActivityFromAppTask(context, 2780 thread.getApplicationThread(), mAppTaskImpl, intent, options); 2781 } 2782 2783 /** 2784 * Modify the {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag in the root 2785 * Intent of this AppTask. 2786 * 2787 * @param exclude If true, {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} will 2788 * be set; otherwise, it will be cleared. 2789 */ 2790 public void setExcludeFromRecents(boolean exclude) { 2791 try { 2792 mAppTaskImpl.setExcludeFromRecents(exclude); 2793 } catch (RemoteException e) { 2794 Slog.e(TAG, "Invalid AppTask", e); 2795 } 2796 } 2797 } 2798} 2799