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