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