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