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