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.Resources;
     23 import android.content.res.TypedArray;
     24 import android.database.sqlite.SQLiteDatabase;
     25 import android.database.sqlite.SQLiteDatabase.CursorFactory;
     26 import android.graphics.Bitmap;
     27 import android.graphics.drawable.Drawable;
     28 import android.net.Uri;
     29 import android.os.Bundle;
     30 import android.os.Handler;
     31 import android.os.Looper;
     32 import android.util.AttributeSet;
     33 
     34 import java.io.File;
     35 import java.io.FileInputStream;
     36 import java.io.FileNotFoundException;
     37 import java.io.FileOutputStream;
     38 import java.io.IOException;
     39 import java.io.InputStream;
     40 
     41 /**
     42  * Interface to global information about an application environment.  This is
     43  * an abstract class whose implementation is provided by
     44  * the Android system.  It
     45  * allows access to application-specific resources and classes, as well as
     46  * up-calls for application-level operations such as launching activities,
     47  * broadcasting and receiving intents, etc.
     48  */
     49 public abstract class Context {
     50     /**
     51      * File creation mode: the default mode, where the created file can only
     52      * be accessed by the calling application (or all applications sharing the
     53      * same user ID).
     54      * @see #MODE_WORLD_READABLE
     55      * @see #MODE_WORLD_WRITEABLE
     56      */
     57     public static final int MODE_PRIVATE = 0x0000;
     58     /**
     59      * File creation mode: allow all other applications to have read access
     60      * to the created file.
     61      * @see #MODE_PRIVATE
     62      * @see #MODE_WORLD_WRITEABLE
     63      */
     64     public static final int MODE_WORLD_READABLE = 0x0001;
     65     /**
     66      * File creation mode: allow all other applications to have write access
     67      * to the created file.
     68      * @see #MODE_PRIVATE
     69      * @see #MODE_WORLD_READABLE
     70      */
     71     public static final int MODE_WORLD_WRITEABLE = 0x0002;
     72     /**
     73      * File creation mode: for use with {@link #openFileOutput}, if the file
     74      * already exists then write data to the end of the existing file
     75      * instead of erasing it.
     76      * @see #openFileOutput
     77      */
     78     public static final int MODE_APPEND = 0x8000;
     79 
     80     /**
     81      * Flag for {@link #bindService}: automatically create the service as long
     82      * as the binding exists.  Note that while this will create the service,
     83      * its {@link android.app.Service#onStart} method will still only be called due to an
     84      * explicit call to {@link #startService}.  Even without that, though,
     85      * this still provides you with access to the service object while the
     86      * service is created.
     87      *
     88      * <p>Specifying this flag also tells the system to treat the service
     89      * as being as important as your own process -- that is, when deciding
     90      * which process should be killed to free memory, the service will only
     91      * be considered a candidate as long as the processes of any such bindings
     92      * is also a candidate to be killed.  This is to avoid situations where
     93      * the service is being continually created and killed due to low memory.
     94      */
     95     public static final int BIND_AUTO_CREATE = 0x0001;
     96 
     97     /**
     98      * Flag for {@link #bindService}: include debugging help for mismatched
     99      * calls to unbind.  When this flag is set, the callstack of the following
    100      * {@link #unbindService} call is retained, to be printed if a later
    101      * incorrect unbind call is made.  Note that doing this requires retaining
    102      * information about the binding that was made for the lifetime of the app,
    103      * resulting in a leak -- this should only be used for debugging.
    104      */
    105     public static final int BIND_DEBUG_UNBIND = 0x0002;
    106 
    107     /**
    108      * Flag for {@link #bindService}: don't allow this binding to raise
    109      * the target service's process to the foreground scheduling priority.
    110      * It will still be raised to the at least the same memory priority
    111      * as the client (so that its process will not be killable in any
    112      * situation where the client is not killable), but for CPU scheduling
    113      * purposes it may be left in the background.  This only has an impact
    114      * in the situation where the binding client is a foreground process
    115      * and the target service is in a background process.
    116      */
    117     public static final int BIND_NOT_FOREGROUND = 0x0004;
    118 
    119     /** Return an AssetManager instance for your application's package. */
    120     public abstract AssetManager getAssets();
    121 
    122     /** Return a Resources instance for your application's package. */
    123     public abstract Resources getResources();
    124 
    125     /** Return PackageManager instance to find global package information. */
    126     public abstract PackageManager getPackageManager();
    127 
    128     /** Return a ContentResolver instance for your application's package. */
    129     public abstract ContentResolver getContentResolver();
    130 
    131     /**
    132      * Return the Looper for the main thread of the current process.  This is
    133      * the thread used to dispatch calls to application components (activities,
    134      * services, etc).
    135      */
    136     public abstract Looper getMainLooper();
    137 
    138     /**
    139      * Return the context of the single, global Application object of the
    140      * current process.  This generally should only be used if you need a
    141      * Context whose lifecycle is separate from the current context, that is
    142      * tied to the lifetime of the process rather than the current component.
    143      *
    144      * <p>Consider for example how this interacts with
    145      * {@ #registerReceiver(BroadcastReceiver, IntentFilter)}:
    146      * <ul>
    147      * <li> <p>If used from an Activity context, the receiver is being registered
    148      * within that activity.  This means that you are expected to unregister
    149      * before the activity is done being destroyed; in fact if you do not do
    150      * so, the framework will clean up your leaked registration as it removes
    151      * the activity and log an error.  Thus, if you use the Activity context
    152      * to register a receiver that is static (global to the process, not
    153      * associated with an Activity instance) then that registration will be
    154      * removed on you at whatever point the activity you used is destroyed.
    155      * <li> <p>If used from the Context returned here, the receiver is being
    156      * registered with the global state associated with your application.  Thus
    157      * it will never be unregistered for you.  This is necessary if the receiver
    158      * is associated with static data, not a particular component.  However
    159      * using the ApplicationContext elsewhere can easily lead to serious leaks
    160      * if you forget to unregister, unbind, etc.
    161      * </ul>
    162      */
    163     public abstract Context getApplicationContext();
    164 
    165     /**
    166      * Return a localized, styled CharSequence from the application's package's
    167      * default string table.
    168      *
    169      * @param resId Resource id for the CharSequence text
    170      */
    171     public final CharSequence getText(int resId) {
    172         return getResources().getText(resId);
    173     }
    174 
    175     /**
    176      * Return a localized string from the application's package's
    177      * default string table.
    178      *
    179      * @param resId Resource id for the string
    180      */
    181     public final String getString(int resId) {
    182         return getResources().getString(resId);
    183     }
    184 
    185     /**
    186      * Return a localized formatted string from the application's package's
    187      * default string table, substituting the format arguments as defined in
    188      * {@link java.util.Formatter} and {@link java.lang.String#format}.
    189      *
    190      * @param resId Resource id for the format string
    191      * @param formatArgs The format arguments that will be used for substitution.
    192      */
    193 
    194     public final String getString(int resId, Object... formatArgs) {
    195         return getResources().getString(resId, formatArgs);
    196     }
    197 
    198      /**
    199      * Set the base theme for this context.  Note that this should be called
    200      * before any views are instantiated in the Context (for example before
    201      * calling {@link android.app.Activity#setContentView} or
    202      * {@link android.view.LayoutInflater#inflate}).
    203      *
    204      * @param resid The style resource describing the theme.
    205      */
    206     public abstract void setTheme(int resid);
    207 
    208     /**
    209      * Return the Theme object associated with this Context.
    210      */
    211     public abstract Resources.Theme getTheme();
    212 
    213     /**
    214      * Retrieve styled attribute information in this Context's theme.  See
    215      * {@link Resources.Theme#obtainStyledAttributes(int[])}
    216      * for more information.
    217      *
    218      * @see Resources.Theme#obtainStyledAttributes(int[])
    219      */
    220     public final TypedArray obtainStyledAttributes(
    221             int[] attrs) {
    222         return getTheme().obtainStyledAttributes(attrs);
    223     }
    224 
    225     /**
    226      * Retrieve styled attribute information in this Context's theme.  See
    227      * {@link Resources.Theme#obtainStyledAttributes(int, int[])}
    228      * for more information.
    229      *
    230      * @see Resources.Theme#obtainStyledAttributes(int, int[])
    231      */
    232     public final TypedArray obtainStyledAttributes(
    233             int resid, int[] attrs) throws Resources.NotFoundException {
    234         return getTheme().obtainStyledAttributes(resid, attrs);
    235     }
    236 
    237     /**
    238      * Retrieve styled attribute information in this Context's theme.  See
    239      * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
    240      * for more information.
    241      *
    242      * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
    243      */
    244     public final TypedArray obtainStyledAttributes(
    245             AttributeSet set, int[] attrs) {
    246         return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
    247     }
    248 
    249     /**
    250      * Retrieve styled attribute information in this Context's theme.  See
    251      * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
    252      * for more information.
    253      *
    254      * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
    255      */
    256     public final TypedArray obtainStyledAttributes(
    257             AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) {
    258         return getTheme().obtainStyledAttributes(
    259             set, attrs, defStyleAttr, defStyleRes);
    260     }
    261 
    262     /**
    263      * Return a class loader you can use to retrieve classes in this package.
    264      */
    265     public abstract ClassLoader getClassLoader();
    266 
    267     /** Return the name of this application's package. */
    268     public abstract String getPackageName();
    269 
    270     /** Return the full application info for this context's package. */
    271     public abstract ApplicationInfo getApplicationInfo();
    272 
    273     /**
    274      * Return the full path to this context's primary Android package.
    275      * The Android package is a ZIP file which contains the application's
    276      * primary resources.
    277      *
    278      * <p>Note: this is not generally useful for applications, since they should
    279      * not be directly accessing the file system.
    280      *
    281      * @return String Path to the resources.
    282      */
    283     public abstract String getPackageResourcePath();
    284 
    285     /**
    286      * Return the full path to this context's primary Android package.
    287      * The Android package is a ZIP file which contains application's
    288      * primary code and assets.
    289      *
    290      * <p>Note: this is not generally useful for applications, since they should
    291      * not be directly accessing the file system.
    292      *
    293      * @return String Path to the code and assets.
    294      */
    295     public abstract String getPackageCodePath();
    296 
    297     /**
    298      * {@hide}
    299      * Return the full path to the shared prefs file for the given prefs group name.
    300      *
    301      * <p>Note: this is not generally useful for applications, since they should
    302      * not be directly accessing the file system.
    303      */
    304     public abstract File getSharedPrefsFile(String name);
    305 
    306     /**
    307      * Retrieve and hold the contents of the preferences file 'name', returning
    308      * a SharedPreferences through which you can retrieve and modify its
    309      * values.  Only one instance of the SharedPreferences object is returned
    310      * to any callers for the same name, meaning they will see each other's
    311      * edits as soon as they are made.
    312      *
    313      * @param name Desired preferences file. If a preferences file by this name
    314      * does not exist, it will be created when you retrieve an
    315      * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
    316      * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
    317      * default operation, {@link #MODE_WORLD_READABLE}
    318      * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
    319      *
    320      * @return Returns the single SharedPreferences instance that can be used
    321      *         to retrieve and modify the preference values.
    322      *
    323      * @see #MODE_PRIVATE
    324      * @see #MODE_WORLD_READABLE
    325      * @see #MODE_WORLD_WRITEABLE
    326      */
    327     public abstract SharedPreferences getSharedPreferences(String name,
    328             int mode);
    329 
    330     /**
    331      * Open a private file associated with this Context's application package
    332      * for reading.
    333      *
    334      * @param name The name of the file to open; can not contain path
    335      *             separators.
    336      *
    337      * @return FileInputStream Resulting input stream.
    338      *
    339      * @see #openFileOutput
    340      * @see #fileList
    341      * @see #deleteFile
    342      * @see java.io.FileInputStream#FileInputStream(String)
    343      */
    344     public abstract FileInputStream openFileInput(String name)
    345         throws FileNotFoundException;
    346 
    347     /**
    348      * Open a private file associated with this Context's application package
    349      * for writing.  Creates the file if it doesn't already exist.
    350      *
    351      * @param name The name of the file to open; can not contain path
    352      *             separators.
    353      * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
    354      * default operation, {@link #MODE_APPEND} to append to an existing file,
    355      * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control
    356      * permissions.
    357      *
    358      * @return FileOutputStream Resulting output stream.
    359      *
    360      * @see #MODE_APPEND
    361      * @see #MODE_PRIVATE
    362      * @see #MODE_WORLD_READABLE
    363      * @see #MODE_WORLD_WRITEABLE
    364      * @see #openFileInput
    365      * @see #fileList
    366      * @see #deleteFile
    367      * @see java.io.FileOutputStream#FileOutputStream(String)
    368      */
    369     public abstract FileOutputStream openFileOutput(String name, int mode)
    370         throws FileNotFoundException;
    371 
    372     /**
    373      * Delete the given private file associated with this Context's
    374      * application package.
    375      *
    376      * @param name The name of the file to delete; can not contain path
    377      *             separators.
    378      *
    379      * @return True if the file was successfully deleted; else
    380      *         false.
    381      *
    382      * @see #openFileInput
    383      * @see #openFileOutput
    384      * @see #fileList
    385      * @see java.io.File#delete()
    386      */
    387     public abstract boolean deleteFile(String name);
    388 
    389     /**
    390      * Returns the absolute path on the filesystem where a file created with
    391      * {@link #openFileOutput} is stored.
    392      *
    393      * @param name The name of the file for which you would like to get
    394      *          its path.
    395      *
    396      * @return Returns an absolute path to the given file.
    397      *
    398      * @see #openFileOutput
    399      * @see #getFilesDir
    400      * @see #getDir
    401      */
    402     public abstract File getFileStreamPath(String name);
    403 
    404     /**
    405      * Returns the absolute path to the directory on the filesystem where
    406      * files created with {@link #openFileOutput} are stored.
    407      *
    408      * @return Returns the path of the directory holding application files.
    409      *
    410      * @see #openFileOutput
    411      * @see #getFileStreamPath
    412      * @see #getDir
    413      */
    414     public abstract File getFilesDir();
    415 
    416     /**
    417      * Returns the absolute path to the directory on the external filesystem
    418      * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
    419      * Environment.getExternalStorageDirectory()}) where the application can
    420      * place persistent files it owns.  These files are private to the
    421      * applications, and not typically visible to the user as media.
    422      *
    423      * <p>This is like {@link #getFilesDir()} in that these
    424      * files will be deleted when the application is uninstalled, however there
    425      * are some important differences:
    426      *
    427      * <ul>
    428      * <li>External files are not always available: they will disappear if the
    429      * user mounts the external storage on a computer or removes it.  See the
    430      * APIs on {@link android.os.Environment} for information in the storage state.
    431      * <li>There is no security enforced with these files.  All applications
    432      * can read and write files placed here.
    433      * </ul>
    434      *
    435      * <p>Here is an example of typical code to manipulate a file in
    436      * an application's private storage:</p>
    437      *
    438      * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
    439      * private_file}
    440      *
    441      * <p>If you supply a non-null <var>type</var> to this function, the returned
    442      * file will be a path to a sub-directory of the given type.  Though these files
    443      * are not automatically scanned by the media scanner, you can explicitly
    444      * add them to the media database with
    445      * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
    446      *      OnScanCompletedListener) MediaScannerConnection.scanFile}.
    447      * Note that this is not the same as
    448      * {@link android.os.Environment#getExternalStoragePublicDirectory
    449      * Environment.getExternalStoragePublicDirectory()}, which provides
    450      * directories of media shared by all applications.  The
    451      * directories returned here are
    452      * owned by the application, and their contents will be removed when the
    453      * application is uninstalled.  Unlike
    454      * {@link android.os.Environment#getExternalStoragePublicDirectory
    455      * Environment.getExternalStoragePublicDirectory()}, the directory
    456      * returned here will be automatically created for you.
    457      *
    458      * <p>Here is an example of typical code to manipulate a picture in
    459      * an application's private storage and add it to the media database:</p>
    460      *
    461      * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
    462      * private_picture}
    463      *
    464      * @param type The type of files directory to return.  May be null for
    465      * the root of the files directory or one of
    466      * the following Environment constants for a subdirectory:
    467      * {@link android.os.Environment#DIRECTORY_MUSIC},
    468      * {@link android.os.Environment#DIRECTORY_PODCASTS},
    469      * {@link android.os.Environment#DIRECTORY_RINGTONES},
    470      * {@link android.os.Environment#DIRECTORY_ALARMS},
    471      * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
    472      * {@link android.os.Environment#DIRECTORY_PICTURES}, or
    473      * {@link android.os.Environment#DIRECTORY_MOVIES}.
    474      *
    475      * @return Returns the path of the directory holding application files
    476      * on external storage.  Returns null if external storage is not currently
    477      * mounted so it could not ensure the path exists; you will need to call
    478      * this method again when it is available.
    479      *
    480      * @see #getFilesDir
    481      * @see android.os.Environment#getExternalStoragePublicDirectory
    482      */
    483     public abstract File getExternalFilesDir(String type);
    484 
    485     /**
    486      * Returns the absolute path to the application specific cache directory
    487      * on the filesystem. These files will be ones that get deleted first when the
    488      * device runs low on storage.
    489      * There is no guarantee when these files will be deleted.
    490      *
    491      * <strong>Note: you should not <em>rely</em> on the system deleting these
    492      * files for you; you should always have a reasonable maximum, such as 1 MB,
    493      * for the amount of space you consume with cache files, and prune those
    494      * files when exceeding that space.</strong>
    495      *
    496      * @return Returns the path of the directory holding application cache files.
    497      *
    498      * @see #openFileOutput
    499      * @see #getFileStreamPath
    500      * @see #getDir
    501      */
    502     public abstract File getCacheDir();
    503 
    504     /**
    505      * Returns the absolute path to the directory on the external filesystem
    506      * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
    507      * Environment.getExternalStorageDirectory()} where the application can
    508      * place cache files it owns.
    509      *
    510      * <p>This is like {@link #getCacheDir()} in that these
    511      * files will be deleted when the application is uninstalled, however there
    512      * are some important differences:
    513      *
    514      * <ul>
    515      * <li>The platform does not monitor the space available in external storage,
    516      * and thus will not automatically delete these files.  Note that you should
    517      * be managing the maximum space you will use for these anyway, just like
    518      * with {@link #getCacheDir()}.
    519      * <li>External files are not always available: they will disappear if the
    520      * user mounts the external storage on a computer or removes it.  See the
    521      * APIs on {@link android.os.Environment} for information in the storage state.
    522      * <li>There is no security enforced with these files.  All applications
    523      * can read and write files placed here.
    524      * </ul>
    525      *
    526      * @return Returns the path of the directory holding application cache files
    527      * on external storage.  Returns null if external storage is not currently
    528      * mounted so it could not ensure the path exists; you will need to call
    529      * this method again when it is available.
    530      *
    531      * @see #getCacheDir
    532      */
    533     public abstract File getExternalCacheDir();
    534 
    535     /**
    536      * Returns an array of strings naming the private files associated with
    537      * this Context's application package.
    538      *
    539      * @return Array of strings naming the private files.
    540      *
    541      * @see #openFileInput
    542      * @see #openFileOutput
    543      * @see #deleteFile
    544      */
    545     public abstract String[] fileList();
    546 
    547     /**
    548      * Retrieve, creating if needed, a new directory in which the application
    549      * can place its own custom data files.  You can use the returned File
    550      * object to create and access files in this directory.  Note that files
    551      * created through a File object will only be accessible by your own
    552      * application; you can only set the mode of the entire directory, not
    553      * of individual files.
    554      *
    555      * @param name Name of the directory to retrieve.  This is a directory
    556      * that is created as part of your application data.
    557      * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
    558      * default operation, {@link #MODE_WORLD_READABLE} and
    559      * {@link #MODE_WORLD_WRITEABLE} to control permissions.
    560      *
    561      * @return Returns a File object for the requested directory.  The directory
    562      * will have been created if it does not already exist.
    563      *
    564      * @see #openFileOutput(String, int)
    565      */
    566     public abstract File getDir(String name, int mode);
    567 
    568     /**
    569      * Open a new private SQLiteDatabase associated with this Context's
    570      * application package.  Create the database file if it doesn't exist.
    571      *
    572      * @param name The name (unique in the application package) of the database.
    573      * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
    574      *     default operation, {@link #MODE_WORLD_READABLE}
    575      *     and {@link #MODE_WORLD_WRITEABLE} to control permissions.
    576      * @param factory An optional factory class that is called to instantiate a
    577      *     cursor when query is called.
    578      *
    579      * @return The contents of a newly created database with the given name.
    580      * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
    581      *
    582      * @see #MODE_PRIVATE
    583      * @see #MODE_WORLD_READABLE
    584      * @see #MODE_WORLD_WRITEABLE
    585      * @see #deleteDatabase
    586      */
    587     public abstract SQLiteDatabase openOrCreateDatabase(String name,
    588             int mode, CursorFactory factory);
    589 
    590     /**
    591      * Delete an existing private SQLiteDatabase associated with this Context's
    592      * application package.
    593      *
    594      * @param name The name (unique in the application package) of the
    595      *             database.
    596      *
    597      * @return True if the database was successfully deleted; else false.
    598      *
    599      * @see #openOrCreateDatabase
    600      */
    601     public abstract boolean deleteDatabase(String name);
    602 
    603     /**
    604      * Returns the absolute path on the filesystem where a database created with
    605      * {@link #openOrCreateDatabase} is stored.
    606      *
    607      * @param name The name of the database for which you would like to get
    608      *          its path.
    609      *
    610      * @return Returns an absolute path to the given database.
    611      *
    612      * @see #openOrCreateDatabase
    613      */
    614     public abstract File getDatabasePath(String name);
    615 
    616     /**
    617      * Returns an array of strings naming the private databases associated with
    618      * this Context's application package.
    619      *
    620      * @return Array of strings naming the private databases.
    621      *
    622      * @see #openOrCreateDatabase
    623      * @see #deleteDatabase
    624      */
    625     public abstract String[] databaseList();
    626 
    627     /**
    628      * @deprecated Use {@link android.app.WallpaperManager#getDrawable
    629      * WallpaperManager.get()} instead.
    630      */
    631     @Deprecated
    632     public abstract Drawable getWallpaper();
    633 
    634     /**
    635      * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
    636      * WallpaperManager.peek()} instead.
    637      */
    638     @Deprecated
    639     public abstract Drawable peekWallpaper();
    640 
    641     /**
    642      * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
    643      * WallpaperManager.getDesiredMinimumWidth()} instead.
    644      */
    645     @Deprecated
    646     public abstract int getWallpaperDesiredMinimumWidth();
    647 
    648     /**
    649      * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
    650      * WallpaperManager.getDesiredMinimumHeight()} instead.
    651      */
    652     @Deprecated
    653     public abstract int getWallpaperDesiredMinimumHeight();
    654 
    655     /**
    656      * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
    657      * WallpaperManager.set()} instead.
    658      */
    659     @Deprecated
    660     public abstract void setWallpaper(Bitmap bitmap) throws IOException;
    661 
    662     /**
    663      * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
    664      * WallpaperManager.set()} instead.
    665      */
    666     @Deprecated
    667     public abstract void setWallpaper(InputStream data) throws IOException;
    668 
    669     /**
    670      * @deprecated Use {@link android.app.WallpaperManager#clear
    671      * WallpaperManager.clear()} instead.
    672      */
    673     @Deprecated
    674     public abstract void clearWallpaper() throws IOException;
    675 
    676     /**
    677      * Launch a new activity.  You will not receive any information about when
    678      * the activity exits.
    679      *
    680      * <p>Note that if this method is being called from outside of an
    681      * {@link android.app.Activity} Context, then the Intent must include
    682      * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag.  This is because,
    683      * without being started from an existing Activity, there is no existing
    684      * task in which to place the new activity and thus it needs to be placed
    685      * in its own separate task.
    686      *
    687      * <p>This method throws {@link ActivityNotFoundException}
    688      * if there was no Activity found to run the given Intent.
    689      *
    690      * @param intent The description of the activity to start.
    691      *
    692      * @throws ActivityNotFoundException
    693      *
    694      * @see PackageManager#resolveActivity
    695      */
    696     public abstract void startActivity(Intent intent);
    697 
    698     /**
    699      * Like {@link #startActivity(Intent)}, but taking a IntentSender
    700      * to start.  If the IntentSender is for an activity, that activity will be started
    701      * as if you had called the regular {@link #startActivity(Intent)}
    702      * here; otherwise, its associated action will be executed (such as
    703      * sending a broadcast) as if you had called
    704      * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
    705      *
    706      * @param intent The IntentSender to launch.
    707      * @param fillInIntent If non-null, this will be provided as the
    708      * intent parameter to {@link IntentSender#sendIntent}.
    709      * @param flagsMask Intent flags in the original IntentSender that you
    710      * would like to change.
    711      * @param flagsValues Desired values for any bits set in
    712      * <var>flagsMask</var>
    713      * @param extraFlags Always set to 0.
    714      */
    715     public abstract void startIntentSender(IntentSender intent,
    716             Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
    717             throws IntentSender.SendIntentException;
    718 
    719     /**
    720      * Broadcast the given intent to all interested BroadcastReceivers.  This
    721      * call is asynchronous; it returns immediately, and you will continue
    722      * executing while the receivers are run.  No results are propagated from
    723      * receivers and receivers can not abort the broadcast. If you want
    724      * to allow receivers to propagate results or abort the broadcast, you must
    725      * send an ordered broadcast using
    726      * {@link #sendOrderedBroadcast(Intent, String)}.
    727      *
    728      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
    729      *
    730      * @param intent The Intent to broadcast; all receivers matching this
    731      *               Intent will receive the broadcast.
    732      *
    733      * @see android.content.BroadcastReceiver
    734      * @see #registerReceiver
    735      * @see #sendBroadcast(Intent, String)
    736      * @see #sendOrderedBroadcast(Intent, String)
    737      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
    738      */
    739     public abstract void sendBroadcast(Intent intent);
    740 
    741     /**
    742      * Broadcast the given intent to all interested BroadcastReceivers, allowing
    743      * an optional required permission to be enforced.  This
    744      * call is asynchronous; it returns immediately, and you will continue
    745      * executing while the receivers are run.  No results are propagated from
    746      * receivers and receivers can not abort the broadcast. If you want
    747      * to allow receivers to propagate results or abort the broadcast, you must
    748      * send an ordered broadcast using
    749      * {@link #sendOrderedBroadcast(Intent, String)}.
    750      *
    751      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
    752      *
    753      * @param intent The Intent to broadcast; all receivers matching this
    754      *               Intent will receive the broadcast.
    755      * @param receiverPermission (optional) String naming a permissions that
    756      *               a receiver must hold in order to receive your broadcast.
    757      *               If null, no permission is required.
    758      *
    759      * @see android.content.BroadcastReceiver
    760      * @see #registerReceiver
    761      * @see #sendBroadcast(Intent)
    762      * @see #sendOrderedBroadcast(Intent, String)
    763      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
    764      */
    765     public abstract void sendBroadcast(Intent intent,
    766             String receiverPermission);
    767 
    768     /**
    769      * Broadcast the given intent to all interested BroadcastReceivers, delivering
    770      * them one at a time to allow more preferred receivers to consume the
    771      * broadcast before it is delivered to less preferred receivers.  This
    772      * call is asynchronous; it returns immediately, and you will continue
    773      * executing while the receivers are run.
    774      *
    775      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
    776      *
    777      * @param intent The Intent to broadcast; all receivers matching this
    778      *               Intent will receive the broadcast.
    779      * @param receiverPermission (optional) String naming a permissions that
    780      *               a receiver must hold in order to receive your broadcast.
    781      *               If null, no permission is required.
    782      *
    783      * @see android.content.BroadcastReceiver
    784      * @see #registerReceiver
    785      * @see #sendBroadcast(Intent)
    786      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
    787      */
    788     public abstract void sendOrderedBroadcast(Intent intent,
    789             String receiverPermission);
    790 
    791     /**
    792      * Version of {@link #sendBroadcast(Intent)} that allows you to
    793      * receive data back from the broadcast.  This is accomplished by
    794      * supplying your own BroadcastReceiver when calling, which will be
    795      * treated as a final receiver at the end of the broadcast -- its
    796      * {@link BroadcastReceiver#onReceive} method will be called with
    797      * the result values collected from the other receivers.  The broadcast will
    798      * be serialized in the same way as calling
    799      * {@link #sendOrderedBroadcast(Intent, String)}.
    800      *
    801      * <p>Like {@link #sendBroadcast(Intent)}, this method is
    802      * asynchronous; it will return before
    803      * resultReceiver.onReceive() is called.
    804      *
    805      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
    806      *
    807      * @param intent The Intent to broadcast; all receivers matching this
    808      *               Intent will receive the broadcast.
    809      * @param receiverPermission String naming a permissions that
    810      *               a receiver must hold in order to receive your broadcast.
    811      *               If null, no permission is required.
    812      * @param resultReceiver Your own BroadcastReceiver to treat as the final
    813      *                       receiver of the broadcast.
    814      * @param scheduler A custom Handler with which to schedule the
    815      *                  resultReceiver callback; if null it will be
    816      *                  scheduled in the Context's main thread.
    817      * @param initialCode An initial value for the result code.  Often
    818      *                    Activity.RESULT_OK.
    819      * @param initialData An initial value for the result data.  Often
    820      *                    null.
    821      * @param initialExtras An initial value for the result extras.  Often
    822      *                      null.
    823      *
    824      * @see #sendBroadcast(Intent)
    825      * @see #sendBroadcast(Intent, String)
    826      * @see #sendOrderedBroadcast(Intent, String)
    827      * @see #sendStickyBroadcast(Intent)
    828      * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
    829      * @see android.content.BroadcastReceiver
    830      * @see #registerReceiver
    831      * @see android.app.Activity#RESULT_OK
    832      */
    833     public abstract void sendOrderedBroadcast(Intent intent,
    834             String receiverPermission, BroadcastReceiver resultReceiver,
    835             Handler scheduler, int initialCode, String initialData,
    836             Bundle initialExtras);
    837 
    838     /**
    839      * Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
    840      * Intent you are sending stays around after the broadcast is complete,
    841      * so that others can quickly retrieve that data through the return
    842      * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}.  In
    843      * all other ways, this behaves the same as
    844      * {@link #sendBroadcast(Intent)}.
    845      *
    846      * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
    847      * permission in order to use this API.  If you do not hold that
    848      * permission, {@link SecurityException} will be thrown.
    849      *
    850      * @param intent The Intent to broadcast; all receivers matching this
    851      * Intent will receive the broadcast, and the Intent will be held to
    852      * be re-broadcast to future receivers.
    853      *
    854      * @see #sendBroadcast(Intent)
    855      * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
    856      */
    857     public abstract void sendStickyBroadcast(Intent intent);
    858 
    859     /**
    860      * Version of {@link #sendStickyBroadcast} that allows you to
    861      * receive data back from the broadcast.  This is accomplished by
    862      * supplying your own BroadcastReceiver when calling, which will be
    863      * treated as a final receiver at the end of the broadcast -- its
    864      * {@link BroadcastReceiver#onReceive} method will be called with
    865      * the result values collected from the other receivers.  The broadcast will
    866      * be serialized in the same way as calling
    867      * {@link #sendOrderedBroadcast(Intent, String)}.
    868      *
    869      * <p>Like {@link #sendBroadcast(Intent)}, this method is
    870      * asynchronous; it will return before
    871      * resultReceiver.onReceive() is called.  Note that the sticky data
    872      * stored is only the data you initially supply to the broadcast, not
    873      * the result of any changes made by the receivers.
    874      *
    875      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
    876      *
    877      * @param intent The Intent to broadcast; all receivers matching this
    878      *               Intent will receive the broadcast.
    879      * @param resultReceiver Your own BroadcastReceiver to treat as the final
    880      *                       receiver of the broadcast.
    881      * @param scheduler A custom Handler with which to schedule the
    882      *                  resultReceiver callback; if null it will be
    883      *                  scheduled in the Context's main thread.
    884      * @param initialCode An initial value for the result code.  Often
    885      *                    Activity.RESULT_OK.
    886      * @param initialData An initial value for the result data.  Often
    887      *                    null.
    888      * @param initialExtras An initial value for the result extras.  Often
    889      *                      null.
    890      *
    891      * @see #sendBroadcast(Intent)
    892      * @see #sendBroadcast(Intent, String)
    893      * @see #sendOrderedBroadcast(Intent, String)
    894      * @see #sendStickyBroadcast(Intent)
    895      * @see android.content.BroadcastReceiver
    896      * @see #registerReceiver
    897      * @see android.app.Activity#RESULT_OK
    898      */
    899     public abstract void sendStickyOrderedBroadcast(Intent intent,
    900             BroadcastReceiver resultReceiver,
    901             Handler scheduler, int initialCode, String initialData,
    902             Bundle initialExtras);
    903 
    904 
    905     /**
    906      * Remove the data previously sent with {@link #sendStickyBroadcast},
    907      * so that it is as if the sticky broadcast had never happened.
    908      *
    909      * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
    910      * permission in order to use this API.  If you do not hold that
    911      * permission, {@link SecurityException} will be thrown.
    912      *
    913      * @param intent The Intent that was previously broadcast.
    914      *
    915      * @see #sendStickyBroadcast
    916      */
    917     public abstract void removeStickyBroadcast(Intent intent);
    918 
    919     /**
    920      * Register a BroadcastReceiver to be run in the main activity thread.  The
    921      * <var>receiver</var> will be called with any broadcast Intent that
    922      * matches <var>filter</var>, in the main application thread.
    923      *
    924      * <p>The system may broadcast Intents that are "sticky" -- these stay
    925      * around after the broadcast as finished, to be sent to any later
    926      * registrations. If your IntentFilter matches one of these sticky
    927      * Intents, that Intent will be returned by this function
    928      * <strong>and</strong> sent to your <var>receiver</var> as if it had just
    929      * been broadcast.
    930      *
    931      * <p>There may be multiple sticky Intents that match <var>filter</var>,
    932      * in which case each of these will be sent to <var>receiver</var>.  In
    933      * this case, only one of these can be returned directly by the function;
    934      * which of these that is returned is arbitrarily decided by the system.
    935      *
    936      * <p>If you know the Intent your are registering for is sticky, you can
    937      * supply null for your <var>receiver</var>.  In this case, no receiver is
    938      * registered -- the function simply returns the sticky Intent that
    939      * matches <var>filter</var>.  In the case of multiple matches, the same
    940      * rules as described above apply.
    941      *
    942      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
    943      *
    944      * <p class="note">Note: this method <em>cannot be called from a
    945      * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
    946      * that is declared in an application's manifest.  It is okay, however, to call
    947      * this method from another BroadcastReceiver that has itself been registered
    948      * at run time with {@link #registerReceiver}, since the lifetime of such a
    949      * registered BroadcastReceiver is tied to the object that registered it.</p>
    950      *
    951      * @param receiver The BroadcastReceiver to handle the broadcast.
    952      * @param filter Selects the Intent broadcasts to be received.
    953      *
    954      * @return The first sticky intent found that matches <var>filter</var>,
    955      *         or null if there are none.
    956      *
    957      * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
    958      * @see #sendBroadcast
    959      * @see #unregisterReceiver
    960      */
    961     public abstract Intent registerReceiver(BroadcastReceiver receiver,
    962                                             IntentFilter filter);
    963 
    964     /**
    965      * Register to receive intent broadcasts, to run in the context of
    966      * <var>scheduler</var>.  See
    967      * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
    968      * information.  This allows you to enforce permissions on who can
    969      * broadcast intents to your receiver, or have the receiver run in
    970      * a different thread than the main application thread.
    971      *
    972      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
    973      *
    974      * @param receiver The BroadcastReceiver to handle the broadcast.
    975      * @param filter Selects the Intent broadcasts to be received.
    976      * @param broadcastPermission String naming a permissions that a
    977      *      broadcaster must hold in order to send an Intent to you.  If null,
    978      *      no permission is required.
    979      * @param scheduler Handler identifying the thread that will receive
    980      *      the Intent.  If null, the main thread of the process will be used.
    981      *
    982      * @return The first sticky intent found that matches <var>filter</var>,
    983      *         or null if there are none.
    984      *
    985      * @see #registerReceiver(BroadcastReceiver, IntentFilter)
    986      * @see #sendBroadcast
    987      * @see #unregisterReceiver
    988      */
    989     public abstract Intent registerReceiver(BroadcastReceiver receiver,
    990                                             IntentFilter filter,
    991                                             String broadcastPermission,
    992                                             Handler scheduler);
    993 
    994     /**
    995      * Unregister a previously registered BroadcastReceiver.  <em>All</em>
    996      * filters that have been registered for this BroadcastReceiver will be
    997      * removed.
    998      *
    999      * @param receiver The BroadcastReceiver to unregister.
   1000      *
   1001      * @see #registerReceiver
   1002      */
   1003     public abstract void unregisterReceiver(BroadcastReceiver receiver);
   1004 
   1005     /**
   1006      * Request that a given application service be started.  The Intent
   1007      * can either contain the complete class name of a specific service
   1008      * implementation to start, or an abstract definition through the
   1009      * action and other fields of the kind of service to start.  If this service
   1010      * is not already running, it will be instantiated and started (creating a
   1011      * process for it if needed); if it is running then it remains running.
   1012      *
   1013      * <p>Every call to this method will result in a corresponding call to
   1014      * the target service's {@link android.app.Service#onStart} method,
   1015      * with the <var>intent</var> given here.  This provides a convenient way
   1016      * to submit jobs to a service without having to bind and call on to its
   1017      * interface.
   1018      *
   1019      * <p>Using startService() overrides the default service lifetime that is
   1020      * managed by {@link #bindService}: it requires the service to remain
   1021      * running until {@link #stopService} is called, regardless of whether
   1022      * any clients are connected to it.  Note that calls to startService()
   1023      * are not nesting: no matter how many times you call startService(),
   1024      * a single call to {@link #stopService} will stop it.
   1025      *
   1026      * <p>The system attempts to keep running services around as much as
   1027      * possible.  The only time they should be stopped is if the current
   1028      * foreground application is using so many resources that the service needs
   1029      * to be killed.  If any errors happen in the service's process, it will
   1030      * automatically be restarted.
   1031      *
   1032      * <p>This function will throw {@link SecurityException} if you do not
   1033      * have permission to start the given service.
   1034      *
   1035      * @param service Identifies the service to be started.  The Intent may
   1036      *      specify either an explicit component name to start, or a logical
   1037      *      description (action, category, etc) to match an
   1038      *      {@link IntentFilter} published by a service.  Additional values
   1039      *      may be included in the Intent extras to supply arguments along with
   1040      *      this specific start call.
   1041      *
   1042      * @return If the service is being started or is already running, the
   1043      * {@link ComponentName} of the actual service that was started is
   1044      * returned; else if the service does not exist null is returned.
   1045      *
   1046      * @throws SecurityException
   1047      *
   1048      * @see #stopService
   1049      * @see #bindService
   1050      */
   1051     public abstract ComponentName startService(Intent service);
   1052 
   1053     /**
   1054      * Request that a given application service be stopped.  If the service is
   1055      * not running, nothing happens.  Otherwise it is stopped.  Note that calls
   1056      * to startService() are not counted -- this stops the service no matter
   1057      * how many times it was started.
   1058      *
   1059      * <p>Note that if a stopped service still has {@link ServiceConnection}
   1060      * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
   1061      * not be destroyed until all of these bindings are removed.  See
   1062      * the {@link android.app.Service} documentation for more details on a
   1063      * service's lifecycle.
   1064      *
   1065      * <p>This function will throw {@link SecurityException} if you do not
   1066      * have permission to stop the given service.
   1067      *
   1068      * @param service Description of the service to be stopped.  The Intent may
   1069      *      specify either an explicit component name to start, or a logical
   1070      *      description (action, category, etc) to match an
   1071      *      {@link IntentFilter} published by a service.
   1072      *
   1073      * @return If there is a service matching the given Intent that is already
   1074      * running, then it is stopped and true is returned; else false is returned.
   1075      *
   1076      * @throws SecurityException
   1077      *
   1078      * @see #startService
   1079      */
   1080     public abstract boolean stopService(Intent service);
   1081 
   1082     /**
   1083      * Connect to an application service, creating it if needed.  This defines
   1084      * a dependency between your application and the service.  The given
   1085      * <var>conn</var> will receive the service object when its created and be
   1086      * told if it dies and restarts.  The service will be considered required
   1087      * by the system only for as long as the calling context exists.  For
   1088      * example, if this Context is an Activity that is stopped, the service will
   1089      * not be required to continue running until the Activity is resumed.
   1090      *
   1091      * <p>This function will throw {@link SecurityException} if you do not
   1092      * have permission to bind to the given service.
   1093      *
   1094      * <p class="note">Note: this method <em>can not be called from an
   1095      * {@link BroadcastReceiver} component</em>.  A pattern you can use to
   1096      * communicate from an BroadcastReceiver to a Service is to call
   1097      * {@link #startService} with the arguments containing the command to be
   1098      * sent, with the service calling its
   1099      * {@link android.app.Service#stopSelf(int)} method when done executing
   1100      * that command.  See the API demo App/Service/Service Start Arguments
   1101      * Controller for an illustration of this.  It is okay, however, to use
   1102      * this method from an BroadcastReceiver that has been registered with
   1103      * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
   1104      * is tied to another object (the one that registered it).</p>
   1105      *
   1106      * @param service Identifies the service to connect to.  The Intent may
   1107      *      specify either an explicit component name, or a logical
   1108      *      description (action, category, etc) to match an
   1109      *      {@link IntentFilter} published by a service.
   1110      * @param conn Receives information as the service is started and stopped.
   1111      * @param flags Operation options for the binding.  May be 0 or
   1112      *          {@link #BIND_AUTO_CREATE}.
   1113      * @return If you have successfully bound to the service, true is returned;
   1114      *         false is returned if the connection is not made so you will not
   1115      *         receive the service object.
   1116      *
   1117      * @throws SecurityException
   1118      *
   1119      * @see #unbindService
   1120      * @see #startService
   1121      * @see #BIND_AUTO_CREATE
   1122      */
   1123     public abstract boolean bindService(Intent service, ServiceConnection conn,
   1124             int flags);
   1125 
   1126     /**
   1127      * Disconnect from an application service.  You will no longer receive
   1128      * calls as the service is restarted, and the service is now allowed to
   1129      * stop at any time.
   1130      *
   1131      * @param conn The connection interface previously supplied to
   1132      *             bindService().
   1133      *
   1134      * @see #bindService
   1135      */
   1136     public abstract void unbindService(ServiceConnection conn);
   1137 
   1138     /**
   1139      * Start executing an {@link android.app.Instrumentation} class.  The given
   1140      * Instrumentation component will be run by killing its target application
   1141      * (if currently running), starting the target process, instantiating the
   1142      * instrumentation component, and then letting it drive the application.
   1143      *
   1144      * <p>This function is not synchronous -- it returns as soon as the
   1145      * instrumentation has started and while it is running.
   1146      *
   1147      * <p>Instrumentation is normally only allowed to run against a package
   1148      * that is either unsigned or signed with a signature that the
   1149      * the instrumentation package is also signed with (ensuring the target
   1150      * trusts the instrumentation).
   1151      *
   1152      * @param className Name of the Instrumentation component to be run.
   1153      * @param profileFile Optional path to write profiling data as the
   1154      * instrumentation runs, or null for no profiling.
   1155      * @param arguments Additional optional arguments to pass to the
   1156      * instrumentation, or null.
   1157      *
   1158      * @return Returns true if the instrumentation was successfully started,
   1159      * else false if it could not be found.
   1160      */
   1161     public abstract boolean startInstrumentation(ComponentName className,
   1162             String profileFile, Bundle arguments);
   1163 
   1164     /**
   1165      * Return the handle to a system-level service by name. The class of the
   1166      * returned object varies by the requested name. Currently available names
   1167      * are:
   1168      *
   1169      * <dl>
   1170      *  <dt> {@link #WINDOW_SERVICE} ("window")
   1171      *  <dd> The top-level window manager in which you can place custom
   1172      *  windows.  The returned object is a {@link android.view.WindowManager}.
   1173      *  <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
   1174      *  <dd> A {@link android.view.LayoutInflater} for inflating layout resources
   1175      *  in this context.
   1176      *  <dt> {@link #ACTIVITY_SERVICE} ("activity")
   1177      *  <dd> A {@link android.app.ActivityManager} for interacting with the
   1178      *  global activity state of the system.
   1179      *  <dt> {@link #POWER_SERVICE} ("power")
   1180      *  <dd> A {@link android.os.PowerManager} for controlling power
   1181      *  management.
   1182      *  <dt> {@link #ALARM_SERVICE} ("alarm")
   1183      *  <dd> A {@link android.app.AlarmManager} for receiving intents at the
   1184      *  time of your choosing.
   1185      *  <dt> {@link #NOTIFICATION_SERVICE} ("notification")
   1186      *  <dd> A {@link android.app.NotificationManager} for informing the user
   1187      *   of background events.
   1188      *  <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
   1189      *  <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
   1190      *  <dt> {@link #LOCATION_SERVICE} ("location")
   1191      *  <dd> A {@link android.location.LocationManager} for controlling location
   1192      *   (e.g., GPS) updates.
   1193      *  <dt> {@link #SEARCH_SERVICE} ("search")
   1194      *  <dd> A {@link android.app.SearchManager} for handling search.
   1195      *  <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
   1196      *  <dd> A {@link android.os.Vibrator} for interacting with the vibrator
   1197      *  hardware.
   1198      *  <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
   1199      *  <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
   1200      *  handling management of network connections.
   1201      *  <dt> {@link #WIFI_SERVICE} ("wifi")
   1202      *  <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
   1203      * Wi-Fi connectivity.
   1204      * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
   1205      * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
   1206      * for management of input methods.
   1207      * <dt> {@link #UI_MODE_SERVICE} ("uimode")
   1208      * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
   1209      * </dl>
   1210      *
   1211      * <p>Note:  System services obtained via this API may be closely associated with
   1212      * the Context in which they are obtained from.  In general, do not share the
   1213      * service objects between various different contexts (Activities, Applications,
   1214      * Services, Providers, etc.)
   1215      *
   1216      * @param name The name of the desired service.
   1217      *
   1218      * @return The service or null if the name does not exist.
   1219      *
   1220      * @see #WINDOW_SERVICE
   1221      * @see android.view.WindowManager
   1222      * @see #LAYOUT_INFLATER_SERVICE
   1223      * @see android.view.LayoutInflater
   1224      * @see #ACTIVITY_SERVICE
   1225      * @see android.app.ActivityManager
   1226      * @see #POWER_SERVICE
   1227      * @see android.os.PowerManager
   1228      * @see #ALARM_SERVICE
   1229      * @see android.app.AlarmManager
   1230      * @see #NOTIFICATION_SERVICE
   1231      * @see android.app.NotificationManager
   1232      * @see #KEYGUARD_SERVICE
   1233      * @see android.app.KeyguardManager
   1234      * @see #LOCATION_SERVICE
   1235      * @see android.location.LocationManager
   1236      * @see #SEARCH_SERVICE
   1237      * @see android.app.SearchManager
   1238      * @see #SENSOR_SERVICE
   1239      * @see android.hardware.SensorManager
   1240      * @see #STORAGE_SERVICE
   1241      * @see android.os.storage.StorageManager
   1242      * @see #VIBRATOR_SERVICE
   1243      * @see android.os.Vibrator
   1244      * @see #CONNECTIVITY_SERVICE
   1245      * @see android.net.ConnectivityManager
   1246      * @see #WIFI_SERVICE
   1247      * @see android.net.wifi.WifiManager
   1248      * @see #AUDIO_SERVICE
   1249      * @see android.media.AudioManager
   1250      * @see #TELEPHONY_SERVICE
   1251      * @see android.telephony.TelephonyManager
   1252      * @see #INPUT_METHOD_SERVICE
   1253      * @see android.view.inputmethod.InputMethodManager
   1254      * @see #UI_MODE_SERVICE
   1255      * @see android.app.UiModeManager
   1256      */
   1257     public abstract Object getSystemService(String name);
   1258 
   1259     /**
   1260      * Use with {@link #getSystemService} to retrieve a
   1261      * {@link android.os.PowerManager} for controlling power management,
   1262      * including "wake locks," which let you keep the device on while
   1263      * you're running long tasks.
   1264      */
   1265     public static final String POWER_SERVICE = "power";
   1266 
   1267     /**
   1268      * Use with {@link #getSystemService} to retrieve a
   1269      * {@link android.view.WindowManager} for accessing the system's window
   1270      * manager.
   1271      *
   1272      * @see #getSystemService
   1273      * @see android.view.WindowManager
   1274      */
   1275     public static final String WINDOW_SERVICE = "window";
   1276 
   1277     /**
   1278      * Use with {@link #getSystemService} to retrieve a
   1279      * {@link android.view.LayoutInflater} for inflating layout resources in this
   1280      * context.
   1281      *
   1282      * @see #getSystemService
   1283      * @see android.view.LayoutInflater
   1284      */
   1285     public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
   1286 
   1287     /**
   1288      * Use with {@link #getSystemService} to retrieve a
   1289      * {@link android.accounts.AccountManager} for receiving intents at a
   1290      * time of your choosing.
   1291      *
   1292      * @see #getSystemService
   1293      * @see android.accounts.AccountManager
   1294      */
   1295     public static final String ACCOUNT_SERVICE = "account";
   1296 
   1297     /**
   1298      * Use with {@link #getSystemService} to retrieve a
   1299      * {@link android.app.ActivityManager} for interacting with the global
   1300      * system state.
   1301      *
   1302      * @see #getSystemService
   1303      * @see android.app.ActivityManager
   1304      */
   1305     public static final String ACTIVITY_SERVICE = "activity";
   1306 
   1307     /**
   1308      * Use with {@link #getSystemService} to retrieve a
   1309      * {@link android.app.AlarmManager} for receiving intents at a
   1310      * time of your choosing.
   1311      *
   1312      * @see #getSystemService
   1313      * @see android.app.AlarmManager
   1314      */
   1315     public static final String ALARM_SERVICE = "alarm";
   1316 
   1317     /**
   1318      * Use with {@link #getSystemService} to retrieve a
   1319      * {@link android.app.NotificationManager} for informing the user of
   1320      * background events.
   1321      *
   1322      * @see #getSystemService
   1323      * @see android.app.NotificationManager
   1324      */
   1325     public static final String NOTIFICATION_SERVICE = "notification";
   1326 
   1327     /**
   1328      * Use with {@link #getSystemService} to retrieve a
   1329      * {@link android.view.accessibility.AccessibilityManager} for giving the user
   1330      * feedback for UI events through the registered event listeners.
   1331      *
   1332      * @see #getSystemService
   1333      * @see android.view.accessibility.AccessibilityManager
   1334      */
   1335     public static final String ACCESSIBILITY_SERVICE = "accessibility";
   1336 
   1337     /**
   1338      * Use with {@link #getSystemService} to retrieve a
   1339      * {@link android.app.NotificationManager} for controlling keyguard.
   1340      *
   1341      * @see #getSystemService
   1342      * @see android.app.KeyguardManager
   1343      */
   1344     public static final String KEYGUARD_SERVICE = "keyguard";
   1345 
   1346     /**
   1347      * Use with {@link #getSystemService} to retrieve a {@link
   1348      * android.location.LocationManager} for controlling location
   1349      * updates.
   1350      *
   1351      * @see #getSystemService
   1352      * @see android.location.LocationManager
   1353      */
   1354     public static final String LOCATION_SERVICE = "location";
   1355 
   1356     /**
   1357      * Use with {@link #getSystemService} to retrieve a {@link
   1358      * android.app.SearchManager} for handling searches.
   1359      *
   1360      * @see #getSystemService
   1361      * @see android.app.SearchManager
   1362      */
   1363     public static final String SEARCH_SERVICE = "search";
   1364 
   1365     /**
   1366      * Use with {@link #getSystemService} to retrieve a {@link
   1367      * android.hardware.SensorManager} for accessing sensors.
   1368      *
   1369      * @see #getSystemService
   1370      * @see android.hardware.SensorManager
   1371      */
   1372     public static final String SENSOR_SERVICE = "sensor";
   1373 
   1374     /**
   1375      * @hide
   1376      * Use with {@link #getSystemService} to retrieve a {@link
   1377      * android.os.storage.StorageManager} for accesssing system storage
   1378      * functions.
   1379      *
   1380      * @see #getSystemService
   1381      * @see android.os.storage.StorageManager
   1382      */
   1383     public static final String STORAGE_SERVICE = "storage";
   1384 
   1385     /**
   1386      * Use with {@link #getSystemService} to retrieve a
   1387      * com.android.server.WallpaperService for accessing wallpapers.
   1388      *
   1389      * @see #getSystemService
   1390      */
   1391     public static final String WALLPAPER_SERVICE = "wallpaper";
   1392 
   1393     /**
   1394      * Use with {@link #getSystemService} to retrieve a {@link
   1395      * android.os.Vibrator} for interacting with the vibration hardware.
   1396      *
   1397      * @see #getSystemService
   1398      * @see android.os.Vibrator
   1399      */
   1400     public static final String VIBRATOR_SERVICE = "vibrator";
   1401 
   1402     /**
   1403      * Use with {@link #getSystemService} to retrieve a {@link
   1404      * android.app.StatusBarManager} for interacting with the status bar.
   1405      *
   1406      * @see #getSystemService
   1407      * @see android.app.StatusBarManager
   1408      * @hide
   1409      */
   1410     public static final String STATUS_BAR_SERVICE = "statusbar";
   1411 
   1412     /**
   1413      * Use with {@link #getSystemService} to retrieve a {@link
   1414      * android.net.ConnectivityManager} for handling management of
   1415      * network connections.
   1416      *
   1417      * @see #getSystemService
   1418      * @see android.net.ConnectivityManager
   1419      */
   1420     public static final String CONNECTIVITY_SERVICE = "connectivity";
   1421 
   1422     /**
   1423      * Use with {@link #getSystemService} to retrieve a {@link
   1424      * android.net.ThrottleManager} for handling management of
   1425      * throttling.
   1426      *
   1427      * @hide
   1428      * @see #getSystemService
   1429      * @see android.net.ThrottleManager
   1430      */
   1431     public static final String THROTTLE_SERVICE = "throttle";
   1432 
   1433     /**
   1434      * Use with {@link #getSystemService} to retrieve a {@link
   1435      * android.net.NetworkManagementService} for handling management of
   1436      * system network services
   1437      *
   1438      * @hide
   1439      * @see #getSystemService
   1440      * @see android.net.NetworkManagementService
   1441      */
   1442     public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
   1443 
   1444     /**
   1445      * Use with {@link #getSystemService} to retrieve a {@link
   1446      * android.net.wifi.WifiManager} for handling management of
   1447      * Wi-Fi access.
   1448      *
   1449      * @see #getSystemService
   1450      * @see android.net.wifi.WifiManager
   1451      */
   1452     public static final String WIFI_SERVICE = "wifi";
   1453 
   1454     /**
   1455      * Use with {@link #getSystemService} to retrieve a
   1456      * {@link android.media.AudioManager} for handling management of volume,
   1457      * ringer modes and audio routing.
   1458      *
   1459      * @see #getSystemService
   1460      * @see android.media.AudioManager
   1461      */
   1462     public static final String AUDIO_SERVICE = "audio";
   1463 
   1464     /**
   1465      * Use with {@link #getSystemService} to retrieve a
   1466      * {@link android.telephony.TelephonyManager} for handling management the
   1467      * telephony features of the device.
   1468      *
   1469      * @see #getSystemService
   1470      * @see android.telephony.TelephonyManager
   1471      */
   1472     public static final String TELEPHONY_SERVICE = "phone";
   1473 
   1474     /**
   1475      * Use with {@link #getSystemService} to retrieve a
   1476      * {@link android.text.ClipboardManager} for accessing and modifying
   1477      * the contents of the global clipboard.
   1478      *
   1479      * @see #getSystemService
   1480      * @see android.text.ClipboardManager
   1481      */
   1482     public static final String CLIPBOARD_SERVICE = "clipboard";
   1483 
   1484     /**
   1485      * Use with {@link #getSystemService} to retrieve a
   1486      * {@link android.view.inputmethod.InputMethodManager} for accessing input
   1487      * methods.
   1488      *
   1489      * @see #getSystemService
   1490      */
   1491     public static final String INPUT_METHOD_SERVICE = "input_method";
   1492 
   1493     /**
   1494      * Use with {@link #getSystemService} to retrieve a
   1495      * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
   1496      *
   1497      * @hide
   1498      * @see #getSystemService
   1499      */
   1500     public static final String APPWIDGET_SERVICE = "appwidget";
   1501 
   1502     /**
   1503      * Use with {@link #getSystemService} to retrieve an
   1504      * {@link android.app.backup.IBackupManager IBackupManager} for communicating
   1505      * with the backup mechanism.
   1506      * @hide
   1507      *
   1508      * @see #getSystemService
   1509      */
   1510     public static final String BACKUP_SERVICE = "backup";
   1511 
   1512     /**
   1513      * Use with {@link #getSystemService} to retrieve a
   1514      * {@link android.os.DropBoxManager} instance for recording
   1515      * diagnostic logs.
   1516      * @see #getSystemService
   1517      */
   1518     public static final String DROPBOX_SERVICE = "dropbox";
   1519 
   1520     /**
   1521      * Use with {@link #getSystemService} to retrieve a
   1522      * {@link android.app.admin.DevicePolicyManager} for working with global
   1523      * device policy management.
   1524      *
   1525      * @see #getSystemService
   1526      */
   1527     public static final String DEVICE_POLICY_SERVICE = "device_policy";
   1528 
   1529     /**
   1530      * Use with {@link #getSystemService} to retrieve a
   1531      * {@link android.app.UiModeManager} for controlling UI modes.
   1532      *
   1533      * @see #getSystemService
   1534      */
   1535     public static final String UI_MODE_SERVICE = "uimode";
   1536 
   1537     /**
   1538      * Determine whether the given permission is allowed for a particular
   1539      * process and user ID running in the system.
   1540      *
   1541      * @param permission The name of the permission being checked.
   1542      * @param pid The process ID being checked against.  Must be > 0.
   1543      * @param uid The user ID being checked against.  A uid of 0 is the root
   1544      * user, which will pass every permission check.
   1545      *
   1546      * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the given
   1547      * pid/uid is allowed that permission, or
   1548      * {@link PackageManager#PERMISSION_DENIED} if it is not.
   1549      *
   1550      * @see PackageManager#checkPermission(String, String)
   1551      * @see #checkCallingPermission
   1552      */
   1553     public abstract int checkPermission(String permission, int pid, int uid);
   1554 
   1555     /**
   1556      * Determine whether the calling process of an IPC you are handling has been
   1557      * granted a particular permission.  This is basically the same as calling
   1558      * {@link #checkPermission(String, int, int)} with the pid and uid returned
   1559      * by {@link android.os.Binder#getCallingPid} and
   1560      * {@link android.os.Binder#getCallingUid}.  One important difference
   1561      * is that if you are not currently processing an IPC, this function
   1562      * will always fail.  This is done to protect against accidentally
   1563      * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
   1564      * to avoid this protection.
   1565      *
   1566      * @param permission The name of the permission being checked.
   1567      *
   1568      * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the calling
   1569      * pid/uid is allowed that permission, or
   1570      * {@link PackageManager#PERMISSION_DENIED} if it is not.
   1571      *
   1572      * @see PackageManager#checkPermission(String, String)
   1573      * @see #checkPermission
   1574      * @see #checkCallingOrSelfPermission
   1575      */
   1576     public abstract int checkCallingPermission(String permission);
   1577 
   1578     /**
   1579      * Determine whether the calling process of an IPC <em>or you</em> have been
   1580      * granted a particular permission.  This is the same as
   1581      * {@link #checkCallingPermission}, except it grants your own permissions
   1582      * if you are not currently processing an IPC.  Use with care!
   1583      *
   1584      * @param permission The name of the permission being checked.
   1585      *
   1586      * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the calling
   1587      * pid/uid is allowed that permission, or
   1588      * {@link PackageManager#PERMISSION_DENIED} if it is not.
   1589      *
   1590      * @see PackageManager#checkPermission(String, String)
   1591      * @see #checkPermission
   1592      * @see #checkCallingPermission
   1593      */
   1594     public abstract int checkCallingOrSelfPermission(String permission);
   1595 
   1596     /**
   1597      * If the given permission is not allowed for a particular process
   1598      * and user ID running in the system, throw a {@link SecurityException}.
   1599      *
   1600      * @param permission The name of the permission being checked.
   1601      * @param pid The process ID being checked against.  Must be &gt; 0.
   1602      * @param uid The user ID being checked against.  A uid of 0 is the root
   1603      * user, which will pass every permission check.
   1604      * @param message A message to include in the exception if it is thrown.
   1605      *
   1606      * @see #checkPermission(String, int, int)
   1607      */
   1608     public abstract void enforcePermission(
   1609             String permission, int pid, int uid, String message);
   1610 
   1611     /**
   1612      * If the calling process of an IPC you are handling has not been
   1613      * granted a particular permission, throw a {@link
   1614      * SecurityException}.  This is basically the same as calling
   1615      * {@link #enforcePermission(String, int, int, String)} with the
   1616      * pid and uid returned by {@link android.os.Binder#getCallingPid}
   1617      * and {@link android.os.Binder#getCallingUid}.  One important
   1618      * difference is that if you are not currently processing an IPC,
   1619      * this function will always throw the SecurityException.  This is
   1620      * done to protect against accidentally leaking permissions; you
   1621      * can use {@link #enforceCallingOrSelfPermission} to avoid this
   1622      * protection.
   1623      *
   1624      * @param permission The name of the permission being checked.
   1625      * @param message A message to include in the exception if it is thrown.
   1626      *
   1627      * @see #checkCallingPermission(String)
   1628      */
   1629     public abstract void enforceCallingPermission(
   1630             String permission, String message);
   1631 
   1632     /**
   1633      * If neither you nor the calling process of an IPC you are
   1634      * handling has been granted a particular permission, throw a
   1635      * {@link SecurityException}.  This is the same as {@link
   1636      * #enforceCallingPermission}, except it grants your own
   1637      * permissions if you are not currently processing an IPC.  Use
   1638      * with care!
   1639      *
   1640      * @param permission The name of the permission being checked.
   1641      * @param message A message to include in the exception if it is thrown.
   1642      *
   1643      * @see #checkCallingOrSelfPermission(String)
   1644      */
   1645     public abstract void enforceCallingOrSelfPermission(
   1646             String permission, String message);
   1647 
   1648     /**
   1649      * Grant permission to access a specific Uri to another package, regardless
   1650      * of whether that package has general permission to access the Uri's
   1651      * content provider.  This can be used to grant specific, temporary
   1652      * permissions, typically in response to user interaction (such as the
   1653      * user opening an attachment that you would like someone else to
   1654      * display).
   1655      *
   1656      * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
   1657      * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
   1658      * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
   1659      * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
   1660      * start an activity instead of this function directly.  If you use this
   1661      * function directly, you should be sure to call
   1662      * {@link #revokeUriPermission} when the target should no longer be allowed
   1663      * to access it.
   1664      *
   1665      * <p>To succeed, the content provider owning the Uri must have set the
   1666      * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
   1667      * grantUriPermissions} attribute in its manifest or included the
   1668      * {@link android.R.styleable#AndroidManifestGrantUriPermission
   1669      * &lt;grant-uri-permissions&gt;} tag.
   1670      *
   1671      * @param toPackage The package you would like to allow to access the Uri.
   1672      * @param uri The Uri you would like to grant access to.
   1673      * @param modeFlags The desired access modes.  Any combination of
   1674      * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
   1675      * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
   1676      * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
   1677      * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
   1678      *
   1679      * @see #revokeUriPermission
   1680      */
   1681     public abstract void grantUriPermission(String toPackage, Uri uri,
   1682             int modeFlags);
   1683 
   1684     /**
   1685      * Remove all permissions to access a particular content provider Uri
   1686      * that were previously added with {@link #grantUriPermission}.  The given
   1687      * Uri will match all previously granted Uris that are the same or a
   1688      * sub-path of the given Uri.  That is, revoking "content://foo/one" will
   1689      * revoke both "content://foo/target" and "content://foo/target/sub", but not
   1690      * "content://foo".
   1691      *
   1692      * @param uri The Uri you would like to revoke access to.
   1693      * @param modeFlags The desired access modes.  Any combination of
   1694      * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
   1695      * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
   1696      * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
   1697      * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
   1698      *
   1699      * @see #grantUriPermission
   1700      */
   1701     public abstract void revokeUriPermission(Uri uri, int modeFlags);
   1702 
   1703     /**
   1704      * Determine whether a particular process and user ID has been granted
   1705      * permission to access a specific URI.  This only checks for permissions
   1706      * that have been explicitly granted -- if the given process/uid has
   1707      * more general access to the URI's content provider then this check will
   1708      * always fail.
   1709      *
   1710      * @param uri The uri that is being checked.
   1711      * @param pid The process ID being checked against.  Must be &gt; 0.
   1712      * @param uid The user ID being checked against.  A uid of 0 is the root
   1713      * user, which will pass every permission check.
   1714      * @param modeFlags The type of access to grant.  May be one or both of
   1715      * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
   1716      * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
   1717      *
   1718      * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the given
   1719      * pid/uid is allowed to access that uri, or
   1720      * {@link PackageManager#PERMISSION_DENIED} if it is not.
   1721      *
   1722      * @see #checkCallingUriPermission
   1723      */
   1724     public abstract int checkUriPermission(Uri uri, int pid, int uid, int modeFlags);
   1725 
   1726     /**
   1727      * Determine whether the calling process and user ID has been
   1728      * granted permission to access a specific URI.  This is basically
   1729      * the same as calling {@link #checkUriPermission(Uri, int, int,
   1730      * int)} with the pid and uid returned by {@link
   1731      * android.os.Binder#getCallingPid} and {@link
   1732      * android.os.Binder#getCallingUid}.  One important difference is
   1733      * that if you are not currently processing an IPC, this function
   1734      * will always fail.
   1735      *
   1736      * @param uri The uri that is being checked.
   1737      * @param modeFlags The type of access to grant.  May be one or both of
   1738      * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
   1739      * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
   1740      *
   1741      * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
   1742      * is allowed to access that uri, or
   1743      * {@link PackageManager#PERMISSION_DENIED} if it is not.
   1744      *
   1745      * @see #checkUriPermission(Uri, int, int, int)
   1746      */
   1747     public abstract int checkCallingUriPermission(Uri uri, int modeFlags);
   1748 
   1749     /**
   1750      * Determine whether the calling process of an IPC <em>or you</em> has been granted
   1751      * permission to access a specific URI.  This is the same as
   1752      * {@link #checkCallingUriPermission}, except it grants your own permissions
   1753      * if you are not currently processing an IPC.  Use with care!
   1754      *
   1755      * @param uri The uri that is being checked.
   1756      * @param modeFlags The type of access to grant.  May be one or both of
   1757      * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
   1758      * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
   1759      *
   1760      * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
   1761      * is allowed to access that uri, or
   1762      * {@link PackageManager#PERMISSION_DENIED} if it is not.
   1763      *
   1764      * @see #checkCallingUriPermission
   1765      */
   1766     public abstract int checkCallingOrSelfUriPermission(Uri uri, int modeFlags);
   1767 
   1768     /**
   1769      * Check both a Uri and normal permission.  This allows you to perform
   1770      * both {@link #checkPermission} and {@link #checkUriPermission} in one
   1771      * call.
   1772      *
   1773      * @param uri The Uri whose permission is to be checked, or null to not
   1774      * do this check.
   1775      * @param readPermission The permission that provides overall read access,
   1776      * or null to not do this check.
   1777      * @param writePermission The permission that provides overall write
   1778      * acess, or null to not do this check.
   1779      * @param pid The process ID being checked against.  Must be &gt; 0.
   1780      * @param uid The user ID being checked against.  A uid of 0 is the root
   1781      * user, which will pass every permission check.
   1782      * @param modeFlags The type of access to grant.  May be one or both of
   1783      * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
   1784      * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
   1785      *
   1786      * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
   1787      * is allowed to access that uri or holds one of the given permissions, or
   1788      * {@link PackageManager#PERMISSION_DENIED} if it is not.
   1789      */
   1790     public abstract int checkUriPermission(Uri uri, String readPermission,
   1791             String writePermission, int pid, int uid, int modeFlags);
   1792 
   1793     /**
   1794      * If a particular process and user ID has not been granted
   1795      * permission to access a specific URI, throw {@link
   1796      * SecurityException}.  This only checks for permissions that have
   1797      * been explicitly granted -- if the given process/uid has more
   1798      * general access to the URI's content provider then this check
   1799      * will always fail.
   1800      *
   1801      * @param uri The uri that is being checked.
   1802      * @param pid The process ID being checked against.  Must be &gt; 0.
   1803      * @param uid The user ID being checked against.  A uid of 0 is the root
   1804      * user, which will pass every permission check.
   1805      * @param modeFlags The type of access to grant.  May be one or both of
   1806      * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
   1807      * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
   1808      * @param message A message to include in the exception if it is thrown.
   1809      *
   1810      * @see #checkUriPermission(Uri, int, int, int)
   1811      */
   1812     public abstract void enforceUriPermission(
   1813             Uri uri, int pid, int uid, int modeFlags, String message);
   1814 
   1815     /**
   1816      * If the calling process and user ID has not been granted
   1817      * permission to access a specific URI, throw {@link
   1818      * SecurityException}.  This is basically the same as calling
   1819      * {@link #enforceUriPermission(Uri, int, int, int, String)} with
   1820      * the pid and uid returned by {@link
   1821      * android.os.Binder#getCallingPid} and {@link
   1822      * android.os.Binder#getCallingUid}.  One important difference is
   1823      * that if you are not currently processing an IPC, this function
   1824      * will always throw a SecurityException.
   1825      *
   1826      * @param uri The uri that is being checked.
   1827      * @param modeFlags The type of access to grant.  May be one or both of
   1828      * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
   1829      * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
   1830      * @param message A message to include in the exception if it is thrown.
   1831      *
   1832      * @see #checkCallingUriPermission(Uri, int)
   1833      */
   1834     public abstract void enforceCallingUriPermission(
   1835             Uri uri, int modeFlags, String message);
   1836 
   1837     /**
   1838      * If the calling process of an IPC <em>or you</em> has not been
   1839      * granted permission to access a specific URI, throw {@link
   1840      * SecurityException}.  This is the same as {@link
   1841      * #enforceCallingUriPermission}, except it grants your own
   1842      * permissions if you are not currently processing an IPC.  Use
   1843      * with care!
   1844      *
   1845      * @param uri The uri that is being checked.
   1846      * @param modeFlags The type of access to grant.  May be one or both of
   1847      * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
   1848      * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
   1849      * @param message A message to include in the exception if it is thrown.
   1850      *
   1851      * @see #checkCallingOrSelfUriPermission(Uri, int)
   1852      */
   1853     public abstract void enforceCallingOrSelfUriPermission(
   1854             Uri uri, int modeFlags, String message);
   1855 
   1856     /**
   1857      * Enforce both a Uri and normal permission.  This allows you to perform
   1858      * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
   1859      * call.
   1860      *
   1861      * @param uri The Uri whose permission is to be checked, or null to not
   1862      * do this check.
   1863      * @param readPermission The permission that provides overall read access,
   1864      * or null to not do this check.
   1865      * @param writePermission The permission that provides overall write
   1866      * acess, or null to not do this check.
   1867      * @param pid The process ID being checked against.  Must be &gt; 0.
   1868      * @param uid The user ID being checked against.  A uid of 0 is the root
   1869      * user, which will pass every permission check.
   1870      * @param modeFlags The type of access to grant.  May be one or both of
   1871      * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
   1872      * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
   1873      * @param message A message to include in the exception if it is thrown.
   1874      *
   1875      * @see #checkUriPermission(Uri, String, String, int, int, int)
   1876      */
   1877     public abstract void enforceUriPermission(
   1878             Uri uri, String readPermission, String writePermission,
   1879             int pid, int uid, int modeFlags, String message);
   1880 
   1881     /**
   1882      * Flag for use with {@link #createPackageContext}: include the application
   1883      * code with the context.  This means loading code into the caller's
   1884      * process, so that {@link #getClassLoader()} can be used to instantiate
   1885      * the application's classes.  Setting this flags imposes security
   1886      * restrictions on what application context you can access; if the
   1887      * requested application can not be safely loaded into your process,
   1888      * java.lang.SecurityException will be thrown.  If this flag is not set,
   1889      * there will be no restrictions on the packages that can be loaded,
   1890      * but {@link #getClassLoader} will always return the default system
   1891      * class loader.
   1892      */
   1893     public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
   1894 
   1895     /**
   1896      * Flag for use with {@link #createPackageContext}: ignore any security
   1897      * restrictions on the Context being requested, allowing it to always
   1898      * be loaded.  For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
   1899      * to be loaded into a process even when it isn't safe to do so.  Use
   1900      * with extreme care!
   1901      */
   1902     public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
   1903 
   1904     /**
   1905      * Flag for use with {@link #createPackageContext}: a restricted context may
   1906      * disable specific features. For instance, a View associated with a restricted
   1907      * context would ignore particular XML attributes.
   1908      */
   1909     public static final int CONTEXT_RESTRICTED = 0x00000004;
   1910 
   1911     /**
   1912      * Return a new Context object for the given application name.  This
   1913      * Context is the same as what the named application gets when it is
   1914      * launched, containing the same resources and class loader.  Each call to
   1915      * this method returns a new instance of a Context object; Context objects
   1916      * are not shared, however they share common state (Resources, ClassLoader,
   1917      * etc) so the Context instance itself is fairly lightweight.
   1918      *
   1919      * <p>Throws {@link PackageManager.NameNotFoundException} if there is no
   1920      * application with the given package name.
   1921      *
   1922      * <p>Throws {@link java.lang.SecurityException} if the Context requested
   1923      * can not be loaded into the caller's process for security reasons (see
   1924      * {@link #CONTEXT_INCLUDE_CODE} for more information}.
   1925      *
   1926      * @param packageName Name of the application's package.
   1927      * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
   1928      *              or {@link #CONTEXT_IGNORE_SECURITY}.
   1929      *
   1930      * @return A Context for the application.
   1931      *
   1932      * @throws java.lang.SecurityException
   1933      * @throws PackageManager.NameNotFoundException if there is no application with
   1934      * the given package name
   1935      */
   1936     public abstract Context createPackageContext(String packageName,
   1937             int flags) throws PackageManager.NameNotFoundException;
   1938 
   1939     /**
   1940      * Indicates whether this Context is restricted.
   1941      *
   1942      * @return True if this Context is restricted, false otherwise.
   1943      *
   1944      * @see #CONTEXT_RESTRICTED
   1945      */
   1946     public boolean isRestricted() {
   1947         return false;
   1948     }
   1949 }
   1950