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