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