• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.content;
18 
19 import android.annotation.AttrRes;
20 import android.annotation.CheckResult;
21 import android.annotation.ColorInt;
22 import android.annotation.ColorRes;
23 import android.annotation.DrawableRes;
24 import android.annotation.IntDef;
25 import android.annotation.NonNull;
26 import android.annotation.Nullable;
27 import android.annotation.RequiresPermission;
28 import android.annotation.StringDef;
29 import android.annotation.StringRes;
30 import android.annotation.StyleRes;
31 import android.annotation.StyleableRes;
32 import android.annotation.SystemApi;
33 import android.annotation.TestApi;
34 import android.annotation.UserIdInt;
35 import android.app.IApplicationThread;
36 import android.app.IServiceConnection;
37 import android.app.VrManager;
38 import android.content.pm.ApplicationInfo;
39 import android.content.pm.PackageManager;
40 import android.content.res.AssetManager;
41 import android.content.res.ColorStateList;
42 import android.content.res.Configuration;
43 import android.content.res.Resources;
44 import android.content.res.TypedArray;
45 import android.database.DatabaseErrorHandler;
46 import android.database.sqlite.SQLiteDatabase;
47 import android.database.sqlite.SQLiteDatabase.CursorFactory;
48 import android.graphics.Bitmap;
49 import android.graphics.drawable.Drawable;
50 import android.net.Uri;
51 import android.os.Bundle;
52 import android.os.Environment;
53 import android.os.Handler;
54 import android.os.IBinder;
55 import android.os.Looper;
56 import android.os.StatFs;
57 import android.os.UserHandle;
58 import android.os.UserManager;
59 import android.os.storage.StorageManager;
60 import android.provider.MediaStore;
61 import android.util.AttributeSet;
62 import android.view.Display;
63 import android.view.DisplayAdjustments;
64 import android.view.View;
65 import android.view.ViewDebug;
66 import android.view.WindowManager;
67 import android.view.autofill.AutofillManager.AutofillClient;
68 import android.view.textclassifier.TextClassificationManager;
69 
70 import java.io.File;
71 import java.io.FileInputStream;
72 import java.io.FileNotFoundException;
73 import java.io.FileOutputStream;
74 import java.io.IOException;
75 import java.io.InputStream;
76 import java.lang.annotation.Retention;
77 import java.lang.annotation.RetentionPolicy;
78 
79 /**
80  * Interface to global information about an application environment.  This is
81  * an abstract class whose implementation is provided by
82  * the Android system.  It
83  * allows access to application-specific resources and classes, as well as
84  * up-calls for application-level operations such as launching activities,
85  * broadcasting and receiving intents, etc.
86  */
87 public abstract class Context {
88     /** @hide */
89     @IntDef(flag = true, prefix = { "MODE_" }, value = {
90             MODE_PRIVATE,
91             MODE_WORLD_READABLE,
92             MODE_WORLD_WRITEABLE,
93             MODE_APPEND,
94     })
95     @Retention(RetentionPolicy.SOURCE)
96     public @interface FileMode {}
97 
98     /** @hide */
99     @IntDef(flag = true, prefix = { "MODE_" }, value = {
100             MODE_PRIVATE,
101             MODE_WORLD_READABLE,
102             MODE_WORLD_WRITEABLE,
103             MODE_MULTI_PROCESS,
104     })
105     @Retention(RetentionPolicy.SOURCE)
106     public @interface PreferencesMode {}
107 
108     /** @hide */
109     @IntDef(flag = true, prefix = { "MODE_" }, value = {
110             MODE_PRIVATE,
111             MODE_WORLD_READABLE,
112             MODE_WORLD_WRITEABLE,
113             MODE_ENABLE_WRITE_AHEAD_LOGGING,
114             MODE_NO_LOCALIZED_COLLATORS,
115     })
116     @Retention(RetentionPolicy.SOURCE)
117     public @interface DatabaseMode {}
118 
119     /**
120      * File creation mode: the default mode, where the created file can only
121      * be accessed by the calling application (or all applications sharing the
122      * same user ID).
123      */
124     public static final int MODE_PRIVATE = 0x0000;
125 
126     /**
127      * File creation mode: allow all other applications to have read access to
128      * the created file.
129      * <p>
130      * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
131      * mode throws a {@link SecurityException}.
132      *
133      * @deprecated Creating world-readable files is very dangerous, and likely
134      *             to cause security holes in applications. It is strongly
135      *             discouraged; instead, applications should use more formal
136      *             mechanism for interactions such as {@link ContentProvider},
137      *             {@link BroadcastReceiver}, and {@link android.app.Service}.
138      *             There are no guarantees that this access mode will remain on
139      *             a file, such as when it goes through a backup and restore.
140      * @see android.support.v4.content.FileProvider
141      * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
142      */
143     @Deprecated
144     public static final int MODE_WORLD_READABLE = 0x0001;
145 
146     /**
147      * File creation mode: allow all other applications to have write access to
148      * the created file.
149      * <p>
150      * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
151      * mode will throw a {@link SecurityException}.
152      *
153      * @deprecated Creating world-writable files is very dangerous, and likely
154      *             to cause security holes in applications. It is strongly
155      *             discouraged; instead, applications should use more formal
156      *             mechanism for interactions such as {@link ContentProvider},
157      *             {@link BroadcastReceiver}, and {@link android.app.Service}.
158      *             There are no guarantees that this access mode will remain on
159      *             a file, such as when it goes through a backup and restore.
160      * @see android.support.v4.content.FileProvider
161      * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
162      */
163     @Deprecated
164     public static final int MODE_WORLD_WRITEABLE = 0x0002;
165 
166     /**
167      * File creation mode: for use with {@link #openFileOutput}, if the file
168      * already exists then write data to the end of the existing file
169      * instead of erasing it.
170      * @see #openFileOutput
171      */
172     public static final int MODE_APPEND = 0x8000;
173 
174     /**
175      * SharedPreference loading flag: when set, the file on disk will
176      * be checked for modification even if the shared preferences
177      * instance is already loaded in this process.  This behavior is
178      * sometimes desired in cases where the application has multiple
179      * processes, all writing to the same SharedPreferences file.
180      * Generally there are better forms of communication between
181      * processes, though.
182      *
183      * <p>This was the legacy (but undocumented) behavior in and
184      * before Gingerbread (Android 2.3) and this flag is implied when
185      * targetting such releases.  For applications targetting SDK
186      * versions <em>greater than</em> Android 2.3, this flag must be
187      * explicitly set if desired.
188      *
189      * @see #getSharedPreferences
190      *
191      * @deprecated MODE_MULTI_PROCESS does not work reliably in
192      * some versions of Android, and furthermore does not provide any
193      * mechanism for reconciling concurrent modifications across
194      * processes.  Applications should not attempt to use it.  Instead,
195      * they should use an explicit cross-process data management
196      * approach such as {@link android.content.ContentProvider ContentProvider}.
197      */
198     @Deprecated
199     public static final int MODE_MULTI_PROCESS = 0x0004;
200 
201     /**
202      * Database open flag: when set, the database is opened with write-ahead
203      * logging enabled by default.
204      *
205      * @see #openOrCreateDatabase(String, int, CursorFactory)
206      * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
207      * @see SQLiteDatabase#enableWriteAheadLogging
208      */
209     public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
210 
211     /**
212      * Database open flag: when set, the database is opened without support for
213      * localized collators.
214      *
215      * @see #openOrCreateDatabase(String, int, CursorFactory)
216      * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
217      * @see SQLiteDatabase#NO_LOCALIZED_COLLATORS
218      */
219     public static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010;
220 
221     /** @hide */
222     @IntDef(flag = true,
223             value = {
224                 BIND_AUTO_CREATE,
225                 BIND_DEBUG_UNBIND,
226                 BIND_NOT_FOREGROUND,
227                 BIND_ABOVE_CLIENT,
228                 BIND_ALLOW_OOM_MANAGEMENT,
229                 BIND_WAIVE_PRIORITY,
230                 BIND_IMPORTANT,
231                 BIND_ADJUST_WITH_ACTIVITY
232             })
233     @Retention(RetentionPolicy.SOURCE)
234     public @interface BindServiceFlags {}
235 
236     /**
237      * Flag for {@link #bindService}: automatically create the service as long
238      * as the binding exists.  Note that while this will create the service,
239      * its {@link android.app.Service#onStartCommand}
240      * method will still only be called due to an
241      * explicit call to {@link #startService}.  Even without that, though,
242      * this still provides you with access to the service object while the
243      * service is created.
244      *
245      * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
246      * not supplying this flag would also impact how important the system
247      * consider's the target service's process to be.  When set, the only way
248      * for it to be raised was by binding from a service in which case it will
249      * only be important when that activity is in the foreground.  Now to
250      * achieve this behavior you must explicitly supply the new flag
251      * {@link #BIND_ADJUST_WITH_ACTIVITY}.  For compatibility, old applications
252      * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
253      * the flags {@link #BIND_WAIVE_PRIORITY} and
254      * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
255      * the same result.
256      */
257     public static final int BIND_AUTO_CREATE = 0x0001;
258 
259     /**
260      * Flag for {@link #bindService}: include debugging help for mismatched
261      * calls to unbind.  When this flag is set, the callstack of the following
262      * {@link #unbindService} call is retained, to be printed if a later
263      * incorrect unbind call is made.  Note that doing this requires retaining
264      * information about the binding that was made for the lifetime of the app,
265      * resulting in a leak -- this should only be used for debugging.
266      */
267     public static final int BIND_DEBUG_UNBIND = 0x0002;
268 
269     /**
270      * Flag for {@link #bindService}: don't allow this binding to raise
271      * the target service's process to the foreground scheduling priority.
272      * It will still be raised to at least the same memory priority
273      * as the client (so that its process will not be killable in any
274      * situation where the client is not killable), but for CPU scheduling
275      * purposes it may be left in the background.  This only has an impact
276      * in the situation where the binding client is a foreground process
277      * and the target service is in a background process.
278      */
279     public static final int BIND_NOT_FOREGROUND = 0x0004;
280 
281     /**
282      * Flag for {@link #bindService}: indicates that the client application
283      * binding to this service considers the service to be more important than
284      * the app itself.  When set, the platform will try to have the out of
285      * memory killer kill the app before it kills the service it is bound to, though
286      * this is not guaranteed to be the case.
287      */
288     public static final int BIND_ABOVE_CLIENT = 0x0008;
289 
290     /**
291      * Flag for {@link #bindService}: allow the process hosting the bound
292      * service to go through its normal memory management.  It will be
293      * treated more like a running service, allowing the system to
294      * (temporarily) expunge the process if low on memory or for some other
295      * whim it may have, and being more aggressive about making it a candidate
296      * to be killed (and restarted) if running for a long time.
297      */
298     public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
299 
300     /**
301      * Flag for {@link #bindService}: don't impact the scheduling or
302      * memory management priority of the target service's hosting process.
303      * Allows the service's process to be managed on the background LRU list
304      * just like a regular application process in the background.
305      */
306     public static final int BIND_WAIVE_PRIORITY = 0x0020;
307 
308     /**
309      * Flag for {@link #bindService}: this service is very important to
310      * the client, so should be brought to the foreground process level
311      * when the client is.  Normally a process can only be raised to the
312      * visibility level by a client, even if that client is in the foreground.
313      */
314     public static final int BIND_IMPORTANT = 0x0040;
315 
316     /**
317      * Flag for {@link #bindService}: If binding from an activity, allow the
318      * target service's process importance to be raised based on whether the
319      * activity is visible to the user, regardless whether another flag is
320      * used to reduce the amount that the client process's overall importance
321      * is used to impact it.
322      */
323     public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
324 
325     /**
326      * @hide Flag for {@link #bindService}: like {@link #BIND_NOT_FOREGROUND}, but puts it
327      * up in to the important background state (instead of transient).
328      */
329     public static final int BIND_IMPORTANT_BACKGROUND = 0x00800000;
330 
331     /**
332      * @hide Flag for {@link #bindService}: allows application hosting service to manage whitelists
333      * such as temporary allowing a {@code PendingIntent} to bypass Power Save mode.
334      */
335     public static final int BIND_ALLOW_WHITELIST_MANAGEMENT = 0x01000000;
336 
337     /**
338      * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
339      * but only applies while the device is awake.
340      */
341     public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
342 
343     /**
344      * @hide Flag for {@link #bindService}: For only the case where the binding
345      * is coming from the system, set the process state to FOREGROUND_SERVICE
346      * instead of the normal maximum of IMPORTANT_FOREGROUND.  That is, this is
347      * saying that the process shouldn't participate in the normal power reduction
348      * modes (removing network access etc).
349      */
350     public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
351 
352     /**
353      * @hide Flag for {@link #bindService}: Treat the binding as hosting
354      * an activity, an unbinding as the activity going in the background.
355      * That is, when unbinding, the process when empty will go on the activity
356      * LRU list instead of the regular one, keeping it around more aggressively
357      * than it otherwise would be.  This is intended for use with IMEs to try
358      * to keep IME processes around for faster keyboard switching.
359      */
360     public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
361 
362     /**
363      * @hide An idea that is not yet implemented.
364      * Flag for {@link #bindService}: If binding from an activity, consider
365      * this service to be visible like the binding activity is.  That is,
366      * it will be treated as something more important to keep around than
367      * invisible background activities.  This will impact the number of
368      * recent activities the user can switch between without having them
369      * restart.  There is no guarantee this will be respected, as the system
370      * tries to balance such requests from one app vs. the importantance of
371      * keeping other apps around.
372      */
373     public static final int BIND_VISIBLE = 0x10000000;
374 
375     /**
376      * @hide
377      * Flag for {@link #bindService}: Consider this binding to be causing the target
378      * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
379      * away.
380      */
381     public static final int BIND_SHOWING_UI = 0x20000000;
382 
383     /**
384      * Flag for {@link #bindService}: Don't consider the bound service to be
385      * visible, even if the caller is visible.
386      * @hide
387      */
388     public static final int BIND_NOT_VISIBLE = 0x40000000;
389 
390     /**
391      * Flag for {@link #bindService}: The service being bound is an
392      * {@link android.R.attr#isolatedProcess isolated},
393      * {@link android.R.attr#externalService external} service.  This binds the service into the
394      * calling application's package, rather than the package in which the service is declared.
395      * <p>
396      * When using this flag, the code for the service being bound will execute under the calling
397      * application's package name and user ID.  Because the service must be an isolated process,
398      * it will not have direct access to the application's data, though.
399      *
400      * The purpose of this flag is to allow applications to provide services that are attributed
401      * to the app using the service, rather than the application providing the service.
402      * </p>
403      */
404     public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
405 
406     /** @hide */
407     @IntDef(flag = true,
408             value = {
409                 RECEIVER_VISIBLE_TO_INSTANT_APPS
410             })
411     @Retention(RetentionPolicy.SOURCE)
412     public @interface RegisterReceiverFlags {}
413 
414     /**
415      * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from Instant Apps.
416      */
417     public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 0x1;
418 
419     /**
420      * Returns an AssetManager instance for the application's package.
421      * <p>
422      * <strong>Note:</strong> Implementations of this method should return
423      * an AssetManager instance that is consistent with the Resources instance
424      * returned by {@link #getResources()}. For example, they should share the
425      * same {@link Configuration} object.
426      *
427      * @return an AssetManager instance for the application's package
428      * @see #getResources()
429      */
getAssets()430     public abstract AssetManager getAssets();
431 
432     /**
433      * Returns a Resources instance for the application's package.
434      * <p>
435      * <strong>Note:</strong> Implementations of this method should return
436      * a Resources instance that is consistent with the AssetManager instance
437      * returned by {@link #getAssets()}. For example, they should share the
438      * same {@link Configuration} object.
439      *
440      * @return a Resources instance for the application's package
441      * @see #getAssets()
442      */
getResources()443     public abstract Resources getResources();
444 
445     /** Return PackageManager instance to find global package information. */
getPackageManager()446     public abstract PackageManager getPackageManager();
447 
448     /** Return a ContentResolver instance for your application's package. */
getContentResolver()449     public abstract ContentResolver getContentResolver();
450 
451     /**
452      * Return the Looper for the main thread of the current process.  This is
453      * the thread used to dispatch calls to application components (activities,
454      * services, etc).
455      * <p>
456      * By definition, this method returns the same result as would be obtained
457      * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
458      * </p>
459      *
460      * @return The main looper.
461      */
getMainLooper()462     public abstract Looper getMainLooper();
463 
464     /**
465      * Return the context of the single, global Application object of the
466      * current process.  This generally should only be used if you need a
467      * Context whose lifecycle is separate from the current context, that is
468      * tied to the lifetime of the process rather than the current component.
469      *
470      * <p>Consider for example how this interacts with
471      * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
472      * <ul>
473      * <li> <p>If used from an Activity context, the receiver is being registered
474      * within that activity.  This means that you are expected to unregister
475      * before the activity is done being destroyed; in fact if you do not do
476      * so, the framework will clean up your leaked registration as it removes
477      * the activity and log an error.  Thus, if you use the Activity context
478      * to register a receiver that is static (global to the process, not
479      * associated with an Activity instance) then that registration will be
480      * removed on you at whatever point the activity you used is destroyed.
481      * <li> <p>If used from the Context returned here, the receiver is being
482      * registered with the global state associated with your application.  Thus
483      * it will never be unregistered for you.  This is necessary if the receiver
484      * is associated with static data, not a particular component.  However
485      * using the ApplicationContext elsewhere can easily lead to serious leaks
486      * if you forget to unregister, unbind, etc.
487      * </ul>
488      */
getApplicationContext()489     public abstract Context getApplicationContext();
490 
491     /** Non-activity related autofill ids are unique in the app */
492     private static int sLastAutofillId = View.NO_ID;
493 
494     /**
495      * Gets the next autofill ID.
496      *
497      * <p>All IDs will be smaller or the same as {@link View#LAST_APP_AUTOFILL_ID}. All IDs
498      * returned will be unique.
499      *
500      * @return A ID that is unique in the process
501      *
502      * {@hide}
503      */
getNextAutofillId()504     public int getNextAutofillId() {
505         if (sLastAutofillId == View.LAST_APP_AUTOFILL_ID - 1) {
506             sLastAutofillId = View.NO_ID;
507         }
508 
509         sLastAutofillId++;
510 
511         return sLastAutofillId;
512     }
513 
514     /**
515      * Add a new {@link ComponentCallbacks} to the base application of the
516      * Context, which will be called at the same times as the ComponentCallbacks
517      * methods of activities and other components are called.  Note that you
518      * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
519      * appropriate in the future; this will not be removed for you.
520      *
521      * @param callback The interface to call.  This can be either a
522      * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
523      */
registerComponentCallbacks(ComponentCallbacks callback)524     public void registerComponentCallbacks(ComponentCallbacks callback) {
525         getApplicationContext().registerComponentCallbacks(callback);
526     }
527 
528     /**
529      * Remove a {@link ComponentCallbacks} object that was previously registered
530      * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
531      */
unregisterComponentCallbacks(ComponentCallbacks callback)532     public void unregisterComponentCallbacks(ComponentCallbacks callback) {
533         getApplicationContext().unregisterComponentCallbacks(callback);
534     }
535 
536     /**
537      * Return a localized, styled CharSequence from the application's package's
538      * default string table.
539      *
540      * @param resId Resource id for the CharSequence text
541      */
getText(@tringRes int resId)542     public final CharSequence getText(@StringRes int resId) {
543         return getResources().getText(resId);
544     }
545 
546     /**
547      * Returns a localized string from the application's package's
548      * default string table.
549      *
550      * @param resId Resource id for the string
551      * @return The string data associated with the resource, stripped of styled
552      *         text information.
553      */
554     @NonNull
getString(@tringRes int resId)555     public final String getString(@StringRes int resId) {
556         return getResources().getString(resId);
557     }
558 
559     /**
560      * Returns a localized formatted string from the application's package's
561      * default string table, substituting the format arguments as defined in
562      * {@link java.util.Formatter} and {@link java.lang.String#format}.
563      *
564      * @param resId Resource id for the format string
565      * @param formatArgs The format arguments that will be used for
566      *                   substitution.
567      * @return The string data associated with the resource, formatted and
568      *         stripped of styled text information.
569      */
570     @NonNull
getString(@tringRes int resId, Object... formatArgs)571     public final String getString(@StringRes int resId, Object... formatArgs) {
572         return getResources().getString(resId, formatArgs);
573     }
574 
575     /**
576      * Returns a color associated with a particular resource ID and styled for
577      * the current theme.
578      *
579      * @param id The desired resource identifier, as generated by the aapt
580      *           tool. This integer encodes the package, type, and resource
581      *           entry. The value 0 is an invalid identifier.
582      * @return A single color value in the form 0xAARRGGBB.
583      * @throws android.content.res.Resources.NotFoundException if the given ID
584      *         does not exist.
585      */
586     @ColorInt
getColor(@olorRes int id)587     public final int getColor(@ColorRes int id) {
588         return getResources().getColor(id, getTheme());
589     }
590 
591     /**
592      * Returns a drawable object associated with a particular resource ID and
593      * styled for the current theme.
594      *
595      * @param id The desired resource identifier, as generated by the aapt
596      *           tool. This integer encodes the package, type, and resource
597      *           entry. The value 0 is an invalid identifier.
598      * @return An object that can be used to draw this resource, or
599      *         {@code null} if the resource could not be resolved.
600      * @throws android.content.res.Resources.NotFoundException if the given ID
601      *         does not exist.
602      */
603     @Nullable
getDrawable(@rawableRes int id)604     public final Drawable getDrawable(@DrawableRes int id) {
605         return getResources().getDrawable(id, getTheme());
606     }
607 
608     /**
609      * Returns a color state list associated with a particular resource ID and
610      * styled for the current theme.
611      *
612      * @param id The desired resource identifier, as generated by the aapt
613      *           tool. This integer encodes the package, type, and resource
614      *           entry. The value 0 is an invalid identifier.
615      * @return A color state list, or {@code null} if the resource could not be
616      *         resolved.
617      * @throws android.content.res.Resources.NotFoundException if the given ID
618      *         does not exist.
619      */
620     @Nullable
getColorStateList(@olorRes int id)621     public final ColorStateList getColorStateList(@ColorRes int id) {
622         return getResources().getColorStateList(id, getTheme());
623     }
624 
625      /**
626      * Set the base theme for this context.  Note that this should be called
627      * before any views are instantiated in the Context (for example before
628      * calling {@link android.app.Activity#setContentView} or
629      * {@link android.view.LayoutInflater#inflate}).
630      *
631      * @param resid The style resource describing the theme.
632      */
setTheme(@tyleRes int resid)633     public abstract void setTheme(@StyleRes int resid);
634 
635     /** @hide Needed for some internal implementation...  not public because
636      * you can't assume this actually means anything. */
getThemeResId()637     public int getThemeResId() {
638         return 0;
639     }
640 
641     /**
642      * Return the Theme object associated with this Context.
643      */
644     @ViewDebug.ExportedProperty(deepExport = true)
getTheme()645     public abstract Resources.Theme getTheme();
646 
647     /**
648      * Retrieve styled attribute information in this Context's theme.  See
649      * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
650      * for more information.
651      *
652      * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
653      */
obtainStyledAttributes(@tyleableRes int[] attrs)654     public final TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
655         return getTheme().obtainStyledAttributes(attrs);
656     }
657 
658     /**
659      * Retrieve styled attribute information in this Context's theme.  See
660      * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
661      * for more information.
662      *
663      * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
664      */
obtainStyledAttributes( @tyleRes int resid, @StyleableRes int[] attrs)665     public final TypedArray obtainStyledAttributes(
666             @StyleRes int resid, @StyleableRes int[] attrs) throws Resources.NotFoundException {
667         return getTheme().obtainStyledAttributes(resid, attrs);
668     }
669 
670     /**
671      * Retrieve styled attribute information in this Context's theme.  See
672      * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
673      * for more information.
674      *
675      * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
676      */
obtainStyledAttributes( AttributeSet set, @StyleableRes int[] attrs)677     public final TypedArray obtainStyledAttributes(
678             AttributeSet set, @StyleableRes int[] attrs) {
679         return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
680     }
681 
682     /**
683      * Retrieve styled attribute information in this Context's theme.  See
684      * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
685      * for more information.
686      *
687      * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
688      */
obtainStyledAttributes( AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes)689     public final TypedArray obtainStyledAttributes(
690             AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
691             @StyleRes int defStyleRes) {
692         return getTheme().obtainStyledAttributes(
693             set, attrs, defStyleAttr, defStyleRes);
694     }
695 
696     /**
697      * Return a class loader you can use to retrieve classes in this package.
698      */
getClassLoader()699     public abstract ClassLoader getClassLoader();
700 
701     /** Return the name of this application's package. */
getPackageName()702     public abstract String getPackageName();
703 
704     /** @hide Return the name of the base context this context is derived from. */
getBasePackageName()705     public abstract String getBasePackageName();
706 
707     /** @hide Return the package name that should be used for app ops calls from
708      * this context.  This is the same as {@link #getBasePackageName()} except in
709      * cases where system components are loaded into other app processes, in which
710      * case this will be the name of the primary package in that process (so that app
711      * ops uid verification will work with the name). */
getOpPackageName()712     public abstract String getOpPackageName();
713 
714     /** Return the full application info for this context's package. */
getApplicationInfo()715     public abstract ApplicationInfo getApplicationInfo();
716 
717     /**
718      * Return the full path to this context's primary Android package.
719      * The Android package is a ZIP file which contains the application's
720      * primary resources.
721      *
722      * <p>Note: this is not generally useful for applications, since they should
723      * not be directly accessing the file system.
724      *
725      * @return String Path to the resources.
726      */
getPackageResourcePath()727     public abstract String getPackageResourcePath();
728 
729     /**
730      * Return the full path to this context's primary Android package.
731      * The Android package is a ZIP file which contains application's
732      * primary code and assets.
733      *
734      * <p>Note: this is not generally useful for applications, since they should
735      * not be directly accessing the file system.
736      *
737      * @return String Path to the code and assets.
738      */
getPackageCodePath()739     public abstract String getPackageCodePath();
740 
741     /**
742      * @hide
743      * @deprecated use {@link #getSharedPreferencesPath(String)}
744      */
745     @Deprecated
getSharedPrefsFile(String name)746     public File getSharedPrefsFile(String name) {
747         return getSharedPreferencesPath(name);
748     }
749 
750     /**
751      * Retrieve and hold the contents of the preferences file 'name', returning
752      * a SharedPreferences through which you can retrieve and modify its
753      * values.  Only one instance of the SharedPreferences object is returned
754      * to any callers for the same name, meaning they will see each other's
755      * edits as soon as they are made.
756      *
757      * @param name Desired preferences file. If a preferences file by this name
758      * does not exist, it will be created when you retrieve an
759      * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
760      * @param mode Operating mode.
761      *
762      * @return The single {@link SharedPreferences} instance that can be used
763      *         to retrieve and modify the preference values.
764      *
765      * @see #MODE_PRIVATE
766      */
getSharedPreferences(String name, @PreferencesMode int mode)767     public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
768 
769     /**
770      * Retrieve and hold the contents of the preferences file, returning
771      * a SharedPreferences through which you can retrieve and modify its
772      * values.  Only one instance of the SharedPreferences object is returned
773      * to any callers for the same name, meaning they will see each other's
774      * edits as soon as they are made.
775      *
776      * @param file Desired preferences file. If a preferences file by this name
777      * does not exist, it will be created when you retrieve an
778      * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
779      * @param mode Operating mode.
780      *
781      * @return The single {@link SharedPreferences} instance that can be used
782      *         to retrieve and modify the preference values.
783      *
784      * @see #getSharedPreferencesPath(String)
785      * @see #MODE_PRIVATE
786      * @removed
787      */
getSharedPreferences(File file, @PreferencesMode int mode)788     public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
789 
790     /**
791      * Move an existing shared preferences file from the given source storage
792      * context to this context. This is typically used to migrate data between
793      * storage locations after an upgrade, such as moving to device protected
794      * storage.
795      *
796      * @param sourceContext The source context which contains the existing
797      *            shared preferences to move.
798      * @param name The name of the shared preferences file.
799      * @return {@code true} if the move was successful or if the shared
800      *         preferences didn't exist in the source context, otherwise
801      *         {@code false}.
802      * @see #createDeviceProtectedStorageContext()
803      */
moveSharedPreferencesFrom(Context sourceContext, String name)804     public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
805 
806     /**
807      * Delete an existing shared preferences file.
808      *
809      * @param name The name (unique in the application package) of the shared
810      *            preferences file.
811      * @return {@code true} if the shared preferences file was successfully
812      *         deleted; else {@code false}.
813      * @see #getSharedPreferences(String, int)
814      */
deleteSharedPreferences(String name)815     public abstract boolean deleteSharedPreferences(String name);
816 
817     /** @hide */
reloadSharedPreferences()818     public abstract void reloadSharedPreferences();
819 
820     /**
821      * Open a private file associated with this Context's application package
822      * for reading.
823      *
824      * @param name The name of the file to open; can not contain path
825      *             separators.
826      *
827      * @return The resulting {@link FileInputStream}.
828      *
829      * @see #openFileOutput
830      * @see #fileList
831      * @see #deleteFile
832      * @see java.io.FileInputStream#FileInputStream(String)
833      */
openFileInput(String name)834     public abstract FileInputStream openFileInput(String name)
835         throws FileNotFoundException;
836 
837     /**
838      * Open a private file associated with this Context's application package
839      * for writing. Creates the file if it doesn't already exist.
840      * <p>
841      * No additional permissions are required for the calling app to read or
842      * write the returned file.
843      *
844      * @param name The name of the file to open; can not contain path
845      *            separators.
846      * @param mode Operating mode.
847      * @return The resulting {@link FileOutputStream}.
848      * @see #MODE_APPEND
849      * @see #MODE_PRIVATE
850      * @see #openFileInput
851      * @see #fileList
852      * @see #deleteFile
853      * @see java.io.FileOutputStream#FileOutputStream(String)
854      */
openFileOutput(String name, @FileMode int mode)855     public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
856         throws FileNotFoundException;
857 
858     /**
859      * Delete the given private file associated with this Context's
860      * application package.
861      *
862      * @param name The name of the file to delete; can not contain path
863      *             separators.
864      *
865      * @return {@code true} if the file was successfully deleted; else
866      *         {@code false}.
867      *
868      * @see #openFileInput
869      * @see #openFileOutput
870      * @see #fileList
871      * @see java.io.File#delete()
872      */
deleteFile(String name)873     public abstract boolean deleteFile(String name);
874 
875     /**
876      * Returns the absolute path on the filesystem where a file created with
877      * {@link #openFileOutput} is stored.
878      * <p>
879      * The returned path may change over time if the calling app is moved to an
880      * adopted storage device, so only relative paths should be persisted.
881      *
882      * @param name The name of the file for which you would like to get
883      *          its path.
884      *
885      * @return An absolute path to the given file.
886      *
887      * @see #openFileOutput
888      * @see #getFilesDir
889      * @see #getDir
890      */
getFileStreamPath(String name)891     public abstract File getFileStreamPath(String name);
892 
893     /**
894      * Returns the absolute path on the filesystem where a file created with
895      * {@link #getSharedPreferences(String, int)} is stored.
896      * <p>
897      * The returned path may change over time if the calling app is moved to an
898      * adopted storage device, so only relative paths should be persisted.
899      *
900      * @param name The name of the shared preferences for which you would like
901      *            to get a path.
902      * @return An absolute path to the given file.
903      * @see #getSharedPreferences(String, int)
904      * @removed
905      */
getSharedPreferencesPath(String name)906     public abstract File getSharedPreferencesPath(String name);
907 
908     /**
909      * Returns the absolute path to the directory on the filesystem where all
910      * private files belonging to this app are stored. Apps should not use this
911      * path directly; they should instead use {@link #getFilesDir()},
912      * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
913      * APIs on this class.
914      * <p>
915      * The returned path may change over time if the calling app is moved to an
916      * adopted storage device, so only relative paths should be persisted.
917      * <p>
918      * No additional permissions are required for the calling app to read or
919      * write files under the returned path.
920      *
921      * @see ApplicationInfo#dataDir
922      */
getDataDir()923     public abstract File getDataDir();
924 
925     /**
926      * Returns the absolute path to the directory on the filesystem where files
927      * created with {@link #openFileOutput} are stored.
928      * <p>
929      * The returned path may change over time if the calling app is moved to an
930      * adopted storage device, so only relative paths should be persisted.
931      * <p>
932      * No additional permissions are required for the calling app to read or
933      * write files under the returned path.
934      *
935      * @return The path of the directory holding application files.
936      * @see #openFileOutput
937      * @see #getFileStreamPath
938      * @see #getDir
939      */
getFilesDir()940     public abstract File getFilesDir();
941 
942     /**
943      * Returns the absolute path to the directory on the filesystem similar to
944      * {@link #getFilesDir()}. The difference is that files placed under this
945      * directory will be excluded from automatic backup to remote storage. See
946      * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
947      * of the automatic backup mechanism in Android.
948      * <p>
949      * The returned path may change over time if the calling app is moved to an
950      * adopted storage device, so only relative paths should be persisted.
951      * <p>
952      * No additional permissions are required for the calling app to read or
953      * write files under the returned path.
954      *
955      * @return The path of the directory holding application files that will not
956      *         be automatically backed up to remote storage.
957      * @see #openFileOutput
958      * @see #getFileStreamPath
959      * @see #getDir
960      * @see android.app.backup.BackupAgent
961      */
getNoBackupFilesDir()962     public abstract File getNoBackupFilesDir();
963 
964     /**
965      * Returns the absolute path to the directory on the primary shared/external
966      * storage device where the application can place persistent files it owns.
967      * These files are internal to the applications, and not typically visible
968      * to the user as media.
969      * <p>
970      * This is like {@link #getFilesDir()} in that these files will be deleted
971      * when the application is uninstalled, however there are some important
972      * differences:
973      * <ul>
974      * <li>Shared storage may not always be available, since removable media can
975      * be ejected by the user. Media state can be checked using
976      * {@link Environment#getExternalStorageState(File)}.
977      * <li>There is no security enforced with these files. For example, any
978      * application holding
979      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
980      * these files.
981      * </ul>
982      * <p>
983      * If a shared storage device is emulated (as determined by
984      * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
985      * backed by a private user data partition, which means there is little
986      * benefit to storing data here instead of the private directories returned
987      * by {@link #getFilesDir()}, etc.
988      * <p>
989      * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
990      * are required to read or write to the returned path; it's always
991      * accessible to the calling app. This only applies to paths generated for
992      * package name of the calling application. To access paths belonging to
993      * other packages,
994      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
995      * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
996      * <p>
997      * On devices with multiple users (as described by {@link UserManager}),
998      * each user has their own isolated shared storage. Applications only have
999      * access to the shared storage for the user they're running as.
1000      * <p>
1001      * The returned path may change over time if different shared storage media
1002      * is inserted, so only relative paths should be persisted.
1003      * <p>
1004      * Here is an example of typical code to manipulate a file in an
1005      * application's shared storage:
1006      * </p>
1007      * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1008      * private_file}
1009      * <p>
1010      * If you supply a non-null <var>type</var> to this function, the returned
1011      * file will be a path to a sub-directory of the given type. Though these
1012      * files are not automatically scanned by the media scanner, you can
1013      * explicitly add them to the media database with
1014      * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1015      * MediaScannerConnection.scanFile}. Note that this is not the same as
1016      * {@link android.os.Environment#getExternalStoragePublicDirectory
1017      * Environment.getExternalStoragePublicDirectory()}, which provides
1018      * directories of media shared by all applications. The directories returned
1019      * here are owned by the application, and their contents will be removed
1020      * when the application is uninstalled. Unlike
1021      * {@link android.os.Environment#getExternalStoragePublicDirectory
1022      * Environment.getExternalStoragePublicDirectory()}, the directory returned
1023      * here will be automatically created for you.
1024      * <p>
1025      * Here is an example of typical code to manipulate a picture in an
1026      * application's shared storage and add it to the media database:
1027      * </p>
1028      * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1029      * private_picture}
1030      *
1031      * @param type The type of files directory to return. May be {@code null}
1032      *            for the root of the files directory or one of the following
1033      *            constants for a subdirectory:
1034      *            {@link android.os.Environment#DIRECTORY_MUSIC},
1035      *            {@link android.os.Environment#DIRECTORY_PODCASTS},
1036      *            {@link android.os.Environment#DIRECTORY_RINGTONES},
1037      *            {@link android.os.Environment#DIRECTORY_ALARMS},
1038      *            {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1039      *            {@link android.os.Environment#DIRECTORY_PICTURES}, or
1040      *            {@link android.os.Environment#DIRECTORY_MOVIES}.
1041      * @return the absolute path to application-specific directory. May return
1042      *         {@code null} if shared storage is not currently available.
1043      * @see #getFilesDir
1044      * @see #getExternalFilesDirs(String)
1045      * @see Environment#getExternalStorageState(File)
1046      * @see Environment#isExternalStorageEmulated(File)
1047      * @see Environment#isExternalStorageRemovable(File)
1048      */
1049     @Nullable
getExternalFilesDir(@ullable String type)1050     public abstract File getExternalFilesDir(@Nullable String type);
1051 
1052     /**
1053      * Returns absolute paths to application-specific directories on all
1054      * shared/external storage devices where the application can place
1055      * persistent files it owns. These files are internal to the application,
1056      * and not typically visible to the user as media.
1057      * <p>
1058      * This is like {@link #getFilesDir()} in that these files will be deleted
1059      * when the application is uninstalled, however there are some important
1060      * differences:
1061      * <ul>
1062      * <li>Shared storage may not always be available, since removable media can
1063      * be ejected by the user. Media state can be checked using
1064      * {@link Environment#getExternalStorageState(File)}.
1065      * <li>There is no security enforced with these files. For example, any
1066      * application holding
1067      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1068      * these files.
1069      * </ul>
1070      * <p>
1071      * If a shared storage device is emulated (as determined by
1072      * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1073      * backed by a private user data partition, which means there is little
1074      * benefit to storing data here instead of the private directories returned
1075      * by {@link #getFilesDir()}, etc.
1076      * <p>
1077      * Shared storage devices returned here are considered a stable part of the
1078      * device, including physical media slots under a protective cover. The
1079      * returned paths do not include transient devices, such as USB flash drives
1080      * connected to handheld devices.
1081      * <p>
1082      * An application may store data on any or all of the returned devices. For
1083      * example, an app may choose to store large files on the device with the
1084      * most available space, as measured by {@link StatFs}.
1085      * <p>
1086      * No additional permissions are required for the calling app to read or
1087      * write files under the returned path. Write access outside of these paths
1088      * on secondary external storage devices is not available.
1089      * <p>
1090      * The returned path may change over time if different shared storage media
1091      * is inserted, so only relative paths should be persisted.
1092      *
1093      * @param type The type of files directory to return. May be {@code null}
1094      *            for the root of the files directory or one of the following
1095      *            constants for a subdirectory:
1096      *            {@link android.os.Environment#DIRECTORY_MUSIC},
1097      *            {@link android.os.Environment#DIRECTORY_PODCASTS},
1098      *            {@link android.os.Environment#DIRECTORY_RINGTONES},
1099      *            {@link android.os.Environment#DIRECTORY_ALARMS},
1100      *            {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1101      *            {@link android.os.Environment#DIRECTORY_PICTURES}, or
1102      *            {@link android.os.Environment#DIRECTORY_MOVIES}.
1103      * @return the absolute paths to application-specific directories. Some
1104      *         individual paths may be {@code null} if that shared storage is
1105      *         not currently available. The first path returned is the same as
1106      *         {@link #getExternalFilesDir(String)}.
1107      * @see #getExternalFilesDir(String)
1108      * @see Environment#getExternalStorageState(File)
1109      * @see Environment#isExternalStorageEmulated(File)
1110      * @see Environment#isExternalStorageRemovable(File)
1111      */
getExternalFilesDirs(String type)1112     public abstract File[] getExternalFilesDirs(String type);
1113 
1114     /**
1115      * Return the primary shared/external storage directory where this
1116      * application's OBB files (if there are any) can be found. Note if the
1117      * application does not have any OBB files, this directory may not exist.
1118      * <p>
1119      * This is like {@link #getFilesDir()} in that these files will be deleted
1120      * when the application is uninstalled, however there are some important
1121      * differences:
1122      * <ul>
1123      * <li>Shared storage may not always be available, since removable media can
1124      * be ejected by the user. Media state can be checked using
1125      * {@link Environment#getExternalStorageState(File)}.
1126      * <li>There is no security enforced with these files. For example, any
1127      * application holding
1128      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1129      * these files.
1130      * </ul>
1131      * <p>
1132      * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
1133      * are required to read or write to the path that this method returns.
1134      * However, starting from {@link android.os.Build.VERSION_CODES#M},
1135      * to read the OBB expansion files, you must declare the
1136      * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1137      * permission at runtime as follows:
1138      * </p>
1139      * <p>
1140      * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1141      * android:maxSdkVersion="23" />}
1142      * </p>
1143      * <p>
1144      * Starting from {@link android.os.Build.VERSION_CODES#N},
1145      * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1146      * permission is not required, so don’t ask for this
1147      * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1148      * and if it fails, you must request
1149      * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1150      * </p>
1151      *
1152      * <p>
1153      * The following code snippet shows how to do this:
1154      * </p>
1155      *
1156      * <pre>
1157      * File obb = new File(obb_filename);
1158      * boolean open_failed = false;
1159      *
1160      * try {
1161      *     BufferedReader br = new BufferedReader(new FileReader(obb));
1162      *     open_failed = false;
1163      *     ReadObbFile(br);
1164      * } catch (IOException e) {
1165      *     open_failed = true;
1166      * }
1167      *
1168      * if (open_failed) {
1169      *     // request READ_EXTERNAL_STORAGE permission before reading OBB file
1170      *     ReadObbFileWithPermission();
1171      * }
1172      * </pre>
1173      *
1174      * On devices with multiple users (as described by {@link UserManager}),
1175      * multiple users may share the same OBB storage location. Applications
1176      * should ensure that multiple instances running under different users don't
1177      * interfere with each other.
1178      *
1179      * @return the absolute path to application-specific directory. May return
1180      *         {@code null} if shared storage is not currently available.
1181      * @see #getObbDirs()
1182      * @see Environment#getExternalStorageState(File)
1183      * @see Environment#isExternalStorageEmulated(File)
1184      * @see Environment#isExternalStorageRemovable(File)
1185      */
getObbDir()1186     public abstract File getObbDir();
1187 
1188     /**
1189      * Returns absolute paths to application-specific directories on all
1190      * shared/external storage devices where the application's OBB files (if
1191      * there are any) can be found. Note if the application does not have any
1192      * OBB files, these directories may not exist.
1193      * <p>
1194      * This is like {@link #getFilesDir()} in that these files will be deleted
1195      * when the application is uninstalled, however there are some important
1196      * differences:
1197      * <ul>
1198      * <li>Shared storage may not always be available, since removable media can
1199      * be ejected by the user. Media state can be checked using
1200      * {@link Environment#getExternalStorageState(File)}.
1201      * <li>There is no security enforced with these files. For example, any
1202      * application holding
1203      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1204      * these files.
1205      * </ul>
1206      * <p>
1207      * Shared storage devices returned here are considered a stable part of the
1208      * device, including physical media slots under a protective cover. The
1209      * returned paths do not include transient devices, such as USB flash drives
1210      * connected to handheld devices.
1211      * <p>
1212      * An application may store data on any or all of the returned devices. For
1213      * example, an app may choose to store large files on the device with the
1214      * most available space, as measured by {@link StatFs}.
1215      * <p>
1216      * No additional permissions are required for the calling app to read or
1217      * write files under the returned path. Write access outside of these paths
1218      * on secondary external storage devices is not available.
1219      *
1220      * @return the absolute paths to application-specific directories. Some
1221      *         individual paths may be {@code null} if that shared storage is
1222      *         not currently available. The first path returned is the same as
1223      *         {@link #getObbDir()}
1224      * @see #getObbDir()
1225      * @see Environment#getExternalStorageState(File)
1226      * @see Environment#isExternalStorageEmulated(File)
1227      * @see Environment#isExternalStorageRemovable(File)
1228      */
getObbDirs()1229     public abstract File[] getObbDirs();
1230 
1231     /**
1232      * Returns the absolute path to the application specific cache directory on
1233      * the filesystem.
1234      * <p>
1235      * The system will automatically delete files in this directory as disk
1236      * space is needed elsewhere on the device. The system will always delete
1237      * older files first, as reported by {@link File#lastModified()}. If
1238      * desired, you can exert more control over how files are deleted using
1239      * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1240      * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1241      * <p>
1242      * Apps are strongly encouraged to keep their usage of cache space below the
1243      * quota returned by
1244      * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1245      * goes above this quota, your cached files will be some of the first to be
1246      * deleted when additional disk space is needed. Conversely, if your app
1247      * stays under this quota, your cached files will be some of the last to be
1248      * deleted when additional disk space is needed.
1249      * <p>
1250      * Note that your cache quota will change over time depending on how
1251      * frequently the user interacts with your app, and depending on how much
1252      * system-wide disk space is used.
1253      * <p>
1254      * The returned path may change over time if the calling app is moved to an
1255      * adopted storage device, so only relative paths should be persisted.
1256      * <p>
1257      * Apps require no extra permissions to read or write to the returned path,
1258      * since this path lives in their private storage.
1259      *
1260      * @return The path of the directory holding application cache files.
1261      * @see #openFileOutput
1262      * @see #getFileStreamPath
1263      * @see #getDir
1264      * @see #getExternalCacheDir
1265      */
getCacheDir()1266     public abstract File getCacheDir();
1267 
1268     /**
1269      * Returns the absolute path to the application specific cache directory on
1270      * the filesystem designed for storing cached code.
1271      * <p>
1272      * The system will delete any files stored in this location both when your
1273      * specific application is upgraded, and when the entire platform is
1274      * upgraded.
1275      * <p>
1276      * This location is optimal for storing compiled or optimized code generated
1277      * by your application at runtime.
1278      * <p>
1279      * The returned path may change over time if the calling app is moved to an
1280      * adopted storage device, so only relative paths should be persisted.
1281      * <p>
1282      * Apps require no extra permissions to read or write to the returned path,
1283      * since this path lives in their private storage.
1284      *
1285      * @return The path of the directory holding application code cache files.
1286      */
getCodeCacheDir()1287     public abstract File getCodeCacheDir();
1288 
1289     /**
1290      * Returns absolute path to application-specific directory on the primary
1291      * shared/external storage device where the application can place cache
1292      * files it owns. These files are internal to the application, and not
1293      * typically visible to the user as media.
1294      * <p>
1295      * This is like {@link #getCacheDir()} in that these files will be deleted
1296      * when the application is uninstalled, however there are some important
1297      * differences:
1298      * <ul>
1299      * <li>The platform does not always monitor the space available in shared
1300      * storage, and thus may not automatically delete these files. Apps should
1301      * always manage the maximum space used in this location. Currently the only
1302      * time files here will be deleted by the platform is when running on
1303      * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1304      * {@link Environment#isExternalStorageEmulated(File)} returns true.
1305      * <li>Shared storage may not always be available, since removable media can
1306      * be ejected by the user. Media state can be checked using
1307      * {@link Environment#getExternalStorageState(File)}.
1308      * <li>There is no security enforced with these files. For example, any
1309      * application holding
1310      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1311      * these files.
1312      * </ul>
1313      * <p>
1314      * If a shared storage device is emulated (as determined by
1315      * {@link Environment#isExternalStorageEmulated(File)}), its contents are
1316      * backed by a private user data partition, which means there is little
1317      * benefit to storing data here instead of the private directory returned by
1318      * {@link #getCacheDir()}.
1319      * <p>
1320      * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
1321      * are required to read or write to the returned path; it's always
1322      * accessible to the calling app. This only applies to paths generated for
1323      * package name of the calling application. To access paths belonging to
1324      * other packages,
1325      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1326      * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1327      * <p>
1328      * On devices with multiple users (as described by {@link UserManager}),
1329      * each user has their own isolated shared storage. Applications only have
1330      * access to the shared storage for the user they're running as.
1331      * <p>
1332      * The returned path may change over time if different shared storage media
1333      * is inserted, so only relative paths should be persisted.
1334      *
1335      * @return the absolute path to application-specific directory. May return
1336      *         {@code null} if shared storage is not currently available.
1337      * @see #getCacheDir
1338      * @see #getExternalCacheDirs()
1339      * @see Environment#getExternalStorageState(File)
1340      * @see Environment#isExternalStorageEmulated(File)
1341      * @see Environment#isExternalStorageRemovable(File)
1342      */
1343     @Nullable
getExternalCacheDir()1344     public abstract File getExternalCacheDir();
1345 
1346     /**
1347      * Returns absolute path to application-specific directory in the preloaded cache.
1348      * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1349      * There is no guarantee when these files will be deleted.
1350      * @hide
1351      */
1352     @Nullable
1353     @SystemApi
getPreloadsFileCache()1354     public abstract File getPreloadsFileCache();
1355 
1356     /**
1357      * Returns absolute paths to application-specific directories on all
1358      * shared/external storage devices where the application can place cache
1359      * files it owns. These files are internal to the application, and not
1360      * typically visible to the user as media.
1361      * <p>
1362      * This is like {@link #getCacheDir()} in that these files will be deleted
1363      * when the application is uninstalled, however there are some important
1364      * differences:
1365      * <ul>
1366      * <li>The platform does not always monitor the space available in shared
1367      * storage, and thus may not automatically delete these files. Apps should
1368      * always manage the maximum space used in this location. Currently the only
1369      * time files here will be deleted by the platform is when running on
1370      * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1371      * {@link Environment#isExternalStorageEmulated(File)} returns true.
1372      * <li>Shared storage may not always be available, since removable media can
1373      * be ejected by the user. Media state can be checked using
1374      * {@link Environment#getExternalStorageState(File)}.
1375      * <li>There is no security enforced with these files. For example, any
1376      * application holding
1377      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1378      * these files.
1379      * </ul>
1380      * <p>
1381      * If a shared storage device is emulated (as determined by
1382      * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1383      * backed by a private user data partition, which means there is little
1384      * benefit to storing data here instead of the private directory returned by
1385      * {@link #getCacheDir()}.
1386      * <p>
1387      * Shared storage devices returned here are considered a stable part of the
1388      * device, including physical media slots under a protective cover. The
1389      * returned paths do not include transient devices, such as USB flash drives
1390      * connected to handheld devices.
1391      * <p>
1392      * An application may store data on any or all of the returned devices. For
1393      * example, an app may choose to store large files on the device with the
1394      * most available space, as measured by {@link StatFs}.
1395      * <p>
1396      * No additional permissions are required for the calling app to read or
1397      * write files under the returned path. Write access outside of these paths
1398      * on secondary external storage devices is not available.
1399      * <p>
1400      * The returned paths may change over time if different shared storage media
1401      * is inserted, so only relative paths should be persisted.
1402      *
1403      * @return the absolute paths to application-specific directories. Some
1404      *         individual paths may be {@code null} if that shared storage is
1405      *         not currently available. The first path returned is the same as
1406      *         {@link #getExternalCacheDir()}.
1407      * @see #getExternalCacheDir()
1408      * @see Environment#getExternalStorageState(File)
1409      * @see Environment#isExternalStorageEmulated(File)
1410      * @see Environment#isExternalStorageRemovable(File)
1411      */
getExternalCacheDirs()1412     public abstract File[] getExternalCacheDirs();
1413 
1414     /**
1415      * Returns absolute paths to application-specific directories on all
1416      * shared/external storage devices where the application can place media
1417      * files. These files are scanned and made available to other apps through
1418      * {@link MediaStore}.
1419      * <p>
1420      * This is like {@link #getExternalFilesDirs} in that these files will be
1421      * deleted when the application is uninstalled, however there are some
1422      * important differences:
1423      * <ul>
1424      * <li>Shared storage may not always be available, since removable media can
1425      * be ejected by the user. Media state can be checked using
1426      * {@link Environment#getExternalStorageState(File)}.
1427      * <li>There is no security enforced with these files. For example, any
1428      * application holding
1429      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1430      * these files.
1431      * </ul>
1432      * <p>
1433      * Shared storage devices returned here are considered a stable part of the
1434      * device, including physical media slots under a protective cover. The
1435      * returned paths do not include transient devices, such as USB flash drives
1436      * connected to handheld devices.
1437      * <p>
1438      * An application may store data on any or all of the returned devices. For
1439      * example, an app may choose to store large files on the device with the
1440      * most available space, as measured by {@link StatFs}.
1441      * <p>
1442      * No additional permissions are required for the calling app to read or
1443      * write files under the returned path. Write access outside of these paths
1444      * on secondary external storage devices is not available.
1445      * <p>
1446      * The returned paths may change over time if different shared storage media
1447      * is inserted, so only relative paths should be persisted.
1448      *
1449      * @return the absolute paths to application-specific directories. Some
1450      *         individual paths may be {@code null} if that shared storage is
1451      *         not currently available.
1452      * @see Environment#getExternalStorageState(File)
1453      * @see Environment#isExternalStorageEmulated(File)
1454      * @see Environment#isExternalStorageRemovable(File)
1455      */
getExternalMediaDirs()1456     public abstract File[] getExternalMediaDirs();
1457 
1458     /**
1459      * Returns an array of strings naming the private files associated with
1460      * this Context's application package.
1461      *
1462      * @return Array of strings naming the private files.
1463      *
1464      * @see #openFileInput
1465      * @see #openFileOutput
1466      * @see #deleteFile
1467      */
fileList()1468     public abstract String[] fileList();
1469 
1470     /**
1471      * Retrieve, creating if needed, a new directory in which the application
1472      * can place its own custom data files.  You can use the returned File
1473      * object to create and access files in this directory.  Note that files
1474      * created through a File object will only be accessible by your own
1475      * application; you can only set the mode of the entire directory, not
1476      * of individual files.
1477      * <p>
1478      * The returned path may change over time if the calling app is moved to an
1479      * adopted storage device, so only relative paths should be persisted.
1480      * <p>
1481      * Apps require no extra permissions to read or write to the returned path,
1482      * since this path lives in their private storage.
1483      *
1484      * @param name Name of the directory to retrieve.  This is a directory
1485      * that is created as part of your application data.
1486      * @param mode Operating mode.
1487      *
1488      * @return A {@link File} object for the requested directory.  The directory
1489      * will have been created if it does not already exist.
1490      *
1491      * @see #openFileOutput(String, int)
1492      */
getDir(String name, @FileMode int mode)1493     public abstract File getDir(String name, @FileMode int mode);
1494 
1495     /**
1496      * Open a new private SQLiteDatabase associated with this Context's
1497      * application package. Create the database file if it doesn't exist.
1498      *
1499      * @param name The name (unique in the application package) of the database.
1500      * @param mode Operating mode.
1501      * @param factory An optional factory class that is called to instantiate a
1502      *            cursor when query is called.
1503      * @return The contents of a newly created database with the given name.
1504      * @throws android.database.sqlite.SQLiteException if the database file
1505      *             could not be opened.
1506      * @see #MODE_PRIVATE
1507      * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
1508      * @see #MODE_NO_LOCALIZED_COLLATORS
1509      * @see #deleteDatabase
1510      */
openOrCreateDatabase(String name, @DatabaseMode int mode, CursorFactory factory)1511     public abstract SQLiteDatabase openOrCreateDatabase(String name,
1512             @DatabaseMode int mode, CursorFactory factory);
1513 
1514     /**
1515      * Open a new private SQLiteDatabase associated with this Context's
1516      * application package. Creates the database file if it doesn't exist.
1517      * <p>
1518      * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1519      * to be used to handle corruption when sqlite reports database corruption.
1520      * </p>
1521      *
1522      * @param name The name (unique in the application package) of the database.
1523      * @param mode Operating mode.
1524      * @param factory An optional factory class that is called to instantiate a
1525      *            cursor when query is called.
1526      * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1527      *            sqlite reports database corruption. if null,
1528      *            {@link android.database.DefaultDatabaseErrorHandler} is
1529      *            assumed.
1530      * @return The contents of a newly created database with the given name.
1531      * @throws android.database.sqlite.SQLiteException if the database file
1532      *             could not be opened.
1533      * @see #MODE_PRIVATE
1534      * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
1535      * @see #MODE_NO_LOCALIZED_COLLATORS
1536      * @see #deleteDatabase
1537      */
openOrCreateDatabase(String name, @DatabaseMode int mode, CursorFactory factory, @Nullable DatabaseErrorHandler errorHandler)1538     public abstract SQLiteDatabase openOrCreateDatabase(String name,
1539             @DatabaseMode int mode, CursorFactory factory,
1540             @Nullable DatabaseErrorHandler errorHandler);
1541 
1542     /**
1543      * Move an existing database file from the given source storage context to
1544      * this context. This is typically used to migrate data between storage
1545      * locations after an upgrade, such as migrating to device protected
1546      * storage.
1547      * <p>
1548      * The database must be closed before being moved.
1549      *
1550      * @param sourceContext The source context which contains the existing
1551      *            database to move.
1552      * @param name The name of the database file.
1553      * @return {@code true} if the move was successful or if the database didn't
1554      *         exist in the source context, otherwise {@code false}.
1555      * @see #createDeviceProtectedStorageContext()
1556      */
moveDatabaseFrom(Context sourceContext, String name)1557     public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1558 
1559     /**
1560      * Delete an existing private SQLiteDatabase associated with this Context's
1561      * application package.
1562      *
1563      * @param name The name (unique in the application package) of the
1564      *             database.
1565      *
1566      * @return {@code true} if the database was successfully deleted; else {@code false}.
1567      *
1568      * @see #openOrCreateDatabase
1569      */
deleteDatabase(String name)1570     public abstract boolean deleteDatabase(String name);
1571 
1572     /**
1573      * Returns the absolute path on the filesystem where a database created with
1574      * {@link #openOrCreateDatabase} is stored.
1575      * <p>
1576      * The returned path may change over time if the calling app is moved to an
1577      * adopted storage device, so only relative paths should be persisted.
1578      *
1579      * @param name The name of the database for which you would like to get
1580      *          its path.
1581      *
1582      * @return An absolute path to the given database.
1583      *
1584      * @see #openOrCreateDatabase
1585      */
getDatabasePath(String name)1586     public abstract File getDatabasePath(String name);
1587 
1588     /**
1589      * Returns an array of strings naming the private databases associated with
1590      * this Context's application package.
1591      *
1592      * @return Array of strings naming the private databases.
1593      *
1594      * @see #openOrCreateDatabase
1595      * @see #deleteDatabase
1596      */
databaseList()1597     public abstract String[] databaseList();
1598 
1599     /**
1600      * @deprecated Use {@link android.app.WallpaperManager#getDrawable
1601      * WallpaperManager.get()} instead.
1602      */
1603     @Deprecated
getWallpaper()1604     public abstract Drawable getWallpaper();
1605 
1606     /**
1607      * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
1608      * WallpaperManager.peek()} instead.
1609      */
1610     @Deprecated
peekWallpaper()1611     public abstract Drawable peekWallpaper();
1612 
1613     /**
1614      * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1615      * WallpaperManager.getDesiredMinimumWidth()} instead.
1616      */
1617     @Deprecated
getWallpaperDesiredMinimumWidth()1618     public abstract int getWallpaperDesiredMinimumWidth();
1619 
1620     /**
1621      * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1622      * WallpaperManager.getDesiredMinimumHeight()} instead.
1623      */
1624     @Deprecated
getWallpaperDesiredMinimumHeight()1625     public abstract int getWallpaperDesiredMinimumHeight();
1626 
1627     /**
1628      * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
1629      * WallpaperManager.set()} instead.
1630      * <p>This method requires the caller to hold the permission
1631      * {@link android.Manifest.permission#SET_WALLPAPER}.
1632      */
1633     @Deprecated
setWallpaper(Bitmap bitmap)1634     public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1635 
1636     /**
1637      * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
1638      * WallpaperManager.set()} instead.
1639      * <p>This method requires the caller to hold the permission
1640      * {@link android.Manifest.permission#SET_WALLPAPER}.
1641      */
1642     @Deprecated
setWallpaper(InputStream data)1643     public abstract void setWallpaper(InputStream data) throws IOException;
1644 
1645     /**
1646      * @deprecated Use {@link android.app.WallpaperManager#clear
1647      * WallpaperManager.clear()} instead.
1648      * <p>This method requires the caller to hold the permission
1649      * {@link android.Manifest.permission#SET_WALLPAPER}.
1650      */
1651     @Deprecated
clearWallpaper()1652     public abstract void clearWallpaper() throws IOException;
1653 
1654     /**
1655      * Same as {@link #startActivity(Intent, Bundle)} with no options
1656      * specified.
1657      *
1658      * @param intent The description of the activity to start.
1659      *
1660      * @throws ActivityNotFoundException &nbsp;
1661      *`
1662      * @see #startActivity(Intent, Bundle)
1663      * @see PackageManager#resolveActivity
1664      */
startActivity(@equiresPermission Intent intent)1665     public abstract void startActivity(@RequiresPermission Intent intent);
1666 
1667     /**
1668      * Version of {@link #startActivity(Intent)} that allows you to specify the
1669      * user the activity will be started for.  This is not available to applications
1670      * that are not pre-installed on the system image.
1671      * @param intent The description of the activity to start.
1672      * @param user The UserHandle of the user to start this activity for.
1673      * @throws ActivityNotFoundException &nbsp;
1674      * @hide
1675      */
1676     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
startActivityAsUser(@equiresPermission Intent intent, UserHandle user)1677     public void startActivityAsUser(@RequiresPermission Intent intent, UserHandle user) {
1678         throw new RuntimeException("Not implemented. Must override in a subclass.");
1679     }
1680 
1681     /**
1682      * Launch a new activity.  You will not receive any information about when
1683      * the activity exits.
1684      *
1685      * <p>Note that if this method is being called from outside of an
1686      * {@link android.app.Activity} Context, then the Intent must include
1687      * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag.  This is because,
1688      * without being started from an existing Activity, there is no existing
1689      * task in which to place the new activity and thus it needs to be placed
1690      * in its own separate task.
1691      *
1692      * <p>This method throws {@link ActivityNotFoundException}
1693      * if there was no Activity found to run the given Intent.
1694      *
1695      * @param intent The description of the activity to start.
1696      * @param options Additional options for how the Activity should be started.
1697      * May be null if there are no options.  See {@link android.app.ActivityOptions}
1698      * for how to build the Bundle supplied here; there are no supported definitions
1699      * for building it manually.
1700      *
1701      * @throws ActivityNotFoundException &nbsp;
1702      *
1703      * @see #startActivity(Intent)
1704      * @see PackageManager#resolveActivity
1705      */
startActivity(@equiresPermission Intent intent, @Nullable Bundle options)1706     public abstract void startActivity(@RequiresPermission Intent intent,
1707             @Nullable Bundle options);
1708 
1709     /**
1710      * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1711      * user the activity will be started for.  This is not available to applications
1712      * that are not pre-installed on the system image.
1713      * @param intent The description of the activity to start.
1714      * @param options Additional options for how the Activity should be started.
1715      * May be null if there are no options.  See {@link android.app.ActivityOptions}
1716      * for how to build the Bundle supplied here; there are no supported definitions
1717      * for building it manually.
1718      * @param userId The UserHandle of the user to start this activity for.
1719      * @throws ActivityNotFoundException &nbsp;
1720      * @hide
1721      */
1722     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
startActivityAsUser(@equiresPermission Intent intent, @Nullable Bundle options, UserHandle userId)1723     public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1724             UserHandle userId) {
1725         throw new RuntimeException("Not implemented. Must override in a subclass.");
1726     }
1727 
1728     /**
1729      * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1730      * is only supported for Views and Fragments.
1731      * @param who The identifier for the calling element that will receive the result.
1732      * @param intent The intent to start.
1733      * @param requestCode The code that will be returned with onActivityResult() identifying this
1734      *          request.
1735      * @param options Additional options for how the Activity should be started.
1736      *          May be null if there are no options.  See {@link android.app.ActivityOptions}
1737      *          for how to build the Bundle supplied here; there are no supported definitions
1738      *          for building it manually.
1739      * @hide
1740      */
startActivityForResult( @onNull String who, Intent intent, int requestCode, @Nullable Bundle options)1741     public void startActivityForResult(
1742             @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1743         throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1744                 + "Check canStartActivityForResult() before calling.");
1745     }
1746 
1747     /**
1748      * Identifies whether this Context instance will be able to process calls to
1749      * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1750      * @hide
1751      */
canStartActivityForResult()1752     public boolean canStartActivityForResult() {
1753         return false;
1754     }
1755 
1756     /**
1757      * Same as {@link #startActivities(Intent[], Bundle)} with no options
1758      * specified.
1759      *
1760      * @param intents An array of Intents to be started.
1761      *
1762      * @throws ActivityNotFoundException &nbsp;
1763      *
1764      * @see #startActivities(Intent[], Bundle)
1765      * @see PackageManager#resolveActivity
1766      */
startActivities(@equiresPermission Intent[] intents)1767     public abstract void startActivities(@RequiresPermission Intent[] intents);
1768 
1769     /**
1770      * Launch multiple new activities.  This is generally the same as calling
1771      * {@link #startActivity(Intent)} for the first Intent in the array,
1772      * that activity during its creation calling {@link #startActivity(Intent)}
1773      * for the second entry, etc.  Note that unlike that approach, generally
1774      * none of the activities except the last in the array will be created
1775      * at this point, but rather will be created when the user first visits
1776      * them (due to pressing back from the activity on top).
1777      *
1778      * <p>This method throws {@link ActivityNotFoundException}
1779      * if there was no Activity found for <em>any</em> given Intent.  In this
1780      * case the state of the activity stack is undefined (some Intents in the
1781      * list may be on it, some not), so you probably want to avoid such situations.
1782      *
1783      * @param intents An array of Intents to be started.
1784      * @param options Additional options for how the Activity should be started.
1785      * See {@link android.content.Context#startActivity(Intent, Bundle)}
1786      * Context.startActivity(Intent, Bundle)} for more details.
1787      *
1788      * @throws ActivityNotFoundException &nbsp;
1789      *
1790      * @see #startActivities(Intent[])
1791      * @see PackageManager#resolveActivity
1792      */
startActivities(@equiresPermission Intent[] intents, Bundle options)1793     public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
1794 
1795     /**
1796      * @hide
1797      * Launch multiple new activities.  This is generally the same as calling
1798      * {@link #startActivity(Intent)} for the first Intent in the array,
1799      * that activity during its creation calling {@link #startActivity(Intent)}
1800      * for the second entry, etc.  Note that unlike that approach, generally
1801      * none of the activities except the last in the array will be created
1802      * at this point, but rather will be created when the user first visits
1803      * them (due to pressing back from the activity on top).
1804      *
1805      * <p>This method throws {@link ActivityNotFoundException}
1806      * if there was no Activity found for <em>any</em> given Intent.  In this
1807      * case the state of the activity stack is undefined (some Intents in the
1808      * list may be on it, some not), so you probably want to avoid such situations.
1809      *
1810      * @param intents An array of Intents to be started.
1811      * @param options Additional options for how the Activity should be started.
1812      * @param userHandle The user for whom to launch the activities
1813      * See {@link android.content.Context#startActivity(Intent, Bundle)}
1814      * Context.startActivity(Intent, Bundle)} for more details.
1815      *
1816      * @throws ActivityNotFoundException &nbsp;
1817      *
1818      * @see #startActivities(Intent[])
1819      * @see PackageManager#resolveActivity
1820      */
1821     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle)1822     public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1823         throw new RuntimeException("Not implemented. Must override in a subclass.");
1824     }
1825 
1826     /**
1827      * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1828      * with no options specified.
1829      *
1830      * @param intent The IntentSender to launch.
1831      * @param fillInIntent If non-null, this will be provided as the
1832      * intent parameter to {@link IntentSender#sendIntent}.
1833      * @param flagsMask Intent flags in the original IntentSender that you
1834      * would like to change.
1835      * @param flagsValues Desired values for any bits set in
1836      * <var>flagsMask</var>
1837      * @param extraFlags Always set to 0.
1838      *
1839      * @see #startActivity(Intent)
1840      * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1841      */
startIntentSender(IntentSender intent, @Nullable Intent fillInIntent, @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues, int extraFlags)1842     public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1843             @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1844             int extraFlags) throws IntentSender.SendIntentException;
1845 
1846     /**
1847      * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
1848      * to start.  If the IntentSender is for an activity, that activity will be started
1849      * as if you had called the regular {@link #startActivity(Intent)}
1850      * here; otherwise, its associated action will be executed (such as
1851      * sending a broadcast) as if you had called
1852      * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
1853      *
1854      * @param intent The IntentSender to launch.
1855      * @param fillInIntent If non-null, this will be provided as the
1856      * intent parameter to {@link IntentSender#sendIntent}.
1857      * @param flagsMask Intent flags in the original IntentSender that you
1858      * would like to change.
1859      * @param flagsValues Desired values for any bits set in
1860      * <var>flagsMask</var>
1861      * @param extraFlags Always set to 0.
1862      * @param options Additional options for how the Activity should be started.
1863      * See {@link android.content.Context#startActivity(Intent, Bundle)}
1864      * Context.startActivity(Intent, Bundle)} for more details.  If options
1865      * have also been supplied by the IntentSender, options given here will
1866      * override any that conflict with those given by the IntentSender.
1867      *
1868      * @see #startActivity(Intent, Bundle)
1869      * @see #startIntentSender(IntentSender, Intent, int, int, int)
1870      */
startIntentSender(IntentSender intent, @Nullable Intent fillInIntent, @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues, int extraFlags, @Nullable Bundle options)1871     public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1872             @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1873             int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
1874 
1875     /**
1876      * Broadcast the given intent to all interested BroadcastReceivers.  This
1877      * call is asynchronous; it returns immediately, and you will continue
1878      * executing while the receivers are run.  No results are propagated from
1879      * receivers and receivers can not abort the broadcast. If you want
1880      * to allow receivers to propagate results or abort the broadcast, you must
1881      * send an ordered broadcast using
1882      * {@link #sendOrderedBroadcast(Intent, String)}.
1883      *
1884      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1885      *
1886      * @param intent The Intent to broadcast; all receivers matching this
1887      *               Intent will receive the broadcast.
1888      *
1889      * @see android.content.BroadcastReceiver
1890      * @see #registerReceiver
1891      * @see #sendBroadcast(Intent, String)
1892      * @see #sendOrderedBroadcast(Intent, String)
1893      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1894      */
sendBroadcast(@equiresPermission Intent intent)1895     public abstract void sendBroadcast(@RequiresPermission Intent intent);
1896 
1897     /**
1898      * Broadcast the given intent to all interested BroadcastReceivers, allowing
1899      * an optional required permission to be enforced.  This
1900      * call is asynchronous; it returns immediately, and you will continue
1901      * executing while the receivers are run.  No results are propagated from
1902      * receivers and receivers can not abort the broadcast. If you want
1903      * to allow receivers to propagate results or abort the broadcast, you must
1904      * send an ordered broadcast using
1905      * {@link #sendOrderedBroadcast(Intent, String)}.
1906      *
1907      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1908      *
1909      * @param intent The Intent to broadcast; all receivers matching this
1910      *               Intent will receive the broadcast.
1911      * @param receiverPermission (optional) String naming a permission that
1912      *               a receiver must hold in order to receive your broadcast.
1913      *               If null, no permission is required.
1914      *
1915      * @see android.content.BroadcastReceiver
1916      * @see #registerReceiver
1917      * @see #sendBroadcast(Intent)
1918      * @see #sendOrderedBroadcast(Intent, String)
1919      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1920      */
sendBroadcast(@equiresPermission Intent intent, @Nullable String receiverPermission)1921     public abstract void sendBroadcast(@RequiresPermission Intent intent,
1922             @Nullable String receiverPermission);
1923 
1924 
1925     /**
1926      * Broadcast the given intent to all interested BroadcastReceivers, allowing
1927      * an array of required permissions to be enforced.  This call is asynchronous; it returns
1928      * immediately, and you will continue executing while the receivers are run.  No results are
1929      * propagated from receivers and receivers can not abort the broadcast. If you want to allow
1930      * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
1931      * using {@link #sendOrderedBroadcast(Intent, String)}.
1932      *
1933      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1934      *
1935      * @param intent The Intent to broadcast; all receivers matching this
1936      *               Intent will receive the broadcast.
1937      * @param receiverPermissions Array of names of permissions that a receiver must hold
1938      *                            in order to receive your broadcast.
1939      *                            If null or empty, no permissions are required.
1940      *
1941      * @see android.content.BroadcastReceiver
1942      * @see #registerReceiver
1943      * @see #sendBroadcast(Intent)
1944      * @see #sendOrderedBroadcast(Intent, String)
1945      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1946      * @hide
1947      */
sendBroadcastMultiplePermissions(Intent intent, String[] receiverPermissions)1948     public abstract void sendBroadcastMultiplePermissions(Intent intent,
1949             String[] receiverPermissions);
1950 
1951     /**
1952      * Broadcast the given intent to all interested BroadcastReceivers, allowing
1953      * an optional required permission to be enforced.  This
1954      * call is asynchronous; it returns immediately, and you will continue
1955      * executing while the receivers are run.  No results are propagated from
1956      * receivers and receivers can not abort the broadcast. If you want
1957      * to allow receivers to propagate results or abort the broadcast, you must
1958      * send an ordered broadcast using
1959      * {@link #sendOrderedBroadcast(Intent, String)}.
1960      *
1961      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1962      *
1963      * @param intent The Intent to broadcast; all receivers matching this
1964      *               Intent will receive the broadcast.
1965      * @param receiverPermission (optional) String naming a permission that
1966      *               a receiver must hold in order to receive your broadcast.
1967      *               If null, no permission is required.
1968      * @param options (optional) Additional sending options, generated from a
1969      * {@link android.app.BroadcastOptions}.
1970      *
1971      * @see android.content.BroadcastReceiver
1972      * @see #registerReceiver
1973      * @see #sendBroadcast(Intent)
1974      * @see #sendOrderedBroadcast(Intent, String)
1975      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1976      * @hide
1977      */
1978     @SystemApi
sendBroadcast(Intent intent, @Nullable String receiverPermission, @Nullable Bundle options)1979     public abstract void sendBroadcast(Intent intent,
1980             @Nullable String receiverPermission,
1981             @Nullable Bundle options);
1982 
1983     /**
1984      * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
1985      * of an associated app op as per {@link android.app.AppOpsManager}.
1986      * @hide
1987      */
sendBroadcast(Intent intent, String receiverPermission, int appOp)1988     public abstract void sendBroadcast(Intent intent,
1989             String receiverPermission, int appOp);
1990 
1991     /**
1992      * Broadcast the given intent to all interested BroadcastReceivers, delivering
1993      * them one at a time to allow more preferred receivers to consume the
1994      * broadcast before it is delivered to less preferred receivers.  This
1995      * call is asynchronous; it returns immediately, and you will continue
1996      * executing while the receivers are run.
1997      *
1998      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1999      *
2000      * @param intent The Intent to broadcast; all receivers matching this
2001      *               Intent will receive the broadcast.
2002      * @param receiverPermission (optional) String naming a permissions that
2003      *               a receiver must hold in order to receive your broadcast.
2004      *               If null, no permission is required.
2005      *
2006      * @see android.content.BroadcastReceiver
2007      * @see #registerReceiver
2008      * @see #sendBroadcast(Intent)
2009      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2010      */
sendOrderedBroadcast(@equiresPermission Intent intent, @Nullable String receiverPermission)2011     public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
2012             @Nullable String receiverPermission);
2013 
2014     /**
2015      * Version of {@link #sendBroadcast(Intent)} that allows you to
2016      * receive data back from the broadcast.  This is accomplished by
2017      * supplying your own BroadcastReceiver when calling, which will be
2018      * treated as a final receiver at the end of the broadcast -- its
2019      * {@link BroadcastReceiver#onReceive} method will be called with
2020      * the result values collected from the other receivers.  The broadcast will
2021      * be serialized in the same way as calling
2022      * {@link #sendOrderedBroadcast(Intent, String)}.
2023      *
2024      * <p>Like {@link #sendBroadcast(Intent)}, this method is
2025      * asynchronous; it will return before
2026      * resultReceiver.onReceive() is called.
2027      *
2028      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2029      *
2030      * @param intent The Intent to broadcast; all receivers matching this
2031      *               Intent will receive the broadcast.
2032      * @param receiverPermission String naming a permissions that
2033      *               a receiver must hold in order to receive your broadcast.
2034      *               If null, no permission is required.
2035      * @param resultReceiver Your own BroadcastReceiver to treat as the final
2036      *                       receiver of the broadcast.
2037      * @param scheduler A custom Handler with which to schedule the
2038      *                  resultReceiver callback; if null it will be
2039      *                  scheduled in the Context's main thread.
2040      * @param initialCode An initial value for the result code.  Often
2041      *                    Activity.RESULT_OK.
2042      * @param initialData An initial value for the result data.  Often
2043      *                    null.
2044      * @param initialExtras An initial value for the result extras.  Often
2045      *                      null.
2046      *
2047      * @see #sendBroadcast(Intent)
2048      * @see #sendBroadcast(Intent, String)
2049      * @see #sendOrderedBroadcast(Intent, String)
2050      * @see android.content.BroadcastReceiver
2051      * @see #registerReceiver
2052      * @see android.app.Activity#RESULT_OK
2053      */
sendOrderedBroadcast(@equiresPermission @onNull Intent intent, @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)2054     public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
2055             @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
2056             @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2057             @Nullable Bundle initialExtras);
2058 
2059     /**
2060      * Version of {@link #sendBroadcast(Intent)} that allows you to
2061      * receive data back from the broadcast.  This is accomplished by
2062      * supplying your own BroadcastReceiver when calling, which will be
2063      * treated as a final receiver at the end of the broadcast -- its
2064      * {@link BroadcastReceiver#onReceive} method will be called with
2065      * the result values collected from the other receivers.  The broadcast will
2066      * be serialized in the same way as calling
2067      * {@link #sendOrderedBroadcast(Intent, String)}.
2068      *
2069      * <p>Like {@link #sendBroadcast(Intent)}, this method is
2070      * asynchronous; it will return before
2071      * resultReceiver.onReceive() is called.
2072      *
2073      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2074      *
2075      *
2076      * @param intent The Intent to broadcast; all receivers matching this
2077      *               Intent will receive the broadcast.
2078      * @param receiverPermission String naming a permissions that
2079      *               a receiver must hold in order to receive your broadcast.
2080      *               If null, no permission is required.
2081      * @param options (optional) Additional sending options, generated from a
2082      * {@link android.app.BroadcastOptions}.
2083      * @param resultReceiver Your own BroadcastReceiver to treat as the final
2084      *                       receiver of the broadcast.
2085      * @param scheduler A custom Handler with which to schedule the
2086      *                  resultReceiver callback; if null it will be
2087      *                  scheduled in the Context's main thread.
2088      * @param initialCode An initial value for the result code.  Often
2089      *                    Activity.RESULT_OK.
2090      * @param initialData An initial value for the result data.  Often
2091      *                    null.
2092      * @param initialExtras An initial value for the result extras.  Often
2093      *                      null.
2094      * @see #sendBroadcast(Intent)
2095      * @see #sendBroadcast(Intent, String)
2096      * @see #sendOrderedBroadcast(Intent, String)
2097      * @see android.content.BroadcastReceiver
2098      * @see #registerReceiver
2099      * @see android.app.Activity#RESULT_OK
2100      * @hide
2101      */
2102     @SystemApi
sendOrderedBroadcast(@onNull Intent intent, @Nullable String receiverPermission, @Nullable Bundle options, @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)2103     public abstract void sendOrderedBroadcast(@NonNull Intent intent,
2104             @Nullable String receiverPermission, @Nullable Bundle options,
2105             @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2106             int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
2107 
2108     /**
2109      * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2110      * int, String, android.os.Bundle)}, but also allows specification
2111      * of an associated app op as per {@link android.app.AppOpsManager}.
2112      * @hide
2113      */
sendOrderedBroadcast(Intent intent, String receiverPermission, int appOp, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)2114     public abstract void sendOrderedBroadcast(Intent intent,
2115             String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2116             Handler scheduler, int initialCode, String initialData,
2117             Bundle initialExtras);
2118 
2119     /**
2120      * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2121      * user the broadcast will be sent to.  This is not available to applications
2122      * that are not pre-installed on the system image.
2123      * @param intent The intent to broadcast
2124      * @param user UserHandle to send the intent to.
2125      * @see #sendBroadcast(Intent)
2126      */
2127     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
sendBroadcastAsUser(@equiresPermission Intent intent, UserHandle user)2128     public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2129             UserHandle user);
2130 
2131     /**
2132      * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2133      * user the broadcast will be sent to.  This is not available to applications
2134      * that are not pre-installed on the system image.
2135      *
2136      * @param intent The Intent to broadcast; all receivers matching this
2137      *               Intent will receive the broadcast.
2138      * @param user UserHandle to send the intent to.
2139      * @param receiverPermission (optional) String naming a permission that
2140      *               a receiver must hold in order to receive your broadcast.
2141      *               If null, no permission is required.
2142      *
2143      * @see #sendBroadcast(Intent, String)
2144      */
2145     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
sendBroadcastAsUser(@equiresPermission Intent intent, UserHandle user, @Nullable String receiverPermission)2146     public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2147             UserHandle user, @Nullable String receiverPermission);
2148 
2149     /**
2150      * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2151      * user the broadcast will be sent to.  This is not available to applications
2152      * that are not pre-installed on the system image.
2153      *
2154      * @param intent The Intent to broadcast; all receivers matching this
2155      *               Intent will receive the broadcast.
2156      * @param user UserHandle to send the intent to.
2157      * @param receiverPermission (optional) String naming a permission that
2158      *               a receiver must hold in order to receive your broadcast.
2159      *               If null, no permission is required.
2160      * @param options (optional) Additional sending options, generated from a
2161      * {@link android.app.BroadcastOptions}.
2162      *
2163      * @see #sendBroadcast(Intent, String, Bundle)
2164      * @hide
2165      */
2166     @SystemApi
2167     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
sendBroadcastAsUser(@equiresPermission Intent intent, UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options)2168     public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2169             UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
2170 
2171     /**
2172      * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2173      * user the broadcast will be sent to.  This is not available to applications
2174      * that are not pre-installed on the system image.
2175      *
2176      * @param intent The Intent to broadcast; all receivers matching this
2177      *               Intent will receive the broadcast.
2178      * @param user UserHandle to send the intent to.
2179      * @param receiverPermission (optional) String naming a permission that
2180      *               a receiver must hold in order to receive your broadcast.
2181      *               If null, no permission is required.
2182      * @param appOp The app op associated with the broadcast.
2183      *
2184      * @see #sendBroadcast(Intent, String)
2185      *
2186      * @hide
2187      */
2188     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
sendBroadcastAsUser(@equiresPermission Intent intent, UserHandle user, @Nullable String receiverPermission, int appOp)2189     public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2190             UserHandle user, @Nullable String receiverPermission, int appOp);
2191 
2192     /**
2193      * Version of
2194      * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2195      * that allows you to specify the
2196      * user the broadcast will be sent to.  This is not available to applications
2197      * that are not pre-installed on the system image.
2198      *
2199      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2200      *
2201      * @param intent The Intent to broadcast; all receivers matching this
2202      *               Intent will receive the broadcast.
2203      * @param user UserHandle to send the intent to.
2204      * @param receiverPermission String naming a permissions that
2205      *               a receiver must hold in order to receive your broadcast.
2206      *               If null, no permission is required.
2207      * @param resultReceiver Your own BroadcastReceiver to treat as the final
2208      *                       receiver of the broadcast.
2209      * @param scheduler A custom Handler with which to schedule the
2210      *                  resultReceiver callback; if null it will be
2211      *                  scheduled in the Context's main thread.
2212      * @param initialCode An initial value for the result code.  Often
2213      *                    Activity.RESULT_OK.
2214      * @param initialData An initial value for the result data.  Often
2215      *                    null.
2216      * @param initialExtras An initial value for the result extras.  Often
2217      *                      null.
2218      *
2219      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2220      */
2221     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
sendOrderedBroadcastAsUser(@equiresPermission Intent intent, UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)2222     public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2223             UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
2224             @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2225             @Nullable  Bundle initialExtras);
2226 
2227     /**
2228      * Similar to above but takes an appOp as well, to enforce restrictions.
2229      * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2230      *       BroadcastReceiver, Handler, int, String, Bundle)
2231      * @hide
2232      */
2233     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
sendOrderedBroadcastAsUser(Intent intent, UserHandle user, @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)2234     public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2235             @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2236             @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2237             @Nullable  Bundle initialExtras);
2238 
2239     /**
2240      * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2241      * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2242      *       BroadcastReceiver, Handler, int, String, Bundle)
2243      * @hide
2244      */
2245     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
sendOrderedBroadcastAsUser(Intent intent, UserHandle user, @Nullable String receiverPermission, int appOp, @Nullable Bundle options, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)2246     public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2247             @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2248             BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2249             @Nullable String initialData, @Nullable  Bundle initialExtras);
2250 
2251     /**
2252      * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
2253      * Intent you are sending stays around after the broadcast is complete,
2254      * so that others can quickly retrieve that data through the return
2255      * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}.  In
2256      * all other ways, this behaves the same as
2257      * {@link #sendBroadcast(Intent)}.
2258      *
2259      * @deprecated Sticky broadcasts should not be used.  They provide no security (anyone
2260      * can access them), no protection (anyone can modify them), and many other problems.
2261      * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2262      * has changed, with another mechanism for apps to retrieve the current value whenever
2263      * desired.
2264      *
2265      * @param intent The Intent to broadcast; all receivers matching this
2266      * Intent will receive the broadcast, and the Intent will be held to
2267      * be re-broadcast to future receivers.
2268      *
2269      * @see #sendBroadcast(Intent)
2270      * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2271      */
2272     @Deprecated
2273     @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
sendStickyBroadcast(@equiresPermission Intent intent)2274     public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
2275 
2276     /**
2277      * <p>Version of {@link #sendStickyBroadcast} that allows you to
2278      * receive data back from the broadcast.  This is accomplished by
2279      * supplying your own BroadcastReceiver when calling, which will be
2280      * treated as a final receiver at the end of the broadcast -- its
2281      * {@link BroadcastReceiver#onReceive} method will be called with
2282      * the result values collected from the other receivers.  The broadcast will
2283      * be serialized in the same way as calling
2284      * {@link #sendOrderedBroadcast(Intent, String)}.
2285      *
2286      * <p>Like {@link #sendBroadcast(Intent)}, this method is
2287      * asynchronous; it will return before
2288      * resultReceiver.onReceive() is called.  Note that the sticky data
2289      * stored is only the data you initially supply to the broadcast, not
2290      * the result of any changes made by the receivers.
2291      *
2292      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2293      *
2294      * @deprecated Sticky broadcasts should not be used.  They provide no security (anyone
2295      * can access them), no protection (anyone can modify them), and many other problems.
2296      * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2297      * has changed, with another mechanism for apps to retrieve the current value whenever
2298      * desired.
2299      *
2300      * @param intent The Intent to broadcast; all receivers matching this
2301      *               Intent will receive the broadcast.
2302      * @param resultReceiver Your own BroadcastReceiver to treat as the final
2303      *                       receiver of the broadcast.
2304      * @param scheduler A custom Handler with which to schedule the
2305      *                  resultReceiver callback; if null it will be
2306      *                  scheduled in the Context's main thread.
2307      * @param initialCode An initial value for the result code.  Often
2308      *                    Activity.RESULT_OK.
2309      * @param initialData An initial value for the result data.  Often
2310      *                    null.
2311      * @param initialExtras An initial value for the result extras.  Often
2312      *                      null.
2313      *
2314      * @see #sendBroadcast(Intent)
2315      * @see #sendBroadcast(Intent, String)
2316      * @see #sendOrderedBroadcast(Intent, String)
2317      * @see #sendStickyBroadcast(Intent)
2318      * @see android.content.BroadcastReceiver
2319      * @see #registerReceiver
2320      * @see android.app.Activity#RESULT_OK
2321      */
2322     @Deprecated
2323     @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
sendStickyOrderedBroadcast(@equiresPermission Intent intent, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)2324     public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
2325             BroadcastReceiver resultReceiver,
2326             @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2327             @Nullable Bundle initialExtras);
2328 
2329     /**
2330      * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
2331      * so that it is as if the sticky broadcast had never happened.
2332      *
2333      * @deprecated Sticky broadcasts should not be used.  They provide no security (anyone
2334      * can access them), no protection (anyone can modify them), and many other problems.
2335      * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2336      * has changed, with another mechanism for apps to retrieve the current value whenever
2337      * desired.
2338      *
2339      * @param intent The Intent that was previously broadcast.
2340      *
2341      * @see #sendStickyBroadcast
2342      */
2343     @Deprecated
2344     @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
removeStickyBroadcast(@equiresPermission Intent intent)2345     public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
2346 
2347     /**
2348      * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
2349      * user the broadcast will be sent to.  This is not available to applications
2350      * that are not pre-installed on the system image.
2351      *
2352      * @deprecated Sticky broadcasts should not be used.  They provide no security (anyone
2353      * can access them), no protection (anyone can modify them), and many other problems.
2354      * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2355      * has changed, with another mechanism for apps to retrieve the current value whenever
2356      * desired.
2357      *
2358      * @param intent The Intent to broadcast; all receivers matching this
2359      * Intent will receive the broadcast, and the Intent will be held to
2360      * be re-broadcast to future receivers.
2361      * @param user UserHandle to send the intent to.
2362      *
2363      * @see #sendBroadcast(Intent)
2364      */
2365     @Deprecated
2366     @RequiresPermission(allOf = {
2367             android.Manifest.permission.INTERACT_ACROSS_USERS,
2368             android.Manifest.permission.BROADCAST_STICKY
2369     })
sendStickyBroadcastAsUser(@equiresPermission Intent intent, UserHandle user)2370     public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2371             UserHandle user);
2372 
2373     /**
2374      * @hide
2375      * This is just here for sending CONNECTIVITY_ACTION.
2376      */
2377     @Deprecated
2378     @RequiresPermission(allOf = {
2379             android.Manifest.permission.INTERACT_ACROSS_USERS,
2380             android.Manifest.permission.BROADCAST_STICKY
2381     })
sendStickyBroadcastAsUser(@equiresPermission Intent intent, UserHandle user, Bundle options)2382     public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2383             UserHandle user, Bundle options);
2384 
2385     /**
2386      * <p>Version of
2387      * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2388      * that allows you to specify the
2389      * user the broadcast will be sent to.  This is not available to applications
2390      * that are not pre-installed on the system image.
2391      *
2392      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2393      *
2394      * @deprecated Sticky broadcasts should not be used.  They provide no security (anyone
2395      * can access them), no protection (anyone can modify them), and many other problems.
2396      * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2397      * has changed, with another mechanism for apps to retrieve the current value whenever
2398      * desired.
2399      *
2400      * @param intent The Intent to broadcast; all receivers matching this
2401      *               Intent will receive the broadcast.
2402      * @param user UserHandle to send the intent to.
2403      * @param resultReceiver Your own BroadcastReceiver to treat as the final
2404      *                       receiver of the broadcast.
2405      * @param scheduler A custom Handler with which to schedule the
2406      *                  resultReceiver callback; if null it will be
2407      *                  scheduled in the Context's main thread.
2408      * @param initialCode An initial value for the result code.  Often
2409      *                    Activity.RESULT_OK.
2410      * @param initialData An initial value for the result data.  Often
2411      *                    null.
2412      * @param initialExtras An initial value for the result extras.  Often
2413      *                      null.
2414      *
2415      * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2416      */
2417     @Deprecated
2418     @RequiresPermission(allOf = {
2419             android.Manifest.permission.INTERACT_ACROSS_USERS,
2420             android.Manifest.permission.BROADCAST_STICKY
2421     })
sendStickyOrderedBroadcastAsUser(@equiresPermission Intent intent, UserHandle user, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)2422     public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2423             UserHandle user, BroadcastReceiver resultReceiver,
2424             @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2425             @Nullable Bundle initialExtras);
2426 
2427     /**
2428      * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
2429      * user the broadcast will be sent to.  This is not available to applications
2430      * that are not pre-installed on the system image.
2431      *
2432      * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2433      * permission in order to use this API.  If you do not hold that
2434      * permission, {@link SecurityException} will be thrown.
2435      *
2436      * @deprecated Sticky broadcasts should not be used.  They provide no security (anyone
2437      * can access them), no protection (anyone can modify them), and many other problems.
2438      * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2439      * has changed, with another mechanism for apps to retrieve the current value whenever
2440      * desired.
2441      *
2442      * @param intent The Intent that was previously broadcast.
2443      * @param user UserHandle to remove the sticky broadcast from.
2444      *
2445      * @see #sendStickyBroadcastAsUser
2446      */
2447     @Deprecated
2448     @RequiresPermission(allOf = {
2449             android.Manifest.permission.INTERACT_ACROSS_USERS,
2450             android.Manifest.permission.BROADCAST_STICKY
2451     })
removeStickyBroadcastAsUser(@equiresPermission Intent intent, UserHandle user)2452     public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2453             UserHandle user);
2454 
2455     /**
2456      * Register a BroadcastReceiver to be run in the main activity thread.  The
2457      * <var>receiver</var> will be called with any broadcast Intent that
2458      * matches <var>filter</var>, in the main application thread.
2459      *
2460      * <p>The system may broadcast Intents that are "sticky" -- these stay
2461      * around after the broadcast has finished, to be sent to any later
2462      * registrations. If your IntentFilter matches one of these sticky
2463      * Intents, that Intent will be returned by this function
2464      * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2465      * been broadcast.
2466      *
2467      * <p>There may be multiple sticky Intents that match <var>filter</var>,
2468      * in which case each of these will be sent to <var>receiver</var>.  In
2469      * this case, only one of these can be returned directly by the function;
2470      * which of these that is returned is arbitrarily decided by the system.
2471      *
2472      * <p>If you know the Intent your are registering for is sticky, you can
2473      * supply null for your <var>receiver</var>.  In this case, no receiver is
2474      * registered -- the function simply returns the sticky Intent that
2475      * matches <var>filter</var>.  In the case of multiple matches, the same
2476      * rules as described above apply.
2477      *
2478      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2479      *
2480      * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2481      * registered with this method will correctly respect the
2482      * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2483      * Prior to that, it would be ignored and delivered to all matching registered
2484      * receivers.  Be careful if using this for security.</p>
2485      *
2486      * <p class="note">Note: this method <em>cannot be called from a
2487      * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2488      * that is declared in an application's manifest.  It is okay, however, to call
2489      * this method from another BroadcastReceiver that has itself been registered
2490      * at run time with {@link #registerReceiver}, since the lifetime of such a
2491      * registered BroadcastReceiver is tied to the object that registered it.</p>
2492      *
2493      * @param receiver The BroadcastReceiver to handle the broadcast.
2494      * @param filter Selects the Intent broadcasts to be received.
2495      *
2496      * @return The first sticky intent found that matches <var>filter</var>,
2497      *         or null if there are none.
2498      *
2499      * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2500      * @see #sendBroadcast
2501      * @see #unregisterReceiver
2502      */
2503     @Nullable
registerReceiver(@ullable BroadcastReceiver receiver, IntentFilter filter)2504     public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
2505                                             IntentFilter filter);
2506 
2507     /**
2508      * Register to receive intent broadcasts, with the receiver optionally being
2509      * exposed to Instant Apps. See
2510      * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2511      * information. By default Instant Apps cannot interact with receivers in other
2512      * applications, this allows you to expose a receiver that Instant Apps can
2513      * interact with.
2514      *
2515      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2516      *
2517      * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2518      * registered with this method will correctly respect the
2519      * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2520      * Prior to that, it would be ignored and delivered to all matching registered
2521      * receivers.  Be careful if using this for security.</p>
2522      *
2523      * @param receiver The BroadcastReceiver to handle the broadcast.
2524      * @param filter Selects the Intent broadcasts to be received.
2525      * @param flags Additional options for the receiver. May be 0 or
2526      *      {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
2527      *
2528      * @return The first sticky intent found that matches <var>filter</var>,
2529      *         or null if there are none.
2530      *
2531      * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2532      * @see #sendBroadcast
2533      * @see #unregisterReceiver
2534      */
2535     @Nullable
registerReceiver(@ullable BroadcastReceiver receiver, IntentFilter filter, @RegisterReceiverFlags int flags)2536     public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
2537                                             IntentFilter filter,
2538                                             @RegisterReceiverFlags int flags);
2539 
2540     /**
2541      * Register to receive intent broadcasts, to run in the context of
2542      * <var>scheduler</var>.  See
2543      * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2544      * information.  This allows you to enforce permissions on who can
2545      * broadcast intents to your receiver, or have the receiver run in
2546      * a different thread than the main application thread.
2547      *
2548      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2549      *
2550      * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2551      * registered with this method will correctly respect the
2552      * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2553      * Prior to that, it would be ignored and delivered to all matching registered
2554      * receivers.  Be careful if using this for security.</p>
2555      *
2556      * @param receiver The BroadcastReceiver to handle the broadcast.
2557      * @param filter Selects the Intent broadcasts to be received.
2558      * @param broadcastPermission String naming a permissions that a
2559      *      broadcaster must hold in order to send an Intent to you.  If null,
2560      *      no permission is required.
2561      * @param scheduler Handler identifying the thread that will receive
2562      *      the Intent.  If null, the main thread of the process will be used.
2563      *
2564      * @return The first sticky intent found that matches <var>filter</var>,
2565      *         or null if there are none.
2566      *
2567      * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2568      * @see #sendBroadcast
2569      * @see #unregisterReceiver
2570      */
2571     @Nullable
registerReceiver(BroadcastReceiver receiver, IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler)2572     public abstract Intent registerReceiver(BroadcastReceiver receiver,
2573             IntentFilter filter, @Nullable String broadcastPermission,
2574             @Nullable Handler scheduler);
2575 
2576     /**
2577      * Register to receive intent broadcasts, to run in the context of
2578      * <var>scheduler</var>. See
2579      * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
2580      * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2581      * for more information.
2582      *
2583      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2584      *
2585      * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2586      * registered with this method will correctly respect the
2587      * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2588      * Prior to that, it would be ignored and delivered to all matching registered
2589      * receivers.  Be careful if using this for security.</p>
2590      *
2591      * @param receiver The BroadcastReceiver to handle the broadcast.
2592      * @param filter Selects the Intent broadcasts to be received.
2593      * @param broadcastPermission String naming a permissions that a
2594      *      broadcaster must hold in order to send an Intent to you.  If null,
2595      *      no permission is required.
2596      * @param scheduler Handler identifying the thread that will receive
2597      *      the Intent.  If null, the main thread of the process will be used.
2598      * @param flags Additional options for the receiver. May be 0 or
2599      *      {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
2600      *
2601      * @return The first sticky intent found that matches <var>filter</var>,
2602      *         or null if there are none.
2603      *
2604      * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
2605      * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2606      * @see #sendBroadcast
2607      * @see #unregisterReceiver
2608      */
2609     @Nullable
registerReceiver(BroadcastReceiver receiver, IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler, @RegisterReceiverFlags int flags)2610     public abstract Intent registerReceiver(BroadcastReceiver receiver,
2611             IntentFilter filter, @Nullable String broadcastPermission,
2612             @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
2613 
2614     /**
2615      * @hide
2616      * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2617      * but for a specific user.  This receiver will receiver broadcasts that
2618      * are sent to the requested user.
2619      *
2620      * @param receiver The BroadcastReceiver to handle the broadcast.
2621      * @param user UserHandle to send the intent to.
2622      * @param filter Selects the Intent broadcasts to be received.
2623      * @param broadcastPermission String naming a permissions that a
2624      *      broadcaster must hold in order to send an Intent to you.  If null,
2625      *      no permission is required.
2626      * @param scheduler Handler identifying the thread that will receive
2627      *      the Intent.  If null, the main thread of the process will be used.
2628      *
2629      * @return The first sticky intent found that matches <var>filter</var>,
2630      *         or null if there are none.
2631      *
2632      * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2633      * @see #sendBroadcast
2634      * @see #unregisterReceiver
2635      */
2636     @Nullable
2637     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user, IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler)2638     public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
2639             UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2640             @Nullable Handler scheduler);
2641 
2642     /**
2643      * Unregister a previously registered BroadcastReceiver.  <em>All</em>
2644      * filters that have been registered for this BroadcastReceiver will be
2645      * removed.
2646      *
2647      * @param receiver The BroadcastReceiver to unregister.
2648      *
2649      * @see #registerReceiver
2650      */
unregisterReceiver(BroadcastReceiver receiver)2651     public abstract void unregisterReceiver(BroadcastReceiver receiver);
2652 
2653     /**
2654      * Request that a given application service be started.  The Intent
2655      * should either contain the complete class name of a specific service
2656      * implementation to start, or a specific package name to target.  If the
2657      * Intent is less specified, it logs a warning about this.  In this case any of the
2658      * multiple matching services may be used.  If this service
2659      * is not already running, it will be instantiated and started (creating a
2660      * process for it if needed); if it is running then it remains running.
2661      *
2662      * <p>Every call to this method will result in a corresponding call to
2663      * the target service's {@link android.app.Service#onStartCommand} method,
2664      * with the <var>intent</var> given here.  This provides a convenient way
2665      * to submit jobs to a service without having to bind and call on to its
2666      * interface.
2667      *
2668      * <p>Using startService() overrides the default service lifetime that is
2669      * managed by {@link #bindService}: it requires the service to remain
2670      * running until {@link #stopService} is called, regardless of whether
2671      * any clients are connected to it.  Note that calls to startService()
2672      * do not nest: no matter how many times you call startService(),
2673      * a single call to {@link #stopService} will stop it.
2674      *
2675      * <p>The system attempts to keep running services around as much as
2676      * possible.  The only time they should be stopped is if the current
2677      * foreground application is using so many resources that the service needs
2678      * to be killed.  If any errors happen in the service's process, it will
2679      * automatically be restarted.
2680      *
2681      * <p>This function will throw {@link SecurityException} if you do not
2682      * have permission to start the given service.
2683      *
2684      * <p class="note"><strong>Note:</strong> Each call to startService()
2685      * results in significant work done by the system to manage service
2686      * lifecycle surrounding the processing of the intent, which can take
2687      * multiple milliseconds of CPU time. Due to this cost, startService()
2688      * should not be used for frequent intent delivery to a service, and only
2689      * for scheduling significant work. Use {@link #bindService bound services}
2690      * for high frequency calls.
2691      * </p>
2692      *
2693      * @param service Identifies the service to be started.  The Intent must be
2694      *      fully explicit (supplying a component name).  Additional values
2695      *      may be included in the Intent extras to supply arguments along with
2696      *      this specific start call.
2697      *
2698      * @return If the service is being started or is already running, the
2699      * {@link ComponentName} of the actual service that was started is
2700      * returned; else if the service does not exist null is returned.
2701      *
2702      * @throws SecurityException If the caller does not have permission to access the service
2703      * or the service can not be found.
2704      * @throws IllegalStateException If the application is in a state where the service
2705      * can not be started (such as not in the foreground in a state when services are allowed).
2706      *
2707      * @see #stopService
2708      * @see #bindService
2709      */
2710     @Nullable
startService(Intent service)2711     public abstract ComponentName startService(Intent service);
2712 
2713     /**
2714      * Similar to {@link #startService(Intent)}, but with an implicit promise that the
2715      * Service will call {@link android.app.Service#startForeground(int, android.app.Notification)
2716      * startForeground(int, android.app.Notification)} once it begins running.  The service is given
2717      * an amount of time comparable to the ANR interval to do this, otherwise the system
2718      * will automatically stop the service and declare the app ANR.
2719      *
2720      * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
2721      * at any time, regardless of whether the app hosting the service is in a foreground
2722      * state.
2723      *
2724      * @param service Identifies the service to be started.  The Intent must be
2725      *      fully explicit (supplying a component name).  Additional values
2726      *      may be included in the Intent extras to supply arguments along with
2727      *      this specific start call.
2728      *
2729      * @return If the service is being started or is already running, the
2730      * {@link ComponentName} of the actual service that was started is
2731      * returned; else if the service does not exist null is returned.
2732      *
2733      * @throws SecurityException If the caller does not have permission to access the service
2734      * or the service can not be found.
2735      *
2736      * @see #stopService
2737      * @see android.app.Service#startForeground(int, android.app.Notification)
2738      */
2739     @Nullable
startForegroundService(Intent service)2740     public abstract ComponentName startForegroundService(Intent service);
2741 
2742     /**
2743      * @hide like {@link #startForegroundService(Intent)} but for a specific user.
2744      */
2745     @Nullable
2746     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
startForegroundServiceAsUser(Intent service, UserHandle user)2747     public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
2748 
2749     /**
2750      * Request that a given application service be stopped.  If the service is
2751      * not running, nothing happens.  Otherwise it is stopped.  Note that calls
2752      * to startService() are not counted -- this stops the service no matter
2753      * how many times it was started.
2754      *
2755      * <p>Note that if a stopped service still has {@link ServiceConnection}
2756      * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2757      * not be destroyed until all of these bindings are removed.  See
2758      * the {@link android.app.Service} documentation for more details on a
2759      * service's lifecycle.
2760      *
2761      * <p>This function will throw {@link SecurityException} if you do not
2762      * have permission to stop the given service.
2763      *
2764      * @param service Description of the service to be stopped.  The Intent must be either
2765      *      fully explicit (supplying a component name) or specify a specific package
2766      *      name it is targetted to.
2767      *
2768      * @return If there is a service matching the given Intent that is already
2769      * running, then it is stopped and {@code true} is returned; else {@code false} is returned.
2770      *
2771      * @throws SecurityException If the caller does not have permission to access the service
2772      * or the service can not be found.
2773      * @throws IllegalStateException If the application is in a state where the service
2774      * can not be started (such as not in the foreground in a state when services are allowed).
2775      *
2776      * @see #startService
2777      */
stopService(Intent service)2778     public abstract boolean stopService(Intent service);
2779 
2780     /**
2781      * @hide like {@link #startService(Intent)} but for a specific user.
2782      */
2783     @Nullable
2784     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
startServiceAsUser(Intent service, UserHandle user)2785     public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2786 
2787     /**
2788      * @hide like {@link #stopService(Intent)} but for a specific user.
2789      */
2790     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
stopServiceAsUser(Intent service, UserHandle user)2791     public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
2792 
2793     /**
2794      * Connect to an application service, creating it if needed.  This defines
2795      * a dependency between your application and the service.  The given
2796      * <var>conn</var> will receive the service object when it is created and be
2797      * told if it dies and restarts.  The service will be considered required
2798      * by the system only for as long as the calling context exists.  For
2799      * example, if this Context is an Activity that is stopped, the service will
2800      * not be required to continue running until the Activity is resumed.
2801      *
2802      * <p>This function will throw {@link SecurityException} if you do not
2803      * have permission to bind to the given service.
2804      *
2805      * <p class="note">Note: this method <em>can not be called from a
2806      * {@link BroadcastReceiver} component</em>.  A pattern you can use to
2807      * communicate from a BroadcastReceiver to a Service is to call
2808      * {@link #startService} with the arguments containing the command to be
2809      * sent, with the service calling its
2810      * {@link android.app.Service#stopSelf(int)} method when done executing
2811      * that command.  See the API demo App/Service/Service Start Arguments
2812      * Controller for an illustration of this.  It is okay, however, to use
2813      * this method from a BroadcastReceiver that has been registered with
2814      * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2815      * is tied to another object (the one that registered it).</p>
2816      *
2817      * @param service Identifies the service to connect to.  The Intent must
2818      *      specify an explicit component name.
2819      * @param conn Receives information as the service is started and stopped.
2820      *      This must be a valid ServiceConnection object; it must not be null.
2821      * @param flags Operation options for the binding.  May be 0,
2822      *          {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2823      *          {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2824      *          {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2825      *          {@link #BIND_WAIVE_PRIORITY}.
2826      * @return If you have successfully bound to the service, {@code true} is returned;
2827      *         {@code false} is returned if the connection is not made so you will not
2828      *         receive the service object. However, you should still call
2829      *         {@link #unbindService} to release the connection.
2830      *
2831      * @throws SecurityException If the caller does not have permission to access the service
2832      * or the service can not be found.
2833      *
2834      * @see #unbindService
2835      * @see #startService
2836      * @see #BIND_AUTO_CREATE
2837      * @see #BIND_DEBUG_UNBIND
2838      * @see #BIND_NOT_FOREGROUND
2839      */
bindService(@equiresPermission Intent service, @NonNull ServiceConnection conn, @BindServiceFlags int flags)2840     public abstract boolean bindService(@RequiresPermission Intent service,
2841             @NonNull ServiceConnection conn, @BindServiceFlags int flags);
2842 
2843     /**
2844      * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
2845      * argument for use by system server and other multi-user aware code.
2846      * @hide
2847      */
2848     @SystemApi
2849     @SuppressWarnings("unused")
2850     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
bindServiceAsUser(@equiresPermission Intent service, ServiceConnection conn, int flags, UserHandle user)2851     public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
2852             int flags, UserHandle user) {
2853         throw new RuntimeException("Not implemented. Must override in a subclass.");
2854     }
2855 
2856     /**
2857      * Same as {@link #bindService(Intent, ServiceConnection, int, UserHandle)}, but with an
2858      * explicit non-null Handler to run the ServiceConnection callbacks on.
2859      *
2860      * @hide
2861      */
2862     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
bindServiceAsUser(Intent service, ServiceConnection conn, int flags, Handler handler, UserHandle user)2863     public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
2864             Handler handler, UserHandle user) {
2865         throw new RuntimeException("Not implemented. Must override in a subclass.");
2866     }
2867 
2868     /**
2869      * Disconnect from an application service.  You will no longer receive
2870      * calls as the service is restarted, and the service is now allowed to
2871      * stop at any time.
2872      *
2873      * @param conn The connection interface previously supplied to
2874      *             bindService().  This parameter must not be null.
2875      *
2876      * @see #bindService
2877      */
unbindService(@onNull ServiceConnection conn)2878     public abstract void unbindService(@NonNull ServiceConnection conn);
2879 
2880     /**
2881      * Start executing an {@link android.app.Instrumentation} class.  The given
2882      * Instrumentation component will be run by killing its target application
2883      * (if currently running), starting the target process, instantiating the
2884      * instrumentation component, and then letting it drive the application.
2885      *
2886      * <p>This function is not synchronous -- it returns as soon as the
2887      * instrumentation has started and while it is running.
2888      *
2889      * <p>Instrumentation is normally only allowed to run against a package
2890      * that is either unsigned or signed with a signature that the
2891      * the instrumentation package is also signed with (ensuring the target
2892      * trusts the instrumentation).
2893      *
2894      * @param className Name of the Instrumentation component to be run.
2895      * @param profileFile Optional path to write profiling data as the
2896      * instrumentation runs, or null for no profiling.
2897      * @param arguments Additional optional arguments to pass to the
2898      * instrumentation, or null.
2899      *
2900      * @return {@code true} if the instrumentation was successfully started,
2901      * else {@code false} if it could not be found.
2902      */
startInstrumentation(@onNull ComponentName className, @Nullable String profileFile, @Nullable Bundle arguments)2903     public abstract boolean startInstrumentation(@NonNull ComponentName className,
2904             @Nullable String profileFile, @Nullable Bundle arguments);
2905 
2906     /** @hide */
2907     @StringDef({
2908             POWER_SERVICE,
2909             WINDOW_SERVICE,
2910             LAYOUT_INFLATER_SERVICE,
2911             ACCOUNT_SERVICE,
2912             ACTIVITY_SERVICE,
2913             ALARM_SERVICE,
2914             NOTIFICATION_SERVICE,
2915             ACCESSIBILITY_SERVICE,
2916             CAPTIONING_SERVICE,
2917             KEYGUARD_SERVICE,
2918             LOCATION_SERVICE,
2919             //@hide: COUNTRY_DETECTOR,
2920             SEARCH_SERVICE,
2921             SENSOR_SERVICE,
2922             STORAGE_SERVICE,
2923             STORAGE_STATS_SERVICE,
2924             WALLPAPER_SERVICE,
2925             TIME_ZONE_RULES_MANAGER_SERVICE,
2926             VIBRATOR_SERVICE,
2927             //@hide: STATUS_BAR_SERVICE,
2928             CONNECTIVITY_SERVICE,
2929             IPSEC_SERVICE,
2930             //@hide: UPDATE_LOCK_SERVICE,
2931             //@hide: NETWORKMANAGEMENT_SERVICE,
2932             NETWORK_STATS_SERVICE,
2933             //@hide: NETWORK_POLICY_SERVICE,
2934             WIFI_SERVICE,
2935             WIFI_AWARE_SERVICE,
2936             WIFI_P2P_SERVICE,
2937             WIFI_SCANNING_SERVICE,
2938             //@hide: LOWPAN_SERVICE,
2939             //@hide: WIFI_RTT_SERVICE,
2940             //@hide: ETHERNET_SERVICE,
2941             WIFI_RTT_SERVICE,
2942             NSD_SERVICE,
2943             AUDIO_SERVICE,
2944             FINGERPRINT_SERVICE,
2945             MEDIA_ROUTER_SERVICE,
2946             TELEPHONY_SERVICE,
2947             TELEPHONY_SUBSCRIPTION_SERVICE,
2948             CARRIER_CONFIG_SERVICE,
2949             TELECOM_SERVICE,
2950             CLIPBOARD_SERVICE,
2951             INPUT_METHOD_SERVICE,
2952             TEXT_SERVICES_MANAGER_SERVICE,
2953             TEXT_CLASSIFICATION_SERVICE,
2954             APPWIDGET_SERVICE,
2955             //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
2956             //@hide: BACKUP_SERVICE,
2957             DROPBOX_SERVICE,
2958             //@hide: DEVICE_IDLE_CONTROLLER,
2959             DEVICE_POLICY_SERVICE,
2960             UI_MODE_SERVICE,
2961             DOWNLOAD_SERVICE,
2962             NFC_SERVICE,
2963             BLUETOOTH_SERVICE,
2964             //@hide: SIP_SERVICE,
2965             USB_SERVICE,
2966             LAUNCHER_APPS_SERVICE,
2967             //@hide: SERIAL_SERVICE,
2968             //@hide: HDMI_CONTROL_SERVICE,
2969             INPUT_SERVICE,
2970             DISPLAY_SERVICE,
2971             USER_SERVICE,
2972             RESTRICTIONS_SERVICE,
2973             APP_OPS_SERVICE,
2974             CAMERA_SERVICE,
2975             PRINT_SERVICE,
2976             CONSUMER_IR_SERVICE,
2977             //@hide: TRUST_SERVICE,
2978             TV_INPUT_SERVICE,
2979             //@hide: NETWORK_SCORE_SERVICE,
2980             USAGE_STATS_SERVICE,
2981             MEDIA_SESSION_SERVICE,
2982             BATTERY_SERVICE,
2983             JOB_SCHEDULER_SERVICE,
2984             //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
2985             //@hide: OEM_LOCK_SERVICE,
2986             MEDIA_PROJECTION_SERVICE,
2987             MIDI_SERVICE,
2988             RADIO_SERVICE,
2989             HARDWARE_PROPERTIES_SERVICE,
2990             //@hide: SOUND_TRIGGER_SERVICE,
2991             SHORTCUT_SERVICE,
2992             //@hide: CONTEXTHUB_SERVICE,
2993             SYSTEM_HEALTH_SERVICE,
2994             //@hide: INCIDENT_SERVICE,
2995             COMPANION_DEVICE_SERVICE
2996     })
2997     @Retention(RetentionPolicy.SOURCE)
2998     public @interface ServiceName {}
2999 
3000     /**
3001      * Return the handle to a system-level service by name. The class of the
3002      * returned object varies by the requested name. Currently available names
3003      * are:
3004      *
3005      * <dl>
3006      *  <dt> {@link #WINDOW_SERVICE} ("window")
3007      *  <dd> The top-level window manager in which you can place custom
3008      *  windows.  The returned object is a {@link android.view.WindowManager}.
3009      *  <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
3010      *  <dd> A {@link android.view.LayoutInflater} for inflating layout resources
3011      *  in this context.
3012      *  <dt> {@link #ACTIVITY_SERVICE} ("activity")
3013      *  <dd> A {@link android.app.ActivityManager} for interacting with the
3014      *  global activity state of the system.
3015      *  <dt> {@link #POWER_SERVICE} ("power")
3016      *  <dd> A {@link android.os.PowerManager} for controlling power
3017      *  management.
3018      *  <dt> {@link #ALARM_SERVICE} ("alarm")
3019      *  <dd> A {@link android.app.AlarmManager} for receiving intents at the
3020      *  time of your choosing.
3021      *  <dt> {@link #NOTIFICATION_SERVICE} ("notification")
3022      *  <dd> A {@link android.app.NotificationManager} for informing the user
3023      *   of background events.
3024      *  <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
3025      *  <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
3026      *  <dt> {@link #LOCATION_SERVICE} ("location")
3027      *  <dd> A {@link android.location.LocationManager} for controlling location
3028      *   (e.g., GPS) updates.
3029      *  <dt> {@link #SEARCH_SERVICE} ("search")
3030      *  <dd> A {@link android.app.SearchManager} for handling search.
3031      *  <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
3032      *  <dd> A {@link android.os.Vibrator} for interacting with the vibrator
3033      *  hardware.
3034      *  <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
3035      *  <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
3036      *  handling management of network connections.
3037      *  <dt> {@link #WIFI_SERVICE} ("wifi")
3038      *  <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
3039      *  connectivity.  On releases before NYC, it should only be obtained from an application
3040      *  context, and not from any other derived context to avoid memory leaks within the calling
3041      *  process.
3042      *  <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
3043      *  <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
3044      * Wi-Fi Aware discovery and connectivity.
3045      *  <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
3046      *  <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
3047      * Wi-Fi Direct connectivity.
3048      * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
3049      * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
3050      * for management of input methods.
3051      * <dt> {@link #UI_MODE_SERVICE} ("uimode")
3052      * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
3053      * <dt> {@link #DOWNLOAD_SERVICE} ("download")
3054      * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
3055      * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
3056      * <dd> A {@link android.os.BatteryManager} for managing battery state
3057      * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
3058      * <dd>  A {@link android.app.job.JobScheduler} for managing scheduled tasks
3059      * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
3060      * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
3061      * usage statistics.
3062      * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
3063      * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
3064      * </dl>
3065      *
3066      * <p>Note:  System services obtained via this API may be closely associated with
3067      * the Context in which they are obtained from.  In general, do not share the
3068      * service objects between various different contexts (Activities, Applications,
3069      * Services, Providers, etc.)
3070      *
3071      * @param name The name of the desired service.
3072      *
3073      * @return The service or null if the name does not exist.
3074      *
3075      * @see #WINDOW_SERVICE
3076      * @see android.view.WindowManager
3077      * @see #LAYOUT_INFLATER_SERVICE
3078      * @see android.view.LayoutInflater
3079      * @see #ACTIVITY_SERVICE
3080      * @see android.app.ActivityManager
3081      * @see #POWER_SERVICE
3082      * @see android.os.PowerManager
3083      * @see #ALARM_SERVICE
3084      * @see android.app.AlarmManager
3085      * @see #NOTIFICATION_SERVICE
3086      * @see android.app.NotificationManager
3087      * @see #KEYGUARD_SERVICE
3088      * @see android.app.KeyguardManager
3089      * @see #LOCATION_SERVICE
3090      * @see android.location.LocationManager
3091      * @see #SEARCH_SERVICE
3092      * @see android.app.SearchManager
3093      * @see #SENSOR_SERVICE
3094      * @see android.hardware.SensorManager
3095      * @see #STORAGE_SERVICE
3096      * @see android.os.storage.StorageManager
3097      * @see #VIBRATOR_SERVICE
3098      * @see android.os.Vibrator
3099      * @see #CONNECTIVITY_SERVICE
3100      * @see android.net.ConnectivityManager
3101      * @see #WIFI_SERVICE
3102      * @see android.net.wifi.WifiManager
3103      * @see #AUDIO_SERVICE
3104      * @see android.media.AudioManager
3105      * @see #MEDIA_ROUTER_SERVICE
3106      * @see android.media.MediaRouter
3107      * @see #TELEPHONY_SERVICE
3108      * @see android.telephony.TelephonyManager
3109      * @see #TELEPHONY_SUBSCRIPTION_SERVICE
3110      * @see android.telephony.SubscriptionManager
3111      * @see #CARRIER_CONFIG_SERVICE
3112      * @see android.telephony.CarrierConfigManager
3113      * @see #INPUT_METHOD_SERVICE
3114      * @see android.view.inputmethod.InputMethodManager
3115      * @see #UI_MODE_SERVICE
3116      * @see android.app.UiModeManager
3117      * @see #DOWNLOAD_SERVICE
3118      * @see android.app.DownloadManager
3119      * @see #BATTERY_SERVICE
3120      * @see android.os.BatteryManager
3121      * @see #JOB_SCHEDULER_SERVICE
3122      * @see android.app.job.JobScheduler
3123      * @see #NETWORK_STATS_SERVICE
3124      * @see android.app.usage.NetworkStatsManager
3125      * @see android.os.HardwarePropertiesManager
3126      * @see #HARDWARE_PROPERTIES_SERVICE
3127      */
getSystemService(@erviceName @onNull String name)3128     public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
3129 
3130     /**
3131      * Return the handle to a system-level service by class.
3132      * <p>
3133      * Currently available classes are:
3134      * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
3135      * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
3136      * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
3137      * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
3138      * {@link android.app.SearchManager}, {@link android.os.Vibrator},
3139      * {@link android.net.ConnectivityManager},
3140      * {@link android.net.wifi.WifiManager},
3141      * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
3142      * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
3143      * {@link android.view.inputmethod.InputMethodManager},
3144      * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
3145      * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
3146      * {@link android.app.usage.NetworkStatsManager}.
3147      * </p><p>
3148      * Note: System services obtained via this API may be closely associated with
3149      * the Context in which they are obtained from.  In general, do not share the
3150      * service objects between various different contexts (Activities, Applications,
3151      * Services, Providers, etc.)
3152      * </p>
3153      *
3154      * @param serviceClass The class of the desired service.
3155      * @return The service or null if the class is not a supported system service.
3156      */
3157     @SuppressWarnings("unchecked")
getSystemService(@onNull Class<T> serviceClass)3158     public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) {
3159         // Because subclasses may override getSystemService(String) we cannot
3160         // perform a lookup by class alone.  We must first map the class to its
3161         // service name then invoke the string-based method.
3162         String serviceName = getSystemServiceName(serviceClass);
3163         return serviceName != null ? (T)getSystemService(serviceName) : null;
3164     }
3165 
3166     /**
3167      * Gets the name of the system-level service that is represented by the specified class.
3168      *
3169      * @param serviceClass The class of the desired service.
3170      * @return The service name or null if the class is not a supported system service.
3171      */
getSystemServiceName(@onNull Class<?> serviceClass)3172     public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
3173 
3174     /**
3175      * Use with {@link #getSystemService} to retrieve a
3176      * {@link android.os.PowerManager} for controlling power management,
3177      * including "wake locks," which let you keep the device on while
3178      * you're running long tasks.
3179      */
3180     public static final String POWER_SERVICE = "power";
3181 
3182     /**
3183      * Use with {@link #getSystemService} to retrieve a
3184      * {@link android.os.RecoverySystem} for accessing the recovery system
3185      * service.
3186      *
3187      * @see #getSystemService
3188      * @hide
3189      */
3190     public static final String RECOVERY_SERVICE = "recovery";
3191 
3192     /**
3193      * Use with {@link #getSystemService} to retrieve a
3194      * {@link android.view.WindowManager} for accessing the system's window
3195      * manager.
3196      *
3197      * @see #getSystemService
3198      * @see android.view.WindowManager
3199      */
3200     public static final String WINDOW_SERVICE = "window";
3201 
3202     /**
3203      * Use with {@link #getSystemService} to retrieve a
3204      * {@link android.view.LayoutInflater} for inflating layout resources in this
3205      * context.
3206      *
3207      * @see #getSystemService
3208      * @see android.view.LayoutInflater
3209      */
3210     public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
3211 
3212     /**
3213      * Use with {@link #getSystemService} to retrieve a
3214      * {@link android.accounts.AccountManager} for receiving intents at a
3215      * time of your choosing.
3216      *
3217      * @see #getSystemService
3218      * @see android.accounts.AccountManager
3219      */
3220     public static final String ACCOUNT_SERVICE = "account";
3221 
3222     /**
3223      * Use with {@link #getSystemService} to retrieve a
3224      * {@link android.app.ActivityManager} for interacting with the global
3225      * system state.
3226      *
3227      * @see #getSystemService
3228      * @see android.app.ActivityManager
3229      */
3230     public static final String ACTIVITY_SERVICE = "activity";
3231 
3232     /**
3233      * Use with {@link #getSystemService} to retrieve a
3234      * {@link android.app.AlarmManager} for receiving intents at a
3235      * time of your choosing.
3236      *
3237      * @see #getSystemService
3238      * @see android.app.AlarmManager
3239      */
3240     public static final String ALARM_SERVICE = "alarm";
3241 
3242     /**
3243      * Use with {@link #getSystemService} to retrieve a
3244      * {@link android.app.NotificationManager} for informing the user of
3245      * background events.
3246      *
3247      * @see #getSystemService
3248      * @see android.app.NotificationManager
3249      */
3250     public static final String NOTIFICATION_SERVICE = "notification";
3251 
3252     /**
3253      * Use with {@link #getSystemService} to retrieve a
3254      * {@link android.view.accessibility.AccessibilityManager} for giving the user
3255      * feedback for UI events through the registered event listeners.
3256      *
3257      * @see #getSystemService
3258      * @see android.view.accessibility.AccessibilityManager
3259      */
3260     public static final String ACCESSIBILITY_SERVICE = "accessibility";
3261 
3262     /**
3263      * Use with {@link #getSystemService} to retrieve a
3264      * {@link android.view.accessibility.CaptioningManager} for obtaining
3265      * captioning properties and listening for changes in captioning
3266      * preferences.
3267      *
3268      * @see #getSystemService
3269      * @see android.view.accessibility.CaptioningManager
3270      */
3271     public static final String CAPTIONING_SERVICE = "captioning";
3272 
3273     /**
3274      * Use with {@link #getSystemService} to retrieve a
3275      * {@link android.app.NotificationManager} for controlling keyguard.
3276      *
3277      * @see #getSystemService
3278      * @see android.app.KeyguardManager
3279      */
3280     public static final String KEYGUARD_SERVICE = "keyguard";
3281 
3282     /**
3283      * Use with {@link #getSystemService} to retrieve a {@link
3284      * android.location.LocationManager} for controlling location
3285      * updates.
3286      *
3287      * @see #getSystemService
3288      * @see android.location.LocationManager
3289      */
3290     public static final String LOCATION_SERVICE = "location";
3291 
3292     /**
3293      * Use with {@link #getSystemService} to retrieve a
3294      * {@link android.location.CountryDetector} for detecting the country that
3295      * the user is in.
3296      *
3297      * @hide
3298      */
3299     public static final String COUNTRY_DETECTOR = "country_detector";
3300 
3301     /**
3302      * Use with {@link #getSystemService} to retrieve a {@link
3303      * android.app.SearchManager} for handling searches.
3304      *
3305      * @see #getSystemService
3306      * @see android.app.SearchManager
3307      */
3308     public static final String SEARCH_SERVICE = "search";
3309 
3310     /**
3311      * Use with {@link #getSystemService} to retrieve a {@link
3312      * android.hardware.SensorManager} for accessing sensors.
3313      *
3314      * @see #getSystemService
3315      * @see android.hardware.SensorManager
3316      */
3317     public static final String SENSOR_SERVICE = "sensor";
3318 
3319     /**
3320      * Use with {@link #getSystemService} to retrieve a {@link
3321      * android.os.storage.StorageManager} for accessing system storage
3322      * functions.
3323      *
3324      * @see #getSystemService
3325      * @see android.os.storage.StorageManager
3326      */
3327     public static final String STORAGE_SERVICE = "storage";
3328 
3329     /**
3330      * Use with {@link #getSystemService} to retrieve a {@link
3331      * android.app.usage.StorageStatsManager} for accessing system storage
3332      * statistics.
3333      *
3334      * @see #getSystemService
3335      * @see android.app.usage.StorageStatsManager
3336      */
3337     public static final String STORAGE_STATS_SERVICE = "storagestats";
3338 
3339     /**
3340      * Use with {@link #getSystemService} to retrieve a
3341      * com.android.server.WallpaperService for accessing wallpapers.
3342      *
3343      * @see #getSystemService
3344      */
3345     public static final String WALLPAPER_SERVICE = "wallpaper";
3346 
3347     /**
3348      * Use with {@link #getSystemService} to retrieve a {@link
3349      * android.os.Vibrator} for interacting with the vibration hardware.
3350      *
3351      * @see #getSystemService
3352      * @see android.os.Vibrator
3353      */
3354     public static final String VIBRATOR_SERVICE = "vibrator";
3355 
3356     /**
3357      * Use with {@link #getSystemService} to retrieve a {@link
3358      * android.app.StatusBarManager} for interacting with the status bar.
3359      *
3360      * @see #getSystemService
3361      * @see android.app.StatusBarManager
3362      * @hide
3363      */
3364     public static final String STATUS_BAR_SERVICE = "statusbar";
3365 
3366     /**
3367      * Use with {@link #getSystemService} to retrieve a {@link
3368      * android.net.ConnectivityManager} for handling management of
3369      * network connections.
3370      *
3371      * @see #getSystemService
3372      * @see android.net.ConnectivityManager
3373      */
3374     public static final String CONNECTIVITY_SERVICE = "connectivity";
3375 
3376     /**
3377      * Use with {@link #getSystemService} to retrieve a
3378      * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
3379      * IPSec.
3380      *
3381      * @hide
3382      * @see #getSystemService
3383      */
3384     public static final String IPSEC_SERVICE = "ipsec";
3385 
3386     /**
3387      * Use with {@link #getSystemService} to retrieve a {@link
3388      * android.os.IUpdateLock} for managing runtime sequences that
3389      * must not be interrupted by headless OTA application or similar.
3390      *
3391      * @hide
3392      * @see #getSystemService
3393      * @see android.os.UpdateLock
3394      */
3395     public static final String UPDATE_LOCK_SERVICE = "updatelock";
3396 
3397     /**
3398      * Constant for the internal network management service, not really a Context service.
3399      * @hide
3400      */
3401     public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3402 
3403     /**
3404      * Use with {@link #getSystemService} to retrieve a {@link
3405      * android.app.usage.NetworkStatsManager} for querying network usage stats.
3406      *
3407      * @see #getSystemService
3408      * @see android.app.usage.NetworkStatsManager
3409      */
3410     public static final String NETWORK_STATS_SERVICE = "netstats";
3411     /** {@hide} */
3412     public static final String NETWORK_POLICY_SERVICE = "netpolicy";
3413 
3414     /**
3415      * Use with {@link #getSystemService} to retrieve a {@link
3416      * android.net.wifi.WifiManager} for handling management of
3417      * Wi-Fi access.
3418      *
3419      * @see #getSystemService
3420      * @see android.net.wifi.WifiManager
3421      */
3422     public static final String WIFI_SERVICE = "wifi";
3423 
3424     /**
3425      * Use with {@link #getSystemService} to retrieve a {@link
3426      * android.net.wifi.p2p.WifiP2pManager} for handling management of
3427      * Wi-Fi peer-to-peer connections.
3428      *
3429      * @see #getSystemService
3430      * @see android.net.wifi.p2p.WifiP2pManager
3431      */
3432     public static final String WIFI_P2P_SERVICE = "wifip2p";
3433 
3434     /**
3435      * Use with {@link #getSystemService} to retrieve a
3436      * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
3437      * Wi-Fi Aware.
3438      *
3439      * @see #getSystemService
3440      * @see android.net.wifi.aware.WifiAwareManager
3441      */
3442     public static final String WIFI_AWARE_SERVICE = "wifiaware";
3443 
3444     /**
3445      * Use with {@link #getSystemService} to retrieve a {@link
3446      * android.net.wifi.WifiScanner} for scanning the wifi universe
3447      *
3448      * @see #getSystemService
3449      * @see android.net.wifi.WifiScanner
3450      * @hide
3451      */
3452     @SystemApi
3453     public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3454 
3455     /**
3456      * Use with {@link #getSystemService} to retrieve a {@link
3457      * android.net.wifi.RttManager} for ranging devices with wifi
3458      *
3459      * @see #getSystemService
3460      * @see android.net.wifi.RttManager
3461      * @hide
3462      */
3463     @SystemApi
3464     public static final String WIFI_RTT_SERVICE = "rttmanager";
3465 
3466     /**
3467      * Use with {@link #getSystemService} to retrieve a {@link
3468      * android.net.lowpan.LowpanManager} for handling management of
3469      * LoWPAN access.
3470      *
3471      * @see #getSystemService
3472      * @see android.net.lowpan.LowpanManager
3473      *
3474      * @hide
3475      */
3476     public static final String LOWPAN_SERVICE = "lowpan";
3477 
3478     /**
3479      * Use with {@link #getSystemService} to retrieve a {@link
3480      * android.net.EthernetManager} for handling management of
3481      * Ethernet access.
3482      *
3483      * @see #getSystemService
3484      * @see android.net.EthernetManager
3485      *
3486      * @hide
3487      */
3488     public static final String ETHERNET_SERVICE = "ethernet";
3489 
3490     /**
3491      * Use with {@link #getSystemService} to retrieve a {@link
3492      * android.net.nsd.NsdManager} for handling management of network service
3493      * discovery
3494      *
3495      * @see #getSystemService
3496      * @see android.net.nsd.NsdManager
3497      */
3498     public static final String NSD_SERVICE = "servicediscovery";
3499 
3500     /**
3501      * Use with {@link #getSystemService} to retrieve a
3502      * {@link android.media.AudioManager} for handling management of volume,
3503      * ringer modes and audio routing.
3504      *
3505      * @see #getSystemService
3506      * @see android.media.AudioManager
3507      */
3508     public static final String AUDIO_SERVICE = "audio";
3509 
3510     /**
3511      * Use with {@link #getSystemService} to retrieve a
3512      * {@link android.hardware.fingerprint.FingerprintManager} for handling management
3513      * of fingerprints.
3514      *
3515      * @see #getSystemService
3516      * @see android.hardware.fingerprint.FingerprintManager
3517      */
3518     public static final String FINGERPRINT_SERVICE = "fingerprint";
3519 
3520     /**
3521      * Use with {@link #getSystemService} to retrieve a
3522      * {@link android.media.MediaRouter} for controlling and managing
3523      * routing of media.
3524      *
3525      * @see #getSystemService
3526      * @see android.media.MediaRouter
3527      */
3528     public static final String MEDIA_ROUTER_SERVICE = "media_router";
3529 
3530     /**
3531      * Use with {@link #getSystemService} to retrieve a
3532      * {@link android.media.session.MediaSessionManager} for managing media Sessions.
3533      *
3534      * @see #getSystemService
3535      * @see android.media.session.MediaSessionManager
3536      */
3537     public static final String MEDIA_SESSION_SERVICE = "media_session";
3538 
3539     /**
3540      * Use with {@link #getSystemService} to retrieve a
3541      * {@link android.telephony.TelephonyManager} for handling management the
3542      * telephony features of the device.
3543      *
3544      * @see #getSystemService
3545      * @see android.telephony.TelephonyManager
3546      */
3547     public static final String TELEPHONY_SERVICE = "phone";
3548 
3549     /**
3550      * Use with {@link #getSystemService} to retrieve a
3551      * {@link android.telephony.SubscriptionManager} for handling management the
3552      * telephony subscriptions of the device.
3553      *
3554      * @see #getSystemService
3555      * @see android.telephony.SubscriptionManager
3556      */
3557     public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
3558 
3559     /**
3560      * Use with {@link #getSystemService} to retrieve a
3561      * {@link android.telecom.TelecomManager} to manage telecom-related features
3562      * of the device.
3563      *
3564      * @see #getSystemService
3565      * @see android.telecom.TelecomManager
3566      */
3567     public static final String TELECOM_SERVICE = "telecom";
3568 
3569     /**
3570      * Use with {@link #getSystemService} to retrieve a
3571      * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
3572      *
3573      * @see #getSystemService
3574      * @see android.telephony.CarrierConfigManager
3575      */
3576     public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
3577 
3578     /**
3579      * Use with {@link #getSystemService} to retrieve a
3580      * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
3581      *
3582      * @see #getSystemService
3583      * @see android.telephony.euicc.EuiccManager
3584      * TODO(b/35851809): Unhide this API.
3585      * @hide
3586      */
3587     public static final String EUICC_SERVICE = "euicc_service";
3588 
3589     /**
3590      * Use with {@link #getSystemService} to retrieve a
3591      * {@link android.text.ClipboardManager} for accessing and modifying
3592      * {@link android.content.ClipboardManager} for accessing and modifying
3593      * the contents of the global clipboard.
3594      *
3595      * @see #getSystemService
3596      * @see android.content.ClipboardManager
3597      */
3598     public static final String CLIPBOARD_SERVICE = "clipboard";
3599 
3600     /**
3601      * Use with {@link #getSystemService} to retrieve a
3602      * {@link TextClassificationManager} for text classification services.
3603      *
3604      * @see #getSystemService
3605      * @see TextClassificationManager
3606      */
3607     public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
3608 
3609     /**
3610      * Use with {@link #getSystemService} to retrieve a
3611      * {@link android.view.inputmethod.InputMethodManager} for accessing input
3612      * methods.
3613      *
3614      * @see #getSystemService
3615      */
3616     public static final String INPUT_METHOD_SERVICE = "input_method";
3617 
3618     /**
3619      * Use with {@link #getSystemService} to retrieve a
3620      * {@link android.view.textservice.TextServicesManager} for accessing
3621      * text services.
3622      *
3623      * @see #getSystemService
3624      */
3625     public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
3626 
3627     /**
3628      * Use with {@link #getSystemService} to retrieve a
3629      * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
3630      *
3631      * @see #getSystemService
3632      */
3633     public static final String APPWIDGET_SERVICE = "appwidget";
3634 
3635     /**
3636      * Official published name of the (internal) voice interaction manager service.
3637      *
3638      * @hide
3639      * @see #getSystemService
3640      */
3641     public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
3642 
3643     /**
3644      * Official published name of the (internal) autofill service.
3645      *
3646      * @hide
3647      * @see #getSystemService
3648      */
3649     public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
3650 
3651     /**
3652      * Use with {@link #getSystemService} to access the
3653      * {@link com.android.server.voiceinteraction.SoundTriggerService}.
3654      *
3655      * @hide
3656      * @see #getSystemService
3657      */
3658     public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
3659 
3660 
3661     /**
3662      * Use with {@link #getSystemService} to retrieve an
3663      * {@link android.app.backup.IBackupManager IBackupManager} for communicating
3664      * with the backup mechanism.
3665      * @hide
3666      *
3667      * @see #getSystemService
3668      */
3669     @SystemApi
3670     public static final String BACKUP_SERVICE = "backup";
3671 
3672     /**
3673      * Use with {@link #getSystemService} to retrieve a
3674      * {@link android.os.DropBoxManager} instance for recording
3675      * diagnostic logs.
3676      * @see #getSystemService
3677      */
3678     public static final String DROPBOX_SERVICE = "dropbox";
3679 
3680     /**
3681      * System service name for the DeviceIdleController.  There is no Java API for this.
3682      * @see #getSystemService
3683      * @hide
3684      */
3685     public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
3686 
3687     /**
3688      * Use with {@link #getSystemService} to retrieve a
3689      * {@link android.app.admin.DevicePolicyManager} for working with global
3690      * device policy management.
3691      *
3692      * @see #getSystemService
3693      */
3694     public static final String DEVICE_POLICY_SERVICE = "device_policy";
3695 
3696     /**
3697      * Use with {@link #getSystemService} to retrieve a
3698      * {@link android.app.UiModeManager} for controlling UI modes.
3699      *
3700      * @see #getSystemService
3701      */
3702     public static final String UI_MODE_SERVICE = "uimode";
3703 
3704     /**
3705      * Use with {@link #getSystemService} to retrieve a
3706      * {@link android.app.DownloadManager} for requesting HTTP downloads.
3707      *
3708      * @see #getSystemService
3709      */
3710     public static final String DOWNLOAD_SERVICE = "download";
3711 
3712     /**
3713      * Use with {@link #getSystemService} to retrieve a
3714      * {@link android.os.BatteryManager} for managing battery state.
3715      *
3716      * @see #getSystemService
3717      */
3718     public static final String BATTERY_SERVICE = "batterymanager";
3719 
3720     /**
3721      * Use with {@link #getSystemService} to retrieve a
3722      * {@link android.nfc.NfcManager} for using NFC.
3723      *
3724      * @see #getSystemService
3725      */
3726     public static final String NFC_SERVICE = "nfc";
3727 
3728     /**
3729      * Use with {@link #getSystemService} to retrieve a
3730      * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
3731      *
3732      * @see #getSystemService
3733      */
3734     public static final String BLUETOOTH_SERVICE = "bluetooth";
3735 
3736     /**
3737      * Use with {@link #getSystemService} to retrieve a
3738      * {@link android.net.sip.SipManager} for accessing the SIP related service.
3739      *
3740      * @see #getSystemService
3741      */
3742     /** @hide */
3743     public static final String SIP_SERVICE = "sip";
3744 
3745     /**
3746      * Use with {@link #getSystemService} to retrieve a {@link
3747      * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
3748      * and for controlling this device's behavior as a USB device.
3749      *
3750      * @see #getSystemService
3751      * @see android.hardware.usb.UsbManager
3752      */
3753     public static final String USB_SERVICE = "usb";
3754 
3755     /**
3756      * Use with {@link #getSystemService} to retrieve a {@link
3757      * android.hardware.SerialManager} for access to serial ports.
3758      *
3759      * @see #getSystemService
3760      * @see android.hardware.SerialManager
3761      *
3762      * @hide
3763      */
3764     public static final String SERIAL_SERVICE = "serial";
3765 
3766     /**
3767      * Use with {@link #getSystemService} to retrieve a
3768      * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
3769      * HDMI-CEC protocol.
3770      *
3771      * @see #getSystemService
3772      * @see android.hardware.hdmi.HdmiControlManager
3773      * @hide
3774      */
3775     @SystemApi
3776     public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
3777 
3778     /**
3779      * Use with {@link #getSystemService} to retrieve a
3780      * {@link android.hardware.input.InputManager} for interacting with input devices.
3781      *
3782      * @see #getSystemService
3783      * @see android.hardware.input.InputManager
3784      */
3785     public static final String INPUT_SERVICE = "input";
3786 
3787     /**
3788      * Use with {@link #getSystemService} to retrieve a
3789      * {@link android.hardware.display.DisplayManager} for interacting with display devices.
3790      *
3791      * @see #getSystemService
3792      * @see android.hardware.display.DisplayManager
3793      */
3794     public static final String DISPLAY_SERVICE = "display";
3795 
3796     /**
3797      * Use with {@link #getSystemService} to retrieve a
3798      * {@link android.os.UserManager} for managing users on devices that support multiple users.
3799      *
3800      * @see #getSystemService
3801      * @see android.os.UserManager
3802      */
3803     public static final String USER_SERVICE = "user";
3804 
3805     /**
3806      * Use with {@link #getSystemService} to retrieve a
3807      * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
3808      * profiles of a user.
3809      *
3810      * @see #getSystemService
3811      * @see android.content.pm.LauncherApps
3812      */
3813     public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
3814 
3815     /**
3816      * Use with {@link #getSystemService} to retrieve a
3817      * {@link android.content.RestrictionsManager} for retrieving application restrictions
3818      * and requesting permissions for restricted operations.
3819      * @see #getSystemService
3820      * @see android.content.RestrictionsManager
3821      */
3822     public static final String RESTRICTIONS_SERVICE = "restrictions";
3823 
3824     /**
3825      * Use with {@link #getSystemService} to retrieve a
3826      * {@link android.app.AppOpsManager} for tracking application operations
3827      * on the device.
3828      *
3829      * @see #getSystemService
3830      * @see android.app.AppOpsManager
3831      */
3832     public static final String APP_OPS_SERVICE = "appops";
3833 
3834     /**
3835      * Use with {@link #getSystemService} to retrieve a
3836      * {@link android.hardware.camera2.CameraManager} for interacting with
3837      * camera devices.
3838      *
3839      * @see #getSystemService
3840      * @see android.hardware.camera2.CameraManager
3841      */
3842     public static final String CAMERA_SERVICE = "camera";
3843 
3844     /**
3845      * {@link android.print.PrintManager} for printing and managing
3846      * printers and print tasks.
3847      *
3848      * @see #getSystemService
3849      * @see android.print.PrintManager
3850      */
3851     public static final String PRINT_SERVICE = "print";
3852 
3853     /**
3854      * Use with {@link #getSystemService} to retrieve a
3855      * {@link android.companion.CompanionDeviceManager} for managing companion devices
3856      *
3857      * @see #getSystemService
3858      * @see android.companion.CompanionDeviceManager
3859      */
3860     public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
3861 
3862     /**
3863      * Use with {@link #getSystemService} to retrieve a
3864      * {@link android.hardware.ConsumerIrManager} for transmitting infrared
3865      * signals from the device.
3866      *
3867      * @see #getSystemService
3868      * @see android.hardware.ConsumerIrManager
3869      */
3870     public static final String CONSUMER_IR_SERVICE = "consumer_ir";
3871 
3872     /**
3873      * {@link android.app.trust.TrustManager} for managing trust agents.
3874      * @see #getSystemService
3875      * @see android.app.trust.TrustManager
3876      * @hide
3877      */
3878     public static final String TRUST_SERVICE = "trust";
3879 
3880     /**
3881      * Use with {@link #getSystemService} to retrieve a
3882      * {@link android.media.tv.TvInputManager} for interacting with TV inputs
3883      * on the device.
3884      *
3885      * @see #getSystemService
3886      * @see android.media.tv.TvInputManager
3887      */
3888     public static final String TV_INPUT_SERVICE = "tv_input";
3889 
3890     /**
3891      * {@link android.net.NetworkScoreManager} for managing network scoring.
3892      * @see #getSystemService
3893      * @see android.net.NetworkScoreManager
3894      * @hide
3895      */
3896     @SystemApi
3897     public static final String NETWORK_SCORE_SERVICE = "network_score";
3898 
3899     /**
3900      * Use with {@link #getSystemService} to retrieve a {@link
3901      * android.app.usage.UsageStatsManager} for querying device usage stats.
3902      *
3903      * @see #getSystemService
3904      * @see android.app.usage.UsageStatsManager
3905      */
3906     public static final String USAGE_STATS_SERVICE = "usagestats";
3907 
3908     /**
3909      * Use with {@link #getSystemService} to retrieve a {@link
3910      * android.app.job.JobScheduler} instance for managing occasional
3911      * background tasks.
3912      * @see #getSystemService
3913      * @see android.app.job.JobScheduler
3914      */
3915     public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
3916 
3917     /**
3918      * Use with {@link #getSystemService} to retrieve a {@link
3919      * android.service.persistentdata.PersistentDataBlockManager} instance
3920      * for interacting with a storage device that lives across factory resets.
3921      *
3922      * @see #getSystemService
3923      * @see android.service.persistentdata.PersistentDataBlockManager
3924      * @hide
3925      */
3926     @SystemApi
3927     public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
3928 
3929     /**
3930      * Use with {@link #getSystemService} to retrieve a {@link
3931      * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
3932      *
3933      * @see #getSystemService
3934      * @see android.service.oemlock.OemLockManager
3935      * @hide
3936      */
3937     @SystemApi
3938     public static final String OEM_LOCK_SERVICE = "oem_lock";
3939 
3940     /**
3941      * Use with {@link #getSystemService} to retrieve a {@link
3942      * android.media.projection.MediaProjectionManager} instance for managing
3943      * media projection sessions.
3944      * @see #getSystemService
3945      * @see android.media.projection.MediaProjectionManager
3946      */
3947     public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
3948 
3949     /**
3950      * Use with {@link #getSystemService} to retrieve a
3951      * {@link android.media.midi.MidiManager} for accessing the MIDI service.
3952      *
3953      * @see #getSystemService
3954      */
3955     public static final String MIDI_SERVICE = "midi";
3956 
3957 
3958     /**
3959      * Use with {@link #getSystemService} to retrieve a
3960      * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
3961      *
3962      * @see #getSystemService
3963      * @hide
3964      */
3965     public static final String RADIO_SERVICE = "broadcastradio";
3966 
3967     /**
3968      * Use with {@link #getSystemService} to retrieve a
3969      * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
3970      *
3971      * @see #getSystemService
3972      */
3973     public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
3974 
3975     /**
3976      * Use with {@link #getSystemService} to retrieve a
3977      * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
3978      *
3979      * @see #getSystemService
3980      * @see android.content.pm.ShortcutManager
3981      */
3982     public static final String SHORTCUT_SERVICE = "shortcut";
3983 
3984     /**
3985      * Use with {@link #getSystemService} to retrieve a {@link
3986      * android.hardware.location.ContextHubManager} for accessing context hubs.
3987      *
3988      * @see #getSystemService
3989      * @see android.hardware.location.ContextHubManager
3990      *
3991      * @hide
3992      */
3993     @SystemApi
3994     public static final String CONTEXTHUB_SERVICE = "contexthub";
3995 
3996     /**
3997      * Use with {@link #getSystemService} to retrieve a
3998      * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
3999      * memory, etc) metrics.
4000      *
4001      * @see #getSystemService
4002      */
4003     public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
4004 
4005     /**
4006      * Gatekeeper Service.
4007      * @hide
4008      */
4009     public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
4010 
4011     /**
4012      * Service defining the policy for access to device identifiers.
4013      * @hide
4014      */
4015     public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
4016 
4017     /**
4018      * Service to report a system health "incident"
4019      * @hide
4020      */
4021     public static final String INCIDENT_SERVICE = "incident";
4022 
4023     /**
4024      * Use with {@link #getSystemService} to retrieve a {@link
4025      * android.content.om.OverlayManager} for managing overlay packages.
4026      *
4027      * @see #getSystemService
4028      * @see android.content.om.OverlayManager
4029      * @hide
4030      */
4031     public static final String OVERLAY_SERVICE = "overlay";
4032 
4033     /**
4034      * Use with {@link #getSystemService} to retrieve a
4035      * {@link VrManager} for accessing the VR service.
4036      *
4037      * @see #getSystemService
4038      * @hide
4039      */
4040     @SystemApi
4041     public static final String VR_SERVICE = "vrmanager";
4042 
4043     /**
4044      * Use with {@link #getSystemService} to retrieve an
4045      * {@link android.app.timezone.ITimeZoneRulesManager}.
4046      * @hide
4047      *
4048      * @see #getSystemService
4049      */
4050     public static final String TIME_ZONE_RULES_MANAGER_SERVICE = "timezone";
4051 
4052     /**
4053      * Determine whether the given permission is allowed for a particular
4054      * process and user ID running in the system.
4055      *
4056      * @param permission The name of the permission being checked.
4057      * @param pid The process ID being checked against.  Must be > 0.
4058      * @param uid The user ID being checked against.  A uid of 0 is the root
4059      * user, which will pass every permission check.
4060      *
4061      * @return {@link PackageManager#PERMISSION_GRANTED} if the given
4062      * pid/uid is allowed that permission, or
4063      * {@link PackageManager#PERMISSION_DENIED} if it is not.
4064      *
4065      * @see PackageManager#checkPermission(String, String)
4066      * @see #checkCallingPermission
4067      */
4068     @CheckResult(suggest="#enforcePermission(String,int,int,String)")
4069     @PackageManager.PermissionResult
checkPermission(@onNull String permission, int pid, int uid)4070     public abstract int checkPermission(@NonNull String permission, int pid, int uid);
4071 
4072     /** @hide */
4073     @PackageManager.PermissionResult
checkPermission(@onNull String permission, int pid, int uid, IBinder callerToken)4074     public abstract int checkPermission(@NonNull String permission, int pid, int uid,
4075             IBinder callerToken);
4076 
4077     /**
4078      * Determine whether the calling process of an IPC you are handling has been
4079      * granted a particular permission.  This is basically the same as calling
4080      * {@link #checkPermission(String, int, int)} with the pid and uid returned
4081      * by {@link android.os.Binder#getCallingPid} and
4082      * {@link android.os.Binder#getCallingUid}.  One important difference
4083      * is that if you are not currently processing an IPC, this function
4084      * will always fail.  This is done to protect against accidentally
4085      * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
4086      * to avoid this protection.
4087      *
4088      * @param permission The name of the permission being checked.
4089      *
4090      * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
4091      * pid/uid is allowed that permission, or
4092      * {@link PackageManager#PERMISSION_DENIED} if it is not.
4093      *
4094      * @see PackageManager#checkPermission(String, String)
4095      * @see #checkPermission
4096      * @see #checkCallingOrSelfPermission
4097      */
4098     @CheckResult(suggest="#enforceCallingPermission(String,String)")
4099     @PackageManager.PermissionResult
checkCallingPermission(@onNull String permission)4100     public abstract int checkCallingPermission(@NonNull String permission);
4101 
4102     /**
4103      * Determine whether the calling process of an IPC <em>or you</em> have been
4104      * granted a particular permission.  This is the same as
4105      * {@link #checkCallingPermission}, except it grants your own permissions
4106      * if you are not currently processing an IPC.  Use with care!
4107      *
4108      * @param permission The name of the permission being checked.
4109      *
4110      * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
4111      * pid/uid is allowed that permission, or
4112      * {@link PackageManager#PERMISSION_DENIED} if it is not.
4113      *
4114      * @see PackageManager#checkPermission(String, String)
4115      * @see #checkPermission
4116      * @see #checkCallingPermission
4117      */
4118     @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
4119     @PackageManager.PermissionResult
checkCallingOrSelfPermission(@onNull String permission)4120     public abstract int checkCallingOrSelfPermission(@NonNull String permission);
4121 
4122     /**
4123      * Determine whether <em>you</em> have been granted a particular permission.
4124      *
4125      * @param permission The name of the permission being checked.
4126      *
4127      * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
4128      * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
4129      *
4130      * @see PackageManager#checkPermission(String, String)
4131      * @see #checkCallingPermission(String)
4132      */
4133     @PackageManager.PermissionResult
checkSelfPermission(@onNull String permission)4134     public abstract int checkSelfPermission(@NonNull String permission);
4135 
4136     /**
4137      * If the given permission is not allowed for a particular process
4138      * and user ID running in the system, throw a {@link SecurityException}.
4139      *
4140      * @param permission The name of the permission being checked.
4141      * @param pid The process ID being checked against.  Must be &gt; 0.
4142      * @param uid The user ID being checked against.  A uid of 0 is the root
4143      * user, which will pass every permission check.
4144      * @param message A message to include in the exception if it is thrown.
4145      *
4146      * @see #checkPermission(String, int, int)
4147      */
enforcePermission( @onNull String permission, int pid, int uid, @Nullable String message)4148     public abstract void enforcePermission(
4149             @NonNull String permission, int pid, int uid, @Nullable String message);
4150 
4151     /**
4152      * If the calling process of an IPC you are handling has not been
4153      * granted a particular permission, throw a {@link
4154      * SecurityException}.  This is basically the same as calling
4155      * {@link #enforcePermission(String, int, int, String)} with the
4156      * pid and uid returned by {@link android.os.Binder#getCallingPid}
4157      * and {@link android.os.Binder#getCallingUid}.  One important
4158      * difference is that if you are not currently processing an IPC,
4159      * this function will always throw the SecurityException.  This is
4160      * done to protect against accidentally leaking permissions; you
4161      * can use {@link #enforceCallingOrSelfPermission} to avoid this
4162      * protection.
4163      *
4164      * @param permission The name of the permission being checked.
4165      * @param message A message to include in the exception if it is thrown.
4166      *
4167      * @see #checkCallingPermission(String)
4168      */
enforceCallingPermission( @onNull String permission, @Nullable String message)4169     public abstract void enforceCallingPermission(
4170             @NonNull String permission, @Nullable String message);
4171 
4172     /**
4173      * If neither you nor the calling process of an IPC you are
4174      * handling has been granted a particular permission, throw a
4175      * {@link SecurityException}.  This is the same as {@link
4176      * #enforceCallingPermission}, except it grants your own
4177      * permissions if you are not currently processing an IPC.  Use
4178      * with care!
4179      *
4180      * @param permission The name of the permission being checked.
4181      * @param message A message to include in the exception if it is thrown.
4182      *
4183      * @see #checkCallingOrSelfPermission(String)
4184      */
enforceCallingOrSelfPermission( @onNull String permission, @Nullable String message)4185     public abstract void enforceCallingOrSelfPermission(
4186             @NonNull String permission, @Nullable String message);
4187 
4188     /**
4189      * Grant permission to access a specific Uri to another package, regardless
4190      * of whether that package has general permission to access the Uri's
4191      * content provider.  This can be used to grant specific, temporary
4192      * permissions, typically in response to user interaction (such as the
4193      * user opening an attachment that you would like someone else to
4194      * display).
4195      *
4196      * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
4197      * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4198      * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
4199      * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
4200      * start an activity instead of this function directly.  If you use this
4201      * function directly, you should be sure to call
4202      * {@link #revokeUriPermission} when the target should no longer be allowed
4203      * to access it.
4204      *
4205      * <p>To succeed, the content provider owning the Uri must have set the
4206      * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
4207      * grantUriPermissions} attribute in its manifest or included the
4208      * {@link android.R.styleable#AndroidManifestGrantUriPermission
4209      * &lt;grant-uri-permissions&gt;} tag.
4210      *
4211      * @param toPackage The package you would like to allow to access the Uri.
4212      * @param uri The Uri you would like to grant access to.
4213      * @param modeFlags The desired access modes.
4214      *
4215      * @see #revokeUriPermission
4216      */
grantUriPermission(String toPackage, Uri uri, @Intent.GrantUriMode int modeFlags)4217     public abstract void grantUriPermission(String toPackage, Uri uri,
4218             @Intent.GrantUriMode int modeFlags);
4219 
4220     /**
4221      * Remove all permissions to access a particular content provider Uri
4222      * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
4223      * The given Uri will match all previously granted Uris that are the same or a
4224      * sub-path of the given Uri.  That is, revoking "content://foo/target" will
4225      * revoke both "content://foo/target" and "content://foo/target/sub", but not
4226      * "content://foo".  It will not remove any prefix grants that exist at a
4227      * higher level.
4228      *
4229      * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
4230      * regular permission access to a Uri, but had received access to it through
4231      * a specific Uri permission grant, you could not revoke that grant with this
4232      * function and a {@link SecurityException} would be thrown.  As of
4233      * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
4234      * exception, but will remove whatever permission grants to the Uri had been given to the app
4235      * (or none).</p>
4236      *
4237      * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
4238      * grants matching the given Uri, for any package they had been granted to, through any
4239      * mechanism this had happened (such as indirectly through the clipboard, activity launch,
4240      * service start, etc).  That means this can be potentially dangerous to use, as it can
4241      * revoke grants that another app could be strongly expecting to stick around.</p>
4242      *
4243      * @param uri The Uri you would like to revoke access to.
4244      * @param modeFlags The access modes to revoke.
4245      *
4246      * @see #grantUriPermission
4247      */
revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags)4248     public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
4249 
4250     /**
4251      * Remove permissions to access a particular content provider Uri
4252      * that were previously added with {@link #grantUriPermission} for a specific target
4253      * package.  The given Uri will match all previously granted Uris that are the same or a
4254      * sub-path of the given Uri.  That is, revoking "content://foo/target" will
4255      * revoke both "content://foo/target" and "content://foo/target/sub", but not
4256      * "content://foo".  It will not remove any prefix grants that exist at a
4257      * higher level.
4258      *
4259      * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
4260      * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
4261      * and only for the package specified.  Any matching grants that have happened through
4262      * other mechanisms (clipboard, activity launching, service starting, etc) will not be
4263      * removed.</p>
4264      *
4265      * @param toPackage The package you had previously granted access to.
4266      * @param uri The Uri you would like to revoke access to.
4267      * @param modeFlags The access modes to revoke.
4268      *
4269      * @see #grantUriPermission
4270      */
revokeUriPermission(String toPackage, Uri uri, @Intent.AccessUriMode int modeFlags)4271     public abstract void revokeUriPermission(String toPackage, Uri uri,
4272             @Intent.AccessUriMode int modeFlags);
4273 
4274     /**
4275      * Determine whether a particular process and user ID has been granted
4276      * permission to access a specific URI.  This only checks for permissions
4277      * that have been explicitly granted -- if the given process/uid has
4278      * more general access to the URI's content provider then this check will
4279      * always fail.
4280      *
4281      * @param uri The uri that is being checked.
4282      * @param pid The process ID being checked against.  Must be &gt; 0.
4283      * @param uid The user ID being checked against.  A uid of 0 is the root
4284      * user, which will pass every permission check.
4285      * @param modeFlags The access modes to check.
4286      *
4287      * @return {@link PackageManager#PERMISSION_GRANTED} if the given
4288      * pid/uid is allowed to access that uri, or
4289      * {@link PackageManager#PERMISSION_DENIED} if it is not.
4290      *
4291      * @see #checkCallingUriPermission
4292      */
4293     @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
4294     @PackageManager.PermissionResult
checkUriPermission(Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags)4295     public abstract int checkUriPermission(Uri uri, int pid, int uid,
4296             @Intent.AccessUriMode int modeFlags);
4297 
4298     /** @hide */
4299     @PackageManager.PermissionResult
checkUriPermission(Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, IBinder callerToken)4300     public abstract int checkUriPermission(Uri uri, int pid, int uid,
4301             @Intent.AccessUriMode int modeFlags, IBinder callerToken);
4302 
4303     /**
4304      * Determine whether the calling process and user ID has been
4305      * granted permission to access a specific URI.  This is basically
4306      * the same as calling {@link #checkUriPermission(Uri, int, int,
4307      * int)} with the pid and uid returned by {@link
4308      * android.os.Binder#getCallingPid} and {@link
4309      * android.os.Binder#getCallingUid}.  One important difference is
4310      * that if you are not currently processing an IPC, this function
4311      * will always fail.
4312      *
4313      * @param uri The uri that is being checked.
4314      * @param modeFlags The access modes to check.
4315      *
4316      * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
4317      * is allowed to access that uri, or
4318      * {@link PackageManager#PERMISSION_DENIED} if it is not.
4319      *
4320      * @see #checkUriPermission(Uri, int, int, int)
4321      */
4322     @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
4323     @PackageManager.PermissionResult
checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags)4324     public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
4325 
4326     /**
4327      * Determine whether the calling process of an IPC <em>or you</em> has been granted
4328      * permission to access a specific URI.  This is the same as
4329      * {@link #checkCallingUriPermission}, except it grants your own permissions
4330      * if you are not currently processing an IPC.  Use with care!
4331      *
4332      * @param uri The uri that is being checked.
4333      * @param modeFlags The access modes to check.
4334      *
4335      * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
4336      * is allowed to access that uri, or
4337      * {@link PackageManager#PERMISSION_DENIED} if it is not.
4338      *
4339      * @see #checkCallingUriPermission
4340      */
4341     @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
4342     @PackageManager.PermissionResult
checkCallingOrSelfUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags)4343     public abstract int checkCallingOrSelfUriPermission(Uri uri,
4344             @Intent.AccessUriMode int modeFlags);
4345 
4346     /**
4347      * Check both a Uri and normal permission.  This allows you to perform
4348      * both {@link #checkPermission} and {@link #checkUriPermission} in one
4349      * call.
4350      *
4351      * @param uri The Uri whose permission is to be checked, or null to not
4352      * do this check.
4353      * @param readPermission The permission that provides overall read access,
4354      * or null to not do this check.
4355      * @param writePermission The permission that provides overall write
4356      * access, or null to not do this check.
4357      * @param pid The process ID being checked against.  Must be &gt; 0.
4358      * @param uid The user ID being checked against.  A uid of 0 is the root
4359      * user, which will pass every permission check.
4360      * @param modeFlags The access modes to check.
4361      *
4362      * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
4363      * is allowed to access that uri or holds one of the given permissions, or
4364      * {@link PackageManager#PERMISSION_DENIED} if it is not.
4365      */
4366     @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
4367     @PackageManager.PermissionResult
checkUriPermission(@ullable Uri uri, @Nullable String readPermission, @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags)4368     public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
4369             @Nullable String writePermission, int pid, int uid,
4370             @Intent.AccessUriMode int modeFlags);
4371 
4372     /**
4373      * If a particular process and user ID has not been granted
4374      * permission to access a specific URI, throw {@link
4375      * SecurityException}.  This only checks for permissions that have
4376      * been explicitly granted -- if the given process/uid has more
4377      * general access to the URI's content provider then this check
4378      * will always fail.
4379      *
4380      * @param uri The uri that is being checked.
4381      * @param pid The process ID being checked against.  Must be &gt; 0.
4382      * @param uid The user ID being checked against.  A uid of 0 is the root
4383      * user, which will pass every permission check.
4384      * @param modeFlags The access modes to enforce.
4385      * @param message A message to include in the exception if it is thrown.
4386      *
4387      * @see #checkUriPermission(Uri, int, int, int)
4388      */
enforceUriPermission( Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message)4389     public abstract void enforceUriPermission(
4390             Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
4391 
4392     /**
4393      * If the calling process and user ID has not been granted
4394      * permission to access a specific URI, throw {@link
4395      * SecurityException}.  This is basically the same as calling
4396      * {@link #enforceUriPermission(Uri, int, int, int, String)} with
4397      * the pid and uid returned by {@link
4398      * android.os.Binder#getCallingPid} and {@link
4399      * android.os.Binder#getCallingUid}.  One important difference is
4400      * that if you are not currently processing an IPC, this function
4401      * will always throw a SecurityException.
4402      *
4403      * @param uri The uri that is being checked.
4404      * @param modeFlags The access modes to enforce.
4405      * @param message A message to include in the exception if it is thrown.
4406      *
4407      * @see #checkCallingUriPermission(Uri, int)
4408      */
enforceCallingUriPermission( Uri uri, @Intent.AccessUriMode int modeFlags, String message)4409     public abstract void enforceCallingUriPermission(
4410             Uri uri, @Intent.AccessUriMode int modeFlags, String message);
4411 
4412     /**
4413      * If the calling process of an IPC <em>or you</em> has not been
4414      * granted permission to access a specific URI, throw {@link
4415      * SecurityException}.  This is the same as {@link
4416      * #enforceCallingUriPermission}, except it grants your own
4417      * permissions if you are not currently processing an IPC.  Use
4418      * with care!
4419      *
4420      * @param uri The uri that is being checked.
4421      * @param modeFlags The access modes to enforce.
4422      * @param message A message to include in the exception if it is thrown.
4423      *
4424      * @see #checkCallingOrSelfUriPermission(Uri, int)
4425      */
enforceCallingOrSelfUriPermission( Uri uri, @Intent.AccessUriMode int modeFlags, String message)4426     public abstract void enforceCallingOrSelfUriPermission(
4427             Uri uri, @Intent.AccessUriMode int modeFlags, String message);
4428 
4429     /**
4430      * Enforce both a Uri and normal permission.  This allows you to perform
4431      * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
4432      * call.
4433      *
4434      * @param uri The Uri whose permission is to be checked, or null to not
4435      * do this check.
4436      * @param readPermission The permission that provides overall read access,
4437      * or null to not do this check.
4438      * @param writePermission The permission that provides overall write
4439      * access, or null to not do this check.
4440      * @param pid The process ID being checked against.  Must be &gt; 0.
4441      * @param uid The user ID being checked against.  A uid of 0 is the root
4442      * user, which will pass every permission check.
4443      * @param modeFlags The access modes to enforce.
4444      * @param message A message to include in the exception if it is thrown.
4445      *
4446      * @see #checkUriPermission(Uri, String, String, int, int, int)
4447      */
enforceUriPermission( @ullable Uri uri, @Nullable String readPermission, @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags, @Nullable String message)4448     public abstract void enforceUriPermission(
4449             @Nullable Uri uri, @Nullable String readPermission,
4450             @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
4451             @Nullable String message);
4452 
4453     /** @hide */
4454     @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
4455             CONTEXT_INCLUDE_CODE,
4456             CONTEXT_IGNORE_SECURITY,
4457             CONTEXT_RESTRICTED,
4458             CONTEXT_DEVICE_PROTECTED_STORAGE,
4459             CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
4460             CONTEXT_REGISTER_PACKAGE,
4461     })
4462     @Retention(RetentionPolicy.SOURCE)
4463     public @interface CreatePackageOptions {}
4464 
4465     /**
4466      * Flag for use with {@link #createPackageContext}: include the application
4467      * code with the context.  This means loading code into the caller's
4468      * process, so that {@link #getClassLoader()} can be used to instantiate
4469      * the application's classes.  Setting this flags imposes security
4470      * restrictions on what application context you can access; if the
4471      * requested application can not be safely loaded into your process,
4472      * java.lang.SecurityException will be thrown.  If this flag is not set,
4473      * there will be no restrictions on the packages that can be loaded,
4474      * but {@link #getClassLoader} will always return the default system
4475      * class loader.
4476      */
4477     public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
4478 
4479     /**
4480      * Flag for use with {@link #createPackageContext}: ignore any security
4481      * restrictions on the Context being requested, allowing it to always
4482      * be loaded.  For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
4483      * to be loaded into a process even when it isn't safe to do so.  Use
4484      * with extreme care!
4485      */
4486     public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
4487 
4488     /**
4489      * Flag for use with {@link #createPackageContext}: a restricted context may
4490      * disable specific features. For instance, a View associated with a restricted
4491      * context would ignore particular XML attributes.
4492      */
4493     public static final int CONTEXT_RESTRICTED = 0x00000004;
4494 
4495     /**
4496      * Flag for use with {@link #createPackageContext}: point all file APIs at
4497      * device-protected storage.
4498      *
4499      * @hide
4500      */
4501     public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
4502 
4503     /**
4504      * Flag for use with {@link #createPackageContext}: point all file APIs at
4505      * credential-protected storage.
4506      *
4507      * @hide
4508      */
4509     public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
4510 
4511     /**
4512      * @hide Used to indicate we should tell the activity manager about the process
4513      * loading this code.
4514      */
4515     public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
4516 
4517     /**
4518      * Return a new Context object for the given application name.  This
4519      * Context is the same as what the named application gets when it is
4520      * launched, containing the same resources and class loader.  Each call to
4521      * this method returns a new instance of a Context object; Context objects
4522      * are not shared, however they share common state (Resources, ClassLoader,
4523      * etc) so the Context instance itself is fairly lightweight.
4524      *
4525      * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
4526      * application with the given package name.
4527      *
4528      * <p>Throws {@link java.lang.SecurityException} if the Context requested
4529      * can not be loaded into the caller's process for security reasons (see
4530      * {@link #CONTEXT_INCLUDE_CODE} for more information}.
4531      *
4532      * @param packageName Name of the application's package.
4533      * @param flags Option flags.
4534      *
4535      * @return A {@link Context} for the application.
4536      *
4537      * @throws SecurityException &nbsp;
4538      * @throws PackageManager.NameNotFoundException if there is no application with
4539      * the given package name.
4540      */
createPackageContext(String packageName, @CreatePackageOptions int flags)4541     public abstract Context createPackageContext(String packageName,
4542             @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
4543 
4544     /**
4545      * Similar to {@link #createPackageContext(String, int)}, but with a
4546      * different {@link UserHandle}. For example, {@link #getContentResolver()}
4547      * will open any {@link Uri} as the given user.
4548      *
4549      * @hide
4550      */
createPackageContextAsUser( String packageName, @CreatePackageOptions int flags, UserHandle user)4551     public abstract Context createPackageContextAsUser(
4552             String packageName, @CreatePackageOptions int flags, UserHandle user)
4553             throws PackageManager.NameNotFoundException;
4554 
4555     /**
4556      * Creates a context given an {@link android.content.pm.ApplicationInfo}.
4557      *
4558      * @hide
4559      */
createApplicationContext(ApplicationInfo application, @CreatePackageOptions int flags)4560     public abstract Context createApplicationContext(ApplicationInfo application,
4561             @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
4562 
4563     /**
4564      * Return a new Context object for the given split name. The new Context has a ClassLoader and
4565      * Resources object that can access the split's and all of its dependencies' code/resources.
4566      * Each call to this method returns a new instance of a Context object;
4567      * Context objects are not shared, however common state (ClassLoader, other Resources for
4568      * the same split) may be so the Context itself can be fairly lightweight.
4569      *
4570      * @param splitName The name of the split to include, as declared in the split's
4571      *                  <code>AndroidManifest.xml</code>.
4572      * @return A {@link Context} with the given split's code and/or resources loaded.
4573      */
createContextForSplit(String splitName)4574     public abstract Context createContextForSplit(String splitName)
4575             throws PackageManager.NameNotFoundException;
4576 
4577     /**
4578      * Get the userId associated with this context
4579      * @return user id
4580      *
4581      * @hide
4582      */
4583     @TestApi
getUserId()4584     public abstract @UserIdInt int getUserId();
4585 
4586     /**
4587      * Return a new Context object for the current Context but whose resources
4588      * are adjusted to match the given Configuration.  Each call to this method
4589      * returns a new instance of a Context object; Context objects are not
4590      * shared, however common state (ClassLoader, other Resources for the
4591      * same configuration) may be so the Context itself can be fairly lightweight.
4592      *
4593      * @param overrideConfiguration A {@link Configuration} specifying what
4594      * values to modify in the base Configuration of the original Context's
4595      * resources.  If the base configuration changes (such as due to an
4596      * orientation change), the resources of this context will also change except
4597      * for those that have been explicitly overridden with a value here.
4598      *
4599      * @return A {@link Context} with the given configuration override.
4600      */
createConfigurationContext( @onNull Configuration overrideConfiguration)4601     public abstract Context createConfigurationContext(
4602             @NonNull Configuration overrideConfiguration);
4603 
4604     /**
4605      * Return a new Context object for the current Context but whose resources
4606      * are adjusted to match the metrics of the given Display.  Each call to this method
4607      * returns a new instance of a Context object; Context objects are not
4608      * shared, however common state (ClassLoader, other Resources for the
4609      * same configuration) may be so the Context itself can be fairly lightweight.
4610      *
4611      * The returned display Context provides a {@link WindowManager}
4612      * (see {@link #getSystemService(String)}) that is configured to show windows
4613      * on the given display.  The WindowManager's {@link WindowManager#getDefaultDisplay}
4614      * method can be used to retrieve the Display from the returned Context.
4615      *
4616      * @param display A {@link Display} object specifying the display
4617      * for whose metrics the Context's resources should be tailored and upon which
4618      * new windows should be shown.
4619      *
4620      * @return A {@link Context} for the display.
4621      */
createDisplayContext(@onNull Display display)4622     public abstract Context createDisplayContext(@NonNull Display display);
4623 
4624     /**
4625      * Return a new Context object for the current Context but whose storage
4626      * APIs are backed by device-protected storage.
4627      * <p>
4628      * On devices with direct boot, data stored in this location is encrypted
4629      * with a key tied to the physical device, and it can be accessed
4630      * immediately after the device has booted successfully, both
4631      * <em>before and after</em> the user has authenticated with their
4632      * credentials (such as a lock pattern or PIN).
4633      * <p>
4634      * Because device-protected data is available without user authentication,
4635      * you should carefully limit the data you store using this Context. For
4636      * example, storing sensitive authentication tokens or passwords in the
4637      * device-protected area is strongly discouraged.
4638      * <p>
4639      * If the underlying device does not have the ability to store
4640      * device-protected and credential-protected data using different keys, then
4641      * both storage areas will become available at the same time. They remain as
4642      * two distinct storage locations on disk, and only the window of
4643      * availability changes.
4644      * <p>
4645      * Each call to this method returns a new instance of a Context object;
4646      * Context objects are not shared, however common state (ClassLoader, other
4647      * Resources for the same configuration) may be so the Context itself can be
4648      * fairly lightweight.
4649      *
4650      * @see #isDeviceProtectedStorage()
4651      */
createDeviceProtectedStorageContext()4652     public abstract Context createDeviceProtectedStorageContext();
4653 
4654     /**
4655      * Return a new Context object for the current Context but whose storage
4656      * APIs are backed by credential-protected storage. This is the default
4657      * storage area for apps unless
4658      * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
4659      * <p>
4660      * On devices with direct boot, data stored in this location is encrypted
4661      * with a key tied to user credentials, which can be accessed
4662      * <em>only after</em> the user has entered their credentials (such as a
4663      * lock pattern or PIN).
4664      * <p>
4665      * If the underlying device does not have the ability to store
4666      * device-protected and credential-protected data using different keys, then
4667      * both storage areas will become available at the same time. They remain as
4668      * two distinct storage locations on disk, and only the window of
4669      * availability changes.
4670      * <p>
4671      * Each call to this method returns a new instance of a Context object;
4672      * Context objects are not shared, however common state (ClassLoader, other
4673      * Resources for the same configuration) may be so the Context itself can be
4674      * fairly lightweight.
4675      *
4676      * @see #isCredentialProtectedStorage()
4677      * @hide
4678      */
4679     @SystemApi
createCredentialProtectedStorageContext()4680     public abstract Context createCredentialProtectedStorageContext();
4681 
4682     /**
4683      * Gets the display adjustments holder for this context.  This information
4684      * is provided on a per-application or activity basis and is used to simulate lower density
4685      * display metrics for legacy applications and restricted screen sizes.
4686      *
4687      * @param displayId The display id for which to get compatibility info.
4688      * @return The compatibility info holder, or null if not required by the application.
4689      * @hide
4690      */
getDisplayAdjustments(int displayId)4691     public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
4692 
4693     /**
4694      * @hide
4695      */
getDisplay()4696     public abstract Display getDisplay();
4697 
4698     /**
4699      * @hide
4700      */
updateDisplay(int displayId)4701     public abstract void updateDisplay(int displayId);
4702 
4703     /**
4704      * Indicates whether this Context is restricted.
4705      *
4706      * @return {@code true} if this Context is restricted, {@code false} otherwise.
4707      *
4708      * @see #CONTEXT_RESTRICTED
4709      */
isRestricted()4710     public boolean isRestricted() {
4711         return false;
4712     }
4713 
4714     /**
4715      * Indicates if the storage APIs of this Context are backed by
4716      * device-protected storage.
4717      *
4718      * @see #createDeviceProtectedStorageContext()
4719      */
isDeviceProtectedStorage()4720     public abstract boolean isDeviceProtectedStorage();
4721 
4722     /**
4723      * Indicates if the storage APIs of this Context are backed by
4724      * credential-protected storage.
4725      *
4726      * @see #createCredentialProtectedStorageContext()
4727      * @hide
4728      */
4729     @SystemApi
isCredentialProtectedStorage()4730     public abstract boolean isCredentialProtectedStorage();
4731 
4732     /**
4733      * Returns true if the context can load unsafe resources, e.g. fonts.
4734      * @hide
4735      */
canLoadUnsafeResources()4736     public abstract boolean canLoadUnsafeResources();
4737 
4738     /**
4739      * @hide
4740      */
getActivityToken()4741     public IBinder getActivityToken() {
4742         throw new RuntimeException("Not implemented. Must override in a subclass.");
4743     }
4744 
4745     /**
4746      * @hide
4747      */
4748     @Nullable
getServiceDispatcher(ServiceConnection conn, Handler handler, int flags)4749     public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
4750             int flags) {
4751         throw new RuntimeException("Not implemented. Must override in a subclass.");
4752     }
4753 
4754     /**
4755      * @hide
4756      */
getIApplicationThread()4757     public IApplicationThread getIApplicationThread() {
4758         throw new RuntimeException("Not implemented. Must override in a subclass.");
4759     }
4760 
4761     /**
4762      * @hide
4763      */
getMainThreadHandler()4764     public Handler getMainThreadHandler() {
4765         throw new RuntimeException("Not implemented. Must override in a subclass.");
4766     }
4767 
4768     /**
4769      * @hide
4770      */
getAutofillClient()4771     public AutofillClient getAutofillClient() {
4772         return null;
4773     }
4774 
4775     /**
4776      * @hide
4777      */
setAutofillClient(AutofillClient client)4778     public void setAutofillClient(AutofillClient client) {
4779     }
4780 
4781     /**
4782      * Throws an exception if the Context is using system resources,
4783      * which are non-runtime-overlay-themable and may show inconsistent UI.
4784      * @hide
4785      */
assertRuntimeOverlayThemable()4786     public void assertRuntimeOverlayThemable() {
4787         // Resources.getSystem() is a singleton and the only Resources not managed by
4788         // ResourcesManager; therefore Resources.getSystem() is not themable.
4789         if (getResources() == Resources.getSystem()) {
4790             throw new IllegalArgumentException("Non-UI context used to display UI; "
4791                     + "get a UI context from ActivityThread#getSystemUiContext()");
4792         }
4793     }
4794 }
4795