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