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