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