Aurimas Liutikas | 93554f2 | 2022-04-19 16:51:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.content; |
| 18 | |
| 19 | import android.annotation.AttrRes; |
| 20 | import android.annotation.CallbackExecutor; |
| 21 | import android.annotation.CheckResult; |
| 22 | import android.annotation.ColorInt; |
| 23 | import android.annotation.ColorRes; |
| 24 | import android.annotation.DisplayContext; |
| 25 | import android.annotation.DrawableRes; |
| 26 | import android.annotation.IntDef; |
| 27 | import android.annotation.NonNull; |
| 28 | import android.annotation.Nullable; |
| 29 | import android.annotation.RequiresPermission; |
| 30 | import android.annotation.StringDef; |
| 31 | import android.annotation.StringRes; |
| 32 | import android.annotation.StyleRes; |
| 33 | import android.annotation.StyleableRes; |
| 34 | import android.annotation.SuppressLint; |
| 35 | import android.annotation.SystemApi; |
| 36 | import android.annotation.TestApi; |
| 37 | import android.annotation.UiContext; |
| 38 | import android.annotation.UserIdInt; |
| 39 | import android.app.ActivityManager; |
| 40 | import android.app.GameManager; |
| 41 | import android.app.IApplicationThread; |
| 42 | import android.app.IServiceConnection; |
| 43 | import android.app.VrManager; |
| 44 | import android.app.people.PeopleManager; |
| 45 | import android.app.time.TimeManager; |
| 46 | import android.compat.annotation.UnsupportedAppUsage; |
| 47 | import android.content.pm.ApplicationInfo; |
| 48 | import android.content.pm.PackageManager; |
| 49 | import android.content.res.AssetManager; |
| 50 | import android.content.res.ColorStateList; |
| 51 | import android.content.res.Configuration; |
| 52 | import android.content.res.Resources; |
| 53 | import android.content.res.TypedArray; |
| 54 | import android.database.DatabaseErrorHandler; |
| 55 | import android.database.sqlite.SQLiteDatabase; |
| 56 | import android.database.sqlite.SQLiteDatabase.CursorFactory; |
| 57 | import android.graphics.Bitmap; |
| 58 | import android.graphics.drawable.Drawable; |
| 59 | import android.net.Uri; |
| 60 | import android.os.Build; |
| 61 | import android.os.Bundle; |
| 62 | import android.os.Environment; |
| 63 | import android.os.Handler; |
| 64 | import android.os.HandlerExecutor; |
| 65 | import android.os.IBinder; |
| 66 | import android.os.Looper; |
| 67 | import android.os.StatFs; |
| 68 | import android.os.UserHandle; |
| 69 | import android.os.UserManager; |
| 70 | import android.os.storage.StorageManager; |
| 71 | import android.provider.MediaStore; |
| 72 | import android.telephony.TelephonyRegistryManager; |
| 73 | import android.util.AttributeSet; |
| 74 | import android.view.Display; |
| 75 | import android.view.DisplayAdjustments; |
| 76 | import android.view.View; |
| 77 | import android.view.ViewDebug; |
| 78 | import android.view.ViewGroup.LayoutParams; |
| 79 | import android.view.WindowManager; |
| 80 | import android.view.WindowManager.LayoutParams.WindowType; |
| 81 | import android.view.autofill.AutofillManager.AutofillClient; |
| 82 | import android.view.contentcapture.ContentCaptureManager.ContentCaptureClient; |
| 83 | import android.view.textclassifier.TextClassificationManager; |
| 84 | import android.window.WindowContext; |
| 85 | |
| 86 | import com.android.internal.compat.IPlatformCompat; |
| 87 | import com.android.internal.compat.IPlatformCompatNative; |
| 88 | |
| 89 | import java.io.File; |
| 90 | import java.io.FileInputStream; |
| 91 | import java.io.FileNotFoundException; |
| 92 | import java.io.FileOutputStream; |
| 93 | import java.io.IOException; |
| 94 | import java.io.InputStream; |
| 95 | import java.lang.annotation.Retention; |
| 96 | import java.lang.annotation.RetentionPolicy; |
| 97 | import java.util.List; |
| 98 | import java.util.concurrent.Executor; |
| 99 | |
| 100 | /** |
| 101 | * Interface to global information about an application environment. This is |
| 102 | * an abstract class whose implementation is provided by |
| 103 | * the Android system. It |
| 104 | * allows access to application-specific resources and classes, as well as |
| 105 | * up-calls for application-level operations such as launching activities, |
| 106 | * broadcasting and receiving intents, etc. |
| 107 | */ |
| 108 | public abstract class Context { |
| 109 | /** @hide */ |
| 110 | @IntDef(flag = true, prefix = { "MODE_" }, value = { |
| 111 | MODE_PRIVATE, |
| 112 | MODE_WORLD_READABLE, |
| 113 | MODE_WORLD_WRITEABLE, |
| 114 | MODE_APPEND, |
| 115 | }) |
| 116 | @Retention(RetentionPolicy.SOURCE) |
| 117 | public @interface FileMode {} |
| 118 | |
| 119 | /** @hide */ |
| 120 | @IntDef(flag = true, prefix = { "MODE_" }, value = { |
| 121 | MODE_PRIVATE, |
| 122 | MODE_WORLD_READABLE, |
| 123 | MODE_WORLD_WRITEABLE, |
| 124 | MODE_MULTI_PROCESS, |
| 125 | }) |
| 126 | @Retention(RetentionPolicy.SOURCE) |
| 127 | public @interface PreferencesMode {} |
| 128 | |
| 129 | /** @hide */ |
| 130 | @IntDef(flag = true, prefix = { "MODE_" }, value = { |
| 131 | MODE_PRIVATE, |
| 132 | MODE_WORLD_READABLE, |
| 133 | MODE_WORLD_WRITEABLE, |
| 134 | MODE_ENABLE_WRITE_AHEAD_LOGGING, |
| 135 | MODE_NO_LOCALIZED_COLLATORS, |
| 136 | }) |
| 137 | @Retention(RetentionPolicy.SOURCE) |
| 138 | public @interface DatabaseMode {} |
| 139 | |
| 140 | /** |
| 141 | * File creation mode: the default mode, where the created file can only |
| 142 | * be accessed by the calling application (or all applications sharing the |
| 143 | * same user ID). |
| 144 | */ |
| 145 | public static final int MODE_PRIVATE = 0x0000; |
| 146 | |
| 147 | /** |
| 148 | * File creation mode: allow all other applications to have read access to |
| 149 | * the created file. |
| 150 | * <p> |
| 151 | * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this |
| 152 | * mode throws a {@link SecurityException}. |
| 153 | * |
| 154 | * @deprecated Creating world-readable files is very dangerous, and likely |
| 155 | * to cause security holes in applications. It is strongly |
| 156 | * discouraged; instead, applications should use more formal |
| 157 | * mechanism for interactions such as {@link ContentProvider}, |
| 158 | * {@link BroadcastReceiver}, and {@link android.app.Service}. |
| 159 | * There are no guarantees that this access mode will remain on |
| 160 | * a file, such as when it goes through a backup and restore. |
| 161 | * @see android.support.v4.content.FileProvider |
| 162 | * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 163 | */ |
| 164 | @Deprecated |
| 165 | public static final int MODE_WORLD_READABLE = 0x0001; |
| 166 | |
| 167 | /** |
| 168 | * File creation mode: allow all other applications to have write access to |
| 169 | * the created file. |
| 170 | * <p> |
| 171 | * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this |
| 172 | * mode will throw a {@link SecurityException}. |
| 173 | * |
| 174 | * @deprecated Creating world-writable files is very dangerous, and likely |
| 175 | * to cause security holes in applications. It is strongly |
| 176 | * discouraged; instead, applications should use more formal |
| 177 | * mechanism for interactions such as {@link ContentProvider}, |
| 178 | * {@link BroadcastReceiver}, and {@link android.app.Service}. |
| 179 | * There are no guarantees that this access mode will remain on |
| 180 | * a file, such as when it goes through a backup and restore. |
| 181 | * @see android.support.v4.content.FileProvider |
| 182 | * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 183 | */ |
| 184 | @Deprecated |
| 185 | public static final int MODE_WORLD_WRITEABLE = 0x0002; |
| 186 | |
| 187 | /** |
| 188 | * File creation mode: for use with {@link #openFileOutput}, if the file |
| 189 | * already exists then write data to the end of the existing file |
| 190 | * instead of erasing it. |
| 191 | * @see #openFileOutput |
| 192 | */ |
| 193 | public static final int MODE_APPEND = 0x8000; |
| 194 | |
| 195 | /** |
| 196 | * SharedPreference loading flag: when set, the file on disk will |
| 197 | * be checked for modification even if the shared preferences |
| 198 | * instance is already loaded in this process. This behavior is |
| 199 | * sometimes desired in cases where the application has multiple |
| 200 | * processes, all writing to the same SharedPreferences file. |
| 201 | * Generally there are better forms of communication between |
| 202 | * processes, though. |
| 203 | * |
| 204 | * <p>This was the legacy (but undocumented) behavior in and |
| 205 | * before Gingerbread (Android 2.3) and this flag is implied when |
| 206 | * targeting such releases. For applications targeting SDK |
| 207 | * versions <em>greater than</em> Android 2.3, this flag must be |
| 208 | * explicitly set if desired. |
| 209 | * |
| 210 | * @see #getSharedPreferences |
| 211 | * |
| 212 | * @deprecated MODE_MULTI_PROCESS does not work reliably in |
| 213 | * some versions of Android, and furthermore does not provide any |
| 214 | * mechanism for reconciling concurrent modifications across |
| 215 | * processes. Applications should not attempt to use it. Instead, |
| 216 | * they should use an explicit cross-process data management |
| 217 | * approach such as {@link android.content.ContentProvider ContentProvider}. |
| 218 | */ |
| 219 | @Deprecated |
| 220 | public static final int MODE_MULTI_PROCESS = 0x0004; |
| 221 | |
| 222 | /** |
| 223 | * Database open flag: when set, the database is opened with write-ahead |
| 224 | * logging enabled by default. |
| 225 | * |
| 226 | * @see #openOrCreateDatabase(String, int, CursorFactory) |
| 227 | * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler) |
| 228 | * @see SQLiteDatabase#enableWriteAheadLogging |
| 229 | */ |
| 230 | public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008; |
| 231 | |
| 232 | /** |
| 233 | * Database open flag: when set, the database is opened without support for |
| 234 | * localized collators. |
| 235 | * |
| 236 | * @see #openOrCreateDatabase(String, int, CursorFactory) |
| 237 | * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler) |
| 238 | * @see SQLiteDatabase#NO_LOCALIZED_COLLATORS |
| 239 | */ |
| 240 | public static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010; |
| 241 | |
| 242 | /** @hide */ |
| 243 | @IntDef(flag = true, prefix = { "BIND_" }, value = { |
| 244 | BIND_AUTO_CREATE, |
| 245 | BIND_DEBUG_UNBIND, |
| 246 | BIND_NOT_FOREGROUND, |
| 247 | BIND_ABOVE_CLIENT, |
| 248 | BIND_ALLOW_OOM_MANAGEMENT, |
| 249 | BIND_WAIVE_PRIORITY, |
| 250 | BIND_IMPORTANT, |
| 251 | BIND_ADJUST_WITH_ACTIVITY, |
| 252 | BIND_NOT_PERCEPTIBLE, |
| 253 | BIND_INCLUDE_CAPABILITIES |
| 254 | }) |
| 255 | @Retention(RetentionPolicy.SOURCE) |
| 256 | public @interface BindServiceFlags {} |
| 257 | |
| 258 | /** |
| 259 | * Flag for {@link #bindService}: automatically create the service as long |
| 260 | * as the binding exists. Note that while this will create the service, |
| 261 | * its {@link android.app.Service#onStartCommand} |
| 262 | * method will still only be called due to an |
| 263 | * explicit call to {@link #startService}. Even without that, though, |
| 264 | * this still provides you with access to the service object while the |
| 265 | * service is created. |
| 266 | * |
| 267 | * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, |
| 268 | * not supplying this flag would also impact how important the system |
| 269 | * consider's the target service's process to be. When set, the only way |
| 270 | * for it to be raised was by binding from a service in which case it will |
| 271 | * only be important when that activity is in the foreground. Now to |
| 272 | * achieve this behavior you must explicitly supply the new flag |
| 273 | * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications |
| 274 | * that don't specify {@link #BIND_AUTO_CREATE} will automatically have |
| 275 | * the flags {@link #BIND_WAIVE_PRIORITY} and |
| 276 | * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve |
| 277 | * the same result. |
| 278 | */ |
| 279 | public static final int BIND_AUTO_CREATE = 0x0001; |
| 280 | |
| 281 | /** |
| 282 | * Flag for {@link #bindService}: include debugging help for mismatched |
| 283 | * calls to unbind. When this flag is set, the callstack of the following |
| 284 | * {@link #unbindService} call is retained, to be printed if a later |
| 285 | * incorrect unbind call is made. Note that doing this requires retaining |
| 286 | * information about the binding that was made for the lifetime of the app, |
| 287 | * resulting in a leak -- this should only be used for debugging. |
| 288 | */ |
| 289 | public static final int BIND_DEBUG_UNBIND = 0x0002; |
| 290 | |
| 291 | /** |
| 292 | * Flag for {@link #bindService}: don't allow this binding to raise |
| 293 | * the target service's process to the foreground scheduling priority. |
| 294 | * It will still be raised to at least the same memory priority |
| 295 | * as the client (so that its process will not be killable in any |
| 296 | * situation where the client is not killable), but for CPU scheduling |
| 297 | * purposes it may be left in the background. This only has an impact |
| 298 | * in the situation where the binding client is a foreground process |
| 299 | * and the target service is in a background process. |
| 300 | */ |
| 301 | public static final int BIND_NOT_FOREGROUND = 0x0004; |
| 302 | |
| 303 | /** |
| 304 | * Flag for {@link #bindService}: indicates that the client application |
| 305 | * binding to this service considers the service to be more important than |
| 306 | * the app itself. When set, the platform will try to have the out of |
| 307 | * memory killer kill the app before it kills the service it is bound to, though |
| 308 | * this is not guaranteed to be the case. |
| 309 | */ |
| 310 | public static final int BIND_ABOVE_CLIENT = 0x0008; |
| 311 | |
| 312 | /** |
| 313 | * Flag for {@link #bindService}: allow the process hosting the bound |
| 314 | * service to go through its normal memory management. It will be |
| 315 | * treated more like a running service, allowing the system to |
| 316 | * (temporarily) expunge the process if low on memory or for some other |
| 317 | * whim it may have, and being more aggressive about making it a candidate |
| 318 | * to be killed (and restarted) if running for a long time. |
| 319 | */ |
| 320 | public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010; |
| 321 | |
| 322 | /** |
| 323 | * Flag for {@link #bindService}: don't impact the scheduling or |
| 324 | * memory management priority of the target service's hosting process. |
| 325 | * Allows the service's process to be managed on the background LRU list |
| 326 | * just like a regular application process in the background. |
| 327 | */ |
| 328 | public static final int BIND_WAIVE_PRIORITY = 0x0020; |
| 329 | |
| 330 | /** |
| 331 | * Flag for {@link #bindService}: this service is very important to |
| 332 | * the client, so should be brought to the foreground process level |
| 333 | * when the client is. Normally a process can only be raised to the |
| 334 | * visibility level by a client, even if that client is in the foreground. |
| 335 | */ |
| 336 | public static final int BIND_IMPORTANT = 0x0040; |
| 337 | |
| 338 | /** |
| 339 | * Flag for {@link #bindService}: If binding from an activity, allow the |
| 340 | * target service's process importance to be raised based on whether the |
| 341 | * activity is visible to the user, regardless whether another flag is |
| 342 | * used to reduce the amount that the client process's overall importance |
| 343 | * is used to impact it. |
| 344 | */ |
| 345 | public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080; |
| 346 | |
| 347 | /** |
| 348 | * Flag for {@link #bindService}: If binding from an app that is visible or user-perceptible, |
| 349 | * lower the target service's importance to below the perceptible level. This allows |
| 350 | * the system to (temporarily) expunge the bound process from memory to make room for more |
| 351 | * important user-perceptible processes. |
| 352 | */ |
| 353 | public static final int BIND_NOT_PERCEPTIBLE = 0x00000100; |
| 354 | |
| 355 | /** |
| 356 | * Flag for {@link #bindService}: If binding from an app that has specific capabilities |
| 357 | * due to its foreground state such as an activity or foreground service, then this flag will |
| 358 | * allow the bound app to get the same capabilities, as long as it has the required permissions |
| 359 | * as well. |
| 360 | * |
| 361 | * If binding from a top app and its target SDK version is at or above |
| 362 | * {@link android.os.Build.VERSION_CODES#R}, the app needs to |
| 363 | * explicitly use BIND_INCLUDE_CAPABILITIES flag to pass all capabilities to the service so the |
| 364 | * other app can have while-use-use access such as location, camera, microphone from background. |
| 365 | * If binding from a top app and its target SDK version is below |
| 366 | * {@link android.os.Build.VERSION_CODES#R}, BIND_INCLUDE_CAPABILITIES is implicit. |
| 367 | */ |
| 368 | public static final int BIND_INCLUDE_CAPABILITIES = 0x000001000; |
| 369 | |
| 370 | /*********** Public flags above this line ***********/ |
| 371 | /*********** Hidden flags below this line ***********/ |
| 372 | |
| 373 | /** |
| 374 | * Flag for {@link #bindService}: This flag is only intended to be used by the system to |
| 375 | * indicate that a service binding is not considered as real package component usage and should |
| 376 | * not generate a {@link android.app.usage.UsageEvents.Event#APP_COMPONENT_USED} event in usage |
| 377 | * stats. |
| 378 | * @hide |
| 379 | */ |
| 380 | public static final int BIND_NOT_APP_COMPONENT_USAGE = 0x00008000; |
| 381 | |
| 382 | /** |
| 383 | * Flag for {@link #bindService}: allow the process hosting the target service to be treated |
| 384 | * as if it's as important as a perceptible app to the user and avoid the oom killer killing |
| 385 | * this process in low memory situations until there aren't any other processes left but the |
| 386 | * ones which are user-perceptible. |
| 387 | * |
| 388 | * @hide |
| 389 | */ |
| 390 | public static final int BIND_ALMOST_PERCEPTIBLE = 0x000010000; |
| 391 | |
| 392 | /** |
| 393 | * Flag for {@link #bindService}: allow the process hosting the target service to gain |
| 394 | * {@link ActivityManager#PROCESS_CAPABILITY_NETWORK}, which allows it be able |
| 395 | * to access network regardless of any power saving restrictions. |
| 396 | * |
| 397 | * @hide |
| 398 | */ |
| 399 | public static final int BIND_BYPASS_POWER_NETWORK_RESTRICTIONS = 0x00020000; |
| 400 | |
| 401 | /** |
| 402 | * Do not use. This flag is no longer needed nor used. |
| 403 | * @hide |
| 404 | */ |
| 405 | @SystemApi |
| 406 | public static final int BIND_ALLOW_FOREGROUND_SERVICE_STARTS_FROM_BACKGROUND = 0x00040000; |
| 407 | |
| 408 | /** |
| 409 | * Flag for {@link #bindService}: This flag is intended to be used only by the system to adjust |
| 410 | * the scheduling policy for IMEs (and any other out-of-process user-visible components that |
| 411 | * work closely with the top app) so that UI hosted in such services can have the same |
| 412 | * scheduling policy (e.g. SCHED_FIFO when it is enabled and TOP_APP_PRIORITY_BOOST otherwise) |
| 413 | * as the actual top-app. |
| 414 | * @hide |
| 415 | */ |
| 416 | public static final int BIND_SCHEDULE_LIKE_TOP_APP = 0x00080000; |
| 417 | |
| 418 | /** |
| 419 | * Flag for {@link #bindService}: allow background activity starts from the bound service's |
| 420 | * process. |
| 421 | * This flag is only respected if the caller is holding |
| 422 | * {@link android.Manifest.permission#START_ACTIVITIES_FROM_BACKGROUND}. |
| 423 | * @hide |
| 424 | */ |
| 425 | @SystemApi |
| 426 | public static final int BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS = 0x00100000; |
| 427 | |
| 428 | /** |
| 429 | * @hide Flag for {@link #bindService}: the service being bound to represents a |
| 430 | * protected system component, so must have association restrictions applied to it. |
| 431 | * That is, a system config must have one or more allow-association tags limiting |
| 432 | * which packages it can interact with. If it does not have any such association |
| 433 | * restrictions, a default empty set will be created. |
| 434 | */ |
| 435 | public static final int BIND_RESTRICT_ASSOCIATIONS = 0x00200000; |
| 436 | |
| 437 | /** |
| 438 | * @hide Flag for {@link #bindService}: allows binding to a service provided |
| 439 | * by an instant app. Note that the caller may not have access to the instant |
| 440 | * app providing the service which is a violation of the instant app sandbox. |
| 441 | * This flag is intended ONLY for development/testing and should be used with |
| 442 | * great care. Only the system is allowed to use this flag. |
| 443 | */ |
| 444 | public static final int BIND_ALLOW_INSTANT = 0x00400000; |
| 445 | |
| 446 | /** |
| 447 | * @hide Flag for {@link #bindService}: like {@link #BIND_NOT_FOREGROUND}, but puts it |
| 448 | * up in to the important background state (instead of transient). |
| 449 | */ |
| 450 | public static final int BIND_IMPORTANT_BACKGROUND = 0x00800000; |
| 451 | |
| 452 | /** |
| 453 | * @hide Flag for {@link #bindService}: allows application hosting service to manage whitelists |
| 454 | * such as temporary allowing a {@code PendingIntent} to bypass Power Save mode. |
| 455 | */ |
| 456 | public static final int BIND_ALLOW_WHITELIST_MANAGEMENT = 0x01000000; |
| 457 | |
| 458 | /** |
| 459 | * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE}, |
| 460 | * but only applies while the device is awake. |
| 461 | */ |
| 462 | public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000; |
| 463 | |
| 464 | /** |
| 465 | * @hide Flag for {@link #bindService}: For only the case where the binding |
| 466 | * is coming from the system, set the process state to FOREGROUND_SERVICE |
| 467 | * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is |
| 468 | * saying that the process shouldn't participate in the normal power reduction |
| 469 | * modes (removing network access etc). |
| 470 | */ |
| 471 | public static final int BIND_FOREGROUND_SERVICE = 0x04000000; |
| 472 | |
| 473 | /** |
| 474 | * @hide Flag for {@link #bindService}: Treat the binding as hosting |
| 475 | * an activity, an unbinding as the activity going in the background. |
| 476 | * That is, when unbinding, the process when empty will go on the activity |
| 477 | * LRU list instead of the regular one, keeping it around more aggressively |
| 478 | * than it otherwise would be. This is intended for use with IMEs to try |
| 479 | * to keep IME processes around for faster keyboard switching. |
| 480 | */ |
| 481 | public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000; |
| 482 | |
| 483 | /** |
| 484 | * @hide An idea that is not yet implemented. |
| 485 | * Flag for {@link #bindService}: If binding from an activity, consider |
| 486 | * this service to be visible like the binding activity is. That is, |
| 487 | * it will be treated as something more important to keep around than |
| 488 | * invisible background activities. This will impact the number of |
| 489 | * recent activities the user can switch between without having them |
| 490 | * restart. There is no guarantee this will be respected, as the system |
| 491 | * tries to balance such requests from one app vs. the importance of |
| 492 | * keeping other apps around. |
| 493 | */ |
| 494 | public static final int BIND_VISIBLE = 0x10000000; |
| 495 | |
| 496 | /** |
| 497 | * @hide |
| 498 | * Flag for {@link #bindService}: Consider this binding to be causing the target |
| 499 | * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes |
| 500 | * away. |
| 501 | */ |
| 502 | public static final int BIND_SHOWING_UI = 0x20000000; |
| 503 | |
| 504 | /** |
| 505 | * Flag for {@link #bindService}: Don't consider the bound service to be |
| 506 | * visible, even if the caller is visible. |
| 507 | * @hide |
| 508 | */ |
| 509 | public static final int BIND_NOT_VISIBLE = 0x40000000; |
| 510 | |
| 511 | /** |
| 512 | * Flag for {@link #bindService}: The service being bound is an |
| 513 | * {@link android.R.attr#isolatedProcess isolated}, |
| 514 | * {@link android.R.attr#externalService external} service. This binds the service into the |
| 515 | * calling application's package, rather than the package in which the service is declared. |
| 516 | * <p> |
| 517 | * When using this flag, the code for the service being bound will execute under the calling |
| 518 | * application's package name and user ID. Because the service must be an isolated process, |
| 519 | * it will not have direct access to the application's data, though. |
| 520 | * |
| 521 | * The purpose of this flag is to allow applications to provide services that are attributed |
| 522 | * to the app using the service, rather than the application providing the service. |
| 523 | * </p> |
| 524 | */ |
| 525 | public static final int BIND_EXTERNAL_SERVICE = 0x80000000; |
| 526 | |
| 527 | /** |
| 528 | * These bind flags reduce the strength of the binding such that we shouldn't |
| 529 | * consider it as pulling the process up to the level of the one that is bound to it. |
| 530 | * @hide |
| 531 | */ |
| 532 | public static final int BIND_REDUCTION_FLAGS = |
| 533 | Context.BIND_ALLOW_OOM_MANAGEMENT | Context.BIND_WAIVE_PRIORITY |
| 534 | | Context.BIND_NOT_PERCEPTIBLE | Context.BIND_NOT_VISIBLE; |
| 535 | |
| 536 | /** @hide */ |
| 537 | @IntDef(flag = true, prefix = { "RECEIVER_VISIBLE_" }, value = { |
| 538 | RECEIVER_VISIBLE_TO_INSTANT_APPS |
| 539 | }) |
| 540 | @Retention(RetentionPolicy.SOURCE) |
| 541 | public @interface RegisterReceiverFlags {} |
| 542 | |
| 543 | /** |
| 544 | * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from Instant Apps. |
| 545 | */ |
| 546 | public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 0x1; |
| 547 | |
| 548 | /** |
| 549 | * Returns an AssetManager instance for the application's package. |
| 550 | * <p> |
| 551 | * <strong>Note:</strong> Implementations of this method should return |
| 552 | * an AssetManager instance that is consistent with the Resources instance |
| 553 | * returned by {@link #getResources()}. For example, they should share the |
| 554 | * same {@link Configuration} object. |
| 555 | * |
| 556 | * @return an AssetManager instance for the application's package |
| 557 | * @see #getResources() |
| 558 | */ |
| 559 | public abstract AssetManager getAssets(); |
| 560 | |
| 561 | /** |
| 562 | * Returns a Resources instance for the application's package. |
| 563 | * <p> |
| 564 | * <strong>Note:</strong> Implementations of this method should return |
| 565 | * a Resources instance that is consistent with the AssetManager instance |
| 566 | * returned by {@link #getAssets()}. For example, they should share the |
| 567 | * same {@link Configuration} object. |
| 568 | * |
| 569 | * @return a Resources instance for the application's package |
| 570 | * @see #getAssets() |
| 571 | */ |
| 572 | public abstract Resources getResources(); |
| 573 | |
| 574 | /** Return PackageManager instance to find global package information. */ |
| 575 | public abstract PackageManager getPackageManager(); |
| 576 | |
| 577 | /** Return a ContentResolver instance for your application's package. */ |
| 578 | public abstract ContentResolver getContentResolver(); |
| 579 | |
| 580 | /** |
| 581 | * Return the Looper for the main thread of the current process. This is |
| 582 | * the thread used to dispatch calls to application components (activities, |
| 583 | * services, etc). |
| 584 | * <p> |
| 585 | * By definition, this method returns the same result as would be obtained |
| 586 | * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}. |
| 587 | * </p> |
| 588 | * |
| 589 | * @return The main looper. |
| 590 | */ |
| 591 | public abstract Looper getMainLooper(); |
| 592 | |
| 593 | /** |
| 594 | * Return an {@link Executor} that will run enqueued tasks on the main |
| 595 | * thread associated with this context. This is the thread used to dispatch |
| 596 | * calls to application components (activities, services, etc). |
| 597 | */ |
| 598 | public Executor getMainExecutor() { |
| 599 | // This is pretty inefficient, which is why ContextImpl overrides it |
| 600 | return new HandlerExecutor(new Handler(getMainLooper())); |
| 601 | } |
| 602 | |
| 603 | /** |
| 604 | * Return the context of the single, global Application object of the |
| 605 | * current process. This generally should only be used if you need a |
| 606 | * Context whose lifecycle is separate from the current context, that is |
| 607 | * tied to the lifetime of the process rather than the current component. |
| 608 | * |
| 609 | * <p>Consider for example how this interacts with |
| 610 | * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}: |
| 611 | * <ul> |
| 612 | * <li> <p>If used from an Activity context, the receiver is being registered |
| 613 | * within that activity. This means that you are expected to unregister |
| 614 | * before the activity is done being destroyed; in fact if you do not do |
| 615 | * so, the framework will clean up your leaked registration as it removes |
| 616 | * the activity and log an error. Thus, if you use the Activity context |
| 617 | * to register a receiver that is static (global to the process, not |
| 618 | * associated with an Activity instance) then that registration will be |
| 619 | * removed on you at whatever point the activity you used is destroyed. |
| 620 | * <li> <p>If used from the Context returned here, the receiver is being |
| 621 | * registered with the global state associated with your application. Thus |
| 622 | * it will never be unregistered for you. This is necessary if the receiver |
| 623 | * is associated with static data, not a particular component. However |
| 624 | * using the ApplicationContext elsewhere can easily lead to serious leaks |
| 625 | * if you forget to unregister, unbind, etc. |
| 626 | * </ul> |
| 627 | */ |
| 628 | public abstract Context getApplicationContext(); |
| 629 | |
| 630 | /** Non-activity related autofill ids are unique in the app */ |
| 631 | private static int sLastAutofillId = View.NO_ID; |
| 632 | |
| 633 | /** |
| 634 | * Gets the next autofill ID. |
| 635 | * |
| 636 | * <p>All IDs will be smaller or the same as {@link View#LAST_APP_AUTOFILL_ID}. All IDs |
| 637 | * returned will be unique. |
| 638 | * |
| 639 | * @return A ID that is unique in the process |
| 640 | * |
| 641 | * {@hide} |
| 642 | */ |
| 643 | public int getNextAutofillId() { |
| 644 | if (sLastAutofillId == View.LAST_APP_AUTOFILL_ID - 1) { |
| 645 | sLastAutofillId = View.NO_ID; |
| 646 | } |
| 647 | |
| 648 | sLastAutofillId++; |
| 649 | |
| 650 | return sLastAutofillId; |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * Add a new {@link ComponentCallbacks} to the base application of the |
| 655 | * Context, which will be called at the same times as the ComponentCallbacks |
| 656 | * methods of activities and other components are called. Note that you |
| 657 | * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when |
| 658 | * appropriate in the future; this will not be removed for you. |
| 659 | * <p> |
| 660 | * After {@link Build.VERSION_CODES#S}, Registering the ComponentCallbacks to Context created |
| 661 | * via {@link #createWindowContext(int, Bundle)} or |
| 662 | * {@link #createWindowContext(Display, int, Bundle)} will receive |
| 663 | * {@link ComponentCallbacks#onConfigurationChanged(Configuration)} from Window Context rather |
| 664 | * than its base application. It is helpful if you want to handle UI components that |
| 665 | * associated with the Window Context when the Window Context has configuration changes.</p> |
| 666 | * |
| 667 | * @param callback The interface to call. This can be either a |
| 668 | * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface. |
| 669 | * |
| 670 | * @see Context#createWindowContext(int, Bundle) |
| 671 | */ |
| 672 | public void registerComponentCallbacks(ComponentCallbacks callback) { |
| 673 | getApplicationContext().registerComponentCallbacks(callback); |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * Remove a {@link ComponentCallbacks} object that was previously registered |
| 678 | * with {@link #registerComponentCallbacks(ComponentCallbacks)}. |
| 679 | */ |
| 680 | public void unregisterComponentCallbacks(ComponentCallbacks callback) { |
| 681 | getApplicationContext().unregisterComponentCallbacks(callback); |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * Return a localized, styled CharSequence from the application's package's |
| 686 | * default string table. |
| 687 | * |
| 688 | * @param resId Resource id for the CharSequence text |
| 689 | */ |
| 690 | @NonNull |
| 691 | public final CharSequence getText(@StringRes int resId) { |
| 692 | return getResources().getText(resId); |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * Returns a localized string from the application's package's |
| 697 | * default string table. |
| 698 | * |
| 699 | * @param resId Resource id for the string |
| 700 | * @return The string data associated with the resource, stripped of styled |
| 701 | * text information. |
| 702 | */ |
| 703 | @NonNull |
| 704 | public final String getString(@StringRes int resId) { |
| 705 | return getResources().getString(resId); |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * Returns a localized formatted string from the application's package's |
| 710 | * default string table, substituting the format arguments as defined in |
| 711 | * {@link java.util.Formatter} and {@link java.lang.String#format}. |
| 712 | * |
| 713 | * @param resId Resource id for the format string |
| 714 | * @param formatArgs The format arguments that will be used for |
| 715 | * substitution. |
| 716 | * @return The string data associated with the resource, formatted and |
| 717 | * stripped of styled text information. |
| 718 | */ |
| 719 | @NonNull |
| 720 | public final String getString(@StringRes int resId, Object... formatArgs) { |
| 721 | return getResources().getString(resId, formatArgs); |
| 722 | } |
| 723 | |
| 724 | /** |
| 725 | * Returns a color associated with a particular resource ID and styled for |
| 726 | * the current theme. |
| 727 | * |
| 728 | * @param id The desired resource identifier, as generated by the aapt |
| 729 | * tool. This integer encodes the package, type, and resource |
| 730 | * entry. The value 0 is an invalid identifier. |
| 731 | * @return A single color value in the form 0xAARRGGBB. |
| 732 | * @throws android.content.res.Resources.NotFoundException if the given ID |
| 733 | * does not exist. |
| 734 | */ |
| 735 | @ColorInt |
| 736 | public final int getColor(@ColorRes int id) { |
| 737 | return getResources().getColor(id, getTheme()); |
| 738 | } |
| 739 | |
| 740 | /** |
| 741 | * Returns a drawable object associated with a particular resource ID and |
| 742 | * styled for the current theme. |
| 743 | * |
| 744 | * @param id The desired resource identifier, as generated by the aapt |
| 745 | * tool. This integer encodes the package, type, and resource |
| 746 | * entry. The value 0 is an invalid identifier. |
| 747 | * @return An object that can be used to draw this resource. |
| 748 | * @throws android.content.res.Resources.NotFoundException if the given ID |
| 749 | * does not exist. |
| 750 | */ |
| 751 | @Nullable |
| 752 | public final Drawable getDrawable(@DrawableRes int id) { |
| 753 | return getResources().getDrawable(id, getTheme()); |
| 754 | } |
| 755 | |
| 756 | /** |
| 757 | * Returns a color state list associated with a particular resource ID and |
| 758 | * styled for the current theme. |
| 759 | * |
| 760 | * @param id The desired resource identifier, as generated by the aapt |
| 761 | * tool. This integer encodes the package, type, and resource |
| 762 | * entry. The value 0 is an invalid identifier. |
| 763 | * @return A color state list. |
| 764 | * @throws android.content.res.Resources.NotFoundException if the given ID |
| 765 | * does not exist. |
| 766 | */ |
| 767 | @NonNull |
| 768 | public final ColorStateList getColorStateList(@ColorRes int id) { |
| 769 | return getResources().getColorStateList(id, getTheme()); |
| 770 | } |
| 771 | |
| 772 | /** |
| 773 | * Set the base theme for this context. Note that this should be called |
| 774 | * before any views are instantiated in the Context (for example before |
| 775 | * calling {@link android.app.Activity#setContentView} or |
| 776 | * {@link android.view.LayoutInflater#inflate}). |
| 777 | * |
| 778 | * @param resid The style resource describing the theme. |
| 779 | */ |
| 780 | public abstract void setTheme(@StyleRes int resid); |
| 781 | |
| 782 | /** @hide Needed for some internal implementation... not public because |
| 783 | * you can't assume this actually means anything. */ |
| 784 | @UnsupportedAppUsage |
| 785 | public int getThemeResId() { |
| 786 | return 0; |
| 787 | } |
| 788 | |
| 789 | /** |
| 790 | * Return the Theme object associated with this Context. |
| 791 | */ |
| 792 | @ViewDebug.ExportedProperty(deepExport = true) |
| 793 | public abstract Resources.Theme getTheme(); |
| 794 | |
| 795 | /** |
| 796 | * Retrieve styled attribute information in this Context's theme. See |
| 797 | * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])} |
| 798 | * for more information. |
| 799 | * |
| 800 | * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[]) |
| 801 | */ |
| 802 | @NonNull |
| 803 | public final TypedArray obtainStyledAttributes(@NonNull @StyleableRes int[] attrs) { |
| 804 | return getTheme().obtainStyledAttributes(attrs); |
| 805 | } |
| 806 | |
| 807 | /** |
| 808 | * Retrieve styled attribute information in this Context's theme. See |
| 809 | * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])} |
| 810 | * for more information. |
| 811 | * |
| 812 | * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[]) |
| 813 | */ |
| 814 | @NonNull |
| 815 | public final TypedArray obtainStyledAttributes(@StyleRes int resid, |
| 816 | @NonNull @StyleableRes int[] attrs) throws Resources.NotFoundException { |
| 817 | return getTheme().obtainStyledAttributes(resid, attrs); |
| 818 | } |
| 819 | |
| 820 | /** |
| 821 | * Retrieve styled attribute information in this Context's theme. See |
| 822 | * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)} |
| 823 | * for more information. |
| 824 | * |
| 825 | * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) |
| 826 | */ |
| 827 | @NonNull |
| 828 | public final TypedArray obtainStyledAttributes( |
| 829 | @Nullable AttributeSet set, @NonNull @StyleableRes int[] attrs) { |
| 830 | return getTheme().obtainStyledAttributes(set, attrs, 0, 0); |
| 831 | } |
| 832 | |
| 833 | /** |
| 834 | * Retrieve styled attribute information in this Context's theme. See |
| 835 | * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)} |
| 836 | * for more information. |
| 837 | * |
| 838 | * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) |
| 839 | */ |
| 840 | @NonNull |
| 841 | public final TypedArray obtainStyledAttributes(@Nullable AttributeSet set, |
| 842 | @NonNull @StyleableRes int[] attrs, @AttrRes int defStyleAttr, |
| 843 | @StyleRes int defStyleRes) { |
| 844 | return getTheme().obtainStyledAttributes( |
| 845 | set, attrs, defStyleAttr, defStyleRes); |
| 846 | } |
| 847 | |
| 848 | /** |
| 849 | * Return a class loader you can use to retrieve classes in this package. |
| 850 | */ |
| 851 | public abstract ClassLoader getClassLoader(); |
| 852 | |
| 853 | /** Return the name of this application's package. */ |
| 854 | public abstract String getPackageName(); |
| 855 | |
| 856 | /** |
| 857 | * @hide Return the name of the base context this context is derived from. |
| 858 | * This is the same as {@link #getOpPackageName()} except in |
| 859 | * cases where system components are loaded into other app processes, in which |
| 860 | * case {@link #getOpPackageName()} will be the name of the primary package in |
| 861 | * that process (so that app ops uid verification will work with the name). |
| 862 | */ |
| 863 | @SuppressWarnings("HiddenAbstractMethod") |
| 864 | @UnsupportedAppUsage |
| 865 | public abstract String getBasePackageName(); |
| 866 | |
| 867 | /** |
| 868 | * Return the package name that should be used for {@link android.app.AppOpsManager} calls from |
| 869 | * this context, so that app ops manager's uid verification will work with the name. |
| 870 | * <p> |
| 871 | * This is not generally intended for third party application developers. |
| 872 | */ |
| 873 | @NonNull |
| 874 | public String getOpPackageName() { |
| 875 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 876 | } |
| 877 | |
| 878 | /** |
| 879 | * <p>Attribution can be used in complex apps to logically separate parts of the app. E.g. a |
| 880 | * blogging app might also have a instant messaging app built in. In this case two separate tags |
| 881 | * can for used each sub-feature. |
| 882 | * |
| 883 | * @return the attribution tag this context is for or {@code null} if this is the default. |
| 884 | */ |
| 885 | public @Nullable String getAttributionTag() { |
| 886 | return null; |
| 887 | } |
| 888 | |
| 889 | /** |
| 890 | * @return The identity of this context for permission purposes. |
| 891 | * |
| 892 | * @see AttributionSource |
| 893 | */ |
| 894 | public @NonNull AttributionSource getAttributionSource() { |
| 895 | return null; |
| 896 | } |
| 897 | |
| 898 | // TODO moltmann: Remove |
| 899 | /** |
| 900 | * @removed |
| 901 | */ |
| 902 | @Deprecated |
| 903 | public @Nullable String getFeatureId() { |
| 904 | return getAttributionTag(); |
| 905 | } |
| 906 | |
| 907 | /** |
| 908 | * Return the set of parameters which this Context was created with, if it |
| 909 | * was created via {@link #createContext(ContextParams)}. |
| 910 | */ |
| 911 | public @Nullable ContextParams getParams() { |
| 912 | return null; |
| 913 | } |
| 914 | |
| 915 | /** Return the full application info for this context's package. */ |
| 916 | public abstract ApplicationInfo getApplicationInfo(); |
| 917 | |
| 918 | /** |
| 919 | * Return the full path to this context's primary Android package. |
| 920 | * The Android package is a ZIP file which contains the application's |
| 921 | * primary resources. |
| 922 | * |
| 923 | * <p>Note: this is not generally useful for applications, since they should |
| 924 | * not be directly accessing the file system. |
| 925 | * |
| 926 | * @return String Path to the resources. |
| 927 | */ |
| 928 | public abstract String getPackageResourcePath(); |
| 929 | |
| 930 | /** |
| 931 | * Return the full path to this context's primary Android package. |
| 932 | * The Android package is a ZIP file which contains application's |
| 933 | * primary code and assets. |
| 934 | * |
| 935 | * <p>Note: this is not generally useful for applications, since they should |
| 936 | * not be directly accessing the file system. |
| 937 | * |
| 938 | * @return String Path to the code and assets. |
| 939 | */ |
| 940 | public abstract String getPackageCodePath(); |
| 941 | |
| 942 | /** |
| 943 | * @hide |
| 944 | * @deprecated use {@link #getSharedPreferencesPath(String)} |
| 945 | */ |
| 946 | @Deprecated |
| 947 | @UnsupportedAppUsage |
| 948 | public File getSharedPrefsFile(String name) { |
| 949 | return getSharedPreferencesPath(name); |
| 950 | } |
| 951 | |
| 952 | /** |
| 953 | * Retrieve and hold the contents of the preferences file 'name', returning |
| 954 | * a SharedPreferences through which you can retrieve and modify its |
| 955 | * values. Only one instance of the SharedPreferences object is returned |
| 956 | * to any callers for the same name, meaning they will see each other's |
| 957 | * edits as soon as they are made. |
| 958 | * |
| 959 | * <p>This method is thread-safe. |
| 960 | * |
| 961 | * <p>If the preferences directory does not already exist, it will be created when this method |
| 962 | * is called. |
| 963 | * |
| 964 | * <p>If a preferences file by this name does not exist, it will be created when you retrieve an |
| 965 | * editor ({@link SharedPreferences#edit()}) and then commit changes ({@link |
| 966 | * SharedPreferences.Editor#commit()} or {@link SharedPreferences.Editor#apply()}). |
| 967 | * |
| 968 | * @param name Desired preferences file. |
| 969 | * @param mode Operating mode. |
| 970 | * |
| 971 | * @return The single {@link SharedPreferences} instance that can be used |
| 972 | * to retrieve and modify the preference values. |
| 973 | * |
| 974 | * @see #MODE_PRIVATE |
| 975 | */ |
| 976 | public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode); |
| 977 | |
| 978 | /** |
| 979 | * Retrieve and hold the contents of the preferences file, returning |
| 980 | * a SharedPreferences through which you can retrieve and modify its |
| 981 | * values. Only one instance of the SharedPreferences object is returned |
| 982 | * to any callers for the same name, meaning they will see each other's |
| 983 | * edits as soon as they are made. |
| 984 | * |
| 985 | * @param file Desired preferences file. If a preferences file by this name |
| 986 | * does not exist, it will be created when you retrieve an |
| 987 | * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()). |
| 988 | * @param mode Operating mode. |
| 989 | * |
| 990 | * @return The single {@link SharedPreferences} instance that can be used |
| 991 | * to retrieve and modify the preference values. |
| 992 | * |
| 993 | * @see #getSharedPreferencesPath(String) |
| 994 | * @see #MODE_PRIVATE |
| 995 | * @removed |
| 996 | */ |
| 997 | @SuppressWarnings("HiddenAbstractMethod") |
| 998 | public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode); |
| 999 | |
| 1000 | /** |
| 1001 | * Move an existing shared preferences file from the given source storage |
| 1002 | * context to this context. This is typically used to migrate data between |
| 1003 | * storage locations after an upgrade, such as moving to device protected |
| 1004 | * storage. |
| 1005 | * |
| 1006 | * @param sourceContext The source context which contains the existing |
| 1007 | * shared preferences to move. |
| 1008 | * @param name The name of the shared preferences file. |
| 1009 | * @return {@code true} if the move was successful or if the shared |
| 1010 | * preferences didn't exist in the source context, otherwise |
| 1011 | * {@code false}. |
| 1012 | * @see #createDeviceProtectedStorageContext() |
| 1013 | */ |
| 1014 | public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name); |
| 1015 | |
| 1016 | /** |
| 1017 | * Delete an existing shared preferences file. |
| 1018 | * |
| 1019 | * @param name The name (unique in the application package) of the shared |
| 1020 | * preferences file. |
| 1021 | * @return {@code true} if the shared preferences file was successfully |
| 1022 | * deleted; else {@code false}. |
| 1023 | * @see #getSharedPreferences(String, int) |
| 1024 | */ |
| 1025 | public abstract boolean deleteSharedPreferences(String name); |
| 1026 | |
| 1027 | /** @hide */ |
| 1028 | @SuppressWarnings("HiddenAbstractMethod") |
| 1029 | public abstract void reloadSharedPreferences(); |
| 1030 | |
| 1031 | /** |
| 1032 | * Open a private file associated with this Context's application package |
| 1033 | * for reading. |
| 1034 | * |
| 1035 | * @param name The name of the file to open; can not contain path |
| 1036 | * separators. |
| 1037 | * |
| 1038 | * @return The resulting {@link FileInputStream}. |
| 1039 | * |
| 1040 | * @see #openFileOutput |
| 1041 | * @see #fileList |
| 1042 | * @see #deleteFile |
| 1043 | * @see java.io.FileInputStream#FileInputStream(String) |
| 1044 | */ |
| 1045 | public abstract FileInputStream openFileInput(String name) |
| 1046 | throws FileNotFoundException; |
| 1047 | |
| 1048 | /** |
| 1049 | * Open a private file associated with this Context's application package |
| 1050 | * for writing. Creates the file if it doesn't already exist. |
| 1051 | * <p> |
| 1052 | * No additional permissions are required for the calling app to read or |
| 1053 | * write the returned file. |
| 1054 | * |
| 1055 | * @param name The name of the file to open; can not contain path |
| 1056 | * separators. |
| 1057 | * @param mode Operating mode. |
| 1058 | * @return The resulting {@link FileOutputStream}. |
| 1059 | * @see #MODE_APPEND |
| 1060 | * @see #MODE_PRIVATE |
| 1061 | * @see #openFileInput |
| 1062 | * @see #fileList |
| 1063 | * @see #deleteFile |
| 1064 | * @see java.io.FileOutputStream#FileOutputStream(String) |
| 1065 | */ |
| 1066 | public abstract FileOutputStream openFileOutput(String name, @FileMode int mode) |
| 1067 | throws FileNotFoundException; |
| 1068 | |
| 1069 | /** |
| 1070 | * Delete the given private file associated with this Context's |
| 1071 | * application package. |
| 1072 | * |
| 1073 | * @param name The name of the file to delete; can not contain path |
| 1074 | * separators. |
| 1075 | * |
| 1076 | * @return {@code true} if the file was successfully deleted; else |
| 1077 | * {@code false}. |
| 1078 | * |
| 1079 | * @see #openFileInput |
| 1080 | * @see #openFileOutput |
| 1081 | * @see #fileList |
| 1082 | * @see java.io.File#delete() |
| 1083 | */ |
| 1084 | public abstract boolean deleteFile(String name); |
| 1085 | |
| 1086 | /** |
| 1087 | * Returns the absolute path on the filesystem where a file created with |
| 1088 | * {@link #openFileOutput} is stored. |
| 1089 | * <p> |
| 1090 | * The returned path may change over time if the calling app is moved to an |
| 1091 | * adopted storage device, so only relative paths should be persisted. |
| 1092 | * |
| 1093 | * @param name The name of the file for which you would like to get |
| 1094 | * its path. |
| 1095 | * |
| 1096 | * @return An absolute path to the given file. |
| 1097 | * |
| 1098 | * @see #openFileOutput |
| 1099 | * @see #getFilesDir |
| 1100 | * @see #getDir |
| 1101 | */ |
| 1102 | public abstract File getFileStreamPath(String name); |
| 1103 | |
| 1104 | /** |
| 1105 | * Returns the absolute path on the filesystem where a file created with |
| 1106 | * {@link #getSharedPreferences(String, int)} is stored. |
| 1107 | * <p> |
| 1108 | * The returned path may change over time if the calling app is moved to an |
| 1109 | * adopted storage device, so only relative paths should be persisted. |
| 1110 | * |
| 1111 | * @param name The name of the shared preferences for which you would like |
| 1112 | * to get a path. |
| 1113 | * @return An absolute path to the given file. |
| 1114 | * @see #getSharedPreferences(String, int) |
| 1115 | * @removed |
| 1116 | */ |
| 1117 | @SuppressWarnings("HiddenAbstractMethod") |
| 1118 | public abstract File getSharedPreferencesPath(String name); |
| 1119 | |
| 1120 | /** |
| 1121 | * Returns the absolute path to the directory on the filesystem where all |
| 1122 | * private files belonging to this app are stored. Apps should not use this |
| 1123 | * path directly; they should instead use {@link #getFilesDir()}, |
| 1124 | * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage |
| 1125 | * APIs on this class. |
| 1126 | * <p> |
| 1127 | * The returned path may change over time if the calling app is moved to an |
| 1128 | * adopted storage device, so only relative paths should be persisted. |
| 1129 | * <p> |
| 1130 | * No additional permissions are required for the calling app to read or |
| 1131 | * write files under the returned path. |
| 1132 | * |
| 1133 | * @see ApplicationInfo#dataDir |
| 1134 | */ |
| 1135 | public abstract File getDataDir(); |
| 1136 | |
| 1137 | /** |
| 1138 | * Returns the absolute path to the directory on the filesystem where files |
| 1139 | * created with {@link #openFileOutput} are stored. |
| 1140 | * <p> |
| 1141 | * The returned path may change over time if the calling app is moved to an |
| 1142 | * adopted storage device, so only relative paths should be persisted. |
| 1143 | * <p> |
| 1144 | * No additional permissions are required for the calling app to read or |
| 1145 | * write files under the returned path. |
| 1146 | * |
| 1147 | * @return The path of the directory holding application files. |
| 1148 | * @see #openFileOutput |
| 1149 | * @see #getFileStreamPath |
| 1150 | * @see #getDir |
| 1151 | */ |
| 1152 | public abstract File getFilesDir(); |
| 1153 | |
| 1154 | /** |
| 1155 | * Returns the absolute path to the directory that is related to the crate on the filesystem. |
| 1156 | * <p> |
| 1157 | * The crateId require a validated file name. It can't contain any "..", ".", |
| 1158 | * {@link File#separatorChar} etc.. |
| 1159 | * </p> |
| 1160 | * <p> |
| 1161 | * The returned path may change over time if the calling app is moved to an |
| 1162 | * adopted storage device, so only relative paths should be persisted. |
| 1163 | * </p> |
| 1164 | * <p> |
| 1165 | * No additional permissions are required for the calling app to read or |
| 1166 | * write files under the returned path. |
| 1167 | *</p> |
| 1168 | * |
| 1169 | * @param crateId the relative validated file name under {@link Context#getDataDir()}/crates |
| 1170 | * @return the crate directory file. |
| 1171 | * @hide |
| 1172 | */ |
| 1173 | @NonNull |
| 1174 | @TestApi |
| 1175 | public File getCrateDir(@NonNull String crateId) { |
| 1176 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 1177 | } |
| 1178 | |
| 1179 | /** |
| 1180 | * Returns the absolute path to the directory on the filesystem similar to |
| 1181 | * {@link #getFilesDir()}. The difference is that files placed under this |
| 1182 | * directory will be excluded from automatic backup to remote storage. See |
| 1183 | * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion |
| 1184 | * of the automatic backup mechanism in Android. |
| 1185 | * <p> |
| 1186 | * The returned path may change over time if the calling app is moved to an |
| 1187 | * adopted storage device, so only relative paths should be persisted. |
| 1188 | * <p> |
| 1189 | * No additional permissions are required for the calling app to read or |
| 1190 | * write files under the returned path. |
| 1191 | * |
| 1192 | * @return The path of the directory holding application files that will not |
| 1193 | * be automatically backed up to remote storage. |
| 1194 | * @see #openFileOutput |
| 1195 | * @see #getFileStreamPath |
| 1196 | * @see #getDir |
| 1197 | * @see android.app.backup.BackupAgent |
| 1198 | */ |
| 1199 | public abstract File getNoBackupFilesDir(); |
| 1200 | |
| 1201 | /** |
| 1202 | * Returns the absolute path to the directory on the primary shared/external |
| 1203 | * storage device where the application can place persistent files it owns. |
| 1204 | * These files are internal to the applications, and not typically visible |
| 1205 | * to the user as media. |
| 1206 | * <p> |
| 1207 | * This is like {@link #getFilesDir()} in that these files will be deleted |
| 1208 | * when the application is uninstalled, however there are some important |
| 1209 | * differences: |
| 1210 | * <ul> |
| 1211 | * <li>Shared storage may not always be available, since removable media can |
| 1212 | * be ejected by the user. Media state can be checked using |
| 1213 | * {@link Environment#getExternalStorageState(File)}. |
| 1214 | * <li>There is no security enforced with these files. For example, any |
| 1215 | * application holding |
| 1216 | * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to |
| 1217 | * these files. |
| 1218 | * </ul> |
| 1219 | * <p> |
| 1220 | * If a shared storage device is emulated (as determined by |
| 1221 | * {@link Environment#isExternalStorageEmulated(File)}), it's contents are |
| 1222 | * backed by a private user data partition, which means there is little |
| 1223 | * benefit to storing data here instead of the private directories returned |
| 1224 | * by {@link #getFilesDir()}, etc. |
| 1225 | * <p> |
| 1226 | * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions |
| 1227 | * are required to read or write to the returned path; it's always |
| 1228 | * accessible to the calling app. This only applies to paths generated for |
| 1229 | * package name of the calling application. To access paths belonging to |
| 1230 | * other packages, |
| 1231 | * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or |
| 1232 | * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required. |
| 1233 | * <p> |
| 1234 | * On devices with multiple users (as described by {@link UserManager}), |
| 1235 | * each user has their own isolated shared storage. Applications only have |
| 1236 | * access to the shared storage for the user they're running as. |
| 1237 | * <p> |
| 1238 | * The returned path may change over time if different shared storage media |
| 1239 | * is inserted, so only relative paths should be persisted. |
| 1240 | * <p> |
| 1241 | * Here is an example of typical code to manipulate a file in an |
| 1242 | * application's shared storage: |
| 1243 | * </p> |
| 1244 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java |
| 1245 | * private_file} |
| 1246 | * <p> |
| 1247 | * If you supply a non-null <var>type</var> to this function, the returned |
| 1248 | * file will be a path to a sub-directory of the given type. Though these |
| 1249 | * files are not automatically scanned by the media scanner, you can |
| 1250 | * explicitly add them to the media database with |
| 1251 | * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener) |
| 1252 | * MediaScannerConnection.scanFile}. Note that this is not the same as |
| 1253 | * {@link android.os.Environment#getExternalStoragePublicDirectory |
| 1254 | * Environment.getExternalStoragePublicDirectory()}, which provides |
| 1255 | * directories of media shared by all applications. The directories returned |
| 1256 | * here are owned by the application, and their contents will be removed |
| 1257 | * when the application is uninstalled. Unlike |
| 1258 | * {@link android.os.Environment#getExternalStoragePublicDirectory |
| 1259 | * Environment.getExternalStoragePublicDirectory()}, the directory returned |
| 1260 | * here will be automatically created for you. |
| 1261 | * <p> |
| 1262 | * Here is an example of typical code to manipulate a picture in an |
| 1263 | * application's shared storage and add it to the media database: |
| 1264 | * </p> |
| 1265 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java |
| 1266 | * private_picture} |
| 1267 | * |
| 1268 | * @param type The type of files directory to return. May be {@code null} |
| 1269 | * for the root of the files directory or one of the following |
| 1270 | * constants for a subdirectory: |
| 1271 | * {@link android.os.Environment#DIRECTORY_MUSIC}, |
| 1272 | * {@link android.os.Environment#DIRECTORY_PODCASTS}, |
| 1273 | * {@link android.os.Environment#DIRECTORY_RINGTONES}, |
| 1274 | * {@link android.os.Environment#DIRECTORY_ALARMS}, |
| 1275 | * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS}, |
| 1276 | * {@link android.os.Environment#DIRECTORY_PICTURES}, or |
| 1277 | * {@link android.os.Environment#DIRECTORY_MOVIES}. |
| 1278 | * @return the absolute path to application-specific directory. May return |
| 1279 | * {@code null} if shared storage is not currently available. |
| 1280 | * @see #getFilesDir |
| 1281 | * @see #getExternalFilesDirs(String) |
| 1282 | * @see Environment#getExternalStorageState(File) |
| 1283 | * @see Environment#isExternalStorageEmulated(File) |
| 1284 | * @see Environment#isExternalStorageRemovable(File) |
| 1285 | */ |
| 1286 | @Nullable |
| 1287 | public abstract File getExternalFilesDir(@Nullable String type); |
| 1288 | |
| 1289 | /** |
| 1290 | * Returns absolute paths to application-specific directories on all |
| 1291 | * shared/external storage devices where the application can place |
| 1292 | * persistent files it owns. These files are internal to the application, |
| 1293 | * and not typically visible to the user as media. |
| 1294 | * <p> |
| 1295 | * This is like {@link #getFilesDir()} in that these files will be deleted |
| 1296 | * when the application is uninstalled, however there are some important |
| 1297 | * differences: |
| 1298 | * <ul> |
| 1299 | * <li>Shared storage may not always be available, since removable media can |
| 1300 | * be ejected by the user. Media state can be checked using |
| 1301 | * {@link Environment#getExternalStorageState(File)}. |
| 1302 | * <li>There is no security enforced with these files. For example, any |
| 1303 | * application holding |
| 1304 | * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to |
| 1305 | * these files. |
| 1306 | * </ul> |
| 1307 | * <p> |
| 1308 | * If a shared storage device is emulated (as determined by |
| 1309 | * {@link Environment#isExternalStorageEmulated(File)}), it's contents are |
| 1310 | * backed by a private user data partition, which means there is little |
| 1311 | * benefit to storing data here instead of the private directories returned |
| 1312 | * by {@link #getFilesDir()}, etc. |
| 1313 | * <p> |
| 1314 | * Shared storage devices returned here are considered a stable part of the |
| 1315 | * device, including physical media slots under a protective cover. The |
| 1316 | * returned paths do not include transient devices, such as USB flash drives |
| 1317 | * connected to handheld devices. |
| 1318 | * <p> |
| 1319 | * An application may store data on any or all of the returned devices. For |
| 1320 | * example, an app may choose to store large files on the device with the |
| 1321 | * most available space, as measured by {@link StatFs}. |
| 1322 | * <p> |
| 1323 | * No additional permissions are required for the calling app to read or |
| 1324 | * write files under the returned path. Write access outside of these paths |
| 1325 | * on secondary external storage devices is not available. |
| 1326 | * <p> |
| 1327 | * The returned path may change over time if different shared storage media |
| 1328 | * is inserted, so only relative paths should be persisted. |
| 1329 | * |
| 1330 | * @param type The type of files directory to return. May be {@code null} |
| 1331 | * for the root of the files directory or one of the following |
| 1332 | * constants for a subdirectory: |
| 1333 | * {@link android.os.Environment#DIRECTORY_MUSIC}, |
| 1334 | * {@link android.os.Environment#DIRECTORY_PODCASTS}, |
| 1335 | * {@link android.os.Environment#DIRECTORY_RINGTONES}, |
| 1336 | * {@link android.os.Environment#DIRECTORY_ALARMS}, |
| 1337 | * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS}, |
| 1338 | * {@link android.os.Environment#DIRECTORY_PICTURES}, or |
| 1339 | * {@link android.os.Environment#DIRECTORY_MOVIES}. |
| 1340 | * @return the absolute paths to application-specific directories. Some |
| 1341 | * individual paths may be {@code null} if that shared storage is |
| 1342 | * not currently available. The first path returned is the same as |
| 1343 | * {@link #getExternalFilesDir(String)}. |
| 1344 | * @see #getExternalFilesDir(String) |
| 1345 | * @see Environment#getExternalStorageState(File) |
| 1346 | * @see Environment#isExternalStorageEmulated(File) |
| 1347 | * @see Environment#isExternalStorageRemovable(File) |
| 1348 | */ |
| 1349 | public abstract File[] getExternalFilesDirs(String type); |
| 1350 | |
| 1351 | /** |
| 1352 | * Return the primary shared/external storage directory where this |
| 1353 | * application's OBB files (if there are any) can be found. Note if the |
| 1354 | * application does not have any OBB files, this directory may not exist. |
| 1355 | * <p> |
| 1356 | * This is like {@link #getFilesDir()} in that these files will be deleted |
| 1357 | * when the application is uninstalled, however there are some important |
| 1358 | * differences: |
| 1359 | * <ul> |
| 1360 | * <li>Shared storage may not always be available, since removable media can |
| 1361 | * be ejected by the user. Media state can be checked using |
| 1362 | * {@link Environment#getExternalStorageState(File)}. |
| 1363 | * <li>There is no security enforced with these files. For example, any |
| 1364 | * application holding |
| 1365 | * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to |
| 1366 | * these files. |
| 1367 | * </ul> |
| 1368 | * <p> |
| 1369 | * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions |
| 1370 | * are required to read or write to the path that this method returns. |
| 1371 | * However, starting from {@link android.os.Build.VERSION_CODES#M}, |
| 1372 | * to read the OBB expansion files, you must declare the |
| 1373 | * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for |
| 1374 | * permission at runtime as follows: |
| 1375 | * </p> |
| 1376 | * <p> |
| 1377 | * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" |
| 1378 | * android:maxSdkVersion="23" />} |
| 1379 | * </p> |
| 1380 | * <p> |
| 1381 | * Starting from {@link android.os.Build.VERSION_CODES#N}, |
| 1382 | * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} |
| 1383 | * permission is not required, so don’t ask for this |
| 1384 | * permission at runtime. To handle both cases, your app must first try to read the OBB file, |
| 1385 | * and if it fails, you must request |
| 1386 | * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime. |
| 1387 | * </p> |
| 1388 | * |
| 1389 | * <p> |
| 1390 | * The following code snippet shows how to do this: |
| 1391 | * </p> |
| 1392 | * |
| 1393 | * <pre> |
| 1394 | * File obb = new File(obb_filename); |
| 1395 | * boolean open_failed = false; |
| 1396 | * |
| 1397 | * try { |
| 1398 | * BufferedReader br = new BufferedReader(new FileReader(obb)); |
| 1399 | * open_failed = false; |
| 1400 | * ReadObbFile(br); |
| 1401 | * } catch (IOException e) { |
| 1402 | * open_failed = true; |
| 1403 | * } |
| 1404 | * |
| 1405 | * if (open_failed) { |
| 1406 | * // request READ_EXTERNAL_STORAGE permission before reading OBB file |
| 1407 | * ReadObbFileWithPermission(); |
| 1408 | * } |
| 1409 | * </pre> |
| 1410 | * |
| 1411 | * On devices with multiple users (as described by {@link UserManager}), |
| 1412 | * multiple users may share the same OBB storage location. Applications |
| 1413 | * should ensure that multiple instances running under different users don't |
| 1414 | * interfere with each other. |
| 1415 | * |
| 1416 | * @return the absolute path to application-specific directory. May return |
| 1417 | * {@code null} if shared storage is not currently available. |
| 1418 | * @see #getObbDirs() |
| 1419 | * @see Environment#getExternalStorageState(File) |
| 1420 | * @see Environment#isExternalStorageEmulated(File) |
| 1421 | * @see Environment#isExternalStorageRemovable(File) |
| 1422 | */ |
| 1423 | public abstract File getObbDir(); |
| 1424 | |
| 1425 | /** |
| 1426 | * Returns absolute paths to application-specific directories on all |
| 1427 | * shared/external storage devices where the application's OBB files (if |
| 1428 | * there are any) can be found. Note if the application does not have any |
| 1429 | * OBB files, these directories may not exist. |
| 1430 | * <p> |
| 1431 | * This is like {@link #getFilesDir()} in that these files will be deleted |
| 1432 | * when the application is uninstalled, however there are some important |
| 1433 | * differences: |
| 1434 | * <ul> |
| 1435 | * <li>Shared storage may not always be available, since removable media can |
| 1436 | * be ejected by the user. Media state can be checked using |
| 1437 | * {@link Environment#getExternalStorageState(File)}. |
| 1438 | * <li>There is no security enforced with these files. For example, any |
| 1439 | * application holding |
| 1440 | * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to |
| 1441 | * these files. |
| 1442 | * </ul> |
| 1443 | * <p> |
| 1444 | * Shared storage devices returned here are considered a stable part of the |
| 1445 | * device, including physical media slots under a protective cover. The |
| 1446 | * returned paths do not include transient devices, such as USB flash drives |
| 1447 | * connected to handheld devices. |
| 1448 | * <p> |
| 1449 | * An application may store data on any or all of the returned devices. For |
| 1450 | * example, an app may choose to store large files on the device with the |
| 1451 | * most available space, as measured by {@link StatFs}. |
| 1452 | * <p> |
| 1453 | * No additional permissions are required for the calling app to read or |
| 1454 | * write files under the returned path. Write access outside of these paths |
| 1455 | * on secondary external storage devices is not available. |
| 1456 | * |
| 1457 | * @return the absolute paths to application-specific directories. Some |
| 1458 | * individual paths may be {@code null} if that shared storage is |
| 1459 | * not currently available. The first path returned is the same as |
| 1460 | * {@link #getObbDir()} |
| 1461 | * @see #getObbDir() |
| 1462 | * @see Environment#getExternalStorageState(File) |
| 1463 | * @see Environment#isExternalStorageEmulated(File) |
| 1464 | * @see Environment#isExternalStorageRemovable(File) |
| 1465 | */ |
| 1466 | public abstract File[] getObbDirs(); |
| 1467 | |
| 1468 | /** |
| 1469 | * Returns the absolute path to the application specific cache directory on |
| 1470 | * the filesystem. |
| 1471 | * <p> |
| 1472 | * The system will automatically delete files in this directory as disk |
| 1473 | * space is needed elsewhere on the device. The system will always delete |
| 1474 | * older files first, as reported by {@link File#lastModified()}. If |
| 1475 | * desired, you can exert more control over how files are deleted using |
| 1476 | * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and |
| 1477 | * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}. |
| 1478 | * <p> |
| 1479 | * Apps are strongly encouraged to keep their usage of cache space below the |
| 1480 | * quota returned by |
| 1481 | * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app |
| 1482 | * goes above this quota, your cached files will be some of the first to be |
| 1483 | * deleted when additional disk space is needed. Conversely, if your app |
| 1484 | * stays under this quota, your cached files will be some of the last to be |
| 1485 | * deleted when additional disk space is needed. |
| 1486 | * <p> |
| 1487 | * Note that your cache quota will change over time depending on how |
| 1488 | * frequently the user interacts with your app, and depending on how much |
| 1489 | * system-wide disk space is used. |
| 1490 | * <p> |
| 1491 | * The returned path may change over time if the calling app is moved to an |
| 1492 | * adopted storage device, so only relative paths should be persisted. |
| 1493 | * <p> |
| 1494 | * Apps require no extra permissions to read or write to the returned path, |
| 1495 | * since this path lives in their private storage. |
| 1496 | * |
| 1497 | * @return The path of the directory holding application cache files. |
| 1498 | * @see #openFileOutput |
| 1499 | * @see #getFileStreamPath |
| 1500 | * @see #getDir |
| 1501 | * @see #getExternalCacheDir |
| 1502 | */ |
| 1503 | public abstract File getCacheDir(); |
| 1504 | |
| 1505 | /** |
| 1506 | * Returns the absolute path to the application specific cache directory on |
| 1507 | * the filesystem designed for storing cached code. |
| 1508 | * <p> |
| 1509 | * The system will delete any files stored in this location both when your |
| 1510 | * specific application is upgraded, and when the entire platform is |
| 1511 | * upgraded. |
| 1512 | * <p> |
| 1513 | * This location is optimal for storing compiled or optimized code generated |
| 1514 | * by your application at runtime. |
| 1515 | * <p> |
| 1516 | * The returned path may change over time if the calling app is moved to an |
| 1517 | * adopted storage device, so only relative paths should be persisted. |
| 1518 | * <p> |
| 1519 | * Apps require no extra permissions to read or write to the returned path, |
| 1520 | * since this path lives in their private storage. |
| 1521 | * |
| 1522 | * @return The path of the directory holding application code cache files. |
| 1523 | */ |
| 1524 | public abstract File getCodeCacheDir(); |
| 1525 | |
| 1526 | /** |
| 1527 | * Returns absolute path to application-specific directory on the primary |
| 1528 | * shared/external storage device where the application can place cache |
| 1529 | * files it owns. These files are internal to the application, and not |
| 1530 | * typically visible to the user as media. |
| 1531 | * <p> |
| 1532 | * This is like {@link #getCacheDir()} in that these files will be deleted |
| 1533 | * when the application is uninstalled, however there are some important |
| 1534 | * differences: |
| 1535 | * <ul> |
| 1536 | * <li>The platform does not always monitor the space available in shared |
| 1537 | * storage, and thus may not automatically delete these files. Apps should |
| 1538 | * always manage the maximum space used in this location. Currently the only |
| 1539 | * time files here will be deleted by the platform is when running on |
| 1540 | * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and |
| 1541 | * {@link Environment#isExternalStorageEmulated(File)} returns true. |
| 1542 | * <li>Shared storage may not always be available, since removable media can |
| 1543 | * be ejected by the user. Media state can be checked using |
| 1544 | * {@link Environment#getExternalStorageState(File)}. |
| 1545 | * <li>There is no security enforced with these files. For example, any |
| 1546 | * application holding |
| 1547 | * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to |
| 1548 | * these files. |
| 1549 | * </ul> |
| 1550 | * <p> |
| 1551 | * If a shared storage device is emulated (as determined by |
| 1552 | * {@link Environment#isExternalStorageEmulated(File)}), its contents are |
| 1553 | * backed by a private user data partition, which means there is little |
| 1554 | * benefit to storing data here instead of the private directory returned by |
| 1555 | * {@link #getCacheDir()}. |
| 1556 | * <p> |
| 1557 | * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions |
| 1558 | * are required to read or write to the returned path; it's always |
| 1559 | * accessible to the calling app. This only applies to paths generated for |
| 1560 | * package name of the calling application. To access paths belonging to |
| 1561 | * other packages, |
| 1562 | * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or |
| 1563 | * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required. |
| 1564 | * <p> |
| 1565 | * On devices with multiple users (as described by {@link UserManager}), |
| 1566 | * each user has their own isolated shared storage. Applications only have |
| 1567 | * access to the shared storage for the user they're running as. |
| 1568 | * <p> |
| 1569 | * The returned path may change over time if different shared storage media |
| 1570 | * is inserted, so only relative paths should be persisted. |
| 1571 | * |
| 1572 | * @return the absolute path to application-specific directory. May return |
| 1573 | * {@code null} if shared storage is not currently available. |
| 1574 | * @see #getCacheDir |
| 1575 | * @see #getExternalCacheDirs() |
| 1576 | * @see Environment#getExternalStorageState(File) |
| 1577 | * @see Environment#isExternalStorageEmulated(File) |
| 1578 | * @see Environment#isExternalStorageRemovable(File) |
| 1579 | */ |
| 1580 | @Nullable |
| 1581 | public abstract File getExternalCacheDir(); |
| 1582 | |
| 1583 | /** |
| 1584 | * Returns absolute path to application-specific directory in the preloaded cache. |
| 1585 | * <p>Files stored in the cache directory can be deleted when the device runs low on storage. |
| 1586 | * There is no guarantee when these files will be deleted. |
| 1587 | * @hide |
| 1588 | */ |
| 1589 | @SuppressWarnings("HiddenAbstractMethod") |
| 1590 | @Nullable |
| 1591 | @SystemApi |
| 1592 | public abstract File getPreloadsFileCache(); |
| 1593 | |
| 1594 | /** |
| 1595 | * Returns absolute paths to application-specific directories on all |
| 1596 | * shared/external storage devices where the application can place cache |
| 1597 | * files it owns. These files are internal to the application, and not |
| 1598 | * typically visible to the user as media. |
| 1599 | * <p> |
| 1600 | * This is like {@link #getCacheDir()} in that these files will be deleted |
| 1601 | * when the application is uninstalled, however there are some important |
| 1602 | * differences: |
| 1603 | * <ul> |
| 1604 | * <li>The platform does not always monitor the space available in shared |
| 1605 | * storage, and thus may not automatically delete these files. Apps should |
| 1606 | * always manage the maximum space used in this location. Currently the only |
| 1607 | * time files here will be deleted by the platform is when running on |
| 1608 | * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and |
| 1609 | * {@link Environment#isExternalStorageEmulated(File)} returns true. |
| 1610 | * <li>Shared storage may not always be available, since removable media can |
| 1611 | * be ejected by the user. Media state can be checked using |
| 1612 | * {@link Environment#getExternalStorageState(File)}. |
| 1613 | * <li>There is no security enforced with these files. For example, any |
| 1614 | * application holding |
| 1615 | * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to |
| 1616 | * these files. |
| 1617 | * </ul> |
| 1618 | * <p> |
| 1619 | * If a shared storage device is emulated (as determined by |
| 1620 | * {@link Environment#isExternalStorageEmulated(File)}), it's contents are |
| 1621 | * backed by a private user data partition, which means there is little |
| 1622 | * benefit to storing data here instead of the private directory returned by |
| 1623 | * {@link #getCacheDir()}. |
| 1624 | * <p> |
| 1625 | * Shared storage devices returned here are considered a stable part of the |
| 1626 | * device, including physical media slots under a protective cover. The |
| 1627 | * returned paths do not include transient devices, such as USB flash drives |
| 1628 | * connected to handheld devices. |
| 1629 | * <p> |
| 1630 | * An application may store data on any or all of the returned devices. For |
| 1631 | * example, an app may choose to store large files on the device with the |
| 1632 | * most available space, as measured by {@link StatFs}. |
| 1633 | * <p> |
| 1634 | * No additional permissions are required for the calling app to read or |
| 1635 | * write files under the returned path. Write access outside of these paths |
| 1636 | * on secondary external storage devices is not available. |
| 1637 | * <p> |
| 1638 | * The returned paths may change over time if different shared storage media |
| 1639 | * is inserted, so only relative paths should be persisted. |
| 1640 | * |
| 1641 | * @return the absolute paths to application-specific directories. Some |
| 1642 | * individual paths may be {@code null} if that shared storage is |
| 1643 | * not currently available. The first path returned is the same as |
| 1644 | * {@link #getExternalCacheDir()}. |
| 1645 | * @see #getExternalCacheDir() |
| 1646 | * @see Environment#getExternalStorageState(File) |
| 1647 | * @see Environment#isExternalStorageEmulated(File) |
| 1648 | * @see Environment#isExternalStorageRemovable(File) |
| 1649 | */ |
| 1650 | public abstract File[] getExternalCacheDirs(); |
| 1651 | |
| 1652 | /** |
| 1653 | * Returns absolute paths to application-specific directories on all |
| 1654 | * shared/external storage devices where the application can place media |
| 1655 | * files. These files are scanned and made available to other apps through |
| 1656 | * {@link MediaStore}. |
| 1657 | * <p> |
| 1658 | * This is like {@link #getExternalFilesDirs} in that these files will be |
| 1659 | * deleted when the application is uninstalled, however there are some |
| 1660 | * important differences: |
| 1661 | * <ul> |
| 1662 | * <li>Shared storage may not always be available, since removable media can |
| 1663 | * be ejected by the user. Media state can be checked using |
| 1664 | * {@link Environment#getExternalStorageState(File)}. |
| 1665 | * <li>There is no security enforced with these files. For example, any |
| 1666 | * application holding |
| 1667 | * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to |
| 1668 | * these files. |
| 1669 | * </ul> |
| 1670 | * <p> |
| 1671 | * Shared storage devices returned here are considered a stable part of the |
| 1672 | * device, including physical media slots under a protective cover. The |
| 1673 | * returned paths do not include transient devices, such as USB flash drives |
| 1674 | * connected to handheld devices. |
| 1675 | * <p> |
| 1676 | * An application may store data on any or all of the returned devices. For |
| 1677 | * example, an app may choose to store large files on the device with the |
| 1678 | * most available space, as measured by {@link StatFs}. |
| 1679 | * <p> |
| 1680 | * No additional permissions are required for the calling app to read or |
| 1681 | * write files under the returned path. Write access outside of these paths |
| 1682 | * on secondary external storage devices is not available. |
| 1683 | * <p> |
| 1684 | * The returned paths may change over time if different shared storage media |
| 1685 | * is inserted, so only relative paths should be persisted. |
| 1686 | * |
| 1687 | * @return the absolute paths to application-specific directories. Some |
| 1688 | * individual paths may be {@code null} if that shared storage is |
| 1689 | * not currently available. |
| 1690 | * @see Environment#getExternalStorageState(File) |
| 1691 | * @see Environment#isExternalStorageEmulated(File) |
| 1692 | * @see Environment#isExternalStorageRemovable(File) |
| 1693 | * @deprecated These directories still exist and are scanned, but developers |
| 1694 | * are encouraged to migrate to inserting content into a |
| 1695 | * {@link MediaStore} collection directly, as any app can |
| 1696 | * contribute new media to {@link MediaStore} with no |
| 1697 | * permissions required, starting in |
| 1698 | * {@link android.os.Build.VERSION_CODES#Q}. |
| 1699 | */ |
| 1700 | @Deprecated |
| 1701 | public abstract File[] getExternalMediaDirs(); |
| 1702 | |
| 1703 | /** |
| 1704 | * Returns an array of strings naming the private files associated with |
| 1705 | * this Context's application package. |
| 1706 | * |
| 1707 | * @return Array of strings naming the private files. |
| 1708 | * |
| 1709 | * @see #openFileInput |
| 1710 | * @see #openFileOutput |
| 1711 | * @see #deleteFile |
| 1712 | */ |
| 1713 | public abstract String[] fileList(); |
| 1714 | |
| 1715 | /** |
| 1716 | * Retrieve, creating if needed, a new directory in which the application |
| 1717 | * can place its own custom data files. You can use the returned File |
| 1718 | * object to create and access files in this directory. Note that files |
| 1719 | * created through a File object will only be accessible by your own |
| 1720 | * application; you can only set the mode of the entire directory, not |
| 1721 | * of individual files. |
| 1722 | * <p> |
| 1723 | * The returned path may change over time if the calling app is moved to an |
| 1724 | * adopted storage device, so only relative paths should be persisted. |
| 1725 | * <p> |
| 1726 | * Apps require no extra permissions to read or write to the returned path, |
| 1727 | * since this path lives in their private storage. |
| 1728 | * |
| 1729 | * @param name Name of the directory to retrieve. This is a directory |
| 1730 | * that is created as part of your application data. |
| 1731 | * @param mode Operating mode. |
| 1732 | * |
| 1733 | * @return A {@link File} object for the requested directory. The directory |
| 1734 | * will have been created if it does not already exist. |
| 1735 | * |
| 1736 | * @see #openFileOutput(String, int) |
| 1737 | */ |
| 1738 | public abstract File getDir(String name, @FileMode int mode); |
| 1739 | |
| 1740 | /** |
| 1741 | * Open a new private SQLiteDatabase associated with this Context's |
| 1742 | * application package. Create the database file if it doesn't exist. |
| 1743 | * |
| 1744 | * @param name The name (unique in the application package) of the database. |
| 1745 | * @param mode Operating mode. |
| 1746 | * @param factory An optional factory class that is called to instantiate a |
| 1747 | * cursor when query is called. |
| 1748 | * @return The contents of a newly created database with the given name. |
| 1749 | * @throws android.database.sqlite.SQLiteException if the database file |
| 1750 | * could not be opened. |
| 1751 | * @see #MODE_PRIVATE |
| 1752 | * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING |
| 1753 | * @see #MODE_NO_LOCALIZED_COLLATORS |
| 1754 | * @see #deleteDatabase |
| 1755 | */ |
| 1756 | public abstract SQLiteDatabase openOrCreateDatabase(String name, |
| 1757 | @DatabaseMode int mode, CursorFactory factory); |
| 1758 | |
| 1759 | /** |
| 1760 | * Open a new private SQLiteDatabase associated with this Context's |
| 1761 | * application package. Creates the database file if it doesn't exist. |
| 1762 | * <p> |
| 1763 | * Accepts input param: a concrete instance of {@link DatabaseErrorHandler} |
| 1764 | * to be used to handle corruption when sqlite reports database corruption. |
| 1765 | * </p> |
| 1766 | * |
| 1767 | * @param name The name (unique in the application package) of the database. |
| 1768 | * @param mode Operating mode. |
| 1769 | * @param factory An optional factory class that is called to instantiate a |
| 1770 | * cursor when query is called. |
| 1771 | * @param errorHandler the {@link DatabaseErrorHandler} to be used when |
| 1772 | * sqlite reports database corruption. if null, |
| 1773 | * {@link android.database.DefaultDatabaseErrorHandler} is |
| 1774 | * assumed. |
| 1775 | * @return The contents of a newly created database with the given name. |
| 1776 | * @throws android.database.sqlite.SQLiteException if the database file |
| 1777 | * could not be opened. |
| 1778 | * @see #MODE_PRIVATE |
| 1779 | * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING |
| 1780 | * @see #MODE_NO_LOCALIZED_COLLATORS |
| 1781 | * @see #deleteDatabase |
| 1782 | */ |
| 1783 | public abstract SQLiteDatabase openOrCreateDatabase(String name, |
| 1784 | @DatabaseMode int mode, CursorFactory factory, |
| 1785 | @Nullable DatabaseErrorHandler errorHandler); |
| 1786 | |
| 1787 | /** |
| 1788 | * Move an existing database file from the given source storage context to |
| 1789 | * this context. This is typically used to migrate data between storage |
| 1790 | * locations after an upgrade, such as migrating to device protected |
| 1791 | * storage. |
| 1792 | * <p> |
| 1793 | * The database must be closed before being moved. |
| 1794 | * |
| 1795 | * @param sourceContext The source context which contains the existing |
| 1796 | * database to move. |
| 1797 | * @param name The name of the database file. |
| 1798 | * @return {@code true} if the move was successful or if the database didn't |
| 1799 | * exist in the source context, otherwise {@code false}. |
| 1800 | * @see #createDeviceProtectedStorageContext() |
| 1801 | */ |
| 1802 | public abstract boolean moveDatabaseFrom(Context sourceContext, String name); |
| 1803 | |
| 1804 | /** |
| 1805 | * Delete an existing private SQLiteDatabase associated with this Context's |
| 1806 | * application package. |
| 1807 | * |
| 1808 | * @param name The name (unique in the application package) of the |
| 1809 | * database. |
| 1810 | * |
| 1811 | * @return {@code true} if the database was successfully deleted; else {@code false}. |
| 1812 | * |
| 1813 | * @see #openOrCreateDatabase |
| 1814 | */ |
| 1815 | public abstract boolean deleteDatabase(String name); |
| 1816 | |
| 1817 | /** |
| 1818 | * Returns the absolute path on the filesystem where a database created with |
| 1819 | * {@link #openOrCreateDatabase} is stored. |
| 1820 | * <p> |
| 1821 | * The returned path may change over time if the calling app is moved to an |
| 1822 | * adopted storage device, so only relative paths should be persisted. |
| 1823 | * |
| 1824 | * @param name The name of the database for which you would like to get |
| 1825 | * its path. |
| 1826 | * |
| 1827 | * @return An absolute path to the given database. |
| 1828 | * |
| 1829 | * @see #openOrCreateDatabase |
| 1830 | */ |
| 1831 | public abstract File getDatabasePath(String name); |
| 1832 | |
| 1833 | /** |
| 1834 | * Returns an array of strings naming the private databases associated with |
| 1835 | * this Context's application package. |
| 1836 | * |
| 1837 | * @return Array of strings naming the private databases. |
| 1838 | * |
| 1839 | * @see #openOrCreateDatabase |
| 1840 | * @see #deleteDatabase |
| 1841 | */ |
| 1842 | public abstract String[] databaseList(); |
| 1843 | |
| 1844 | /** |
| 1845 | * @deprecated Use {@link android.app.WallpaperManager#getDrawable |
| 1846 | * WallpaperManager.get()} instead. |
| 1847 | */ |
| 1848 | @Deprecated |
| 1849 | public abstract Drawable getWallpaper(); |
| 1850 | |
| 1851 | /** |
| 1852 | * @deprecated Use {@link android.app.WallpaperManager#peekDrawable |
| 1853 | * WallpaperManager.peek()} instead. |
| 1854 | */ |
| 1855 | @Deprecated |
| 1856 | public abstract Drawable peekWallpaper(); |
| 1857 | |
| 1858 | /** |
| 1859 | * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth() |
| 1860 | * WallpaperManager.getDesiredMinimumWidth()} instead. |
| 1861 | */ |
| 1862 | @Deprecated |
| 1863 | public abstract int getWallpaperDesiredMinimumWidth(); |
| 1864 | |
| 1865 | /** |
| 1866 | * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight() |
| 1867 | * WallpaperManager.getDesiredMinimumHeight()} instead. |
| 1868 | */ |
| 1869 | @Deprecated |
| 1870 | public abstract int getWallpaperDesiredMinimumHeight(); |
| 1871 | |
| 1872 | /** |
| 1873 | * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap) |
| 1874 | * WallpaperManager.set()} instead. |
| 1875 | * <p>This method requires the caller to hold the permission |
| 1876 | * {@link android.Manifest.permission#SET_WALLPAPER}. |
| 1877 | */ |
| 1878 | @Deprecated |
| 1879 | public abstract void setWallpaper(Bitmap bitmap) throws IOException; |
| 1880 | |
| 1881 | /** |
| 1882 | * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream) |
| 1883 | * WallpaperManager.set()} instead. |
| 1884 | * <p>This method requires the caller to hold the permission |
| 1885 | * {@link android.Manifest.permission#SET_WALLPAPER}. |
| 1886 | */ |
| 1887 | @Deprecated |
| 1888 | public abstract void setWallpaper(InputStream data) throws IOException; |
| 1889 | |
| 1890 | /** |
| 1891 | * @deprecated Use {@link android.app.WallpaperManager#clear |
| 1892 | * WallpaperManager.clear()} instead. |
| 1893 | * <p>This method requires the caller to hold the permission |
| 1894 | * {@link android.Manifest.permission#SET_WALLPAPER}. |
| 1895 | */ |
| 1896 | @Deprecated |
| 1897 | public abstract void clearWallpaper() throws IOException; |
| 1898 | |
| 1899 | /** |
| 1900 | * Same as {@link #startActivity(Intent, Bundle)} with no options |
| 1901 | * specified. |
| 1902 | * |
| 1903 | * @param intent The description of the activity to start. |
| 1904 | * |
| 1905 | * @throws ActivityNotFoundException |
| 1906 | *` |
| 1907 | * @see #startActivity(Intent, Bundle) |
| 1908 | * @see PackageManager#resolveActivity |
| 1909 | */ |
| 1910 | public abstract void startActivity(@RequiresPermission Intent intent); |
| 1911 | |
| 1912 | /** |
| 1913 | * Version of {@link #startActivity(Intent)} that allows you to specify the |
| 1914 | * user the activity will be started for. This is not available to applications |
| 1915 | * that are not pre-installed on the system image. |
| 1916 | * @param intent The description of the activity to start. |
| 1917 | * @param user The UserHandle of the user to start this activity for. |
| 1918 | * @throws ActivityNotFoundException |
| 1919 | * @hide |
| 1920 | */ |
| 1921 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) |
| 1922 | @SystemApi |
| 1923 | public void startActivityAsUser(@RequiresPermission @NonNull Intent intent, |
| 1924 | @NonNull UserHandle user) { |
| 1925 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 1926 | } |
| 1927 | |
| 1928 | /** |
| 1929 | * Launch a new activity. You will not receive any information about when |
| 1930 | * the activity exits. |
| 1931 | * |
| 1932 | * <p>Note that if this method is being called from outside of an |
| 1933 | * {@link android.app.Activity} Context, then the Intent must include |
| 1934 | * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because, |
| 1935 | * without being started from an existing Activity, there is no existing |
| 1936 | * task in which to place the new activity and thus it needs to be placed |
| 1937 | * in its own separate task. |
| 1938 | * |
| 1939 | * <p>This method throws {@link ActivityNotFoundException} |
| 1940 | * if there was no Activity found to run the given Intent. |
| 1941 | * |
| 1942 | * @param intent The description of the activity to start. |
| 1943 | * @param options Additional options for how the Activity should be started. |
| 1944 | * May be null if there are no options. See {@link android.app.ActivityOptions} |
| 1945 | * for how to build the Bundle supplied here; there are no supported definitions |
| 1946 | * for building it manually. |
| 1947 | * |
| 1948 | * @throws ActivityNotFoundException |
| 1949 | * |
| 1950 | * @see #startActivity(Intent) |
| 1951 | * @see PackageManager#resolveActivity |
| 1952 | */ |
| 1953 | public abstract void startActivity(@RequiresPermission Intent intent, |
| 1954 | @Nullable Bundle options); |
| 1955 | |
| 1956 | /** |
| 1957 | * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the |
| 1958 | * user the activity will be started for. This is not available to applications |
| 1959 | * that are not pre-installed on the system image. |
| 1960 | * @param intent The description of the activity to start. |
| 1961 | * @param options Additional options for how the Activity should be started. |
| 1962 | * May be null if there are no options. See {@link android.app.ActivityOptions} |
| 1963 | * for how to build the Bundle supplied here; there are no supported definitions |
| 1964 | * for building it manually. |
| 1965 | * @param userId The UserHandle of the user to start this activity for. |
| 1966 | * @throws ActivityNotFoundException |
| 1967 | * @hide |
| 1968 | */ |
| 1969 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) |
| 1970 | @UnsupportedAppUsage |
| 1971 | public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options, |
| 1972 | UserHandle userId) { |
| 1973 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 1974 | } |
| 1975 | |
| 1976 | /** |
| 1977 | * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This |
| 1978 | * is only supported for Views and Fragments. |
| 1979 | * @param who The identifier for the calling element that will receive the result. |
| 1980 | * @param intent The intent to start. |
| 1981 | * @param requestCode The code that will be returned with onActivityResult() identifying this |
| 1982 | * request. |
| 1983 | * @param options Additional options for how the Activity should be started. |
| 1984 | * May be null if there are no options. See {@link android.app.ActivityOptions} |
| 1985 | * for how to build the Bundle supplied here; there are no supported definitions |
| 1986 | * for building it manually. |
| 1987 | * @hide |
| 1988 | */ |
| 1989 | @UnsupportedAppUsage |
| 1990 | public void startActivityForResult( |
| 1991 | @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) { |
| 1992 | throw new RuntimeException("This method is only implemented for Activity-based Contexts. " |
| 1993 | + "Check canStartActivityForResult() before calling."); |
| 1994 | } |
| 1995 | |
| 1996 | /** |
| 1997 | * Identifies whether this Context instance will be able to process calls to |
| 1998 | * {@link #startActivityForResult(String, Intent, int, Bundle)}. |
| 1999 | * @hide |
| 2000 | */ |
| 2001 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 2002 | public boolean canStartActivityForResult() { |
| 2003 | return false; |
| 2004 | } |
| 2005 | |
| 2006 | /** |
| 2007 | * Same as {@link #startActivities(Intent[], Bundle)} with no options |
| 2008 | * specified. |
| 2009 | * |
| 2010 | * @param intents An array of Intents to be started. |
| 2011 | * |
| 2012 | * @throws ActivityNotFoundException |
| 2013 | * |
| 2014 | * @see #startActivities(Intent[], Bundle) |
| 2015 | * @see PackageManager#resolveActivity |
| 2016 | */ |
| 2017 | public abstract void startActivities(@RequiresPermission Intent[] intents); |
| 2018 | |
| 2019 | /** |
| 2020 | * Launch multiple new activities. This is generally the same as calling |
| 2021 | * {@link #startActivity(Intent)} for the first Intent in the array, |
| 2022 | * that activity during its creation calling {@link #startActivity(Intent)} |
| 2023 | * for the second entry, etc. Note that unlike that approach, generally |
| 2024 | * none of the activities except the last in the array will be created |
| 2025 | * at this point, but rather will be created when the user first visits |
| 2026 | * them (due to pressing back from the activity on top). |
| 2027 | * |
| 2028 | * <p>This method throws {@link ActivityNotFoundException} |
| 2029 | * if there was no Activity found for <em>any</em> given Intent. In this |
| 2030 | * case the state of the activity stack is undefined (some Intents in the |
| 2031 | * list may be on it, some not), so you probably want to avoid such situations. |
| 2032 | * |
| 2033 | * @param intents An array of Intents to be started. |
| 2034 | * @param options Additional options for how the Activity should be started. |
| 2035 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
| 2036 | * Context.startActivity(Intent, Bundle)} for more details. |
| 2037 | * |
| 2038 | * @throws ActivityNotFoundException |
| 2039 | * |
| 2040 | * @see #startActivities(Intent[]) |
| 2041 | * @see PackageManager#resolveActivity |
| 2042 | */ |
| 2043 | public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options); |
| 2044 | |
| 2045 | /** |
| 2046 | * @hide |
| 2047 | * Launch multiple new activities. This is generally the same as calling |
| 2048 | * {@link #startActivity(Intent)} for the first Intent in the array, |
| 2049 | * that activity during its creation calling {@link #startActivity(Intent)} |
| 2050 | * for the second entry, etc. Note that unlike that approach, generally |
| 2051 | * none of the activities except the last in the array will be created |
| 2052 | * at this point, but rather will be created when the user first visits |
| 2053 | * them (due to pressing back from the activity on top). |
| 2054 | * |
| 2055 | * <p>This method throws {@link ActivityNotFoundException} |
| 2056 | * if there was no Activity found for <em>any</em> given Intent. In this |
| 2057 | * case the state of the activity stack is undefined (some Intents in the |
| 2058 | * list may be on it, some not), so you probably want to avoid such situations. |
| 2059 | * |
| 2060 | * @param intents An array of Intents to be started. |
| 2061 | * @param options Additional options for how the Activity should be started. |
| 2062 | * @param userHandle The user for whom to launch the activities |
| 2063 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
| 2064 | * Context.startActivity(Intent, Bundle)} for more details. |
| 2065 | * |
| 2066 | * @return The corresponding flag {@link ActivityManager#START_CANCELED}, |
| 2067 | * {@link ActivityManager#START_SUCCESS} etc. indicating whether the launch was |
| 2068 | * successful. |
| 2069 | * |
| 2070 | * @throws ActivityNotFoundException |
| 2071 | * |
| 2072 | * @see #startActivities(Intent[]) |
| 2073 | * @see PackageManager#resolveActivity |
| 2074 | */ |
| 2075 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) |
| 2076 | public int startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) { |
| 2077 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 2078 | } |
| 2079 | |
| 2080 | /** |
| 2081 | * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)} |
| 2082 | * with no options specified. |
| 2083 | * |
| 2084 | * @param intent The IntentSender to launch. |
| 2085 | * @param fillInIntent If non-null, this will be provided as the |
| 2086 | * intent parameter to {@link IntentSender#sendIntent}. |
| 2087 | * @param flagsMask Intent flags in the original IntentSender that you |
| 2088 | * would like to change. |
| 2089 | * @param flagsValues Desired values for any bits set in |
| 2090 | * <var>flagsMask</var> |
| 2091 | * @param extraFlags Always set to 0. |
| 2092 | * |
| 2093 | * @see #startActivity(Intent) |
| 2094 | * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle) |
| 2095 | */ |
| 2096 | public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent, |
| 2097 | @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues, |
| 2098 | int extraFlags) throws IntentSender.SendIntentException; |
| 2099 | |
| 2100 | /** |
| 2101 | * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender |
| 2102 | * to start. If the IntentSender is for an activity, that activity will be started |
| 2103 | * as if you had called the regular {@link #startActivity(Intent)} |
| 2104 | * here; otherwise, its associated action will be executed (such as |
| 2105 | * sending a broadcast) as if you had called |
| 2106 | * {@link IntentSender#sendIntent IntentSender.sendIntent} on it. |
| 2107 | * |
| 2108 | * @param intent The IntentSender to launch. |
| 2109 | * @param fillInIntent If non-null, this will be provided as the |
| 2110 | * intent parameter to {@link IntentSender#sendIntent}. |
| 2111 | * @param flagsMask Intent flags in the original IntentSender that you |
| 2112 | * would like to change. |
| 2113 | * @param flagsValues Desired values for any bits set in |
| 2114 | * <var>flagsMask</var> |
| 2115 | * @param extraFlags Always set to 0. |
| 2116 | * @param options Additional options for how the Activity should be started. |
| 2117 | * See {@link android.content.Context#startActivity(Intent, Bundle)} |
| 2118 | * Context.startActivity(Intent, Bundle)} for more details. If options |
| 2119 | * have also been supplied by the IntentSender, options given here will |
| 2120 | * override any that conflict with those given by the IntentSender. |
| 2121 | * |
| 2122 | * @see #startActivity(Intent, Bundle) |
| 2123 | * @see #startIntentSender(IntentSender, Intent, int, int, int) |
| 2124 | */ |
| 2125 | public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent, |
| 2126 | @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues, |
| 2127 | int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException; |
| 2128 | |
| 2129 | /** |
| 2130 | * Broadcast the given intent to all interested BroadcastReceivers. This |
| 2131 | * call is asynchronous; it returns immediately, and you will continue |
| 2132 | * executing while the receivers are run. No results are propagated from |
| 2133 | * receivers and receivers can not abort the broadcast. If you want |
| 2134 | * to allow receivers to propagate results or abort the broadcast, you must |
| 2135 | * send an ordered broadcast using |
| 2136 | * {@link #sendOrderedBroadcast(Intent, String)}. |
| 2137 | * |
| 2138 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2139 | * |
| 2140 | * @param intent The Intent to broadcast; all receivers matching this |
| 2141 | * Intent will receive the broadcast. |
| 2142 | * |
| 2143 | * @see android.content.BroadcastReceiver |
| 2144 | * @see #registerReceiver |
| 2145 | * @see #sendBroadcast(Intent, String) |
| 2146 | * @see #sendOrderedBroadcast(Intent, String) |
| 2147 | * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) |
| 2148 | */ |
| 2149 | public abstract void sendBroadcast(@RequiresPermission Intent intent); |
| 2150 | |
| 2151 | /** |
| 2152 | * Broadcast the given intent to all interested BroadcastReceivers, allowing |
| 2153 | * an optional required permission to be enforced. This |
| 2154 | * call is asynchronous; it returns immediately, and you will continue |
| 2155 | * executing while the receivers are run. No results are propagated from |
| 2156 | * receivers and receivers can not abort the broadcast. If you want |
| 2157 | * to allow receivers to propagate results or abort the broadcast, you must |
| 2158 | * send an ordered broadcast using |
| 2159 | * {@link #sendOrderedBroadcast(Intent, String)}. |
| 2160 | * |
| 2161 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2162 | * |
| 2163 | * @param intent The Intent to broadcast; all receivers matching this |
| 2164 | * Intent will receive the broadcast. |
| 2165 | * @param receiverPermission (optional) String naming a permission that |
| 2166 | * a receiver must hold in order to receive your broadcast. |
| 2167 | * If null, no permission is required. |
| 2168 | * |
| 2169 | * @see android.content.BroadcastReceiver |
| 2170 | * @see #registerReceiver |
| 2171 | * @see #sendBroadcast(Intent) |
| 2172 | * @see #sendOrderedBroadcast(Intent, String) |
| 2173 | * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) |
| 2174 | */ |
| 2175 | public abstract void sendBroadcast(@RequiresPermission Intent intent, |
| 2176 | @Nullable String receiverPermission); |
| 2177 | |
| 2178 | |
| 2179 | /** |
| 2180 | * Broadcast the given intent to all interested BroadcastReceivers, allowing |
| 2181 | * an array of required permissions to be enforced. This call is asynchronous; it returns |
| 2182 | * immediately, and you will continue executing while the receivers are run. No results are |
| 2183 | * propagated from receivers and receivers can not abort the broadcast. If you want to allow |
| 2184 | * receivers to propagate results or abort the broadcast, you must send an ordered broadcast |
| 2185 | * using {@link #sendOrderedBroadcast(Intent, String)}. |
| 2186 | * |
| 2187 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2188 | * |
| 2189 | * @param intent The Intent to broadcast; all receivers matching this |
| 2190 | * Intent will receive the broadcast. |
| 2191 | * @param receiverPermissions Array of names of permissions that a receiver must hold |
| 2192 | * in order to receive your broadcast. |
| 2193 | * If empty, no permissions are required. |
| 2194 | * |
| 2195 | * @see android.content.BroadcastReceiver |
| 2196 | * @see #registerReceiver |
| 2197 | * @see #sendBroadcast(Intent) |
| 2198 | * @see #sendOrderedBroadcast(Intent, String) |
| 2199 | * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) |
| 2200 | * @hide |
| 2201 | */ |
| 2202 | public void sendBroadcastMultiplePermissions(@NonNull Intent intent, |
| 2203 | @NonNull String[] receiverPermissions) { |
| 2204 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 2205 | } |
| 2206 | |
| 2207 | /** |
| 2208 | * Like {@link #sendBroadcastMultiplePermissions(Intent, String[])}, but also allows |
| 2209 | * specification of a list of excluded permissions. This allows sending a broadcast to an |
| 2210 | * app that has the permissions in `receiverPermissions` but not `excludedPermissions`. |
| 2211 | * @hide |
| 2212 | */ |
| 2213 | public void sendBroadcastMultiplePermissions(@NonNull Intent intent, |
| 2214 | @NonNull String[] receiverPermissions, @Nullable String[] excludedPermissions) { |
| 2215 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 2216 | } |
| 2217 | |
| 2218 | /** |
| 2219 | * Version of {@link #sendBroadcastMultiplePermissions(Intent, String[])} that allows you to |
| 2220 | * specify the {@link android.app.BroadcastOptions}. |
| 2221 | * |
| 2222 | * @param intent The Intent to broadcast; all receivers matching this |
| 2223 | * Intent will receive the broadcast. |
| 2224 | * @param receiverPermissions Array of names of permissions that a receiver must hold |
| 2225 | * in order to receive your broadcast. |
| 2226 | * If empty, no permissions are required. |
| 2227 | * @param options Additional sending options, generated from a |
| 2228 | * {@link android.app.BroadcastOptions}. |
| 2229 | * @see #sendBroadcastMultiplePermissions(Intent, String[]) |
| 2230 | * @see android.app.BroadcastOptions |
| 2231 | * @hide |
| 2232 | */ |
| 2233 | public void sendBroadcastMultiplePermissions(@NonNull Intent intent, |
| 2234 | @NonNull String[] receiverPermissions, @Nullable Bundle options) { |
| 2235 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 2236 | } |
| 2237 | |
| 2238 | /** |
| 2239 | * Broadcast the given intent to all interested BroadcastReceivers, allowing |
| 2240 | * an array of required permissions to be enforced. This call is asynchronous; it returns |
| 2241 | * immediately, and you will continue executing while the receivers are run. No results are |
| 2242 | * propagated from receivers and receivers can not abort the broadcast. If you want to allow |
| 2243 | * receivers to propagate results or abort the broadcast, you must send an ordered broadcast |
| 2244 | * using {@link #sendOrderedBroadcast(Intent, String)}. |
| 2245 | * |
| 2246 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2247 | * |
| 2248 | * @param intent The Intent to broadcast; all receivers matching this |
| 2249 | * Intent will receive the broadcast. |
| 2250 | * @param receiverPermissions Array of names of permissions that a receiver must hold |
| 2251 | * in order to receive your broadcast. |
| 2252 | * If empty, no permissions are required. |
| 2253 | * |
| 2254 | * @see android.content.BroadcastReceiver |
| 2255 | * @see #registerReceiver |
| 2256 | * @see #sendBroadcast(Intent) |
| 2257 | * @see #sendOrderedBroadcast(Intent, String) |
| 2258 | * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) |
| 2259 | */ |
| 2260 | public void sendBroadcastWithMultiplePermissions(@NonNull Intent intent, |
| 2261 | @NonNull String[] receiverPermissions) { |
| 2262 | sendBroadcastMultiplePermissions(intent, receiverPermissions); |
| 2263 | } |
| 2264 | |
| 2265 | /** |
| 2266 | * Broadcast the given intent to all interested BroadcastReceivers, allowing |
| 2267 | * an array of required permissions to be enforced. This call is asynchronous; it returns |
| 2268 | * immediately, and you will continue executing while the receivers are run. No results are |
| 2269 | * propagated from receivers and receivers can not abort the broadcast. If you want to allow |
| 2270 | * receivers to propagate results or abort the broadcast, you must send an ordered broadcast |
| 2271 | * using {@link #sendOrderedBroadcast(Intent, String)}. |
| 2272 | * |
| 2273 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2274 | * |
| 2275 | * @param intent The Intent to broadcast; all receivers matching this |
| 2276 | * Intent will receive the broadcast. |
| 2277 | * @param user The user to send the broadcast to. |
| 2278 | * @param receiverPermissions Array of names of permissions that a receiver must hold |
| 2279 | * in order to receive your broadcast. |
| 2280 | * If null or empty, no permissions are required. |
| 2281 | * |
| 2282 | * @see android.content.BroadcastReceiver |
| 2283 | * @see #registerReceiver |
| 2284 | * @see #sendBroadcast(Intent) |
| 2285 | * @see #sendOrderedBroadcast(Intent, String) |
| 2286 | * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) |
| 2287 | * @hide |
| 2288 | */ |
| 2289 | @SuppressWarnings("HiddenAbstractMethod") |
| 2290 | public abstract void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user, |
| 2291 | String[] receiverPermissions); |
| 2292 | |
| 2293 | /** |
| 2294 | * Broadcast the given intent to all interested BroadcastReceivers, allowing |
| 2295 | * an optional required permission to be enforced. This |
| 2296 | * call is asynchronous; it returns immediately, and you will continue |
| 2297 | * executing while the receivers are run. No results are propagated from |
| 2298 | * receivers and receivers can not abort the broadcast. If you want |
| 2299 | * to allow receivers to propagate results or abort the broadcast, you must |
| 2300 | * send an ordered broadcast using |
| 2301 | * {@link #sendOrderedBroadcast(Intent, String)}. |
| 2302 | * |
| 2303 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2304 | * |
| 2305 | * @param intent The Intent to broadcast; all receivers matching this |
| 2306 | * Intent will receive the broadcast. |
| 2307 | * @param receiverPermission (optional) String naming a permission that |
| 2308 | * a receiver must hold in order to receive your broadcast. |
| 2309 | * If null, no permission is required. |
| 2310 | * @param options (optional) Additional sending options, generated from a |
| 2311 | * {@link android.app.BroadcastOptions}. |
| 2312 | * |
| 2313 | * @see android.content.BroadcastReceiver |
| 2314 | * @see #registerReceiver |
| 2315 | * @see #sendBroadcast(Intent) |
| 2316 | * @see #sendOrderedBroadcast(Intent, String) |
| 2317 | * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) |
| 2318 | * @hide |
| 2319 | */ |
| 2320 | @SuppressWarnings("HiddenAbstractMethod") |
| 2321 | @SystemApi |
| 2322 | public abstract void sendBroadcast(Intent intent, |
| 2323 | @Nullable String receiverPermission, |
| 2324 | @Nullable Bundle options); |
| 2325 | |
| 2326 | /** |
| 2327 | * Like {@link #sendBroadcast(Intent, String)}, but also allows specification |
| 2328 | * of an associated app op as per {@link android.app.AppOpsManager}. |
| 2329 | * @hide |
| 2330 | */ |
| 2331 | @SuppressWarnings("HiddenAbstractMethod") |
| 2332 | @UnsupportedAppUsage |
| 2333 | public abstract void sendBroadcast(Intent intent, |
| 2334 | String receiverPermission, int appOp); |
| 2335 | |
| 2336 | /** |
| 2337 | * Broadcast the given intent to all interested BroadcastReceivers, delivering |
| 2338 | * them one at a time to allow more preferred receivers to consume the |
| 2339 | * broadcast before it is delivered to less preferred receivers. This |
| 2340 | * call is asynchronous; it returns immediately, and you will continue |
| 2341 | * executing while the receivers are run. |
| 2342 | * |
| 2343 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2344 | * |
| 2345 | * @param intent The Intent to broadcast; all receivers matching this |
| 2346 | * Intent will receive the broadcast. |
| 2347 | * @param receiverPermission (optional) String naming a permissions that |
| 2348 | * a receiver must hold in order to receive your broadcast. |
| 2349 | * If null, no permission is required. |
| 2350 | * |
| 2351 | * @see android.content.BroadcastReceiver |
| 2352 | * @see #registerReceiver |
| 2353 | * @see #sendBroadcast(Intent) |
| 2354 | * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) |
| 2355 | */ |
| 2356 | public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent, |
| 2357 | @Nullable String receiverPermission); |
| 2358 | |
| 2359 | /** |
| 2360 | * Version of {@link #sendBroadcast(Intent)} that allows you to |
| 2361 | * receive data back from the broadcast. This is accomplished by |
| 2362 | * supplying your own BroadcastReceiver when calling, which will be |
| 2363 | * treated as a final receiver at the end of the broadcast -- its |
| 2364 | * {@link BroadcastReceiver#onReceive} method will be called with |
| 2365 | * the result values collected from the other receivers. The broadcast will |
| 2366 | * be serialized in the same way as calling |
| 2367 | * {@link #sendOrderedBroadcast(Intent, String)}. |
| 2368 | * |
| 2369 | * <p>Like {@link #sendBroadcast(Intent)}, this method is |
| 2370 | * asynchronous; it will return before |
| 2371 | * resultReceiver.onReceive() is called. |
| 2372 | * |
| 2373 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2374 | * |
| 2375 | * @param intent The Intent to broadcast; all receivers matching this |
| 2376 | * Intent will receive the broadcast. |
| 2377 | * @param receiverPermission String naming a permissions that |
| 2378 | * a receiver must hold in order to receive your broadcast. |
| 2379 | * If null, no permission is required. |
| 2380 | * @param resultReceiver Your own BroadcastReceiver to treat as the final |
| 2381 | * receiver of the broadcast. |
| 2382 | * @param scheduler A custom Handler with which to schedule the |
| 2383 | * resultReceiver callback; if null it will be |
| 2384 | * scheduled in the Context's main thread. |
| 2385 | * @param initialCode An initial value for the result code. Often |
| 2386 | * Activity.RESULT_OK. |
| 2387 | * @param initialData An initial value for the result data. Often |
| 2388 | * null. |
| 2389 | * @param initialExtras An initial value for the result extras. Often |
| 2390 | * null. |
| 2391 | * |
| 2392 | * @see #sendBroadcast(Intent) |
| 2393 | * @see #sendBroadcast(Intent, String) |
| 2394 | * @see #sendOrderedBroadcast(Intent, String) |
| 2395 | * @see android.content.BroadcastReceiver |
| 2396 | * @see #registerReceiver |
| 2397 | * @see android.app.Activity#RESULT_OK |
| 2398 | */ |
| 2399 | public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent, |
| 2400 | @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver, |
| 2401 | @Nullable Handler scheduler, int initialCode, @Nullable String initialData, |
| 2402 | @Nullable Bundle initialExtras); |
| 2403 | |
| 2404 | /** |
| 2405 | * Version of {@link #sendBroadcast(Intent)} that allows you to |
| 2406 | * receive data back from the broadcast. This is accomplished by |
| 2407 | * supplying your own BroadcastReceiver when calling, which will be |
| 2408 | * treated as a final receiver at the end of the broadcast -- its |
| 2409 | * {@link BroadcastReceiver#onReceive} method will be called with |
| 2410 | * the result values collected from the other receivers. The broadcast will |
| 2411 | * be serialized in the same way as calling |
| 2412 | * {@link #sendOrderedBroadcast(Intent, String)}. |
| 2413 | * |
| 2414 | * <p>Like {@link #sendBroadcast(Intent)}, this method is |
| 2415 | * asynchronous; it will return before |
| 2416 | * resultReceiver.onReceive() is called. |
| 2417 | * |
| 2418 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2419 | * |
| 2420 | * |
| 2421 | * @param intent The Intent to broadcast; all receivers matching this |
| 2422 | * Intent will receive the broadcast. |
| 2423 | * @param receiverPermission String naming a permissions that |
| 2424 | * a receiver must hold in order to receive your broadcast. |
| 2425 | * If null, no permission is required. |
| 2426 | * @param options (optional) Additional sending options, generated from a |
| 2427 | * {@link android.app.BroadcastOptions}. |
| 2428 | * @param resultReceiver Your own BroadcastReceiver to treat as the final |
| 2429 | * receiver of the broadcast. |
| 2430 | * @param scheduler A custom Handler with which to schedule the |
| 2431 | * resultReceiver callback; if null it will be |
| 2432 | * scheduled in the Context's main thread. |
| 2433 | * @param initialCode An initial value for the result code. Often |
| 2434 | * Activity.RESULT_OK. |
| 2435 | * @param initialData An initial value for the result data. Often |
| 2436 | * null. |
| 2437 | * @param initialExtras An initial value for the result extras. Often |
| 2438 | * null. |
| 2439 | * @see #sendBroadcast(Intent) |
| 2440 | * @see #sendBroadcast(Intent, String) |
| 2441 | * @see #sendOrderedBroadcast(Intent, String) |
| 2442 | * @see android.content.BroadcastReceiver |
| 2443 | * @see #registerReceiver |
| 2444 | * @see android.app.Activity#RESULT_OK |
| 2445 | * @hide |
| 2446 | */ |
| 2447 | @SuppressWarnings("HiddenAbstractMethod") |
| 2448 | @SystemApi |
| 2449 | public abstract void sendOrderedBroadcast(@NonNull Intent intent, |
| 2450 | @Nullable String receiverPermission, @Nullable Bundle options, |
| 2451 | @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, |
| 2452 | int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras); |
| 2453 | |
| 2454 | /** |
| 2455 | * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, |
| 2456 | * int, String, android.os.Bundle)}, but also allows specification |
| 2457 | * of an associated app op as per {@link android.app.AppOpsManager}. |
| 2458 | * @hide |
| 2459 | */ |
| 2460 | @SuppressWarnings("HiddenAbstractMethod") |
| 2461 | @UnsupportedAppUsage |
| 2462 | public abstract void sendOrderedBroadcast(Intent intent, |
| 2463 | String receiverPermission, int appOp, BroadcastReceiver resultReceiver, |
| 2464 | Handler scheduler, int initialCode, String initialData, |
| 2465 | Bundle initialExtras); |
| 2466 | |
| 2467 | /** |
| 2468 | * Version of {@link #sendBroadcast(Intent)} that allows you to specify the |
| 2469 | * user the broadcast will be sent to. This is not available to applications |
| 2470 | * that are not pre-installed on the system image. |
| 2471 | * @param intent The intent to broadcast |
| 2472 | * @param user UserHandle to send the intent to. |
| 2473 | * @see #sendBroadcast(Intent) |
| 2474 | */ |
| 2475 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) |
| 2476 | public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent, |
| 2477 | UserHandle user); |
| 2478 | |
| 2479 | /** |
| 2480 | * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the |
| 2481 | * user the broadcast will be sent to. This is not available to applications |
| 2482 | * that are not pre-installed on the system image. |
| 2483 | * |
| 2484 | * @param intent The Intent to broadcast; all receivers matching this |
| 2485 | * Intent will receive the broadcast. |
| 2486 | * @param user UserHandle to send the intent to. |
| 2487 | * @param receiverPermission (optional) String naming a permission that |
| 2488 | * a receiver must hold in order to receive your broadcast. |
| 2489 | * If null, no permission is required. |
| 2490 | * |
| 2491 | * @see #sendBroadcast(Intent, String) |
| 2492 | */ |
| 2493 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) |
| 2494 | public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent, |
| 2495 | UserHandle user, @Nullable String receiverPermission); |
| 2496 | |
| 2497 | /** |
| 2498 | * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the |
| 2499 | * user the broadcast will be sent to. This is not available to applications |
| 2500 | * that are not pre-installed on the system image. |
| 2501 | * |
| 2502 | * @param intent The Intent to broadcast; all receivers matching this |
| 2503 | * Intent will receive the broadcast. |
| 2504 | * @param user UserHandle to send the intent to. |
| 2505 | * @param receiverPermission (optional) String naming a permission that |
| 2506 | * a receiver must hold in order to receive your broadcast. |
| 2507 | * If null, no permission is required. |
| 2508 | * @param options (optional) Additional sending options, generated from a |
| 2509 | * {@link android.app.BroadcastOptions}. |
| 2510 | * |
| 2511 | * @see #sendBroadcast(Intent, String, Bundle) |
| 2512 | * @hide |
| 2513 | */ |
| 2514 | @SuppressWarnings("HiddenAbstractMethod") |
| 2515 | @SystemApi |
| 2516 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) |
| 2517 | public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent, |
| 2518 | UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options); |
| 2519 | |
| 2520 | /** |
| 2521 | * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the |
| 2522 | * user the broadcast will be sent to. This is not available to applications |
| 2523 | * that are not pre-installed on the system image. |
| 2524 | * |
| 2525 | * @param intent The Intent to broadcast; all receivers matching this |
| 2526 | * Intent will receive the broadcast. |
| 2527 | * @param user UserHandle to send the intent to. |
| 2528 | * @param receiverPermission (optional) String naming a permission that |
| 2529 | * a receiver must hold in order to receive your broadcast. |
| 2530 | * If null, no permission is required. |
| 2531 | * @param appOp The app op associated with the broadcast. |
| 2532 | * |
| 2533 | * @see #sendBroadcast(Intent, String) |
| 2534 | * |
| 2535 | * @hide |
| 2536 | */ |
| 2537 | @SuppressWarnings("HiddenAbstractMethod") |
| 2538 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) |
| 2539 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 2540 | public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent, |
| 2541 | UserHandle user, @Nullable String receiverPermission, int appOp); |
| 2542 | |
| 2543 | /** |
| 2544 | * Version of |
| 2545 | * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)} |
| 2546 | * that allows you to specify the |
| 2547 | * user the broadcast will be sent to. This is not available to applications |
| 2548 | * that are not pre-installed on the system image. |
| 2549 | * |
| 2550 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2551 | * |
| 2552 | * @param intent The Intent to broadcast; all receivers matching this |
| 2553 | * Intent will receive the broadcast. |
| 2554 | * @param user UserHandle to send the intent to. |
| 2555 | * @param receiverPermission String naming a permissions that |
| 2556 | * a receiver must hold in order to receive your broadcast. |
| 2557 | * If null, no permission is required. |
| 2558 | * @param resultReceiver Your own BroadcastReceiver to treat as the final |
| 2559 | * receiver of the broadcast. |
| 2560 | * @param scheduler A custom Handler with which to schedule the |
| 2561 | * resultReceiver callback; if null it will be |
| 2562 | * scheduled in the Context's main thread. |
| 2563 | * @param initialCode An initial value for the result code. Often |
| 2564 | * Activity.RESULT_OK. |
| 2565 | * @param initialData An initial value for the result data. Often |
| 2566 | * null. |
| 2567 | * @param initialExtras An initial value for the result extras. Often |
| 2568 | * null. |
| 2569 | * |
| 2570 | * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) |
| 2571 | */ |
| 2572 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) |
| 2573 | public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent, |
| 2574 | UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver, |
| 2575 | @Nullable Handler scheduler, int initialCode, @Nullable String initialData, |
| 2576 | @Nullable Bundle initialExtras); |
| 2577 | |
| 2578 | /** |
| 2579 | * Similar to above but takes an appOp as well, to enforce restrictions. |
| 2580 | * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String, |
| 2581 | * BroadcastReceiver, Handler, int, String, Bundle) |
| 2582 | * @hide |
| 2583 | */ |
| 2584 | @SuppressWarnings("HiddenAbstractMethod") |
| 2585 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) |
| 2586 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 2587 | public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, |
| 2588 | @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver, |
| 2589 | @Nullable Handler scheduler, int initialCode, @Nullable String initialData, |
| 2590 | @Nullable Bundle initialExtras); |
| 2591 | |
| 2592 | /** |
| 2593 | * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle. |
| 2594 | * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String, |
| 2595 | * BroadcastReceiver, Handler, int, String, Bundle) |
| 2596 | * @hide |
| 2597 | */ |
| 2598 | @SuppressWarnings("HiddenAbstractMethod") |
| 2599 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) |
| 2600 | @UnsupportedAppUsage |
| 2601 | public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, |
| 2602 | @Nullable String receiverPermission, int appOp, @Nullable Bundle options, |
| 2603 | BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, |
| 2604 | @Nullable String initialData, @Nullable Bundle initialExtras); |
| 2605 | |
| 2606 | /** |
| 2607 | * Version of |
| 2608 | * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, |
| 2609 | * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers |
| 2610 | * the broadcast will be sent to. |
| 2611 | * |
| 2612 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2613 | * |
| 2614 | * @param intent The Intent to broadcast; all receivers matching this |
| 2615 | * Intent will receive the broadcast. |
| 2616 | * @param receiverPermission String naming a permissions that |
| 2617 | * a receiver must hold in order to receive your broadcast. |
| 2618 | * If null, no permission is required. |
| 2619 | * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is |
| 2620 | * required. If both receiverAppOp and receiverPermission are non-null, |
| 2621 | * a receiver must have both of them to |
| 2622 | * receive the broadcast |
| 2623 | * @param resultReceiver Your own BroadcastReceiver to treat as the final |
| 2624 | * receiver of the broadcast. |
| 2625 | * @param scheduler A custom Handler with which to schedule the |
| 2626 | * resultReceiver callback; if null it will be |
| 2627 | * scheduled in the Context's main thread. |
| 2628 | * @param initialCode An initial value for the result code. Often |
| 2629 | * Activity.RESULT_OK. |
| 2630 | * @param initialData An initial value for the result data. Often |
| 2631 | * null. |
| 2632 | * @param initialExtras An initial value for the result extras. Often |
| 2633 | * null. |
| 2634 | * |
| 2635 | * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) |
| 2636 | */ |
| 2637 | public void sendOrderedBroadcast(@NonNull Intent intent, @Nullable String receiverPermission, |
| 2638 | @Nullable String receiverAppOp, @Nullable BroadcastReceiver resultReceiver, |
| 2639 | @Nullable Handler scheduler, int initialCode, @Nullable String initialData, |
| 2640 | @Nullable Bundle initialExtras) { |
| 2641 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 2642 | } |
| 2643 | |
| 2644 | /** |
| 2645 | * Version of |
| 2646 | * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, |
| 2647 | * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers |
| 2648 | * the broadcast will be sent to as well as supply an optional sending options |
| 2649 | * |
| 2650 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2651 | * |
| 2652 | * @param intent The Intent to broadcast; all receivers matching this |
| 2653 | * Intent will receive the broadcast. |
| 2654 | * @param receiverPermission String naming a permissions that |
| 2655 | * a receiver must hold in order to receive your broadcast. |
| 2656 | * If null, no permission is required. |
| 2657 | * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is |
| 2658 | * required. If both receiverAppOp and receiverPermission are non-null, |
| 2659 | * a receiver must have both of them to |
| 2660 | * receive the broadcast |
| 2661 | * @param options (optional) Additional sending options, generated from a |
| 2662 | * {@link android.app.BroadcastOptions}. |
| 2663 | * @param resultReceiver Your own BroadcastReceiver to treat as the final |
| 2664 | * receiver of the broadcast. |
| 2665 | * @param scheduler A custom Handler with which to schedule the |
| 2666 | * resultReceiver callback; if null it will be |
| 2667 | * scheduled in the Context's main thread. |
| 2668 | * @param initialCode An initial value for the result code. Often |
| 2669 | * Activity.RESULT_OK. |
| 2670 | * @param initialData An initial value for the result data. Often |
| 2671 | * null. |
| 2672 | * @param initialExtras An initial value for the result extras. Often |
| 2673 | * null. |
| 2674 | * |
| 2675 | * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) |
| 2676 | * @see android.app.BroadcastOptions |
| 2677 | * @hide |
| 2678 | */ |
| 2679 | public void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent, int initialCode, |
| 2680 | @Nullable String receiverPermission, @Nullable String receiverAppOp, |
| 2681 | @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, |
| 2682 | @Nullable String initialData, @Nullable Bundle initialExtras, |
| 2683 | @Nullable Bundle options) { |
| 2684 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 2685 | } |
| 2686 | |
| 2687 | /** |
| 2688 | * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the |
| 2689 | * Intent you are sending stays around after the broadcast is complete, |
| 2690 | * so that others can quickly retrieve that data through the return |
| 2691 | * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In |
| 2692 | * all other ways, this behaves the same as |
| 2693 | * {@link #sendBroadcast(Intent)}. |
| 2694 | * |
| 2695 | * @deprecated Sticky broadcasts should not be used. They provide no security (anyone |
| 2696 | * can access them), no protection (anyone can modify them), and many other problems. |
| 2697 | * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> |
| 2698 | * has changed, with another mechanism for apps to retrieve the current value whenever |
| 2699 | * desired. |
| 2700 | * |
| 2701 | * @param intent The Intent to broadcast; all receivers matching this |
| 2702 | * Intent will receive the broadcast, and the Intent will be held to |
| 2703 | * be re-broadcast to future receivers. |
| 2704 | * |
| 2705 | * @see #sendBroadcast(Intent) |
| 2706 | * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle) |
| 2707 | */ |
| 2708 | @Deprecated |
| 2709 | @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY) |
| 2710 | public abstract void sendStickyBroadcast(@RequiresPermission Intent intent); |
| 2711 | |
| 2712 | /** |
| 2713 | * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the |
| 2714 | * Intent you are sending stays around after the broadcast is complete, |
| 2715 | * so that others can quickly retrieve that data through the return |
| 2716 | * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In |
| 2717 | * all other ways, this behaves the same as |
| 2718 | * {@link #sendBroadcast(Intent)}. |
| 2719 | * |
| 2720 | * @deprecated Sticky broadcasts should not be used. They provide no security (anyone |
| 2721 | * can access them), no protection (anyone can modify them), and many other problems. |
| 2722 | * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> |
| 2723 | * has changed, with another mechanism for apps to retrieve the current value whenever |
| 2724 | * desired. |
| 2725 | * |
| 2726 | * @param intent The Intent to broadcast; all receivers matching this |
| 2727 | * Intent will receive the broadcast, and the Intent will be held to |
| 2728 | * be re-broadcast to future receivers. |
| 2729 | * @param options (optional) Additional sending options, generated from a |
| 2730 | * {@link android.app.BroadcastOptions}. |
| 2731 | * |
| 2732 | * @see #sendBroadcast(Intent) |
| 2733 | * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle) |
| 2734 | */ |
| 2735 | @Deprecated |
| 2736 | @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY) |
| 2737 | public void sendStickyBroadcast(@RequiresPermission @NonNull Intent intent, |
| 2738 | @Nullable Bundle options) { |
| 2739 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 2740 | } |
| 2741 | |
| 2742 | /** |
| 2743 | * <p>Version of {@link #sendStickyBroadcast} that allows you to |
| 2744 | * receive data back from the broadcast. This is accomplished by |
| 2745 | * supplying your own BroadcastReceiver when calling, which will be |
| 2746 | * treated as a final receiver at the end of the broadcast -- its |
| 2747 | * {@link BroadcastReceiver#onReceive} method will be called with |
| 2748 | * the result values collected from the other receivers. The broadcast will |
| 2749 | * be serialized in the same way as calling |
| 2750 | * {@link #sendOrderedBroadcast(Intent, String)}. |
| 2751 | * |
| 2752 | * <p>Like {@link #sendBroadcast(Intent)}, this method is |
| 2753 | * asynchronous; it will return before |
| 2754 | * resultReceiver.onReceive() is called. Note that the sticky data |
| 2755 | * stored is only the data you initially supply to the broadcast, not |
| 2756 | * the result of any changes made by the receivers. |
| 2757 | * |
| 2758 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2759 | * |
| 2760 | * @deprecated Sticky broadcasts should not be used. They provide no security (anyone |
| 2761 | * can access them), no protection (anyone can modify them), and many other problems. |
| 2762 | * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> |
| 2763 | * has changed, with another mechanism for apps to retrieve the current value whenever |
| 2764 | * desired. |
| 2765 | * |
| 2766 | * @param intent The Intent to broadcast; all receivers matching this |
| 2767 | * Intent will receive the broadcast. |
| 2768 | * @param resultReceiver Your own BroadcastReceiver to treat as the final |
| 2769 | * receiver of the broadcast. |
| 2770 | * @param scheduler A custom Handler with which to schedule the |
| 2771 | * resultReceiver callback; if null it will be |
| 2772 | * scheduled in the Context's main thread. |
| 2773 | * @param initialCode An initial value for the result code. Often |
| 2774 | * Activity.RESULT_OK. |
| 2775 | * @param initialData An initial value for the result data. Often |
| 2776 | * null. |
| 2777 | * @param initialExtras An initial value for the result extras. Often |
| 2778 | * null. |
| 2779 | * |
| 2780 | * @see #sendBroadcast(Intent) |
| 2781 | * @see #sendBroadcast(Intent, String) |
| 2782 | * @see #sendOrderedBroadcast(Intent, String) |
| 2783 | * @see #sendStickyBroadcast(Intent) |
| 2784 | * @see android.content.BroadcastReceiver |
| 2785 | * @see #registerReceiver |
| 2786 | * @see android.app.Activity#RESULT_OK |
| 2787 | */ |
| 2788 | @Deprecated |
| 2789 | @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY) |
| 2790 | public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent, |
| 2791 | BroadcastReceiver resultReceiver, |
| 2792 | @Nullable Handler scheduler, int initialCode, @Nullable String initialData, |
| 2793 | @Nullable Bundle initialExtras); |
| 2794 | |
| 2795 | /** |
| 2796 | * <p>Remove the data previously sent with {@link #sendStickyBroadcast}, |
| 2797 | * so that it is as if the sticky broadcast had never happened. |
| 2798 | * |
| 2799 | * @deprecated Sticky broadcasts should not be used. They provide no security (anyone |
| 2800 | * can access them), no protection (anyone can modify them), and many other problems. |
| 2801 | * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> |
| 2802 | * has changed, with another mechanism for apps to retrieve the current value whenever |
| 2803 | * desired. |
| 2804 | * |
| 2805 | * @param intent The Intent that was previously broadcast. |
| 2806 | * |
| 2807 | * @see #sendStickyBroadcast |
| 2808 | */ |
| 2809 | @Deprecated |
| 2810 | @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY) |
| 2811 | public abstract void removeStickyBroadcast(@RequiresPermission Intent intent); |
| 2812 | |
| 2813 | /** |
| 2814 | * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the |
| 2815 | * user the broadcast will be sent to. This is not available to applications |
| 2816 | * that are not pre-installed on the system image. |
| 2817 | * |
| 2818 | * @deprecated Sticky broadcasts should not be used. They provide no security (anyone |
| 2819 | * can access them), no protection (anyone can modify them), and many other problems. |
| 2820 | * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> |
| 2821 | * has changed, with another mechanism for apps to retrieve the current value whenever |
| 2822 | * desired. |
| 2823 | * |
| 2824 | * @param intent The Intent to broadcast; all receivers matching this |
| 2825 | * Intent will receive the broadcast, and the Intent will be held to |
| 2826 | * be re-broadcast to future receivers. |
| 2827 | * @param user UserHandle to send the intent to. |
| 2828 | * |
| 2829 | * @see #sendBroadcast(Intent) |
| 2830 | */ |
| 2831 | @Deprecated |
| 2832 | @RequiresPermission(allOf = { |
| 2833 | android.Manifest.permission.INTERACT_ACROSS_USERS, |
| 2834 | android.Manifest.permission.BROADCAST_STICKY |
| 2835 | }) |
| 2836 | public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent, |
| 2837 | UserHandle user); |
| 2838 | |
| 2839 | /** |
| 2840 | * @hide |
| 2841 | * This is just here for sending CONNECTIVITY_ACTION. |
| 2842 | */ |
| 2843 | @SuppressWarnings("HiddenAbstractMethod") |
| 2844 | @Deprecated |
| 2845 | @RequiresPermission(allOf = { |
| 2846 | android.Manifest.permission.INTERACT_ACROSS_USERS, |
| 2847 | android.Manifest.permission.BROADCAST_STICKY |
| 2848 | }) |
| 2849 | public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent, |
| 2850 | UserHandle user, Bundle options); |
| 2851 | |
| 2852 | /** |
| 2853 | * <p>Version of |
| 2854 | * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)} |
| 2855 | * that allows you to specify the |
| 2856 | * user the broadcast will be sent to. This is not available to applications |
| 2857 | * that are not pre-installed on the system image. |
| 2858 | * |
| 2859 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2860 | * |
| 2861 | * @deprecated Sticky broadcasts should not be used. They provide no security (anyone |
| 2862 | * can access them), no protection (anyone can modify them), and many other problems. |
| 2863 | * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> |
| 2864 | * has changed, with another mechanism for apps to retrieve the current value whenever |
| 2865 | * desired. |
| 2866 | * |
| 2867 | * @param intent The Intent to broadcast; all receivers matching this |
| 2868 | * Intent will receive the broadcast. |
| 2869 | * @param user UserHandle to send the intent to. |
| 2870 | * @param resultReceiver Your own BroadcastReceiver to treat as the final |
| 2871 | * receiver of the broadcast. |
| 2872 | * @param scheduler A custom Handler with which to schedule the |
| 2873 | * resultReceiver callback; if null it will be |
| 2874 | * scheduled in the Context's main thread. |
| 2875 | * @param initialCode An initial value for the result code. Often |
| 2876 | * Activity.RESULT_OK. |
| 2877 | * @param initialData An initial value for the result data. Often |
| 2878 | * null. |
| 2879 | * @param initialExtras An initial value for the result extras. Often |
| 2880 | * null. |
| 2881 | * |
| 2882 | * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle) |
| 2883 | */ |
| 2884 | @Deprecated |
| 2885 | @RequiresPermission(allOf = { |
| 2886 | android.Manifest.permission.INTERACT_ACROSS_USERS, |
| 2887 | android.Manifest.permission.BROADCAST_STICKY |
| 2888 | }) |
| 2889 | public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent, |
| 2890 | UserHandle user, BroadcastReceiver resultReceiver, |
| 2891 | @Nullable Handler scheduler, int initialCode, @Nullable String initialData, |
| 2892 | @Nullable Bundle initialExtras); |
| 2893 | |
| 2894 | /** |
| 2895 | * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the |
| 2896 | * user the broadcast will be sent to. This is not available to applications |
| 2897 | * that are not pre-installed on the system image. |
| 2898 | * |
| 2899 | * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY} |
| 2900 | * permission in order to use this API. If you do not hold that |
| 2901 | * permission, {@link SecurityException} will be thrown. |
| 2902 | * |
| 2903 | * @deprecated Sticky broadcasts should not be used. They provide no security (anyone |
| 2904 | * can access them), no protection (anyone can modify them), and many other problems. |
| 2905 | * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> |
| 2906 | * has changed, with another mechanism for apps to retrieve the current value whenever |
| 2907 | * desired. |
| 2908 | * |
| 2909 | * @param intent The Intent that was previously broadcast. |
| 2910 | * @param user UserHandle to remove the sticky broadcast from. |
| 2911 | * |
| 2912 | * @see #sendStickyBroadcastAsUser |
| 2913 | */ |
| 2914 | @Deprecated |
| 2915 | @RequiresPermission(allOf = { |
| 2916 | android.Manifest.permission.INTERACT_ACROSS_USERS, |
| 2917 | android.Manifest.permission.BROADCAST_STICKY |
| 2918 | }) |
| 2919 | public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent, |
| 2920 | UserHandle user); |
| 2921 | |
| 2922 | /** |
| 2923 | * Register a BroadcastReceiver to be run in the main activity thread. The |
| 2924 | * <var>receiver</var> will be called with any broadcast Intent that |
| 2925 | * matches <var>filter</var>, in the main application thread. |
| 2926 | * |
| 2927 | * <p>The system may broadcast Intents that are "sticky" -- these stay |
| 2928 | * around after the broadcast has finished, to be sent to any later |
| 2929 | * registrations. If your IntentFilter matches one of these sticky |
| 2930 | * Intents, that Intent will be returned by this function |
| 2931 | * <strong>and</strong> sent to your <var>receiver</var> as if it had just |
| 2932 | * been broadcast. |
| 2933 | * |
| 2934 | * <p>There may be multiple sticky Intents that match <var>filter</var>, |
| 2935 | * in which case each of these will be sent to <var>receiver</var>. In |
| 2936 | * this case, only one of these can be returned directly by the function; |
| 2937 | * which of these that is returned is arbitrarily decided by the system. |
| 2938 | * |
| 2939 | * <p>If you know the Intent your are registering for is sticky, you can |
| 2940 | * supply null for your <var>receiver</var>. In this case, no receiver is |
| 2941 | * registered -- the function simply returns the sticky Intent that |
| 2942 | * matches <var>filter</var>. In the case of multiple matches, the same |
| 2943 | * rules as described above apply. |
| 2944 | * |
| 2945 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2946 | * |
| 2947 | * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers |
| 2948 | * registered with this method will correctly respect the |
| 2949 | * {@link Intent#setPackage(String)} specified for an Intent being broadcast. |
| 2950 | * Prior to that, it would be ignored and delivered to all matching registered |
| 2951 | * receivers. Be careful if using this for security.</p> |
| 2952 | * |
| 2953 | * <p class="note">Note: this method <em>cannot be called from a |
| 2954 | * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver |
| 2955 | * that is declared in an application's manifest. It is okay, however, to call |
| 2956 | * this method from another BroadcastReceiver that has itself been registered |
| 2957 | * at run time with {@link #registerReceiver}, since the lifetime of such a |
| 2958 | * registered BroadcastReceiver is tied to the object that registered it.</p> |
| 2959 | * |
| 2960 | * @param receiver The BroadcastReceiver to handle the broadcast. |
| 2961 | * @param filter Selects the Intent broadcasts to be received. |
| 2962 | * |
| 2963 | * @return The first sticky intent found that matches <var>filter</var>, |
| 2964 | * or null if there are none. |
| 2965 | * |
| 2966 | * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler) |
| 2967 | * @see #sendBroadcast |
| 2968 | * @see #unregisterReceiver |
| 2969 | */ |
| 2970 | @Nullable |
| 2971 | public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver, |
| 2972 | IntentFilter filter); |
| 2973 | |
| 2974 | /** |
| 2975 | * Register to receive intent broadcasts, with the receiver optionally being |
| 2976 | * exposed to Instant Apps. See |
| 2977 | * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more |
| 2978 | * information. By default Instant Apps cannot interact with receivers in other |
| 2979 | * applications, this allows you to expose a receiver that Instant Apps can |
| 2980 | * interact with. |
| 2981 | * |
| 2982 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 2983 | * |
| 2984 | * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers |
| 2985 | * registered with this method will correctly respect the |
| 2986 | * {@link Intent#setPackage(String)} specified for an Intent being broadcast. |
| 2987 | * Prior to that, it would be ignored and delivered to all matching registered |
| 2988 | * receivers. Be careful if using this for security.</p> |
| 2989 | * |
| 2990 | * @param receiver The BroadcastReceiver to handle the broadcast. |
| 2991 | * @param filter Selects the Intent broadcasts to be received. |
| 2992 | * @param flags Additional options for the receiver. May be 0 or |
| 2993 | * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}. |
| 2994 | * |
| 2995 | * @return The first sticky intent found that matches <var>filter</var>, |
| 2996 | * or null if there are none. |
| 2997 | * |
| 2998 | * @see #registerReceiver(BroadcastReceiver, IntentFilter) |
| 2999 | * @see #sendBroadcast |
| 3000 | * @see #unregisterReceiver |
| 3001 | */ |
| 3002 | @Nullable |
| 3003 | public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver, |
| 3004 | IntentFilter filter, |
| 3005 | @RegisterReceiverFlags int flags); |
| 3006 | |
| 3007 | /** |
| 3008 | * Register to receive intent broadcasts, to run in the context of |
| 3009 | * <var>scheduler</var>. See |
| 3010 | * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more |
| 3011 | * information. This allows you to enforce permissions on who can |
| 3012 | * broadcast intents to your receiver, or have the receiver run in |
| 3013 | * a different thread than the main application thread. |
| 3014 | * |
| 3015 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 3016 | * |
| 3017 | * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers |
| 3018 | * registered with this method will correctly respect the |
| 3019 | * {@link Intent#setPackage(String)} specified for an Intent being broadcast. |
| 3020 | * Prior to that, it would be ignored and delivered to all matching registered |
| 3021 | * receivers. Be careful if using this for security.</p> |
| 3022 | * |
| 3023 | * @param receiver The BroadcastReceiver to handle the broadcast. |
| 3024 | * @param filter Selects the Intent broadcasts to be received. |
| 3025 | * @param broadcastPermission String naming a permissions that a |
| 3026 | * broadcaster must hold in order to send an Intent to you. If null, |
| 3027 | * no permission is required. |
| 3028 | * @param scheduler Handler identifying the thread that will receive |
| 3029 | * the Intent. If null, the main thread of the process will be used. |
| 3030 | * |
| 3031 | * @return The first sticky intent found that matches <var>filter</var>, |
| 3032 | * or null if there are none. |
| 3033 | * |
| 3034 | * @see #registerReceiver(BroadcastReceiver, IntentFilter) |
| 3035 | * @see #sendBroadcast |
| 3036 | * @see #unregisterReceiver |
| 3037 | */ |
| 3038 | @Nullable |
| 3039 | public abstract Intent registerReceiver(BroadcastReceiver receiver, |
| 3040 | IntentFilter filter, @Nullable String broadcastPermission, |
| 3041 | @Nullable Handler scheduler); |
| 3042 | |
| 3043 | /** |
| 3044 | * Register to receive intent broadcasts, to run in the context of |
| 3045 | * <var>scheduler</var>. See |
| 3046 | * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and |
| 3047 | * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)} |
| 3048 | * for more information. |
| 3049 | * |
| 3050 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 3051 | * |
| 3052 | * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers |
| 3053 | * registered with this method will correctly respect the |
| 3054 | * {@link Intent#setPackage(String)} specified for an Intent being broadcast. |
| 3055 | * Prior to that, it would be ignored and delivered to all matching registered |
| 3056 | * receivers. Be careful if using this for security.</p> |
| 3057 | * |
| 3058 | * @param receiver The BroadcastReceiver to handle the broadcast. |
| 3059 | * @param filter Selects the Intent broadcasts to be received. |
| 3060 | * @param broadcastPermission String naming a permissions that a |
| 3061 | * broadcaster must hold in order to send an Intent to you. If null, |
| 3062 | * no permission is required. |
| 3063 | * @param scheduler Handler identifying the thread that will receive |
| 3064 | * the Intent. If null, the main thread of the process will be used. |
| 3065 | * @param flags Additional options for the receiver. May be 0 or |
| 3066 | * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}. |
| 3067 | * |
| 3068 | * @return The first sticky intent found that matches <var>filter</var>, |
| 3069 | * or null if there are none. |
| 3070 | * |
| 3071 | * @see #registerReceiver(BroadcastReceiver, IntentFilter, int) |
| 3072 | * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler) |
| 3073 | * @see #sendBroadcast |
| 3074 | * @see #unregisterReceiver |
| 3075 | */ |
| 3076 | @Nullable |
| 3077 | public abstract Intent registerReceiver(BroadcastReceiver receiver, |
| 3078 | IntentFilter filter, @Nullable String broadcastPermission, |
| 3079 | @Nullable Handler scheduler, @RegisterReceiverFlags int flags); |
| 3080 | |
| 3081 | /** |
| 3082 | * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)} |
| 3083 | * but this receiver will receive broadcasts that are sent to all users. The receiver can |
| 3084 | * use {@link BroadcastReceiver#getSendingUser} to determine on which user the broadcast |
| 3085 | * was sent. |
| 3086 | * |
| 3087 | * @param receiver The BroadcastReceiver to handle the broadcast. |
| 3088 | * @param filter Selects the Intent broadcasts to be received. |
| 3089 | * @param broadcastPermission String naming a permissions that a |
| 3090 | * broadcaster must hold in order to send an Intent to you. If {@code null}, |
| 3091 | * no permission is required. |
| 3092 | * @param scheduler Handler identifying the thread that will receive |
| 3093 | * the Intent. If {@code null}, the main thread of the process will be used. |
| 3094 | * |
| 3095 | * @return The first sticky intent found that matches <var>filter</var>, |
| 3096 | * or {@code null} if there are none. |
| 3097 | * |
| 3098 | * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler) |
| 3099 | * @see #sendBroadcast |
| 3100 | * @see #unregisterReceiver |
| 3101 | * @hide |
| 3102 | */ |
| 3103 | @Nullable |
| 3104 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
| 3105 | @SystemApi |
| 3106 | public Intent registerReceiverForAllUsers(@Nullable BroadcastReceiver receiver, |
| 3107 | @NonNull IntentFilter filter, @Nullable String broadcastPermission, |
| 3108 | @Nullable Handler scheduler) { |
| 3109 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 3110 | } |
| 3111 | |
| 3112 | /** |
| 3113 | * @hide |
| 3114 | * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler) |
| 3115 | * but for a specific user. This receiver will receiver broadcasts that |
| 3116 | * are sent to the requested user. |
| 3117 | * |
| 3118 | * @param receiver The BroadcastReceiver to handle the broadcast. |
| 3119 | * @param user UserHandle to send the intent to. |
| 3120 | * @param filter Selects the Intent broadcasts to be received. |
| 3121 | * @param broadcastPermission String naming a permissions that a |
| 3122 | * broadcaster must hold in order to send an Intent to you. If null, |
| 3123 | * no permission is required. |
| 3124 | * @param scheduler Handler identifying the thread that will receive |
| 3125 | * the Intent. If null, the main thread of the process will be used. |
| 3126 | * |
| 3127 | * @return The first sticky intent found that matches <var>filter</var>, |
| 3128 | * or null if there are none. |
| 3129 | * |
| 3130 | * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler) |
| 3131 | * @see #sendBroadcast |
| 3132 | * @see #unregisterReceiver |
| 3133 | */ |
| 3134 | @SuppressWarnings("HiddenAbstractMethod") |
| 3135 | @Nullable |
| 3136 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
| 3137 | @UnsupportedAppUsage |
| 3138 | public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver, |
| 3139 | UserHandle user, IntentFilter filter, @Nullable String broadcastPermission, |
| 3140 | @Nullable Handler scheduler); |
| 3141 | |
| 3142 | /** |
| 3143 | * Unregister a previously registered BroadcastReceiver. <em>All</em> |
| 3144 | * filters that have been registered for this BroadcastReceiver will be |
| 3145 | * removed. |
| 3146 | * |
| 3147 | * @param receiver The BroadcastReceiver to unregister. |
| 3148 | * |
| 3149 | * @see #registerReceiver |
| 3150 | */ |
| 3151 | public abstract void unregisterReceiver(BroadcastReceiver receiver); |
| 3152 | |
| 3153 | /** |
| 3154 | * Request that a given application service be started. The Intent |
| 3155 | * should either contain the complete class name of a specific service |
| 3156 | * implementation to start, or a specific package name to target. If the |
| 3157 | * Intent is less specified, it logs a warning about this. In this case any of the |
| 3158 | * multiple matching services may be used. If this service |
| 3159 | * is not already running, it will be instantiated and started (creating a |
| 3160 | * process for it if needed); if it is running then it remains running. |
| 3161 | * |
| 3162 | * <p>Every call to this method will result in a corresponding call to |
| 3163 | * the target service's {@link android.app.Service#onStartCommand} method, |
| 3164 | * with the <var>intent</var> given here. This provides a convenient way |
| 3165 | * to submit jobs to a service without having to bind and call on to its |
| 3166 | * interface. |
| 3167 | * |
| 3168 | * <p>Using startService() overrides the default service lifetime that is |
| 3169 | * managed by {@link #bindService}: it requires the service to remain |
| 3170 | * running until {@link #stopService} is called, regardless of whether |
| 3171 | * any clients are connected to it. Note that calls to startService() |
| 3172 | * do not nest: no matter how many times you call startService(), |
| 3173 | * a single call to {@link #stopService} will stop it. |
| 3174 | * |
| 3175 | * <p>The system attempts to keep running services around as much as |
| 3176 | * possible. The only time they should be stopped is if the current |
| 3177 | * foreground application is using so many resources that the service needs |
| 3178 | * to be killed. If any errors happen in the service's process, it will |
| 3179 | * automatically be restarted. |
| 3180 | * |
| 3181 | * <p>This function will throw {@link SecurityException} if you do not |
| 3182 | * have permission to start the given service. |
| 3183 | * |
| 3184 | * <div class="caution"> |
| 3185 | * <p><strong>Note:</strong> Each call to startService() |
| 3186 | * results in significant work done by the system to manage service |
| 3187 | * lifecycle surrounding the processing of the intent, which can take |
| 3188 | * multiple milliseconds of CPU time. Due to this cost, startService() |
| 3189 | * should not be used for frequent intent delivery to a service, and only |
| 3190 | * for scheduling significant work. Use {@link #bindService bound services} |
| 3191 | * for high frequency calls. |
| 3192 | * </p> |
| 3193 | * |
| 3194 | * Beginning with SDK Version {@link android.os.Build.VERSION_CODES#O}, |
| 3195 | * apps targeting SDK Version {@link android.os.Build.VERSION_CODES#O} |
| 3196 | * or higher are not allowed to start background services from the background. |
| 3197 | * See |
| 3198 | * <a href="{@docRoot}/about/versions/oreo/background"> |
| 3199 | * Background Execution Limits</a> |
| 3200 | * for more details. |
| 3201 | * |
| 3202 | * <p><strong>Note:</strong> |
| 3203 | * Beginning with SDK Version {@link android.os.Build.VERSION_CODES#S}, |
| 3204 | * apps targeting SDK Version {@link android.os.Build.VERSION_CODES#S} |
| 3205 | * or higher are not allowed to start foreground services from the background. |
| 3206 | * See |
| 3207 | * <a href="{@docRoot}/about/versions/12/behavior-changes-12"> |
| 3208 | * Behavior changes: Apps targeting Android 12 |
| 3209 | * </a> |
| 3210 | * for more details. |
| 3211 | * </div> |
| 3212 | * |
| 3213 | * @param service Identifies the service to be started. The Intent must be |
| 3214 | * fully explicit (supplying a component name). Additional values |
| 3215 | * may be included in the Intent extras to supply arguments along with |
| 3216 | * this specific start call. |
| 3217 | * |
| 3218 | * @return If the service is being started or is already running, the |
| 3219 | * {@link ComponentName} of the actual service that was started is |
| 3220 | * returned; else if the service does not exist null is returned. |
| 3221 | * |
| 3222 | * @throws SecurityException If the caller does not have permission to access the service |
| 3223 | * or the service can not be found. |
| 3224 | * @throws IllegalStateException |
| 3225 | * Before Android {@link android.os.Build.VERSION_CODES#S}, |
| 3226 | * if the application is in a state where the service |
| 3227 | * can not be started (such as not in the foreground in a state when services are allowed), |
| 3228 | * {@link IllegalStateException} was thrown. |
| 3229 | * @throws android.app.BackgroundServiceStartNotAllowedException |
| 3230 | * On Android {@link android.os.Build.VERSION_CODES#S} and later, |
| 3231 | * if the application is in a state where the service |
| 3232 | * can not be started (such as not in the foreground in a state when services are allowed), |
| 3233 | * {@link android.app.BackgroundServiceStartNotAllowedException} is thrown |
| 3234 | * This excemption extends {@link IllegalStateException}, so apps can |
| 3235 | * use {@code catch (IllegalStateException)} to catch both. |
| 3236 | * |
| 3237 | * @see #startForegroundService(Intent) |
| 3238 | * @see #stopService |
| 3239 | * @see #bindService |
| 3240 | */ |
| 3241 | @Nullable |
| 3242 | public abstract ComponentName startService(Intent service); |
| 3243 | |
| 3244 | /** |
| 3245 | * Similar to {@link #startService(Intent)}, but with an implicit promise that the |
| 3246 | * Service will call {@link android.app.Service#startForeground(int, android.app.Notification) |
| 3247 | * startForeground(int, android.app.Notification)} once it begins running. The service is given |
| 3248 | * an amount of time comparable to the ANR interval to do this, otherwise the system |
| 3249 | * will automatically stop the service and declare the app ANR. |
| 3250 | * |
| 3251 | * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used |
| 3252 | * at any time, regardless of whether the app hosting the service is in a foreground |
| 3253 | * state. |
| 3254 | * |
| 3255 | * <div class="caution"> |
| 3256 | * <p><strong>Note:</strong> |
| 3257 | * Beginning with SDK Version {@link android.os.Build.VERSION_CODES#S}, |
| 3258 | * apps targeting SDK Version {@link android.os.Build.VERSION_CODES#S} |
| 3259 | * or higher are not allowed to start foreground services from the background. |
| 3260 | * See |
| 3261 | * <a href="{@docRoot}/about/versions/12/behavior-changes-12"> |
| 3262 | * Behavior changes: Apps targeting Android 12 |
| 3263 | * </a> |
| 3264 | * for more details. |
| 3265 | * </div> |
| 3266 | * |
| 3267 | * @param service Identifies the service to be started. The Intent must be |
| 3268 | * fully explicit (supplying a component name). Additional values |
| 3269 | * may be included in the Intent extras to supply arguments along with |
| 3270 | * this specific start call. |
| 3271 | * |
| 3272 | * @return If the service is being started or is already running, the |
| 3273 | * {@link ComponentName} of the actual service that was started is |
| 3274 | * returned; else if the service does not exist null is returned. |
| 3275 | * |
| 3276 | * @throws SecurityException If the caller does not have permission to access the service |
| 3277 | * or the service can not be found. |
| 3278 | * |
| 3279 | * @throws android.app.ForegroundServiceStartNotAllowedException |
| 3280 | * If the caller app's targeting API is |
| 3281 | * {@link android.os.Build.VERSION_CODES#S} or later, and the foreground service is restricted |
| 3282 | * from start due to background restriction. |
| 3283 | * |
| 3284 | * @see #stopService |
| 3285 | * @see android.app.Service#startForeground(int, android.app.Notification) |
| 3286 | */ |
| 3287 | @Nullable |
| 3288 | public abstract ComponentName startForegroundService(Intent service); |
| 3289 | |
| 3290 | /** |
| 3291 | * @hide like {@link #startForegroundService(Intent)} but for a specific user. |
| 3292 | */ |
| 3293 | @SuppressWarnings("HiddenAbstractMethod") |
| 3294 | @Nullable |
| 3295 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) |
| 3296 | public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user); |
| 3297 | |
| 3298 | /** |
| 3299 | * Request that a given application service be stopped. If the service is |
| 3300 | * not running, nothing happens. Otherwise it is stopped. Note that calls |
| 3301 | * to startService() are not counted -- this stops the service no matter |
| 3302 | * how many times it was started. |
| 3303 | * |
| 3304 | * <p>Note that if a stopped service still has {@link ServiceConnection} |
| 3305 | * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will |
| 3306 | * not be destroyed until all of these bindings are removed. See |
| 3307 | * the {@link android.app.Service} documentation for more details on a |
| 3308 | * service's lifecycle. |
| 3309 | * |
| 3310 | * <p>This function will throw {@link SecurityException} if you do not |
| 3311 | * have permission to stop the given service. |
| 3312 | * |
| 3313 | * @param service Description of the service to be stopped. The Intent must be either |
| 3314 | * fully explicit (supplying a component name) or specify a specific package |
| 3315 | * name it is targeted to. |
| 3316 | * |
| 3317 | * @return If there is a service matching the given Intent that is already |
| 3318 | * running, then it is stopped and {@code true} is returned; else {@code false} is returned. |
| 3319 | * |
| 3320 | * @throws SecurityException If the caller does not have permission to access the service |
| 3321 | * or the service can not be found. |
| 3322 | * @throws IllegalStateException If the application is in a state where the service |
| 3323 | * can not be started (such as not in the foreground in a state when services are allowed). |
| 3324 | * |
| 3325 | * @see #startService |
| 3326 | */ |
| 3327 | public abstract boolean stopService(Intent service); |
| 3328 | |
| 3329 | /** |
| 3330 | * @hide like {@link #startService(Intent)} but for a specific user. |
| 3331 | */ |
| 3332 | @SuppressWarnings("HiddenAbstractMethod") |
| 3333 | @Nullable |
| 3334 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) |
| 3335 | @UnsupportedAppUsage |
| 3336 | public abstract ComponentName startServiceAsUser(Intent service, UserHandle user); |
| 3337 | |
| 3338 | /** |
| 3339 | * @hide like {@link #stopService(Intent)} but for a specific user. |
| 3340 | */ |
| 3341 | @SuppressWarnings("HiddenAbstractMethod") |
| 3342 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) |
| 3343 | public abstract boolean stopServiceAsUser(Intent service, UserHandle user); |
| 3344 | |
| 3345 | /** |
| 3346 | * Connect to an application service, creating it if needed. This defines |
| 3347 | * a dependency between your application and the service. The given |
| 3348 | * <var>conn</var> will receive the service object when it is created and be |
| 3349 | * told if it dies and restarts. The service will be considered required |
| 3350 | * by the system only for as long as the calling context exists. For |
| 3351 | * example, if this Context is an Activity that is stopped, the service will |
| 3352 | * not be required to continue running until the Activity is resumed. |
| 3353 | * |
| 3354 | * <p>If the service does not support binding, it may return {@code null} from |
| 3355 | * its {@link android.app.Service#onBind(Intent) onBind()} method. If it does, then |
| 3356 | * the ServiceConnection's |
| 3357 | * {@link ServiceConnection#onNullBinding(ComponentName) onNullBinding()} method |
| 3358 | * will be invoked instead of |
| 3359 | * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder) onServiceConnected()}. |
| 3360 | * |
| 3361 | * <p>This method will throw {@link SecurityException} if the calling app does not |
| 3362 | * have permission to bind to the given service. |
| 3363 | * |
| 3364 | * <p class="note">Note: this method <em>cannot be called from a |
| 3365 | * {@link BroadcastReceiver} component</em>. A pattern you can use to |
| 3366 | * communicate from a BroadcastReceiver to a Service is to call |
| 3367 | * {@link #startService} with the arguments containing the command to be |
| 3368 | * sent, with the service calling its |
| 3369 | * {@link android.app.Service#stopSelf(int)} method when done executing |
| 3370 | * that command. See the API demo App/Service/Service Start Arguments |
| 3371 | * Controller for an illustration of this. It is okay, however, to use |
| 3372 | * this method from a BroadcastReceiver that has been registered with |
| 3373 | * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver |
| 3374 | * is tied to another object (the one that registered it).</p> |
| 3375 | * |
| 3376 | * @param service Identifies the service to connect to. The Intent must |
| 3377 | * specify an explicit component name. |
| 3378 | * @param conn Receives information as the service is started and stopped. |
| 3379 | * This must be a valid ServiceConnection object; it must not be null. |
| 3380 | * @param flags Operation options for the binding. May be 0, |
| 3381 | * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND}, |
| 3382 | * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT}, |
| 3383 | * {@link #BIND_ALLOW_OOM_MANAGEMENT}, {@link #BIND_WAIVE_PRIORITY}. |
| 3384 | * {@link #BIND_IMPORTANT}, {@link #BIND_ADJUST_WITH_ACTIVITY}, |
| 3385 | * {@link #BIND_NOT_PERCEPTIBLE}, or {@link #BIND_INCLUDE_CAPABILITIES}. |
| 3386 | * @return {@code true} if the system is in the process of bringing up a |
| 3387 | * service that your client has permission to bind to; {@code false} |
| 3388 | * if the system couldn't find the service or if your client doesn't |
| 3389 | * have permission to bind to it. If this value is {@code true}, you |
| 3390 | * should later call {@link #unbindService} to release the |
| 3391 | * connection. |
| 3392 | * |
| 3393 | * @throws SecurityException If the caller does not have permission to access the service |
| 3394 | * or the service can not be found. |
| 3395 | * |
| 3396 | * @see #unbindService |
| 3397 | * @see #startService |
| 3398 | * @see #BIND_AUTO_CREATE |
| 3399 | * @see #BIND_DEBUG_UNBIND |
| 3400 | * @see #BIND_NOT_FOREGROUND |
| 3401 | * @see #BIND_ABOVE_CLIENT |
| 3402 | * @see #BIND_ALLOW_OOM_MANAGEMENT |
| 3403 | * @see #BIND_WAIVE_PRIORITY |
| 3404 | * @see #BIND_IMPORTANT |
| 3405 | * @see #BIND_ADJUST_WITH_ACTIVITY |
| 3406 | * @see #BIND_NOT_PERCEPTIBLE |
| 3407 | * @see #BIND_INCLUDE_CAPABILITIES |
| 3408 | */ |
| 3409 | public abstract boolean bindService(@RequiresPermission Intent service, |
| 3410 | @NonNull ServiceConnection conn, @BindServiceFlags int flags); |
| 3411 | |
| 3412 | /** |
| 3413 | * Same as {@link #bindService(Intent, ServiceConnection, int)} with executor to control |
| 3414 | * ServiceConnection callbacks. |
| 3415 | * @param executor Callbacks on ServiceConnection will be called on executor. Must use same |
| 3416 | * instance for the same instance of ServiceConnection. |
| 3417 | */ |
| 3418 | public boolean bindService(@RequiresPermission @NonNull Intent service, |
| 3419 | @BindServiceFlags int flags, @NonNull @CallbackExecutor Executor executor, |
| 3420 | @NonNull ServiceConnection conn) { |
| 3421 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 3422 | } |
| 3423 | |
| 3424 | /** |
| 3425 | * Variation of {@link #bindService} that, in the specific case of isolated |
| 3426 | * services, allows the caller to generate multiple instances of a service |
| 3427 | * from a single component declaration. In other words, you can use this to bind |
| 3428 | * to a service that has specified {@link android.R.attr#isolatedProcess} and, in |
| 3429 | * addition to the existing behavior of running in an isolated process, you can |
| 3430 | * also through the arguments here have the system bring up multiple concurrent |
| 3431 | * processes hosting their own instances of that service. The <var>instanceName</var> |
| 3432 | * you provide here identifies the different instances, and you can use |
| 3433 | * {@link #updateServiceGroup(ServiceConnection, int, int)} to tell the system how it |
| 3434 | * should manage each of these instances. |
| 3435 | * |
| 3436 | * @param service Identifies the service to connect to. The Intent must |
| 3437 | * specify an explicit component name. |
| 3438 | * @param flags Operation options for the binding as per {@link #bindService}. |
| 3439 | * @param instanceName Unique identifier for the service instance. Each unique |
| 3440 | * name here will result in a different service instance being created. Identifiers |
| 3441 | * must only contain ASCII letters, digits, underscores, and periods. |
| 3442 | * @return Returns success of binding as per {@link #bindService}. |
| 3443 | * @param executor Callbacks on ServiceConnection will be called on executor. |
| 3444 | * Must use same instance for the same instance of ServiceConnection. |
| 3445 | * @param conn Receives information as the service is started and stopped. |
| 3446 | * This must be a valid ServiceConnection object; it must not be null. |
| 3447 | * |
| 3448 | * @throws SecurityException If the caller does not have permission to access the service |
| 3449 | * @throws IllegalArgumentException If the instanceName is invalid. |
| 3450 | * |
| 3451 | * @see #bindService |
| 3452 | * @see #updateServiceGroup |
| 3453 | * @see android.R.attr#isolatedProcess |
| 3454 | */ |
| 3455 | public boolean bindIsolatedService(@RequiresPermission @NonNull Intent service, |
| 3456 | @BindServiceFlags int flags, @NonNull String instanceName, |
| 3457 | @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn) { |
| 3458 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 3459 | } |
| 3460 | |
| 3461 | /** |
| 3462 | * Binds to a service in the given {@code user} in the same manner as |
| 3463 | * {@link #bindService(Intent, ServiceConnection, int)}. |
| 3464 | * |
| 3465 | * <p>If the given {@code user} is in the same profile group and the target package is the |
| 3466 | * same as the caller, {@code android.Manifest.permission.INTERACT_ACROSS_PROFILES} is |
| 3467 | * sufficient. Otherwise, requires {@code android.Manifest.permission.INTERACT_ACROSS_USERS} |
| 3468 | * for interacting with other users. |
| 3469 | * |
| 3470 | * @param service Identifies the service to connect to. The Intent must |
| 3471 | * specify an explicit component name. |
| 3472 | * @param conn Receives information as the service is started and stopped. |
| 3473 | * This must be a valid ServiceConnection object; it must not be null. |
| 3474 | * @param flags Operation options for the binding. May be 0, |
| 3475 | * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND}, |
| 3476 | * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT}, |
| 3477 | * {@link #BIND_ALLOW_OOM_MANAGEMENT}, {@link #BIND_WAIVE_PRIORITY}. |
| 3478 | * {@link #BIND_IMPORTANT}, or |
| 3479 | * {@link #BIND_ADJUST_WITH_ACTIVITY}. |
| 3480 | * @return {@code true} if the system is in the process of bringing up a |
| 3481 | * service that your client has permission to bind to; {@code false} |
| 3482 | * if the system couldn't find the service. If this value is {@code true}, you |
| 3483 | * should later call {@link #unbindService} to release the |
| 3484 | * connection. |
| 3485 | * |
| 3486 | * @throws SecurityException if the client does not have the required permission to bind. |
| 3487 | */ |
| 3488 | @SuppressWarnings("unused") |
| 3489 | @RequiresPermission(anyOf = { |
| 3490 | android.Manifest.permission.INTERACT_ACROSS_USERS, |
| 3491 | android.Manifest.permission.INTERACT_ACROSS_PROFILES |
| 3492 | }) |
| 3493 | public boolean bindServiceAsUser( |
| 3494 | @NonNull @RequiresPermission Intent service, @NonNull ServiceConnection conn, int flags, |
| 3495 | @NonNull UserHandle user) { |
| 3496 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 3497 | } |
| 3498 | |
| 3499 | /** |
| 3500 | * Same as {@link #bindServiceAsUser(Intent, ServiceConnection, int, UserHandle)}, but with an |
| 3501 | * explicit non-null Handler to run the ServiceConnection callbacks on. |
| 3502 | * |
| 3503 | * @hide |
| 3504 | */ |
| 3505 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) |
| 3506 | @UnsupportedAppUsage(trackingBug = 136728678) |
| 3507 | public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags, |
| 3508 | Handler handler, UserHandle user) { |
| 3509 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 3510 | } |
| 3511 | |
| 3512 | /** |
| 3513 | * For a service previously bound with {@link #bindService} or a related method, change |
| 3514 | * how the system manages that service's process in relation to other processes. This |
| 3515 | * doesn't modify the original bind flags that were passed in when binding, but adjusts |
| 3516 | * how the process will be managed in some cases based on those flags. Currently only |
| 3517 | * works on isolated processes (will be ignored for non-isolated processes). |
| 3518 | * |
| 3519 | * <p>Note that this call does not take immediate effect, but will be applied the next |
| 3520 | * time the impacted process is adjusted for some other reason. Typically you would |
| 3521 | * call this before then calling a new {@link #bindIsolatedService} on the service |
| 3522 | * of interest, with that binding causing the process to be shuffled accordingly.</p> |
| 3523 | * |
| 3524 | * @param conn The connection interface previously supplied to bindService(). This |
| 3525 | * parameter must not be null. |
| 3526 | * @param group A group to put this connection's process in. Upon calling here, this |
| 3527 | * will override any previous group that was set for that process. The group |
| 3528 | * tells the system about processes that are logically grouped together, so |
| 3529 | * should be managed as one unit of importance (such as when being considered |
| 3530 | * a recently used app). All processes in the same app with the same group |
| 3531 | * are considered to be related. Supplying 0 reverts to the default behavior |
| 3532 | * of not grouping. |
| 3533 | * @param importance Additional importance of the processes within a group. Upon calling |
| 3534 | * here, this will override any previous importance that was set for that |
| 3535 | * process. The most important process is 0, and higher values are |
| 3536 | * successively less important. You can view this as describing how |
| 3537 | * to order the processes in an array, with the processes at the end of |
| 3538 | * the array being the least important. This value has no meaning besides |
| 3539 | * indicating how processes should be ordered in that array one after the |
| 3540 | * other. This provides a way to fine-tune the system's process killing, |
| 3541 | * guiding it to kill processes at the end of the array first. |
| 3542 | * |
| 3543 | * @see #bindIsolatedService |
| 3544 | */ |
| 3545 | public void updateServiceGroup(@NonNull ServiceConnection conn, int group, |
| 3546 | int importance) { |
| 3547 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 3548 | } |
| 3549 | |
| 3550 | /** |
| 3551 | * Disconnect from an application service. You will no longer receive |
| 3552 | * calls as the service is restarted, and the service is now allowed to |
| 3553 | * stop at any time. |
| 3554 | * |
| 3555 | * @param conn The connection interface previously supplied to |
| 3556 | * bindService(). This parameter must not be null. |
| 3557 | * |
| 3558 | * @see #bindService |
| 3559 | */ |
| 3560 | public abstract void unbindService(@NonNull ServiceConnection conn); |
| 3561 | |
| 3562 | /** |
| 3563 | * Start executing an {@link android.app.Instrumentation} class. The given |
| 3564 | * Instrumentation component will be run by killing its target application |
| 3565 | * (if currently running), starting the target process, instantiating the |
| 3566 | * instrumentation component, and then letting it drive the application. |
| 3567 | * |
| 3568 | * <p>This function is not synchronous -- it returns as soon as the |
| 3569 | * instrumentation has started and while it is running. |
| 3570 | * |
| 3571 | * <p>Instrumentation is normally only allowed to run against a package |
| 3572 | * that is either unsigned or signed with a signature that the |
| 3573 | * the instrumentation package is also signed with (ensuring the target |
| 3574 | * trusts the instrumentation). |
| 3575 | * |
| 3576 | * @param className Name of the Instrumentation component to be run. |
| 3577 | * @param profileFile Optional path to write profiling data as the |
| 3578 | * instrumentation runs, or null for no profiling. |
| 3579 | * @param arguments Additional optional arguments to pass to the |
| 3580 | * instrumentation, or null. |
| 3581 | * |
| 3582 | * @return {@code true} if the instrumentation was successfully started, |
| 3583 | * else {@code false} if it could not be found. |
| 3584 | */ |
| 3585 | public abstract boolean startInstrumentation(@NonNull ComponentName className, |
| 3586 | @Nullable String profileFile, @Nullable Bundle arguments); |
| 3587 | |
| 3588 | /** @hide */ |
| 3589 | @StringDef(suffix = { "_SERVICE" }, value = { |
| 3590 | POWER_SERVICE, |
| 3591 | //@hide: POWER_STATS_SERVICE, |
| 3592 | WINDOW_SERVICE, |
| 3593 | LAYOUT_INFLATER_SERVICE, |
| 3594 | ACCOUNT_SERVICE, |
| 3595 | ACTIVITY_SERVICE, |
| 3596 | ALARM_SERVICE, |
| 3597 | NOTIFICATION_SERVICE, |
| 3598 | ACCESSIBILITY_SERVICE, |
| 3599 | CAPTIONING_SERVICE, |
| 3600 | KEYGUARD_SERVICE, |
| 3601 | LOCATION_SERVICE, |
| 3602 | //@hide: COUNTRY_DETECTOR, |
| 3603 | SEARCH_SERVICE, |
| 3604 | SENSOR_SERVICE, |
| 3605 | SENSOR_PRIVACY_SERVICE, |
| 3606 | STORAGE_SERVICE, |
| 3607 | STORAGE_STATS_SERVICE, |
| 3608 | WALLPAPER_SERVICE, |
| 3609 | TIME_ZONE_RULES_MANAGER_SERVICE, |
| 3610 | VIBRATOR_MANAGER_SERVICE, |
| 3611 | VIBRATOR_SERVICE, |
| 3612 | //@hide: STATUS_BAR_SERVICE, |
| 3613 | CONNECTIVITY_SERVICE, |
| 3614 | PAC_PROXY_SERVICE, |
| 3615 | VCN_MANAGEMENT_SERVICE, |
| 3616 | //@hide: IP_MEMORY_STORE_SERVICE, |
| 3617 | IPSEC_SERVICE, |
| 3618 | VPN_MANAGEMENT_SERVICE, |
| 3619 | TEST_NETWORK_SERVICE, |
| 3620 | //@hide: UPDATE_LOCK_SERVICE, |
| 3621 | //@hide: NETWORKMANAGEMENT_SERVICE, |
| 3622 | NETWORK_STATS_SERVICE, |
| 3623 | //@hide: NETWORK_POLICY_SERVICE, |
| 3624 | WIFI_SERVICE, |
| 3625 | WIFI_AWARE_SERVICE, |
| 3626 | WIFI_P2P_SERVICE, |
| 3627 | WIFI_SCANNING_SERVICE, |
| 3628 | //@hide: LOWPAN_SERVICE, |
| 3629 | //@hide: WIFI_RTT_SERVICE, |
| 3630 | //@hide: ETHERNET_SERVICE, |
| 3631 | WIFI_RTT_RANGING_SERVICE, |
| 3632 | NSD_SERVICE, |
| 3633 | AUDIO_SERVICE, |
| 3634 | AUTH_SERVICE, |
| 3635 | FINGERPRINT_SERVICE, |
| 3636 | //@hide: FACE_SERVICE, |
| 3637 | BIOMETRIC_SERVICE, |
| 3638 | MEDIA_ROUTER_SERVICE, |
| 3639 | TELEPHONY_SERVICE, |
| 3640 | TELEPHONY_SUBSCRIPTION_SERVICE, |
| 3641 | CARRIER_CONFIG_SERVICE, |
| 3642 | EUICC_SERVICE, |
| 3643 | //@hide: MMS_SERVICE, |
| 3644 | TELECOM_SERVICE, |
| 3645 | CLIPBOARD_SERVICE, |
| 3646 | INPUT_METHOD_SERVICE, |
| 3647 | TEXT_SERVICES_MANAGER_SERVICE, |
| 3648 | TEXT_CLASSIFICATION_SERVICE, |
| 3649 | APPWIDGET_SERVICE, |
| 3650 | //@hide: VOICE_INTERACTION_MANAGER_SERVICE, |
| 3651 | //@hide: BACKUP_SERVICE, |
| 3652 | REBOOT_READINESS_SERVICE, |
| 3653 | ROLLBACK_SERVICE, |
| 3654 | DROPBOX_SERVICE, |
| 3655 | //@hide: DEVICE_IDLE_CONTROLLER, |
| 3656 | //@hide: POWER_WHITELIST_MANAGER, |
| 3657 | DEVICE_POLICY_SERVICE, |
| 3658 | UI_MODE_SERVICE, |
| 3659 | DOWNLOAD_SERVICE, |
| 3660 | NFC_SERVICE, |
| 3661 | BLUETOOTH_SERVICE, |
| 3662 | //@hide: SIP_SERVICE, |
| 3663 | USB_SERVICE, |
| 3664 | LAUNCHER_APPS_SERVICE, |
| 3665 | //@hide: SERIAL_SERVICE, |
| 3666 | //@hide: HDMI_CONTROL_SERVICE, |
| 3667 | INPUT_SERVICE, |
| 3668 | DISPLAY_SERVICE, |
| 3669 | //@hide COLOR_DISPLAY_SERVICE, |
| 3670 | USER_SERVICE, |
| 3671 | RESTRICTIONS_SERVICE, |
| 3672 | APP_OPS_SERVICE, |
| 3673 | ROLE_SERVICE, |
| 3674 | //@hide ROLE_CONTROLLER_SERVICE, |
| 3675 | CAMERA_SERVICE, |
| 3676 | //@hide: PLATFORM_COMPAT_SERVICE, |
| 3677 | //@hide: PLATFORM_COMPAT_NATIVE_SERVICE, |
| 3678 | PRINT_SERVICE, |
| 3679 | CONSUMER_IR_SERVICE, |
| 3680 | //@hide: TRUST_SERVICE, |
| 3681 | TV_INPUT_SERVICE, |
| 3682 | //@hide: TV_TUNER_RESOURCE_MGR_SERVICE, |
| 3683 | //@hide: NETWORK_SCORE_SERVICE, |
| 3684 | USAGE_STATS_SERVICE, |
| 3685 | MEDIA_SESSION_SERVICE, |
| 3686 | MEDIA_COMMUNICATION_SERVICE, |
| 3687 | BATTERY_SERVICE, |
| 3688 | JOB_SCHEDULER_SERVICE, |
| 3689 | //@hide: PERSISTENT_DATA_BLOCK_SERVICE, |
| 3690 | //@hide: OEM_LOCK_SERVICE, |
| 3691 | MEDIA_PROJECTION_SERVICE, |
| 3692 | MIDI_SERVICE, |
| 3693 | RADIO_SERVICE, |
| 3694 | HARDWARE_PROPERTIES_SERVICE, |
| 3695 | //@hide: SOUND_TRIGGER_SERVICE, |
| 3696 | SHORTCUT_SERVICE, |
| 3697 | //@hide: CONTEXTHUB_SERVICE, |
| 3698 | SYSTEM_HEALTH_SERVICE, |
| 3699 | //@hide: INCIDENT_SERVICE, |
| 3700 | //@hide: INCIDENT_COMPANION_SERVICE, |
| 3701 | //@hide: STATS_COMPANION_SERVICE, |
| 3702 | COMPANION_DEVICE_SERVICE, |
| 3703 | CROSS_PROFILE_APPS_SERVICE, |
| 3704 | //@hide: SYSTEM_UPDATE_SERVICE, |
| 3705 | //@hide: TIME_DETECTOR_SERVICE, |
| 3706 | //@hide: TIME_ZONE_DETECTOR_SERVICE, |
| 3707 | PERMISSION_SERVICE, |
| 3708 | LIGHTS_SERVICE, |
| 3709 | //@hide: PEOPLE_SERVICE, |
| 3710 | //@hide: DEVICE_STATE_SERVICE, |
| 3711 | //@hide: SPEECH_RECOGNITION_SERVICE, |
| 3712 | UWB_SERVICE, |
| 3713 | MEDIA_METRICS_SERVICE, |
| 3714 | }) |
| 3715 | @Retention(RetentionPolicy.SOURCE) |
| 3716 | public @interface ServiceName {} |
| 3717 | |
| 3718 | /** |
| 3719 | * Return the handle to a system-level service by name. The class of the |
| 3720 | * returned object varies by the requested name. Currently available names |
| 3721 | * are: |
| 3722 | * |
| 3723 | * <dl> |
| 3724 | * <dt> {@link #WINDOW_SERVICE} ("window") |
| 3725 | * <dd> The top-level window manager in which you can place custom |
| 3726 | * windows. The returned object is a {@link android.view.WindowManager}. Must only be obtained |
| 3727 | * from a visual context such as Activity or a Context created with |
| 3728 | * {@link #createWindowContext(int, Bundle)}, which are adjusted to the configuration and |
| 3729 | * visual bounds of an area on screen. |
| 3730 | * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater") |
| 3731 | * <dd> A {@link android.view.LayoutInflater} for inflating layout resources |
| 3732 | * in this context. Must only be obtained from a visual context such as Activity or a Context |
| 3733 | * created with {@link #createWindowContext(int, Bundle)}, which are adjusted to the |
| 3734 | * configuration and visual bounds of an area on screen. |
| 3735 | * <dt> {@link #ACTIVITY_SERVICE} ("activity") |
| 3736 | * <dd> A {@link android.app.ActivityManager} for interacting with the |
| 3737 | * global activity state of the system. |
| 3738 | * <dt> {@link #WALLPAPER_SERVICE} ("wallpaper") |
| 3739 | * <dd> A {@link android.service.wallpaper.WallpaperService} for accessing wallpapers in this |
| 3740 | * context. Must only be obtained from a visual context such as Activity or a Context created |
| 3741 | * with {@link #createWindowContext(int, Bundle)}, which are adjusted to the configuration and |
| 3742 | * visual bounds of an area on screen. |
| 3743 | * <dt> {@link #POWER_SERVICE} ("power") |
| 3744 | * <dd> A {@link android.os.PowerManager} for controlling power |
| 3745 | * management. |
| 3746 | * <dt> {@link #ALARM_SERVICE} ("alarm") |
| 3747 | * <dd> A {@link android.app.AlarmManager} for receiving intents at the |
| 3748 | * time of your choosing. |
| 3749 | * <dt> {@link #NOTIFICATION_SERVICE} ("notification") |
| 3750 | * <dd> A {@link android.app.NotificationManager} for informing the user |
| 3751 | * of background events. |
| 3752 | * <dt> {@link #KEYGUARD_SERVICE} ("keyguard") |
| 3753 | * <dd> A {@link android.app.KeyguardManager} for controlling keyguard. |
| 3754 | * <dt> {@link #LOCATION_SERVICE} ("location") |
| 3755 | * <dd> A {@link android.location.LocationManager} for controlling location |
| 3756 | * (e.g., GPS) updates. |
| 3757 | * <dt> {@link #SEARCH_SERVICE} ("search") |
| 3758 | * <dd> A {@link android.app.SearchManager} for handling search. |
| 3759 | * <dt> {@link #VIBRATOR_MANAGER_SERVICE} ("vibrator_manager") |
| 3760 | * <dd> A {@link android.os.VibratorManager} for accessing the device vibrators, interacting |
| 3761 | * with individual ones and playing synchronized effects on multiple vibrators. |
| 3762 | * <dt> {@link #VIBRATOR_SERVICE} ("vibrator") |
| 3763 | * <dd> A {@link android.os.Vibrator} for interacting with the vibrator hardware. |
| 3764 | * <dt> {@link #CONNECTIVITY_SERVICE} ("connectivity") |
| 3765 | * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for |
| 3766 | * handling management of network connections. |
| 3767 | * <dt> {@link #IPSEC_SERVICE} ("ipsec") |
| 3768 | * <dd> A {@link android.net.IpSecManager IpSecManager} for managing IPSec on |
| 3769 | * sockets and networks. |
| 3770 | * <dt> {@link #WIFI_SERVICE} ("wifi") |
| 3771 | * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi |
| 3772 | * connectivity. On releases before NYC, it should only be obtained from an application |
| 3773 | * context, and not from any other derived context to avoid memory leaks within the calling |
| 3774 | * process. |
| 3775 | * <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware") |
| 3776 | * <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of |
| 3777 | * Wi-Fi Aware discovery and connectivity. |
| 3778 | * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p") |
| 3779 | * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of |
| 3780 | * Wi-Fi Direct connectivity. |
| 3781 | * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method") |
| 3782 | * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager} |
| 3783 | * for management of input methods. |
| 3784 | * <dt> {@link #UI_MODE_SERVICE} ("uimode") |
| 3785 | * <dd> An {@link android.app.UiModeManager} for controlling UI modes. |
| 3786 | * <dt> {@link #DOWNLOAD_SERVICE} ("download") |
| 3787 | * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads |
| 3788 | * <dt> {@link #BATTERY_SERVICE} ("batterymanager") |
| 3789 | * <dd> A {@link android.os.BatteryManager} for managing battery state |
| 3790 | * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager") |
| 3791 | * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks |
| 3792 | * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats") |
| 3793 | * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network |
| 3794 | * usage statistics. |
| 3795 | * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties") |
| 3796 | * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties. |
| 3797 | * <dt> {@link #DOMAIN_VERIFICATION_SERVICE} ("domain_verification") |
| 3798 | * <dd> A {@link android.content.pm.verify.domain.DomainVerificationManager} for accessing |
| 3799 | * web domain approval state. |
| 3800 | * </dl> |
| 3801 | * |
| 3802 | * <p>Note: System services obtained via this API may be closely associated with |
| 3803 | * the Context in which they are obtained from. In general, do not share the |
| 3804 | * service objects between various different contexts (Activities, Applications, |
| 3805 | * Services, Providers, etc.) |
| 3806 | * |
| 3807 | * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true, |
| 3808 | * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE}, |
| 3809 | * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE}, |
| 3810 | * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE}, |
| 3811 | * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will |
| 3812 | * return <code>null</code>. Generally, if you are running as an instant app you should always |
| 3813 | * check whether the result of this method is {@code null}. |
| 3814 | * |
| 3815 | * <p>Note: When implementing this method, keep in mind that new services can be added on newer |
| 3816 | * Android releases, so if you're looking for just the explicit names mentioned above, make sure |
| 3817 | * to return {@code null} when you don't recognize the name — if you throw a |
| 3818 | * {@link RuntimeException} exception instead, you're app might break on new Android releases. |
| 3819 | * |
| 3820 | * @param name The name of the desired service. |
| 3821 | * |
| 3822 | * @return The service or {@code null} if the name does not exist. |
| 3823 | * |
| 3824 | * @see #WINDOW_SERVICE |
| 3825 | * @see android.view.WindowManager |
| 3826 | * @see #LAYOUT_INFLATER_SERVICE |
| 3827 | * @see android.view.LayoutInflater |
| 3828 | * @see #ACTIVITY_SERVICE |
| 3829 | * @see android.app.ActivityManager |
| 3830 | * @see #POWER_SERVICE |
| 3831 | * @see android.os.PowerManager |
| 3832 | * @see #ALARM_SERVICE |
| 3833 | * @see android.app.AlarmManager |
| 3834 | * @see #NOTIFICATION_SERVICE |
| 3835 | * @see android.app.NotificationManager |
| 3836 | * @see #KEYGUARD_SERVICE |
| 3837 | * @see android.app.KeyguardManager |
| 3838 | * @see #LOCATION_SERVICE |
| 3839 | * @see android.location.LocationManager |
| 3840 | * @see #SEARCH_SERVICE |
| 3841 | * @see android.app.SearchManager |
| 3842 | * @see #SENSOR_SERVICE |
| 3843 | * @see android.hardware.SensorManager |
| 3844 | * @see #STORAGE_SERVICE |
| 3845 | * @see android.os.storage.StorageManager |
| 3846 | * @see #VIBRATOR_MANAGER_SERVICE |
| 3847 | * @see android.os.VibratorManager |
| 3848 | * @see #VIBRATOR_SERVICE |
| 3849 | * @see android.os.Vibrator |
| 3850 | * @see #CONNECTIVITY_SERVICE |
| 3851 | * @see android.net.ConnectivityManager |
| 3852 | * @see #WIFI_SERVICE |
| 3853 | * @see android.net.wifi.WifiManager |
| 3854 | * @see #AUDIO_SERVICE |
| 3855 | * @see android.media.AudioManager |
| 3856 | * @see #MEDIA_ROUTER_SERVICE |
| 3857 | * @see android.media.MediaRouter |
| 3858 | * @see #TELEPHONY_SERVICE |
| 3859 | * @see android.telephony.TelephonyManager |
| 3860 | * @see #TELEPHONY_SUBSCRIPTION_SERVICE |
| 3861 | * @see android.telephony.SubscriptionManager |
| 3862 | * @see #CARRIER_CONFIG_SERVICE |
| 3863 | * @see android.telephony.CarrierConfigManager |
| 3864 | * @see #EUICC_SERVICE |
| 3865 | * @see android.telephony.euicc.EuiccManager |
| 3866 | * @see android.telephony.MmsManager |
| 3867 | * @see #INPUT_METHOD_SERVICE |
| 3868 | * @see android.view.inputmethod.InputMethodManager |
| 3869 | * @see #UI_MODE_SERVICE |
| 3870 | * @see android.app.UiModeManager |
| 3871 | * @see #DOWNLOAD_SERVICE |
| 3872 | * @see android.app.DownloadManager |
| 3873 | * @see #BATTERY_SERVICE |
| 3874 | * @see android.os.BatteryManager |
| 3875 | * @see #JOB_SCHEDULER_SERVICE |
| 3876 | * @see android.app.job.JobScheduler |
| 3877 | * @see #NETWORK_STATS_SERVICE |
| 3878 | * @see android.app.usage.NetworkStatsManager |
| 3879 | * @see android.os.HardwarePropertiesManager |
| 3880 | * @see #HARDWARE_PROPERTIES_SERVICE |
| 3881 | * @see #DOMAIN_VERIFICATION_SERVICE |
| 3882 | * @see android.content.pm.verify.domain.DomainVerificationManager |
| 3883 | */ |
| 3884 | public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name); |
| 3885 | |
| 3886 | /** |
| 3887 | * Return the handle to a system-level service by class. |
| 3888 | * <p> |
| 3889 | * Currently available classes are: |
| 3890 | * {@link android.view.WindowManager}, {@link android.view.LayoutInflater}, |
| 3891 | * {@link android.app.ActivityManager}, {@link android.os.PowerManager}, |
| 3892 | * {@link android.app.AlarmManager}, {@link android.app.NotificationManager}, |
| 3893 | * {@link android.app.KeyguardManager}, {@link android.location.LocationManager}, |
| 3894 | * {@link android.app.SearchManager}, {@link android.os.Vibrator}, |
| 3895 | * {@link android.net.ConnectivityManager}, |
| 3896 | * {@link android.net.wifi.WifiManager}, |
| 3897 | * {@link android.media.AudioManager}, {@link android.media.MediaRouter}, |
| 3898 | * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager}, |
| 3899 | * {@link android.view.inputmethod.InputMethodManager}, |
| 3900 | * {@link android.app.UiModeManager}, {@link android.app.DownloadManager}, |
| 3901 | * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler}, |
| 3902 | * {@link android.app.usage.NetworkStatsManager}, |
| 3903 | * {@link android.content.pm.verify.domain.DomainVerificationManager}. |
| 3904 | * </p> |
| 3905 | * |
| 3906 | * <p> |
| 3907 | * Note: System services obtained via this API may be closely associated with |
| 3908 | * the Context in which they are obtained from. In general, do not share the |
| 3909 | * service objects between various different contexts (Activities, Applications, |
| 3910 | * Services, Providers, etc.) |
| 3911 | * </p> |
| 3912 | * |
| 3913 | * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true, |
| 3914 | * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE}, |
| 3915 | * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE}, |
| 3916 | * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE}, |
| 3917 | * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will |
| 3918 | * return {@code null}. Generally, if you are running as an instant app you should always |
| 3919 | * check whether the result of this method is {@code null}. |
| 3920 | * </p> |
| 3921 | * |
| 3922 | * @param serviceClass The class of the desired service. |
| 3923 | * @return The service or {@code null} if the class is not a supported system service. Note: |
| 3924 | * <b>never</b> throw a {@link RuntimeException} if the name is not supported. |
| 3925 | */ |
| 3926 | @SuppressWarnings("unchecked") |
| 3927 | public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) { |
| 3928 | // Because subclasses may override getSystemService(String) we cannot |
| 3929 | // perform a lookup by class alone. We must first map the class to its |
| 3930 | // service name then invoke the string-based method. |
| 3931 | String serviceName = getSystemServiceName(serviceClass); |
| 3932 | return serviceName != null ? (T)getSystemService(serviceName) : null; |
| 3933 | } |
| 3934 | |
| 3935 | /** |
| 3936 | * Gets the name of the system-level service that is represented by the specified class. |
| 3937 | * |
| 3938 | * @param serviceClass The class of the desired service. |
| 3939 | * @return The service name or null if the class is not a supported system service. |
| 3940 | */ |
| 3941 | public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass); |
| 3942 | |
| 3943 | /** |
| 3944 | * Use with {@link #getSystemService(String)} to retrieve a |
| 3945 | * {@link android.os.PowerManager} for controlling power management, |
| 3946 | * including "wake locks," which let you keep the device on while |
| 3947 | * you're running long tasks. |
| 3948 | */ |
| 3949 | public static final String POWER_SERVICE = "power"; |
| 3950 | |
| 3951 | /** |
| 3952 | * Use with {@link #getSystemService(String)} to retrieve a |
| 3953 | * {@link android.os.PowerStatsService} for accessing power stats |
| 3954 | * service. |
| 3955 | * |
| 3956 | * @see #getSystemService(String) |
| 3957 | * @hide |
| 3958 | */ |
| 3959 | public static final String POWER_STATS_SERVICE = "powerstats"; |
| 3960 | |
| 3961 | /** |
| 3962 | * Use with {@link #getSystemService(String)} to retrieve a |
| 3963 | * {@link android.os.RecoverySystem} for accessing the recovery system |
| 3964 | * service. |
| 3965 | * |
| 3966 | * @see #getSystemService(String) |
| 3967 | * @hide |
| 3968 | */ |
| 3969 | public static final String RECOVERY_SERVICE = "recovery"; |
| 3970 | |
| 3971 | /** |
| 3972 | * Use with {@link #getSystemService(String)} to retrieve a |
| 3973 | * {@link android.os.SystemUpdateManager} for accessing the system update |
| 3974 | * manager service. |
| 3975 | * |
| 3976 | * @see #getSystemService(String) |
| 3977 | * @hide |
| 3978 | */ |
| 3979 | @SystemApi |
| 3980 | public static final String SYSTEM_UPDATE_SERVICE = "system_update"; |
| 3981 | |
| 3982 | /** |
| 3983 | * Use with {@link #getSystemService(String)} to retrieve a |
| 3984 | * {@link android.view.WindowManager} for accessing the system's window |
| 3985 | * manager. |
| 3986 | * |
| 3987 | * @see #getSystemService(String) |
| 3988 | * @see android.view.WindowManager |
| 3989 | */ |
| 3990 | @UiContext |
| 3991 | public static final String WINDOW_SERVICE = "window"; |
| 3992 | |
| 3993 | /** |
| 3994 | * Use with {@link #getSystemService(String)} to retrieve a |
| 3995 | * {@link android.view.LayoutInflater} for inflating layout resources in this |
| 3996 | * context. |
| 3997 | * |
| 3998 | * @see #getSystemService(String) |
| 3999 | * @see android.view.LayoutInflater |
| 4000 | */ |
| 4001 | @UiContext |
| 4002 | public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater"; |
| 4003 | |
| 4004 | /** |
| 4005 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4006 | * {@link android.accounts.AccountManager} for receiving intents at a |
| 4007 | * time of your choosing. |
| 4008 | * |
| 4009 | * @see #getSystemService(String) |
| 4010 | * @see android.accounts.AccountManager |
| 4011 | */ |
| 4012 | public static final String ACCOUNT_SERVICE = "account"; |
| 4013 | |
| 4014 | /** |
| 4015 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4016 | * {@link android.app.ActivityManager} for interacting with the global |
| 4017 | * system state. |
| 4018 | * |
| 4019 | * @see #getSystemService(String) |
| 4020 | * @see android.app.ActivityManager |
| 4021 | */ |
| 4022 | public static final String ACTIVITY_SERVICE = "activity"; |
| 4023 | |
| 4024 | /** |
| 4025 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4026 | * {@link android.app.ActivityTaskManager} for interacting with the global system state. |
| 4027 | * |
| 4028 | * @see #getSystemService(String) |
| 4029 | * @see android.app.ActivityTaskManager |
| 4030 | * @hide |
| 4031 | */ |
| 4032 | public static final String ACTIVITY_TASK_SERVICE = "activity_task"; |
| 4033 | |
| 4034 | /** |
| 4035 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4036 | * {@link android.app.UriGrantsManager} for interacting with the global system state. |
| 4037 | * |
| 4038 | * @see #getSystemService(String) |
| 4039 | * @see android.app.UriGrantsManager |
| 4040 | * @hide |
| 4041 | */ |
| 4042 | public static final String URI_GRANTS_SERVICE = "uri_grants"; |
| 4043 | |
| 4044 | /** |
| 4045 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4046 | * {@link android.app.AlarmManager} for receiving intents at a |
| 4047 | * time of your choosing. |
| 4048 | * |
| 4049 | * @see #getSystemService(String) |
| 4050 | * @see android.app.AlarmManager |
| 4051 | */ |
| 4052 | public static final String ALARM_SERVICE = "alarm"; |
| 4053 | |
| 4054 | /** |
| 4055 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4056 | * {@link android.app.NotificationManager} for informing the user of |
| 4057 | * background events. |
| 4058 | * |
| 4059 | * @see #getSystemService(String) |
| 4060 | * @see android.app.NotificationManager |
| 4061 | */ |
| 4062 | public static final String NOTIFICATION_SERVICE = "notification"; |
| 4063 | |
| 4064 | /** |
| 4065 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4066 | * {@link android.view.accessibility.AccessibilityManager} for giving the user |
| 4067 | * feedback for UI events through the registered event listeners. |
| 4068 | * |
| 4069 | * @see #getSystemService(String) |
| 4070 | * @see android.view.accessibility.AccessibilityManager |
| 4071 | */ |
| 4072 | public static final String ACCESSIBILITY_SERVICE = "accessibility"; |
| 4073 | |
| 4074 | /** |
| 4075 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4076 | * {@link android.view.accessibility.CaptioningManager} for obtaining |
| 4077 | * captioning properties and listening for changes in captioning |
| 4078 | * preferences. |
| 4079 | * |
| 4080 | * @see #getSystemService(String) |
| 4081 | * @see android.view.accessibility.CaptioningManager |
| 4082 | */ |
| 4083 | public static final String CAPTIONING_SERVICE = "captioning"; |
| 4084 | |
| 4085 | /** |
| 4086 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4087 | * {@link android.app.KeyguardManager} for controlling keyguard. |
| 4088 | * |
| 4089 | * @see #getSystemService(String) |
| 4090 | * @see android.app.KeyguardManager |
| 4091 | */ |
| 4092 | public static final String KEYGUARD_SERVICE = "keyguard"; |
| 4093 | |
| 4094 | /** |
| 4095 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4096 | * android.location.LocationManager} for controlling location |
| 4097 | * updates. |
| 4098 | * |
| 4099 | * @see #getSystemService(String) |
| 4100 | * @see android.location.LocationManager |
| 4101 | */ |
| 4102 | public static final String LOCATION_SERVICE = "location"; |
| 4103 | |
| 4104 | /** |
| 4105 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4106 | * {@link android.location.CountryDetector} for detecting the country that |
| 4107 | * the user is in. |
| 4108 | * |
| 4109 | * @hide |
| 4110 | */ |
| 4111 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 4112 | public static final String COUNTRY_DETECTOR = "country_detector"; |
| 4113 | |
| 4114 | /** |
| 4115 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4116 | * android.app.SearchManager} for handling searches. |
| 4117 | * |
| 4118 | * <p> |
| 4119 | * {@link Configuration#UI_MODE_TYPE_WATCH} does not support |
| 4120 | * {@link android.app.SearchManager}. |
| 4121 | * |
| 4122 | * @see #getSystemService |
| 4123 | * @see android.app.SearchManager |
| 4124 | */ |
| 4125 | public static final String SEARCH_SERVICE = "search"; |
| 4126 | |
| 4127 | /** |
| 4128 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4129 | * android.hardware.SensorManager} for accessing sensors. |
| 4130 | * |
| 4131 | * @see #getSystemService(String) |
| 4132 | * @see android.hardware.SensorManager |
| 4133 | */ |
| 4134 | public static final String SENSOR_SERVICE = "sensor"; |
| 4135 | |
| 4136 | /** |
| 4137 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4138 | * android.hardware.SensorPrivacyManager} for accessing sensor privacy |
| 4139 | * functions. |
| 4140 | * |
| 4141 | * @see #getSystemService(String) |
| 4142 | * @see android.hardware.SensorPrivacyManager |
| 4143 | * |
| 4144 | * @hide |
| 4145 | */ |
| 4146 | public static final String SENSOR_PRIVACY_SERVICE = "sensor_privacy"; |
| 4147 | |
| 4148 | /** |
| 4149 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4150 | * android.os.storage.StorageManager} for accessing system storage |
| 4151 | * functions. |
| 4152 | * |
| 4153 | * @see #getSystemService(String) |
| 4154 | * @see android.os.storage.StorageManager |
| 4155 | */ |
| 4156 | public static final String STORAGE_SERVICE = "storage"; |
| 4157 | |
| 4158 | /** |
| 4159 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4160 | * android.app.usage.StorageStatsManager} for accessing system storage |
| 4161 | * statistics. |
| 4162 | * |
| 4163 | * @see #getSystemService(String) |
| 4164 | * @see android.app.usage.StorageStatsManager |
| 4165 | */ |
| 4166 | public static final String STORAGE_STATS_SERVICE = "storagestats"; |
| 4167 | |
| 4168 | /** |
| 4169 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4170 | * com.android.server.WallpaperService for accessing wallpapers. |
| 4171 | * |
| 4172 | * @see #getSystemService(String) |
| 4173 | */ |
| 4174 | @UiContext |
| 4175 | public static final String WALLPAPER_SERVICE = "wallpaper"; |
| 4176 | |
| 4177 | /** |
| 4178 | * Use with {@link #getSystemService(String)} to retrieve a {@link android.os.VibratorManager} |
| 4179 | * for accessing the device vibrators, interacting with individual ones and playing synchronized |
| 4180 | * effects on multiple vibrators. |
| 4181 | * |
| 4182 | * @see #getSystemService(String) |
| 4183 | * @see android.os.VibratorManager |
| 4184 | */ |
| 4185 | @SuppressLint("ServiceName") |
| 4186 | public static final String VIBRATOR_MANAGER_SERVICE = "vibrator_manager"; |
| 4187 | |
| 4188 | /** |
| 4189 | * Use with {@link #getSystemService(String)} to retrieve a {@link android.os.Vibrator} for |
| 4190 | * interacting with the vibration hardware. |
| 4191 | * |
| 4192 | * @deprecated Use {@link android.os.VibratorManager} to retrieve the default system vibrator. |
| 4193 | * @see #getSystemService(String) |
| 4194 | * @see android.os.Vibrator |
| 4195 | */ |
| 4196 | @Deprecated |
| 4197 | public static final String VIBRATOR_SERVICE = "vibrator"; |
| 4198 | |
| 4199 | /** |
| 4200 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4201 | * android.app.StatusBarManager} for interacting with the status bar. |
| 4202 | * |
| 4203 | * @see #getSystemService(String) |
| 4204 | * @see android.app.StatusBarManager |
| 4205 | * |
| 4206 | * @hide |
| 4207 | */ |
| 4208 | @SystemApi |
| 4209 | @SuppressLint("ServiceName") |
| 4210 | public static final String STATUS_BAR_SERVICE = "statusbar"; |
| 4211 | |
| 4212 | /** |
| 4213 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4214 | * android.net.ConnectivityManager} for handling management of |
| 4215 | * network connections. |
| 4216 | * |
| 4217 | * @see #getSystemService(String) |
| 4218 | * @see android.net.ConnectivityManager |
| 4219 | */ |
| 4220 | public static final String CONNECTIVITY_SERVICE = "connectivity"; |
| 4221 | |
| 4222 | /** |
| 4223 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4224 | * android.net.PacProxyManager} for handling management of |
| 4225 | * pac proxy information. |
| 4226 | * |
| 4227 | * @see #getSystemService(String) |
| 4228 | * @see android.net.PacProxyManager |
| 4229 | * @hide |
| 4230 | */ |
| 4231 | @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) |
| 4232 | public static final String PAC_PROXY_SERVICE = "pac_proxy"; |
| 4233 | |
| 4234 | /** |
| 4235 | * Use with {@link #getSystemService(String)} to retrieve a {@link android.net.vcn.VcnManager} |
| 4236 | * for managing Virtual Carrier Networks |
| 4237 | * |
| 4238 | * @see #getSystemService(String) |
| 4239 | * @see android.net.vcn.VcnManager |
| 4240 | * @hide |
| 4241 | */ |
| 4242 | public static final String VCN_MANAGEMENT_SERVICE = "vcn_management"; |
| 4243 | |
| 4244 | /** |
| 4245 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4246 | * {@link android.net.INetd} for communicating with the network stack |
| 4247 | * @hide |
| 4248 | * @see #getSystemService(String) |
| 4249 | * @hide |
| 4250 | */ |
| 4251 | @SystemApi |
| 4252 | public static final String NETD_SERVICE = "netd"; |
| 4253 | |
| 4254 | /** |
| 4255 | * Use with {@link android.os.ServiceManager.getService()} to retrieve a |
| 4256 | * {@link INetworkStackConnector} IBinder for communicating with the network stack |
| 4257 | * @hide |
| 4258 | * @see NetworkStackClient |
| 4259 | */ |
| 4260 | public static final String NETWORK_STACK_SERVICE = "network_stack"; |
| 4261 | |
| 4262 | /** |
| 4263 | * Use with {@link #getSystemService(String)} to retrieve a {@link android.net.TetheringManager} |
| 4264 | * for managing tethering functions. |
| 4265 | * @hide |
| 4266 | * @see android.net.TetheringManager |
| 4267 | */ |
| 4268 | @SystemApi |
| 4269 | public static final String TETHERING_SERVICE = "tethering"; |
| 4270 | |
| 4271 | /** |
| 4272 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4273 | * {@link android.net.IpSecManager} for encrypting Sockets or Networks with |
| 4274 | * IPSec. |
| 4275 | * |
| 4276 | * @see #getSystemService(String) |
| 4277 | */ |
| 4278 | public static final String IPSEC_SERVICE = "ipsec"; |
| 4279 | |
| 4280 | /** |
| 4281 | * Use with {@link #getSystemService(String)} to retrieve a {@link android.net.VpnManager} to |
| 4282 | * manage profiles for the platform built-in VPN. |
| 4283 | * |
| 4284 | * @see #getSystemService(String) |
| 4285 | */ |
| 4286 | public static final String VPN_MANAGEMENT_SERVICE = "vpn_management"; |
| 4287 | |
| 4288 | /** |
| 4289 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4290 | * android.net.ConnectivityDiagnosticsManager} for performing network connectivity diagnostics |
| 4291 | * as well as receiving network connectivity information from the system. |
| 4292 | * |
| 4293 | * @see #getSystemService(String) |
| 4294 | * @see android.net.ConnectivityDiagnosticsManager |
| 4295 | */ |
| 4296 | public static final String CONNECTIVITY_DIAGNOSTICS_SERVICE = "connectivity_diagnostics"; |
| 4297 | |
| 4298 | /** |
| 4299 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4300 | * android.net.TestNetworkManager} for building TUNs and limited-use Networks |
| 4301 | * |
| 4302 | * @see #getSystemService(String) |
| 4303 | * @hide |
| 4304 | */ |
| 4305 | @TestApi @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) |
| 4306 | public static final String TEST_NETWORK_SERVICE = "test_network"; |
| 4307 | |
| 4308 | /** |
| 4309 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4310 | * android.os.IUpdateLock} for managing runtime sequences that |
| 4311 | * must not be interrupted by headless OTA application or similar. |
| 4312 | * |
| 4313 | * @hide |
| 4314 | * @see #getSystemService(String) |
| 4315 | * @see android.os.UpdateLock |
| 4316 | */ |
| 4317 | public static final String UPDATE_LOCK_SERVICE = "updatelock"; |
| 4318 | |
| 4319 | /** |
| 4320 | * Constant for the internal network management service, not really a Context service. |
| 4321 | * @hide |
| 4322 | */ |
| 4323 | public static final String NETWORKMANAGEMENT_SERVICE = "network_management"; |
| 4324 | |
| 4325 | /** |
| 4326 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4327 | * {@link com.android.server.slice.SliceManagerService} for managing slices. |
| 4328 | * @hide |
| 4329 | * @see #getSystemService(String) |
| 4330 | */ |
| 4331 | public static final String SLICE_SERVICE = "slice"; |
| 4332 | |
| 4333 | /** |
| 4334 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4335 | * android.app.usage.NetworkStatsManager} for querying network usage stats. |
| 4336 | * |
| 4337 | * @see #getSystemService(String) |
| 4338 | * @see android.app.usage.NetworkStatsManager |
| 4339 | */ |
| 4340 | public static final String NETWORK_STATS_SERVICE = "netstats"; |
| 4341 | /** {@hide} */ |
| 4342 | public static final String NETWORK_POLICY_SERVICE = "netpolicy"; |
| 4343 | /** {@hide} */ |
| 4344 | public static final String NETWORK_WATCHLIST_SERVICE = "network_watchlist"; |
| 4345 | |
| 4346 | /** |
| 4347 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4348 | * android.net.wifi.WifiManager} for handling management of |
| 4349 | * Wi-Fi access. |
| 4350 | * |
| 4351 | * @see #getSystemService(String) |
| 4352 | * @see android.net.wifi.WifiManager |
| 4353 | */ |
| 4354 | public static final String WIFI_SERVICE = "wifi"; |
| 4355 | |
| 4356 | /** |
| 4357 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4358 | * {@link android.net.wifi.wificond.WifiNl80211Manager} for handling management of the |
| 4359 | * Wi-Fi nl802.11 daemon (wificond). |
| 4360 | * |
| 4361 | * @see #getSystemService(String) |
| 4362 | * @see android.net.wifi.wificond.WifiNl80211Manager |
| 4363 | * @hide |
| 4364 | */ |
| 4365 | @SystemApi |
| 4366 | @SuppressLint("ServiceName") |
| 4367 | public static final String WIFI_NL80211_SERVICE = "wifinl80211"; |
| 4368 | |
| 4369 | /** |
| 4370 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4371 | * android.net.wifi.p2p.WifiP2pManager} for handling management of |
| 4372 | * Wi-Fi peer-to-peer connections. |
| 4373 | * |
| 4374 | * @see #getSystemService(String) |
| 4375 | * @see android.net.wifi.p2p.WifiP2pManager |
| 4376 | */ |
| 4377 | public static final String WIFI_P2P_SERVICE = "wifip2p"; |
| 4378 | |
| 4379 | /** |
| 4380 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4381 | * {@link android.net.wifi.aware.WifiAwareManager} for handling management of |
| 4382 | * Wi-Fi Aware. |
| 4383 | * |
| 4384 | * @see #getSystemService(String) |
| 4385 | * @see android.net.wifi.aware.WifiAwareManager |
| 4386 | */ |
| 4387 | public static final String WIFI_AWARE_SERVICE = "wifiaware"; |
| 4388 | |
| 4389 | /** |
| 4390 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4391 | * android.net.wifi.WifiScanner} for scanning the wifi universe |
| 4392 | * |
| 4393 | * @see #getSystemService(String) |
| 4394 | * @see android.net.wifi.WifiScanner |
| 4395 | * @hide |
| 4396 | */ |
| 4397 | @SystemApi |
| 4398 | public static final String WIFI_SCANNING_SERVICE = "wifiscanner"; |
| 4399 | |
| 4400 | /** |
| 4401 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4402 | * android.net.wifi.RttManager} for ranging devices with wifi |
| 4403 | * |
| 4404 | * @see #getSystemService(String) |
| 4405 | * @see android.net.wifi.RttManager |
| 4406 | * @hide |
| 4407 | */ |
| 4408 | @SystemApi |
| 4409 | @Deprecated |
| 4410 | public static final String WIFI_RTT_SERVICE = "rttmanager"; |
| 4411 | |
| 4412 | /** |
| 4413 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4414 | * android.net.wifi.rtt.WifiRttManager} for ranging devices with wifi. |
| 4415 | * |
| 4416 | * @see #getSystemService(String) |
| 4417 | * @see android.net.wifi.rtt.WifiRttManager |
| 4418 | */ |
| 4419 | public static final String WIFI_RTT_RANGING_SERVICE = "wifirtt"; |
| 4420 | |
| 4421 | /** |
| 4422 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4423 | * android.net.lowpan.LowpanManager} for handling management of |
| 4424 | * LoWPAN access. |
| 4425 | * |
| 4426 | * @see #getSystemService(String) |
| 4427 | * @see android.net.lowpan.LowpanManager |
| 4428 | * |
| 4429 | * @hide |
| 4430 | */ |
| 4431 | public static final String LOWPAN_SERVICE = "lowpan"; |
| 4432 | |
| 4433 | /** |
| 4434 | * Use with {@link #getSystemService(String)} to retrieve a {@link android.net.EthernetManager} |
| 4435 | * for handling management of Ethernet access. |
| 4436 | * |
| 4437 | * @see #getSystemService(String) |
| 4438 | * @see android.net.EthernetManager |
| 4439 | * |
| 4440 | * @hide |
| 4441 | */ |
| 4442 | @SystemApi |
| 4443 | public static final String ETHERNET_SERVICE = "ethernet"; |
| 4444 | |
| 4445 | /** |
| 4446 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4447 | * android.net.nsd.NsdManager} for handling management of network service |
| 4448 | * discovery |
| 4449 | * |
| 4450 | * @see #getSystemService(String) |
| 4451 | * @see android.net.nsd.NsdManager |
| 4452 | */ |
| 4453 | public static final String NSD_SERVICE = "servicediscovery"; |
| 4454 | |
| 4455 | /** |
| 4456 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4457 | * {@link android.media.AudioManager} for handling management of volume, |
| 4458 | * ringer modes and audio routing. |
| 4459 | * |
| 4460 | * @see #getSystemService(String) |
| 4461 | * @see android.media.AudioManager |
| 4462 | */ |
| 4463 | public static final String AUDIO_SERVICE = "audio"; |
| 4464 | |
| 4465 | /** |
| 4466 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 4467 | * android.media.MediaTranscodingManager} for transcoding media. |
| 4468 | * |
| 4469 | * @hide |
| 4470 | * @see #getSystemService(String) |
| 4471 | * @see android.media.MediaTranscodingManager |
| 4472 | */ |
| 4473 | @SystemApi |
| 4474 | public static final String MEDIA_TRANSCODING_SERVICE = "media_transcoding"; |
| 4475 | |
| 4476 | /** |
| 4477 | * AuthService orchestrates biometric and PIN/pattern/password authentication. |
| 4478 | * |
| 4479 | * BiometricService was split into two services, AuthService and BiometricService, where |
| 4480 | * AuthService is the high level service that orchestrates all types of authentication, and |
| 4481 | * BiometricService is a lower layer responsible only for biometric authentication. |
| 4482 | * |
| 4483 | * Ideally we should have renamed BiometricManager to AuthManager, because it logically |
| 4484 | * corresponds to AuthService. However, because BiometricManager is a public API, we kept |
| 4485 | * the old name but changed the internal implementation to use AuthService. |
| 4486 | * |
| 4487 | * As of now, the AUTH_SERVICE constant is only used to identify the service in |
| 4488 | * SystemServiceRegistry and SELinux. To obtain the manager for AUTH_SERVICE, one should use |
| 4489 | * BIOMETRIC_SERVICE with {@link #getSystemService(String)} to retrieve a |
| 4490 | * {@link android.hardware.biometrics.BiometricManager} |
| 4491 | * |
| 4492 | * Map of the two services and their managers: |
| 4493 | * [Service] [Manager] |
| 4494 | * AuthService BiometricManager |
| 4495 | * BiometricService N/A |
| 4496 | * |
| 4497 | * @hide |
| 4498 | */ |
| 4499 | public static final String AUTH_SERVICE = "auth"; |
| 4500 | |
| 4501 | /** |
| 4502 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4503 | * {@link android.hardware.fingerprint.FingerprintManager} for handling management |
| 4504 | * of fingerprints. |
| 4505 | * |
| 4506 | * @see #getSystemService(String) |
| 4507 | * @see android.hardware.fingerprint.FingerprintManager |
| 4508 | */ |
| 4509 | public static final String FINGERPRINT_SERVICE = "fingerprint"; |
| 4510 | |
| 4511 | /** |
| 4512 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4513 | * {@link android.hardware.face.FaceManager} for handling management |
| 4514 | * of face authentication. |
| 4515 | * |
| 4516 | * @hide |
| 4517 | * @see #getSystemService |
| 4518 | * @see android.hardware.face.FaceManager |
| 4519 | */ |
| 4520 | public static final String FACE_SERVICE = "face"; |
| 4521 | |
| 4522 | /** |
| 4523 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4524 | * {@link android.hardware.iris.IrisManager} for handling management |
| 4525 | * of iris authentication. |
| 4526 | * |
| 4527 | * @hide |
| 4528 | * @see #getSystemService |
| 4529 | * @see android.hardware.iris.IrisManager |
| 4530 | */ |
| 4531 | public static final String IRIS_SERVICE = "iris"; |
| 4532 | |
| 4533 | /** |
| 4534 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4535 | * {@link android.hardware.biometrics.BiometricManager} for handling |
| 4536 | * biometric and PIN/pattern/password authentication. |
| 4537 | * |
| 4538 | * @see #getSystemService |
| 4539 | * @see android.hardware.biometrics.BiometricManager |
| 4540 | */ |
| 4541 | public static final String BIOMETRIC_SERVICE = "biometric"; |
| 4542 | |
| 4543 | /** |
| 4544 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4545 | * {@link android.media.MediaCommunicationManager} |
| 4546 | * for managing {@link android.media.MediaSession2}. |
| 4547 | * |
| 4548 | * @see #getSystemService(String) |
| 4549 | * @see android.media.MediaCommunicationManager |
| 4550 | */ |
| 4551 | public static final String MEDIA_COMMUNICATION_SERVICE = "media_communication"; |
| 4552 | |
| 4553 | /** |
| 4554 | * Use with {@link #getSystemService} to retrieve a |
| 4555 | * {@link android.media.MediaRouter} for controlling and managing |
| 4556 | * routing of media. |
| 4557 | * |
| 4558 | * @see #getSystemService(String) |
| 4559 | * @see android.media.MediaRouter |
| 4560 | */ |
| 4561 | public static final String MEDIA_ROUTER_SERVICE = "media_router"; |
| 4562 | |
| 4563 | /** |
| 4564 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4565 | * {@link android.media.session.MediaSessionManager} for managing media Sessions. |
| 4566 | * |
| 4567 | * @see #getSystemService(String) |
| 4568 | * @see android.media.session.MediaSessionManager |
| 4569 | */ |
| 4570 | public static final String MEDIA_SESSION_SERVICE = "media_session"; |
| 4571 | |
| 4572 | /** |
| 4573 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4574 | * {@link android.telephony.TelephonyManager} for handling management the |
| 4575 | * telephony features of the device. |
| 4576 | * |
| 4577 | * @see #getSystemService(String) |
| 4578 | * @see android.telephony.TelephonyManager |
| 4579 | */ |
| 4580 | public static final String TELEPHONY_SERVICE = "phone"; |
| 4581 | |
| 4582 | /** |
| 4583 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4584 | * {@link android.telephony.SubscriptionManager} for handling management the |
| 4585 | * telephony subscriptions of the device. |
| 4586 | * |
| 4587 | * @see #getSystemService(String) |
| 4588 | * @see android.telephony.SubscriptionManager |
| 4589 | */ |
| 4590 | public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service"; |
| 4591 | |
| 4592 | /** |
| 4593 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4594 | * {@link android.telecom.TelecomManager} to manage telecom-related features |
| 4595 | * of the device. |
| 4596 | * |
| 4597 | * @see #getSystemService(String) |
| 4598 | * @see android.telecom.TelecomManager |
| 4599 | */ |
| 4600 | public static final String TELECOM_SERVICE = "telecom"; |
| 4601 | |
| 4602 | /** |
| 4603 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4604 | * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values. |
| 4605 | * |
| 4606 | * @see #getSystemService(String) |
| 4607 | * @see android.telephony.CarrierConfigManager |
| 4608 | */ |
| 4609 | public static final String CARRIER_CONFIG_SERVICE = "carrier_config"; |
| 4610 | |
| 4611 | /** |
| 4612 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4613 | * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM). |
| 4614 | * |
| 4615 | * @see #getSystemService(String) |
| 4616 | * @see android.telephony.euicc.EuiccManager |
| 4617 | */ |
| 4618 | public static final String EUICC_SERVICE = "euicc"; |
| 4619 | |
| 4620 | /** |
| 4621 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4622 | * {@link android.telephony.euicc.EuiccCardManager} to access the device eUICC (embedded SIM). |
| 4623 | * |
| 4624 | * @see #getSystemService(String) |
| 4625 | * @see android.telephony.euicc.EuiccCardManager |
| 4626 | * @hide |
| 4627 | */ |
| 4628 | @SystemApi |
| 4629 | public static final String EUICC_CARD_SERVICE = "euicc_card"; |
| 4630 | |
| 4631 | /** |
| 4632 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4633 | * {@link android.telephony.MmsManager} to send/receive MMS messages. |
| 4634 | * |
| 4635 | * @see #getSystemService(String) |
| 4636 | * @see android.telephony.MmsManager |
| 4637 | * @hide |
| 4638 | */ |
| 4639 | public static final String MMS_SERVICE = "mms"; |
| 4640 | |
| 4641 | /** |
| 4642 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4643 | * {@link android.content.ClipboardManager} for accessing and modifying |
| 4644 | * the contents of the global clipboard. |
| 4645 | * |
| 4646 | * @see #getSystemService(String) |
| 4647 | * @see android.content.ClipboardManager |
| 4648 | */ |
| 4649 | public static final String CLIPBOARD_SERVICE = "clipboard"; |
| 4650 | |
| 4651 | /** |
| 4652 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4653 | * {@link TextClassificationManager} for text classification services. |
| 4654 | * |
| 4655 | * @see #getSystemService(String) |
| 4656 | * @see TextClassificationManager |
| 4657 | */ |
| 4658 | public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification"; |
| 4659 | |
| 4660 | /** |
| 4661 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4662 | * {@link android.graphics.fonts.FontManager} for font services. |
| 4663 | * |
| 4664 | * @see #getSystemService(String) |
| 4665 | * @see android.graphics.fonts.FontManager |
| 4666 | * @hide |
| 4667 | */ |
| 4668 | @SystemApi |
| 4669 | @TestApi |
| 4670 | public static final String FONT_SERVICE = "font"; |
| 4671 | |
| 4672 | /** |
| 4673 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4674 | * {@link com.android.server.attention.AttentionManagerService} for attention services. |
| 4675 | * |
| 4676 | * @see #getSystemService(String) |
| 4677 | * @see android.server.attention.AttentionManagerService |
| 4678 | * @hide |
| 4679 | */ |
| 4680 | public static final String ATTENTION_SERVICE = "attention"; |
| 4681 | |
| 4682 | /** |
| 4683 | * Official published name of the (internal) rotation resolver service. |
| 4684 | * |
| 4685 | * // TODO(b/178151184): change it back to rotation resolver before S release. |
| 4686 | * |
| 4687 | * @see #getSystemService(String) |
| 4688 | * @hide |
| 4689 | */ |
| 4690 | public static final String ROTATION_RESOLVER_SERVICE = "resolver"; |
| 4691 | |
| 4692 | /** |
| 4693 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4694 | * {@link android.view.inputmethod.InputMethodManager} for accessing input |
| 4695 | * methods. |
| 4696 | * |
| 4697 | * @see #getSystemService(String) |
| 4698 | */ |
| 4699 | public static final String INPUT_METHOD_SERVICE = "input_method"; |
| 4700 | |
| 4701 | /** |
| 4702 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4703 | * {@link android.view.textservice.TextServicesManager} for accessing |
| 4704 | * text services. |
| 4705 | * |
| 4706 | * @see #getSystemService(String) |
| 4707 | */ |
| 4708 | public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices"; |
| 4709 | |
| 4710 | /** |
| 4711 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4712 | * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets. |
| 4713 | * |
| 4714 | * @see #getSystemService(String) |
| 4715 | */ |
| 4716 | public static final String APPWIDGET_SERVICE = "appwidget"; |
| 4717 | |
| 4718 | /** |
| 4719 | * Official published name of the (internal) voice interaction manager service. |
| 4720 | * |
| 4721 | * @hide |
| 4722 | * @see #getSystemService(String) |
| 4723 | */ |
| 4724 | public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction"; |
| 4725 | |
| 4726 | /** |
| 4727 | * Official published name of the (internal) autofill service. |
| 4728 | * |
| 4729 | * @hide |
| 4730 | * @see #getSystemService(String) |
| 4731 | */ |
| 4732 | public static final String AUTOFILL_MANAGER_SERVICE = "autofill"; |
| 4733 | |
| 4734 | /** |
| 4735 | * Official published name of the (internal) text to speech manager service. |
| 4736 | * |
| 4737 | * @hide |
| 4738 | * @see #getSystemService(String) |
| 4739 | */ |
| 4740 | public static final String TEXT_TO_SPEECH_MANAGER_SERVICE = "texttospeech"; |
| 4741 | |
| 4742 | /** |
| 4743 | * Official published name of the content capture service. |
| 4744 | * |
| 4745 | * @hide |
| 4746 | * @see #getSystemService(String) |
| 4747 | */ |
| 4748 | @TestApi |
| 4749 | @SuppressLint("ServiceName") // TODO: This should be renamed to CONTENT_CAPTURE_SERVICE |
| 4750 | public static final String CONTENT_CAPTURE_MANAGER_SERVICE = "content_capture"; |
| 4751 | |
| 4752 | /** |
| 4753 | * Official published name of the translation service. |
| 4754 | * |
| 4755 | * @hide |
| 4756 | * @see #getSystemService(String) |
| 4757 | */ |
| 4758 | @SystemApi |
| 4759 | @SuppressLint("ServiceName") |
| 4760 | public static final String TRANSLATION_MANAGER_SERVICE = "translation"; |
| 4761 | |
| 4762 | /** |
| 4763 | * Official published name of the translation service which supports ui translation function. |
| 4764 | * |
| 4765 | * @hide |
| 4766 | * @see #getSystemService(String) |
| 4767 | */ |
| 4768 | @SystemApi |
| 4769 | public static final String UI_TRANSLATION_SERVICE = "ui_translation"; |
| 4770 | |
| 4771 | /** |
| 4772 | * Used for getting content selections and classifications for task snapshots. |
| 4773 | * |
| 4774 | * @hide |
| 4775 | * @see #getSystemService(String) |
| 4776 | */ |
| 4777 | @SystemApi |
| 4778 | public static final String CONTENT_SUGGESTIONS_SERVICE = "content_suggestions"; |
| 4779 | |
| 4780 | /** |
| 4781 | * Official published name of the app prediction service. |
| 4782 | * |
| 4783 | * <p><b>NOTE: </b> this service is optional; callers of |
| 4784 | * {@code Context.getSystemServiceName(APP_PREDICTION_SERVICE)} should check for {@code null}. |
| 4785 | * |
| 4786 | * @hide |
| 4787 | * @see #getSystemService(String) |
| 4788 | */ |
| 4789 | @SystemApi |
| 4790 | public static final String APP_PREDICTION_SERVICE = "app_prediction"; |
| 4791 | |
| 4792 | /** |
| 4793 | * Official published name of the search ui service. |
| 4794 | * |
| 4795 | * <p><b>NOTE: </b> this service is optional; callers of |
| 4796 | * {@code Context.getSystemServiceName(SEARCH_UI_SERVICE)} should check for {@code null}. |
| 4797 | * |
| 4798 | * @hide |
| 4799 | * @see #getSystemService(String) |
| 4800 | */ |
| 4801 | @SystemApi |
| 4802 | public static final String SEARCH_UI_SERVICE = "search_ui"; |
| 4803 | |
| 4804 | /** |
| 4805 | * Used for getting the smartspace service. |
| 4806 | * |
| 4807 | * <p><b>NOTE: </b> this service is optional; callers of |
| 4808 | * {@code Context.getSystemServiceName(SMARTSPACE_SERVICE)} should check for {@code null}. |
| 4809 | * |
| 4810 | * @hide |
| 4811 | * @see #getSystemService(String) |
| 4812 | */ |
| 4813 | @SystemApi |
| 4814 | public static final String SMARTSPACE_SERVICE = "smartspace"; |
| 4815 | |
| 4816 | /** |
| 4817 | * Use with {@link #getSystemService(String)} to access the |
| 4818 | * {@link com.android.server.voiceinteraction.SoundTriggerService}. |
| 4819 | * |
| 4820 | * @hide |
| 4821 | * @see #getSystemService(String) |
| 4822 | */ |
| 4823 | public static final String SOUND_TRIGGER_SERVICE = "soundtrigger"; |
| 4824 | |
| 4825 | /** |
| 4826 | * Use with {@link #getSystemService(String)} to access the |
| 4827 | * {@link com.android.server.soundtrigger_middleware.SoundTriggerMiddlewareService}. |
| 4828 | * |
| 4829 | * @hide |
| 4830 | * @see #getSystemService(String) |
| 4831 | */ |
| 4832 | public static final String SOUND_TRIGGER_MIDDLEWARE_SERVICE = "soundtrigger_middleware"; |
| 4833 | |
| 4834 | /** |
| 4835 | * Used to access {@link MusicRecognitionManagerService}. |
| 4836 | * |
| 4837 | * @hide |
| 4838 | * @see #getSystemService(String) |
| 4839 | */ |
| 4840 | @SystemApi |
| 4841 | public static final String MUSIC_RECOGNITION_SERVICE = "music_recognition"; |
| 4842 | |
| 4843 | /** |
| 4844 | * Official published name of the (internal) permission service. |
| 4845 | * |
| 4846 | * @see #getSystemService(String) |
| 4847 | * @hide |
| 4848 | */ |
| 4849 | @SystemApi |
| 4850 | public static final String PERMISSION_SERVICE = "permission"; |
| 4851 | |
| 4852 | /** |
| 4853 | * Official published name of the legacy (internal) permission service. |
| 4854 | * |
| 4855 | * @see #getSystemService(String) |
| 4856 | * @hide |
| 4857 | */ |
| 4858 | //@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) |
| 4859 | public static final String LEGACY_PERMISSION_SERVICE = "legacy_permission"; |
| 4860 | |
| 4861 | /** |
| 4862 | * Official published name of the (internal) permission controller service. |
| 4863 | * |
| 4864 | * @see #getSystemService(String) |
| 4865 | * @hide |
| 4866 | */ |
| 4867 | @SystemApi |
| 4868 | public static final String PERMISSION_CONTROLLER_SERVICE = "permission_controller"; |
| 4869 | |
| 4870 | /** |
| 4871 | * Official published name of the (internal) permission checker service. |
| 4872 | * |
| 4873 | * @see #getSystemService(String) |
| 4874 | * @hide |
| 4875 | */ |
| 4876 | public static final String PERMISSION_CHECKER_SERVICE = "permission_checker"; |
| 4877 | |
| 4878 | /** |
| 4879 | * Use with {@link #getSystemService(String) to retrieve an |
| 4880 | * {@link android.apphibernation.AppHibernationManager}} for |
| 4881 | * communicating with the hibernation service. |
| 4882 | * @hide |
| 4883 | * |
| 4884 | * @see #getSystemService(String) |
| 4885 | */ |
| 4886 | @SystemApi |
| 4887 | public static final String APP_HIBERNATION_SERVICE = "app_hibernation"; |
| 4888 | |
| 4889 | /** |
| 4890 | * Use with {@link #getSystemService(String)} to retrieve an |
| 4891 | * {@link android.app.backup.IBackupManager IBackupManager} for communicating |
| 4892 | * with the backup mechanism. |
| 4893 | * @hide |
| 4894 | * |
| 4895 | * @see #getSystemService(String) |
| 4896 | */ |
| 4897 | @SystemApi |
| 4898 | public static final String BACKUP_SERVICE = "backup"; |
| 4899 | |
| 4900 | /** |
| 4901 | * Use with {@link #getSystemService(String)} to retrieve an |
| 4902 | * {@link android.content.rollback.RollbackManager} for communicating |
| 4903 | * with the rollback manager |
| 4904 | * |
| 4905 | * @see #getSystemService(String) |
| 4906 | * @hide |
| 4907 | */ |
| 4908 | @SystemApi |
| 4909 | public static final String ROLLBACK_SERVICE = "rollback"; |
| 4910 | |
| 4911 | /** |
| 4912 | * Use with {@link #getSystemService(String)} to retrieve an |
| 4913 | * {@link android.scheduling.RebootReadinessManager} for communicating |
| 4914 | * with the reboot readiness detector. |
| 4915 | * |
| 4916 | * @see #getSystemService(String) |
| 4917 | * @hide |
| 4918 | */ |
| 4919 | @SystemApi |
| 4920 | public static final String REBOOT_READINESS_SERVICE = "reboot_readiness"; |
| 4921 | |
| 4922 | /** |
| 4923 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4924 | * {@link android.os.DropBoxManager} instance for recording |
| 4925 | * diagnostic logs. |
| 4926 | * @see #getSystemService(String) |
| 4927 | */ |
| 4928 | public static final String DROPBOX_SERVICE = "dropbox"; |
| 4929 | |
| 4930 | /** |
| 4931 | * System service name for the DeviceIdleManager. |
| 4932 | * @see #getSystemService(String) |
| 4933 | * @hide |
| 4934 | */ |
| 4935 | @TestApi |
| 4936 | @SuppressLint("ServiceName") // TODO: This should be renamed to DEVICE_IDLE_SERVICE |
| 4937 | public static final String DEVICE_IDLE_CONTROLLER = "deviceidle"; |
| 4938 | |
| 4939 | /** |
| 4940 | * System service name for the PowerWhitelistManager. |
| 4941 | * |
| 4942 | * @see #getSystemService(String) |
| 4943 | * @hide |
| 4944 | */ |
| 4945 | @TestApi |
| 4946 | @Deprecated |
| 4947 | @SuppressLint("ServiceName") |
| 4948 | public static final String POWER_WHITELIST_MANAGER = "power_whitelist"; |
| 4949 | |
| 4950 | /** |
| 4951 | * System service name for the PowerExemptionManager. |
| 4952 | * |
| 4953 | * @see #getSystemService(String) |
| 4954 | * @hide |
| 4955 | */ |
| 4956 | @TestApi |
| 4957 | public static final String POWER_EXEMPTION_SERVICE = "power_exemption"; |
| 4958 | |
| 4959 | /** |
| 4960 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4961 | * {@link android.app.admin.DevicePolicyManager} for working with global |
| 4962 | * device policy management. |
| 4963 | * |
| 4964 | * @see #getSystemService(String) |
| 4965 | */ |
| 4966 | public static final String DEVICE_POLICY_SERVICE = "device_policy"; |
| 4967 | |
| 4968 | /** |
| 4969 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4970 | * {@link android.app.UiModeManager} for controlling UI modes. |
| 4971 | * |
| 4972 | * @see #getSystemService(String) |
| 4973 | */ |
| 4974 | public static final String UI_MODE_SERVICE = "uimode"; |
| 4975 | |
| 4976 | /** |
| 4977 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4978 | * {@link android.app.DownloadManager} for requesting HTTP downloads. |
| 4979 | * |
| 4980 | * @see #getSystemService(String) |
| 4981 | */ |
| 4982 | public static final String DOWNLOAD_SERVICE = "download"; |
| 4983 | |
| 4984 | /** |
| 4985 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4986 | * {@link android.os.BatteryManager} for managing battery state. |
| 4987 | * |
| 4988 | * @see #getSystemService(String) |
| 4989 | */ |
| 4990 | public static final String BATTERY_SERVICE = "batterymanager"; |
| 4991 | |
| 4992 | /** |
| 4993 | * Use with {@link #getSystemService(String)} to retrieve a |
| 4994 | * {@link android.nfc.NfcManager} for using NFC. |
| 4995 | * |
| 4996 | * @see #getSystemService(String) |
| 4997 | */ |
| 4998 | public static final String NFC_SERVICE = "nfc"; |
| 4999 | |
| 5000 | /** |
| 5001 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5002 | * {@link android.bluetooth.BluetoothManager} for using Bluetooth. |
| 5003 | * |
| 5004 | * @see #getSystemService(String) |
| 5005 | */ |
| 5006 | public static final String BLUETOOTH_SERVICE = "bluetooth"; |
| 5007 | |
| 5008 | /** |
| 5009 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5010 | * {@link android.net.sip.SipManager} for accessing the SIP related service. |
| 5011 | * |
| 5012 | * @see #getSystemService(String) |
| 5013 | */ |
| 5014 | /** @hide */ |
| 5015 | public static final String SIP_SERVICE = "sip"; |
| 5016 | |
| 5017 | /** |
| 5018 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 5019 | * android.hardware.usb.UsbManager} for access to USB devices (as a USB host) |
| 5020 | * and for controlling this device's behavior as a USB device. |
| 5021 | * |
| 5022 | * @see #getSystemService(String) |
| 5023 | * @see android.hardware.usb.UsbManager |
| 5024 | */ |
| 5025 | public static final String USB_SERVICE = "usb"; |
| 5026 | |
| 5027 | /** |
| 5028 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 5029 | * Use with {@link #getSystemService} to retrieve a {@link |
| 5030 | * android.debug.AdbManager} for access to ADB debug functions. |
| 5031 | * |
| 5032 | * @see #getSystemService(String) |
| 5033 | * @see android.debug.AdbManager |
| 5034 | * |
| 5035 | * @hide |
| 5036 | */ |
| 5037 | public static final String ADB_SERVICE = "adb"; |
| 5038 | |
| 5039 | /** |
| 5040 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 5041 | * android.hardware.SerialManager} for access to serial ports. |
| 5042 | * |
| 5043 | * @see #getSystemService(String) |
| 5044 | * @see android.hardware.SerialManager |
| 5045 | * |
| 5046 | * @hide |
| 5047 | */ |
| 5048 | public static final String SERIAL_SERVICE = "serial"; |
| 5049 | |
| 5050 | /** |
| 5051 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5052 | * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing |
| 5053 | * HDMI-CEC protocol. |
| 5054 | * |
| 5055 | * @see #getSystemService(String) |
| 5056 | * @see android.hardware.hdmi.HdmiControlManager |
| 5057 | * @hide |
| 5058 | */ |
| 5059 | @SystemApi |
| 5060 | public static final String HDMI_CONTROL_SERVICE = "hdmi_control"; |
| 5061 | |
| 5062 | /** |
| 5063 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5064 | * {@link android.hardware.input.InputManager} for interacting with input devices. |
| 5065 | * |
| 5066 | * @see #getSystemService(String) |
| 5067 | * @see android.hardware.input.InputManager |
| 5068 | */ |
| 5069 | public static final String INPUT_SERVICE = "input"; |
| 5070 | |
| 5071 | /** |
| 5072 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5073 | * {@link android.hardware.display.DisplayManager} for interacting with display devices. |
| 5074 | * |
| 5075 | * @see #getSystemService(String) |
| 5076 | * @see android.hardware.display.DisplayManager |
| 5077 | */ |
| 5078 | public static final String DISPLAY_SERVICE = "display"; |
| 5079 | |
| 5080 | /** |
| 5081 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5082 | * {@link android.hardware.display.ColorDisplayManager} for controlling color transforms. |
| 5083 | * |
| 5084 | * @see #getSystemService(String) |
| 5085 | * @see android.hardware.display.ColorDisplayManager |
| 5086 | * @hide |
| 5087 | */ |
| 5088 | public static final String COLOR_DISPLAY_SERVICE = "color_display"; |
| 5089 | |
| 5090 | /** |
| 5091 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5092 | * {@link android.os.UserManager} for managing users on devices that support multiple users. |
| 5093 | * |
| 5094 | * @see #getSystemService(String) |
| 5095 | * @see android.os.UserManager |
| 5096 | */ |
| 5097 | public static final String USER_SERVICE = "user"; |
| 5098 | |
| 5099 | /** |
| 5100 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5101 | * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across |
| 5102 | * profiles of a user. |
| 5103 | * |
| 5104 | * @see #getSystemService(String) |
| 5105 | * @see android.content.pm.LauncherApps |
| 5106 | */ |
| 5107 | public static final String LAUNCHER_APPS_SERVICE = "launcherapps"; |
| 5108 | |
| 5109 | /** |
| 5110 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5111 | * {@link android.content.RestrictionsManager} for retrieving application restrictions |
| 5112 | * and requesting permissions for restricted operations. |
| 5113 | * @see #getSystemService(String) |
| 5114 | * @see android.content.RestrictionsManager |
| 5115 | */ |
| 5116 | public static final String RESTRICTIONS_SERVICE = "restrictions"; |
| 5117 | |
| 5118 | /** |
| 5119 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5120 | * {@link android.app.AppOpsManager} for tracking application operations |
| 5121 | * on the device. |
| 5122 | * |
| 5123 | * @see #getSystemService(String) |
| 5124 | * @see android.app.AppOpsManager |
| 5125 | */ |
| 5126 | public static final String APP_OPS_SERVICE = "appops"; |
| 5127 | |
| 5128 | /** |
| 5129 | * Use with {@link #getSystemService(String)} to retrieve a {@link android.app.role.RoleManager} |
| 5130 | * for managing roles. |
| 5131 | * |
| 5132 | * @see #getSystemService(String) |
| 5133 | * @see android.app.role.RoleManager |
| 5134 | */ |
| 5135 | public static final String ROLE_SERVICE = "role"; |
| 5136 | |
| 5137 | /** |
| 5138 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5139 | * {@link android.hardware.camera2.CameraManager} for interacting with |
| 5140 | * camera devices. |
| 5141 | * |
| 5142 | * @see #getSystemService(String) |
| 5143 | * @see android.hardware.camera2.CameraManager |
| 5144 | */ |
| 5145 | public static final String CAMERA_SERVICE = "camera"; |
| 5146 | |
| 5147 | /** |
| 5148 | * {@link android.print.PrintManager} for printing and managing |
| 5149 | * printers and print tasks. |
| 5150 | * |
| 5151 | * @see #getSystemService(String) |
| 5152 | * @see android.print.PrintManager |
| 5153 | */ |
| 5154 | public static final String PRINT_SERVICE = "print"; |
| 5155 | |
| 5156 | /** |
| 5157 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5158 | * {@link android.companion.CompanionDeviceManager} for managing companion devices |
| 5159 | * |
| 5160 | * @see #getSystemService(String) |
| 5161 | * @see android.companion.CompanionDeviceManager |
| 5162 | */ |
| 5163 | public static final String COMPANION_DEVICE_SERVICE = "companiondevice"; |
| 5164 | |
| 5165 | /** |
| 5166 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5167 | * {@link android.hardware.ConsumerIrManager} for transmitting infrared |
| 5168 | * signals from the device. |
| 5169 | * |
| 5170 | * @see #getSystemService(String) |
| 5171 | * @see android.hardware.ConsumerIrManager |
| 5172 | */ |
| 5173 | public static final String CONSUMER_IR_SERVICE = "consumer_ir"; |
| 5174 | |
| 5175 | /** |
| 5176 | * {@link android.app.trust.TrustManager} for managing trust agents. |
| 5177 | * @see #getSystemService(String) |
| 5178 | * @see android.app.trust.TrustManager |
| 5179 | * @hide |
| 5180 | */ |
| 5181 | public static final String TRUST_SERVICE = "trust"; |
| 5182 | |
| 5183 | /** |
| 5184 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5185 | * {@link android.media.tv.TvInputManager} for interacting with TV inputs |
| 5186 | * on the device. |
| 5187 | * |
| 5188 | * @see #getSystemService(String) |
| 5189 | * @see android.media.tv.TvInputManager |
| 5190 | */ |
| 5191 | public static final String TV_INPUT_SERVICE = "tv_input"; |
| 5192 | |
| 5193 | /** |
| 5194 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5195 | * {@link android.media.tv.TunerResourceManager} for interacting with TV |
| 5196 | * tuner resources on the device. |
| 5197 | * |
| 5198 | * @see #getSystemService(String) |
| 5199 | * @see android.media.tv.TunerResourceManager |
| 5200 | * @hide |
| 5201 | */ |
| 5202 | public static final String TV_TUNER_RESOURCE_MGR_SERVICE = "tv_tuner_resource_mgr"; |
| 5203 | |
| 5204 | /** |
| 5205 | * {@link android.net.NetworkScoreManager} for managing network scoring. |
| 5206 | * @see #getSystemService(String) |
| 5207 | * @see android.net.NetworkScoreManager |
| 5208 | * @hide |
| 5209 | */ |
| 5210 | @SystemApi |
| 5211 | public static final String NETWORK_SCORE_SERVICE = "network_score"; |
| 5212 | |
| 5213 | /** |
| 5214 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 5215 | * android.app.usage.UsageStatsManager} for querying device usage stats. |
| 5216 | * |
| 5217 | * @see #getSystemService(String) |
| 5218 | * @see android.app.usage.UsageStatsManager |
| 5219 | */ |
| 5220 | public static final String USAGE_STATS_SERVICE = "usagestats"; |
| 5221 | |
| 5222 | /** |
| 5223 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 5224 | * android.app.job.JobScheduler} instance for managing occasional |
| 5225 | * background tasks. |
| 5226 | * @see #getSystemService(String) |
| 5227 | * @see android.app.job.JobScheduler |
| 5228 | */ |
| 5229 | public static final String JOB_SCHEDULER_SERVICE = "jobscheduler"; |
| 5230 | |
| 5231 | /** |
| 5232 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 5233 | * android.service.persistentdata.PersistentDataBlockManager} instance |
| 5234 | * for interacting with a storage device that lives across factory resets. |
| 5235 | * |
| 5236 | * @see #getSystemService(String) |
| 5237 | * @see android.service.persistentdata.PersistentDataBlockManager |
| 5238 | * @hide |
| 5239 | */ |
| 5240 | @SystemApi |
| 5241 | public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block"; |
| 5242 | |
| 5243 | /** |
| 5244 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 5245 | * android.service.oemlock.OemLockManager} instance for managing the OEM lock. |
| 5246 | * |
| 5247 | * @see #getSystemService(String) |
| 5248 | * @see android.service.oemlock.OemLockManager |
| 5249 | * @hide |
| 5250 | */ |
| 5251 | @SystemApi |
| 5252 | public static final String OEM_LOCK_SERVICE = "oem_lock"; |
| 5253 | |
| 5254 | /** |
| 5255 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 5256 | * android.media.projection.MediaProjectionManager} instance for managing |
| 5257 | * media projection sessions. |
| 5258 | * @see #getSystemService(String) |
| 5259 | * @see android.media.projection.MediaProjectionManager |
| 5260 | */ |
| 5261 | public static final String MEDIA_PROJECTION_SERVICE = "media_projection"; |
| 5262 | |
| 5263 | /** |
| 5264 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5265 | * {@link android.media.midi.MidiManager} for accessing the MIDI service. |
| 5266 | * |
| 5267 | * @see #getSystemService(String) |
| 5268 | */ |
| 5269 | public static final String MIDI_SERVICE = "midi"; |
| 5270 | |
| 5271 | |
| 5272 | /** |
| 5273 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5274 | * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service. |
| 5275 | * |
| 5276 | * @see #getSystemService(String) |
| 5277 | * @hide |
| 5278 | */ |
| 5279 | public static final String RADIO_SERVICE = "broadcastradio"; |
| 5280 | |
| 5281 | /** |
| 5282 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5283 | * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service. |
| 5284 | * |
| 5285 | * @see #getSystemService(String) |
| 5286 | */ |
| 5287 | public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties"; |
| 5288 | |
| 5289 | /** |
| 5290 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5291 | * {@link android.os.ThermalService} for accessing the thermal service. |
| 5292 | * |
| 5293 | * @see #getSystemService(String) |
| 5294 | * @hide |
| 5295 | */ |
| 5296 | public static final String THERMAL_SERVICE = "thermalservice"; |
| 5297 | |
| 5298 | /** |
| 5299 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5300 | * {@link android.os.PerformanceHintManager} for accessing the performance hinting service. |
| 5301 | * |
| 5302 | * @see #getSystemService(String) |
| 5303 | */ |
| 5304 | public static final String PERFORMANCE_HINT_SERVICE = "performance_hint"; |
| 5305 | |
| 5306 | /** |
| 5307 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5308 | * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service. |
| 5309 | * |
| 5310 | * @see #getSystemService(String) |
| 5311 | * @see android.content.pm.ShortcutManager |
| 5312 | */ |
| 5313 | public static final String SHORTCUT_SERVICE = "shortcut"; |
| 5314 | |
| 5315 | /** |
| 5316 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 5317 | * android.hardware.location.ContextHubManager} for accessing context hubs. |
| 5318 | * |
| 5319 | * @see #getSystemService(String) |
| 5320 | * @see android.hardware.location.ContextHubManager |
| 5321 | * |
| 5322 | * @hide |
| 5323 | */ |
| 5324 | @SystemApi |
| 5325 | public static final String CONTEXTHUB_SERVICE = "contexthub"; |
| 5326 | |
| 5327 | /** |
| 5328 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5329 | * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power, |
| 5330 | * memory, etc) metrics. |
| 5331 | * |
| 5332 | * @see #getSystemService(String) |
| 5333 | */ |
| 5334 | public static final String SYSTEM_HEALTH_SERVICE = "systemhealth"; |
| 5335 | |
| 5336 | /** |
| 5337 | * Gatekeeper Service. |
| 5338 | * @hide |
| 5339 | */ |
| 5340 | public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService"; |
| 5341 | |
| 5342 | /** |
| 5343 | * Service defining the policy for access to device identifiers. |
| 5344 | * @hide |
| 5345 | */ |
| 5346 | public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers"; |
| 5347 | |
| 5348 | /** |
| 5349 | * Service to report a system health "incident" |
| 5350 | * @hide |
| 5351 | */ |
| 5352 | public static final String INCIDENT_SERVICE = "incident"; |
| 5353 | |
| 5354 | /** |
| 5355 | * Service to assist incidentd and dumpstated in reporting status to the user |
| 5356 | * and in confirming authorization to take an incident report or bugreport |
| 5357 | * @hide |
| 5358 | */ |
| 5359 | public static final String INCIDENT_COMPANION_SERVICE = "incidentcompanion"; |
| 5360 | |
| 5361 | /** |
| 5362 | * Service to assist {@link android.app.StatsManager} that lives in system server. |
| 5363 | * @hide |
| 5364 | */ |
| 5365 | public static final String STATS_MANAGER_SERVICE = "statsmanager"; |
| 5366 | |
| 5367 | /** |
| 5368 | * Service to assist statsd in obtaining general stats. |
| 5369 | * @hide |
| 5370 | */ |
| 5371 | public static final String STATS_COMPANION_SERVICE = "statscompanion"; |
| 5372 | |
| 5373 | /** |
| 5374 | * Use with {@link #getSystemService(String)} to retrieve an {@link android.app.StatsManager}. |
| 5375 | * @hide |
| 5376 | */ |
| 5377 | @SystemApi |
| 5378 | public static final String STATS_MANAGER = "stats"; |
| 5379 | |
| 5380 | /** |
| 5381 | * Use with {@link android.os.ServiceManager.getService()} to retrieve a |
| 5382 | * {@link IPlatformCompat} IBinder for communicating with the platform compat service. |
| 5383 | * @hide |
| 5384 | */ |
| 5385 | public static final String PLATFORM_COMPAT_SERVICE = "platform_compat"; |
| 5386 | |
| 5387 | /** |
| 5388 | * Use with {@link android.os.ServiceManager.getService()} to retrieve a |
| 5389 | * {@link IPlatformCompatNative} IBinder for native code communicating with the platform compat |
| 5390 | * service. |
| 5391 | * @hide |
| 5392 | */ |
| 5393 | public static final String PLATFORM_COMPAT_NATIVE_SERVICE = "platform_compat_native"; |
| 5394 | |
| 5395 | /** |
| 5396 | * Service to capture a bugreport. |
| 5397 | * @see #getSystemService(String) |
| 5398 | * @see android.os.BugreportManager |
| 5399 | */ |
| 5400 | public static final String BUGREPORT_SERVICE = "bugreport"; |
| 5401 | |
| 5402 | /** |
| 5403 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 5404 | * android.content.om.OverlayManager} for managing overlay packages. |
| 5405 | * |
| 5406 | * @see #getSystemService(String) |
| 5407 | * @see android.content.om.OverlayManager |
| 5408 | * @hide |
| 5409 | */ |
| 5410 | public static final String OVERLAY_SERVICE = "overlay"; |
| 5411 | |
| 5412 | /** |
| 5413 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5414 | * {android.os.IIdmap2} for managing idmap files (used by overlay |
| 5415 | * packages). |
| 5416 | * |
| 5417 | * @see #getSystemService(String) |
| 5418 | * @hide |
| 5419 | */ |
| 5420 | public static final String IDMAP_SERVICE = "idmap"; |
| 5421 | |
| 5422 | /** |
| 5423 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5424 | * {@link VrManager} for accessing the VR service. |
| 5425 | * |
| 5426 | * @see #getSystemService(String) |
| 5427 | * @hide |
| 5428 | */ |
| 5429 | @SystemApi |
| 5430 | public static final String VR_SERVICE = "vrmanager"; |
| 5431 | |
| 5432 | /** |
| 5433 | * Use with {@link #getSystemService(String)} to retrieve an |
| 5434 | * {@link android.app.timezone.ITimeZoneRulesManager}. |
| 5435 | * @hide |
| 5436 | * |
| 5437 | * @see #getSystemService(String) |
| 5438 | */ |
| 5439 | public static final String TIME_ZONE_RULES_MANAGER_SERVICE = "timezone"; |
| 5440 | |
| 5441 | /** |
| 5442 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5443 | * {@link android.content.pm.CrossProfileApps} for cross profile operations. |
| 5444 | * |
| 5445 | * @see #getSystemService(String) |
| 5446 | */ |
| 5447 | public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps"; |
| 5448 | |
| 5449 | /** |
| 5450 | * Use with {@link #getSystemService} to retrieve a |
| 5451 | * {@link android.se.omapi.ISecureElementService} |
| 5452 | * for accessing the SecureElementService. |
| 5453 | * |
| 5454 | * @hide |
| 5455 | */ |
| 5456 | @SystemApi |
| 5457 | public static final String SECURE_ELEMENT_SERVICE = "secure_element"; |
| 5458 | |
| 5459 | /** |
| 5460 | * Use with {@link #getSystemService(String)} to retrieve an |
| 5461 | * {@link android.app.timedetector.TimeDetector}. |
| 5462 | * @hide |
| 5463 | * |
| 5464 | * @see #getSystemService(String) |
| 5465 | */ |
| 5466 | public static final String TIME_DETECTOR_SERVICE = "time_detector"; |
| 5467 | |
| 5468 | /** |
| 5469 | * Use with {@link #getSystemService(String)} to retrieve an |
| 5470 | * {@link android.app.timezonedetector.TimeZoneDetector}. |
| 5471 | * @hide |
| 5472 | * |
| 5473 | * @see #getSystemService(String) |
| 5474 | */ |
| 5475 | public static final String TIME_ZONE_DETECTOR_SERVICE = "time_zone_detector"; |
| 5476 | |
| 5477 | /** |
| 5478 | * Use with {@link #getSystemService(String)} to retrieve an {@link TimeManager}. |
| 5479 | * @hide |
| 5480 | * |
| 5481 | * @see #getSystemService(String) |
| 5482 | */ |
| 5483 | public static final String TIME_MANAGER = "time_manager"; |
| 5484 | |
| 5485 | /** |
| 5486 | * Binder service name for {@link AppBindingService}. |
| 5487 | * @hide |
| 5488 | */ |
| 5489 | public static final String APP_BINDING_SERVICE = "app_binding"; |
| 5490 | |
| 5491 | /** |
| 5492 | * Use with {@link #getSystemService(String)} to retrieve an |
| 5493 | * {@link android.telephony.ims.ImsManager}. |
| 5494 | */ |
| 5495 | public static final String TELEPHONY_IMS_SERVICE = "telephony_ims"; |
| 5496 | |
| 5497 | /** |
| 5498 | * Use with {@link #getSystemService(String)} to retrieve an |
| 5499 | * {@link android.os.SystemConfigManager}. |
| 5500 | * @hide |
| 5501 | */ |
| 5502 | @SystemApi |
| 5503 | public static final String SYSTEM_CONFIG_SERVICE = "system_config"; |
| 5504 | |
| 5505 | /** |
| 5506 | * Use with {@link #getSystemService(String)} to retrieve an |
| 5507 | * {@link android.telephony.ims.RcsMessageManager}. |
| 5508 | * @hide |
| 5509 | */ |
| 5510 | public static final String TELEPHONY_RCS_MESSAGE_SERVICE = "ircsmessage"; |
| 5511 | |
| 5512 | /** |
| 5513 | * Use with {@link #getSystemService(String)} to retrieve an |
| 5514 | * {@link android.os.image.DynamicSystemManager}. |
| 5515 | * @hide |
| 5516 | */ |
| 5517 | public static final String DYNAMIC_SYSTEM_SERVICE = "dynamic_system"; |
| 5518 | |
| 5519 | /** |
| 5520 | * Use with {@link #getSystemService(String)} to retrieve a {@link |
| 5521 | * android.app.blob.BlobStoreManager} for contributing and accessing data blobs |
| 5522 | * from the blob store maintained by the system. |
| 5523 | * |
| 5524 | * @see #getSystemService(String) |
| 5525 | * @see android.app.blob.BlobStoreManager |
| 5526 | */ |
| 5527 | public static final String BLOB_STORE_SERVICE = "blob_store"; |
| 5528 | |
| 5529 | /** |
| 5530 | * Use with {@link #getSystemService(String)} to retrieve an |
| 5531 | * {@link TelephonyRegistryManager}. |
| 5532 | * @hide |
| 5533 | */ |
| 5534 | public static final String TELEPHONY_REGISTRY_SERVICE = "telephony_registry"; |
| 5535 | |
| 5536 | /** |
| 5537 | * Use with {@link #getSystemService(String)} to retrieve an |
| 5538 | * {@link android.os.BatteryStatsManager}. |
| 5539 | * @hide |
| 5540 | */ |
| 5541 | @SystemApi |
| 5542 | @SuppressLint("ServiceName") |
| 5543 | public static final String BATTERY_STATS_SERVICE = "batterystats"; |
| 5544 | |
| 5545 | /** |
| 5546 | * Use with {@link #getSystemService(String)} to retrieve an |
| 5547 | * {@link android.app.appsearch.AppSearchManager} for |
| 5548 | * indexing and querying app data managed by the system. |
| 5549 | * |
| 5550 | * @see #getSystemService(String) |
| 5551 | */ |
| 5552 | public static final String APP_SEARCH_SERVICE = "app_search"; |
| 5553 | |
| 5554 | /** |
| 5555 | * Use with {@link #getSystemService(String)} to retrieve an |
| 5556 | * {@link android.content.integrity.AppIntegrityManager}. |
| 5557 | * @hide |
| 5558 | */ |
| 5559 | @SystemApi |
| 5560 | public static final String APP_INTEGRITY_SERVICE = "app_integrity"; |
| 5561 | |
| 5562 | /** |
| 5563 | * Use with {@link #getSystemService(String)} to retrieve an |
| 5564 | * {@link android.content.pm.DataLoaderManager}. |
| 5565 | * @hide |
| 5566 | */ |
| 5567 | public static final String DATA_LOADER_MANAGER_SERVICE = "dataloader_manager"; |
| 5568 | |
| 5569 | /** |
| 5570 | * Use with {@link #getSystemService(String)} to retrieve an |
| 5571 | * {@link android.os.incremental.IncrementalManager}. |
| 5572 | * @hide |
| 5573 | */ |
| 5574 | public static final String INCREMENTAL_SERVICE = "incremental"; |
| 5575 | |
| 5576 | /** |
| 5577 | * Use with {@link #getSystemService(String)} to retrieve an |
| 5578 | * {@link android.security.FileIntegrityManager}. |
| 5579 | * @see #getSystemService(String) |
| 5580 | * @see android.security.FileIntegrityManager |
| 5581 | */ |
| 5582 | public static final String FILE_INTEGRITY_SERVICE = "file_integrity"; |
| 5583 | |
| 5584 | /** |
| 5585 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5586 | * {@link android.hardware.lights.LightsManager} for controlling device lights. |
| 5587 | * |
| 5588 | * @see #getSystemService(String) |
| 5589 | * @hide |
| 5590 | */ |
| 5591 | public static final String LIGHTS_SERVICE = "lights"; |
| 5592 | |
| 5593 | /** |
| 5594 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5595 | * {@link android.uwb.UwbManager}. |
| 5596 | * |
| 5597 | * @see #getSystemService(String) |
| 5598 | * @hide |
| 5599 | */ |
| 5600 | public static final String UWB_SERVICE = "uwb"; |
| 5601 | |
| 5602 | /** |
| 5603 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5604 | * {@link android.app.DreamManager} for controlling Dream states. |
| 5605 | * |
| 5606 | * @see #getSystemService(String) |
| 5607 | |
| 5608 | * @hide |
| 5609 | */ |
| 5610 | @TestApi |
| 5611 | public static final String DREAM_SERVICE = "dream"; |
| 5612 | |
| 5613 | /** |
| 5614 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5615 | * {@link android.telephony.SmsManager} for accessing Sms functionality. |
| 5616 | * |
| 5617 | * @see #getSystemService(String) |
| 5618 | |
| 5619 | * @hide |
| 5620 | */ |
| 5621 | public static final String SMS_SERVICE = "sms"; |
| 5622 | |
| 5623 | /** |
| 5624 | * Use with {@link #getSystemService(String)} to access a {@link PeopleManager} to interact |
| 5625 | * with your published conversations. |
| 5626 | * |
| 5627 | * @see #getSystemService(String) |
| 5628 | */ |
| 5629 | public static final String PEOPLE_SERVICE = "people"; |
| 5630 | |
| 5631 | /** |
| 5632 | * Use with {@link #getSystemService(String)} to access device state service. |
| 5633 | * |
| 5634 | * @see #getSystemService(String) |
| 5635 | * @hide |
| 5636 | */ |
| 5637 | public static final String DEVICE_STATE_SERVICE = "device_state"; |
| 5638 | |
| 5639 | /** |
| 5640 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5641 | * {@link android.media.metrics.MediaMetricsManager} for interacting with media metrics |
| 5642 | * on the device. |
| 5643 | * |
| 5644 | * @see #getSystemService(String) |
| 5645 | * @see android.media.metrics.MediaMetricsManager |
| 5646 | */ |
| 5647 | public static final String MEDIA_METRICS_SERVICE = "media_metrics"; |
| 5648 | |
| 5649 | /** |
| 5650 | * Use with {@link #getSystemService(String)} to access system speech recognition service. |
| 5651 | * |
| 5652 | * @see #getSystemService(String) |
| 5653 | * @hide |
| 5654 | */ |
| 5655 | public static final String SPEECH_RECOGNITION_SERVICE = "speech_recognition"; |
| 5656 | |
| 5657 | /** |
| 5658 | * Use with {@link #getSystemService(String)} to retrieve a |
| 5659 | * {@link GameManager}. |
| 5660 | * |
| 5661 | * @see #getSystemService(String) |
| 5662 | */ |
| 5663 | public static final String GAME_SERVICE = "game"; |
| 5664 | |
| 5665 | /** |
| 5666 | * Use with {@link #getSystemService(String)} to access |
| 5667 | * {@link android.content.pm.verify.domain.DomainVerificationManager} to retrieve approval and |
| 5668 | * user state for declared web domains. |
| 5669 | * |
| 5670 | * @see #getSystemService(String) |
| 5671 | * @see android.content.pm.verify.domain.DomainVerificationManager |
| 5672 | */ |
| 5673 | public static final String DOMAIN_VERIFICATION_SERVICE = "domain_verification"; |
| 5674 | |
| 5675 | /** |
| 5676 | * Use with {@link #getSystemService(String)} to access |
| 5677 | * {@link android.view.displayhash.DisplayHashManager} to handle display hashes. |
| 5678 | * |
| 5679 | * @see #getSystemService(String) |
| 5680 | */ |
| 5681 | public static final String DISPLAY_HASH_SERVICE = "display_hash"; |
| 5682 | |
| 5683 | /** |
| 5684 | * Determine whether the given permission is allowed for a particular |
| 5685 | * process and user ID running in the system. |
| 5686 | * |
| 5687 | * @param permission The name of the permission being checked. |
| 5688 | * @param pid The process ID being checked against. Must be > 0. |
| 5689 | * @param uid The user ID being checked against. A uid of 0 is the root |
| 5690 | * user, which will pass every permission check. |
| 5691 | * |
| 5692 | * @return {@link PackageManager#PERMISSION_GRANTED} if the given |
| 5693 | * pid/uid is allowed that permission, or |
| 5694 | * {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 5695 | * |
| 5696 | * @see PackageManager#checkPermission(String, String) |
| 5697 | * @see #checkCallingPermission |
| 5698 | */ |
| 5699 | @CheckResult(suggest="#enforcePermission(String,int,int,String)") |
| 5700 | @PackageManager.PermissionResult |
| 5701 | public abstract int checkPermission(@NonNull String permission, int pid, int uid); |
| 5702 | |
| 5703 | /** @hide */ |
| 5704 | @SuppressWarnings("HiddenAbstractMethod") |
| 5705 | @PackageManager.PermissionResult |
| 5706 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 5707 | public abstract int checkPermission(@NonNull String permission, int pid, int uid, |
| 5708 | IBinder callerToken); |
| 5709 | |
| 5710 | /** |
| 5711 | * Determine whether the calling process of an IPC you are handling has been |
| 5712 | * granted a particular permission. This is basically the same as calling |
| 5713 | * {@link #checkPermission(String, int, int)} with the pid and uid returned |
| 5714 | * by {@link android.os.Binder#getCallingPid} and |
| 5715 | * {@link android.os.Binder#getCallingUid}. One important difference |
| 5716 | * is that if you are not currently processing an IPC, this function |
| 5717 | * will always fail. This is done to protect against accidentally |
| 5718 | * leaking permissions; you can use {@link #checkCallingOrSelfPermission} |
| 5719 | * to avoid this protection. |
| 5720 | * |
| 5721 | * @param permission The name of the permission being checked. |
| 5722 | * |
| 5723 | * @return {@link PackageManager#PERMISSION_GRANTED} if the calling |
| 5724 | * pid/uid is allowed that permission, or |
| 5725 | * {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 5726 | * |
| 5727 | * @see PackageManager#checkPermission(String, String) |
| 5728 | * @see #checkPermission |
| 5729 | * @see #checkCallingOrSelfPermission |
| 5730 | */ |
| 5731 | @CheckResult(suggest="#enforceCallingPermission(String,String)") |
| 5732 | @PackageManager.PermissionResult |
| 5733 | public abstract int checkCallingPermission(@NonNull String permission); |
| 5734 | |
| 5735 | /** |
| 5736 | * Determine whether the calling process of an IPC <em>or you</em> have been |
| 5737 | * granted a particular permission. This is the same as |
| 5738 | * {@link #checkCallingPermission}, except it grants your own permissions |
| 5739 | * if you are not currently processing an IPC. Use with care! |
| 5740 | * |
| 5741 | * @param permission The name of the permission being checked. |
| 5742 | * |
| 5743 | * @return {@link PackageManager#PERMISSION_GRANTED} if the calling |
| 5744 | * pid/uid is allowed that permission, or |
| 5745 | * {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 5746 | * |
| 5747 | * @see PackageManager#checkPermission(String, String) |
| 5748 | * @see #checkPermission |
| 5749 | * @see #checkCallingPermission |
| 5750 | */ |
| 5751 | @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)") |
| 5752 | @PackageManager.PermissionResult |
| 5753 | public abstract int checkCallingOrSelfPermission(@NonNull String permission); |
| 5754 | |
| 5755 | /** |
| 5756 | * Determine whether <em>you</em> have been granted a particular permission. |
| 5757 | * |
| 5758 | * @param permission The name of the permission being checked. |
| 5759 | * |
| 5760 | * @return {@link PackageManager#PERMISSION_GRANTED} if you have the |
| 5761 | * permission, or {@link PackageManager#PERMISSION_DENIED} if not. |
| 5762 | * |
| 5763 | * @see PackageManager#checkPermission(String, String) |
| 5764 | * @see #checkCallingPermission(String) |
| 5765 | */ |
| 5766 | @PackageManager.PermissionResult |
| 5767 | public abstract int checkSelfPermission(@NonNull String permission); |
| 5768 | |
| 5769 | /** |
| 5770 | * If the given permission is not allowed for a particular process |
| 5771 | * and user ID running in the system, throw a {@link SecurityException}. |
| 5772 | * |
| 5773 | * @param permission The name of the permission being checked. |
| 5774 | * @param pid The process ID being checked against. Must be > 0. |
| 5775 | * @param uid The user ID being checked against. A uid of 0 is the root |
| 5776 | * user, which will pass every permission check. |
| 5777 | * @param message A message to include in the exception if it is thrown. |
| 5778 | * |
| 5779 | * @see #checkPermission(String, int, int) |
| 5780 | */ |
| 5781 | public abstract void enforcePermission( |
| 5782 | @NonNull String permission, int pid, int uid, @Nullable String message); |
| 5783 | |
| 5784 | /** |
| 5785 | * If the calling process of an IPC you are handling has not been |
| 5786 | * granted a particular permission, throw a {@link |
| 5787 | * SecurityException}. This is basically the same as calling |
| 5788 | * {@link #enforcePermission(String, int, int, String)} with the |
| 5789 | * pid and uid returned by {@link android.os.Binder#getCallingPid} |
| 5790 | * and {@link android.os.Binder#getCallingUid}. One important |
| 5791 | * difference is that if you are not currently processing an IPC, |
| 5792 | * this function will always throw the SecurityException. This is |
| 5793 | * done to protect against accidentally leaking permissions; you |
| 5794 | * can use {@link #enforceCallingOrSelfPermission} to avoid this |
| 5795 | * protection. |
| 5796 | * |
| 5797 | * @param permission The name of the permission being checked. |
| 5798 | * @param message A message to include in the exception if it is thrown. |
| 5799 | * |
| 5800 | * @see #checkCallingPermission(String) |
| 5801 | */ |
| 5802 | public abstract void enforceCallingPermission( |
| 5803 | @NonNull String permission, @Nullable String message); |
| 5804 | |
| 5805 | /** |
| 5806 | * If neither you nor the calling process of an IPC you are |
| 5807 | * handling has been granted a particular permission, throw a |
| 5808 | * {@link SecurityException}. This is the same as {@link |
| 5809 | * #enforceCallingPermission}, except it grants your own |
| 5810 | * permissions if you are not currently processing an IPC. Use |
| 5811 | * with care! |
| 5812 | * |
| 5813 | * @param permission The name of the permission being checked. |
| 5814 | * @param message A message to include in the exception if it is thrown. |
| 5815 | * |
| 5816 | * @see #checkCallingOrSelfPermission(String) |
| 5817 | */ |
| 5818 | public abstract void enforceCallingOrSelfPermission( |
| 5819 | @NonNull String permission, @Nullable String message); |
| 5820 | |
| 5821 | /** |
| 5822 | * Grant permission to access a specific Uri to another package, regardless |
| 5823 | * of whether that package has general permission to access the Uri's |
| 5824 | * content provider. This can be used to grant specific, temporary |
| 5825 | * permissions, typically in response to user interaction (such as the |
| 5826 | * user opening an attachment that you would like someone else to |
| 5827 | * display). |
| 5828 | * |
| 5829 | * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION |
| 5830 | * Intent.FLAG_GRANT_READ_URI_PERMISSION} or |
| 5831 | * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 5832 | * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to |
| 5833 | * start an activity instead of this function directly. If you use this |
| 5834 | * function directly, you should be sure to call |
| 5835 | * {@link #revokeUriPermission} when the target should no longer be allowed |
| 5836 | * to access it. |
| 5837 | * |
| 5838 | * <p>To succeed, the content provider owning the Uri must have set the |
| 5839 | * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions |
| 5840 | * grantUriPermissions} attribute in its manifest or included the |
| 5841 | * {@link android.R.styleable#AndroidManifestGrantUriPermission |
| 5842 | * <grant-uri-permissions>} tag. |
| 5843 | * |
| 5844 | * @param toPackage The package you would like to allow to access the Uri. |
| 5845 | * @param uri The Uri you would like to grant access to. |
| 5846 | * @param modeFlags The desired access modes. |
| 5847 | * |
| 5848 | * @see #revokeUriPermission |
| 5849 | */ |
| 5850 | public abstract void grantUriPermission(String toPackage, Uri uri, |
| 5851 | @Intent.GrantUriMode int modeFlags); |
| 5852 | |
| 5853 | /** |
| 5854 | * Remove all permissions to access a particular content provider Uri |
| 5855 | * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism. |
| 5856 | * The given Uri will match all previously granted Uris that are the same or a |
| 5857 | * sub-path of the given Uri. That is, revoking "content://foo/target" will |
| 5858 | * revoke both "content://foo/target" and "content://foo/target/sub", but not |
| 5859 | * "content://foo". It will not remove any prefix grants that exist at a |
| 5860 | * higher level. |
| 5861 | * |
| 5862 | * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have |
| 5863 | * regular permission access to a Uri, but had received access to it through |
| 5864 | * a specific Uri permission grant, you could not revoke that grant with this |
| 5865 | * function and a {@link SecurityException} would be thrown. As of |
| 5866 | * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security |
| 5867 | * exception, but will remove whatever permission grants to the Uri had been given to the app |
| 5868 | * (or none).</p> |
| 5869 | * |
| 5870 | * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission |
| 5871 | * grants matching the given Uri, for any package they had been granted to, through any |
| 5872 | * mechanism this had happened (such as indirectly through the clipboard, activity launch, |
| 5873 | * service start, etc). That means this can be potentially dangerous to use, as it can |
| 5874 | * revoke grants that another app could be strongly expecting to stick around.</p> |
| 5875 | * |
| 5876 | * @param uri The Uri you would like to revoke access to. |
| 5877 | * @param modeFlags The access modes to revoke. |
| 5878 | * |
| 5879 | * @see #grantUriPermission |
| 5880 | */ |
| 5881 | public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags); |
| 5882 | |
| 5883 | /** |
| 5884 | * Remove permissions to access a particular content provider Uri |
| 5885 | * that were previously added with {@link #grantUriPermission} for a specific target |
| 5886 | * package. The given Uri will match all previously granted Uris that are the same or a |
| 5887 | * sub-path of the given Uri. That is, revoking "content://foo/target" will |
| 5888 | * revoke both "content://foo/target" and "content://foo/target/sub", but not |
| 5889 | * "content://foo". It will not remove any prefix grants that exist at a |
| 5890 | * higher level. |
| 5891 | * |
| 5892 | * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em> |
| 5893 | * revoke permissions that had been explicitly granted through {@link #grantUriPermission} |
| 5894 | * and only for the package specified. Any matching grants that have happened through |
| 5895 | * other mechanisms (clipboard, activity launching, service starting, etc) will not be |
| 5896 | * removed.</p> |
| 5897 | * |
| 5898 | * @param toPackage The package you had previously granted access to. |
| 5899 | * @param uri The Uri you would like to revoke access to. |
| 5900 | * @param modeFlags The access modes to revoke. |
| 5901 | * |
| 5902 | * @see #grantUriPermission |
| 5903 | */ |
| 5904 | public abstract void revokeUriPermission(String toPackage, Uri uri, |
| 5905 | @Intent.AccessUriMode int modeFlags); |
| 5906 | |
| 5907 | /** |
| 5908 | * Determine whether a particular process and user ID has been granted |
| 5909 | * permission to access a specific URI. This only checks for permissions |
| 5910 | * that have been explicitly granted -- if the given process/uid has |
| 5911 | * more general access to the URI's content provider then this check will |
| 5912 | * always fail. |
| 5913 | * |
| 5914 | * @param uri The uri that is being checked. |
| 5915 | * @param pid The process ID being checked against. Must be > 0. |
| 5916 | * @param uid The user ID being checked against. A uid of 0 is the root |
| 5917 | * user, which will pass every permission check. |
| 5918 | * @param modeFlags The access modes to check. |
| 5919 | * |
| 5920 | * @return {@link PackageManager#PERMISSION_GRANTED} if the given |
| 5921 | * pid/uid is allowed to access that uri, or |
| 5922 | * {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 5923 | * |
| 5924 | * @see #checkCallingUriPermission |
| 5925 | */ |
| 5926 | @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)") |
| 5927 | @PackageManager.PermissionResult |
| 5928 | public abstract int checkUriPermission(Uri uri, int pid, int uid, |
| 5929 | @Intent.AccessUriMode int modeFlags); |
| 5930 | |
| 5931 | /** |
| 5932 | * Determine whether a particular process and user ID has been granted |
| 5933 | * permission to access a list of URIs. This only checks for permissions |
| 5934 | * that have been explicitly granted -- if the given process/uid has |
| 5935 | * more general access to the URI's content provider then this check will |
| 5936 | * always fail. |
| 5937 | * |
| 5938 | * @param uris The list of URIs that is being checked. |
| 5939 | * @param pid The process ID being checked against. Must be > 0. |
| 5940 | * @param uid The user ID being checked against. A uid of 0 is the root |
| 5941 | * user, which will pass every permission check. |
| 5942 | * @param modeFlags The access modes to check for the list of uris |
| 5943 | * |
| 5944 | * @return Array of permission grants corresponding to each entry in the list of uris. |
| 5945 | * {@link PackageManager#PERMISSION_GRANTED} if the given pid/uid is allowed to access that uri, |
| 5946 | * or {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 5947 | * |
| 5948 | * @see #checkCallingUriPermission |
| 5949 | */ |
| 5950 | @NonNull |
| 5951 | @PackageManager.PermissionResult |
| 5952 | public int[] checkUriPermissions(@NonNull List<Uri> uris, int pid, int uid, |
| 5953 | @Intent.AccessUriMode int modeFlags) { |
| 5954 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 5955 | } |
| 5956 | |
| 5957 | /** @hide */ |
| 5958 | @SuppressWarnings("HiddenAbstractMethod") |
| 5959 | @PackageManager.PermissionResult |
| 5960 | public abstract int checkUriPermission(Uri uri, int pid, int uid, |
| 5961 | @Intent.AccessUriMode int modeFlags, IBinder callerToken); |
| 5962 | |
| 5963 | /** |
| 5964 | * Determine whether the calling process and user ID has been |
| 5965 | * granted permission to access a specific URI. This is basically |
| 5966 | * the same as calling {@link #checkUriPermission(Uri, int, int, |
| 5967 | * int)} with the pid and uid returned by {@link |
| 5968 | * android.os.Binder#getCallingPid} and {@link |
| 5969 | * android.os.Binder#getCallingUid}. One important difference is |
| 5970 | * that if you are not currently processing an IPC, this function |
| 5971 | * will always fail. |
| 5972 | * |
| 5973 | * @param uri The uri that is being checked. |
| 5974 | * @param modeFlags The access modes to check. |
| 5975 | * |
| 5976 | * @return {@link PackageManager#PERMISSION_GRANTED} if the caller |
| 5977 | * is allowed to access that uri, or |
| 5978 | * {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 5979 | * |
| 5980 | * @see #checkUriPermission(Uri, int, int, int) |
| 5981 | */ |
| 5982 | @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)") |
| 5983 | @PackageManager.PermissionResult |
| 5984 | public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags); |
| 5985 | |
| 5986 | /** |
| 5987 | * Determine whether the calling process and user ID has been |
| 5988 | * granted permission to access a list of URIs. This is basically |
| 5989 | * the same as calling {@link #checkUriPermissions(List, int, int, int)} |
| 5990 | * with the pid and uid returned by {@link |
| 5991 | * android.os.Binder#getCallingPid} and {@link |
| 5992 | * android.os.Binder#getCallingUid}. One important difference is |
| 5993 | * that if you are not currently processing an IPC, this function |
| 5994 | * will always fail. |
| 5995 | * |
| 5996 | * @param uris The list of URIs that is being checked. |
| 5997 | * @param modeFlags The access modes to check. |
| 5998 | * |
| 5999 | * @return Array of permission grants corresponding to each entry in the list of uris. |
| 6000 | * {@link PackageManager#PERMISSION_GRANTED} if the given pid/uid is allowed to access that uri, |
| 6001 | * or {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 6002 | * |
| 6003 | * @see #checkUriPermission(Uri, int, int, int) |
| 6004 | */ |
| 6005 | @NonNull |
| 6006 | @PackageManager.PermissionResult |
| 6007 | public int[] checkCallingUriPermissions(@NonNull List<Uri> uris, |
| 6008 | @Intent.AccessUriMode int modeFlags) { |
| 6009 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6010 | } |
| 6011 | |
| 6012 | /** |
| 6013 | * Determine whether the calling process of an IPC <em>or you</em> has been granted |
| 6014 | * permission to access a specific URI. This is the same as |
| 6015 | * {@link #checkCallingUriPermission}, except it grants your own permissions |
| 6016 | * if you are not currently processing an IPC. Use with care! |
| 6017 | * |
| 6018 | * @param uri The uri that is being checked. |
| 6019 | * @param modeFlags The access modes to check. |
| 6020 | * |
| 6021 | * @return {@link PackageManager#PERMISSION_GRANTED} if the caller |
| 6022 | * is allowed to access that uri, or |
| 6023 | * {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 6024 | * |
| 6025 | * @see #checkCallingUriPermission |
| 6026 | */ |
| 6027 | @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)") |
| 6028 | @PackageManager.PermissionResult |
| 6029 | public abstract int checkCallingOrSelfUriPermission(Uri uri, |
| 6030 | @Intent.AccessUriMode int modeFlags); |
| 6031 | |
| 6032 | /** |
| 6033 | * Determine whether the calling process of an IPC <em>or you</em> has been granted |
| 6034 | * permission to access a list of URIs. This is the same as |
| 6035 | * {@link #checkCallingUriPermission}, except it grants your own permissions |
| 6036 | * if you are not currently processing an IPC. Use with care! |
| 6037 | * |
| 6038 | * @param uris The list of URIs that is being checked. |
| 6039 | * @param modeFlags The access modes to check. |
| 6040 | * |
| 6041 | * @return Array of permission grants corresponding to each entry in the list of uris. |
| 6042 | * {@link PackageManager#PERMISSION_GRANTED} if the given pid/uid is allowed to access that uri, |
| 6043 | * or {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 6044 | * |
| 6045 | * @see #checkCallingUriPermission |
| 6046 | */ |
| 6047 | @NonNull |
| 6048 | @PackageManager.PermissionResult |
| 6049 | public int[] checkCallingOrSelfUriPermissions(@NonNull List<Uri> uris, |
| 6050 | @Intent.AccessUriMode int modeFlags) { |
| 6051 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6052 | } |
| 6053 | |
| 6054 | /** |
| 6055 | * Check both a Uri and normal permission. This allows you to perform |
| 6056 | * both {@link #checkPermission} and {@link #checkUriPermission} in one |
| 6057 | * call. |
| 6058 | * |
| 6059 | * @param uri The Uri whose permission is to be checked, or null to not |
| 6060 | * do this check. |
| 6061 | * @param readPermission The permission that provides overall read access, |
| 6062 | * or null to not do this check. |
| 6063 | * @param writePermission The permission that provides overall write |
| 6064 | * access, or null to not do this check. |
| 6065 | * @param pid The process ID being checked against. Must be > 0. |
| 6066 | * @param uid The user ID being checked against. A uid of 0 is the root |
| 6067 | * user, which will pass every permission check. |
| 6068 | * @param modeFlags The access modes to check. |
| 6069 | * |
| 6070 | * @return {@link PackageManager#PERMISSION_GRANTED} if the caller |
| 6071 | * is allowed to access that uri or holds one of the given permissions, or |
| 6072 | * {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 6073 | */ |
| 6074 | @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)") |
| 6075 | @PackageManager.PermissionResult |
| 6076 | public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission, |
| 6077 | @Nullable String writePermission, int pid, int uid, |
| 6078 | @Intent.AccessUriMode int modeFlags); |
| 6079 | |
| 6080 | /** |
| 6081 | * If a particular process and user ID has not been granted |
| 6082 | * permission to access a specific URI, throw {@link |
| 6083 | * SecurityException}. This only checks for permissions that have |
| 6084 | * been explicitly granted -- if the given process/uid has more |
| 6085 | * general access to the URI's content provider then this check |
| 6086 | * will always fail. |
| 6087 | * |
| 6088 | * @param uri The uri that is being checked. |
| 6089 | * @param pid The process ID being checked against. Must be > 0. |
| 6090 | * @param uid The user ID being checked against. A uid of 0 is the root |
| 6091 | * user, which will pass every permission check. |
| 6092 | * @param modeFlags The access modes to enforce. |
| 6093 | * @param message A message to include in the exception if it is thrown. |
| 6094 | * |
| 6095 | * @see #checkUriPermission(Uri, int, int, int) |
| 6096 | */ |
| 6097 | public abstract void enforceUriPermission( |
| 6098 | Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message); |
| 6099 | |
| 6100 | /** |
| 6101 | * If the calling process and user ID has not been granted |
| 6102 | * permission to access a specific URI, throw {@link |
| 6103 | * SecurityException}. This is basically the same as calling |
| 6104 | * {@link #enforceUriPermission(Uri, int, int, int, String)} with |
| 6105 | * the pid and uid returned by {@link |
| 6106 | * android.os.Binder#getCallingPid} and {@link |
| 6107 | * android.os.Binder#getCallingUid}. One important difference is |
| 6108 | * that if you are not currently processing an IPC, this function |
| 6109 | * will always throw a SecurityException. |
| 6110 | * |
| 6111 | * @param uri The uri that is being checked. |
| 6112 | * @param modeFlags The access modes to enforce. |
| 6113 | * @param message A message to include in the exception if it is thrown. |
| 6114 | * |
| 6115 | * @see #checkCallingUriPermission(Uri, int) |
| 6116 | */ |
| 6117 | public abstract void enforceCallingUriPermission( |
| 6118 | Uri uri, @Intent.AccessUriMode int modeFlags, String message); |
| 6119 | |
| 6120 | /** |
| 6121 | * If the calling process of an IPC <em>or you</em> has not been |
| 6122 | * granted permission to access a specific URI, throw {@link |
| 6123 | * SecurityException}. This is the same as {@link |
| 6124 | * #enforceCallingUriPermission}, except it grants your own |
| 6125 | * permissions if you are not currently processing an IPC. Use |
| 6126 | * with care! |
| 6127 | * |
| 6128 | * @param uri The uri that is being checked. |
| 6129 | * @param modeFlags The access modes to enforce. |
| 6130 | * @param message A message to include in the exception if it is thrown. |
| 6131 | * |
| 6132 | * @see #checkCallingOrSelfUriPermission(Uri, int) |
| 6133 | */ |
| 6134 | public abstract void enforceCallingOrSelfUriPermission( |
| 6135 | Uri uri, @Intent.AccessUriMode int modeFlags, String message); |
| 6136 | |
| 6137 | /** |
| 6138 | * Enforce both a Uri and normal permission. This allows you to perform |
| 6139 | * both {@link #enforcePermission} and {@link #enforceUriPermission} in one |
| 6140 | * call. |
| 6141 | * |
| 6142 | * @param uri The Uri whose permission is to be checked, or null to not |
| 6143 | * do this check. |
| 6144 | * @param readPermission The permission that provides overall read access, |
| 6145 | * or null to not do this check. |
| 6146 | * @param writePermission The permission that provides overall write |
| 6147 | * access, or null to not do this check. |
| 6148 | * @param pid The process ID being checked against. Must be > 0. |
| 6149 | * @param uid The user ID being checked against. A uid of 0 is the root |
| 6150 | * user, which will pass every permission check. |
| 6151 | * @param modeFlags The access modes to enforce. |
| 6152 | * @param message A message to include in the exception if it is thrown. |
| 6153 | * |
| 6154 | * @see #checkUriPermission(Uri, String, String, int, int, int) |
| 6155 | */ |
| 6156 | public abstract void enforceUriPermission( |
| 6157 | @Nullable Uri uri, @Nullable String readPermission, |
| 6158 | @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags, |
| 6159 | @Nullable String message); |
| 6160 | |
| 6161 | /** @hide */ |
| 6162 | @IntDef(flag = true, prefix = { "CONTEXT_" }, value = { |
| 6163 | CONTEXT_INCLUDE_CODE, |
| 6164 | CONTEXT_IGNORE_SECURITY, |
| 6165 | CONTEXT_RESTRICTED, |
| 6166 | CONTEXT_DEVICE_PROTECTED_STORAGE, |
| 6167 | CONTEXT_CREDENTIAL_PROTECTED_STORAGE, |
| 6168 | CONTEXT_REGISTER_PACKAGE, |
| 6169 | }) |
| 6170 | @Retention(RetentionPolicy.SOURCE) |
| 6171 | public @interface CreatePackageOptions {} |
| 6172 | |
| 6173 | /** |
| 6174 | * Flag for use with {@link #createPackageContext}: include the application |
| 6175 | * code with the context. This means loading code into the caller's |
| 6176 | * process, so that {@link #getClassLoader()} can be used to instantiate |
| 6177 | * the application's classes. Setting this flags imposes security |
| 6178 | * restrictions on what application context you can access; if the |
| 6179 | * requested application can not be safely loaded into your process, |
| 6180 | * java.lang.SecurityException will be thrown. If this flag is not set, |
| 6181 | * there will be no restrictions on the packages that can be loaded, |
| 6182 | * but {@link #getClassLoader} will always return the default system |
| 6183 | * class loader. |
| 6184 | */ |
| 6185 | public static final int CONTEXT_INCLUDE_CODE = 0x00000001; |
| 6186 | |
| 6187 | /** |
| 6188 | * Flag for use with {@link #createPackageContext}: ignore any security |
| 6189 | * restrictions on the Context being requested, allowing it to always |
| 6190 | * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code |
| 6191 | * to be loaded into a process even when it isn't safe to do so. Use |
| 6192 | * with extreme care! |
| 6193 | */ |
| 6194 | public static final int CONTEXT_IGNORE_SECURITY = 0x00000002; |
| 6195 | |
| 6196 | /** |
| 6197 | * Flag for use with {@link #createPackageContext}: a restricted context may |
| 6198 | * disable specific features. For instance, a View associated with a restricted |
| 6199 | * context would ignore particular XML attributes. |
| 6200 | */ |
| 6201 | public static final int CONTEXT_RESTRICTED = 0x00000004; |
| 6202 | |
| 6203 | /** |
| 6204 | * Flag for use with {@link #createPackageContext}: point all file APIs at |
| 6205 | * device-protected storage. |
| 6206 | * |
| 6207 | * @hide |
| 6208 | */ |
| 6209 | public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008; |
| 6210 | |
| 6211 | /** |
| 6212 | * Flag for use with {@link #createPackageContext}: point all file APIs at |
| 6213 | * credential-protected storage. |
| 6214 | * |
| 6215 | * @hide |
| 6216 | */ |
| 6217 | public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010; |
| 6218 | |
| 6219 | /** |
| 6220 | * @hide Used to indicate we should tell the activity manager about the process |
| 6221 | * loading this code. |
| 6222 | */ |
| 6223 | public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000; |
| 6224 | |
| 6225 | /** |
| 6226 | * Return a new Context object for the given application name. This |
| 6227 | * Context is the same as what the named application gets when it is |
| 6228 | * launched, containing the same resources and class loader. Each call to |
| 6229 | * this method returns a new instance of a Context object; Context objects |
| 6230 | * are not shared, however they share common state (Resources, ClassLoader, |
| 6231 | * etc) so the Context instance itself is fairly lightweight. |
| 6232 | * |
| 6233 | * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no |
| 6234 | * application with the given package name. |
| 6235 | * |
| 6236 | * <p>Throws {@link java.lang.SecurityException} if the Context requested |
| 6237 | * can not be loaded into the caller's process for security reasons (see |
| 6238 | * {@link #CONTEXT_INCLUDE_CODE} for more information}. |
| 6239 | * |
| 6240 | * @param packageName Name of the application's package. |
| 6241 | * @param flags Option flags. |
| 6242 | * |
| 6243 | * @return A {@link Context} for the application. |
| 6244 | * |
| 6245 | * @throws SecurityException |
| 6246 | * @throws PackageManager.NameNotFoundException if there is no application with |
| 6247 | * the given package name. |
| 6248 | */ |
| 6249 | public abstract Context createPackageContext(String packageName, |
| 6250 | @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException; |
| 6251 | |
| 6252 | /** |
| 6253 | * Similar to {@link #createPackageContext(String, int)}, but with a |
| 6254 | * different {@link UserHandle}. For example, {@link #getContentResolver()} |
| 6255 | * will open any {@link Uri} as the given user. |
| 6256 | * |
| 6257 | * @hide |
| 6258 | */ |
| 6259 | @SystemApi |
| 6260 | @NonNull |
| 6261 | public Context createPackageContextAsUser( |
| 6262 | @NonNull String packageName, @CreatePackageOptions int flags, @NonNull UserHandle user) |
| 6263 | throws PackageManager.NameNotFoundException { |
| 6264 | if (Build.IS_ENG) { |
| 6265 | throw new IllegalStateException("createPackageContextAsUser not overridden!"); |
| 6266 | } |
| 6267 | return this; |
| 6268 | } |
| 6269 | |
| 6270 | /** |
| 6271 | * Similar to {@link #createPackageContext(String, int)}, but for the own package with a |
| 6272 | * different {@link UserHandle}. For example, {@link #getContentResolver()} |
| 6273 | * will open any {@link Uri} as the given user. |
| 6274 | * |
| 6275 | * @hide |
| 6276 | */ |
| 6277 | @SystemApi |
| 6278 | @NonNull |
| 6279 | public Context createContextAsUser(@NonNull UserHandle user, @CreatePackageOptions int flags) { |
| 6280 | if (Build.IS_ENG) { |
| 6281 | throw new IllegalStateException("createContextAsUser not overridden!"); |
| 6282 | } |
| 6283 | return this; |
| 6284 | } |
| 6285 | |
| 6286 | /** |
| 6287 | * Creates a context given an {@link android.content.pm.ApplicationInfo}. |
| 6288 | * |
| 6289 | * @hide |
| 6290 | */ |
| 6291 | @SuppressWarnings("HiddenAbstractMethod") |
| 6292 | @UnsupportedAppUsage |
| 6293 | public abstract Context createApplicationContext(ApplicationInfo application, |
| 6294 | @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException; |
| 6295 | |
| 6296 | /** |
| 6297 | * Return a new Context object for the given split name. The new Context has a ClassLoader and |
| 6298 | * Resources object that can access the split's and all of its dependencies' code/resources. |
| 6299 | * Each call to this method returns a new instance of a Context object; |
| 6300 | * Context objects are not shared, however common state (ClassLoader, other Resources for |
| 6301 | * the same split) may be so the Context itself can be fairly lightweight. |
| 6302 | * |
| 6303 | * @param splitName The name of the split to include, as declared in the split's |
| 6304 | * <code>AndroidManifest.xml</code>. |
| 6305 | * @return A {@link Context} with the given split's code and/or resources loaded. |
| 6306 | */ |
| 6307 | public abstract Context createContextForSplit(String splitName) |
| 6308 | throws PackageManager.NameNotFoundException; |
| 6309 | |
| 6310 | /** |
| 6311 | * Get the user associated with this context. |
| 6312 | * |
| 6313 | * @return the user associated with this context |
| 6314 | * |
| 6315 | * @hide |
| 6316 | */ |
| 6317 | @NonNull |
| 6318 | @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) |
| 6319 | @TestApi |
| 6320 | public UserHandle getUser() { |
| 6321 | return android.os.Process.myUserHandle(); |
| 6322 | } |
| 6323 | |
| 6324 | /** |
| 6325 | * Get the user associated with this context |
| 6326 | * @hide |
| 6327 | */ |
| 6328 | @UnsupportedAppUsage |
| 6329 | @TestApi |
| 6330 | public @UserIdInt int getUserId() { |
| 6331 | return android.os.UserHandle.myUserId(); |
| 6332 | } |
| 6333 | |
| 6334 | /** |
| 6335 | * Return a new Context object for the current Context but whose resources |
| 6336 | * are adjusted to match the given Configuration. Each call to this method |
| 6337 | * returns a new instance of a Context object; Context objects are not |
| 6338 | * shared, however common state (ClassLoader, other Resources for the |
| 6339 | * same configuration) may be so the Context itself can be fairly lightweight. |
| 6340 | * |
| 6341 | * @param overrideConfiguration A {@link Configuration} specifying what |
| 6342 | * values to modify in the base Configuration of the original Context's |
| 6343 | * resources. If the base configuration changes (such as due to an |
| 6344 | * orientation change), the resources of this context will also change except |
| 6345 | * for those that have been explicitly overridden with a value here. |
| 6346 | * |
| 6347 | * @return A {@link Context} with the given configuration override. |
| 6348 | */ |
| 6349 | public abstract Context createConfigurationContext( |
| 6350 | @NonNull Configuration overrideConfiguration); |
| 6351 | |
| 6352 | /** |
| 6353 | * Return a new Context object for the current Context but whose resources |
| 6354 | * are adjusted to match the metrics of the given Display. Each call to this method |
| 6355 | * returns a new instance of a Context object; Context objects are not |
| 6356 | * shared, however common state (ClassLoader, other Resources for the |
| 6357 | * same configuration) may be so the Context itself can be fairly lightweight. |
| 6358 | * |
| 6359 | * To obtain an instance of a {@link WindowManager} (see {@link #getSystemService(String)}) that |
| 6360 | * is configured to show windows on the given display call |
| 6361 | * {@link #createWindowContext(int, Bundle)} on the returned display Context or use an |
| 6362 | * {@link android.app.Activity}. |
| 6363 | * |
| 6364 | * <p> |
| 6365 | * Note that invoking #createDisplayContext(Display) from an UI context is not regarded |
| 6366 | * as an UI context. In other words, it is not suggested to access UI components (such as |
| 6367 | * obtain a {@link WindowManager} by {@link #getSystemService(String)}) |
| 6368 | * from the context created from #createDisplayContext(Display). |
| 6369 | * </p> |
| 6370 | * |
| 6371 | * @param display A {@link Display} object specifying the display for whose metrics the |
| 6372 | * Context's resources should be tailored. |
| 6373 | * |
| 6374 | * @return A {@link Context} for the display. |
| 6375 | * |
| 6376 | * @see #getSystemService(String) |
| 6377 | */ |
| 6378 | @DisplayContext |
| 6379 | public abstract Context createDisplayContext(@NonNull Display display); |
| 6380 | |
| 6381 | /** |
| 6382 | * Creates a Context for a non-activity window. |
| 6383 | * |
| 6384 | * <p> |
| 6385 | * A window context is a context that can be used to add non-activity windows, such as |
| 6386 | * {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY}. A window context |
| 6387 | * must be created from a context that has an associated {@link Display}, such as |
| 6388 | * {@link android.app.Activity Activity} or a context created with |
| 6389 | * {@link #createDisplayContext(Display)}. |
| 6390 | * |
| 6391 | * <p> |
| 6392 | * The window context is created with the appropriate {@link Configuration} for the area of the |
| 6393 | * display that the windows created with it can occupy; it must be used when |
| 6394 | * {@link android.view.LayoutInflater inflating} views, such that they can be inflated with |
| 6395 | * proper {@link Resources}. |
| 6396 | * |
| 6397 | * Below is a sample code to <b>add an application overlay window on the primary display:</b> |
| 6398 | * <pre class="prettyprint"> |
| 6399 | * ... |
| 6400 | * final DisplayManager dm = anyContext.getSystemService(DisplayManager.class); |
| 6401 | * final Display primaryDisplay = dm.getDisplay(DEFAULT_DISPLAY); |
| 6402 | * final Context windowContext = anyContext.createDisplayContext(primaryDisplay) |
| 6403 | * .createWindowContext(TYPE_APPLICATION_OVERLAY, null); |
| 6404 | * final View overlayView = Inflater.from(windowContext).inflate(someLayoutXml, null); |
| 6405 | * |
| 6406 | * // WindowManager.LayoutParams initialization |
| 6407 | * ... |
| 6408 | * // The types used in addView and createWindowContext must match. |
| 6409 | * mParams.type = TYPE_APPLICATION_OVERLAY; |
| 6410 | * ... |
| 6411 | * |
| 6412 | * windowContext.getSystemService(WindowManager.class).addView(overlayView, mParams); |
| 6413 | * </pre> |
| 6414 | * |
| 6415 | * <p> |
| 6416 | * This context's configuration and resources are adjusted to an area of the display where |
| 6417 | * the windows with provided type will be added. <b>Note that all windows associated with the |
| 6418 | * same context will have an affinity and can only be moved together between different displays |
| 6419 | * or areas on a display.</b> If there is a need to add different window types, or |
| 6420 | * non-associated windows, separate Contexts should be used. |
| 6421 | * </p> |
| 6422 | * <p> |
| 6423 | * Creating a window context is an expensive operation. Misuse of this API may lead to a huge |
| 6424 | * performance drop. The best practice is to use the same window context when possible. |
| 6425 | * An approach is to create one window context with specific window type and display and |
| 6426 | * use it everywhere it's needed. |
| 6427 | * </p> |
| 6428 | * <p> |
| 6429 | * After {@link Build.VERSION_CODES#S}, window context provides the capability to receive |
| 6430 | * configuration changes for existing token by overriding the |
| 6431 | * {@link android.view.WindowManager.LayoutParams#token token} of the |
| 6432 | * {@link android.view.WindowManager.LayoutParams} passed in |
| 6433 | * {@link WindowManager#addView(View, LayoutParams)}. This is useful when an application needs |
| 6434 | * to attach its window to an existing activity for window token sharing use-case. |
| 6435 | * </p> |
| 6436 | * <p> |
| 6437 | * Note that the window context in {@link Build.VERSION_CODES#R} didn't have this |
| 6438 | * capability. This is a no-op for the window context in {@link Build.VERSION_CODES#R}. |
| 6439 | * </p> |
| 6440 | * Below is sample code to <b>attach an existing token to a window context:</b> |
| 6441 | * <pre class="prettyprint"> |
| 6442 | * final DisplayManager dm = anyContext.getSystemService(DisplayManager.class); |
| 6443 | * final Display primaryDisplay = dm.getDisplay(DEFAULT_DISPLAY); |
| 6444 | * final Context windowContext = anyContext.createWindowContext(primaryDisplay, |
| 6445 | * TYPE_APPLICATION, null); |
| 6446 | * |
| 6447 | * // Get an existing token. |
| 6448 | * final IBinder existingToken = activity.getWindow().getAttributes().token; |
| 6449 | * |
| 6450 | * // The types used in addView() and createWindowContext() must match. |
| 6451 | * final WindowManager.LayoutParams params = new WindowManager.LayoutParams(TYPE_APPLICATION); |
| 6452 | * params.token = existingToken; |
| 6453 | * |
| 6454 | * // After WindowManager#addView(), the server side will extract the provided token from |
| 6455 | * // LayoutParams#token (existingToken in the sample code), and switch to propagate |
| 6456 | * // configuration changes from the node associated with the provided token. |
| 6457 | * windowContext.getSystemService(WindowManager.class).addView(overlayView, mParams); |
| 6458 | * </pre> |
| 6459 | * <p> |
| 6460 | * After {@link Build.VERSION_CODES#S}, window context provides the capability to listen to its |
| 6461 | * {@link Configuration} changes by calling |
| 6462 | * {@link #registerComponentCallbacks(ComponentCallbacks)}, while other kinds of {@link Context} |
| 6463 | * will register the {@link ComponentCallbacks} to {@link #getApplicationContext() its |
| 6464 | * Application context}. Note that window context only propagate |
| 6465 | * {@link ComponentCallbacks#onConfigurationChanged(Configuration)} callback. |
| 6466 | * {@link ComponentCallbacks#onLowMemory()} or other callbacks in {@link ComponentCallbacks2} |
| 6467 | * won't be invoked. |
| 6468 | * </p> |
| 6469 | * <p> |
| 6470 | * Note that using {@link android.app.Application} or {@link android.app.Service} context for |
| 6471 | * UI-related queries may result in layout or continuity issues on devices with variable screen |
| 6472 | * sizes (e.g. foldables) or in multi-window modes, since these non-UI contexts may not reflect |
| 6473 | * the {@link Configuration} changes for the visual container. |
| 6474 | * </p> |
| 6475 | * @param type Window type in {@link WindowManager.LayoutParams} |
| 6476 | * @param options A bundle used to pass window-related options |
| 6477 | * @return A {@link Context} that can be used to create |
| 6478 | * non-{@link android.app.Activity activity} windows. |
| 6479 | * |
| 6480 | * @see #getSystemService(String) |
| 6481 | * @see #getSystemService(Class) |
| 6482 | * @see #WINDOW_SERVICE |
| 6483 | * @see #LAYOUT_INFLATER_SERVICE |
| 6484 | * @see #WALLPAPER_SERVICE |
| 6485 | * @throws UnsupportedOperationException if this {@link Context} does not attach to a display, |
| 6486 | * such as {@link android.app.Application Application} or {@link android.app.Service Service}. |
| 6487 | */ |
| 6488 | @UiContext |
| 6489 | @NonNull |
| 6490 | public Context createWindowContext(@WindowType int type, @Nullable Bundle options) { |
| 6491 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6492 | } |
| 6493 | |
| 6494 | /** |
| 6495 | * Creates a {@code Context} for a non-{@link android.app.Activity activity} window on the given |
| 6496 | * {@link Display}. |
| 6497 | * |
| 6498 | * <p> |
| 6499 | * Similar to {@link #createWindowContext(int, Bundle)}, but the {@code display} is passed in, |
| 6500 | * instead of implicitly using the {@link #getDisplay() original Context's Display}. |
| 6501 | * </p> |
| 6502 | * |
| 6503 | * @param display The {@link Display} to associate with |
| 6504 | * @param type Window type in {@link WindowManager.LayoutParams} |
| 6505 | * @param options A bundle used to pass window-related options. |
| 6506 | * @return A {@link Context} that can be used to create |
| 6507 | * non-{@link android.app.Activity activity} windows. |
| 6508 | * @throws IllegalArgumentException if the {@link Display} is {@code null}. |
| 6509 | * |
| 6510 | * @see #getSystemService(String) |
| 6511 | * @see #getSystemService(Class) |
| 6512 | * @see #WINDOW_SERVICE |
| 6513 | * @see #LAYOUT_INFLATER_SERVICE |
| 6514 | * @see #WALLPAPER_SERVICE |
| 6515 | */ |
| 6516 | @UiContext |
| 6517 | @NonNull |
| 6518 | public Context createWindowContext(@NonNull Display display, @WindowType int type, |
| 6519 | @SuppressLint("NullableCollection") |
| 6520 | @Nullable Bundle options) { |
| 6521 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6522 | } |
| 6523 | |
| 6524 | /** |
| 6525 | * Creates a context with specific properties and behaviors. |
| 6526 | * |
| 6527 | * @param contextParams Parameters for how the new context should behave. |
| 6528 | * @return A context with the specified behaviors. |
| 6529 | * |
| 6530 | * @see ContextParams |
| 6531 | */ |
| 6532 | @NonNull |
| 6533 | public Context createContext(@NonNull ContextParams contextParams) { |
| 6534 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6535 | } |
| 6536 | |
| 6537 | /** |
| 6538 | * Return a new Context object for the current Context but attribute to a different tag. |
| 6539 | * In complex apps attribution tagging can be used to distinguish between separate logical |
| 6540 | * parts. |
| 6541 | * |
| 6542 | * @param attributionTag The tag or {@code null} to create a context for the default. |
| 6543 | * |
| 6544 | * @return A {@link Context} that is tagged for the new attribution |
| 6545 | * |
| 6546 | * @see #getAttributionTag() |
| 6547 | */ |
| 6548 | public @NonNull Context createAttributionContext(@Nullable String attributionTag) { |
| 6549 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6550 | } |
| 6551 | |
| 6552 | // TODO moltmann: remove |
| 6553 | /** |
| 6554 | * @removed |
| 6555 | */ |
| 6556 | @Deprecated |
| 6557 | public @NonNull Context createFeatureContext(@Nullable String attributionTag) { |
| 6558 | return createContext(new ContextParams.Builder(getParams()) |
| 6559 | .setAttributionTag(attributionTag) |
| 6560 | .build()); |
| 6561 | } |
| 6562 | |
| 6563 | /** |
| 6564 | * Return a new Context object for the current Context but whose storage |
| 6565 | * APIs are backed by device-protected storage. |
| 6566 | * <p> |
| 6567 | * On devices with direct boot, data stored in this location is encrypted |
| 6568 | * with a key tied to the physical device, and it can be accessed |
| 6569 | * immediately after the device has booted successfully, both |
| 6570 | * <em>before and after</em> the user has authenticated with their |
| 6571 | * credentials (such as a lock pattern or PIN). |
| 6572 | * <p> |
| 6573 | * Because device-protected data is available without user authentication, |
| 6574 | * you should carefully limit the data you store using this Context. For |
| 6575 | * example, storing sensitive authentication tokens or passwords in the |
| 6576 | * device-protected area is strongly discouraged. |
| 6577 | * <p> |
| 6578 | * If the underlying device does not have the ability to store |
| 6579 | * device-protected and credential-protected data using different keys, then |
| 6580 | * both storage areas will become available at the same time. They remain as |
| 6581 | * two distinct storage locations on disk, and only the window of |
| 6582 | * availability changes. |
| 6583 | * <p> |
| 6584 | * Each call to this method returns a new instance of a Context object; |
| 6585 | * Context objects are not shared, however common state (ClassLoader, other |
| 6586 | * Resources for the same configuration) may be so the Context itself can be |
| 6587 | * fairly lightweight. |
| 6588 | * |
| 6589 | * @see #isDeviceProtectedStorage() |
| 6590 | */ |
| 6591 | public abstract Context createDeviceProtectedStorageContext(); |
| 6592 | |
| 6593 | /** |
| 6594 | * Return a new Context object for the current Context but whose storage |
| 6595 | * APIs are backed by credential-protected storage. This is the default |
| 6596 | * storage area for apps unless |
| 6597 | * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested. |
| 6598 | * <p> |
| 6599 | * On devices with direct boot, data stored in this location is encrypted |
| 6600 | * with a key tied to user credentials, which can be accessed |
| 6601 | * <em>only after</em> the user has entered their credentials (such as a |
| 6602 | * lock pattern or PIN). |
| 6603 | * <p> |
| 6604 | * If the underlying device does not have the ability to store |
| 6605 | * device-protected and credential-protected data using different keys, then |
| 6606 | * both storage areas will become available at the same time. They remain as |
| 6607 | * two distinct storage locations on disk, and only the window of |
| 6608 | * availability changes. |
| 6609 | * <p> |
| 6610 | * Each call to this method returns a new instance of a Context object; |
| 6611 | * Context objects are not shared, however common state (ClassLoader, other |
| 6612 | * Resources for the same configuration) may be so the Context itself can be |
| 6613 | * fairly lightweight. |
| 6614 | * |
| 6615 | * @see #isCredentialProtectedStorage() |
| 6616 | * @hide |
| 6617 | */ |
| 6618 | @SuppressWarnings("HiddenAbstractMethod") |
| 6619 | @SystemApi |
| 6620 | public abstract Context createCredentialProtectedStorageContext(); |
| 6621 | |
| 6622 | /** |
| 6623 | * Creates a UI context with a {@code token}. The users of this API should handle this context's |
| 6624 | * configuration changes. |
| 6625 | * |
| 6626 | * @param token The token to associate with the {@link Resources} |
| 6627 | * @param display The display to associate with the token context |
| 6628 | * |
| 6629 | * @hide |
| 6630 | */ |
| 6631 | @UiContext |
| 6632 | @NonNull |
| 6633 | public Context createTokenContext(@NonNull IBinder token, @NonNull Display display) { |
| 6634 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6635 | } |
| 6636 | |
| 6637 | /** |
| 6638 | * Gets the display adjustments holder for this context. This information |
| 6639 | * is provided on a per-application or activity basis and is used to simulate lower density |
| 6640 | * display metrics for legacy applications and restricted screen sizes. |
| 6641 | * |
| 6642 | * @param displayId The display id for which to get compatibility info. |
| 6643 | * @return The compatibility info holder, or null if not required by the application. |
| 6644 | * @hide |
| 6645 | */ |
| 6646 | @SuppressWarnings("HiddenAbstractMethod") |
| 6647 | public abstract DisplayAdjustments getDisplayAdjustments(int displayId); |
| 6648 | |
| 6649 | /** |
| 6650 | * Get the display this context is associated with. Applications should use this method with |
| 6651 | * {@link android.app.Activity} or a context associated with a {@link Display} via |
| 6652 | * {@link #createDisplayContext(Display)} to get a display object associated with a Context, or |
| 6653 | * {@link android.hardware.display.DisplayManager#getDisplay} to get a display object by id. |
| 6654 | * @return Returns the {@link Display} object this context is associated with. |
| 6655 | * @throws UnsupportedOperationException if the method is called on an instance that is not |
| 6656 | * associated with any display. |
| 6657 | */ |
| 6658 | @Nullable |
| 6659 | public Display getDisplay() { |
| 6660 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6661 | } |
| 6662 | |
| 6663 | /** |
| 6664 | * A version of {@link #getDisplay()} that does not perform a Context misuse check to be used by |
| 6665 | * legacy APIs. |
| 6666 | * TODO(b/149790106): Fix usages and remove. |
| 6667 | * @hide |
| 6668 | */ |
| 6669 | @Nullable |
| 6670 | public Display getDisplayNoVerify() { |
| 6671 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6672 | } |
| 6673 | |
| 6674 | /** |
| 6675 | * Gets the ID of the display this context is associated with. |
| 6676 | * |
| 6677 | * @return display ID associated with this {@link Context}. |
| 6678 | * @see #getDisplay() |
| 6679 | * @hide |
| 6680 | */ |
| 6681 | @SuppressWarnings("HiddenAbstractMethod") |
| 6682 | @TestApi |
| 6683 | public abstract int getDisplayId(); |
| 6684 | |
| 6685 | /** |
| 6686 | * @hide |
| 6687 | */ |
| 6688 | @SuppressWarnings("HiddenAbstractMethod") |
| 6689 | public abstract void updateDisplay(int displayId); |
| 6690 | |
| 6691 | /** |
| 6692 | * Indicates whether this Context is restricted. |
| 6693 | * |
| 6694 | * @return {@code true} if this Context is restricted, {@code false} otherwise. |
| 6695 | * |
| 6696 | * @see #CONTEXT_RESTRICTED |
| 6697 | */ |
| 6698 | public boolean isRestricted() { |
| 6699 | return false; |
| 6700 | } |
| 6701 | |
| 6702 | /** |
| 6703 | * Indicates if the storage APIs of this Context are backed by |
| 6704 | * device-protected storage. |
| 6705 | * |
| 6706 | * @see #createDeviceProtectedStorageContext() |
| 6707 | */ |
| 6708 | public abstract boolean isDeviceProtectedStorage(); |
| 6709 | |
| 6710 | /** |
| 6711 | * Indicates if the storage APIs of this Context are backed by |
| 6712 | * credential-protected storage. |
| 6713 | * |
| 6714 | * @see #createCredentialProtectedStorageContext() |
| 6715 | * @hide |
| 6716 | */ |
| 6717 | @SuppressWarnings("HiddenAbstractMethod") |
| 6718 | @SystemApi |
| 6719 | public abstract boolean isCredentialProtectedStorage(); |
| 6720 | |
| 6721 | /** |
| 6722 | * Returns true if the context can load unsafe resources, e.g. fonts. |
| 6723 | * @hide |
| 6724 | */ |
| 6725 | @SuppressWarnings("HiddenAbstractMethod") |
| 6726 | public abstract boolean canLoadUnsafeResources(); |
| 6727 | |
| 6728 | /** |
| 6729 | * Returns token if the {@link Context} is a {@link android.app.Activity}. Returns |
| 6730 | * {@code null} otherwise. |
| 6731 | * |
| 6732 | * @hide |
| 6733 | */ |
| 6734 | @Nullable |
| 6735 | public IBinder getActivityToken() { |
| 6736 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6737 | } |
| 6738 | |
| 6739 | /** |
| 6740 | * Returns token if the {@link Context} is a {@link android.app.WindowContext}. Returns |
| 6741 | * {@code null} otherwise. |
| 6742 | * |
| 6743 | * @hide |
| 6744 | */ |
| 6745 | @Nullable |
| 6746 | public IBinder getWindowContextToken() { |
| 6747 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6748 | } |
| 6749 | |
| 6750 | /** |
| 6751 | * Returns the proper token of a {@link Context}. |
| 6752 | * |
| 6753 | * If the {@link Context} is an {@link android.app.Activity}, returns |
| 6754 | * {@link #getActivityToken()}. If the {@lijnk Context} is a {@link android.app.WindowContext}, |
| 6755 | * returns {@link #getWindowContextToken()}. Returns {@code null}, otherwise. |
| 6756 | * |
| 6757 | * @hide |
| 6758 | */ |
| 6759 | @Nullable |
| 6760 | public static IBinder getToken(@NonNull Context context) { |
| 6761 | return context.getActivityToken() != null ? context.getActivityToken() |
| 6762 | : context.getWindowContextToken(); |
| 6763 | } |
| 6764 | |
| 6765 | /** |
| 6766 | * @hide |
| 6767 | */ |
| 6768 | @Nullable |
| 6769 | public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler, |
| 6770 | int flags) { |
| 6771 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6772 | } |
| 6773 | |
| 6774 | /** |
| 6775 | * @hide |
| 6776 | */ |
| 6777 | public IApplicationThread getIApplicationThread() { |
| 6778 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6779 | } |
| 6780 | |
| 6781 | /** |
| 6782 | * @hide |
| 6783 | */ |
| 6784 | public Handler getMainThreadHandler() { |
| 6785 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6786 | } |
| 6787 | |
| 6788 | /** |
| 6789 | * @hide |
| 6790 | */ |
| 6791 | public AutofillClient getAutofillClient() { |
| 6792 | return null; |
| 6793 | } |
| 6794 | |
| 6795 | /** |
| 6796 | * @hide |
| 6797 | */ |
| 6798 | public void setAutofillClient(@SuppressWarnings("unused") AutofillClient client) { |
| 6799 | } |
| 6800 | |
| 6801 | /** |
| 6802 | * @hide |
| 6803 | */ |
| 6804 | @Nullable |
| 6805 | public ContentCaptureClient getContentCaptureClient() { |
| 6806 | return null; |
| 6807 | } |
| 6808 | |
| 6809 | /** |
| 6810 | * @hide |
| 6811 | */ |
| 6812 | public final boolean isAutofillCompatibilityEnabled() { |
| 6813 | final AutofillOptions options = getAutofillOptions(); |
| 6814 | return options != null && options.compatModeEnabled; |
| 6815 | } |
| 6816 | |
| 6817 | /** |
| 6818 | * @hide |
| 6819 | */ |
| 6820 | @Nullable |
| 6821 | public AutofillOptions getAutofillOptions() { |
| 6822 | return null; |
| 6823 | } |
| 6824 | |
| 6825 | /** |
| 6826 | * @hide |
| 6827 | */ |
| 6828 | @TestApi |
| 6829 | public void setAutofillOptions(@SuppressWarnings("unused") @Nullable AutofillOptions options) { |
| 6830 | } |
| 6831 | |
| 6832 | /** |
| 6833 | * Gets the Content Capture options for this context, or {@code null} if it's not allowlisted. |
| 6834 | * |
| 6835 | * @hide |
| 6836 | */ |
| 6837 | @Nullable |
| 6838 | public ContentCaptureOptions getContentCaptureOptions() { |
| 6839 | return null; |
| 6840 | } |
| 6841 | |
| 6842 | /** |
| 6843 | * @hide |
| 6844 | */ |
| 6845 | @TestApi |
| 6846 | public void setContentCaptureOptions( |
| 6847 | @SuppressWarnings("unused") @Nullable ContentCaptureOptions options) { |
| 6848 | } |
| 6849 | |
| 6850 | /** |
| 6851 | * Throws an exception if the Context is using system resources, |
| 6852 | * which are non-runtime-overlay-themable and may show inconsistent UI. |
| 6853 | * @hide |
| 6854 | */ |
| 6855 | public void assertRuntimeOverlayThemable() { |
| 6856 | // Resources.getSystem() is a singleton and the only Resources not managed by |
| 6857 | // ResourcesManager; therefore Resources.getSystem() is not themable. |
| 6858 | if (getResources() == Resources.getSystem()) { |
| 6859 | throw new IllegalArgumentException("Non-UI context used to display UI; " |
| 6860 | + "get a UI context from ActivityThread#getSystemUiContext()"); |
| 6861 | } |
| 6862 | } |
| 6863 | |
| 6864 | /** |
| 6865 | * Returns {@code true} if the context is a UI context which can access UI components such as |
| 6866 | * {@link WindowManager}, {@link android.view.LayoutInflater LayoutInflater} or |
| 6867 | * {@link android.app.WallpaperManager WallpaperManager}. Accessing UI components from non-UI |
| 6868 | * contexts throws {@link android.os.strictmode.Violation} if |
| 6869 | * {@link android.os.StrictMode.VmPolicy.Builder#detectIncorrectContextUse()} is enabled. |
| 6870 | * <p> |
| 6871 | * Examples of UI contexts are |
| 6872 | * an {@link android.app.Activity Activity}, a context created from |
| 6873 | * {@link #createWindowContext(int, Bundle)} or |
| 6874 | * {@link android.inputmethodservice.InputMethodService InputMethodService} |
| 6875 | * </p> |
| 6876 | * <p> |
| 6877 | * Note that even if it is allowed programmatically, it is not suggested to override this |
| 6878 | * method to bypass {@link android.os.strictmode.IncorrectContextUseViolation} verification. |
| 6879 | * </p> |
| 6880 | * |
| 6881 | * @see #getDisplay() |
| 6882 | * @see #getSystemService(String) |
| 6883 | * @see android.os.StrictMode.VmPolicy.Builder#detectIncorrectContextUse() |
| 6884 | */ |
| 6885 | public boolean isUiContext() { |
| 6886 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6887 | } |
| 6888 | |
| 6889 | /** |
| 6890 | * Called when a {@link Context} is going to be released. |
| 6891 | * This method can be overridden to perform the final cleanups, such as release |
| 6892 | * {@link BroadcastReceiver} registrations. |
| 6893 | * |
| 6894 | * @see WindowContext#destroy() |
| 6895 | * |
| 6896 | * @hide |
| 6897 | */ |
| 6898 | public void destroy() { } |
| 6899 | |
| 6900 | /** |
| 6901 | * Indicates this {@link Context} has the proper {@link Configuration} to obtain |
| 6902 | * {@link android.view.LayoutInflater}, {@link android.view.ViewConfiguration} and |
| 6903 | * {@link android.view.GestureDetector}. Generally, all UI contexts, such as |
| 6904 | * {@link android.app.Activity} or {@link android.app.WindowContext}, are initialized with base |
| 6905 | * configuration. |
| 6906 | * <p> |
| 6907 | * Note that the context created via {@link Context#createConfigurationContext(Configuration)} |
| 6908 | * is also regarded as a context that is based on a configuration because the |
| 6909 | * configuration is explicitly provided via the API. |
| 6910 | * </p> |
| 6911 | * |
| 6912 | * @see #isUiContext() |
| 6913 | * @see #createConfigurationContext(Configuration) |
| 6914 | * |
| 6915 | * @hide |
| 6916 | */ |
| 6917 | public boolean isConfigurationContext() { |
| 6918 | throw new RuntimeException("Not implemented. Must override in a subclass."); |
| 6919 | } |
| 6920 | } |