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