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