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