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