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.IntDef; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.StringDef; 23 import android.annotation.SystemApi; 24 import android.content.pm.ApplicationInfo; 25 import android.content.pm.PackageManager; 26 import android.content.res.AssetManager; 27 import android.content.res.Configuration; 28 import android.content.res.Resources; 29 import android.content.res.TypedArray; 30 import android.database.DatabaseErrorHandler; 31 import android.database.sqlite.SQLiteDatabase; 32 import android.database.sqlite.SQLiteDatabase.CursorFactory; 33 import android.graphics.Bitmap; 34 import android.graphics.drawable.Drawable; 35 import android.media.MediaScannerConnection.OnScanCompletedListener; 36 import android.net.Uri; 37 import android.os.Bundle; 38 import android.os.Environment; 39 import android.os.Handler; 40 import android.os.Looper; 41 import android.os.StatFs; 42 import android.os.UserHandle; 43 import android.os.UserManager; 44 import android.provider.MediaStore; 45 import android.util.AttributeSet; 46 import android.view.DisplayAdjustments; 47 import android.view.Display; 48 import android.view.ViewDebug; 49 import android.view.WindowManager; 50 51 import java.io.File; 52 import java.io.FileInputStream; 53 import java.io.FileNotFoundException; 54 import java.io.FileOutputStream; 55 import java.io.IOException; 56 import java.io.InputStream; 57 import java.lang.annotation.Retention; 58 import java.lang.annotation.RetentionPolicy; 59 60 /** 61 * Interface to global information about an application environment. This is 62 * an abstract class whose implementation is provided by 63 * the Android system. It 64 * allows access to application-specific resources and classes, as well as 65 * up-calls for application-level operations such as launching activities, 66 * broadcasting and receiving intents, etc. 67 */ 68 public abstract class Context { 69 /** 70 * File creation mode: the default mode, where the created file can only 71 * be accessed by the calling application (or all applications sharing the 72 * same user ID). 73 * @see #MODE_WORLD_READABLE 74 * @see #MODE_WORLD_WRITEABLE 75 */ 76 public static final int MODE_PRIVATE = 0x0000; 77 /** 78 * @deprecated Creating world-readable files is very dangerous, and likely 79 * to cause security holes in applications. It is strongly discouraged; 80 * instead, applications should use more formal mechanism for interactions 81 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and 82 * {@link android.app.Service}. There are no guarantees that this 83 * access mode will remain on a file, such as when it goes through a 84 * backup and restore. 85 * File creation mode: allow all other applications to have read access 86 * to the created file. 87 * @see #MODE_PRIVATE 88 * @see #MODE_WORLD_WRITEABLE 89 */ 90 @Deprecated 91 public static final int MODE_WORLD_READABLE = 0x0001; 92 /** 93 * @deprecated Creating world-writable files is very dangerous, and likely 94 * to cause security holes in applications. It is strongly discouraged; 95 * instead, applications should use more formal mechanism for interactions 96 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and 97 * {@link android.app.Service}. There are no guarantees that this 98 * access mode will remain on a file, such as when it goes through a 99 * backup and restore. 100 * File creation mode: allow all other applications to have write access 101 * to the created file. 102 * @see #MODE_PRIVATE 103 * @see #MODE_WORLD_READABLE 104 */ 105 @Deprecated 106 public static final int MODE_WORLD_WRITEABLE = 0x0002; 107 /** 108 * File creation mode: for use with {@link #openFileOutput}, if the file 109 * already exists then write data to the end of the existing file 110 * instead of erasing it. 111 * @see #openFileOutput 112 */ 113 public static final int MODE_APPEND = 0x8000; 114 115 /** 116 * SharedPreference loading flag: when set, the file on disk will 117 * be checked for modification even if the shared preferences 118 * instance is already loaded in this process. This behavior is 119 * sometimes desired in cases where the application has multiple 120 * processes, all writing to the same SharedPreferences file. 121 * Generally there are better forms of communication between 122 * processes, though. 123 * 124 * <p>This was the legacy (but undocumented) behavior in and 125 * before Gingerbread (Android 2.3) and this flag is implied when 126 * targetting such releases. For applications targetting SDK 127 * versions <em>greater than</em> Android 2.3, this flag must be 128 * explicitly set if desired. 129 * 130 * @see #getSharedPreferences 131 */ 132 public static final int MODE_MULTI_PROCESS = 0x0004; 133 134 /** 135 * Database open flag: when set, the database is opened with write-ahead 136 * logging enabled by default. 137 * 138 * @see #openOrCreateDatabase(String, int, CursorFactory) 139 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler) 140 * @see SQLiteDatabase#enableWriteAheadLogging 141 */ 142 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008; 143 144 /** @hide */ 145 @IntDef(flag = true, 146 value = { 147 BIND_AUTO_CREATE, 148 BIND_AUTO_CREATE, 149 BIND_DEBUG_UNBIND, 150 BIND_NOT_FOREGROUND, 151 BIND_ABOVE_CLIENT, 152 BIND_ALLOW_OOM_MANAGEMENT, 153 BIND_WAIVE_PRIORITY 154 }) 155 @Retention(RetentionPolicy.SOURCE) 156 public @interface BindServiceFlags {} 157 158 /** 159 * Flag for {@link #bindService}: automatically create the service as long 160 * as the binding exists. Note that while this will create the service, 161 * its {@link android.app.Service#onStartCommand} 162 * method will still only be called due to an 163 * explicit call to {@link #startService}. Even without that, though, 164 * this still provides you with access to the service object while the 165 * service is created. 166 * 167 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, 168 * not supplying this flag would also impact how important the system 169 * consider's the target service's process to be. When set, the only way 170 * for it to be raised was by binding from a service in which case it will 171 * only be important when that activity is in the foreground. Now to 172 * achieve this behavior you must explicitly supply the new flag 173 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications 174 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have 175 * the flags {@link #BIND_WAIVE_PRIORITY} and 176 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve 177 * the same result. 178 */ 179 public static final int BIND_AUTO_CREATE = 0x0001; 180 181 /** 182 * Flag for {@link #bindService}: include debugging help for mismatched 183 * calls to unbind. When this flag is set, the callstack of the following 184 * {@link #unbindService} call is retained, to be printed if a later 185 * incorrect unbind call is made. Note that doing this requires retaining 186 * information about the binding that was made for the lifetime of the app, 187 * resulting in a leak -- this should only be used for debugging. 188 */ 189 public static final int BIND_DEBUG_UNBIND = 0x0002; 190 191 /** 192 * Flag for {@link #bindService}: don't allow this binding to raise 193 * the target service's process to the foreground scheduling priority. 194 * It will still be raised to at least the same memory priority 195 * as the client (so that its process will not be killable in any 196 * situation where the client is not killable), but for CPU scheduling 197 * purposes it may be left in the background. This only has an impact 198 * in the situation where the binding client is a foreground process 199 * and the target service is in a background process. 200 */ 201 public static final int BIND_NOT_FOREGROUND = 0x0004; 202 203 /** 204 * Flag for {@link #bindService}: indicates that the client application 205 * binding to this service considers the service to be more important than 206 * the app itself. When set, the platform will try to have the out of 207 * memory killer kill the app before it kills the service it is bound to, though 208 * this is not guaranteed to be the case. 209 */ 210 public static final int BIND_ABOVE_CLIENT = 0x0008; 211 212 /** 213 * Flag for {@link #bindService}: allow the process hosting the bound 214 * service to go through its normal memory management. It will be 215 * treated more like a running service, allowing the system to 216 * (temporarily) expunge the process if low on memory or for some other 217 * whim it may have, and being more aggressive about making it a candidate 218 * to be killed (and restarted) if running for a long time. 219 */ 220 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010; 221 222 /** 223 * Flag for {@link #bindService}: don't impact the scheduling or 224 * memory management priority of the target service's hosting process. 225 * Allows the service's process to be managed on the background LRU list 226 * just like a regular application process in the background. 227 */ 228 public static final int BIND_WAIVE_PRIORITY = 0x0020; 229 230 /** 231 * Flag for {@link #bindService}: this service is very important to 232 * the client, so should be brought to the foreground process level 233 * when the client is. Normally a process can only be raised to the 234 * visibility level by a client, even if that client is in the foreground. 235 */ 236 public static final int BIND_IMPORTANT = 0x0040; 237 238 /** 239 * Flag for {@link #bindService}: If binding from an activity, allow the 240 * target service's process importance to be raised based on whether the 241 * activity is visible to the user, regardless whether another flag is 242 * used to reduce the amount that the client process's overall importance 243 * is used to impact it. 244 */ 245 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080; 246 247 /** 248 * @hide Flag for {@link #bindService}: Treat the binding as hosting 249 * an activity, an unbinding as the activity going in the background. 250 * That is, when unbinding, the process when empty will go on the activity 251 * LRU list instead of the regular one, keeping it around more aggressively 252 * than it otherwise would be. This is intended for use with IMEs to try 253 * to keep IME processes around for faster keyboard switching. 254 */ 255 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000; 256 257 /** 258 * @hide An idea that is not yet implemented. 259 * Flag for {@link #bindService}: If binding from an activity, consider 260 * this service to be visible like the binding activity is. That is, 261 * it will be treated as something more important to keep around than 262 * invisible background activities. This will impact the number of 263 * recent activities the user can switch between without having them 264 * restart. There is no guarantee this will be respected, as the system 265 * tries to balance such requests from one app vs. the importantance of 266 * keeping other apps around. 267 */ 268 public static final int BIND_VISIBLE = 0x10000000; 269 270 /** 271 * @hide 272 * Flag for {@link #bindService}: Consider this binding to be causing the target 273 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes 274 * away. 275 */ 276 public static final int BIND_SHOWING_UI = 0x20000000; 277 278 /** 279 * Flag for {@link #bindService}: Don't consider the bound service to be 280 * visible, even if the caller is visible. 281 * @hide 282 */ 283 public static final int BIND_NOT_VISIBLE = 0x40000000; 284 285 /** Return an AssetManager instance for your application's package. */ getAssets()286 public abstract AssetManager getAssets(); 287 288 /** Return a Resources instance for your application's package. */ getResources()289 public abstract Resources getResources(); 290 291 /** Return PackageManager instance to find global package information. */ getPackageManager()292 public abstract PackageManager getPackageManager(); 293 294 /** Return a ContentResolver instance for your application's package. */ getContentResolver()295 public abstract ContentResolver getContentResolver(); 296 297 /** 298 * Return the Looper for the main thread of the current process. This is 299 * the thread used to dispatch calls to application components (activities, 300 * services, etc). 301 * <p> 302 * By definition, this method returns the same result as would be obtained 303 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}. 304 * </p> 305 * 306 * @return The main looper. 307 */ getMainLooper()308 public abstract Looper getMainLooper(); 309 310 /** 311 * Return the context of the single, global Application object of the 312 * current process. This generally should only be used if you need a 313 * Context whose lifecycle is separate from the current context, that is 314 * tied to the lifetime of the process rather than the current component. 315 * 316 * <p>Consider for example how this interacts with 317 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}: 318 * <ul> 319 * <li> <p>If used from an Activity context, the receiver is being registered 320 * within that activity. This means that you are expected to unregister 321 * before the activity is done being destroyed; in fact if you do not do 322 * so, the framework will clean up your leaked registration as it removes 323 * the activity and log an error. Thus, if you use the Activity context 324 * to register a receiver that is static (global to the process, not 325 * associated with an Activity instance) then that registration will be 326 * removed on you at whatever point the activity you used is destroyed. 327 * <li> <p>If used from the Context returned here, the receiver is being 328 * registered with the global state associated with your application. Thus 329 * it will never be unregistered for you. This is necessary if the receiver 330 * is associated with static data, not a particular component. However 331 * using the ApplicationContext elsewhere can easily lead to serious leaks 332 * if you forget to unregister, unbind, etc. 333 * </ul> 334 */ getApplicationContext()335 public abstract Context getApplicationContext(); 336 337 /** 338 * Add a new {@link ComponentCallbacks} to the base application of the 339 * Context, which will be called at the same times as the ComponentCallbacks 340 * methods of activities and other components are called. Note that you 341 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when 342 * appropriate in the future; this will not be removed for you. 343 * 344 * @param callback The interface to call. This can be either a 345 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface. 346 */ registerComponentCallbacks(ComponentCallbacks callback)347 public void registerComponentCallbacks(ComponentCallbacks callback) { 348 getApplicationContext().registerComponentCallbacks(callback); 349 } 350 351 /** 352 * Remove a {@link ComponentCallbacks} object that was previously registered 353 * with {@link #registerComponentCallbacks(ComponentCallbacks)}. 354 */ unregisterComponentCallbacks(ComponentCallbacks callback)355 public void unregisterComponentCallbacks(ComponentCallbacks callback) { 356 getApplicationContext().unregisterComponentCallbacks(callback); 357 } 358 359 /** 360 * Return a localized, styled CharSequence from the application's package's 361 * default string table. 362 * 363 * @param resId Resource id for the CharSequence text 364 */ getText(int resId)365 public final CharSequence getText(int resId) { 366 return getResources().getText(resId); 367 } 368 369 /** 370 * Return a localized string from the application's package's 371 * default string table. 372 * 373 * @param resId Resource id for the string 374 */ getString(int resId)375 public final String getString(int resId) { 376 return getResources().getString(resId); 377 } 378 379 /** 380 * Return a localized formatted string from the application's package's 381 * default string table, substituting the format arguments as defined in 382 * {@link java.util.Formatter} and {@link java.lang.String#format}. 383 * 384 * @param resId Resource id for the format string 385 * @param formatArgs The format arguments that will be used for substitution. 386 */ 387 getString(int resId, Object... formatArgs)388 public final String getString(int resId, Object... formatArgs) { 389 return getResources().getString(resId, formatArgs); 390 } 391 392 /** 393 * Return a drawable object associated with a particular resource ID and 394 * styled for the current theme. 395 * 396 * @param id The desired resource identifier, as generated by the aapt 397 * tool. This integer encodes the package, type, and resource 398 * entry. The value 0 is an invalid identifier. 399 * @return Drawable An object that can be used to draw this resource. 400 */ getDrawable(int id)401 public final Drawable getDrawable(int id) { 402 return getResources().getDrawable(id, getTheme()); 403 } 404 405 /** 406 * Set the base theme for this context. Note that this should be called 407 * before any views are instantiated in the Context (for example before 408 * calling {@link android.app.Activity#setContentView} or 409 * {@link android.view.LayoutInflater#inflate}). 410 * 411 * @param resid The style resource describing the theme. 412 */ setTheme(int resid)413 public abstract void setTheme(int resid); 414 415 /** @hide Needed for some internal implementation... not public because 416 * you can't assume this actually means anything. */ getThemeResId()417 public int getThemeResId() { 418 return 0; 419 } 420 421 /** 422 * Return the Theme object associated with this Context. 423 */ 424 @ViewDebug.ExportedProperty(deepExport = true) getTheme()425 public abstract Resources.Theme getTheme(); 426 427 /** 428 * Retrieve styled attribute information in this Context's theme. See 429 * {@link Resources.Theme#obtainStyledAttributes(int[])} 430 * for more information. 431 * 432 * @see Resources.Theme#obtainStyledAttributes(int[]) 433 */ obtainStyledAttributes( int[] attrs)434 public final TypedArray obtainStyledAttributes( 435 int[] attrs) { 436 return getTheme().obtainStyledAttributes(attrs); 437 } 438 439 /** 440 * Retrieve styled attribute information in this Context's theme. See 441 * {@link Resources.Theme#obtainStyledAttributes(int, int[])} 442 * for more information. 443 * 444 * @see Resources.Theme#obtainStyledAttributes(int, int[]) 445 */ obtainStyledAttributes( int resid, int[] attrs)446 public final TypedArray obtainStyledAttributes( 447 int resid, int[] attrs) throws Resources.NotFoundException { 448 return getTheme().obtainStyledAttributes(resid, attrs); 449 } 450 451 /** 452 * Retrieve styled attribute information in this Context's theme. See 453 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)} 454 * for more information. 455 * 456 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) 457 */ obtainStyledAttributes( AttributeSet set, int[] attrs)458 public final TypedArray obtainStyledAttributes( 459 AttributeSet set, int[] attrs) { 460 return getTheme().obtainStyledAttributes(set, attrs, 0, 0); 461 } 462 463 /** 464 * Retrieve styled attribute information in this Context's theme. See 465 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)} 466 * for more information. 467 * 468 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) 469 */ obtainStyledAttributes( AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes)470 public final TypedArray obtainStyledAttributes( 471 AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) { 472 return getTheme().obtainStyledAttributes( 473 set, attrs, defStyleAttr, defStyleRes); 474 } 475 476 /** 477 * Return a class loader you can use to retrieve classes in this package. 478 */ getClassLoader()479 public abstract ClassLoader getClassLoader(); 480 481 /** Return the name of this application's package. */ getPackageName()482 public abstract String getPackageName(); 483 484 /** @hide Return the name of the base context this context is derived from. */ getBasePackageName()485 public abstract String getBasePackageName(); 486 487 /** @hide Return the package name that should be used for app ops calls from 488 * this context. This is the same as {@link #getBasePackageName()} except in 489 * cases where system components are loaded into other app processes, in which 490 * case this will be the name of the primary package in that process (so that app 491 * ops uid verification will work with the name). */ getOpPackageName()492 public abstract String getOpPackageName(); 493 494 /** Return the full application info for this context's package. */ getApplicationInfo()495 public abstract ApplicationInfo getApplicationInfo(); 496 497 /** 498 * Return the full path to this context's primary Android package. 499 * The Android package is a ZIP file which contains the application's 500 * primary resources. 501 * 502 * <p>Note: this is not generally useful for applications, since they should 503 * not be directly accessing the file system. 504 * 505 * @return String Path to the resources. 506 */ getPackageResourcePath()507 public abstract String getPackageResourcePath(); 508 509 /** 510 * Return the full path to this context's primary Android package. 511 * The Android package is a ZIP file which contains application's 512 * primary code and assets. 513 * 514 * <p>Note: this is not generally useful for applications, since they should 515 * not be directly accessing the file system. 516 * 517 * @return String Path to the code and assets. 518 */ getPackageCodePath()519 public abstract String getPackageCodePath(); 520 521 /** 522 * {@hide} 523 * Return the full path to the shared prefs file for the given prefs group name. 524 * 525 * <p>Note: this is not generally useful for applications, since they should 526 * not be directly accessing the file system. 527 */ getSharedPrefsFile(String name)528 public abstract File getSharedPrefsFile(String name); 529 530 /** 531 * Retrieve and hold the contents of the preferences file 'name', returning 532 * a SharedPreferences through which you can retrieve and modify its 533 * values. Only one instance of the SharedPreferences object is returned 534 * to any callers for the same name, meaning they will see each other's 535 * edits as soon as they are made. 536 * 537 * @param name Desired preferences file. If a preferences file by this name 538 * does not exist, it will be created when you retrieve an 539 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()). 540 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 541 * default operation, {@link #MODE_WORLD_READABLE} 542 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. The bit 543 * {@link #MODE_MULTI_PROCESS} can also be used if multiple processes 544 * are mutating the same SharedPreferences file. {@link #MODE_MULTI_PROCESS} 545 * is always on in apps targeting Gingerbread (Android 2.3) and below, and 546 * off by default in later versions. 547 * 548 * @return The single {@link SharedPreferences} instance that can be used 549 * to retrieve and modify the preference values. 550 * 551 * @see #MODE_PRIVATE 552 * @see #MODE_WORLD_READABLE 553 * @see #MODE_WORLD_WRITEABLE 554 * @see #MODE_MULTI_PROCESS 555 */ getSharedPreferences(String name, int mode)556 public abstract SharedPreferences getSharedPreferences(String name, 557 int mode); 558 559 /** 560 * Open a private file associated with this Context's application package 561 * for reading. 562 * 563 * @param name The name of the file to open; can not contain path 564 * separators. 565 * 566 * @return The resulting {@link FileInputStream}. 567 * 568 * @see #openFileOutput 569 * @see #fileList 570 * @see #deleteFile 571 * @see java.io.FileInputStream#FileInputStream(String) 572 */ openFileInput(String name)573 public abstract FileInputStream openFileInput(String name) 574 throws FileNotFoundException; 575 576 /** 577 * Open a private file associated with this Context's application package 578 * for writing. Creates the file if it doesn't already exist. 579 * 580 * <p>No permissions are required to invoke this method, since it uses internal 581 * storage. 582 * 583 * @param name The name of the file to open; can not contain path 584 * separators. 585 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 586 * default operation, {@link #MODE_APPEND} to append to an existing file, 587 * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control 588 * permissions. 589 * 590 * @return The resulting {@link FileOutputStream}. 591 * 592 * @see #MODE_APPEND 593 * @see #MODE_PRIVATE 594 * @see #MODE_WORLD_READABLE 595 * @see #MODE_WORLD_WRITEABLE 596 * @see #openFileInput 597 * @see #fileList 598 * @see #deleteFile 599 * @see java.io.FileOutputStream#FileOutputStream(String) 600 */ openFileOutput(String name, int mode)601 public abstract FileOutputStream openFileOutput(String name, int mode) 602 throws FileNotFoundException; 603 604 /** 605 * Delete the given private file associated with this Context's 606 * application package. 607 * 608 * @param name The name of the file to delete; can not contain path 609 * separators. 610 * 611 * @return {@code true} if the file was successfully deleted; else 612 * {@code false}. 613 * 614 * @see #openFileInput 615 * @see #openFileOutput 616 * @see #fileList 617 * @see java.io.File#delete() 618 */ deleteFile(String name)619 public abstract boolean deleteFile(String name); 620 621 /** 622 * Returns the absolute path on the filesystem where a file created with 623 * {@link #openFileOutput} is stored. 624 * 625 * @param name The name of the file for which you would like to get 626 * its path. 627 * 628 * @return An absolute path to the given file. 629 * 630 * @see #openFileOutput 631 * @see #getFilesDir 632 * @see #getDir 633 */ getFileStreamPath(String name)634 public abstract File getFileStreamPath(String name); 635 636 /** 637 * Returns the absolute path to the directory on the filesystem where 638 * files created with {@link #openFileOutput} are stored. 639 * 640 * <p>No permissions are required to read or write to the returned path, since this 641 * path is internal storage. 642 * 643 * @return The path of the directory holding application files. 644 * 645 * @see #openFileOutput 646 * @see #getFileStreamPath 647 * @see #getDir 648 */ getFilesDir()649 public abstract File getFilesDir(); 650 651 /** 652 * Returns the absolute path to the directory on the filesystem similar to 653 * {@link #getFilesDir()}. The difference is that files placed under this 654 * directory will be excluded from automatic backup to remote storage. See 655 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion 656 * of the automatic backup mechanism in Android. 657 * 658 * <p>No permissions are required to read or write to the returned path, since this 659 * path is internal storage. 660 * 661 * @return The path of the directory holding application files that will not be 662 * automatically backed up to remote storage. 663 * 664 * @see #openFileOutput 665 * @see #getFileStreamPath 666 * @see #getDir 667 * @see android.app.backup.BackupAgent 668 */ getNoBackupFilesDir()669 public abstract File getNoBackupFilesDir(); 670 671 /** 672 * Returns the absolute path to the directory on the primary external filesystem 673 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory() 674 * Environment.getExternalStorageDirectory()}) where the application can 675 * place persistent files it owns. These files are internal to the 676 * applications, and not typically visible to the user as media. 677 * 678 * <p>This is like {@link #getFilesDir()} in that these 679 * files will be deleted when the application is uninstalled, however there 680 * are some important differences: 681 * 682 * <ul> 683 * <li>External files are not always available: they will disappear if the 684 * user mounts the external storage on a computer or removes it. See the 685 * APIs on {@link android.os.Environment} for information in the storage state. 686 * <li>There is no security enforced with these files. For example, any application 687 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to 688 * these files. 689 * </ul> 690 * 691 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions 692 * are required to read or write to the returned path; it's always 693 * accessible to the calling app. This only applies to paths generated for 694 * package name of the calling application. To access paths belonging 695 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} 696 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required. 697 * 698 * <p>On devices with multiple users (as described by {@link UserManager}), 699 * each user has their own isolated external storage. Applications only 700 * have access to the external storage for the user they're running as.</p> 701 * 702 * <p>Here is an example of typical code to manipulate a file in 703 * an application's private storage:</p> 704 * 705 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java 706 * private_file} 707 * 708 * <p>If you supply a non-null <var>type</var> to this function, the returned 709 * file will be a path to a sub-directory of the given type. Though these files 710 * are not automatically scanned by the media scanner, you can explicitly 711 * add them to the media database with 712 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], 713 * OnScanCompletedListener) MediaScannerConnection.scanFile}. 714 * Note that this is not the same as 715 * {@link android.os.Environment#getExternalStoragePublicDirectory 716 * Environment.getExternalStoragePublicDirectory()}, which provides 717 * directories of media shared by all applications. The 718 * directories returned here are 719 * owned by the application, and their contents will be removed when the 720 * application is uninstalled. Unlike 721 * {@link android.os.Environment#getExternalStoragePublicDirectory 722 * Environment.getExternalStoragePublicDirectory()}, the directory 723 * returned here will be automatically created for you. 724 * 725 * <p>Here is an example of typical code to manipulate a picture in 726 * an application's private storage and add it to the media database:</p> 727 * 728 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java 729 * private_picture} 730 * 731 * @param type The type of files directory to return. May be null for 732 * the root of the files directory or one of 733 * the following Environment constants for a subdirectory: 734 * {@link android.os.Environment#DIRECTORY_MUSIC}, 735 * {@link android.os.Environment#DIRECTORY_PODCASTS}, 736 * {@link android.os.Environment#DIRECTORY_RINGTONES}, 737 * {@link android.os.Environment#DIRECTORY_ALARMS}, 738 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS}, 739 * {@link android.os.Environment#DIRECTORY_PICTURES}, or 740 * {@link android.os.Environment#DIRECTORY_MOVIES}. 741 * 742 * @return The path of the directory holding application files 743 * on external storage. Returns null if external storage is not currently 744 * mounted so it could not ensure the path exists; you will need to call 745 * this method again when it is available. 746 * 747 * @see #getFilesDir 748 * @see android.os.Environment#getExternalStoragePublicDirectory 749 */ 750 @Nullable getExternalFilesDir(@ullable String type)751 public abstract File getExternalFilesDir(@Nullable String type); 752 753 /** 754 * Returns absolute paths to application-specific directories on all 755 * external storage devices where the application can place persistent files 756 * it owns. These files are internal to the application, and not typically 757 * visible to the user as media. 758 * <p> 759 * This is like {@link #getFilesDir()} in that these files will be deleted when 760 * the application is uninstalled, however there are some important differences: 761 * <ul> 762 * <li>External files are not always available: they will disappear if the 763 * user mounts the external storage on a computer or removes it. 764 * <li>There is no security enforced with these files. 765 * </ul> 766 * <p> 767 * External storage devices returned here are considered a permanent part of 768 * the device, including both emulated external storage and physical media 769 * slots, such as SD cards in a battery compartment. The returned paths do 770 * not include transient devices, such as USB flash drives. 771 * <p> 772 * An application may store data on any or all of the returned devices. For 773 * example, an app may choose to store large files on the device with the 774 * most available space, as measured by {@link StatFs}. 775 * <p> 776 * No permissions are required to read or write to the returned paths; they 777 * are always accessible to the calling app. Write access outside of these 778 * paths on secondary external storage devices is not available. 779 * <p> 780 * The first path returned is the same as {@link #getExternalFilesDir(String)}. 781 * Returned paths may be {@code null} if a storage device is unavailable. 782 * 783 * @see #getExternalFilesDir(String) 784 * @see Environment#getExternalStorageState(File) 785 */ getExternalFilesDirs(String type)786 public abstract File[] getExternalFilesDirs(String type); 787 788 /** 789 * Return the primary external storage directory where this application's OBB 790 * files (if there are any) can be found. Note if the application does not have 791 * any OBB files, this directory may not exist. 792 * <p> 793 * This is like {@link #getFilesDir()} in that these files will be deleted when 794 * the application is uninstalled, however there are some important differences: 795 * <ul> 796 * <li>External files are not always available: they will disappear if the 797 * user mounts the external storage on a computer or removes it. 798 * <li>There is no security enforced with these files. For example, any application 799 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to 800 * these files. 801 * </ul> 802 * <p> 803 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions 804 * are required to read or write to the returned path; it's always 805 * accessible to the calling app. This only applies to paths generated for 806 * package name of the calling application. To access paths belonging 807 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} 808 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required. 809 * <p> 810 * On devices with multiple users (as described by {@link UserManager}), 811 * multiple users may share the same OBB storage location. Applications 812 * should ensure that multiple instances running under different users don't 813 * interfere with each other. 814 */ getObbDir()815 public abstract File getObbDir(); 816 817 /** 818 * Returns absolute paths to application-specific directories on all 819 * external storage devices where the application's OBB files (if there are 820 * any) can be found. Note if the application does not have any OBB files, 821 * these directories may not exist. 822 * <p> 823 * This is like {@link #getFilesDir()} in that these files will be deleted when 824 * the application is uninstalled, however there are some important differences: 825 * <ul> 826 * <li>External files are not always available: they will disappear if the 827 * user mounts the external storage on a computer or removes it. 828 * <li>There is no security enforced with these files. 829 * </ul> 830 * <p> 831 * External storage devices returned here are considered a permanent part of 832 * the device, including both emulated external storage and physical media 833 * slots, such as SD cards in a battery compartment. The returned paths do 834 * not include transient devices, such as USB flash drives. 835 * <p> 836 * An application may store data on any or all of the returned devices. For 837 * example, an app may choose to store large files on the device with the 838 * most available space, as measured by {@link StatFs}. 839 * <p> 840 * No permissions are required to read or write to the returned paths; they 841 * are always accessible to the calling app. Write access outside of these 842 * paths on secondary external storage devices is not available. 843 * <p> 844 * The first path returned is the same as {@link #getObbDir()}. 845 * Returned paths may be {@code null} if a storage device is unavailable. 846 * 847 * @see #getObbDir() 848 * @see Environment#getExternalStorageState(File) 849 */ getObbDirs()850 public abstract File[] getObbDirs(); 851 852 /** 853 * Returns the absolute path to the application specific cache directory 854 * on the filesystem. These files will be ones that get deleted first when the 855 * device runs low on storage. 856 * There is no guarantee when these files will be deleted. 857 * 858 * <strong>Note: you should not <em>rely</em> on the system deleting these 859 * files for you; you should always have a reasonable maximum, such as 1 MB, 860 * for the amount of space you consume with cache files, and prune those 861 * files when exceeding that space.</strong> 862 * 863 * @return The path of the directory holding application cache files. 864 * 865 * @see #openFileOutput 866 * @see #getFileStreamPath 867 * @see #getDir 868 */ getCacheDir()869 public abstract File getCacheDir(); 870 871 /** 872 * Returns the absolute path to the application specific cache directory on 873 * the filesystem designed for storing cached code. The system will delete 874 * any files stored in this location both when your specific application is 875 * upgraded, and when the entire platform is upgraded. 876 * <p> 877 * This location is optimal for storing compiled or optimized code generated 878 * by your application at runtime. 879 * <p> 880 * Apps require no extra permissions to read or write to the returned path, 881 * since this path lives in their private storage. 882 * 883 * @return The path of the directory holding application code cache files. 884 */ getCodeCacheDir()885 public abstract File getCodeCacheDir(); 886 887 /** 888 * Returns the absolute path to the directory on the primary external filesystem 889 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory() 890 * Environment.getExternalStorageDirectory()} where the application can 891 * place cache files it owns. These files are internal to the application, and 892 * not typically visible to the user as media. 893 * 894 * <p>This is like {@link #getCacheDir()} in that these 895 * files will be deleted when the application is uninstalled, however there 896 * are some important differences: 897 * 898 * <ul> 899 * <li>The platform does not always monitor the space available in external 900 * storage, and thus may not automatically delete these files. Currently 901 * the only time files here will be deleted by the platform is when running 902 * on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and 903 * {@link android.os.Environment#isExternalStorageEmulated() 904 * Environment.isExternalStorageEmulated()} returns true. Note that you should 905 * be managing the maximum space you will use for these anyway, just like 906 * with {@link #getCacheDir()}. 907 * <li>External files are not always available: they will disappear if the 908 * user mounts the external storage on a computer or removes it. See the 909 * APIs on {@link android.os.Environment} for information in the storage state. 910 * <li>There is no security enforced with these files. For example, any application 911 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to 912 * these files. 913 * </ul> 914 * 915 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions 916 * are required to read or write to the returned path; it's always 917 * accessible to the calling app. This only applies to paths generated for 918 * package name of the calling application. To access paths belonging 919 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} 920 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required. 921 * 922 * <p>On devices with multiple users (as described by {@link UserManager}), 923 * each user has their own isolated external storage. Applications only 924 * have access to the external storage for the user they're running as.</p> 925 * 926 * @return The path of the directory holding application cache files 927 * on external storage. Returns null if external storage is not currently 928 * mounted so it could not ensure the path exists; you will need to call 929 * this method again when it is available. 930 * 931 * @see #getCacheDir 932 */ 933 @Nullable getExternalCacheDir()934 public abstract File getExternalCacheDir(); 935 936 /** 937 * Returns absolute paths to application-specific directories on all 938 * external storage devices where the application can place cache files it 939 * owns. These files are internal to the application, and not typically 940 * visible to the user as media. 941 * <p> 942 * This is like {@link #getCacheDir()} in that these files will be deleted when 943 * the application is uninstalled, however there are some important differences: 944 * <ul> 945 * <li>External files are not always available: they will disappear if the 946 * user mounts the external storage on a computer or removes it. 947 * <li>There is no security enforced with these files. 948 * </ul> 949 * <p> 950 * External storage devices returned here are considered a permanent part of 951 * the device, including both emulated external storage and physical media 952 * slots, such as SD cards in a battery compartment. The returned paths do 953 * not include transient devices, such as USB flash drives. 954 * <p> 955 * An application may store data on any or all of the returned devices. For 956 * example, an app may choose to store large files on the device with the 957 * most available space, as measured by {@link StatFs}. 958 * <p> 959 * No permissions are required to read or write to the returned paths; they 960 * are always accessible to the calling app. Write access outside of these 961 * paths on secondary external storage devices is not available. 962 * <p> 963 * The first path returned is the same as {@link #getExternalCacheDir()}. 964 * Returned paths may be {@code null} if a storage device is unavailable. 965 * 966 * @see #getExternalCacheDir() 967 * @see Environment#getExternalStorageState(File) 968 */ getExternalCacheDirs()969 public abstract File[] getExternalCacheDirs(); 970 971 /** 972 * Returns absolute paths to application-specific directories on all 973 * external storage devices where the application can place media files. 974 * These files are scanned and made available to other apps through 975 * {@link MediaStore}. 976 * <p> 977 * This is like {@link #getExternalFilesDirs} in that these files will be 978 * deleted when the application is uninstalled, however there are some 979 * important differences: 980 * <ul> 981 * <li>External files are not always available: they will disappear if the 982 * user mounts the external storage on a computer or removes it. 983 * <li>There is no security enforced with these files. 984 * </ul> 985 * <p> 986 * External storage devices returned here are considered a permanent part of 987 * the device, including both emulated external storage and physical media 988 * slots, such as SD cards in a battery compartment. The returned paths do 989 * not include transient devices, such as USB flash drives. 990 * <p> 991 * An application may store data on any or all of the returned devices. For 992 * example, an app may choose to store large files on the device with the 993 * most available space, as measured by {@link StatFs}. 994 * <p> 995 * No permissions are required to read or write to the returned paths; they 996 * are always accessible to the calling app. Write access outside of these 997 * paths on secondary external storage devices is not available. 998 * <p> 999 * Returned paths may be {@code null} if a storage device is unavailable. 1000 * 1001 * @see Environment#getExternalStorageState(File) 1002 */ getExternalMediaDirs()1003 public abstract File[] getExternalMediaDirs(); 1004 1005 /** 1006 * Returns an array of strings naming the private files associated with 1007 * this Context's application package. 1008 * 1009 * @return Array of strings naming the private files. 1010 * 1011 * @see #openFileInput 1012 * @see #openFileOutput 1013 * @see #deleteFile 1014 */ fileList()1015 public abstract String[] fileList(); 1016 1017 /** 1018 * Retrieve, creating if needed, a new directory in which the application 1019 * can place its own custom data files. You can use the returned File 1020 * object to create and access files in this directory. Note that files 1021 * created through a File object will only be accessible by your own 1022 * application; you can only set the mode of the entire directory, not 1023 * of individual files. 1024 * 1025 * @param name Name of the directory to retrieve. This is a directory 1026 * that is created as part of your application data. 1027 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 1028 * default operation, {@link #MODE_WORLD_READABLE} and 1029 * {@link #MODE_WORLD_WRITEABLE} to control permissions. 1030 * 1031 * @return A {@link File} object for the requested directory. The directory 1032 * will have been created if it does not already exist. 1033 * 1034 * @see #openFileOutput(String, int) 1035 */ getDir(String name, int mode)1036 public abstract File getDir(String name, int mode); 1037 1038 /** 1039 * Open a new private SQLiteDatabase associated with this Context's 1040 * application package. Create the database file if it doesn't exist. 1041 * 1042 * @param name The name (unique in the application package) of the database. 1043 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 1044 * default operation, {@link #MODE_WORLD_READABLE} 1045 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. 1046 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default. 1047 * @param factory An optional factory class that is called to instantiate a 1048 * cursor when query is called. 1049 * 1050 * @return The contents of a newly created database with the given name. 1051 * @throws android.database.sqlite.SQLiteException if the database file could not be opened. 1052 * 1053 * @see #MODE_PRIVATE 1054 * @see #MODE_WORLD_READABLE 1055 * @see #MODE_WORLD_WRITEABLE 1056 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING 1057 * @see #deleteDatabase 1058 */ openOrCreateDatabase(String name, int mode, CursorFactory factory)1059 public abstract SQLiteDatabase openOrCreateDatabase(String name, 1060 int mode, CursorFactory factory); 1061 1062 /** 1063 * Open a new private SQLiteDatabase associated with this Context's 1064 * application package. Creates the database file if it doesn't exist. 1065 * 1066 * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be 1067 * used to handle corruption when sqlite reports database corruption.</p> 1068 * 1069 * @param name The name (unique in the application package) of the database. 1070 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 1071 * default operation, {@link #MODE_WORLD_READABLE} 1072 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. 1073 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default. 1074 * @param factory An optional factory class that is called to instantiate a 1075 * cursor when query is called. 1076 * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database 1077 * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed. 1078 * @return The contents of a newly created database with the given name. 1079 * @throws android.database.sqlite.SQLiteException if the database file could not be opened. 1080 * 1081 * @see #MODE_PRIVATE 1082 * @see #MODE_WORLD_READABLE 1083 * @see #MODE_WORLD_WRITEABLE 1084 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING 1085 * @see #deleteDatabase 1086 */ openOrCreateDatabase(String name, int mode, CursorFactory factory, @Nullable DatabaseErrorHandler errorHandler)1087 public abstract SQLiteDatabase openOrCreateDatabase(String name, 1088 int mode, CursorFactory factory, 1089 @Nullable DatabaseErrorHandler errorHandler); 1090 1091 /** 1092 * Delete an existing private SQLiteDatabase associated with this Context's 1093 * application package. 1094 * 1095 * @param name The name (unique in the application package) of the 1096 * database. 1097 * 1098 * @return {@code true} if the database was successfully deleted; else {@code false}. 1099 * 1100 * @see #openOrCreateDatabase 1101 */ deleteDatabase(String name)1102 public abstract boolean deleteDatabase(String name); 1103 1104 /** 1105 * Returns the absolute path on the filesystem where a database created with 1106 * {@link #openOrCreateDatabase} is stored. 1107 * 1108 * @param name The name of the database for which you would like to get 1109 * its path. 1110 * 1111 * @return An absolute path to the given database. 1112 * 1113 * @see #openOrCreateDatabase 1114 */ getDatabasePath(String name)1115 public abstract File getDatabasePath(String name); 1116 1117 /** 1118 * Returns an array of strings naming the private databases associated with 1119 * this Context's application package. 1120 * 1121 * @return Array of strings naming the private databases. 1122 * 1123 * @see #openOrCreateDatabase 1124 * @see #deleteDatabase 1125 */ databaseList()1126 public abstract String[] databaseList(); 1127 1128 /** 1129 * @deprecated Use {@link android.app.WallpaperManager#getDrawable 1130 * WallpaperManager.get()} instead. 1131 */ 1132 @Deprecated getWallpaper()1133 public abstract Drawable getWallpaper(); 1134 1135 /** 1136 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable 1137 * WallpaperManager.peek()} instead. 1138 */ 1139 @Deprecated peekWallpaper()1140 public abstract Drawable peekWallpaper(); 1141 1142 /** 1143 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth() 1144 * WallpaperManager.getDesiredMinimumWidth()} instead. 1145 */ 1146 @Deprecated getWallpaperDesiredMinimumWidth()1147 public abstract int getWallpaperDesiredMinimumWidth(); 1148 1149 /** 1150 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight() 1151 * WallpaperManager.getDesiredMinimumHeight()} instead. 1152 */ 1153 @Deprecated getWallpaperDesiredMinimumHeight()1154 public abstract int getWallpaperDesiredMinimumHeight(); 1155 1156 /** 1157 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap) 1158 * WallpaperManager.set()} instead. 1159 * <p>This method requires the caller to hold the permission 1160 * {@link android.Manifest.permission#SET_WALLPAPER}. 1161 */ 1162 @Deprecated setWallpaper(Bitmap bitmap)1163 public abstract void setWallpaper(Bitmap bitmap) throws IOException; 1164 1165 /** 1166 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream) 1167 * WallpaperManager.set()} instead. 1168 * <p>This method requires the caller to hold the permission 1169 * {@link android.Manifest.permission#SET_WALLPAPER}. 1170 */ 1171 @Deprecated setWallpaper(InputStream data)1172 public abstract void setWallpaper(InputStream data) throws IOException; 1173 1174 /** 1175 * @deprecated Use {@link android.app.WallpaperManager#clear 1176 * WallpaperManager.clear()} instead. 1177 * <p>This method requires the caller to hold the permission 1178 * {@link android.Manifest.permission#SET_WALLPAPER}. 1179 */ 1180 @Deprecated clearWallpaper()1181 public abstract void clearWallpaper() throws IOException; 1182 1183 /** 1184 * Same as {@link #startActivity(Intent, Bundle)} with no options 1185 * specified. 1186 * 1187 * @param intent The description of the activity to start. 1188 * 1189 * @throws ActivityNotFoundException 1190 * 1191 * @see #startActivity(Intent, Bundle) 1192 * @see PackageManager#resolveActivity 1193 */ startActivity(Intent intent)1194 public abstract void startActivity(Intent intent); 1195 1196 /** 1197 * Version of {@link #startActivity(Intent)} that allows you to specify the 1198 * user the activity will be started for. This is not available to applications 1199 * that are not pre-installed on the system image. Using it requires holding 1200 * the INTERACT_ACROSS_USERS_FULL permission. 1201 * @param intent The description of the activity to start. 1202 * @param user The UserHandle of the user to start this activity for. 1203 * @throws ActivityNotFoundException 1204 * @hide 1205 */ startActivityAsUser(Intent intent, UserHandle user)1206 public void startActivityAsUser(Intent intent, UserHandle user) { 1207 throw new RuntimeException("Not implemented. Must override in a subclass."); 1208 } 1209 1210 /** 1211 * Launch a new activity. You will not receive any information about when 1212 * the activity exits. 1213 * 1214 * <p>Note that if this method is being called from outside of an 1215 * {@link android.app.Activity} Context, then the Intent must include 1216 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because, 1217 * without being started from an existing Activity, there is no existing 1218 * task in which to place the new activity and thus it needs to be placed 1219 * in its own separate task. 1220 * 1221 * <p>This method throws {@link ActivityNotFoundException} 1222 * if there was no Activity found to run the given Intent. 1223 * 1224 * @param intent The description of the activity to start. 1225 * @param options Additional options for how the Activity should be started. 1226 * May be null if there are no options. See {@link android.app.ActivityOptions} 1227 * for how to build the Bundle supplied here; there are no supported definitions 1228 * for building it manually. 1229 * 1230 * @throws ActivityNotFoundException 1231 * 1232 * @see #startActivity(Intent) 1233 * @see PackageManager#resolveActivity 1234 */ startActivity(Intent intent, @Nullable Bundle options)1235 public abstract void startActivity(Intent intent, @Nullable Bundle options); 1236 1237 /** 1238 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the 1239 * user the activity will be started for. This is not available to applications 1240 * that are not pre-installed on the system image. Using it requires holding 1241 * the INTERACT_ACROSS_USERS_FULL permission. 1242 * @param intent The description of the activity to start. 1243 * @param options Additional options for how the Activity should be started. 1244 * May be null if there are no options. See {@link android.app.ActivityOptions} 1245 * for how to build the Bundle supplied here; there are no supported definitions 1246 * for building it manually. 1247 * @param userId The UserHandle of the user to start this activity for. 1248 * @throws ActivityNotFoundException 1249 * @hide 1250 */ startActivityAsUser(Intent intent, @Nullable Bundle options, UserHandle userId)1251 public void startActivityAsUser(Intent intent, @Nullable Bundle options, UserHandle userId) { 1252 throw new RuntimeException("Not implemented. Must override in a subclass."); 1253 } 1254 1255 /** 1256 * Same as {@link #startActivities(Intent[], Bundle)} with no options 1257 * specified. 1258 * 1259 * @param intents An array of Intents to be started. 1260 * 1261 * @throws ActivityNotFoundException 1262 * 1263 * @see #startActivities(Intent[], Bundle) 1264 * @see PackageManager#resolveActivity 1265 */ startActivities(Intent[] intents)1266 public abstract void startActivities(Intent[] intents); 1267 1268 /** 1269 * Launch multiple new activities. This is generally the same as calling 1270 * {@link #startActivity(Intent)} for the first Intent in the array, 1271 * that activity during its creation calling {@link #startActivity(Intent)} 1272 * for the second entry, etc. Note that unlike that approach, generally 1273 * none of the activities except the last in the array will be created 1274 * at this point, but rather will be created when the user first visits 1275 * them (due to pressing back from the activity on top). 1276 * 1277 * <p>This method throws {@link ActivityNotFoundException} 1278 * if there was no Activity found for <em>any</em> given Intent. In this 1279 * case the state of the activity stack is undefined (some Intents in the 1280 * list may be on it, some not), so you probably want to avoid such situations. 1281 * 1282 * @param intents An array of Intents to be started. 1283 * @param options Additional options for how the Activity should be started. 1284 * See {@link android.content.Context#startActivity(Intent, Bundle) 1285 * Context.startActivity(Intent, Bundle)} for more details. 1286 * 1287 * @throws ActivityNotFoundException 1288 * 1289 * @see #startActivities(Intent[]) 1290 * @see PackageManager#resolveActivity 1291 */ startActivities(Intent[] intents, Bundle options)1292 public abstract void startActivities(Intent[] intents, Bundle options); 1293 1294 /** 1295 * @hide 1296 * Launch multiple new activities. This is generally the same as calling 1297 * {@link #startActivity(Intent)} for the first Intent in the array, 1298 * that activity during its creation calling {@link #startActivity(Intent)} 1299 * for the second entry, etc. Note that unlike that approach, generally 1300 * none of the activities except the last in the array will be created 1301 * at this point, but rather will be created when the user first visits 1302 * them (due to pressing back from the activity on top). 1303 * 1304 * <p>This method throws {@link ActivityNotFoundException} 1305 * if there was no Activity found for <em>any</em> given Intent. In this 1306 * case the state of the activity stack is undefined (some Intents in the 1307 * list may be on it, some not), so you probably want to avoid such situations. 1308 * 1309 * @param intents An array of Intents to be started. 1310 * @param options Additional options for how the Activity should be started. 1311 * @param userHandle The user for whom to launch the activities 1312 * See {@link android.content.Context#startActivity(Intent, Bundle) 1313 * Context.startActivity(Intent, Bundle)} for more details. 1314 * 1315 * @throws ActivityNotFoundException 1316 * 1317 * @see #startActivities(Intent[]) 1318 * @see PackageManager#resolveActivity 1319 */ startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle)1320 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) { 1321 throw new RuntimeException("Not implemented. Must override in a subclass."); 1322 } 1323 1324 /** 1325 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)} 1326 * with no options specified. 1327 * 1328 * @param intent The IntentSender to launch. 1329 * @param fillInIntent If non-null, this will be provided as the 1330 * intent parameter to {@link IntentSender#sendIntent}. 1331 * @param flagsMask Intent flags in the original IntentSender that you 1332 * would like to change. 1333 * @param flagsValues Desired values for any bits set in 1334 * <var>flagsMask</var> 1335 * @param extraFlags Always set to 0. 1336 * 1337 * @see #startActivity(Intent) 1338 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle) 1339 */ startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)1340 public abstract void startIntentSender(IntentSender intent, 1341 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) 1342 throws IntentSender.SendIntentException; 1343 1344 /** 1345 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender 1346 * to start. If the IntentSender is for an activity, that activity will be started 1347 * as if you had called the regular {@link #startActivity(Intent)} 1348 * here; otherwise, its associated action will be executed (such as 1349 * sending a broadcast) as if you had called 1350 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it. 1351 * 1352 * @param intent The IntentSender to launch. 1353 * @param fillInIntent If non-null, this will be provided as the 1354 * intent parameter to {@link IntentSender#sendIntent}. 1355 * @param flagsMask Intent flags in the original IntentSender that you 1356 * would like to change. 1357 * @param flagsValues Desired values for any bits set in 1358 * <var>flagsMask</var> 1359 * @param extraFlags Always set to 0. 1360 * @param options Additional options for how the Activity should be started. 1361 * See {@link android.content.Context#startActivity(Intent, Bundle) 1362 * Context.startActivity(Intent, Bundle)} for more details. If options 1363 * have also been supplied by the IntentSender, options given here will 1364 * override any that conflict with those given by the IntentSender. 1365 * 1366 * @see #startActivity(Intent, Bundle) 1367 * @see #startIntentSender(IntentSender, Intent, int, int, int) 1368 */ startIntentSender(IntentSender intent, @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options)1369 public abstract void startIntentSender(IntentSender intent, 1370 @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, 1371 Bundle options) throws IntentSender.SendIntentException; 1372 1373 /** 1374 * Broadcast the given intent to all interested BroadcastReceivers. This 1375 * call is asynchronous; it returns immediately, and you will continue 1376 * executing while the receivers are run. No results are propagated from 1377 * receivers and receivers can not abort the broadcast. If you want 1378 * to allow receivers to propagate results or abort the broadcast, you must 1379 * send an ordered broadcast using 1380 * {@link #sendOrderedBroadcast(Intent, String)}. 1381 * 1382 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1383 * 1384 * @param intent The Intent to broadcast; all receivers matching this 1385 * Intent will receive the broadcast. 1386 * 1387 * @see android.content.BroadcastReceiver 1388 * @see #registerReceiver 1389 * @see #sendBroadcast(Intent, String) 1390 * @see #sendOrderedBroadcast(Intent, String) 1391 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 1392 */ sendBroadcast(Intent intent)1393 public abstract void sendBroadcast(Intent intent); 1394 1395 /** 1396 * Broadcast the given intent to all interested BroadcastReceivers, allowing 1397 * an optional required permission to be enforced. This 1398 * call is asynchronous; it returns immediately, and you will continue 1399 * executing while the receivers are run. No results are propagated from 1400 * receivers and receivers can not abort the broadcast. If you want 1401 * to allow receivers to propagate results or abort the broadcast, you must 1402 * send an ordered broadcast using 1403 * {@link #sendOrderedBroadcast(Intent, String)}. 1404 * 1405 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1406 * 1407 * @param intent The Intent to broadcast; all receivers matching this 1408 * Intent will receive the broadcast. 1409 * @param receiverPermission (optional) String naming a permission that 1410 * a receiver must hold in order to receive your broadcast. 1411 * If null, no permission is required. 1412 * 1413 * @see android.content.BroadcastReceiver 1414 * @see #registerReceiver 1415 * @see #sendBroadcast(Intent) 1416 * @see #sendOrderedBroadcast(Intent, String) 1417 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 1418 */ sendBroadcast(Intent intent, @Nullable String receiverPermission)1419 public abstract void sendBroadcast(Intent intent, 1420 @Nullable String receiverPermission); 1421 1422 /** 1423 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification 1424 * of an associated app op as per {@link android.app.AppOpsManager}. 1425 * @hide 1426 */ sendBroadcast(Intent intent, String receiverPermission, int appOp)1427 public abstract void sendBroadcast(Intent intent, 1428 String receiverPermission, int appOp); 1429 1430 /** 1431 * Broadcast the given intent to all interested BroadcastReceivers, delivering 1432 * them one at a time to allow more preferred receivers to consume the 1433 * broadcast before it is delivered to less preferred receivers. This 1434 * call is asynchronous; it returns immediately, and you will continue 1435 * executing while the receivers are run. 1436 * 1437 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1438 * 1439 * @param intent The Intent to broadcast; all receivers matching this 1440 * Intent will receive the broadcast. 1441 * @param receiverPermission (optional) String naming a permissions that 1442 * a receiver must hold in order to receive your broadcast. 1443 * If null, no permission is required. 1444 * 1445 * @see android.content.BroadcastReceiver 1446 * @see #registerReceiver 1447 * @see #sendBroadcast(Intent) 1448 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 1449 */ sendOrderedBroadcast(Intent intent, @Nullable String receiverPermission)1450 public abstract void sendOrderedBroadcast(Intent intent, 1451 @Nullable String receiverPermission); 1452 1453 /** 1454 * Version of {@link #sendBroadcast(Intent)} that allows you to 1455 * receive data back from the broadcast. This is accomplished by 1456 * supplying your own BroadcastReceiver when calling, which will be 1457 * treated as a final receiver at the end of the broadcast -- its 1458 * {@link BroadcastReceiver#onReceive} method will be called with 1459 * the result values collected from the other receivers. The broadcast will 1460 * be serialized in the same way as calling 1461 * {@link #sendOrderedBroadcast(Intent, String)}. 1462 * 1463 * <p>Like {@link #sendBroadcast(Intent)}, this method is 1464 * asynchronous; it will return before 1465 * resultReceiver.onReceive() is called. 1466 * 1467 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1468 * 1469 * @param intent The Intent to broadcast; all receivers matching this 1470 * Intent will receive the broadcast. 1471 * @param receiverPermission String naming a permissions that 1472 * a receiver must hold in order to receive your broadcast. 1473 * If null, no permission is required. 1474 * @param resultReceiver Your own BroadcastReceiver to treat as the final 1475 * receiver of the broadcast. 1476 * @param scheduler A custom Handler with which to schedule the 1477 * resultReceiver callback; if null it will be 1478 * scheduled in the Context's main thread. 1479 * @param initialCode An initial value for the result code. Often 1480 * Activity.RESULT_OK. 1481 * @param initialData An initial value for the result data. Often 1482 * null. 1483 * @param initialExtras An initial value for the result extras. Often 1484 * null. 1485 * 1486 * @see #sendBroadcast(Intent) 1487 * @see #sendBroadcast(Intent, String) 1488 * @see #sendOrderedBroadcast(Intent, String) 1489 * @see android.content.BroadcastReceiver 1490 * @see #registerReceiver 1491 * @see android.app.Activity#RESULT_OK 1492 */ sendOrderedBroadcast(@onNull Intent intent, @Nullable String receiverPermission, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)1493 public abstract void sendOrderedBroadcast(@NonNull Intent intent, 1494 @Nullable String receiverPermission, BroadcastReceiver resultReceiver, 1495 @Nullable Handler scheduler, int initialCode, @Nullable String initialData, 1496 @Nullable Bundle initialExtras); 1497 1498 /** 1499 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, 1500 * int, String, android.os.Bundle)}, but also allows specification 1501 * of an associated app op as per {@link android.app.AppOpsManager}. 1502 * @hide 1503 */ sendOrderedBroadcast(Intent intent, String receiverPermission, int appOp, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)1504 public abstract void sendOrderedBroadcast(Intent intent, 1505 String receiverPermission, int appOp, BroadcastReceiver resultReceiver, 1506 Handler scheduler, int initialCode, String initialData, 1507 Bundle initialExtras); 1508 1509 /** 1510 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the 1511 * user the broadcast will be sent to. This is not available to applications 1512 * that are not pre-installed on the system image. Using it requires holding 1513 * the INTERACT_ACROSS_USERS permission. 1514 * @param intent The intent to broadcast 1515 * @param user UserHandle to send the intent to. 1516 * @see #sendBroadcast(Intent) 1517 */ sendBroadcastAsUser(Intent intent, UserHandle user)1518 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user); 1519 1520 /** 1521 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the 1522 * user the broadcast will be sent to. This is not available to applications 1523 * that are not pre-installed on the system image. Using it requires holding 1524 * the INTERACT_ACROSS_USERS permission. 1525 * 1526 * @param intent The Intent to broadcast; all receivers matching this 1527 * Intent will receive the broadcast. 1528 * @param user UserHandle to send the intent to. 1529 * @param receiverPermission (optional) String naming a permission that 1530 * a receiver must hold in order to receive your broadcast. 1531 * If null, no permission is required. 1532 * 1533 * @see #sendBroadcast(Intent, String) 1534 */ sendBroadcastAsUser(Intent intent, UserHandle user, @Nullable String receiverPermission)1535 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user, 1536 @Nullable String receiverPermission); 1537 1538 /** 1539 * Version of 1540 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)} 1541 * that allows you to specify the 1542 * user the broadcast will be sent to. This is not available to applications 1543 * that are not pre-installed on the system image. Using it requires holding 1544 * the INTERACT_ACROSS_USERS permission. 1545 * 1546 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1547 * 1548 * @param intent The Intent to broadcast; all receivers matching this 1549 * Intent will receive the broadcast. 1550 * @param user UserHandle to send the intent to. 1551 * @param receiverPermission String naming a permissions that 1552 * a receiver must hold in order to receive your broadcast. 1553 * If null, no permission is required. 1554 * @param resultReceiver Your own BroadcastReceiver to treat as the final 1555 * receiver of the broadcast. 1556 * @param scheduler A custom Handler with which to schedule the 1557 * resultReceiver callback; if null it will be 1558 * scheduled in the Context's main thread. 1559 * @param initialCode An initial value for the result code. Often 1560 * Activity.RESULT_OK. 1561 * @param initialData An initial value for the result data. Often 1562 * null. 1563 * @param initialExtras An initial value for the result extras. Often 1564 * null. 1565 * 1566 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 1567 */ sendOrderedBroadcastAsUser(Intent intent, UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)1568 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, 1569 @Nullable String receiverPermission, BroadcastReceiver resultReceiver, 1570 @Nullable Handler scheduler, int initialCode, @Nullable String initialData, 1571 @Nullable Bundle initialExtras); 1572 1573 /** 1574 * Similar to above but takes an appOp as well, to enforce restrictions. 1575 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String, 1576 * BroadcastReceiver, Handler, int, String, Bundle) 1577 * @hide 1578 */ sendOrderedBroadcastAsUser(Intent intent, UserHandle user, @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)1579 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, 1580 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver, 1581 @Nullable Handler scheduler, int initialCode, @Nullable String initialData, 1582 @Nullable Bundle initialExtras); 1583 1584 /** 1585 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the 1586 * Intent you are sending stays around after the broadcast is complete, 1587 * so that others can quickly retrieve that data through the return 1588 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In 1589 * all other ways, this behaves the same as 1590 * {@link #sendBroadcast(Intent)}. 1591 * 1592 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY} 1593 * permission in order to use this API. If you do not hold that 1594 * permission, {@link SecurityException} will be thrown. 1595 * 1596 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone 1597 * can access them), no protection (anyone can modify them), and many other problems. 1598 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> 1599 * has changed, with another mechanism for apps to retrieve the current value whenever 1600 * desired. 1601 * 1602 * @param intent The Intent to broadcast; all receivers matching this 1603 * Intent will receive the broadcast, and the Intent will be held to 1604 * be re-broadcast to future receivers. 1605 * 1606 * @see #sendBroadcast(Intent) 1607 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle) 1608 */ 1609 @Deprecated sendStickyBroadcast(Intent intent)1610 public abstract void sendStickyBroadcast(Intent intent); 1611 1612 /** 1613 * <p>Version of {@link #sendStickyBroadcast} that allows you to 1614 * receive data back from the broadcast. This is accomplished by 1615 * supplying your own BroadcastReceiver when calling, which will be 1616 * treated as a final receiver at the end of the broadcast -- its 1617 * {@link BroadcastReceiver#onReceive} method will be called with 1618 * the result values collected from the other receivers. The broadcast will 1619 * be serialized in the same way as calling 1620 * {@link #sendOrderedBroadcast(Intent, String)}. 1621 * 1622 * <p>Like {@link #sendBroadcast(Intent)}, this method is 1623 * asynchronous; it will return before 1624 * resultReceiver.onReceive() is called. Note that the sticky data 1625 * stored is only the data you initially supply to the broadcast, not 1626 * the result of any changes made by the receivers. 1627 * 1628 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1629 * 1630 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone 1631 * can access them), no protection (anyone can modify them), and many other problems. 1632 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> 1633 * has changed, with another mechanism for apps to retrieve the current value whenever 1634 * desired. 1635 * 1636 * @param intent The Intent to broadcast; all receivers matching this 1637 * Intent will receive the broadcast. 1638 * @param resultReceiver Your own BroadcastReceiver to treat as the final 1639 * receiver of the broadcast. 1640 * @param scheduler A custom Handler with which to schedule the 1641 * resultReceiver callback; if null it will be 1642 * scheduled in the Context's main thread. 1643 * @param initialCode An initial value for the result code. Often 1644 * Activity.RESULT_OK. 1645 * @param initialData An initial value for the result data. Often 1646 * null. 1647 * @param initialExtras An initial value for the result extras. Often 1648 * null. 1649 * 1650 * @see #sendBroadcast(Intent) 1651 * @see #sendBroadcast(Intent, String) 1652 * @see #sendOrderedBroadcast(Intent, String) 1653 * @see #sendStickyBroadcast(Intent) 1654 * @see android.content.BroadcastReceiver 1655 * @see #registerReceiver 1656 * @see android.app.Activity#RESULT_OK 1657 */ 1658 @Deprecated sendStickyOrderedBroadcast(Intent intent, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)1659 public abstract void sendStickyOrderedBroadcast(Intent intent, 1660 BroadcastReceiver resultReceiver, 1661 @Nullable Handler scheduler, int initialCode, @Nullable String initialData, 1662 @Nullable Bundle initialExtras); 1663 1664 /** 1665 * <p>Remove the data previously sent with {@link #sendStickyBroadcast}, 1666 * so that it is as if the sticky broadcast had never happened. 1667 * 1668 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY} 1669 * permission in order to use this API. If you do not hold that 1670 * permission, {@link SecurityException} will be thrown. 1671 * 1672 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone 1673 * can access them), no protection (anyone can modify them), and many other problems. 1674 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> 1675 * has changed, with another mechanism for apps to retrieve the current value whenever 1676 * desired. 1677 * 1678 * @param intent The Intent that was previously broadcast. 1679 * 1680 * @see #sendStickyBroadcast 1681 */ 1682 @Deprecated removeStickyBroadcast(Intent intent)1683 public abstract void removeStickyBroadcast(Intent intent); 1684 1685 /** 1686 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the 1687 * user the broadcast will be sent to. This is not available to applications 1688 * that are not pre-installed on the system image. Using it requires holding 1689 * the INTERACT_ACROSS_USERS permission. 1690 * 1691 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone 1692 * can access them), no protection (anyone can modify them), and many other problems. 1693 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> 1694 * has changed, with another mechanism for apps to retrieve the current value whenever 1695 * desired. 1696 * 1697 * @param intent The Intent to broadcast; all receivers matching this 1698 * Intent will receive the broadcast, and the Intent will be held to 1699 * be re-broadcast to future receivers. 1700 * @param user UserHandle to send the intent to. 1701 * 1702 * @see #sendBroadcast(Intent) 1703 */ 1704 @Deprecated sendStickyBroadcastAsUser(Intent intent, UserHandle user)1705 public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user); 1706 1707 /** 1708 * <p>Version of 1709 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)} 1710 * that allows you to specify the 1711 * user the broadcast will be sent to. This is not available to applications 1712 * that are not pre-installed on the system image. Using it requires holding 1713 * the INTERACT_ACROSS_USERS permission. 1714 * 1715 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1716 * 1717 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone 1718 * can access them), no protection (anyone can modify them), and many other problems. 1719 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> 1720 * has changed, with another mechanism for apps to retrieve the current value whenever 1721 * desired. 1722 * 1723 * @param intent The Intent to broadcast; all receivers matching this 1724 * Intent will receive the broadcast. 1725 * @param user UserHandle to send the intent to. 1726 * @param resultReceiver Your own BroadcastReceiver to treat as the final 1727 * receiver of the broadcast. 1728 * @param scheduler A custom Handler with which to schedule the 1729 * resultReceiver callback; if null it will be 1730 * scheduled in the Context's main thread. 1731 * @param initialCode An initial value for the result code. Often 1732 * Activity.RESULT_OK. 1733 * @param initialData An initial value for the result data. Often 1734 * null. 1735 * @param initialExtras An initial value for the result extras. Often 1736 * null. 1737 * 1738 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle) 1739 */ 1740 @Deprecated sendStickyOrderedBroadcastAsUser(Intent intent, UserHandle user, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)1741 public abstract void sendStickyOrderedBroadcastAsUser(Intent intent, 1742 UserHandle user, BroadcastReceiver resultReceiver, 1743 @Nullable Handler scheduler, int initialCode, @Nullable String initialData, 1744 @Nullable Bundle initialExtras); 1745 1746 /** 1747 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the 1748 * user the broadcast will be sent to. This is not available to applications 1749 * that are not pre-installed on the system image. Using it requires holding 1750 * the INTERACT_ACROSS_USERS permission. 1751 * 1752 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY} 1753 * permission in order to use this API. If you do not hold that 1754 * permission, {@link SecurityException} will be thrown. 1755 * 1756 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone 1757 * can access them), no protection (anyone can modify them), and many other problems. 1758 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> 1759 * has changed, with another mechanism for apps to retrieve the current value whenever 1760 * desired. 1761 * 1762 * @param intent The Intent that was previously broadcast. 1763 * @param user UserHandle to remove the sticky broadcast from. 1764 * 1765 * @see #sendStickyBroadcastAsUser 1766 */ 1767 @Deprecated removeStickyBroadcastAsUser(Intent intent, UserHandle user)1768 public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user); 1769 1770 /** 1771 * Register a BroadcastReceiver to be run in the main activity thread. The 1772 * <var>receiver</var> will be called with any broadcast Intent that 1773 * matches <var>filter</var>, in the main application thread. 1774 * 1775 * <p>The system may broadcast Intents that are "sticky" -- these stay 1776 * around after the broadcast as finished, to be sent to any later 1777 * registrations. If your IntentFilter matches one of these sticky 1778 * Intents, that Intent will be returned by this function 1779 * <strong>and</strong> sent to your <var>receiver</var> as if it had just 1780 * been broadcast. 1781 * 1782 * <p>There may be multiple sticky Intents that match <var>filter</var>, 1783 * in which case each of these will be sent to <var>receiver</var>. In 1784 * this case, only one of these can be returned directly by the function; 1785 * which of these that is returned is arbitrarily decided by the system. 1786 * 1787 * <p>If you know the Intent your are registering for is sticky, you can 1788 * supply null for your <var>receiver</var>. In this case, no receiver is 1789 * registered -- the function simply returns the sticky Intent that 1790 * matches <var>filter</var>. In the case of multiple matches, the same 1791 * rules as described above apply. 1792 * 1793 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1794 * 1795 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers 1796 * registered with this method will correctly respect the 1797 * {@link Intent#setPackage(String)} specified for an Intent being broadcast. 1798 * Prior to that, it would be ignored and delivered to all matching registered 1799 * receivers. Be careful if using this for security.</p> 1800 * 1801 * <p class="note">Note: this method <em>cannot be called from a 1802 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver 1803 * that is declared in an application's manifest. It is okay, however, to call 1804 * this method from another BroadcastReceiver that has itself been registered 1805 * at run time with {@link #registerReceiver}, since the lifetime of such a 1806 * registered BroadcastReceiver is tied to the object that registered it.</p> 1807 * 1808 * @param receiver The BroadcastReceiver to handle the broadcast. 1809 * @param filter Selects the Intent broadcasts to be received. 1810 * 1811 * @return The first sticky intent found that matches <var>filter</var>, 1812 * or null if there are none. 1813 * 1814 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler) 1815 * @see #sendBroadcast 1816 * @see #unregisterReceiver 1817 */ 1818 @Nullable registerReceiver(@ullable BroadcastReceiver receiver, IntentFilter filter)1819 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver, 1820 IntentFilter filter); 1821 1822 /** 1823 * Register to receive intent broadcasts, to run in the context of 1824 * <var>scheduler</var>. See 1825 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more 1826 * information. This allows you to enforce permissions on who can 1827 * broadcast intents to your receiver, or have the receiver run in 1828 * a different thread than the main application thread. 1829 * 1830 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1831 * 1832 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers 1833 * registered with this method will correctly respect the 1834 * {@link Intent#setPackage(String)} specified for an Intent being broadcast. 1835 * Prior to that, it would be ignored and delivered to all matching registered 1836 * receivers. Be careful if using this for security.</p> 1837 * 1838 * @param receiver The BroadcastReceiver to handle the broadcast. 1839 * @param filter Selects the Intent broadcasts to be received. 1840 * @param broadcastPermission String naming a permissions that a 1841 * broadcaster must hold in order to send an Intent to you. If null, 1842 * no permission is required. 1843 * @param scheduler Handler identifying the thread that will receive 1844 * the Intent. If null, the main thread of the process will be used. 1845 * 1846 * @return The first sticky intent found that matches <var>filter</var>, 1847 * or null if there are none. 1848 * 1849 * @see #registerReceiver(BroadcastReceiver, IntentFilter) 1850 * @see #sendBroadcast 1851 * @see #unregisterReceiver 1852 */ 1853 @Nullable registerReceiver(BroadcastReceiver receiver, IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler)1854 public abstract Intent registerReceiver(BroadcastReceiver receiver, 1855 IntentFilter filter, @Nullable String broadcastPermission, 1856 @Nullable Handler scheduler); 1857 1858 /** 1859 * @hide 1860 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler) 1861 * but for a specific user. This receiver will receiver broadcasts that 1862 * are sent to the requested user. It 1863 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} 1864 * permission. 1865 * 1866 * @param receiver The BroadcastReceiver to handle the broadcast. 1867 * @param user UserHandle to send the intent to. 1868 * @param filter Selects the Intent broadcasts to be received. 1869 * @param broadcastPermission String naming a permissions that a 1870 * broadcaster must hold in order to send an Intent to you. If null, 1871 * no permission is required. 1872 * @param scheduler Handler identifying the thread that will receive 1873 * the Intent. If null, the main thread of the process will be used. 1874 * 1875 * @return The first sticky intent found that matches <var>filter</var>, 1876 * or null if there are none. 1877 * 1878 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler 1879 * @see #sendBroadcast 1880 * @see #unregisterReceiver 1881 */ 1882 @Nullable registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user, IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler)1883 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver, 1884 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission, 1885 @Nullable Handler scheduler); 1886 1887 /** 1888 * Unregister a previously registered BroadcastReceiver. <em>All</em> 1889 * filters that have been registered for this BroadcastReceiver will be 1890 * removed. 1891 * 1892 * @param receiver The BroadcastReceiver to unregister. 1893 * 1894 * @see #registerReceiver 1895 */ unregisterReceiver(BroadcastReceiver receiver)1896 public abstract void unregisterReceiver(BroadcastReceiver receiver); 1897 1898 /** 1899 * Request that a given application service be started. The Intent 1900 * should contain either contain the complete class name of a specific service 1901 * implementation to start or a specific package name to target. If the 1902 * Intent is less specified, it log a warning about this and which of the 1903 * multiple matching services it finds and uses will be undefined. If this service 1904 * is not already running, it will be instantiated and started (creating a 1905 * process for it if needed); if it is running then it remains running. 1906 * 1907 * <p>Every call to this method will result in a corresponding call to 1908 * the target service's {@link android.app.Service#onStartCommand} method, 1909 * with the <var>intent</var> given here. This provides a convenient way 1910 * to submit jobs to a service without having to bind and call on to its 1911 * interface. 1912 * 1913 * <p>Using startService() overrides the default service lifetime that is 1914 * managed by {@link #bindService}: it requires the service to remain 1915 * running until {@link #stopService} is called, regardless of whether 1916 * any clients are connected to it. Note that calls to startService() 1917 * are not nesting: no matter how many times you call startService(), 1918 * a single call to {@link #stopService} will stop it. 1919 * 1920 * <p>The system attempts to keep running services around as much as 1921 * possible. The only time they should be stopped is if the current 1922 * foreground application is using so many resources that the service needs 1923 * to be killed. If any errors happen in the service's process, it will 1924 * automatically be restarted. 1925 * 1926 * <p>This function will throw {@link SecurityException} if you do not 1927 * have permission to start the given service. 1928 * 1929 * @param service Identifies the service to be started. The Intent must be either 1930 * fully explicit (supplying a component name) or specify a specific package 1931 * name it is targetted to. Additional values 1932 * may be included in the Intent extras to supply arguments along with 1933 * this specific start call. 1934 * 1935 * @return If the service is being started or is already running, the 1936 * {@link ComponentName} of the actual service that was started is 1937 * returned; else if the service does not exist null is returned. 1938 * 1939 * @throws SecurityException 1940 * 1941 * @see #stopService 1942 * @see #bindService 1943 */ 1944 @Nullable startService(Intent service)1945 public abstract ComponentName startService(Intent service); 1946 1947 /** 1948 * Request that a given application service be stopped. If the service is 1949 * not running, nothing happens. Otherwise it is stopped. Note that calls 1950 * to startService() are not counted -- this stops the service no matter 1951 * how many times it was started. 1952 * 1953 * <p>Note that if a stopped service still has {@link ServiceConnection} 1954 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will 1955 * not be destroyed until all of these bindings are removed. See 1956 * the {@link android.app.Service} documentation for more details on a 1957 * service's lifecycle. 1958 * 1959 * <p>This function will throw {@link SecurityException} if you do not 1960 * have permission to stop the given service. 1961 * 1962 * @param service Description of the service to be stopped. The Intent must be either 1963 * fully explicit (supplying a component name) or specify a specific package 1964 * name it is targetted to. 1965 * 1966 * @return If there is a service matching the given Intent that is already 1967 * running, then it is stopped and {@code true} is returned; else {@code false} is returned. 1968 * 1969 * @throws SecurityException 1970 * 1971 * @see #startService 1972 */ stopService(Intent service)1973 public abstract boolean stopService(Intent service); 1974 1975 /** 1976 * @hide like {@link #startService(Intent)} but for a specific user. 1977 */ startServiceAsUser(Intent service, UserHandle user)1978 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user); 1979 1980 /** 1981 * @hide like {@link #stopService(Intent)} but for a specific user. 1982 */ stopServiceAsUser(Intent service, UserHandle user)1983 public abstract boolean stopServiceAsUser(Intent service, UserHandle user); 1984 1985 /** 1986 * Connect to an application service, creating it if needed. This defines 1987 * a dependency between your application and the service. The given 1988 * <var>conn</var> will receive the service object when it is created and be 1989 * told if it dies and restarts. The service will be considered required 1990 * by the system only for as long as the calling context exists. For 1991 * example, if this Context is an Activity that is stopped, the service will 1992 * not be required to continue running until the Activity is resumed. 1993 * 1994 * <p>This function will throw {@link SecurityException} if you do not 1995 * have permission to bind to the given service. 1996 * 1997 * <p class="note">Note: this method <em>can not be called from a 1998 * {@link BroadcastReceiver} component</em>. A pattern you can use to 1999 * communicate from a BroadcastReceiver to a Service is to call 2000 * {@link #startService} with the arguments containing the command to be 2001 * sent, with the service calling its 2002 * {@link android.app.Service#stopSelf(int)} method when done executing 2003 * that command. See the API demo App/Service/Service Start Arguments 2004 * Controller for an illustration of this. It is okay, however, to use 2005 * this method from a BroadcastReceiver that has been registered with 2006 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver 2007 * is tied to another object (the one that registered it).</p> 2008 * 2009 * @param service Identifies the service to connect to. The Intent may 2010 * specify either an explicit component name, or a logical 2011 * description (action, category, etc) to match an 2012 * {@link IntentFilter} published by a service. 2013 * @param conn Receives information as the service is started and stopped. 2014 * This must be a valid ServiceConnection object; it must not be null. 2015 * @param flags Operation options for the binding. May be 0, 2016 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND}, 2017 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT}, 2018 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or 2019 * {@link #BIND_WAIVE_PRIORITY}. 2020 * @return If you have successfully bound to the service, {@code true} is returned; 2021 * {@code false} is returned if the connection is not made so you will not 2022 * receive the service object. 2023 * 2024 * @throws SecurityException 2025 * 2026 * @see #unbindService 2027 * @see #startService 2028 * @see #BIND_AUTO_CREATE 2029 * @see #BIND_DEBUG_UNBIND 2030 * @see #BIND_NOT_FOREGROUND 2031 */ bindService(Intent service, @NonNull ServiceConnection conn, @BindServiceFlags int flags)2032 public abstract boolean bindService(Intent service, @NonNull ServiceConnection conn, 2033 @BindServiceFlags int flags); 2034 2035 /** 2036 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle 2037 * argument for use by system server and other multi-user aware code. 2038 * @hide 2039 */ 2040 @SystemApi bindServiceAsUser(Intent service, ServiceConnection conn, int flags, UserHandle user)2041 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags, UserHandle user) { 2042 throw new RuntimeException("Not implemented. Must override in a subclass."); 2043 } 2044 2045 /** 2046 * Disconnect from an application service. You will no longer receive 2047 * calls as the service is restarted, and the service is now allowed to 2048 * stop at any time. 2049 * 2050 * @param conn The connection interface previously supplied to 2051 * bindService(). This parameter must not be null. 2052 * 2053 * @see #bindService 2054 */ unbindService(@onNull ServiceConnection conn)2055 public abstract void unbindService(@NonNull ServiceConnection conn); 2056 2057 /** 2058 * Start executing an {@link android.app.Instrumentation} class. The given 2059 * Instrumentation component will be run by killing its target application 2060 * (if currently running), starting the target process, instantiating the 2061 * instrumentation component, and then letting it drive the application. 2062 * 2063 * <p>This function is not synchronous -- it returns as soon as the 2064 * instrumentation has started and while it is running. 2065 * 2066 * <p>Instrumentation is normally only allowed to run against a package 2067 * that is either unsigned or signed with a signature that the 2068 * the instrumentation package is also signed with (ensuring the target 2069 * trusts the instrumentation). 2070 * 2071 * @param className Name of the Instrumentation component to be run. 2072 * @param profileFile Optional path to write profiling data as the 2073 * instrumentation runs, or null for no profiling. 2074 * @param arguments Additional optional arguments to pass to the 2075 * instrumentation, or null. 2076 * 2077 * @return {@code true} if the instrumentation was successfully started, 2078 * else {@code false} if it could not be found. 2079 */ startInstrumentation(@onNull ComponentName className, @Nullable String profileFile, @Nullable Bundle arguments)2080 public abstract boolean startInstrumentation(@NonNull ComponentName className, 2081 @Nullable String profileFile, @Nullable Bundle arguments); 2082 2083 /** @hide */ 2084 @StringDef({ 2085 POWER_SERVICE, 2086 WINDOW_SERVICE, 2087 LAYOUT_INFLATER_SERVICE, 2088 ACCOUNT_SERVICE, 2089 ACTIVITY_SERVICE, 2090 ALARM_SERVICE, 2091 NOTIFICATION_SERVICE, 2092 ACCESSIBILITY_SERVICE, 2093 CAPTIONING_SERVICE, 2094 KEYGUARD_SERVICE, 2095 LOCATION_SERVICE, 2096 //@hide: COUNTRY_DETECTOR, 2097 SEARCH_SERVICE, 2098 SENSOR_SERVICE, 2099 STORAGE_SERVICE, 2100 WALLPAPER_SERVICE, 2101 VIBRATOR_SERVICE, 2102 //@hide: STATUS_BAR_SERVICE, 2103 CONNECTIVITY_SERVICE, 2104 //@hide: UPDATE_LOCK_SERVICE, 2105 //@hide: NETWORKMANAGEMENT_SERVICE, 2106 //@hide: NETWORK_STATS_SERVICE, 2107 //@hide: NETWORK_POLICY_SERVICE, 2108 WIFI_SERVICE, 2109 WIFI_PASSPOINT_SERVICE, 2110 WIFI_P2P_SERVICE, 2111 WIFI_SCANNING_SERVICE, 2112 //@hide: ETHERNET_SERVICE, 2113 WIFI_RTT_SERVICE, 2114 NSD_SERVICE, 2115 AUDIO_SERVICE, 2116 MEDIA_ROUTER_SERVICE, 2117 TELEPHONY_SERVICE, 2118 TELECOM_SERVICE, 2119 CLIPBOARD_SERVICE, 2120 INPUT_METHOD_SERVICE, 2121 TEXT_SERVICES_MANAGER_SERVICE, 2122 APPWIDGET_SERVICE, 2123 //@hide: BACKUP_SERVICE, 2124 DROPBOX_SERVICE, 2125 DEVICE_POLICY_SERVICE, 2126 UI_MODE_SERVICE, 2127 DOWNLOAD_SERVICE, 2128 NFC_SERVICE, 2129 BLUETOOTH_SERVICE, 2130 //@hide: SIP_SERVICE, 2131 USB_SERVICE, 2132 LAUNCHER_APPS_SERVICE, 2133 //@hide: SERIAL_SERVICE, 2134 INPUT_SERVICE, 2135 DISPLAY_SERVICE, 2136 //@hide: SCHEDULING_POLICY_SERVICE, 2137 USER_SERVICE, 2138 //@hide: APP_OPS_SERVICE 2139 CAMERA_SERVICE, 2140 PRINT_SERVICE, 2141 MEDIA_SESSION_SERVICE, 2142 BATTERY_SERVICE, 2143 JOB_SCHEDULER_SERVICE, 2144 }) 2145 @Retention(RetentionPolicy.SOURCE) 2146 public @interface ServiceName {} 2147 2148 /** 2149 * Return the handle to a system-level service by name. The class of the 2150 * returned object varies by the requested name. Currently available names 2151 * are: 2152 * 2153 * <dl> 2154 * <dt> {@link #WINDOW_SERVICE} ("window") 2155 * <dd> The top-level window manager in which you can place custom 2156 * windows. The returned object is a {@link android.view.WindowManager}. 2157 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater") 2158 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources 2159 * in this context. 2160 * <dt> {@link #ACTIVITY_SERVICE} ("activity") 2161 * <dd> A {@link android.app.ActivityManager} for interacting with the 2162 * global activity state of the system. 2163 * <dt> {@link #POWER_SERVICE} ("power") 2164 * <dd> A {@link android.os.PowerManager} for controlling power 2165 * management. 2166 * <dt> {@link #ALARM_SERVICE} ("alarm") 2167 * <dd> A {@link android.app.AlarmManager} for receiving intents at the 2168 * time of your choosing. 2169 * <dt> {@link #NOTIFICATION_SERVICE} ("notification") 2170 * <dd> A {@link android.app.NotificationManager} for informing the user 2171 * of background events. 2172 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard") 2173 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard. 2174 * <dt> {@link #LOCATION_SERVICE} ("location") 2175 * <dd> A {@link android.location.LocationManager} for controlling location 2176 * (e.g., GPS) updates. 2177 * <dt> {@link #SEARCH_SERVICE} ("search") 2178 * <dd> A {@link android.app.SearchManager} for handling search. 2179 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator") 2180 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator 2181 * hardware. 2182 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection") 2183 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for 2184 * handling management of network connections. 2185 * <dt> {@link #WIFI_SERVICE} ("wifi") 2186 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of 2187 * Wi-Fi connectivity. 2188 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p") 2189 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of 2190 * Wi-Fi Direct connectivity. 2191 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method") 2192 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager} 2193 * for management of input methods. 2194 * <dt> {@link #UI_MODE_SERVICE} ("uimode") 2195 * <dd> An {@link android.app.UiModeManager} for controlling UI modes. 2196 * <dt> {@link #DOWNLOAD_SERVICE} ("download") 2197 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads 2198 * <dt> {@link #BATTERY_SERVICE} ("batterymanager") 2199 * <dd> A {@link android.os.BatteryManager} for managing battery state 2200 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager") 2201 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks 2202 * </dl> 2203 * 2204 * <p>Note: System services obtained via this API may be closely associated with 2205 * the Context in which they are obtained from. In general, do not share the 2206 * service objects between various different contexts (Activities, Applications, 2207 * Services, Providers, etc.) 2208 * 2209 * @param name The name of the desired service. 2210 * 2211 * @return The service or null if the name does not exist. 2212 * 2213 * @see #WINDOW_SERVICE 2214 * @see android.view.WindowManager 2215 * @see #LAYOUT_INFLATER_SERVICE 2216 * @see android.view.LayoutInflater 2217 * @see #ACTIVITY_SERVICE 2218 * @see android.app.ActivityManager 2219 * @see #POWER_SERVICE 2220 * @see android.os.PowerManager 2221 * @see #ALARM_SERVICE 2222 * @see android.app.AlarmManager 2223 * @see #NOTIFICATION_SERVICE 2224 * @see android.app.NotificationManager 2225 * @see #KEYGUARD_SERVICE 2226 * @see android.app.KeyguardManager 2227 * @see #LOCATION_SERVICE 2228 * @see android.location.LocationManager 2229 * @see #SEARCH_SERVICE 2230 * @see android.app.SearchManager 2231 * @see #SENSOR_SERVICE 2232 * @see android.hardware.SensorManager 2233 * @see #STORAGE_SERVICE 2234 * @see android.os.storage.StorageManager 2235 * @see #VIBRATOR_SERVICE 2236 * @see android.os.Vibrator 2237 * @see #CONNECTIVITY_SERVICE 2238 * @see android.net.ConnectivityManager 2239 * @see #WIFI_SERVICE 2240 * @see android.net.wifi.WifiManager 2241 * @see #AUDIO_SERVICE 2242 * @see android.media.AudioManager 2243 * @see #MEDIA_ROUTER_SERVICE 2244 * @see android.media.MediaRouter 2245 * @see #TELEPHONY_SERVICE 2246 * @see android.telephony.TelephonyManager 2247 * @see #INPUT_METHOD_SERVICE 2248 * @see android.view.inputmethod.InputMethodManager 2249 * @see #UI_MODE_SERVICE 2250 * @see android.app.UiModeManager 2251 * @see #DOWNLOAD_SERVICE 2252 * @see android.app.DownloadManager 2253 * @see #BATTERY_SERVICE 2254 * @see android.os.BatteryManager 2255 * @see #JOB_SCHEDULER_SERVICE 2256 * @see android.app.job.JobScheduler 2257 */ getSystemService(@erviceName @onNull String name)2258 public abstract Object getSystemService(@ServiceName @NonNull String name); 2259 2260 /** 2261 * Use with {@link #getSystemService} to retrieve a 2262 * {@link android.os.PowerManager} for controlling power management, 2263 * including "wake locks," which let you keep the device on while 2264 * you're running long tasks. 2265 */ 2266 public static final String POWER_SERVICE = "power"; 2267 2268 /** 2269 * Use with {@link #getSystemService} to retrieve a 2270 * {@link android.view.WindowManager} for accessing the system's window 2271 * manager. 2272 * 2273 * @see #getSystemService 2274 * @see android.view.WindowManager 2275 */ 2276 public static final String WINDOW_SERVICE = "window"; 2277 2278 /** 2279 * Use with {@link #getSystemService} to retrieve a 2280 * {@link android.view.LayoutInflater} for inflating layout resources in this 2281 * context. 2282 * 2283 * @see #getSystemService 2284 * @see android.view.LayoutInflater 2285 */ 2286 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater"; 2287 2288 /** 2289 * Use with {@link #getSystemService} to retrieve a 2290 * {@link android.accounts.AccountManager} for receiving intents at a 2291 * time of your choosing. 2292 * 2293 * @see #getSystemService 2294 * @see android.accounts.AccountManager 2295 */ 2296 public static final String ACCOUNT_SERVICE = "account"; 2297 2298 /** 2299 * Use with {@link #getSystemService} to retrieve a 2300 * {@link android.app.ActivityManager} for interacting with the global 2301 * system state. 2302 * 2303 * @see #getSystemService 2304 * @see android.app.ActivityManager 2305 */ 2306 public static final String ACTIVITY_SERVICE = "activity"; 2307 2308 /** 2309 * Use with {@link #getSystemService} to retrieve a 2310 * {@link android.app.AlarmManager} for receiving intents at a 2311 * time of your choosing. 2312 * 2313 * @see #getSystemService 2314 * @see android.app.AlarmManager 2315 */ 2316 public static final String ALARM_SERVICE = "alarm"; 2317 2318 /** 2319 * Use with {@link #getSystemService} to retrieve a 2320 * {@link android.app.NotificationManager} for informing the user of 2321 * background events. 2322 * 2323 * @see #getSystemService 2324 * @see android.app.NotificationManager 2325 */ 2326 public static final String NOTIFICATION_SERVICE = "notification"; 2327 2328 /** 2329 * Use with {@link #getSystemService} to retrieve a 2330 * {@link android.view.accessibility.AccessibilityManager} for giving the user 2331 * feedback for UI events through the registered event listeners. 2332 * 2333 * @see #getSystemService 2334 * @see android.view.accessibility.AccessibilityManager 2335 */ 2336 public static final String ACCESSIBILITY_SERVICE = "accessibility"; 2337 2338 /** 2339 * Use with {@link #getSystemService} to retrieve a 2340 * {@link android.view.accessibility.CaptioningManager} for obtaining 2341 * captioning properties and listening for changes in captioning 2342 * preferences. 2343 * 2344 * @see #getSystemService 2345 * @see android.view.accessibility.CaptioningManager 2346 */ 2347 public static final String CAPTIONING_SERVICE = "captioning"; 2348 2349 /** 2350 * Use with {@link #getSystemService} to retrieve a 2351 * {@link android.app.NotificationManager} for controlling keyguard. 2352 * 2353 * @see #getSystemService 2354 * @see android.app.KeyguardManager 2355 */ 2356 public static final String KEYGUARD_SERVICE = "keyguard"; 2357 2358 /** 2359 * Use with {@link #getSystemService} to retrieve a {@link 2360 * android.location.LocationManager} for controlling location 2361 * updates. 2362 * 2363 * @see #getSystemService 2364 * @see android.location.LocationManager 2365 */ 2366 public static final String LOCATION_SERVICE = "location"; 2367 2368 /** 2369 * Use with {@link #getSystemService} to retrieve a 2370 * {@link android.location.CountryDetector} for detecting the country that 2371 * the user is in. 2372 * 2373 * @hide 2374 */ 2375 public static final String COUNTRY_DETECTOR = "country_detector"; 2376 2377 /** 2378 * Use with {@link #getSystemService} to retrieve a {@link 2379 * android.app.SearchManager} for handling searches. 2380 * 2381 * @see #getSystemService 2382 * @see android.app.SearchManager 2383 */ 2384 public static final String SEARCH_SERVICE = "search"; 2385 2386 /** 2387 * Use with {@link #getSystemService} to retrieve a {@link 2388 * android.hardware.SensorManager} for accessing sensors. 2389 * 2390 * @see #getSystemService 2391 * @see android.hardware.SensorManager 2392 */ 2393 public static final String SENSOR_SERVICE = "sensor"; 2394 2395 /** 2396 * Use with {@link #getSystemService} to retrieve a {@link 2397 * android.os.storage.StorageManager} for accessing system storage 2398 * functions. 2399 * 2400 * @see #getSystemService 2401 * @see android.os.storage.StorageManager 2402 */ 2403 public static final String STORAGE_SERVICE = "storage"; 2404 2405 /** 2406 * Use with {@link #getSystemService} to retrieve a 2407 * com.android.server.WallpaperService for accessing wallpapers. 2408 * 2409 * @see #getSystemService 2410 */ 2411 public static final String WALLPAPER_SERVICE = "wallpaper"; 2412 2413 /** 2414 * Use with {@link #getSystemService} to retrieve a {@link 2415 * android.os.Vibrator} for interacting with the vibration hardware. 2416 * 2417 * @see #getSystemService 2418 * @see android.os.Vibrator 2419 */ 2420 public static final String VIBRATOR_SERVICE = "vibrator"; 2421 2422 /** 2423 * Use with {@link #getSystemService} to retrieve a {@link 2424 * android.app.StatusBarManager} for interacting with the status bar. 2425 * 2426 * @see #getSystemService 2427 * @see android.app.StatusBarManager 2428 * @hide 2429 */ 2430 public static final String STATUS_BAR_SERVICE = "statusbar"; 2431 2432 /** 2433 * Use with {@link #getSystemService} to retrieve a {@link 2434 * android.net.ConnectivityManager} for handling management of 2435 * network connections. 2436 * 2437 * @see #getSystemService 2438 * @see android.net.ConnectivityManager 2439 */ 2440 public static final String CONNECTIVITY_SERVICE = "connectivity"; 2441 2442 /** 2443 * Use with {@link #getSystemService} to retrieve a {@link 2444 * android.os.IUpdateLock} for managing runtime sequences that 2445 * must not be interrupted by headless OTA application or similar. 2446 * 2447 * @hide 2448 * @see #getSystemService 2449 * @see android.os.UpdateLock 2450 */ 2451 public static final String UPDATE_LOCK_SERVICE = "updatelock"; 2452 2453 /** 2454 * Constant for the internal network management service, not really a Context service. 2455 * @hide 2456 */ 2457 public static final String NETWORKMANAGEMENT_SERVICE = "network_management"; 2458 2459 /** {@hide} */ 2460 public static final String NETWORK_STATS_SERVICE = "netstats"; 2461 /** {@hide} */ 2462 public static final String NETWORK_POLICY_SERVICE = "netpolicy"; 2463 2464 /** 2465 * Use with {@link #getSystemService} to retrieve a {@link 2466 * android.net.wifi.WifiManager} for handling management of 2467 * Wi-Fi access. 2468 * 2469 * @see #getSystemService 2470 * @see android.net.wifi.WifiManager 2471 */ 2472 public static final String WIFI_SERVICE = "wifi"; 2473 2474 /** 2475 * Use with {@link #getSystemService} to retrieve a {@link 2476 * android.net.wifi.passpoint.WifiPasspointManager} for handling management of 2477 * Wi-Fi passpoint access. 2478 * 2479 * @see #getSystemService 2480 * @see android.net.wifi.passpoint.WifiPasspointManager 2481 * @hide 2482 */ 2483 public static final String WIFI_PASSPOINT_SERVICE = "wifipasspoint"; 2484 2485 /** 2486 * Use with {@link #getSystemService} to retrieve a {@link 2487 * android.net.wifi.p2p.WifiP2pManager} for handling management of 2488 * Wi-Fi peer-to-peer connections. 2489 * 2490 * @see #getSystemService 2491 * @see android.net.wifi.p2p.WifiP2pManager 2492 */ 2493 public static final String WIFI_P2P_SERVICE = "wifip2p"; 2494 2495 /** 2496 * Use with {@link #getSystemService} to retrieve a {@link 2497 * android.net.wifi.WifiScanner} for scanning the wifi universe 2498 * 2499 * @see #getSystemService 2500 * @see android.net.wifi.WifiScanner 2501 * @hide 2502 */ 2503 @SystemApi 2504 public static final String WIFI_SCANNING_SERVICE = "wifiscanner"; 2505 2506 /** 2507 * Use with {@link #getSystemService} to retrieve a {@link 2508 * android.net.wifi.RttManager} for ranging devices with wifi 2509 * 2510 * @see #getSystemService 2511 * @see android.net.wifi.RttManager 2512 * @hide 2513 */ 2514 @SystemApi 2515 public static final String WIFI_RTT_SERVICE = "rttmanager"; 2516 2517 /** 2518 * Use with {@link #getSystemService} to retrieve a {@link 2519 * android.net.EthernetManager} for handling management of 2520 * Ethernet access. 2521 * 2522 * @see #getSystemService 2523 * @see android.net.EthernetManager 2524 * 2525 * @hide 2526 */ 2527 public static final String ETHERNET_SERVICE = "ethernet"; 2528 2529 /** 2530 * Use with {@link #getSystemService} to retrieve a {@link 2531 * android.net.nsd.NsdManager} for handling management of network service 2532 * discovery 2533 * 2534 * @see #getSystemService 2535 * @see android.net.nsd.NsdManager 2536 */ 2537 public static final String NSD_SERVICE = "servicediscovery"; 2538 2539 /** 2540 * Use with {@link #getSystemService} to retrieve a 2541 * {@link android.media.AudioManager} for handling management of volume, 2542 * ringer modes and audio routing. 2543 * 2544 * @see #getSystemService 2545 * @see android.media.AudioManager 2546 */ 2547 public static final String AUDIO_SERVICE = "audio"; 2548 2549 /** 2550 * Use with {@link #getSystemService} to retrieve a 2551 * {@link android.service.fingerprint.FingerprintManager} for handling management 2552 * of fingerprints. 2553 * 2554 * @see #getSystemService 2555 * @see android.app.FingerprintManager 2556 * @hide 2557 */ 2558 public static final String FINGERPRINT_SERVICE = "fingerprint"; 2559 2560 /** 2561 * Use with {@link #getSystemService} to retrieve a 2562 * {@link android.media.MediaRouter} for controlling and managing 2563 * routing of media. 2564 * 2565 * @see #getSystemService 2566 * @see android.media.MediaRouter 2567 */ 2568 public static final String MEDIA_ROUTER_SERVICE = "media_router"; 2569 2570 /** 2571 * Use with {@link #getSystemService} to retrieve a 2572 * {@link android.media.session.MediaSessionManager} for managing media Sessions. 2573 * 2574 * @see #getSystemService 2575 * @see android.media.session.MediaSessionManager 2576 */ 2577 public static final String MEDIA_SESSION_SERVICE = "media_session"; 2578 2579 /** 2580 * Use with {@link #getSystemService} to retrieve a 2581 * {@link android.telephony.TelephonyManager} for handling management the 2582 * telephony features of the device. 2583 * 2584 * @see #getSystemService 2585 * @see android.telephony.TelephonyManager 2586 */ 2587 public static final String TELEPHONY_SERVICE = "phone"; 2588 2589 /** 2590 * Use with {@link #getSystemService} to retrieve a 2591 * {@link android.telecom.TelecomManager} to manage telecom-related features 2592 * of the device. 2593 * 2594 * @see #getSystemService 2595 * @see android.telecom.TelecomManager 2596 */ 2597 public static final String TELECOM_SERVICE = "telecom"; 2598 2599 /** 2600 * Use with {@link #getSystemService} to retrieve a 2601 * {@link android.text.ClipboardManager} for accessing and modifying 2602 * the contents of the global clipboard. 2603 * 2604 * @see #getSystemService 2605 * @see android.text.ClipboardManager 2606 */ 2607 public static final String CLIPBOARD_SERVICE = "clipboard"; 2608 2609 /** 2610 * Use with {@link #getSystemService} to retrieve a 2611 * {@link android.view.inputmethod.InputMethodManager} for accessing input 2612 * methods. 2613 * 2614 * @see #getSystemService 2615 */ 2616 public static final String INPUT_METHOD_SERVICE = "input_method"; 2617 2618 /** 2619 * Use with {@link #getSystemService} to retrieve a 2620 * {@link android.view.textservice.TextServicesManager} for accessing 2621 * text services. 2622 * 2623 * @see #getSystemService 2624 */ 2625 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices"; 2626 2627 /** 2628 * Use with {@link #getSystemService} to retrieve a 2629 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets. 2630 * 2631 * @see #getSystemService 2632 */ 2633 public static final String APPWIDGET_SERVICE = "appwidget"; 2634 2635 /** 2636 * Official published name of the (internal) voice interaction manager service. 2637 * 2638 * @hide 2639 * @see #getSystemService 2640 */ 2641 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction"; 2642 2643 /** 2644 * Use with {@link #getSystemService} to retrieve an 2645 * {@link android.app.backup.IBackupManager IBackupManager} for communicating 2646 * with the backup mechanism. 2647 * @hide 2648 * 2649 * @see #getSystemService 2650 */ 2651 @SystemApi 2652 public static final String BACKUP_SERVICE = "backup"; 2653 2654 /** 2655 * Use with {@link #getSystemService} to retrieve a 2656 * {@link android.os.DropBoxManager} instance for recording 2657 * diagnostic logs. 2658 * @see #getSystemService 2659 */ 2660 public static final String DROPBOX_SERVICE = "dropbox"; 2661 2662 /** 2663 * Use with {@link #getSystemService} to retrieve a 2664 * {@link android.app.admin.DevicePolicyManager} for working with global 2665 * device policy management. 2666 * 2667 * @see #getSystemService 2668 */ 2669 public static final String DEVICE_POLICY_SERVICE = "device_policy"; 2670 2671 /** 2672 * Use with {@link #getSystemService} to retrieve a 2673 * {@link android.app.UiModeManager} for controlling UI modes. 2674 * 2675 * @see #getSystemService 2676 */ 2677 public static final String UI_MODE_SERVICE = "uimode"; 2678 2679 /** 2680 * Use with {@link #getSystemService} to retrieve a 2681 * {@link android.app.DownloadManager} for requesting HTTP downloads. 2682 * 2683 * @see #getSystemService 2684 */ 2685 public static final String DOWNLOAD_SERVICE = "download"; 2686 2687 /** 2688 * Use with {@link #getSystemService} to retrieve a 2689 * {@link android.os.BatteryManager} for managing battery state. 2690 * 2691 * @see #getSystemService 2692 */ 2693 public static final String BATTERY_SERVICE = "batterymanager"; 2694 2695 /** 2696 * Use with {@link #getSystemService} to retrieve a 2697 * {@link android.nfc.NfcManager} for using NFC. 2698 * 2699 * @see #getSystemService 2700 */ 2701 public static final String NFC_SERVICE = "nfc"; 2702 2703 /** 2704 * Use with {@link #getSystemService} to retrieve a 2705 * {@link android.bluetooth.BluetoothAdapter} for using Bluetooth. 2706 * 2707 * @see #getSystemService 2708 */ 2709 public static final String BLUETOOTH_SERVICE = "bluetooth"; 2710 2711 /** 2712 * Use with {@link #getSystemService} to retrieve a 2713 * {@link android.net.sip.SipManager} for accessing the SIP related service. 2714 * 2715 * @see #getSystemService 2716 */ 2717 /** @hide */ 2718 public static final String SIP_SERVICE = "sip"; 2719 2720 /** 2721 * Use with {@link #getSystemService} to retrieve a {@link 2722 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host) 2723 * and for controlling this device's behavior as a USB device. 2724 * 2725 * @see #getSystemService 2726 * @see android.hardware.usb.UsbManager 2727 */ 2728 public static final String USB_SERVICE = "usb"; 2729 2730 /** 2731 * Use with {@link #getSystemService} to retrieve a {@link 2732 * android.hardware.SerialManager} for access to serial ports. 2733 * 2734 * @see #getSystemService 2735 * @see android.hardware.SerialManager 2736 * 2737 * @hide 2738 */ 2739 public static final String SERIAL_SERVICE = "serial"; 2740 2741 /** 2742 * Use with {@link #getSystemService} to retrieve a 2743 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing 2744 * HDMI-CEC protocol. 2745 * 2746 * @see #getSystemService 2747 * @see android.hardware.hdmi.HdmiControlManager 2748 * @hide 2749 */ 2750 @SystemApi 2751 public static final String HDMI_CONTROL_SERVICE = "hdmi_control"; 2752 2753 /** 2754 * Use with {@link #getSystemService} to retrieve a 2755 * {@link android.hardware.input.InputManager} for interacting with input devices. 2756 * 2757 * @see #getSystemService 2758 * @see android.hardware.input.InputManager 2759 */ 2760 public static final String INPUT_SERVICE = "input"; 2761 2762 /** 2763 * Use with {@link #getSystemService} to retrieve a 2764 * {@link android.hardware.display.DisplayManager} for interacting with display devices. 2765 * 2766 * @see #getSystemService 2767 * @see android.hardware.display.DisplayManager 2768 */ 2769 public static final String DISPLAY_SERVICE = "display"; 2770 2771 /** 2772 * Use with {@link #getSystemService} to retrieve a 2773 * {@link android.os.UserManager} for managing users on devices that support multiple users. 2774 * 2775 * @see #getSystemService 2776 * @see android.os.UserManager 2777 */ 2778 public static final String USER_SERVICE = "user"; 2779 2780 /** 2781 * Use with {@link #getSystemService} to retrieve a 2782 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across 2783 * profiles of a user. 2784 * 2785 * @see #getSystemService 2786 * @see android.content.pm.LauncherApps 2787 */ 2788 public static final String LAUNCHER_APPS_SERVICE = "launcherapps"; 2789 2790 /** 2791 * Use with {@link #getSystemService} to retrieve a 2792 * {@link android.content.RestrictionsManager} for retrieving application restrictions 2793 * and requesting permissions for restricted operations. 2794 * @see #getSystemService 2795 * @see android.content.RestrictionsManager 2796 */ 2797 public static final String RESTRICTIONS_SERVICE = "restrictions"; 2798 2799 /** 2800 * Use with {@link #getSystemService} to retrieve a 2801 * {@link android.app.AppOpsManager} for tracking application operations 2802 * on the device. 2803 * 2804 * @see #getSystemService 2805 * @see android.app.AppOpsManager 2806 */ 2807 public static final String APP_OPS_SERVICE = "appops"; 2808 2809 /** 2810 * Use with {@link #getSystemService} to retrieve a 2811 * {@link android.hardware.camera2.CameraManager} for interacting with 2812 * camera devices. 2813 * 2814 * @see #getSystemService 2815 * @see android.hardware.camera2.CameraManager 2816 */ 2817 public static final String CAMERA_SERVICE = "camera"; 2818 2819 /** 2820 * {@link android.print.PrintManager} for printing and managing 2821 * printers and print tasks. 2822 * 2823 * @see #getSystemService 2824 * @see android.print.PrintManager 2825 */ 2826 public static final String PRINT_SERVICE = "print"; 2827 2828 /** 2829 * Use with {@link #getSystemService} to retrieve a 2830 * {@link android.hardware.ConsumerIrManager} for transmitting infrared 2831 * signals from the device. 2832 * 2833 * @see #getSystemService 2834 * @see android.hardware.ConsumerIrManager 2835 */ 2836 public static final String CONSUMER_IR_SERVICE = "consumer_ir"; 2837 2838 /** 2839 * {@link android.app.trust.TrustManager} for managing trust agents. 2840 * @see #getSystemService 2841 * @see android.app.trust.TrustManager 2842 * @hide 2843 */ 2844 public static final String TRUST_SERVICE = "trust"; 2845 2846 /** 2847 * Use with {@link #getSystemService} to retrieve a 2848 * {@link android.media.tv.TvInputManager} for interacting with TV inputs 2849 * on the device. 2850 * 2851 * @see #getSystemService 2852 * @see android.media.tv.TvInputManager 2853 */ 2854 public static final String TV_INPUT_SERVICE = "tv_input"; 2855 2856 /** 2857 * {@link android.net.NetworkScoreManager} for managing network scoring. 2858 * @see #getSystemService 2859 * @see android.net.NetworkScoreManager 2860 * @hide 2861 */ 2862 @SystemApi 2863 public static final String NETWORK_SCORE_SERVICE = "network_score"; 2864 2865 /** 2866 * Use with {@link #getSystemService} to retrieve a {@link 2867 * android.app.UsageStatsManager} for interacting with the status bar. 2868 * 2869 * @see #getSystemService 2870 * @see android.app.UsageStatsManager 2871 * @hide 2872 */ 2873 public static final String USAGE_STATS_SERVICE = "usagestats"; 2874 2875 /** 2876 * Use with {@link #getSystemService} to retrieve a {@link 2877 * android.app.job.JobScheduler} instance for managing occasional 2878 * background tasks. 2879 * @see #getSystemService 2880 * @see android.app.job.JobScheduler 2881 */ 2882 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler"; 2883 2884 /** 2885 * Use with {@link #getSystemService} to retrieve a {@link 2886 * android.service.persistentdata.PersistentDataBlockManager} instance 2887 * for interacting with a storage device that lives across factory resets. 2888 * 2889 * @see #getSystemService 2890 * @see android.service.persistentdata.PersistentDataBlockManager 2891 * @hide 2892 */ 2893 @SystemApi 2894 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block"; 2895 2896 /** 2897 * Use with {@link #getSystemService} to retrieve a {@link 2898 * android.media.projection.MediaProjectionManager} instance for managing 2899 * media projection sessions. 2900 * @see #getSystemService 2901 * @see android.media.projection.ProjectionManager 2902 */ 2903 public static final String MEDIA_PROJECTION_SERVICE = "media_projection"; 2904 2905 /** 2906 * Determine whether the given permission is allowed for a particular 2907 * process and user ID running in the system. 2908 * 2909 * @param permission The name of the permission being checked. 2910 * @param pid The process ID being checked against. Must be > 0. 2911 * @param uid The user ID being checked against. A uid of 0 is the root 2912 * user, which will pass every permission check. 2913 * 2914 * @return {@link PackageManager#PERMISSION_GRANTED} if the given 2915 * pid/uid is allowed that permission, or 2916 * {@link PackageManager#PERMISSION_DENIED} if it is not. 2917 * 2918 * @see PackageManager#checkPermission(String, String) 2919 * @see #checkCallingPermission 2920 */ 2921 @PackageManager.PermissionResult checkPermission(@onNull String permission, int pid, int uid)2922 public abstract int checkPermission(@NonNull String permission, int pid, int uid); 2923 2924 /** 2925 * Determine whether the calling process of an IPC you are handling has been 2926 * granted a particular permission. This is basically the same as calling 2927 * {@link #checkPermission(String, int, int)} with the pid and uid returned 2928 * by {@link android.os.Binder#getCallingPid} and 2929 * {@link android.os.Binder#getCallingUid}. One important difference 2930 * is that if you are not currently processing an IPC, this function 2931 * will always fail. This is done to protect against accidentally 2932 * leaking permissions; you can use {@link #checkCallingOrSelfPermission} 2933 * to avoid this protection. 2934 * 2935 * @param permission The name of the permission being checked. 2936 * 2937 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling 2938 * pid/uid is allowed that permission, or 2939 * {@link PackageManager#PERMISSION_DENIED} if it is not. 2940 * 2941 * @see PackageManager#checkPermission(String, String) 2942 * @see #checkPermission 2943 * @see #checkCallingOrSelfPermission 2944 */ 2945 @PackageManager.PermissionResult checkCallingPermission(@onNull String permission)2946 public abstract int checkCallingPermission(@NonNull String permission); 2947 2948 /** 2949 * Determine whether the calling process of an IPC <em>or you</em> have been 2950 * granted a particular permission. This is the same as 2951 * {@link #checkCallingPermission}, except it grants your own permissions 2952 * if you are not currently processing an IPC. Use with care! 2953 * 2954 * @param permission The name of the permission being checked. 2955 * 2956 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling 2957 * pid/uid is allowed that permission, or 2958 * {@link PackageManager#PERMISSION_DENIED} if it is not. 2959 * 2960 * @see PackageManager#checkPermission(String, String) 2961 * @see #checkPermission 2962 * @see #checkCallingPermission 2963 */ 2964 @PackageManager.PermissionResult checkCallingOrSelfPermission(@onNull String permission)2965 public abstract int checkCallingOrSelfPermission(@NonNull String permission); 2966 2967 /** 2968 * If the given permission is not allowed for a particular process 2969 * and user ID running in the system, throw a {@link SecurityException}. 2970 * 2971 * @param permission The name of the permission being checked. 2972 * @param pid The process ID being checked against. Must be > 0. 2973 * @param uid The user ID being checked against. A uid of 0 is the root 2974 * user, which will pass every permission check. 2975 * @param message A message to include in the exception if it is thrown. 2976 * 2977 * @see #checkPermission(String, int, int) 2978 */ enforcePermission( @onNull String permission, int pid, int uid, @Nullable String message)2979 public abstract void enforcePermission( 2980 @NonNull String permission, int pid, int uid, @Nullable String message); 2981 2982 /** 2983 * If the calling process of an IPC you are handling has not been 2984 * granted a particular permission, throw a {@link 2985 * SecurityException}. This is basically the same as calling 2986 * {@link #enforcePermission(String, int, int, String)} with the 2987 * pid and uid returned by {@link android.os.Binder#getCallingPid} 2988 * and {@link android.os.Binder#getCallingUid}. One important 2989 * difference is that if you are not currently processing an IPC, 2990 * this function will always throw the SecurityException. This is 2991 * done to protect against accidentally leaking permissions; you 2992 * can use {@link #enforceCallingOrSelfPermission} to avoid this 2993 * protection. 2994 * 2995 * @param permission The name of the permission being checked. 2996 * @param message A message to include in the exception if it is thrown. 2997 * 2998 * @see #checkCallingPermission(String) 2999 */ enforceCallingPermission( @onNull String permission, @Nullable String message)3000 public abstract void enforceCallingPermission( 3001 @NonNull String permission, @Nullable String message); 3002 3003 /** 3004 * If neither you nor the calling process of an IPC you are 3005 * handling has been granted a particular permission, throw a 3006 * {@link SecurityException}. This is the same as {@link 3007 * #enforceCallingPermission}, except it grants your own 3008 * permissions if you are not currently processing an IPC. Use 3009 * with care! 3010 * 3011 * @param permission The name of the permission being checked. 3012 * @param message A message to include in the exception if it is thrown. 3013 * 3014 * @see #checkCallingOrSelfPermission(String) 3015 */ enforceCallingOrSelfPermission( @onNull String permission, @Nullable String message)3016 public abstract void enforceCallingOrSelfPermission( 3017 @NonNull String permission, @Nullable String message); 3018 3019 /** 3020 * Grant permission to access a specific Uri to another package, regardless 3021 * of whether that package has general permission to access the Uri's 3022 * content provider. This can be used to grant specific, temporary 3023 * permissions, typically in response to user interaction (such as the 3024 * user opening an attachment that you would like someone else to 3025 * display). 3026 * 3027 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION 3028 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3029 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION 3030 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to 3031 * start an activity instead of this function directly. If you use this 3032 * function directly, you should be sure to call 3033 * {@link #revokeUriPermission} when the target should no longer be allowed 3034 * to access it. 3035 * 3036 * <p>To succeed, the content provider owning the Uri must have set the 3037 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions 3038 * grantUriPermissions} attribute in its manifest or included the 3039 * {@link android.R.styleable#AndroidManifestGrantUriPermission 3040 * <grant-uri-permissions>} tag. 3041 * 3042 * @param toPackage The package you would like to allow to access the Uri. 3043 * @param uri The Uri you would like to grant access to. 3044 * @param modeFlags The desired access modes. Any combination of 3045 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION 3046 * Intent.FLAG_GRANT_READ_URI_PERMISSION}, 3047 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION 3048 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}, 3049 * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION 3050 * Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION}, or 3051 * {@link Intent#FLAG_GRANT_PREFIX_URI_PERMISSION 3052 * Intent.FLAG_GRANT_PREFIX_URI_PERMISSION}. 3053 * 3054 * @see #revokeUriPermission 3055 */ grantUriPermission(String toPackage, Uri uri, @Intent.GrantUriMode int modeFlags)3056 public abstract void grantUriPermission(String toPackage, Uri uri, 3057 @Intent.GrantUriMode int modeFlags); 3058 3059 /** 3060 * Remove all permissions to access a particular content provider Uri 3061 * that were previously added with {@link #grantUriPermission}. The given 3062 * Uri will match all previously granted Uris that are the same or a 3063 * sub-path of the given Uri. That is, revoking "content://foo/target" will 3064 * revoke both "content://foo/target" and "content://foo/target/sub", but not 3065 * "content://foo". It will not remove any prefix grants that exist at a 3066 * higher level. 3067 * 3068 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have 3069 * regular permission access to a Uri, but had received access to it through 3070 * a specific Uri permission grant, you could not revoke that grant with this 3071 * function and a {@link SecurityException} would be thrown. As of 3072 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security exception, 3073 * but will remove whatever permission grants to the Uri had been given to the app 3074 * (or none).</p> 3075 * 3076 * @param uri The Uri you would like to revoke access to. 3077 * @param modeFlags The desired access modes. Any combination of 3078 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION 3079 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3080 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION 3081 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3082 * 3083 * @see #grantUriPermission 3084 */ revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags)3085 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags); 3086 3087 /** 3088 * Determine whether a particular process and user ID has been granted 3089 * permission to access a specific URI. This only checks for permissions 3090 * that have been explicitly granted -- if the given process/uid has 3091 * more general access to the URI's content provider then this check will 3092 * always fail. 3093 * 3094 * @param uri The uri that is being checked. 3095 * @param pid The process ID being checked against. Must be > 0. 3096 * @param uid The user ID being checked against. A uid of 0 is the root 3097 * user, which will pass every permission check. 3098 * @param modeFlags The type of access to grant. May be one or both of 3099 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3100 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3101 * 3102 * @return {@link PackageManager#PERMISSION_GRANTED} if the given 3103 * pid/uid is allowed to access that uri, or 3104 * {@link PackageManager#PERMISSION_DENIED} if it is not. 3105 * 3106 * @see #checkCallingUriPermission 3107 */ checkUriPermission(Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags)3108 public abstract int checkUriPermission(Uri uri, int pid, int uid, 3109 @Intent.AccessUriMode int modeFlags); 3110 3111 /** 3112 * Determine whether the calling process and user ID has been 3113 * granted permission to access a specific URI. This is basically 3114 * the same as calling {@link #checkUriPermission(Uri, int, int, 3115 * int)} with the pid and uid returned by {@link 3116 * android.os.Binder#getCallingPid} and {@link 3117 * android.os.Binder#getCallingUid}. One important difference is 3118 * that if you are not currently processing an IPC, this function 3119 * will always fail. 3120 * 3121 * @param uri The uri that is being checked. 3122 * @param modeFlags The type of access to grant. May be one or both of 3123 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3124 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3125 * 3126 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller 3127 * is allowed to access that uri, or 3128 * {@link PackageManager#PERMISSION_DENIED} if it is not. 3129 * 3130 * @see #checkUriPermission(Uri, int, int, int) 3131 */ checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags)3132 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags); 3133 3134 /** 3135 * Determine whether the calling process of an IPC <em>or you</em> has been granted 3136 * permission to access a specific URI. This is the same as 3137 * {@link #checkCallingUriPermission}, except it grants your own permissions 3138 * if you are not currently processing an IPC. Use with care! 3139 * 3140 * @param uri The uri that is being checked. 3141 * @param modeFlags The type of access to grant. May be one or both of 3142 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3143 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3144 * 3145 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller 3146 * is allowed to access that uri, or 3147 * {@link PackageManager#PERMISSION_DENIED} if it is not. 3148 * 3149 * @see #checkCallingUriPermission 3150 */ checkCallingOrSelfUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags)3151 public abstract int checkCallingOrSelfUriPermission(Uri uri, 3152 @Intent.AccessUriMode int modeFlags); 3153 3154 /** 3155 * Check both a Uri and normal permission. This allows you to perform 3156 * both {@link #checkPermission} and {@link #checkUriPermission} in one 3157 * call. 3158 * 3159 * @param uri The Uri whose permission is to be checked, or null to not 3160 * do this check. 3161 * @param readPermission The permission that provides overall read access, 3162 * or null to not do this check. 3163 * @param writePermission The permission that provides overall write 3164 * access, or null to not do this check. 3165 * @param pid The process ID being checked against. Must be > 0. 3166 * @param uid The user ID being checked against. A uid of 0 is the root 3167 * user, which will pass every permission check. 3168 * @param modeFlags The type of access to grant. May be one or both of 3169 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3170 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3171 * 3172 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller 3173 * is allowed to access that uri or holds one of the given permissions, or 3174 * {@link PackageManager#PERMISSION_DENIED} if it is not. 3175 */ checkUriPermission(@ullable Uri uri, @Nullable String readPermission, @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags)3176 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission, 3177 @Nullable String writePermission, int pid, int uid, 3178 @Intent.AccessUriMode int modeFlags); 3179 3180 /** 3181 * If a particular process and user ID has not been granted 3182 * permission to access a specific URI, throw {@link 3183 * SecurityException}. This only checks for permissions that have 3184 * been explicitly granted -- if the given process/uid has more 3185 * general access to the URI's content provider then this check 3186 * will always fail. 3187 * 3188 * @param uri The uri that is being checked. 3189 * @param pid The process ID being checked against. Must be > 0. 3190 * @param uid The user ID being checked against. A uid of 0 is the root 3191 * user, which will pass every permission check. 3192 * @param modeFlags The type of access to grant. May be one or both of 3193 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3194 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3195 * @param message A message to include in the exception if it is thrown. 3196 * 3197 * @see #checkUriPermission(Uri, int, int, int) 3198 */ enforceUriPermission( Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message)3199 public abstract void enforceUriPermission( 3200 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message); 3201 3202 /** 3203 * If the calling process and user ID has not been granted 3204 * permission to access a specific URI, throw {@link 3205 * SecurityException}. This is basically the same as calling 3206 * {@link #enforceUriPermission(Uri, int, int, int, String)} with 3207 * the pid and uid returned by {@link 3208 * android.os.Binder#getCallingPid} and {@link 3209 * android.os.Binder#getCallingUid}. One important difference is 3210 * that if you are not currently processing an IPC, this function 3211 * will always throw a SecurityException. 3212 * 3213 * @param uri The uri that is being checked. 3214 * @param modeFlags The type of access to grant. May be one or both of 3215 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3216 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3217 * @param message A message to include in the exception if it is thrown. 3218 * 3219 * @see #checkCallingUriPermission(Uri, int) 3220 */ enforceCallingUriPermission( Uri uri, @Intent.AccessUriMode int modeFlags, String message)3221 public abstract void enforceCallingUriPermission( 3222 Uri uri, @Intent.AccessUriMode int modeFlags, String message); 3223 3224 /** 3225 * If the calling process of an IPC <em>or you</em> has not been 3226 * granted permission to access a specific URI, throw {@link 3227 * SecurityException}. This is the same as {@link 3228 * #enforceCallingUriPermission}, except it grants your own 3229 * permissions if you are not currently processing an IPC. Use 3230 * with care! 3231 * 3232 * @param uri The uri that is being checked. 3233 * @param modeFlags The type of access to grant. May be one or both of 3234 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3235 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3236 * @param message A message to include in the exception if it is thrown. 3237 * 3238 * @see #checkCallingOrSelfUriPermission(Uri, int) 3239 */ enforceCallingOrSelfUriPermission( Uri uri, @Intent.AccessUriMode int modeFlags, String message)3240 public abstract void enforceCallingOrSelfUriPermission( 3241 Uri uri, @Intent.AccessUriMode int modeFlags, String message); 3242 3243 /** 3244 * Enforce both a Uri and normal permission. This allows you to perform 3245 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one 3246 * call. 3247 * 3248 * @param uri The Uri whose permission is to be checked, or null to not 3249 * do this check. 3250 * @param readPermission The permission that provides overall read access, 3251 * or null to not do this check. 3252 * @param writePermission The permission that provides overall write 3253 * access, or null to not do this check. 3254 * @param pid The process ID being checked against. Must be > 0. 3255 * @param uid The user ID being checked against. A uid of 0 is the root 3256 * user, which will pass every permission check. 3257 * @param modeFlags The type of access to grant. May be one or both of 3258 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3259 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3260 * @param message A message to include in the exception if it is thrown. 3261 * 3262 * @see #checkUriPermission(Uri, String, String, int, int, int) 3263 */ enforceUriPermission( @ullable Uri uri, @Nullable String readPermission, @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags, @Nullable String message)3264 public abstract void enforceUriPermission( 3265 @Nullable Uri uri, @Nullable String readPermission, 3266 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags, 3267 @Nullable String message); 3268 3269 /** @hide */ 3270 @IntDef(flag = true, 3271 value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED}) 3272 @Retention(RetentionPolicy.SOURCE) 3273 public @interface CreatePackageOptions {} 3274 3275 /** 3276 * Flag for use with {@link #createPackageContext}: include the application 3277 * code with the context. This means loading code into the caller's 3278 * process, so that {@link #getClassLoader()} can be used to instantiate 3279 * the application's classes. Setting this flags imposes security 3280 * restrictions on what application context you can access; if the 3281 * requested application can not be safely loaded into your process, 3282 * java.lang.SecurityException will be thrown. If this flag is not set, 3283 * there will be no restrictions on the packages that can be loaded, 3284 * but {@link #getClassLoader} will always return the default system 3285 * class loader. 3286 */ 3287 public static final int CONTEXT_INCLUDE_CODE = 0x00000001; 3288 3289 /** 3290 * Flag for use with {@link #createPackageContext}: ignore any security 3291 * restrictions on the Context being requested, allowing it to always 3292 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code 3293 * to be loaded into a process even when it isn't safe to do so. Use 3294 * with extreme care! 3295 */ 3296 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002; 3297 3298 /** 3299 * Flag for use with {@link #createPackageContext}: a restricted context may 3300 * disable specific features. For instance, a View associated with a restricted 3301 * context would ignore particular XML attributes. 3302 */ 3303 public static final int CONTEXT_RESTRICTED = 0x00000004; 3304 3305 /** 3306 * @hide Used to indicate we should tell the activity manager about the process 3307 * loading this code. 3308 */ 3309 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000; 3310 3311 /** 3312 * Return a new Context object for the given application name. This 3313 * Context is the same as what the named application gets when it is 3314 * launched, containing the same resources and class loader. Each call to 3315 * this method returns a new instance of a Context object; Context objects 3316 * are not shared, however they share common state (Resources, ClassLoader, 3317 * etc) so the Context instance itself is fairly lightweight. 3318 * 3319 * <p>Throws {@link PackageManager.NameNotFoundException} if there is no 3320 * application with the given package name. 3321 * 3322 * <p>Throws {@link java.lang.SecurityException} if the Context requested 3323 * can not be loaded into the caller's process for security reasons (see 3324 * {@link #CONTEXT_INCLUDE_CODE} for more information}. 3325 * 3326 * @param packageName Name of the application's package. 3327 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE} 3328 * or {@link #CONTEXT_IGNORE_SECURITY}. 3329 * 3330 * @return A {@link Context} for the application. 3331 * 3332 * @throws SecurityException 3333 * @throws PackageManager.NameNotFoundException if there is no application with 3334 * the given package name. 3335 */ createPackageContext(String packageName, @CreatePackageOptions int flags)3336 public abstract Context createPackageContext(String packageName, 3337 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException; 3338 3339 /** 3340 * Similar to {@link #createPackageContext(String, int)}, but with a 3341 * different {@link UserHandle}. For example, {@link #getContentResolver()} 3342 * will open any {@link Uri} as the given user. 3343 * 3344 * @hide 3345 */ createPackageContextAsUser( String packageName, int flags, UserHandle user)3346 public abstract Context createPackageContextAsUser( 3347 String packageName, int flags, UserHandle user) 3348 throws PackageManager.NameNotFoundException; 3349 3350 /** 3351 * Creates a context given an {@link android.content.pm.ApplicationInfo}. 3352 * 3353 * @hide 3354 */ createApplicationContext(ApplicationInfo application, int flags)3355 public abstract Context createApplicationContext(ApplicationInfo application, 3356 int flags) throws PackageManager.NameNotFoundException; 3357 3358 /** 3359 * Get the userId associated with this context 3360 * @return user id 3361 * 3362 * @hide 3363 */ getUserId()3364 public abstract int getUserId(); 3365 3366 /** 3367 * Return a new Context object for the current Context but whose resources 3368 * are adjusted to match the given Configuration. Each call to this method 3369 * returns a new instance of a Context object; Context objects are not 3370 * shared, however common state (ClassLoader, other Resources for the 3371 * same configuration) may be so the Context itself can be fairly lightweight. 3372 * 3373 * @param overrideConfiguration A {@link Configuration} specifying what 3374 * values to modify in the base Configuration of the original Context's 3375 * resources. If the base configuration changes (such as due to an 3376 * orientation change), the resources of this context will also change except 3377 * for those that have been explicitly overridden with a value here. 3378 * 3379 * @return A {@link Context} with the given configuration override. 3380 */ createConfigurationContext( @onNull Configuration overrideConfiguration)3381 public abstract Context createConfigurationContext( 3382 @NonNull Configuration overrideConfiguration); 3383 3384 /** 3385 * Return a new Context object for the current Context but whose resources 3386 * are adjusted to match the metrics of the given Display. Each call to this method 3387 * returns a new instance of a Context object; Context objects are not 3388 * shared, however common state (ClassLoader, other Resources for the 3389 * same configuration) may be so the Context itself can be fairly lightweight. 3390 * 3391 * The returned display Context provides a {@link WindowManager} 3392 * (see {@link #getSystemService(String)}) that is configured to show windows 3393 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay} 3394 * method can be used to retrieve the Display from the returned Context. 3395 * 3396 * @param display A {@link Display} object specifying the display 3397 * for whose metrics the Context's resources should be tailored and upon which 3398 * new windows should be shown. 3399 * 3400 * @return A {@link Context} for the display. 3401 */ createDisplayContext(@onNull Display display)3402 public abstract Context createDisplayContext(@NonNull Display display); 3403 3404 /** 3405 * Gets the display adjustments holder for this context. This information 3406 * is provided on a per-application or activity basis and is used to simulate lower density 3407 * display metrics for legacy applications and restricted screen sizes. 3408 * 3409 * @param displayId The display id for which to get compatibility info. 3410 * @return The compatibility info holder, or null if not required by the application. 3411 * @hide 3412 */ getDisplayAdjustments(int displayId)3413 public abstract DisplayAdjustments getDisplayAdjustments(int displayId); 3414 3415 /** 3416 * Indicates whether this Context is restricted. 3417 * 3418 * @return {@code true} if this Context is restricted, {@code false} otherwise. 3419 * 3420 * @see #CONTEXT_RESTRICTED 3421 */ isRestricted()3422 public boolean isRestricted() { 3423 return false; 3424 } 3425 } 3426