Context.java revision a58a8751b4c2ce457f0082a0baaee61312d56195
1/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
19import android.content.pm.ApplicationInfo;
20import android.content.pm.PackageManager;
21import android.content.res.AssetManager;
22import android.content.res.Resources;
23import android.content.res.TypedArray;
24import android.database.DatabaseErrorHandler;
25import android.database.sqlite.SQLiteDatabase;
26import android.database.sqlite.SQLiteDatabase.CursorFactory;
27import android.graphics.Bitmap;
28import android.graphics.drawable.Drawable;
29import android.media.MediaScannerConnection.OnScanCompletedListener;
30import android.net.Uri;
31import android.os.Bundle;
32import android.os.Handler;
33import android.os.Looper;
34import android.util.AttributeSet;
35
36import java.io.File;
37import java.io.FileInputStream;
38import java.io.FileNotFoundException;
39import java.io.FileOutputStream;
40import java.io.IOException;
41import java.io.InputStream;
42
43/**
44 * Interface to global information about an application environment.  This is
45 * an abstract class whose implementation is provided by
46 * the Android system.  It
47 * allows access to application-specific resources and classes, as well as
48 * up-calls for application-level operations such as launching activities,
49 * broadcasting and receiving intents, etc.
50 */
51public abstract class Context {
52    /**
53     * File creation mode: the default mode, where the created file can only
54     * be accessed by the calling application (or all applications sharing the
55     * same user ID).
56     * @see #MODE_WORLD_READABLE
57     * @see #MODE_WORLD_WRITEABLE
58     */
59    public static final int MODE_PRIVATE = 0x0000;
60    /**
61     * File creation mode: allow all other applications to have read access
62     * to the created file.
63     * @see #MODE_PRIVATE
64     * @see #MODE_WORLD_WRITEABLE
65     */
66    public static final int MODE_WORLD_READABLE = 0x0001;
67    /**
68     * File creation mode: allow all other applications to have write access
69     * to the created file.
70     * @see #MODE_PRIVATE
71     * @see #MODE_WORLD_READABLE
72     */
73    public static final int MODE_WORLD_WRITEABLE = 0x0002;
74    /**
75     * File creation mode: for use with {@link #openFileOutput}, if the file
76     * already exists then write data to the end of the existing file
77     * instead of erasing it.
78     * @see #openFileOutput
79     */
80    public static final int MODE_APPEND = 0x8000;
81
82    /**
83     * Flag for {@link #bindService}: automatically create the service as long
84     * as the binding exists.  Note that while this will create the service,
85     * its {@link android.app.Service#onStart} method will still only be called due to an
86     * explicit call to {@link #startService}.  Even without that, though,
87     * this still provides you with access to the service object while the
88     * service is created.
89     *
90     * <p>Specifying this flag also tells the system to treat the service
91     * as being as important as your own process -- that is, when deciding
92     * which process should be killed to free memory, the service will only
93     * be considered a candidate as long as the processes of any such bindings
94     * is also a candidate to be killed.  This is to avoid situations where
95     * the service is being continually created and killed due to low memory.
96     */
97    public static final int BIND_AUTO_CREATE = 0x0001;
98
99    /**
100     * Flag for {@link #bindService}: include debugging help for mismatched
101     * calls to unbind.  When this flag is set, the callstack of the following
102     * {@link #unbindService} call is retained, to be printed if a later
103     * incorrect unbind call is made.  Note that doing this requires retaining
104     * information about the binding that was made for the lifetime of the app,
105     * resulting in a leak -- this should only be used for debugging.
106     */
107    public static final int BIND_DEBUG_UNBIND = 0x0002;
108
109    /**
110     * Flag for {@link #bindService}: don't allow this binding to raise
111     * the target service's process to the foreground scheduling priority.
112     * It will still be raised to the at least the same memory priority
113     * as the client (so that its process will not be killable in any
114     * situation where the client is not killable), but for CPU scheduling
115     * purposes it may be left in the background.  This only has an impact
116     * in the situation where the binding client is a foreground process
117     * and the target service is in a background process.
118     */
119    public static final int BIND_NOT_FOREGROUND = 0x0004;
120
121    /** Return an AssetManager instance for your application's package. */
122    public abstract AssetManager getAssets();
123
124    /** Return a Resources instance for your application's package. */
125    public abstract Resources getResources();
126
127    /** Return PackageManager instance to find global package information. */
128    public abstract PackageManager getPackageManager();
129
130    /** Return a ContentResolver instance for your application's package. */
131    public abstract ContentResolver getContentResolver();
132
133    /**
134     * Return the Looper for the main thread of the current process.  This is
135     * the thread used to dispatch calls to application components (activities,
136     * services, etc).
137     */
138    public abstract Looper getMainLooper();
139
140    /**
141     * Return the context of the single, global Application object of the
142     * current process.  This generally should only be used if you need a
143     * Context whose lifecycle is separate from the current context, that is
144     * tied to the lifetime of the process rather than the current component.
145     *
146     * <p>Consider for example how this interacts with
147     * {@ #registerReceiver(BroadcastReceiver, IntentFilter)}:
148     * <ul>
149     * <li> <p>If used from an Activity context, the receiver is being registered
150     * within that activity.  This means that you are expected to unregister
151     * before the activity is done being destroyed; in fact if you do not do
152     * so, the framework will clean up your leaked registration as it removes
153     * the activity and log an error.  Thus, if you use the Activity context
154     * to register a receiver that is static (global to the process, not
155     * associated with an Activity instance) then that registration will be
156     * removed on you at whatever point the activity you used is destroyed.
157     * <li> <p>If used from the Context returned here, the receiver is being
158     * registered with the global state associated with your application.  Thus
159     * it will never be unregistered for you.  This is necessary if the receiver
160     * is associated with static data, not a particular component.  However
161     * using the ApplicationContext elsewhere can easily lead to serious leaks
162     * if you forget to unregister, unbind, etc.
163     * </ul>
164     */
165    public abstract Context getApplicationContext();
166
167    /**
168     * Return a localized, styled CharSequence from the application's package's
169     * default string table.
170     *
171     * @param resId Resource id for the CharSequence text
172     */
173    public final CharSequence getText(int resId) {
174        return getResources().getText(resId);
175    }
176
177    /**
178     * Return a localized string from the application's package's
179     * default string table.
180     *
181     * @param resId Resource id for the string
182     */
183    public final String getString(int resId) {
184        return getResources().getString(resId);
185    }
186
187    /**
188     * Return a localized formatted string from the application's package's
189     * default string table, substituting the format arguments as defined in
190     * {@link java.util.Formatter} and {@link java.lang.String#format}.
191     *
192     * @param resId Resource id for the format string
193     * @param formatArgs The format arguments that will be used for substitution.
194     */
195
196    public final String getString(int resId, Object... formatArgs) {
197        return getResources().getString(resId, formatArgs);
198    }
199
200     /**
201     * Set the base theme for this context.  Note that this should be called
202     * before any views are instantiated in the Context (for example before
203     * calling {@link android.app.Activity#setContentView} or
204     * {@link android.view.LayoutInflater#inflate}).
205     *
206     * @param resid The style resource describing the theme.
207     */
208    public abstract void setTheme(int resid);
209
210    /**
211     * Return the Theme object associated with this Context.
212     */
213    public abstract Resources.Theme getTheme();
214
215    /**
216     * Retrieve styled attribute information in this Context's theme.  See
217     * {@link Resources.Theme#obtainStyledAttributes(int[])}
218     * for more information.
219     *
220     * @see Resources.Theme#obtainStyledAttributes(int[])
221     */
222    public final TypedArray obtainStyledAttributes(
223            int[] attrs) {
224        return getTheme().obtainStyledAttributes(attrs);
225    }
226
227    /**
228     * Retrieve styled attribute information in this Context's theme.  See
229     * {@link Resources.Theme#obtainStyledAttributes(int, int[])}
230     * for more information.
231     *
232     * @see Resources.Theme#obtainStyledAttributes(int, int[])
233     */
234    public final TypedArray obtainStyledAttributes(
235            int resid, int[] attrs) throws Resources.NotFoundException {
236        return getTheme().obtainStyledAttributes(resid, attrs);
237    }
238
239    /**
240     * Retrieve styled attribute information in this Context's theme.  See
241     * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
242     * for more information.
243     *
244     * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
245     */
246    public final TypedArray obtainStyledAttributes(
247            AttributeSet set, int[] attrs) {
248        return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
249    }
250
251    /**
252     * Retrieve styled attribute information in this Context's theme.  See
253     * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
254     * for more information.
255     *
256     * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
257     */
258    public final TypedArray obtainStyledAttributes(
259            AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) {
260        return getTheme().obtainStyledAttributes(
261            set, attrs, defStyleAttr, defStyleRes);
262    }
263
264    /**
265     * Return a class loader you can use to retrieve classes in this package.
266     */
267    public abstract ClassLoader getClassLoader();
268
269    /** Return the name of this application's package. */
270    public abstract String getPackageName();
271
272    /** Return the full application info for this context's package. */
273    public abstract ApplicationInfo getApplicationInfo();
274
275    /**
276     * Return the full path to this context's primary Android package.
277     * The Android package is a ZIP file which contains the application's
278     * primary resources.
279     *
280     * <p>Note: this is not generally useful for applications, since they should
281     * not be directly accessing the file system.
282     *
283     * @return String Path to the resources.
284     */
285    public abstract String getPackageResourcePath();
286
287    /**
288     * Return the full path to this context's primary Android package.
289     * The Android package is a ZIP file which contains application's
290     * primary code and assets.
291     *
292     * <p>Note: this is not generally useful for applications, since they should
293     * not be directly accessing the file system.
294     *
295     * @return String Path to the code and assets.
296     */
297    public abstract String getPackageCodePath();
298
299    /**
300     * {@hide}
301     * Return the full path to the shared prefs file for the given prefs group name.
302     *
303     * <p>Note: this is not generally useful for applications, since they should
304     * not be directly accessing the file system.
305     */
306    public abstract File getSharedPrefsFile(String name);
307
308    /**
309     * Retrieve and hold the contents of the preferences file 'name', returning
310     * a SharedPreferences through which you can retrieve and modify its
311     * values.  Only one instance of the SharedPreferences object is returned
312     * to any callers for the same name, meaning they will see each other's
313     * edits as soon as they are made.
314     *
315     * @param name Desired preferences file. If a preferences file by this name
316     * does not exist, it will be created when you retrieve an
317     * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
318     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
319     * default operation, {@link #MODE_WORLD_READABLE}
320     * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
321     *
322     * @return Returns the single SharedPreferences instance that can be used
323     *         to retrieve and modify the preference values.
324     *
325     * @see #MODE_PRIVATE
326     * @see #MODE_WORLD_READABLE
327     * @see #MODE_WORLD_WRITEABLE
328     */
329    public abstract SharedPreferences getSharedPreferences(String name,
330            int mode);
331
332    /**
333     * Open a private file associated with this Context's application package
334     * for reading.
335     *
336     * @param name The name of the file to open; can not contain path
337     *             separators.
338     *
339     * @return FileInputStream Resulting input stream.
340     *
341     * @see #openFileOutput
342     * @see #fileList
343     * @see #deleteFile
344     * @see java.io.FileInputStream#FileInputStream(String)
345     */
346    public abstract FileInputStream openFileInput(String name)
347        throws FileNotFoundException;
348
349    /**
350     * Open a private file associated with this Context's application package
351     * for writing.  Creates the file if it doesn't already exist.
352     *
353     * @param name The name of the file to open; can not contain path
354     *             separators.
355     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
356     * default operation, {@link #MODE_APPEND} to append to an existing file,
357     * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control
358     * permissions.
359     *
360     * @return FileOutputStream Resulting output stream.
361     *
362     * @see #MODE_APPEND
363     * @see #MODE_PRIVATE
364     * @see #MODE_WORLD_READABLE
365     * @see #MODE_WORLD_WRITEABLE
366     * @see #openFileInput
367     * @see #fileList
368     * @see #deleteFile
369     * @see java.io.FileOutputStream#FileOutputStream(String)
370     */
371    public abstract FileOutputStream openFileOutput(String name, int mode)
372        throws FileNotFoundException;
373
374    /**
375     * Delete the given private file associated with this Context's
376     * application package.
377     *
378     * @param name The name of the file to delete; can not contain path
379     *             separators.
380     *
381     * @return True if the file was successfully deleted; else
382     *         false.
383     *
384     * @see #openFileInput
385     * @see #openFileOutput
386     * @see #fileList
387     * @see java.io.File#delete()
388     */
389    public abstract boolean deleteFile(String name);
390
391    /**
392     * Returns the absolute path on the filesystem where a file created with
393     * {@link #openFileOutput} is stored.
394     *
395     * @param name The name of the file for which you would like to get
396     *          its path.
397     *
398     * @return Returns an absolute path to the given file.
399     *
400     * @see #openFileOutput
401     * @see #getFilesDir
402     * @see #getDir
403     */
404    public abstract File getFileStreamPath(String name);
405
406    /**
407     * Returns the absolute path to the directory on the filesystem where
408     * files created with {@link #openFileOutput} are stored.
409     *
410     * @return Returns the path of the directory holding application files.
411     *
412     * @see #openFileOutput
413     * @see #getFileStreamPath
414     * @see #getDir
415     */
416    public abstract File getFilesDir();
417
418    /**
419     * Returns the absolute path to the directory on the external filesystem
420     * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
421     * Environment.getExternalStorageDirectory()}) where the application can
422     * place persistent files it owns.  These files are private to the
423     * applications, and not typically visible to the user as media.
424     *
425     * <p>This is like {@link #getFilesDir()} in that these
426     * files will be deleted when the application is uninstalled, however there
427     * are some important differences:
428     *
429     * <ul>
430     * <li>External files are not always available: they will disappear if the
431     * user mounts the external storage on a computer or removes it.  See the
432     * APIs on {@link android.os.Environment} for information in the storage state.
433     * <li>There is no security enforced with these files.  All applications
434     * can read and write files placed here.
435     * </ul>
436     *
437     * <p>Here is an example of typical code to manipulate a file in
438     * an application's private storage:</p>
439     *
440     * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
441     * private_file}
442     *
443     * <p>If you supply a non-null <var>type</var> to this function, the returned
444     * file will be a path to a sub-directory of the given type.  Though these files
445     * are not automatically scanned by the media scanner, you can explicitly
446     * add them to the media database with
447     * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
448     *      OnScanCompletedListener) MediaScannerConnection.scanFile}.
449     * Note that this is not the same as
450     * {@link android.os.Environment#getExternalStoragePublicDirectory
451     * Environment.getExternalStoragePublicDirectory()}, which provides
452     * directories of media shared by all applications.  The
453     * directories returned here are
454     * owned by the application, and their contents will be removed when the
455     * application is uninstalled.  Unlike
456     * {@link android.os.Environment#getExternalStoragePublicDirectory
457     * Environment.getExternalStoragePublicDirectory()}, the directory
458     * returned here will be automatically created for you.
459     *
460     * <p>Here is an example of typical code to manipulate a picture in
461     * an application's private storage and add it to the media database:</p>
462     *
463     * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
464     * private_picture}
465     *
466     * @param type The type of files directory to return.  May be null for
467     * the root of the files directory or one of
468     * the following Environment constants for a subdirectory:
469     * {@link android.os.Environment#DIRECTORY_MUSIC},
470     * {@link android.os.Environment#DIRECTORY_PODCASTS},
471     * {@link android.os.Environment#DIRECTORY_RINGTONES},
472     * {@link android.os.Environment#DIRECTORY_ALARMS},
473     * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
474     * {@link android.os.Environment#DIRECTORY_PICTURES}, or
475     * {@link android.os.Environment#DIRECTORY_MOVIES}.
476     *
477     * @return Returns the path of the directory holding application files
478     * on external storage.  Returns null if external storage is not currently
479     * mounted so it could not ensure the path exists; you will need to call
480     * this method again when it is available.
481     *
482     * @see #getFilesDir
483     * @see android.os.Environment#getExternalStoragePublicDirectory
484     */
485    public abstract File getExternalFilesDir(String type);
486
487    /**
488     * Returns the absolute path to the application specific cache directory
489     * on the filesystem. These files will be ones that get deleted first when the
490     * device runs low on storage.
491     * There is no guarantee when these files will be deleted.
492     *
493     * <strong>Note: you should not <em>rely</em> on the system deleting these
494     * files for you; you should always have a reasonable maximum, such as 1 MB,
495     * for the amount of space you consume with cache files, and prune those
496     * files when exceeding that space.</strong>
497     *
498     * @return Returns the path of the directory holding application cache files.
499     *
500     * @see #openFileOutput
501     * @see #getFileStreamPath
502     * @see #getDir
503     */
504    public abstract File getCacheDir();
505
506    /**
507     * Returns the absolute path to the directory on the external filesystem
508     * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
509     * Environment.getExternalStorageDirectory()} where the application can
510     * place cache files it owns.
511     *
512     * <p>This is like {@link #getCacheDir()} in that these
513     * files will be deleted when the application is uninstalled, however there
514     * are some important differences:
515     *
516     * <ul>
517     * <li>The platform does not monitor the space available in external storage,
518     * and thus will not automatically delete these files.  Note that you should
519     * be managing the maximum space you will use for these anyway, just like
520     * with {@link #getCacheDir()}.
521     * <li>External files are not always available: they will disappear if the
522     * user mounts the external storage on a computer or removes it.  See the
523     * APIs on {@link android.os.Environment} for information in the storage state.
524     * <li>There is no security enforced with these files.  All applications
525     * can read and write files placed here.
526     * </ul>
527     *
528     * @return Returns the path of the directory holding application cache files
529     * on external storage.  Returns null if external storage is not currently
530     * mounted so it could not ensure the path exists; you will need to call
531     * this method again when it is available.
532     *
533     * @see #getCacheDir
534     */
535    public abstract File getExternalCacheDir();
536
537    /**
538     * Returns an array of strings naming the private files associated with
539     * this Context's application package.
540     *
541     * @return Array of strings naming the private files.
542     *
543     * @see #openFileInput
544     * @see #openFileOutput
545     * @see #deleteFile
546     */
547    public abstract String[] fileList();
548
549    /**
550     * Retrieve, creating if needed, a new directory in which the application
551     * can place its own custom data files.  You can use the returned File
552     * object to create and access files in this directory.  Note that files
553     * created through a File object will only be accessible by your own
554     * application; you can only set the mode of the entire directory, not
555     * of individual files.
556     *
557     * @param name Name of the directory to retrieve.  This is a directory
558     * that is created as part of your application data.
559     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
560     * default operation, {@link #MODE_WORLD_READABLE} and
561     * {@link #MODE_WORLD_WRITEABLE} to control permissions.
562     *
563     * @return Returns a File object for the requested directory.  The directory
564     * will have been created if it does not already exist.
565     *
566     * @see #openFileOutput(String, int)
567     */
568    public abstract File getDir(String name, int mode);
569
570    /**
571     * Open a new private SQLiteDatabase associated with this Context's
572     * application package.  Create the database file if it doesn't exist.
573     *
574     * @param name The name (unique in the application package) of the database.
575     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
576     *     default operation, {@link #MODE_WORLD_READABLE}
577     *     and {@link #MODE_WORLD_WRITEABLE} to control permissions.
578     * @param factory An optional factory class that is called to instantiate a
579     *     cursor when query is called.
580     *
581     * @return The contents of a newly created database with the given name.
582     * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
583     *
584     * @see #MODE_PRIVATE
585     * @see #MODE_WORLD_READABLE
586     * @see #MODE_WORLD_WRITEABLE
587     * @see #deleteDatabase
588     */
589    public abstract SQLiteDatabase openOrCreateDatabase(String name,
590            int mode, CursorFactory factory);
591
592    /**
593     * Open a new private SQLiteDatabase associated with this Context's
594     * application package.  Creates the database file if it doesn't exist.
595     *
596     * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be
597     * used to handle corruption when sqlite reports database corruption.</p>
598     *
599     * @param name The name (unique in the application package) of the database.
600     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
601     *     default operation, {@link #MODE_WORLD_READABLE}
602     *     and {@link #MODE_WORLD_WRITEABLE} to control permissions.
603     * @param factory An optional factory class that is called to instantiate a
604     *     cursor when query is called.
605     * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database
606     * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed.
607     * @return The contents of a newly created database with the given name.
608     * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
609     *
610     * @see #MODE_PRIVATE
611     * @see #MODE_WORLD_READABLE
612     * @see #MODE_WORLD_WRITEABLE
613     * @see #deleteDatabase
614     */
615    public abstract SQLiteDatabase openOrCreateDatabase(String name,
616            int mode, CursorFactory factory, DatabaseErrorHandler errorHandler);
617
618    /**
619     * Delete an existing private SQLiteDatabase associated with this Context's
620     * application package.
621     *
622     * @param name The name (unique in the application package) of the
623     *             database.
624     *
625     * @return True if the database was successfully deleted; else false.
626     *
627     * @see #openOrCreateDatabase
628     */
629    public abstract boolean deleteDatabase(String name);
630
631    /**
632     * Returns the absolute path on the filesystem where a database created with
633     * {@link #openOrCreateDatabase} is stored.
634     *
635     * @param name The name of the database for which you would like to get
636     *          its path.
637     *
638     * @return Returns an absolute path to the given database.
639     *
640     * @see #openOrCreateDatabase
641     */
642    public abstract File getDatabasePath(String name);
643
644    /**
645     * Returns an array of strings naming the private databases associated with
646     * this Context's application package.
647     *
648     * @return Array of strings naming the private databases.
649     *
650     * @see #openOrCreateDatabase
651     * @see #deleteDatabase
652     */
653    public abstract String[] databaseList();
654
655    /**
656     * @deprecated Use {@link android.app.WallpaperManager#getDrawable
657     * WallpaperManager.get()} instead.
658     */
659    @Deprecated
660    public abstract Drawable getWallpaper();
661
662    /**
663     * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
664     * WallpaperManager.peek()} instead.
665     */
666    @Deprecated
667    public abstract Drawable peekWallpaper();
668
669    /**
670     * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
671     * WallpaperManager.getDesiredMinimumWidth()} instead.
672     */
673    @Deprecated
674    public abstract int getWallpaperDesiredMinimumWidth();
675
676    /**
677     * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
678     * WallpaperManager.getDesiredMinimumHeight()} instead.
679     */
680    @Deprecated
681    public abstract int getWallpaperDesiredMinimumHeight();
682
683    /**
684     * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
685     * WallpaperManager.set()} instead.
686     */
687    @Deprecated
688    public abstract void setWallpaper(Bitmap bitmap) throws IOException;
689
690    /**
691     * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
692     * WallpaperManager.set()} instead.
693     */
694    @Deprecated
695    public abstract void setWallpaper(InputStream data) throws IOException;
696
697    /**
698     * @deprecated Use {@link android.app.WallpaperManager#clear
699     * WallpaperManager.clear()} instead.
700     */
701    @Deprecated
702    public abstract void clearWallpaper() throws IOException;
703
704    /**
705     * Launch a new activity.  You will not receive any information about when
706     * the activity exits.
707     *
708     * <p>Note that if this method is being called from outside of an
709     * {@link android.app.Activity} Context, then the Intent must include
710     * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag.  This is because,
711     * without being started from an existing Activity, there is no existing
712     * task in which to place the new activity and thus it needs to be placed
713     * in its own separate task.
714     *
715     * <p>This method throws {@link ActivityNotFoundException}
716     * if there was no Activity found to run the given Intent.
717     *
718     * @param intent The description of the activity to start.
719     *
720     * @throws ActivityNotFoundException
721     *
722     * @see PackageManager#resolveActivity
723     */
724    public abstract void startActivity(Intent intent);
725
726    /**
727     * Like {@link #startActivity(Intent)}, but taking a IntentSender
728     * to start.  If the IntentSender is for an activity, that activity will be started
729     * as if you had called the regular {@link #startActivity(Intent)}
730     * here; otherwise, its associated action will be executed (such as
731     * sending a broadcast) as if you had called
732     * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
733     *
734     * @param intent The IntentSender to launch.
735     * @param fillInIntent If non-null, this will be provided as the
736     * intent parameter to {@link IntentSender#sendIntent}.
737     * @param flagsMask Intent flags in the original IntentSender that you
738     * would like to change.
739     * @param flagsValues Desired values for any bits set in
740     * <var>flagsMask</var>
741     * @param extraFlags Always set to 0.
742     */
743    public abstract void startIntentSender(IntentSender intent,
744            Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
745            throws IntentSender.SendIntentException;
746
747    /**
748     * Broadcast the given intent to all interested BroadcastReceivers.  This
749     * call is asynchronous; it returns immediately, and you will continue
750     * executing while the receivers are run.  No results are propagated from
751     * receivers and receivers can not abort the broadcast. If you want
752     * to allow receivers to propagate results or abort the broadcast, you must
753     * send an ordered broadcast using
754     * {@link #sendOrderedBroadcast(Intent, String)}.
755     *
756     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
757     *
758     * @param intent The Intent to broadcast; all receivers matching this
759     *               Intent will receive the broadcast.
760     *
761     * @see android.content.BroadcastReceiver
762     * @see #registerReceiver
763     * @see #sendBroadcast(Intent, String)
764     * @see #sendOrderedBroadcast(Intent, String)
765     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
766     */
767    public abstract void sendBroadcast(Intent intent);
768
769    /**
770     * Broadcast the given intent to all interested BroadcastReceivers, allowing
771     * an optional required permission to be enforced.  This
772     * call is asynchronous; it returns immediately, and you will continue
773     * executing while the receivers are run.  No results are propagated from
774     * receivers and receivers can not abort the broadcast. If you want
775     * to allow receivers to propagate results or abort the broadcast, you must
776     * send an ordered broadcast using
777     * {@link #sendOrderedBroadcast(Intent, String)}.
778     *
779     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
780     *
781     * @param intent The Intent to broadcast; all receivers matching this
782     *               Intent will receive the broadcast.
783     * @param receiverPermission (optional) String naming a permissions that
784     *               a receiver must hold in order to receive your broadcast.
785     *               If null, no permission is required.
786     *
787     * @see android.content.BroadcastReceiver
788     * @see #registerReceiver
789     * @see #sendBroadcast(Intent)
790     * @see #sendOrderedBroadcast(Intent, String)
791     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
792     */
793    public abstract void sendBroadcast(Intent intent,
794            String receiverPermission);
795
796    /**
797     * Broadcast the given intent to all interested BroadcastReceivers, delivering
798     * them one at a time to allow more preferred receivers to consume the
799     * broadcast before it is delivered to less preferred receivers.  This
800     * call is asynchronous; it returns immediately, and you will continue
801     * executing while the receivers are run.
802     *
803     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
804     *
805     * @param intent The Intent to broadcast; all receivers matching this
806     *               Intent will receive the broadcast.
807     * @param receiverPermission (optional) String naming a permissions that
808     *               a receiver must hold in order to receive your broadcast.
809     *               If null, no permission is required.
810     *
811     * @see android.content.BroadcastReceiver
812     * @see #registerReceiver
813     * @see #sendBroadcast(Intent)
814     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
815     */
816    public abstract void sendOrderedBroadcast(Intent intent,
817            String receiverPermission);
818
819    /**
820     * Version of {@link #sendBroadcast(Intent)} that allows you to
821     * receive data back from the broadcast.  This is accomplished by
822     * supplying your own BroadcastReceiver when calling, which will be
823     * treated as a final receiver at the end of the broadcast -- its
824     * {@link BroadcastReceiver#onReceive} method will be called with
825     * the result values collected from the other receivers.  The broadcast will
826     * be serialized in the same way as calling
827     * {@link #sendOrderedBroadcast(Intent, String)}.
828     *
829     * <p>Like {@link #sendBroadcast(Intent)}, this method is
830     * asynchronous; it will return before
831     * resultReceiver.onReceive() is called.
832     *
833     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
834     *
835     * @param intent The Intent to broadcast; all receivers matching this
836     *               Intent will receive the broadcast.
837     * @param receiverPermission String naming a permissions that
838     *               a receiver must hold in order to receive your broadcast.
839     *               If null, no permission is required.
840     * @param resultReceiver Your own BroadcastReceiver to treat as the final
841     *                       receiver of the broadcast.
842     * @param scheduler A custom Handler with which to schedule the
843     *                  resultReceiver callback; if null it will be
844     *                  scheduled in the Context's main thread.
845     * @param initialCode An initial value for the result code.  Often
846     *                    Activity.RESULT_OK.
847     * @param initialData An initial value for the result data.  Often
848     *                    null.
849     * @param initialExtras An initial value for the result extras.  Often
850     *                      null.
851     *
852     * @see #sendBroadcast(Intent)
853     * @see #sendBroadcast(Intent, String)
854     * @see #sendOrderedBroadcast(Intent, String)
855     * @see #sendStickyBroadcast(Intent)
856     * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
857     * @see android.content.BroadcastReceiver
858     * @see #registerReceiver
859     * @see android.app.Activity#RESULT_OK
860     */
861    public abstract void sendOrderedBroadcast(Intent intent,
862            String receiverPermission, BroadcastReceiver resultReceiver,
863            Handler scheduler, int initialCode, String initialData,
864            Bundle initialExtras);
865
866    /**
867     * Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
868     * Intent you are sending stays around after the broadcast is complete,
869     * so that others can quickly retrieve that data through the return
870     * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}.  In
871     * all other ways, this behaves the same as
872     * {@link #sendBroadcast(Intent)}.
873     *
874     * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
875     * permission in order to use this API.  If you do not hold that
876     * permission, {@link SecurityException} will be thrown.
877     *
878     * @param intent The Intent to broadcast; all receivers matching this
879     * Intent will receive the broadcast, and the Intent will be held to
880     * be re-broadcast to future receivers.
881     *
882     * @see #sendBroadcast(Intent)
883     * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
884     */
885    public abstract void sendStickyBroadcast(Intent intent);
886
887    /**
888     * Version of {@link #sendStickyBroadcast} that allows you to
889     * receive data back from the broadcast.  This is accomplished by
890     * supplying your own BroadcastReceiver when calling, which will be
891     * treated as a final receiver at the end of the broadcast -- its
892     * {@link BroadcastReceiver#onReceive} method will be called with
893     * the result values collected from the other receivers.  The broadcast will
894     * be serialized in the same way as calling
895     * {@link #sendOrderedBroadcast(Intent, String)}.
896     *
897     * <p>Like {@link #sendBroadcast(Intent)}, this method is
898     * asynchronous; it will return before
899     * resultReceiver.onReceive() is called.  Note that the sticky data
900     * stored is only the data you initially supply to the broadcast, not
901     * the result of any changes made by the receivers.
902     *
903     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
904     *
905     * @param intent The Intent to broadcast; all receivers matching this
906     *               Intent will receive the broadcast.
907     * @param resultReceiver Your own BroadcastReceiver to treat as the final
908     *                       receiver of the broadcast.
909     * @param scheduler A custom Handler with which to schedule the
910     *                  resultReceiver callback; if null it will be
911     *                  scheduled in the Context's main thread.
912     * @param initialCode An initial value for the result code.  Often
913     *                    Activity.RESULT_OK.
914     * @param initialData An initial value for the result data.  Often
915     *                    null.
916     * @param initialExtras An initial value for the result extras.  Often
917     *                      null.
918     *
919     * @see #sendBroadcast(Intent)
920     * @see #sendBroadcast(Intent, String)
921     * @see #sendOrderedBroadcast(Intent, String)
922     * @see #sendStickyBroadcast(Intent)
923     * @see android.content.BroadcastReceiver
924     * @see #registerReceiver
925     * @see android.app.Activity#RESULT_OK
926     */
927    public abstract void sendStickyOrderedBroadcast(Intent intent,
928            BroadcastReceiver resultReceiver,
929            Handler scheduler, int initialCode, String initialData,
930            Bundle initialExtras);
931
932
933    /**
934     * Remove the data previously sent with {@link #sendStickyBroadcast},
935     * so that it is as if the sticky broadcast had never happened.
936     *
937     * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
938     * permission in order to use this API.  If you do not hold that
939     * permission, {@link SecurityException} will be thrown.
940     *
941     * @param intent The Intent that was previously broadcast.
942     *
943     * @see #sendStickyBroadcast
944     */
945    public abstract void removeStickyBroadcast(Intent intent);
946
947    /**
948     * Register a BroadcastReceiver to be run in the main activity thread.  The
949     * <var>receiver</var> will be called with any broadcast Intent that
950     * matches <var>filter</var>, in the main application thread.
951     *
952     * <p>The system may broadcast Intents that are "sticky" -- these stay
953     * around after the broadcast as finished, to be sent to any later
954     * registrations. If your IntentFilter matches one of these sticky
955     * Intents, that Intent will be returned by this function
956     * <strong>and</strong> sent to your <var>receiver</var> as if it had just
957     * been broadcast.
958     *
959     * <p>There may be multiple sticky Intents that match <var>filter</var>,
960     * in which case each of these will be sent to <var>receiver</var>.  In
961     * this case, only one of these can be returned directly by the function;
962     * which of these that is returned is arbitrarily decided by the system.
963     *
964     * <p>If you know the Intent your are registering for is sticky, you can
965     * supply null for your <var>receiver</var>.  In this case, no receiver is
966     * registered -- the function simply returns the sticky Intent that
967     * matches <var>filter</var>.  In the case of multiple matches, the same
968     * rules as described above apply.
969     *
970     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
971     *
972     * <p class="note">Note: this method <em>cannot be called from a
973     * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
974     * that is declared in an application's manifest.  It is okay, however, to call
975     * this method from another BroadcastReceiver that has itself been registered
976     * at run time with {@link #registerReceiver}, since the lifetime of such a
977     * registered BroadcastReceiver is tied to the object that registered it.</p>
978     *
979     * @param receiver The BroadcastReceiver to handle the broadcast.
980     * @param filter Selects the Intent broadcasts to be received.
981     *
982     * @return The first sticky intent found that matches <var>filter</var>,
983     *         or null if there are none.
984     *
985     * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
986     * @see #sendBroadcast
987     * @see #unregisterReceiver
988     */
989    public abstract Intent registerReceiver(BroadcastReceiver receiver,
990                                            IntentFilter filter);
991
992    /**
993     * Register to receive intent broadcasts, to run in the context of
994     * <var>scheduler</var>.  See
995     * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
996     * information.  This allows you to enforce permissions on who can
997     * broadcast intents to your receiver, or have the receiver run in
998     * a different thread than the main application thread.
999     *
1000     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1001     *
1002     * @param receiver The BroadcastReceiver to handle the broadcast.
1003     * @param filter Selects the Intent broadcasts to be received.
1004     * @param broadcastPermission String naming a permissions that a
1005     *      broadcaster must hold in order to send an Intent to you.  If null,
1006     *      no permission is required.
1007     * @param scheduler Handler identifying the thread that will receive
1008     *      the Intent.  If null, the main thread of the process will be used.
1009     *
1010     * @return The first sticky intent found that matches <var>filter</var>,
1011     *         or null if there are none.
1012     *
1013     * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1014     * @see #sendBroadcast
1015     * @see #unregisterReceiver
1016     */
1017    public abstract Intent registerReceiver(BroadcastReceiver receiver,
1018                                            IntentFilter filter,
1019                                            String broadcastPermission,
1020                                            Handler scheduler);
1021
1022    /**
1023     * Unregister a previously registered BroadcastReceiver.  <em>All</em>
1024     * filters that have been registered for this BroadcastReceiver will be
1025     * removed.
1026     *
1027     * @param receiver The BroadcastReceiver to unregister.
1028     *
1029     * @see #registerReceiver
1030     */
1031    public abstract void unregisterReceiver(BroadcastReceiver receiver);
1032
1033    /**
1034     * Request that a given application service be started.  The Intent
1035     * can either contain the complete class name of a specific service
1036     * implementation to start, or an abstract definition through the
1037     * action and other fields of the kind of service to start.  If this service
1038     * is not already running, it will be instantiated and started (creating a
1039     * process for it if needed); if it is running then it remains running.
1040     *
1041     * <p>Every call to this method will result in a corresponding call to
1042     * the target service's {@link android.app.Service#onStart} method,
1043     * with the <var>intent</var> given here.  This provides a convenient way
1044     * to submit jobs to a service without having to bind and call on to its
1045     * interface.
1046     *
1047     * <p>Using startService() overrides the default service lifetime that is
1048     * managed by {@link #bindService}: it requires the service to remain
1049     * running until {@link #stopService} is called, regardless of whether
1050     * any clients are connected to it.  Note that calls to startService()
1051     * are not nesting: no matter how many times you call startService(),
1052     * a single call to {@link #stopService} will stop it.
1053     *
1054     * <p>The system attempts to keep running services around as much as
1055     * possible.  The only time they should be stopped is if the current
1056     * foreground application is using so many resources that the service needs
1057     * to be killed.  If any errors happen in the service's process, it will
1058     * automatically be restarted.
1059     *
1060     * <p>This function will throw {@link SecurityException} if you do not
1061     * have permission to start the given service.
1062     *
1063     * @param service Identifies the service to be started.  The Intent may
1064     *      specify either an explicit component name to start, or a logical
1065     *      description (action, category, etc) to match an
1066     *      {@link IntentFilter} published by a service.  Additional values
1067     *      may be included in the Intent extras to supply arguments along with
1068     *      this specific start call.
1069     *
1070     * @return If the service is being started or is already running, the
1071     * {@link ComponentName} of the actual service that was started is
1072     * returned; else if the service does not exist null is returned.
1073     *
1074     * @throws SecurityException
1075     *
1076     * @see #stopService
1077     * @see #bindService
1078     */
1079    public abstract ComponentName startService(Intent service);
1080
1081    /**
1082     * Request that a given application service be stopped.  If the service is
1083     * not running, nothing happens.  Otherwise it is stopped.  Note that calls
1084     * to startService() are not counted -- this stops the service no matter
1085     * how many times it was started.
1086     *
1087     * <p>Note that if a stopped service still has {@link ServiceConnection}
1088     * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
1089     * not be destroyed until all of these bindings are removed.  See
1090     * the {@link android.app.Service} documentation for more details on a
1091     * service's lifecycle.
1092     *
1093     * <p>This function will throw {@link SecurityException} if you do not
1094     * have permission to stop the given service.
1095     *
1096     * @param service Description of the service to be stopped.  The Intent may
1097     *      specify either an explicit component name to start, or a logical
1098     *      description (action, category, etc) to match an
1099     *      {@link IntentFilter} published by a service.
1100     *
1101     * @return If there is a service matching the given Intent that is already
1102     * running, then it is stopped and true is returned; else false is returned.
1103     *
1104     * @throws SecurityException
1105     *
1106     * @see #startService
1107     */
1108    public abstract boolean stopService(Intent service);
1109
1110    /**
1111     * Connect to an application service, creating it if needed.  This defines
1112     * a dependency between your application and the service.  The given
1113     * <var>conn</var> will receive the service object when its created and be
1114     * told if it dies and restarts.  The service will be considered required
1115     * by the system only for as long as the calling context exists.  For
1116     * example, if this Context is an Activity that is stopped, the service will
1117     * not be required to continue running until the Activity is resumed.
1118     *
1119     * <p>This function will throw {@link SecurityException} if you do not
1120     * have permission to bind to the given service.
1121     *
1122     * <p class="note">Note: this method <em>can not be called from an
1123     * {@link BroadcastReceiver} component</em>.  A pattern you can use to
1124     * communicate from an BroadcastReceiver to a Service is to call
1125     * {@link #startService} with the arguments containing the command to be
1126     * sent, with the service calling its
1127     * {@link android.app.Service#stopSelf(int)} method when done executing
1128     * that command.  See the API demo App/Service/Service Start Arguments
1129     * Controller for an illustration of this.  It is okay, however, to use
1130     * this method from an BroadcastReceiver that has been registered with
1131     * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
1132     * is tied to another object (the one that registered it).</p>
1133     *
1134     * @param service Identifies the service to connect to.  The Intent may
1135     *      specify either an explicit component name, or a logical
1136     *      description (action, category, etc) to match an
1137     *      {@link IntentFilter} published by a service.
1138     * @param conn Receives information as the service is started and stopped.
1139     * @param flags Operation options for the binding.  May be 0 or
1140     *          {@link #BIND_AUTO_CREATE}.
1141     * @return If you have successfully bound to the service, true is returned;
1142     *         false is returned if the connection is not made so you will not
1143     *         receive the service object.
1144     *
1145     * @throws SecurityException
1146     *
1147     * @see #unbindService
1148     * @see #startService
1149     * @see #BIND_AUTO_CREATE
1150     */
1151    public abstract boolean bindService(Intent service, ServiceConnection conn,
1152            int flags);
1153
1154    /**
1155     * Disconnect from an application service.  You will no longer receive
1156     * calls as the service is restarted, and the service is now allowed to
1157     * stop at any time.
1158     *
1159     * @param conn The connection interface previously supplied to
1160     *             bindService().
1161     *
1162     * @see #bindService
1163     */
1164    public abstract void unbindService(ServiceConnection conn);
1165
1166    /**
1167     * Start executing an {@link android.app.Instrumentation} class.  The given
1168     * Instrumentation component will be run by killing its target application
1169     * (if currently running), starting the target process, instantiating the
1170     * instrumentation component, and then letting it drive the application.
1171     *
1172     * <p>This function is not synchronous -- it returns as soon as the
1173     * instrumentation has started and while it is running.
1174     *
1175     * <p>Instrumentation is normally only allowed to run against a package
1176     * that is either unsigned or signed with a signature that the
1177     * the instrumentation package is also signed with (ensuring the target
1178     * trusts the instrumentation).
1179     *
1180     * @param className Name of the Instrumentation component to be run.
1181     * @param profileFile Optional path to write profiling data as the
1182     * instrumentation runs, or null for no profiling.
1183     * @param arguments Additional optional arguments to pass to the
1184     * instrumentation, or null.
1185     *
1186     * @return Returns true if the instrumentation was successfully started,
1187     * else false if it could not be found.
1188     */
1189    public abstract boolean startInstrumentation(ComponentName className,
1190            String profileFile, Bundle arguments);
1191
1192    /**
1193     * Return the handle to a system-level service by name. The class of the
1194     * returned object varies by the requested name. Currently available names
1195     * are:
1196     *
1197     * <dl>
1198     *  <dt> {@link #WINDOW_SERVICE} ("window")
1199     *  <dd> The top-level window manager in which you can place custom
1200     *  windows.  The returned object is a {@link android.view.WindowManager}.
1201     *  <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
1202     *  <dd> A {@link android.view.LayoutInflater} for inflating layout resources
1203     *  in this context.
1204     *  <dt> {@link #ACTIVITY_SERVICE} ("activity")
1205     *  <dd> A {@link android.app.ActivityManager} for interacting with the
1206     *  global activity state of the system.
1207     *  <dt> {@link #POWER_SERVICE} ("power")
1208     *  <dd> A {@link android.os.PowerManager} for controlling power
1209     *  management.
1210     *  <dt> {@link #ALARM_SERVICE} ("alarm")
1211     *  <dd> A {@link android.app.AlarmManager} for receiving intents at the
1212     *  time of your choosing.
1213     *  <dt> {@link #NOTIFICATION_SERVICE} ("notification")
1214     *  <dd> A {@link android.app.NotificationManager} for informing the user
1215     *   of background events.
1216     *  <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
1217     *  <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
1218     *  <dt> {@link #LOCATION_SERVICE} ("location")
1219     *  <dd> A {@link android.location.LocationManager} for controlling location
1220     *   (e.g., GPS) updates.
1221     *  <dt> {@link #SEARCH_SERVICE} ("search")
1222     *  <dd> A {@link android.app.SearchManager} for handling search.
1223     *  <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
1224     *  <dd> A {@link android.os.Vibrator} for interacting with the vibrator
1225     *  hardware.
1226     *  <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
1227     *  <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
1228     *  handling management of network connections.
1229     *  <dt> {@link #WIFI_SERVICE} ("wifi")
1230     *  <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
1231     * Wi-Fi connectivity.
1232     * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
1233     * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
1234     * for management of input methods.
1235     * <dt> {@link #UI_MODE_SERVICE} ("uimode")
1236     * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
1237     * </dl>
1238     *
1239     * <p>Note:  System services obtained via this API may be closely associated with
1240     * the Context in which they are obtained from.  In general, do not share the
1241     * service objects between various different contexts (Activities, Applications,
1242     * Services, Providers, etc.)
1243     *
1244     * @param name The name of the desired service.
1245     *
1246     * @return The service or null if the name does not exist.
1247     *
1248     * @see #WINDOW_SERVICE
1249     * @see android.view.WindowManager
1250     * @see #LAYOUT_INFLATER_SERVICE
1251     * @see android.view.LayoutInflater
1252     * @see #ACTIVITY_SERVICE
1253     * @see android.app.ActivityManager
1254     * @see #POWER_SERVICE
1255     * @see android.os.PowerManager
1256     * @see #ALARM_SERVICE
1257     * @see android.app.AlarmManager
1258     * @see #NOTIFICATION_SERVICE
1259     * @see android.app.NotificationManager
1260     * @see #KEYGUARD_SERVICE
1261     * @see android.app.KeyguardManager
1262     * @see #LOCATION_SERVICE
1263     * @see android.location.LocationManager
1264     * @see #SEARCH_SERVICE
1265     * @see android.app.SearchManager
1266     * @see #SENSOR_SERVICE
1267     * @see android.hardware.SensorManager
1268     * @see #STORAGE_SERVICE
1269     * @see android.os.storage.StorageManager
1270     * @see #VIBRATOR_SERVICE
1271     * @see android.os.Vibrator
1272     * @see #CONNECTIVITY_SERVICE
1273     * @see android.net.ConnectivityManager
1274     * @see #WIFI_SERVICE
1275     * @see android.net.wifi.WifiManager
1276     * @see #AUDIO_SERVICE
1277     * @see android.media.AudioManager
1278     * @see #TELEPHONY_SERVICE
1279     * @see android.telephony.TelephonyManager
1280     * @see #INPUT_METHOD_SERVICE
1281     * @see android.view.inputmethod.InputMethodManager
1282     * @see #UI_MODE_SERVICE
1283     * @see android.app.UiModeManager
1284     */
1285    public abstract Object getSystemService(String name);
1286
1287    /**
1288     * Use with {@link #getSystemService} to retrieve a
1289     * {@link android.os.PowerManager} for controlling power management,
1290     * including "wake locks," which let you keep the device on while
1291     * you're running long tasks.
1292     */
1293    public static final String POWER_SERVICE = "power";
1294
1295    /**
1296     * Use with {@link #getSystemService} to retrieve a
1297     * {@link android.view.WindowManager} for accessing the system's window
1298     * manager.
1299     *
1300     * @see #getSystemService
1301     * @see android.view.WindowManager
1302     */
1303    public static final String WINDOW_SERVICE = "window";
1304
1305    /**
1306     * Use with {@link #getSystemService} to retrieve a
1307     * {@link android.view.LayoutInflater} for inflating layout resources in this
1308     * context.
1309     *
1310     * @see #getSystemService
1311     * @see android.view.LayoutInflater
1312     */
1313    public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
1314
1315    /**
1316     * Use with {@link #getSystemService} to retrieve a
1317     * {@link android.accounts.AccountManager} for receiving intents at a
1318     * time of your choosing.
1319     *
1320     * @see #getSystemService
1321     * @see android.accounts.AccountManager
1322     */
1323    public static final String ACCOUNT_SERVICE = "account";
1324
1325    /**
1326     * Use with {@link #getSystemService} to retrieve a
1327     * {@link android.app.ActivityManager} for interacting with the global
1328     * system state.
1329     *
1330     * @see #getSystemService
1331     * @see android.app.ActivityManager
1332     */
1333    public static final String ACTIVITY_SERVICE = "activity";
1334
1335    /**
1336     * Use with {@link #getSystemService} to retrieve a
1337     * {@link android.app.AlarmManager} for receiving intents at a
1338     * time of your choosing.
1339     *
1340     * @see #getSystemService
1341     * @see android.app.AlarmManager
1342     */
1343    public static final String ALARM_SERVICE = "alarm";
1344
1345    /**
1346     * Use with {@link #getSystemService} to retrieve a
1347     * {@link android.app.NotificationManager} for informing the user of
1348     * background events.
1349     *
1350     * @see #getSystemService
1351     * @see android.app.NotificationManager
1352     */
1353    public static final String NOTIFICATION_SERVICE = "notification";
1354
1355    /**
1356     * Use with {@link #getSystemService} to retrieve a
1357     * {@link android.view.accessibility.AccessibilityManager} for giving the user
1358     * feedback for UI events through the registered event listeners.
1359     *
1360     * @see #getSystemService
1361     * @see android.view.accessibility.AccessibilityManager
1362     */
1363    public static final String ACCESSIBILITY_SERVICE = "accessibility";
1364
1365    /**
1366     * Use with {@link #getSystemService} to retrieve a
1367     * {@link android.app.NotificationManager} for controlling keyguard.
1368     *
1369     * @see #getSystemService
1370     * @see android.app.KeyguardManager
1371     */
1372    public static final String KEYGUARD_SERVICE = "keyguard";
1373
1374    /**
1375     * Use with {@link #getSystemService} to retrieve a {@link
1376     * android.location.LocationManager} for controlling location
1377     * updates.
1378     *
1379     * @see #getSystemService
1380     * @see android.location.LocationManager
1381     */
1382    public static final String LOCATION_SERVICE = "location";
1383
1384    /**
1385     * Use with {@link #getSystemService} to retrieve a
1386     * {@link android.location.CountryDetector} for detecting the country that
1387     * the user is in.
1388     *
1389     * @hide
1390     */
1391    public static final String COUNTRY_DETECTOR = "country_detector";
1392
1393    /**
1394     * Use with {@link #getSystemService} to retrieve a {@link
1395     * android.app.SearchManager} for handling searches.
1396     *
1397     * @see #getSystemService
1398     * @see android.app.SearchManager
1399     */
1400    public static final String SEARCH_SERVICE = "search";
1401
1402    /**
1403     * Use with {@link #getSystemService} to retrieve a {@link
1404     * android.hardware.SensorManager} for accessing sensors.
1405     *
1406     * @see #getSystemService
1407     * @see android.hardware.SensorManager
1408     */
1409    public static final String SENSOR_SERVICE = "sensor";
1410
1411    /**
1412     * Use with {@link #getSystemService} to retrieve a {@link
1413     * android.os.storage.StorageManager} for accessing system storage
1414     * functions.
1415     *
1416     * @see #getSystemService
1417     * @see android.os.storage.StorageManager
1418     */
1419    public static final String STORAGE_SERVICE = "storage";
1420
1421    /**
1422     * Use with {@link #getSystemService} to retrieve a
1423     * com.android.server.WallpaperService for accessing wallpapers.
1424     *
1425     * @see #getSystemService
1426     */
1427    public static final String WALLPAPER_SERVICE = "wallpaper";
1428
1429    /**
1430     * Use with {@link #getSystemService} to retrieve a {@link
1431     * android.os.Vibrator} for interacting with the vibration hardware.
1432     *
1433     * @see #getSystemService
1434     * @see android.os.Vibrator
1435     */
1436    public static final String VIBRATOR_SERVICE = "vibrator";
1437
1438    /**
1439     * Use with {@link #getSystemService} to retrieve a {@link
1440     * android.app.StatusBarManager} for interacting with the status bar.
1441     *
1442     * @see #getSystemService
1443     * @see android.app.StatusBarManager
1444     * @hide
1445     */
1446    public static final String STATUS_BAR_SERVICE = "statusbar";
1447
1448    /**
1449     * Use with {@link #getSystemService} to retrieve a {@link
1450     * android.net.ConnectivityManager} for handling management of
1451     * network connections.
1452     *
1453     * @see #getSystemService
1454     * @see android.net.ConnectivityManager
1455     */
1456    public static final String CONNECTIVITY_SERVICE = "connectivity";
1457
1458    /**
1459     * Use with {@link #getSystemService} to retrieve a {@link
1460     * android.net.ThrottleManager} for handling management of
1461     * throttling.
1462     *
1463     * @hide
1464     * @see #getSystemService
1465     * @see android.net.ThrottleManager
1466     */
1467    public static final String THROTTLE_SERVICE = "throttle";
1468
1469    /**
1470     * Use with {@link #getSystemService} to retrieve a {@link
1471     * android.net.NetworkManagementService} for handling management of
1472     * system network services
1473     *
1474     * @hide
1475     * @see #getSystemService
1476     * @see android.net.NetworkManagementService
1477     */
1478    public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
1479
1480    /**
1481     * Use with {@link #getSystemService} to retrieve a {@link
1482     * android.net.wifi.WifiManager} for handling management of
1483     * Wi-Fi access.
1484     *
1485     * @see #getSystemService
1486     * @see android.net.wifi.WifiManager
1487     */
1488    public static final String WIFI_SERVICE = "wifi";
1489
1490    /**
1491     * Use with {@link #getSystemService} to retrieve a
1492     * {@link android.media.AudioManager} for handling management of volume,
1493     * ringer modes and audio routing.
1494     *
1495     * @see #getSystemService
1496     * @see android.media.AudioManager
1497     */
1498    public static final String AUDIO_SERVICE = "audio";
1499
1500    /**
1501     * Use with {@link #getSystemService} to retrieve a
1502     * {@link android.telephony.TelephonyManager} for handling management the
1503     * telephony features of the device.
1504     *
1505     * @see #getSystemService
1506     * @see android.telephony.TelephonyManager
1507     */
1508    public static final String TELEPHONY_SERVICE = "phone";
1509
1510    /**
1511     * Use with {@link #getSystemService} to retrieve a
1512     * {@link android.text.ClipboardManager} for accessing and modifying
1513     * the contents of the global clipboard.
1514     *
1515     * @see #getSystemService
1516     * @see android.text.ClipboardManager
1517     */
1518    public static final String CLIPBOARD_SERVICE = "clipboard";
1519
1520    /**
1521     * Use with {@link #getSystemService} to retrieve a
1522     * {@link android.view.inputmethod.InputMethodManager} for accessing input
1523     * methods.
1524     *
1525     * @see #getSystemService
1526     */
1527    public static final String INPUT_METHOD_SERVICE = "input_method";
1528
1529    /**
1530     * Use with {@link #getSystemService} to retrieve a
1531     * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
1532     *
1533     * @hide
1534     * @see #getSystemService
1535     */
1536    public static final String APPWIDGET_SERVICE = "appwidget";
1537
1538    /**
1539     * Use with {@link #getSystemService} to retrieve an
1540     * {@link android.app.backup.IBackupManager IBackupManager} for communicating
1541     * with the backup mechanism.
1542     * @hide
1543     *
1544     * @see #getSystemService
1545     */
1546    public static final String BACKUP_SERVICE = "backup";
1547
1548    /**
1549     * Use with {@link #getSystemService} to retrieve a
1550     * {@link android.os.DropBoxManager} instance for recording
1551     * diagnostic logs.
1552     * @see #getSystemService
1553     */
1554    public static final String DROPBOX_SERVICE = "dropbox";
1555
1556    /**
1557     * Use with {@link #getSystemService} to retrieve a
1558     * {@link android.app.admin.DevicePolicyManager} for working with global
1559     * device policy management.
1560     *
1561     * @see #getSystemService
1562     */
1563    public static final String DEVICE_POLICY_SERVICE = "device_policy";
1564
1565    /**
1566     * Use with {@link #getSystemService} to retrieve a
1567     * {@link android.app.UiModeManager} for controlling UI modes.
1568     *
1569     * @see #getSystemService
1570     */
1571    public static final String UI_MODE_SERVICE = "uimode";
1572
1573    /**
1574     * Use with {@link #getSystemService} to retrieve a
1575     * {@link android.net.DownloadManager} for requesting HTTP downloads.
1576     *
1577     * @see #getSystemService
1578     */
1579    public static final String DOWNLOAD_SERVICE = "download";
1580
1581    /**
1582     * Determine whether the given permission is allowed for a particular
1583     * process and user ID running in the system.
1584     *
1585     * @param permission The name of the permission being checked.
1586     * @param pid The process ID being checked against.  Must be > 0.
1587     * @param uid The user ID being checked against.  A uid of 0 is the root
1588     * user, which will pass every permission check.
1589     *
1590     * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the given
1591     * pid/uid is allowed that permission, or
1592     * {@link PackageManager#PERMISSION_DENIED} if it is not.
1593     *
1594     * @see PackageManager#checkPermission(String, String)
1595     * @see #checkCallingPermission
1596     */
1597    public abstract int checkPermission(String permission, int pid, int uid);
1598
1599    /**
1600     * Determine whether the calling process of an IPC you are handling has been
1601     * granted a particular permission.  This is basically the same as calling
1602     * {@link #checkPermission(String, int, int)} with the pid and uid returned
1603     * by {@link android.os.Binder#getCallingPid} and
1604     * {@link android.os.Binder#getCallingUid}.  One important difference
1605     * is that if you are not currently processing an IPC, this function
1606     * will always fail.  This is done to protect against accidentally
1607     * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
1608     * to avoid this protection.
1609     *
1610     * @param permission The name of the permission being checked.
1611     *
1612     * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the calling
1613     * pid/uid is allowed that permission, or
1614     * {@link PackageManager#PERMISSION_DENIED} if it is not.
1615     *
1616     * @see PackageManager#checkPermission(String, String)
1617     * @see #checkPermission
1618     * @see #checkCallingOrSelfPermission
1619     */
1620    public abstract int checkCallingPermission(String permission);
1621
1622    /**
1623     * Determine whether the calling process of an IPC <em>or you</em> have been
1624     * granted a particular permission.  This is the same as
1625     * {@link #checkCallingPermission}, except it grants your own permissions
1626     * if you are not currently processing an IPC.  Use with care!
1627     *
1628     * @param permission The name of the permission being checked.
1629     *
1630     * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the calling
1631     * pid/uid is allowed that permission, or
1632     * {@link PackageManager#PERMISSION_DENIED} if it is not.
1633     *
1634     * @see PackageManager#checkPermission(String, String)
1635     * @see #checkPermission
1636     * @see #checkCallingPermission
1637     */
1638    public abstract int checkCallingOrSelfPermission(String permission);
1639
1640    /**
1641     * If the given permission is not allowed for a particular process
1642     * and user ID running in the system, throw a {@link SecurityException}.
1643     *
1644     * @param permission The name of the permission being checked.
1645     * @param pid The process ID being checked against.  Must be &gt; 0.
1646     * @param uid The user ID being checked against.  A uid of 0 is the root
1647     * user, which will pass every permission check.
1648     * @param message A message to include in the exception if it is thrown.
1649     *
1650     * @see #checkPermission(String, int, int)
1651     */
1652    public abstract void enforcePermission(
1653            String permission, int pid, int uid, String message);
1654
1655    /**
1656     * If the calling process of an IPC you are handling has not been
1657     * granted a particular permission, throw a {@link
1658     * SecurityException}.  This is basically the same as calling
1659     * {@link #enforcePermission(String, int, int, String)} with the
1660     * pid and uid returned by {@link android.os.Binder#getCallingPid}
1661     * and {@link android.os.Binder#getCallingUid}.  One important
1662     * difference is that if you are not currently processing an IPC,
1663     * this function will always throw the SecurityException.  This is
1664     * done to protect against accidentally leaking permissions; you
1665     * can use {@link #enforceCallingOrSelfPermission} to avoid this
1666     * protection.
1667     *
1668     * @param permission The name of the permission being checked.
1669     * @param message A message to include in the exception if it is thrown.
1670     *
1671     * @see #checkCallingPermission(String)
1672     */
1673    public abstract void enforceCallingPermission(
1674            String permission, String message);
1675
1676    /**
1677     * If neither you nor the calling process of an IPC you are
1678     * handling has been granted a particular permission, throw a
1679     * {@link SecurityException}.  This is the same as {@link
1680     * #enforceCallingPermission}, except it grants your own
1681     * permissions if you are not currently processing an IPC.  Use
1682     * with care!
1683     *
1684     * @param permission The name of the permission being checked.
1685     * @param message A message to include in the exception if it is thrown.
1686     *
1687     * @see #checkCallingOrSelfPermission(String)
1688     */
1689    public abstract void enforceCallingOrSelfPermission(
1690            String permission, String message);
1691
1692    /**
1693     * Grant permission to access a specific Uri to another package, regardless
1694     * of whether that package has general permission to access the Uri's
1695     * content provider.  This can be used to grant specific, temporary
1696     * permissions, typically in response to user interaction (such as the
1697     * user opening an attachment that you would like someone else to
1698     * display).
1699     *
1700     * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
1701     * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
1702     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
1703     * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
1704     * start an activity instead of this function directly.  If you use this
1705     * function directly, you should be sure to call
1706     * {@link #revokeUriPermission} when the target should no longer be allowed
1707     * to access it.
1708     *
1709     * <p>To succeed, the content provider owning the Uri must have set the
1710     * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
1711     * grantUriPermissions} attribute in its manifest or included the
1712     * {@link android.R.styleable#AndroidManifestGrantUriPermission
1713     * &lt;grant-uri-permissions&gt;} tag.
1714     *
1715     * @param toPackage The package you would like to allow to access the Uri.
1716     * @param uri The Uri you would like to grant access to.
1717     * @param modeFlags The desired access modes.  Any combination of
1718     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
1719     * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
1720     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
1721     * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
1722     *
1723     * @see #revokeUriPermission
1724     */
1725    public abstract void grantUriPermission(String toPackage, Uri uri,
1726            int modeFlags);
1727
1728    /**
1729     * Remove all permissions to access a particular content provider Uri
1730     * that were previously added with {@link #grantUriPermission}.  The given
1731     * Uri will match all previously granted Uris that are the same or a
1732     * sub-path of the given Uri.  That is, revoking "content://foo/one" will
1733     * revoke both "content://foo/target" and "content://foo/target/sub", but not
1734     * "content://foo".
1735     *
1736     * @param uri The Uri you would like to revoke access to.
1737     * @param modeFlags The desired access modes.  Any combination of
1738     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
1739     * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
1740     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
1741     * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
1742     *
1743     * @see #grantUriPermission
1744     */
1745    public abstract void revokeUriPermission(Uri uri, int modeFlags);
1746
1747    /**
1748     * Determine whether a particular process and user ID has been granted
1749     * permission to access a specific URI.  This only checks for permissions
1750     * that have been explicitly granted -- if the given process/uid has
1751     * more general access to the URI's content provider then this check will
1752     * always fail.
1753     *
1754     * @param uri The uri that is being checked.
1755     * @param pid The process ID being checked against.  Must be &gt; 0.
1756     * @param uid The user ID being checked against.  A uid of 0 is the root
1757     * user, which will pass every permission check.
1758     * @param modeFlags The type of access to grant.  May be one or both of
1759     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
1760     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
1761     *
1762     * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the given
1763     * pid/uid is allowed to access that uri, or
1764     * {@link PackageManager#PERMISSION_DENIED} if it is not.
1765     *
1766     * @see #checkCallingUriPermission
1767     */
1768    public abstract int checkUriPermission(Uri uri, int pid, int uid, int modeFlags);
1769
1770    /**
1771     * Determine whether the calling process and user ID has been
1772     * granted permission to access a specific URI.  This is basically
1773     * the same as calling {@link #checkUriPermission(Uri, int, int,
1774     * int)} with the pid and uid returned by {@link
1775     * android.os.Binder#getCallingPid} and {@link
1776     * android.os.Binder#getCallingUid}.  One important difference is
1777     * that if you are not currently processing an IPC, this function
1778     * will always fail.
1779     *
1780     * @param uri The uri that is being checked.
1781     * @param modeFlags The type of access to grant.  May be one or both of
1782     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
1783     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
1784     *
1785     * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
1786     * is allowed to access that uri, or
1787     * {@link PackageManager#PERMISSION_DENIED} if it is not.
1788     *
1789     * @see #checkUriPermission(Uri, int, int, int)
1790     */
1791    public abstract int checkCallingUriPermission(Uri uri, int modeFlags);
1792
1793    /**
1794     * Determine whether the calling process of an IPC <em>or you</em> has been granted
1795     * permission to access a specific URI.  This is the same as
1796     * {@link #checkCallingUriPermission}, except it grants your own permissions
1797     * if you are not currently processing an IPC.  Use with care!
1798     *
1799     * @param uri The uri that is being checked.
1800     * @param modeFlags The type of access to grant.  May be one or both of
1801     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
1802     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
1803     *
1804     * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
1805     * is allowed to access that uri, or
1806     * {@link PackageManager#PERMISSION_DENIED} if it is not.
1807     *
1808     * @see #checkCallingUriPermission
1809     */
1810    public abstract int checkCallingOrSelfUriPermission(Uri uri, int modeFlags);
1811
1812    /**
1813     * Check both a Uri and normal permission.  This allows you to perform
1814     * both {@link #checkPermission} and {@link #checkUriPermission} in one
1815     * call.
1816     *
1817     * @param uri The Uri whose permission is to be checked, or null to not
1818     * do this check.
1819     * @param readPermission The permission that provides overall read access,
1820     * or null to not do this check.
1821     * @param writePermission The permission that provides overall write
1822     * acess, or null to not do this check.
1823     * @param pid The process ID being checked against.  Must be &gt; 0.
1824     * @param uid The user ID being checked against.  A uid of 0 is the root
1825     * user, which will pass every permission check.
1826     * @param modeFlags The type of access to grant.  May be one or both of
1827     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
1828     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
1829     *
1830     * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
1831     * is allowed to access that uri or holds one of the given permissions, or
1832     * {@link PackageManager#PERMISSION_DENIED} if it is not.
1833     */
1834    public abstract int checkUriPermission(Uri uri, String readPermission,
1835            String writePermission, int pid, int uid, int modeFlags);
1836
1837    /**
1838     * If a particular process and user ID has not been granted
1839     * permission to access a specific URI, throw {@link
1840     * SecurityException}.  This only checks for permissions that have
1841     * been explicitly granted -- if the given process/uid has more
1842     * general access to the URI's content provider then this check
1843     * will always fail.
1844     *
1845     * @param uri The uri that is being checked.
1846     * @param pid The process ID being checked against.  Must be &gt; 0.
1847     * @param uid The user ID being checked against.  A uid of 0 is the root
1848     * user, which will pass every permission check.
1849     * @param modeFlags The type of access to grant.  May be one or both of
1850     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
1851     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
1852     * @param message A message to include in the exception if it is thrown.
1853     *
1854     * @see #checkUriPermission(Uri, int, int, int)
1855     */
1856    public abstract void enforceUriPermission(
1857            Uri uri, int pid, int uid, int modeFlags, String message);
1858
1859    /**
1860     * If the calling process and user ID has not been granted
1861     * permission to access a specific URI, throw {@link
1862     * SecurityException}.  This is basically the same as calling
1863     * {@link #enforceUriPermission(Uri, int, int, int, String)} with
1864     * the pid and uid returned by {@link
1865     * android.os.Binder#getCallingPid} and {@link
1866     * android.os.Binder#getCallingUid}.  One important difference is
1867     * that if you are not currently processing an IPC, this function
1868     * will always throw a SecurityException.
1869     *
1870     * @param uri The uri that is being checked.
1871     * @param modeFlags The type of access to grant.  May be one or both of
1872     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
1873     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
1874     * @param message A message to include in the exception if it is thrown.
1875     *
1876     * @see #checkCallingUriPermission(Uri, int)
1877     */
1878    public abstract void enforceCallingUriPermission(
1879            Uri uri, int modeFlags, String message);
1880
1881    /**
1882     * If the calling process of an IPC <em>or you</em> has not been
1883     * granted permission to access a specific URI, throw {@link
1884     * SecurityException}.  This is the same as {@link
1885     * #enforceCallingUriPermission}, except it grants your own
1886     * permissions if you are not currently processing an IPC.  Use
1887     * with care!
1888     *
1889     * @param uri The uri that is being checked.
1890     * @param modeFlags The type of access to grant.  May be one or both of
1891     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
1892     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
1893     * @param message A message to include in the exception if it is thrown.
1894     *
1895     * @see #checkCallingOrSelfUriPermission(Uri, int)
1896     */
1897    public abstract void enforceCallingOrSelfUriPermission(
1898            Uri uri, int modeFlags, String message);
1899
1900    /**
1901     * Enforce both a Uri and normal permission.  This allows you to perform
1902     * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
1903     * call.
1904     *
1905     * @param uri The Uri whose permission is to be checked, or null to not
1906     * do this check.
1907     * @param readPermission The permission that provides overall read access,
1908     * or null to not do this check.
1909     * @param writePermission The permission that provides overall write
1910     * acess, or null to not do this check.
1911     * @param pid The process ID being checked against.  Must be &gt; 0.
1912     * @param uid The user ID being checked against.  A uid of 0 is the root
1913     * user, which will pass every permission check.
1914     * @param modeFlags The type of access to grant.  May be one or both of
1915     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
1916     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
1917     * @param message A message to include in the exception if it is thrown.
1918     *
1919     * @see #checkUriPermission(Uri, String, String, int, int, int)
1920     */
1921    public abstract void enforceUriPermission(
1922            Uri uri, String readPermission, String writePermission,
1923            int pid, int uid, int modeFlags, String message);
1924
1925    /**
1926     * Flag for use with {@link #createPackageContext}: include the application
1927     * code with the context.  This means loading code into the caller's
1928     * process, so that {@link #getClassLoader()} can be used to instantiate
1929     * the application's classes.  Setting this flags imposes security
1930     * restrictions on what application context you can access; if the
1931     * requested application can not be safely loaded into your process,
1932     * java.lang.SecurityException will be thrown.  If this flag is not set,
1933     * there will be no restrictions on the packages that can be loaded,
1934     * but {@link #getClassLoader} will always return the default system
1935     * class loader.
1936     */
1937    public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
1938
1939    /**
1940     * Flag for use with {@link #createPackageContext}: ignore any security
1941     * restrictions on the Context being requested, allowing it to always
1942     * be loaded.  For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
1943     * to be loaded into a process even when it isn't safe to do so.  Use
1944     * with extreme care!
1945     */
1946    public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
1947
1948    /**
1949     * Flag for use with {@link #createPackageContext}: a restricted context may
1950     * disable specific features. For instance, a View associated with a restricted
1951     * context would ignore particular XML attributes.
1952     */
1953    public static final int CONTEXT_RESTRICTED = 0x00000004;
1954
1955    /**
1956     * Return a new Context object for the given application name.  This
1957     * Context is the same as what the named application gets when it is
1958     * launched, containing the same resources and class loader.  Each call to
1959     * this method returns a new instance of a Context object; Context objects
1960     * are not shared, however they share common state (Resources, ClassLoader,
1961     * etc) so the Context instance itself is fairly lightweight.
1962     *
1963     * <p>Throws {@link PackageManager.NameNotFoundException} if there is no
1964     * application with the given package name.
1965     *
1966     * <p>Throws {@link java.lang.SecurityException} if the Context requested
1967     * can not be loaded into the caller's process for security reasons (see
1968     * {@link #CONTEXT_INCLUDE_CODE} for more information}.
1969     *
1970     * @param packageName Name of the application's package.
1971     * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
1972     *              or {@link #CONTEXT_IGNORE_SECURITY}.
1973     *
1974     * @return A Context for the application.
1975     *
1976     * @throws java.lang.SecurityException
1977     * @throws PackageManager.NameNotFoundException if there is no application with
1978     * the given package name
1979     */
1980    public abstract Context createPackageContext(String packageName,
1981            int flags) throws PackageManager.NameNotFoundException;
1982
1983    /**
1984     * Indicates whether this Context is restricted.
1985     *
1986     * @return True if this Context is restricted, false otherwise.
1987     *
1988     * @see #CONTEXT_RESTRICTED
1989     */
1990    public boolean isRestricted() {
1991        return false;
1992    }
1993}
1994