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