• 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 static android.app.appfunctions.flags.Flags.FLAG_ENABLE_APP_FUNCTION_MANAGER;
20 import static android.app.ondeviceintelligence.flags.Flags.FLAG_ENABLE_ON_DEVICE_INTELLIGENCE_MODULE;
21 import static android.content.flags.Flags.FLAG_ENABLE_BIND_PACKAGE_ISOLATED_PROCESS;
22 import static android.security.Flags.FLAG_SECURE_LOCKDOWN;
23 
24 import android.annotation.AttrRes;
25 import android.annotation.CallbackExecutor;
26 import android.annotation.CheckResult;
27 import android.annotation.ColorInt;
28 import android.annotation.ColorRes;
29 import android.annotation.DisplayContext;
30 import android.annotation.DrawableRes;
31 import android.annotation.FlaggedApi;
32 import android.annotation.IntDef;
33 import android.annotation.LongDef;
34 import android.annotation.NonNull;
35 import android.annotation.Nullable;
36 import android.annotation.PermissionMethod;
37 import android.annotation.PermissionName;
38 import android.annotation.RequiresFeature;
39 import android.annotation.RequiresPermission;
40 import android.annotation.StringDef;
41 import android.annotation.StringRes;
42 import android.annotation.StyleRes;
43 import android.annotation.StyleableRes;
44 import android.annotation.SuppressLint;
45 import android.annotation.SystemApi;
46 import android.annotation.TestApi;
47 import android.annotation.UiContext;
48 import android.annotation.UserIdInt;
49 import android.app.Activity;
50 import android.app.ActivityManager;
51 import android.app.BroadcastOptions;
52 import android.app.GameManager;
53 import android.app.GrammaticalInflectionManager;
54 import android.app.IApplicationThread;
55 import android.app.IServiceConnection;
56 import android.app.VrManager;
57 import android.app.ambientcontext.AmbientContextManager;
58 import android.app.appfunctions.AppFunctionManager;
59 import android.app.people.PeopleManager;
60 import android.app.time.TimeManager;
61 import android.companion.virtual.VirtualDeviceManager;
62 import android.compat.annotation.ChangeId;
63 import android.compat.annotation.EnabledSince;
64 import android.compat.annotation.UnsupportedAppUsage;
65 import android.content.pm.ApplicationInfo;
66 import android.content.pm.PackageManager;
67 import android.content.res.AssetManager;
68 import android.content.res.ColorStateList;
69 import android.content.res.Configuration;
70 import android.content.res.Resources;
71 import android.content.res.TypedArray;
72 import android.credentials.CredentialManager;
73 import android.database.DatabaseErrorHandler;
74 import android.database.sqlite.SQLiteDatabase;
75 import android.database.sqlite.SQLiteDatabase.CursorFactory;
76 import android.graphics.Bitmap;
77 import android.graphics.drawable.Drawable;
78 import android.net.Uri;
79 import android.os.Build;
80 import android.os.Bundle;
81 import android.os.Environment;
82 import android.os.Flags;
83 import android.os.Handler;
84 import android.os.HandlerExecutor;
85 import android.os.IBinder;
86 import android.os.Looper;
87 import android.os.StatFs;
88 import android.os.UserHandle;
89 import android.os.UserManager;
90 import android.os.storage.StorageManager;
91 import android.provider.E2eeContactKeysManager;
92 import android.provider.MediaStore;
93 import android.ravenwood.annotation.RavenwoodKeep;
94 import android.ravenwood.annotation.RavenwoodKeepPartialClass;
95 import android.telephony.TelephonyRegistryManager;
96 import android.util.AttributeSet;
97 import android.view.Display;
98 import android.view.DisplayAdjustments;
99 import android.view.View;
100 import android.view.ViewDebug;
101 import android.view.ViewGroup.LayoutParams;
102 import android.view.WindowManager;
103 import android.view.WindowManager.LayoutParams.WindowType;
104 import android.view.autofill.AutofillManager.AutofillClient;
105 import android.view.contentcapture.ContentCaptureManager.ContentCaptureClient;
106 import android.view.textclassifier.TextClassificationManager;
107 import android.window.WindowContext;
108 
109 import com.android.internal.annotations.VisibleForTesting;
110 import com.android.internal.compat.IPlatformCompat;
111 import com.android.internal.compat.IPlatformCompatNative;
112 import com.android.internal.protolog.ProtoLogConfigurationService;
113 
114 import java.io.File;
115 import java.io.FileInputStream;
116 import java.io.FileNotFoundException;
117 import java.io.FileOutputStream;
118 import java.io.IOException;
119 import java.io.InputStream;
120 import java.lang.annotation.Retention;
121 import java.lang.annotation.RetentionPolicy;
122 import java.util.Collection;
123 import java.util.Collections;
124 import java.util.List;
125 import java.util.concurrent.Executor;
126 import java.util.function.Consumer;
127 import java.util.function.IntConsumer;
128 
129 /**
130  * Interface to global information about an application environment.  This is
131  * an abstract class whose implementation is provided by
132  * the Android system.  It
133  * allows access to application-specific resources and classes, as well as
134  * up-calls for application-level operations such as launching activities,
135  * broadcasting and receiving intents, etc.
136  */
137 @RavenwoodKeepPartialClass
138 public abstract class Context {
139     /**
140      * After {@link Build.VERSION_CODES#TIRAMISU},
141      * {@link #registerComponentCallbacks(ComponentCallbacks)} will add a {@link ComponentCallbacks}
142      * to {@link Activity} or {@link ContextWrapper#getBaseContext()} instead of always adding to
143      * {@link #getApplicationContext()}.
144      *
145      * @hide
146      */
147     @ChangeId
148     @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
149     @VisibleForTesting
150     public static final long OVERRIDABLE_COMPONENT_CALLBACKS = 193247900L;
151 
152     /**
153      * The default device ID, which is the ID of the primary (non-virtual) device.
154      */
155     public static final int DEVICE_ID_DEFAULT = 0;
156     /**
157      * Invalid device ID.
158      */
159     public static final int DEVICE_ID_INVALID = -1;
160 
161     /** @hide */
162     @IntDef(flag = true, prefix = { "MODE_" }, value = {
163             MODE_PRIVATE,
164             MODE_WORLD_READABLE,
165             MODE_WORLD_WRITEABLE,
166             MODE_APPEND,
167     })
168     @Retention(RetentionPolicy.SOURCE)
169     public @interface FileMode {}
170 
171     /** @hide */
172     @IntDef(flag = true, prefix = { "MODE_" }, value = {
173             MODE_PRIVATE,
174             MODE_WORLD_READABLE,
175             MODE_WORLD_WRITEABLE,
176             MODE_MULTI_PROCESS,
177     })
178     @Retention(RetentionPolicy.SOURCE)
179     public @interface PreferencesMode {}
180 
181     /** @hide */
182     @IntDef(flag = true, prefix = { "MODE_" }, value = {
183             MODE_PRIVATE,
184             MODE_WORLD_READABLE,
185             MODE_WORLD_WRITEABLE,
186             MODE_ENABLE_WRITE_AHEAD_LOGGING,
187             MODE_NO_LOCALIZED_COLLATORS,
188     })
189     @Retention(RetentionPolicy.SOURCE)
190     public @interface DatabaseMode {}
191 
192     /**
193      * File creation mode: the default mode, where the created file can only
194      * be accessed by the calling application (or all applications sharing the
195      * same user ID).
196      */
197     public static final int MODE_PRIVATE = 0x0000;
198 
199     /**
200      * File creation mode: allow all other applications to have read access to
201      * the created file.
202      * <p>
203      * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
204      * mode throws a {@link SecurityException}.
205      *
206      * @deprecated Creating world-readable files is very dangerous, and likely
207      *             to cause security holes in applications. It is strongly
208      *             discouraged; instead, applications should use more formal
209      *             mechanism for interactions such as {@link ContentProvider},
210      *             {@link BroadcastReceiver}, and {@link android.app.Service}.
211      *             There are no guarantees that this access mode will remain on
212      *             a file, such as when it goes through a backup and restore.
213      * @see androidx.core.content.FileProvider
214      * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
215      */
216     @Deprecated
217     public static final int MODE_WORLD_READABLE = 0x0001;
218 
219     /**
220      * File creation mode: allow all other applications to have write access to
221      * the created file.
222      * <p>
223      * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
224      * mode will throw a {@link SecurityException}.
225      *
226      * @deprecated Creating world-writable files is very dangerous, and likely
227      *             to cause security holes in applications. It is strongly
228      *             discouraged; instead, applications should use more formal
229      *             mechanism for interactions such as {@link ContentProvider},
230      *             {@link BroadcastReceiver}, and {@link android.app.Service}.
231      *             There are no guarantees that this access mode will remain on
232      *             a file, such as when it goes through a backup and restore.
233      * @see androidx.core.content.FileProvider
234      * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
235      */
236     @Deprecated
237     public static final int MODE_WORLD_WRITEABLE = 0x0002;
238 
239     /**
240      * File creation mode: for use with {@link #openFileOutput}, if the file
241      * already exists then write data to the end of the existing file
242      * instead of erasing it.
243      * @see #openFileOutput
244      */
245     public static final int MODE_APPEND = 0x8000;
246 
247     /**
248      * SharedPreference loading flag: when set, the file on disk will
249      * be checked for modification even if the shared preferences
250      * instance is already loaded in this process.  This behavior is
251      * sometimes desired in cases where the application has multiple
252      * processes, all writing to the same SharedPreferences file.
253      * Generally there are better forms of communication between
254      * processes, though.
255      *
256      * <p>This was the legacy (but undocumented) behavior in and
257      * before Gingerbread (Android 2.3) and this flag is implied when
258      * targeting such releases.  For applications targeting SDK
259      * versions <em>greater than</em> Android 2.3, this flag must be
260      * explicitly set if desired.
261      *
262      * @see #getSharedPreferences
263      *
264      * @deprecated MODE_MULTI_PROCESS does not work reliably in
265      * some versions of Android, and furthermore does not provide any
266      * mechanism for reconciling concurrent modifications across
267      * processes.  Applications should not attempt to use it.  Instead,
268      * they should use an explicit cross-process data management
269      * approach such as {@link android.content.ContentProvider ContentProvider}.
270      */
271     @Deprecated
272     public static final int MODE_MULTI_PROCESS = 0x0004;
273 
274     /**
275      * Database open flag: when set, the database is opened with write-ahead
276      * logging enabled by default.
277      *
278      * @see #openOrCreateDatabase(String, int, CursorFactory)
279      * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
280      * @see SQLiteDatabase#enableWriteAheadLogging
281      */
282     public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
283 
284     /**
285      * Database open flag: when set, the database is opened without support for
286      * localized collators.
287      *
288      * @see #openOrCreateDatabase(String, int, CursorFactory)
289      * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
290      * @see SQLiteDatabase#NO_LOCALIZED_COLLATORS
291      */
292     public static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010;
293 
294     /**
295      * Flags used for bindService(int) APIs. Note, we now have long BIND_* flags.
296      * @hide
297      */
298     @IntDef(flag = true, prefix = { "BIND_" }, value = {
299             BIND_AUTO_CREATE,
300             BIND_DEBUG_UNBIND,
301             BIND_NOT_FOREGROUND,
302             BIND_ABOVE_CLIENT,
303             BIND_ALLOW_OOM_MANAGEMENT,
304             BIND_WAIVE_PRIORITY,
305             BIND_IMPORTANT,
306             BIND_ADJUST_WITH_ACTIVITY,
307             BIND_NOT_PERCEPTIBLE,
308             BIND_ALLOW_ACTIVITY_STARTS,
309             BIND_INCLUDE_CAPABILITIES,
310             BIND_SHARED_ISOLATED_PROCESS,
311             BIND_PACKAGE_ISOLATED_PROCESS,
312             BIND_EXTERNAL_SERVICE
313     })
314     @Retention(RetentionPolicy.SOURCE)
315     public @interface BindServiceFlagsBits {}
316 
317     /**
318      * Long version of BIND_* flags used for bindService(BindServiceFlags) APIs.
319      * @hide
320      */
321     @LongDef(flag = true, prefix = { "BIND_" }, value = {
322             BIND_AUTO_CREATE,
323             BIND_DEBUG_UNBIND,
324             BIND_NOT_FOREGROUND,
325             BIND_ABOVE_CLIENT,
326             BIND_ALLOW_OOM_MANAGEMENT,
327             BIND_WAIVE_PRIORITY,
328             BIND_IMPORTANT,
329             BIND_ADJUST_WITH_ACTIVITY,
330             BIND_NOT_PERCEPTIBLE,
331             BIND_ALLOW_ACTIVITY_STARTS,
332             BIND_INCLUDE_CAPABILITIES,
333             BIND_SHARED_ISOLATED_PROCESS,
334             BIND_PACKAGE_ISOLATED_PROCESS,
335             // Intentionally not include BIND_EXTERNAL_SERVICE, because it'd cause sign-extension.
336             // This would allow Android Studio to show a warning, if someone tries to use
337             // BIND_EXTERNAL_SERVICE BindServiceFlags.
338             BIND_EXTERNAL_SERVICE_LONG,
339             // Make sure no flag uses the sign bit (most significant bit) of the long integer,
340             // to avoid future confusion.
341             BIND_BYPASS_USER_NETWORK_RESTRICTIONS,
342             BIND_MATCH_QUARANTINED_COMPONENTS,
343     })
344     @Retention(RetentionPolicy.SOURCE)
345     public @interface BindServiceFlagsLongBits {}
346 
347     /**
348      * Specific flags used for bindService() call, which encapsulates a 64 bits long integer.
349      * Call {@link BindServiceFlags#of(long)} to obtain an
350      * object of {@code BindServiceFlags}.
351      */
352     public final static class BindServiceFlags {
353         private final long mValue;
354 
BindServiceFlags(@indServiceFlagsLongBits long value)355         private BindServiceFlags(@BindServiceFlagsLongBits long value) {
356             mValue = value;
357         }
358 
359         /**
360          * @return Return flags in 64 bits long integer.
361          * @hide
362          */
getValue()363         public long getValue() {
364             return mValue;
365         }
366 
367         /**
368          * Build {@link BindServiceFlags} from BIND_* FLAGS.
369          *
370          * Note, {@link #BIND_EXTERNAL_SERVICE} is not supported in this method, because
371          * it has the highest integer bit set and cause wrong flags to be set. Use
372          * {@link #BIND_EXTERNAL_SERVICE_LONG} instead.
373          */
374         @NonNull
of(@indServiceFlagsLongBits long value)375         public static BindServiceFlags of(@BindServiceFlagsLongBits long value) {
376             if ((value & Integer.toUnsignedLong(BIND_EXTERNAL_SERVICE)) != 0){
377                 throw new IllegalArgumentException(
378                         "BIND_EXTERNAL_SERVICE is deprecated. Use BIND_EXTERNAL_SERVICE_LONG"
379                                 + " instead");
380             }
381 
382             return new BindServiceFlags(value);
383         }
384     }
385 
386     /**
387      * Flag for {@link #bindService}: automatically create the service as long
388      * as the binding exists.  Note that while this will create the service,
389      * its {@link android.app.Service#onStartCommand}
390      * method will still only be called due to an
391      * explicit call to {@link #startService}.  Even without that, though,
392      * this still provides you with access to the service object while the
393      * service is created.
394      *
395      * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
396      * not supplying this flag would also impact how important the system
397      * consider's the target service's process to be.  When set, the only way
398      * for it to be raised was by binding from a service in which case it will
399      * only be important when that activity is in the foreground.  Now to
400      * achieve this behavior you must explicitly supply the new flag
401      * {@link #BIND_ADJUST_WITH_ACTIVITY}.  For compatibility, old applications
402      * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
403      * the flags {@link #BIND_WAIVE_PRIORITY} and
404      * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
405      * the same result.
406      */
407     public static final int BIND_AUTO_CREATE = 0x0001;
408 
409     /**
410      * Flag for {@link #bindService}: include debugging help for mismatched
411      * calls to unbind.  When this flag is set, the callstack of the following
412      * {@link #unbindService} call is retained, to be printed if a later
413      * incorrect unbind call is made.  Note that doing this requires retaining
414      * information about the binding that was made for the lifetime of the app,
415      * resulting in a leak -- this should only be used for debugging.
416      */
417     public static final int BIND_DEBUG_UNBIND = 0x0002;
418 
419     /**
420      * Flag for {@link #bindService}: don't allow this binding to raise
421      * the target service's process to the foreground scheduling priority.
422      * It will still be raised to at least the same memory priority
423      * as the client (so that its process will not be killable in any
424      * situation where the client is not killable), but for CPU scheduling
425      * purposes it may be left in the background.  This only has an impact
426      * in the situation where the binding client is a foreground process
427      * and the target service is in a background process.
428      */
429     public static final int BIND_NOT_FOREGROUND = 0x0004;
430 
431     /**
432      * Flag for {@link #bindService}: indicates that the client application
433      * binding to this service considers the service to be more important than
434      * the app itself.  When set, the platform will try to have the out of
435      * memory killer kill the app before it kills the service it is bound to, though
436      * this is not guaranteed to be the case.
437      */
438     public static final int BIND_ABOVE_CLIENT = 0x0008;
439 
440     /**
441      * Flag for {@link #bindService}: allow the process hosting the bound
442      * service to go through its normal memory management.  It will be
443      * treated more like a running service, allowing the system to
444      * (temporarily) expunge the process if low on memory or for some other
445      * whim it may have, and being more aggressive about making it a candidate
446      * to be killed (and restarted) if running for a long time.
447      */
448     public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
449 
450     /**
451      * Flag for {@link #bindService}: don't impact the scheduling or
452      * memory management priority of the target service's hosting process.
453      * Allows the service's process to be managed on the background LRU list
454      * just like a regular application process in the background.
455      */
456     public static final int BIND_WAIVE_PRIORITY = 0x0020;
457 
458     /**
459      * Flag for {@link #bindService}: this service is very important to
460      * the client, so should be brought to the foreground process level
461      * when the client is.  Normally a process can only be raised to the
462      * visibility level by a client, even if that client is in the foreground.
463      */
464     public static final int BIND_IMPORTANT = 0x0040;
465 
466     /**
467      * Flag for {@link #bindService}: If binding from an activity, allow the
468      * target service's process importance to be raised based on whether the
469      * activity is visible to the user, regardless whether another flag is
470      * used to reduce the amount that the client process's overall importance
471      * is used to impact it.
472      */
473     public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
474 
475     /**
476      * Flag for {@link #bindService}: If binding from an app that is visible or user-perceptible,
477      * lower the target service's importance to below the perceptible level. This allows
478      * the system to (temporarily) expunge the bound process from memory to make room for more
479      * important user-perceptible processes.
480      */
481     public static final int BIND_NOT_PERCEPTIBLE = 0x00000100;
482 
483     /**
484      * Flag for {@link #bindService}: If binding from an app that is visible, the bound service is
485      * allowed to start an activity from background. This was the default behavior before SDK
486      * version {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}. Since then, the default
487      * behavior changed to disallow the bound service to start a background activity even if the app
488      * bound to it is in foreground, unless this flag is specified when binding.
489      */
490     public static final int BIND_ALLOW_ACTIVITY_STARTS = 0X000000200;
491 
492     /**
493      * Flag for {@link #bindService}: If binding from an app that has specific capabilities
494      * due to its foreground state such as an activity or foreground service, then this flag will
495      * allow the bound app to get the same capabilities, as long as it has the required permissions
496      * as well.
497      *
498      * If binding from a top app and its target SDK version is at or above
499      * {@link android.os.Build.VERSION_CODES#R}, the app needs to
500      * explicitly use BIND_INCLUDE_CAPABILITIES flag to pass all capabilities to the service so the
501      * other app can have while-in-use access such as location, camera, microphone from background.
502      * If binding from a top app and its target SDK version is below
503      * {@link android.os.Build.VERSION_CODES#R}, BIND_INCLUDE_CAPABILITIES is implicit.
504      */
505     public static final int BIND_INCLUDE_CAPABILITIES = 0x000001000;
506 
507     /**
508      * Flag for {@link #bindIsolatedService}: Bind the service into a shared isolated process.
509      * Specifying this flag allows multiple isolated services to be running in a single shared
510      * isolated process.
511      *
512      * The shared isolated process instance is identified by the <var>instanceName</var>
513      * parameter in {@link #bindIsolatedService(Intent, int, String, Executor, ServiceConnection)}.
514      *
515      * Subsequent calls to {@link #bindIsolatedService} with the same <var>instanceName</var>
516      * will cause the isolated service to be co-located in the same shared isolated process.
517      *
518      * Note that the shared isolated process is scoped to the calling app; once created, only
519      * the calling app can bind additional isolated services into the shared process. However,
520      * the services themselves can come from different APKs and therefore different vendors.
521      *
522      * Only services that set the {@link android.R.attr#allowSharedIsolatedProcess} attribute
523      * to {@code true} are allowed to be bound into a shared isolated process.
524      *
525      */
526     public static final int BIND_SHARED_ISOLATED_PROCESS = 0x00002000;
527 
528     /**
529      * Flag for {@link #bindIsolatedService}: Bind the service into a shared isolated process,
530      * but only with other isolated services from the same package that declare the same process
531      * name.
532      *
533      * <p>Specifying this flag allows multiple isolated services defined in the same package to be
534      * running in a single shared isolated process. This shared isolated process must be specified
535      * since this flag will not work with the default application process.
536      *
537      * <p>This flag is different from {@link #BIND_SHARED_ISOLATED_PROCESS} since it only
538      * allows binding services from the same package in the same shared isolated process. This also
539      * means the shared package isolated process is global, and not scoped to each potential
540      * calling app.
541      *
542      * <p>The shared isolated process instance is identified by the "android:process" attribute
543      * defined by the service. This flag cannot be used without this attribute set.
544      */
545     @FlaggedApi(FLAG_ENABLE_BIND_PACKAGE_ISOLATED_PROCESS)
546     public static final int BIND_PACKAGE_ISOLATED_PROCESS = 1 << 14;
547 
548     /***********    Public flags above this line ***********/
549     /***********    Hidden flags below this line ***********/
550 
551     /**
552      * Flag for {@link #bindService}: This flag is only intended to be used by the system to
553      * indicate that a service binding is not considered as real package component usage and should
554      * not generate a {@link android.app.usage.UsageEvents.Event#APP_COMPONENT_USED} event in usage
555      * stats.
556      * @hide
557      */
558     public static final int BIND_NOT_APP_COMPONENT_USAGE = 0x00008000;
559 
560     /**
561      * Flag for {@link #bindService}: allow the process hosting the target service to be treated
562      * as if it's as important as a perceptible app to the user and avoid the oom killer killing
563      * this process in low memory situations until there aren't any other processes left but the
564      * ones which are user-perceptible.
565      *
566      * @hide
567      */
568     public static final int BIND_ALMOST_PERCEPTIBLE = 0x000010000;
569 
570     /**
571      * Flag for {@link #bindService}: allow the process hosting the target service to gain
572      * {@link ActivityManager#PROCESS_CAPABILITY_POWER_RESTRICTED_NETWORK}, which allows it be able
573      * to access network regardless of any power saving restrictions.
574      *
575      * @hide
576      */
577     public static final int BIND_BYPASS_POWER_NETWORK_RESTRICTIONS = 0x00020000;
578 
579     /**
580      * Do not use. This flag is no longer needed nor used.
581      * @hide
582      */
583     @SystemApi
584     @Deprecated
585     public static final int BIND_ALLOW_FOREGROUND_SERVICE_STARTS_FROM_BACKGROUND = 0x00040000;
586 
587     /**
588      * Flag for {@link #bindService}: This flag is intended to be used only by the system to adjust
589      * the scheduling policy for IMEs (and any other out-of-process user-visible components that
590      * work closely with the top app) so that UI hosted in such services can have the same
591      * scheduling policy (e.g. SCHED_FIFO when it is enabled and TOP_APP_PRIORITY_BOOST otherwise)
592      * as the actual top-app.
593      * @hide
594      */
595     public static final int BIND_SCHEDULE_LIKE_TOP_APP = 0x00080000;
596 
597     /**
598      * Flag for {@link #bindService}: allow background activity starts from the bound service's
599      * process.
600      * This flag is only respected if the caller is holding
601      * {@link android.Manifest.permission#START_ACTIVITIES_FROM_BACKGROUND}.
602      * @hide
603      */
604     @SystemApi
605     public static final int BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS = 0x00100000;
606 
607     /**
608      * @hide Flag for {@link #bindService}: the service being bound to represents a
609      * protected system component, so must have association restrictions applied to it.
610      * That is, a system config must have one or more allow-association tags limiting
611      * which packages it can interact with.  If it does not have any such association
612      * restrictions, a default empty set will be created.
613      */
614     public static final int BIND_RESTRICT_ASSOCIATIONS = 0x00200000;
615 
616     /**
617      * @hide Flag for {@link #bindService}: allows binding to a service provided
618      * by an instant app. Note that the caller may not have access to the instant
619      * app providing the service which is a violation of the instant app sandbox.
620      * This flag is intended ONLY for development/testing and should be used with
621      * great care. Only the system is allowed to use this flag.
622      */
623     public static final int BIND_ALLOW_INSTANT = 0x00400000;
624 
625     /**
626      * @hide Flag for {@link #bindService}: like {@link #BIND_NOT_FOREGROUND}, but puts it
627      * up in to the important background state (instead of transient).
628      */
629     public static final int BIND_IMPORTANT_BACKGROUND = 0x00800000;
630 
631     /**
632      * @hide Flag for {@link #bindService}: allows application hosting service to manage allowlists
633      * such as temporary allowing a {@code PendingIntent} to bypass Power Save mode.
634      */
635     public static final int BIND_ALLOW_WHITELIST_MANAGEMENT = 0x01000000;
636 
637     /**
638      * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
639      * but only applies while the device is awake.
640      */
641     public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
642 
643     /**
644      * Flag for {@link #bindService}: For only the case where the binding
645      * is coming from the system, set the process state to BOUND_FOREGROUND_SERVICE
646      * instead of the normal maximum of IMPORTANT_FOREGROUND.  That is, this is
647      * saying that the process shouldn't participate in the normal power reduction
648      * modes (removing network access etc).
649      * @hide
650      */
651     @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
652     @FlaggedApi(FLAG_ENABLE_ON_DEVICE_INTELLIGENCE_MODULE)
653     public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
654 
655     /**
656      * @hide Flag for {@link #bindService}: Treat the binding as hosting
657      * an activity, an unbinding as the activity going in the background.
658      * That is, when unbinding, the process when empty will go on the activity
659      * LRU list instead of the regular one, keeping it around more aggressively
660      * than it otherwise would be.  This is intended for use with IMEs to try
661      * to keep IME processes around for faster keyboard switching.
662      */
663     public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
664 
665     /**
666      * @hide An idea that is not yet implemented.
667      * Flag for {@link #bindService}: If binding from an activity, consider
668      * this service to be visible like the binding activity is.  That is,
669      * it will be treated as something more important to keep around than
670      * invisible background activities.  This will impact the number of
671      * recent activities the user can switch between without having them
672      * restart.  There is no guarantee this will be respected, as the system
673      * tries to balance such requests from one app vs. the importance of
674      * keeping other apps around.
675      *
676      * @deprecated Repurposed to {@link #BIND_TREAT_LIKE_VISIBLE_FOREGROUND_SERVICE}.
677      */
678     @Deprecated
679     public static final int BIND_VISIBLE = 0x10000000;
680 
681     /**
682      * @hide Flag for {@link #bindService}: Treat the binding as hosting a foreground service
683      * and also visible to the user. That is, the app hosting the service will get its process state
684      * bumped to the {@link android.app.ActivityManager#PROCESS_STATE_FOREGROUND_SERVICE},
685      * and it's considered as visible to the user, thus less likely to be expunged from memory
686      * on low memory situations. This is intented for use by processes with the process state
687      * better than the {@link android.app.ActivityManager#PROCESS_STATE_TOP}.
688      */
689     public static final int BIND_TREAT_LIKE_VISIBLE_FOREGROUND_SERVICE = 0x10000000;
690 
691     /**
692      * @hide
693      * Flag for {@link #bindService}: Consider this binding to be causing the target
694      * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
695      * away.
696      */
697     public static final int BIND_SHOWING_UI = 0x20000000;
698 
699     /**
700      * Flag for {@link #bindService}: Don't consider the bound service to be
701      * visible, even if the caller is visible.
702      * @hide
703      */
704     public static final int BIND_NOT_VISIBLE = 0x40000000;
705 
706     /**
707      * Flag for {@link #bindService}: The service being bound is an
708      * {@link android.R.attr#isolatedProcess isolated},
709      * {@link android.R.attr#externalService external} service.  This binds the service into the
710      * calling application's package, rather than the package in which the service is declared.
711      * <p>
712      * When using this flag, the code for the service being bound will execute under the calling
713      * application's package name and user ID.  Because the service must be an isolated process,
714      * it will not have direct access to the application's data, though.
715      *
716      * The purpose of this flag is to allow applications to provide services that are attributed
717      * to the app using the service, rather than the application providing the service.
718      * </p>
719      *
720      * <em>This flag is NOT compatible with {@link BindServiceFlags}. If you need to use
721      * {@link BindServiceFlags}, you must use {@link #BIND_EXTERNAL_SERVICE_LONG} instead.</em>
722      */
723     public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
724 
725     /**
726      * Works in the same way as {@link #BIND_EXTERNAL_SERVICE}, but it's defined as a {@code long}
727      * value that is compatible to {@link BindServiceFlags}.
728      */
729     public static final long BIND_EXTERNAL_SERVICE_LONG = 1L << 62;
730 
731     /**
732      * Flag for {@link #bindService}: allow the process hosting the target service to gain
733      * {@link ActivityManager#PROCESS_CAPABILITY_USER_RESTRICTED_NETWORK}, which allows it be able
734      * to access network regardless of any user restrictions.
735      *
736      * @hide
737      */
738     public static final long BIND_BYPASS_USER_NETWORK_RESTRICTIONS = 0x1_0000_0000L;
739 
740     /**
741      * Flag for {@link #bindService}.
742      *
743      * @hide
744      */
745     public static final long BIND_MATCH_QUARANTINED_COMPONENTS = 0x2_0000_0000L;
746 
747     /**
748      * Flag for {@link #bindService} that allows the bound app to be frozen if it is eligible.
749      *
750      * @hide
751      */
752     public static final long BIND_ALLOW_FREEZE = 0x4_0000_0000L;
753 
754     /**
755      * These bind flags reduce the strength of the binding such that we shouldn't
756      * consider it as pulling the process up to the level of the one that is bound to it.
757      * @hide
758      */
759     public static final long BIND_REDUCTION_FLAGS =
760             Context.BIND_ALLOW_OOM_MANAGEMENT | Context.BIND_WAIVE_PRIORITY
761                     | Context.BIND_NOT_PERCEPTIBLE | Context.BIND_NOT_VISIBLE
762                     | Context.BIND_ALLOW_FREEZE;
763 
764     /** @hide */
765     @IntDef(flag = true, prefix = { "RECEIVER_VISIBLE" }, value = {
766             RECEIVER_VISIBLE_TO_INSTANT_APPS, RECEIVER_EXPORTED, RECEIVER_NOT_EXPORTED,
767             RECEIVER_EXPORTED_UNAUDITED
768     })
769     @Retention(RetentionPolicy.SOURCE)
770     public @interface RegisterReceiverFlags {}
771 
772     /**
773      * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from Instant Apps.
774      */
775     public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 0x1;
776 
777     /**
778      * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from other Apps.
779      * Has the same behavior as marking a statically registered receiver with "exported=true"
780      */
781     public static final int RECEIVER_EXPORTED = 0x2;
782 
783     /**
784      * @deprecated Use {@link #RECEIVER_NOT_EXPORTED} or {@link #RECEIVER_EXPORTED} instead.
785      * @hide
786      */
787     @Deprecated
788     @TestApi
789     public static final int RECEIVER_EXPORTED_UNAUDITED = RECEIVER_EXPORTED;
790 
791     /**
792      * Flag for {@link #registerReceiver}: The receiver cannot receive broadcasts from other Apps.
793      * Has the same behavior as marking a statically registered receiver with "exported=false"
794      */
795     public static final int RECEIVER_NOT_EXPORTED = 0x4;
796 
797     /**
798      * The permission is granted.
799      *
800      * @hide
801      */
802     public static final int PERMISSION_REQUEST_STATE_GRANTED = 0;
803 
804     /**
805      * The permission isn't granted, but apps can request the permission. When the app request
806      * the permission, user will be prompted with permission dialog to grant or deny the request.
807      *
808      * @hide
809      */
810     public static final int PERMISSION_REQUEST_STATE_REQUESTABLE = 1;
811 
812     /**
813      * The permission is denied, and shouldn't be requested by apps. Permission request
814      * will be automatically denied by the system, preventing the permission dialog from being
815      * displayed to the user.
816      *
817      * @hide
818      */
819     public static final int PERMISSION_REQUEST_STATE_UNREQUESTABLE = 2;
820 
821 
822     /** @hide */
823     @IntDef(prefix = { "PERMISSION_REQUEST_STATE_" }, value = {
824             PERMISSION_REQUEST_STATE_GRANTED,
825             PERMISSION_REQUEST_STATE_REQUESTABLE,
826             PERMISSION_REQUEST_STATE_UNREQUESTABLE
827     })
828     @Retention(RetentionPolicy.SOURCE)
829     public @interface PermissionRequestState {}
830 
831     /**
832      * Returns an AssetManager instance for the application's package.
833      * <p>
834      * <strong>Note:</strong> Implementations of this method should return
835      * an AssetManager instance that is consistent with the Resources instance
836      * returned by {@link #getResources()}. For example, they should share the
837      * same {@link Configuration} object.
838      *
839      * @return an AssetManager instance for the application's package
840      * @see #getResources()
841      */
getAssets()842     public abstract AssetManager getAssets();
843 
844     /**
845      * Returns a Resources instance for the application's package.
846      * <p>
847      * <strong>Note:</strong> Implementations of this method should return
848      * a Resources instance that is consistent with the AssetManager instance
849      * returned by {@link #getAssets()}. For example, they should share the
850      * same {@link Configuration} object.
851      *
852      * @return a Resources instance for the application's package
853      * @see #getAssets()
854      */
getResources()855     public abstract Resources getResources();
856 
857     /** Return PackageManager instance to find global package information. */
getPackageManager()858     public abstract PackageManager getPackageManager();
859 
860     /** Return a ContentResolver instance for your application's package. */
getContentResolver()861     public abstract ContentResolver getContentResolver();
862 
863     /**
864      * Return the Looper for the main thread of the current process.  This is
865      * the thread used to dispatch calls to application components (activities,
866      * services, etc).
867      * <p>
868      * By definition, this method returns the same result as would be obtained
869      * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
870      * </p>
871      *
872      * @return The main looper.
873      */
getMainLooper()874     public abstract Looper getMainLooper();
875 
876     /**
877      * Return an {@link Executor} that will run enqueued tasks on the main
878      * thread associated with this context. This is the thread used to dispatch
879      * calls to application components (activities, services, etc).
880      */
getMainExecutor()881     public Executor getMainExecutor() {
882         // This is pretty inefficient, which is why ContextImpl overrides it
883         return new HandlerExecutor(new Handler(getMainLooper()));
884     }
885 
886     /**
887      * Return the context of the single, global Application object of the
888      * current process.  This generally should only be used if you need a
889      * Context whose lifecycle is separate from the current context, that is
890      * tied to the lifetime of the process rather than the current component.
891      *
892      * <p>Consider for example how this interacts with
893      * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
894      * <ul>
895      * <li> <p>If used from an Activity context, the receiver is being registered
896      * within that activity.  This means that you are expected to unregister
897      * before the activity is done being destroyed; in fact if you do not do
898      * so, the framework will clean up your leaked registration as it removes
899      * the activity and log an error.  Thus, if you use the Activity context
900      * to register a receiver that is static (global to the process, not
901      * associated with an Activity instance) then that registration will be
902      * removed on you at whatever point the activity you used is destroyed.
903      * <li> <p>If used from the Context returned here, the receiver is being
904      * registered with the global state associated with your application.  Thus
905      * it will never be unregistered for you.  This is necessary if the receiver
906      * is associated with static data, not a particular component.  However
907      * using the ApplicationContext elsewhere can easily lead to serious leaks
908      * if you forget to unregister, unbind, etc.
909      * </ul>
910      */
getApplicationContext()911     public abstract Context getApplicationContext();
912 
913     /** Non-activity related autofill ids are unique in the app */
914     private static int sLastAutofillId = View.NO_ID;
915 
916     /**
917      * Gets the next autofill ID.
918      *
919      * <p>All IDs will be smaller or the same as {@link View#LAST_APP_AUTOFILL_ID}. All IDs
920      * returned will be unique.
921      *
922      * @return A ID that is unique in the process
923      *
924      * {@hide}
925      */
getNextAutofillId()926     public int getNextAutofillId() {
927         if (sLastAutofillId == View.LAST_APP_AUTOFILL_ID - 1) {
928             sLastAutofillId = View.NO_ID;
929         }
930 
931         sLastAutofillId++;
932 
933         return sLastAutofillId;
934     }
935 
936     /**
937      * Add a new {@link ComponentCallbacks} to the base application of the
938      * Context, which will be called at the same times as the ComponentCallbacks
939      * methods of activities and other components are called. Note that you
940      * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
941      * appropriate in the future; this will not be removed for you.
942      * <p>
943      * After {@link Build.VERSION_CODES#S}, registering the ComponentCallbacks to Context created
944      * via {@link #createWindowContext(int, Bundle)} or
945      * {@link #createWindowContext(Display, int, Bundle)} will receive
946      * {@link ComponentCallbacks#onConfigurationChanged(Configuration)} from Window Context rather
947      * than its base application. It is helpful if you want to handle UI components that
948      * associated with the Window Context when the Window Context has configuration changes.</p>
949      * <p>
950      * After {@link Build.VERSION_CODES#TIRAMISU}, registering the ComponentCallbacks to
951      * {@link Activity} context will receive
952      * {@link ComponentCallbacks#onConfigurationChanged(Configuration)} from
953      * {@link Activity#onConfigurationChanged(Configuration)} rather than its base application.</p>
954      * <p>
955      * After {@link Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, registering the ComponentCallbacks to
956      * {@link android.inputmethodservice.InputMethodService} will receive
957      * {@link ComponentCallbacks#onConfigurationChanged(Configuration)} from InputmethodService
958      * rather than its base application. It is helpful if you want to handle UI components when the
959      * IME has configuration changes.</p>
960      *
961      * @param callback The interface to call.  This can be either a
962      * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
963      *
964      * @see Context#createWindowContext(int, Bundle)
965      */
registerComponentCallbacks(ComponentCallbacks callback)966     public void registerComponentCallbacks(ComponentCallbacks callback) {
967         getApplicationContext().registerComponentCallbacks(callback);
968     }
969 
970     /**
971      * Remove a {@link ComponentCallbacks} object that was previously registered
972      * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
973      */
unregisterComponentCallbacks(ComponentCallbacks callback)974     public void unregisterComponentCallbacks(ComponentCallbacks callback) {
975         getApplicationContext().unregisterComponentCallbacks(callback);
976     }
977 
978     /**
979      * Return a localized, styled CharSequence from the application's package's
980      * default string table.
981      *
982      * @param resId Resource id for the CharSequence text
983      */
984     @NonNull
985     @RavenwoodKeep
getText(@tringRes int resId)986     public final CharSequence getText(@StringRes int resId) {
987         return getResources().getText(resId);
988     }
989 
990     /**
991      * Returns a localized string from the application's package's
992      * default string table.
993      *
994      * @param resId Resource id for the string
995      * @return The string data associated with the resource, stripped of styled
996      *         text information.
997      */
998     @NonNull
999     @RavenwoodKeep
getString(@tringRes int resId)1000     public final String getString(@StringRes int resId) {
1001         return getResources().getString(resId);
1002     }
1003 
1004     /**
1005      * Returns a localized formatted string from the application's package's
1006      * default string table, substituting the format arguments as defined in
1007      * {@link java.util.Formatter} and {@link java.lang.String#format}.
1008      *
1009      * @param resId Resource id for the format string
1010      * @param formatArgs The format arguments that will be used for
1011      *                   substitution.
1012      * @return The string data associated with the resource, formatted and
1013      *         stripped of styled text information.
1014      */
1015     @NonNull
1016     @RavenwoodKeep
getString(@tringRes int resId, Object... formatArgs)1017     public final String getString(@StringRes int resId, Object... formatArgs) {
1018         return getResources().getString(resId, formatArgs);
1019     }
1020 
1021     /**
1022      * Returns a color associated with a particular resource ID and styled for
1023      * the current theme.
1024      *
1025      * @param id The desired resource identifier, as generated by the aapt
1026      *           tool. This integer encodes the package, type, and resource
1027      *           entry. The value 0 is an invalid identifier.
1028      * @return A single color value in the form 0xAARRGGBB.
1029      * @throws android.content.res.Resources.NotFoundException if the given ID
1030      *         does not exist.
1031      */
1032     @ColorInt
1033     @RavenwoodKeep
getColor(@olorRes int id)1034     public final int getColor(@ColorRes int id) {
1035         return getResources().getColor(id, getTheme());
1036     }
1037 
1038     /**
1039      * Returns a drawable object associated with a particular resource ID and
1040      * styled for the current theme.
1041      *
1042      * @param id The desired resource identifier, as generated by the aapt
1043      *           tool. This integer encodes the package, type, and resource
1044      *           entry. The value 0 is an invalid identifier.
1045      * @return An object that can be used to draw this resource.
1046      * @throws android.content.res.Resources.NotFoundException if the given ID
1047      *         does not exist.
1048      */
1049     @Nullable
getDrawable(@rawableRes int id)1050     public final Drawable getDrawable(@DrawableRes int id) {
1051         return getResources().getDrawable(id, getTheme());
1052     }
1053 
1054     /**
1055      * Returns a color state list associated with a particular resource ID and
1056      * styled for the current theme.
1057      *
1058      * @param id The desired resource identifier, as generated by the aapt
1059      *           tool. This integer encodes the package, type, and resource
1060      *           entry. The value 0 is an invalid identifier.
1061      * @return A color state list.
1062      * @throws android.content.res.Resources.NotFoundException if the given ID
1063      *         does not exist.
1064      */
1065     @NonNull
getColorStateList(@olorRes int id)1066     public final ColorStateList getColorStateList(@ColorRes int id) {
1067         return getResources().getColorStateList(id, getTheme());
1068     }
1069 
1070      /**
1071      * Set the base theme for this context.  Note that this should be called
1072      * before any views are instantiated in the Context (for example before
1073      * calling {@link android.app.Activity#setContentView} or
1074      * {@link android.view.LayoutInflater#inflate}).
1075      *
1076      * @param resid The style resource describing the theme.
1077      */
setTheme(@tyleRes int resid)1078     public abstract void setTheme(@StyleRes int resid);
1079 
1080     /** @hide Needed for some internal implementation...  not public because
1081      * you can't assume this actually means anything. */
1082     @UnsupportedAppUsage
getThemeResId()1083     public int getThemeResId() {
1084         return 0;
1085     }
1086 
1087     /**
1088      * Return the Theme object associated with this Context.
1089      */
1090     @ViewDebug.ExportedProperty(deepExport = true)
getTheme()1091     public abstract Resources.Theme getTheme();
1092 
1093     /**
1094      * Retrieve styled attribute information in this Context's theme.  See
1095      * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
1096      * for more information.
1097      *
1098      * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
1099      */
1100     @NonNull
1101     @RavenwoodKeep
obtainStyledAttributes(@onNull @tyleableRes int[] attrs)1102     public final TypedArray obtainStyledAttributes(@NonNull @StyleableRes int[] attrs) {
1103         return getTheme().obtainStyledAttributes(attrs);
1104     }
1105 
1106     /**
1107      * Retrieve styled attribute information in this Context's theme.  See
1108      * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
1109      * for more information.
1110      *
1111      * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
1112      */
1113     @NonNull
1114     @RavenwoodKeep
obtainStyledAttributes(@tyleRes int resid, @NonNull @StyleableRes int[] attrs)1115     public final TypedArray obtainStyledAttributes(@StyleRes int resid,
1116             @NonNull @StyleableRes int[] attrs) throws Resources.NotFoundException {
1117         return getTheme().obtainStyledAttributes(resid, attrs);
1118     }
1119 
1120     /**
1121      * Retrieve styled attribute information in this Context's theme.  See
1122      * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
1123      * for more information.
1124      *
1125      * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
1126      */
1127     @NonNull
1128     @RavenwoodKeep
obtainStyledAttributes( @ullable AttributeSet set, @NonNull @StyleableRes int[] attrs)1129     public final TypedArray obtainStyledAttributes(
1130             @Nullable AttributeSet set, @NonNull @StyleableRes int[] attrs) {
1131         return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
1132     }
1133 
1134     /**
1135      * Retrieve styled attribute information in this Context's theme.  See
1136      * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
1137      * for more information.
1138      *
1139      * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
1140      */
1141     @NonNull
1142     @RavenwoodKeep
obtainStyledAttributes(@ullable AttributeSet set, @NonNull @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes)1143     public final TypedArray obtainStyledAttributes(@Nullable AttributeSet set,
1144             @NonNull @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
1145             @StyleRes int defStyleRes) {
1146         return getTheme().obtainStyledAttributes(
1147             set, attrs, defStyleAttr, defStyleRes);
1148     }
1149 
1150     /**
1151      * Return a class loader you can use to retrieve classes in this package.
1152      */
getClassLoader()1153     public abstract ClassLoader getClassLoader();
1154 
1155     /** Return the name of this application's package. */
getPackageName()1156     public abstract String getPackageName();
1157 
1158     /**
1159      * @hide Return the name of the base context this context is derived from.
1160      * This is the same as {@link #getOpPackageName()} except in
1161      * cases where system components are loaded into other app processes, in which
1162      * case {@link #getOpPackageName()} will be the name of the primary package in
1163      * that process (so that app ops uid verification will work with the name).
1164      */
1165     @SuppressWarnings("HiddenAbstractMethod")
1166     @UnsupportedAppUsage
getBasePackageName()1167     public abstract String getBasePackageName();
1168 
1169     /**
1170      * Return the package name that should be used for {@link android.app.AppOpsManager} calls from
1171      * this context, so that app ops manager's uid verification will work with the name.
1172      * <p>
1173      * This is not generally intended for third party application developers.
1174      */
1175     @NonNull
getOpPackageName()1176     public String getOpPackageName() {
1177         throw new RuntimeException("Not implemented. Must override in a subclass.");
1178     }
1179 
1180     /**
1181      * <p>Attribution can be used in complex apps to logically separate parts of the app. E.g. a
1182      * blogging app might also have a instant messaging app built in. In this case two separate tags
1183      * can for used each sub-feature.
1184      *
1185      * @return the attribution tag this context is for or {@code null} if this is the default.
1186      */
getAttributionTag()1187     public @Nullable String getAttributionTag() {
1188         return null;
1189     }
1190 
1191     /**
1192      * @return The identity of this context for permission purposes.
1193      *
1194      * @see AttributionSource
1195      */
getAttributionSource()1196     public @NonNull AttributionSource getAttributionSource() {
1197         return null;
1198     }
1199 
1200     // TODO moltmann: Remove
1201     /**
1202      * @removed
1203      */
1204     @Deprecated
getFeatureId()1205     public @Nullable String getFeatureId() {
1206         return getAttributionTag();
1207     }
1208 
1209     /**
1210      * Return the set of parameters which this Context was created with, if it
1211      * was created via {@link #createContext(ContextParams)}.
1212      */
getParams()1213     public @Nullable ContextParams getParams() {
1214         return null;
1215     }
1216 
1217     /** Return the full application info for this context's package. */
getApplicationInfo()1218     public abstract ApplicationInfo getApplicationInfo();
1219 
1220     /**
1221      * Return the full path to this context's primary Android package.
1222      * The Android package is a ZIP file which contains the application's
1223      * primary resources.
1224      *
1225      * <p>Note: this is not generally useful for applications, since they should
1226      * not be directly accessing the file system.
1227      *
1228      * @return String Path to the resources.
1229      */
getPackageResourcePath()1230     public abstract String getPackageResourcePath();
1231 
1232     /**
1233      * Return the full path to this context's primary Android package.
1234      * The Android package is a ZIP file which contains application's
1235      * primary code and assets.
1236      *
1237      * <p>Note: this is not generally useful for applications, since they should
1238      * not be directly accessing the file system.
1239      *
1240      * @return String Path to the code and assets.
1241      */
getPackageCodePath()1242     public abstract String getPackageCodePath();
1243 
1244     /**
1245      * @hide
1246      * @deprecated use {@link #getSharedPreferencesPath(String)}
1247      */
1248     @Deprecated
1249     @UnsupportedAppUsage
getSharedPrefsFile(String name)1250     public File getSharedPrefsFile(String name) {
1251         return getSharedPreferencesPath(name);
1252     }
1253 
1254     /**
1255      * Retrieve and hold the contents of the preferences file 'name', returning
1256      * a SharedPreferences through which you can retrieve and modify its
1257      * values.  Only one instance of the SharedPreferences object is returned
1258      * to any callers for the same name, meaning they will see each other's
1259      * edits as soon as they are made.
1260      *
1261      * <p>This method is thread-safe.
1262      *
1263      * <p>If the preferences directory does not already exist, it will be created when this method
1264      * is called.
1265      *
1266      * <p>If a preferences file by this name does not exist, it will be created when you retrieve an
1267      * editor ({@link SharedPreferences#edit()}) and then commit changes ({@link
1268      * SharedPreferences.Editor#commit()} or {@link SharedPreferences.Editor#apply()}).
1269      *
1270      * @param name Desired preferences file.
1271      * @param mode Operating mode.
1272      *
1273      * @return The single {@link SharedPreferences} instance that can be used
1274      *         to retrieve and modify the preference values.
1275      *
1276      * @see #MODE_PRIVATE
1277      */
getSharedPreferences(String name, @PreferencesMode int mode)1278     public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
1279 
1280     /**
1281      * Retrieve and hold the contents of the preferences file, returning
1282      * a SharedPreferences through which you can retrieve and modify its
1283      * values.  Only one instance of the SharedPreferences object is returned
1284      * to any callers for the same name, meaning they will see each other's
1285      * edits as soon as they are made.
1286      *
1287      * @param file Desired preferences file. If a preferences file by this name
1288      * does not exist, it will be created when you retrieve an
1289      * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
1290      * @param mode Operating mode.
1291      *
1292      * @return The single {@link SharedPreferences} instance that can be used
1293      *         to retrieve and modify the preference values.
1294      *
1295      * @see #getSharedPreferencesPath(String)
1296      * @see #MODE_PRIVATE
1297      * @removed
1298      */
1299     @SuppressWarnings("HiddenAbstractMethod")
getSharedPreferences(File file, @PreferencesMode int mode)1300     public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
1301 
1302     /**
1303      * Move an existing shared preferences file from the given source storage
1304      * context to this context. This is typically used to migrate data between
1305      * storage locations after an upgrade, such as moving to device protected
1306      * storage.
1307      *
1308      * @param sourceContext The source context which contains the existing
1309      *            shared preferences to move.
1310      * @param name The name of the shared preferences file.
1311      * @return {@code true} if the move was successful or if the shared
1312      *         preferences didn't exist in the source context, otherwise
1313      *         {@code false}.
1314      * @see #createDeviceProtectedStorageContext()
1315      */
moveSharedPreferencesFrom(Context sourceContext, String name)1316     public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
1317 
1318     /**
1319      * Delete an existing shared preferences file.
1320      *
1321      * @param name The name (unique in the application package) of the shared
1322      *            preferences file.
1323      * @return {@code true} if the shared preferences file was successfully
1324      *         deleted; else {@code false}.
1325      * @see #getSharedPreferences(String, int)
1326      */
deleteSharedPreferences(String name)1327     public abstract boolean deleteSharedPreferences(String name);
1328 
1329     /** @hide */
1330     @SuppressWarnings("HiddenAbstractMethod")
reloadSharedPreferences()1331     public abstract void reloadSharedPreferences();
1332 
1333     /**
1334      * Open a private file associated with this Context's application package
1335      * for reading.
1336      *
1337      * @param name The name of the file to open; can not contain path
1338      *             separators.
1339      *
1340      * @return The resulting {@link FileInputStream}.
1341      *
1342      * @see #openFileOutput
1343      * @see #fileList
1344      * @see #deleteFile
1345      * @see java.io.FileInputStream#FileInputStream(String)
1346      */
openFileInput(String name)1347     public abstract FileInputStream openFileInput(String name)
1348         throws FileNotFoundException;
1349 
1350     /**
1351      * Open a private file associated with this Context's application package
1352      * for writing. Creates the file if it doesn't already exist.
1353      * <p>
1354      * No additional permissions are required for the calling app to read or
1355      * write the returned file.
1356      *
1357      * @param name The name of the file to open; can not contain path
1358      *            separators.
1359      * @param mode Operating mode.
1360      * @return The resulting {@link FileOutputStream}.
1361      * @see #MODE_APPEND
1362      * @see #MODE_PRIVATE
1363      * @see #openFileInput
1364      * @see #fileList
1365      * @see #deleteFile
1366      * @see java.io.FileOutputStream#FileOutputStream(String)
1367      */
openFileOutput(String name, @FileMode int mode)1368     public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
1369         throws FileNotFoundException;
1370 
1371     /**
1372      * Delete the given private file associated with this Context's
1373      * application package.
1374      *
1375      * @param name The name of the file to delete; can not contain path
1376      *             separators.
1377      *
1378      * @return {@code true} if the file was successfully deleted; else
1379      *         {@code false}.
1380      *
1381      * @see #openFileInput
1382      * @see #openFileOutput
1383      * @see #fileList
1384      * @see java.io.File#delete()
1385      */
deleteFile(String name)1386     public abstract boolean deleteFile(String name);
1387 
1388     /**
1389      * Returns the absolute path on the filesystem where a file created with
1390      * {@link #openFileOutput} is stored.
1391      * <p>
1392      * The returned path may change over time if the calling app is moved to an
1393      * adopted storage device, so only relative paths should be persisted.
1394      *
1395      * @param name The name of the file for which you would like to get
1396      *          its path.
1397      *
1398      * @return An absolute path to the given file.
1399      *
1400      * @see #openFileOutput
1401      * @see #getFilesDir
1402      * @see #getDir
1403      */
getFileStreamPath(String name)1404     public abstract File getFileStreamPath(String name);
1405 
1406     /**
1407      * Returns the absolute path on the filesystem where a file created with
1408      * {@link #getSharedPreferences(String, int)} is stored.
1409      * <p>
1410      * The returned path may change over time if the calling app is moved to an
1411      * adopted storage device, so only relative paths should be persisted.
1412      *
1413      * @param name The name of the shared preferences for which you would like
1414      *            to get a path.
1415      * @return An absolute path to the given file.
1416      * @see #getSharedPreferences(String, int)
1417      * @removed
1418      */
1419     @SuppressWarnings("HiddenAbstractMethod")
getSharedPreferencesPath(String name)1420     public abstract File getSharedPreferencesPath(String name);
1421 
1422     /**
1423      * Returns the absolute path to the directory on the filesystem where all
1424      * private files belonging to this app are stored. Apps should not use this
1425      * path directly; they should instead use {@link #getFilesDir()},
1426      * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
1427      * APIs on this class.
1428      * <p>
1429      * The returned path may change over time if the calling app is moved to an
1430      * adopted storage device, so only relative paths should be persisted.
1431      * <p>
1432      * No additional permissions are required for the calling app to read or
1433      * write files under the returned path.
1434      *
1435      * @see ApplicationInfo#dataDir
1436      */
getDataDir()1437     public abstract File getDataDir();
1438 
1439     /**
1440      * Returns the absolute path to the directory on the filesystem where files
1441      * created with {@link #openFileOutput} are stored.
1442      * <p>
1443      * The returned path may change over time if the calling app is moved to an
1444      * adopted storage device, so only relative paths should be persisted.
1445      * <p>
1446      * No additional permissions are required for the calling app to read or
1447      * write files under the returned path.
1448      *
1449      * @return The path of the directory holding application files.
1450      * @see #openFileOutput
1451      * @see #getFileStreamPath
1452      * @see #getDir
1453      */
getFilesDir()1454     public abstract File getFilesDir();
1455 
1456     /**
1457      * Returns the absolute path to the directory that is related to the crate on the filesystem.
1458      * <p>
1459      *     The crateId require a validated file name. It can't contain any "..", ".",
1460      *     {@link File#separatorChar} etc..
1461      * </p>
1462      * <p>
1463      * The returned path may change over time if the calling app is moved to an
1464      * adopted storage device, so only relative paths should be persisted.
1465      * </p>
1466      * <p>
1467      * No additional permissions are required for the calling app to read or
1468      * write files under the returned path.
1469      *</p>
1470      *
1471      * @param crateId the relative validated file name under {@link Context#getDataDir()}/crates
1472      * @return the crate directory file.
1473      * @hide
1474      */
1475     @NonNull
1476     @TestApi
getCrateDir(@onNull String crateId)1477     public File getCrateDir(@NonNull String crateId) {
1478         throw new RuntimeException("Not implemented. Must override in a subclass.");
1479     }
1480 
1481     /**
1482      * Returns the absolute path to the directory on the filesystem similar to
1483      * {@link #getFilesDir()}. The difference is that files placed under this
1484      * directory will be excluded from automatic backup to remote storage. See
1485      * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
1486      * of the automatic backup mechanism in Android.
1487      * <p>
1488      * The returned path may change over time if the calling app is moved to an
1489      * adopted storage device, so only relative paths should be persisted.
1490      * <p>
1491      * No additional permissions are required for the calling app to read or
1492      * write files under the returned path.
1493      *
1494      * @return The path of the directory holding application files that will not
1495      *         be automatically backed up to remote storage.
1496      * @see #openFileOutput
1497      * @see #getFileStreamPath
1498      * @see #getDir
1499      * @see android.app.backup.BackupAgent
1500      */
getNoBackupFilesDir()1501     public abstract File getNoBackupFilesDir();
1502 
1503     /**
1504      * Returns the absolute path to the directory on the primary shared/external
1505      * storage device where the application can place persistent files it owns.
1506      * These files are internal to the applications, and not typically visible
1507      * to the user as media.
1508      * <p>
1509      * This is like {@link #getFilesDir()} in that these files will be deleted
1510      * when the application is uninstalled, however there are some important
1511      * differences:
1512      * <ul>
1513      * <li>Shared storage may not always be available, since removable media can
1514      * be ejected by the user. Media state can be checked using
1515      * {@link Environment#getExternalStorageState(File)}.
1516      * <li>There is no security enforced with these files. For example, any
1517      * application holding
1518      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1519      * these files.
1520      * </ul>
1521      * <p>
1522      * If a shared storage device is emulated (as determined by
1523      * {@link Environment#isExternalStorageEmulated(File)}), its contents are
1524      * backed by a private user data partition, which means there is little
1525      * benefit to storing data here instead of the private directories returned
1526      * by {@link #getFilesDir()}, etc.
1527      * <p>
1528      * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
1529      * are required to read or write to the returned path; it's always
1530      * accessible to the calling app. This only applies to paths generated for
1531      * package name of the calling application. To access paths belonging to
1532      * other packages,
1533      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1534      * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1535      * <p>
1536      * On devices with multiple users (as described by {@link UserManager}),
1537      * each user has their own isolated shared storage. Applications only have
1538      * access to the shared storage for the user they're running as.
1539      * <p>
1540      * The returned path may change over time if different shared storage media
1541      * is inserted, so only relative paths should be persisted.
1542      * <p>
1543      * Here is an example of typical code to manipulate a file in an
1544      * application's shared storage:
1545      * </p>
1546      * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1547      * private_file}
1548      * <p>
1549      * If you supply a non-null <var>type</var> to this function, the returned
1550      * file will be a path to a sub-directory of the given type. Though these
1551      * files are not automatically scanned by the media scanner, you can
1552      * explicitly add them to the media database with
1553      * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1554      * MediaScannerConnection.scanFile}. Note that this is not the same as
1555      * {@link android.os.Environment#getExternalStoragePublicDirectory
1556      * Environment.getExternalStoragePublicDirectory()}, which provides
1557      * directories of media shared by all applications. The directories returned
1558      * here are owned by the application, and their contents will be removed
1559      * when the application is uninstalled. Unlike
1560      * {@link android.os.Environment#getExternalStoragePublicDirectory
1561      * Environment.getExternalStoragePublicDirectory()}, the directory returned
1562      * here will be automatically created for you.
1563      * <p>
1564      * Here is an example of typical code to manipulate a picture in an
1565      * application's shared storage and add it to the media database:
1566      * </p>
1567      * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1568      * private_picture}
1569      *
1570      * @param type The type of files directory to return. May be {@code null}
1571      *            for the root of the files directory or one of the following
1572      *            constants for a subdirectory:
1573      *            {@link android.os.Environment#DIRECTORY_MUSIC},
1574      *            {@link android.os.Environment#DIRECTORY_PODCASTS},
1575      *            {@link android.os.Environment#DIRECTORY_RINGTONES},
1576      *            {@link android.os.Environment#DIRECTORY_ALARMS},
1577      *            {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1578      *            {@link android.os.Environment#DIRECTORY_PICTURES}, or
1579      *            {@link android.os.Environment#DIRECTORY_MOVIES}.
1580      * @return the absolute path to application-specific directory. May return
1581      *         {@code null} if shared storage is not currently available.
1582      * @see #getFilesDir
1583      * @see #getExternalFilesDirs(String)
1584      * @see Environment#getExternalStorageState(File)
1585      * @see Environment#isExternalStorageEmulated(File)
1586      * @see Environment#isExternalStorageRemovable(File)
1587      */
1588     @Nullable
getExternalFilesDir(@ullable String type)1589     public abstract File getExternalFilesDir(@Nullable String type);
1590 
1591     /**
1592      * Returns absolute paths to application-specific directories on all
1593      * shared/external storage devices where the application can place
1594      * persistent files it owns. These files are internal to the application,
1595      * and not typically visible to the user as media.
1596      * <p>
1597      * This is like {@link #getFilesDir()} in that these files will be deleted
1598      * when the application is uninstalled, however there are some important
1599      * differences:
1600      * <ul>
1601      * <li>Shared storage may not always be available, since removable media can
1602      * be ejected by the user. Media state can be checked using
1603      * {@link Environment#getExternalStorageState(File)}.
1604      * <li>There is no security enforced with these files. For example, any
1605      * application holding
1606      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1607      * these files.
1608      * </ul>
1609      * <p>
1610      * If a shared storage device is emulated (as determined by
1611      * {@link Environment#isExternalStorageEmulated(File)}), its contents are
1612      * backed by a private user data partition, which means there is little
1613      * benefit to storing data here instead of the private directories returned
1614      * by {@link #getFilesDir()}, etc.
1615      * <p>
1616      * Shared storage devices returned here are considered a stable part of the
1617      * device, including physical media slots under a protective cover. The
1618      * returned paths do not include transient devices, such as USB flash drives
1619      * connected to handheld devices.
1620      * <p>
1621      * An application may store data on any or all of the returned devices. For
1622      * example, an app may choose to store large files on the device with the
1623      * most available space, as measured by {@link StatFs}.
1624      * <p>
1625      * No additional permissions are required for the calling app to read or
1626      * write files under the returned path. Write access outside of these paths
1627      * on secondary external storage devices is not available.
1628      * <p>
1629      * The returned path may change over time if different shared storage media
1630      * is inserted, so only relative paths should be persisted.
1631      *
1632      * @param type The type of files directory to return. May be {@code null}
1633      *            for the root of the files directory or one of the following
1634      *            constants for a subdirectory:
1635      *            {@link android.os.Environment#DIRECTORY_MUSIC},
1636      *            {@link android.os.Environment#DIRECTORY_PODCASTS},
1637      *            {@link android.os.Environment#DIRECTORY_RINGTONES},
1638      *            {@link android.os.Environment#DIRECTORY_ALARMS},
1639      *            {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1640      *            {@link android.os.Environment#DIRECTORY_PICTURES}, or
1641      *            {@link android.os.Environment#DIRECTORY_MOVIES}.
1642      * @return the absolute paths to application-specific directories. Some
1643      *         individual paths may be {@code null} if that shared storage is
1644      *         not currently available. The first path returned is the same as
1645      *         {@link #getExternalFilesDir(String)}.
1646      * @see #getExternalFilesDir(String)
1647      * @see Environment#getExternalStorageState(File)
1648      * @see Environment#isExternalStorageEmulated(File)
1649      * @see Environment#isExternalStorageRemovable(File)
1650      */
getExternalFilesDirs(String type)1651     public abstract File[] getExternalFilesDirs(String type);
1652 
1653     /**
1654      * Return the primary shared/external storage directory where this
1655      * application's OBB files (if there are any) can be found. Note if the
1656      * application does not have any OBB files, this directory may not exist.
1657      * <p>
1658      * This is like {@link #getFilesDir()} in that these files will be deleted
1659      * when the application is uninstalled, however there are some important
1660      * differences:
1661      * <ul>
1662      * <li>Shared storage may not always be available, since removable media can
1663      * be ejected by the user. Media state can be checked using
1664      * {@link Environment#getExternalStorageState(File)}.
1665      * <li>There is no security enforced with these files. For example, any
1666      * application holding
1667      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1668      * these files.
1669      * </ul>
1670      * <p>
1671      * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
1672      * are required to read or write to the path that this method returns.
1673      * However, starting from {@link android.os.Build.VERSION_CODES#M},
1674      * to read the OBB expansion files, you must declare the
1675      * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1676      * permission at runtime as follows:
1677      * </p>
1678      * <p>
1679      * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1680      * android:maxSdkVersion="23" />}
1681      * </p>
1682      * <p>
1683      * Starting from {@link android.os.Build.VERSION_CODES#N},
1684      * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1685      * permission is not required, so don’t ask for this
1686      * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1687      * and if it fails, you must request
1688      * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1689      * </p>
1690      *
1691      * <p>
1692      * The following code snippet shows how to do this:
1693      * </p>
1694      *
1695      * <pre>
1696      * File obb = new File(obb_filename);
1697      * boolean open_failed = false;
1698      *
1699      * try {
1700      *     BufferedReader br = new BufferedReader(new FileReader(obb));
1701      *     open_failed = false;
1702      *     ReadObbFile(br);
1703      * } catch (IOException e) {
1704      *     open_failed = true;
1705      * }
1706      *
1707      * if (open_failed) {
1708      *     // request READ_EXTERNAL_STORAGE permission before reading OBB file
1709      *     ReadObbFileWithPermission();
1710      * }
1711      * </pre>
1712      *
1713      * On devices with multiple users (as described by {@link UserManager}),
1714      * multiple users may share the same OBB storage location. Applications
1715      * should ensure that multiple instances running under different users don't
1716      * interfere with each other.
1717      *
1718      * @return the absolute path to application-specific directory. May return
1719      *         {@code null} if shared storage is not currently available.
1720      * @see #getObbDirs()
1721      * @see Environment#getExternalStorageState(File)
1722      * @see Environment#isExternalStorageEmulated(File)
1723      * @see Environment#isExternalStorageRemovable(File)
1724      */
getObbDir()1725     public abstract File getObbDir();
1726 
1727     /**
1728      * Returns absolute paths to application-specific directories on all
1729      * shared/external storage devices where the application's OBB files (if
1730      * there are any) can be found. Note if the application does not have any
1731      * OBB files, these directories may not exist.
1732      * <p>
1733      * This is like {@link #getFilesDir()} in that these files will be deleted
1734      * when the application is uninstalled, however there are some important
1735      * differences:
1736      * <ul>
1737      * <li>Shared storage may not always be available, since removable media can
1738      * be ejected by the user. Media state can be checked using
1739      * {@link Environment#getExternalStorageState(File)}.
1740      * <li>There is no security enforced with these files. For example, any
1741      * application holding
1742      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1743      * these files.
1744      * </ul>
1745      * <p>
1746      * Shared storage devices returned here are considered a stable part of the
1747      * device, including physical media slots under a protective cover. The
1748      * returned paths do not include transient devices, such as USB flash drives
1749      * connected to handheld devices.
1750      * <p>
1751      * An application may store data on any or all of the returned devices. For
1752      * example, an app may choose to store large files on the device with the
1753      * most available space, as measured by {@link StatFs}.
1754      * <p>
1755      * No additional permissions are required for the calling app to read or
1756      * write files under the returned path. Write access outside of these paths
1757      * on secondary external storage devices is not available.
1758      *
1759      * @return the absolute paths to application-specific directories. Some
1760      *         individual paths may be {@code null} if that shared storage is
1761      *         not currently available. The first path returned is the same as
1762      *         {@link #getObbDir()}
1763      * @see #getObbDir()
1764      * @see Environment#getExternalStorageState(File)
1765      * @see Environment#isExternalStorageEmulated(File)
1766      * @see Environment#isExternalStorageRemovable(File)
1767      */
getObbDirs()1768     public abstract File[] getObbDirs();
1769 
1770     /**
1771      * Returns the absolute path to the application specific cache directory on
1772      * the filesystem.
1773      * <p>
1774      * The system will automatically delete files in this directory as disk
1775      * space is needed elsewhere on the device. The system will always delete
1776      * older files first, as reported by {@link File#lastModified()}. If
1777      * desired, you can exert more control over how files are deleted using
1778      * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1779      * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1780      * <p>
1781      * Apps are strongly encouraged to keep their usage of cache space below the
1782      * quota returned by
1783      * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1784      * goes above this quota, your cached files will be some of the first to be
1785      * deleted when additional disk space is needed. Conversely, if your app
1786      * stays under this quota, your cached files will be some of the last to be
1787      * deleted when additional disk space is needed.
1788      * <p>
1789      * Note that your cache quota will change over time depending on how
1790      * frequently the user interacts with your app, and depending on how much
1791      * system-wide disk space is used.
1792      * <p>
1793      * The returned path may change over time if the calling app is moved to an
1794      * adopted storage device, so only relative paths should be persisted.
1795      * <p>
1796      * Apps require no extra permissions to read or write to the returned path,
1797      * since this path lives in their private storage.
1798      *
1799      * @return The path of the directory holding application cache files.
1800      * @see #openFileOutput
1801      * @see #getFileStreamPath
1802      * @see #getDir
1803      * @see #getExternalCacheDir
1804      */
getCacheDir()1805     public abstract File getCacheDir();
1806 
1807     /**
1808      * Returns the absolute path to the application specific cache directory on
1809      * the filesystem designed for storing cached code.
1810      * <p>
1811      * The system will delete any files stored in this location both when your
1812      * specific application is upgraded, and when the entire platform is
1813      * upgraded.
1814      * <p>
1815      * This location is optimal for storing compiled or optimized code generated
1816      * by your application at runtime.
1817      * <p>
1818      * The returned path may change over time if the calling app is moved to an
1819      * adopted storage device, so only relative paths should be persisted.
1820      * <p>
1821      * Apps require no extra permissions to read or write to the returned path,
1822      * since this path lives in their private storage.
1823      *
1824      * @return The path of the directory holding application code cache files.
1825      */
getCodeCacheDir()1826     public abstract File getCodeCacheDir();
1827 
1828     /**
1829      * Returns absolute path to application-specific directory on the primary
1830      * shared/external storage device where the application can place cache
1831      * files it owns. These files are internal to the application, and not
1832      * typically visible to the user as media.
1833      * <p>
1834      * This is like {@link #getCacheDir()} in that these files will be deleted
1835      * when the application is uninstalled, however there are some important
1836      * differences:
1837      * <ul>
1838      * <li>The platform does not always monitor the space available in shared
1839      * storage, and thus may not automatically delete these files. Apps should
1840      * always manage the maximum space used in this location. Currently the only
1841      * time files here will be deleted by the platform is when running on
1842      * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1843      * {@link Environment#isExternalStorageEmulated(File)} returns true.
1844      * <li>Shared storage may not always be available, since removable media can
1845      * be ejected by the user. Media state can be checked using
1846      * {@link Environment#getExternalStorageState(File)}.
1847      * <li>There is no security enforced with these files. For example, any
1848      * application holding
1849      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1850      * these files.
1851      * </ul>
1852      * <p>
1853      * If a shared storage device is emulated (as determined by
1854      * {@link Environment#isExternalStorageEmulated(File)}), its contents are
1855      * backed by a private user data partition, which means there is little
1856      * benefit to storing data here instead of the private directory returned by
1857      * {@link #getCacheDir()}.
1858      * <p>
1859      * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
1860      * are required to read or write to the returned path; it's always
1861      * accessible to the calling app. This only applies to paths generated for
1862      * package name of the calling application. To access paths belonging to
1863      * other packages,
1864      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1865      * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1866      * <p>
1867      * On devices with multiple users (as described by {@link UserManager}),
1868      * each user has their own isolated shared storage. Applications only have
1869      * access to the shared storage for the user they're running as.
1870      * <p>
1871      * The returned path may change over time if different shared storage media
1872      * is inserted, so only relative paths should be persisted.
1873      *
1874      * @return the absolute path to application-specific directory. May return
1875      *         {@code null} if shared storage is not currently available.
1876      * @see #getCacheDir
1877      * @see #getExternalCacheDirs()
1878      * @see Environment#getExternalStorageState(File)
1879      * @see Environment#isExternalStorageEmulated(File)
1880      * @see Environment#isExternalStorageRemovable(File)
1881      */
1882     @Nullable
getExternalCacheDir()1883     public abstract File getExternalCacheDir();
1884 
1885     /**
1886      * Returns absolute path to application-specific directory in the preloaded cache.
1887      * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1888      * There is no guarantee when these files will be deleted.
1889      * @hide
1890      */
1891     @SuppressWarnings("HiddenAbstractMethod")
1892     @Nullable
1893     @SystemApi
getPreloadsFileCache()1894     public abstract File getPreloadsFileCache();
1895 
1896     /**
1897      * Returns absolute paths to application-specific directories on all
1898      * shared/external storage devices where the application can place cache
1899      * files it owns. These files are internal to the application, and not
1900      * typically visible to the user as media.
1901      * <p>
1902      * This is like {@link #getCacheDir()} in that these files will be deleted
1903      * when the application is uninstalled, however there are some important
1904      * differences:
1905      * <ul>
1906      * <li>The platform does not always monitor the space available in shared
1907      * storage, and thus may not automatically delete these files. Apps should
1908      * always manage the maximum space used in this location. Currently the only
1909      * time files here will be deleted by the platform is when running on
1910      * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1911      * {@link Environment#isExternalStorageEmulated(File)} returns true.
1912      * <li>Shared storage may not always be available, since removable media can
1913      * be ejected by the user. Media state can be checked using
1914      * {@link Environment#getExternalStorageState(File)}.
1915      * <li>There is no security enforced with these files. For example, any
1916      * application holding
1917      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1918      * these files.
1919      * </ul>
1920      * <p>
1921      * If a shared storage device is emulated (as determined by
1922      * {@link Environment#isExternalStorageEmulated(File)}), its contents are
1923      * backed by a private user data partition, which means there is little
1924      * benefit to storing data here instead of the private directory returned by
1925      * {@link #getCacheDir()}.
1926      * <p>
1927      * Shared storage devices returned here are considered a stable part of the
1928      * device, including physical media slots under a protective cover. The
1929      * returned paths do not include transient devices, such as USB flash drives
1930      * connected to handheld devices.
1931      * <p>
1932      * An application may store data on any or all of the returned devices. For
1933      * example, an app may choose to store large files on the device with the
1934      * most available space, as measured by {@link StatFs}.
1935      * <p>
1936      * No additional permissions are required for the calling app to read or
1937      * write files under the returned path. Write access outside of these paths
1938      * on secondary external storage devices is not available.
1939      * <p>
1940      * The returned paths may change over time if different shared storage media
1941      * is inserted, so only relative paths should be persisted.
1942      *
1943      * @return the absolute paths to application-specific directories. Some
1944      *         individual paths may be {@code null} if that shared storage is
1945      *         not currently available. The first path returned is the same as
1946      *         {@link #getExternalCacheDir()}.
1947      * @see #getExternalCacheDir()
1948      * @see Environment#getExternalStorageState(File)
1949      * @see Environment#isExternalStorageEmulated(File)
1950      * @see Environment#isExternalStorageRemovable(File)
1951      */
getExternalCacheDirs()1952     public abstract File[] getExternalCacheDirs();
1953 
1954     /**
1955      * Returns absolute paths to application-specific directories on all
1956      * shared/external storage devices where the application can place media
1957      * files. These files are scanned and made available to other apps through
1958      * {@link MediaStore}.
1959      * <p>
1960      * This is like {@link #getExternalFilesDirs} in that these files will be
1961      * deleted when the application is uninstalled, however there are some
1962      * important differences:
1963      * <ul>
1964      * <li>Shared storage may not always be available, since removable media can
1965      * be ejected by the user. Media state can be checked using
1966      * {@link Environment#getExternalStorageState(File)}.
1967      * <li>There is no security enforced with these files. For example, any
1968      * application holding
1969      * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1970      * these files.
1971      * </ul>
1972      * <p>
1973      * Shared storage devices returned here are considered a stable part of the
1974      * device, including physical media slots under a protective cover. The
1975      * returned paths do not include transient devices, such as USB flash drives
1976      * connected to handheld devices.
1977      * <p>
1978      * An application may store data on any or all of the returned devices. For
1979      * example, an app may choose to store large files on the device with the
1980      * most available space, as measured by {@link StatFs}.
1981      * <p>
1982      * No additional permissions are required for the calling app to read or
1983      * write files under the returned path. Write access outside of these paths
1984      * on secondary external storage devices is not available.
1985      * <p>
1986      * The returned paths may change over time if different shared storage media
1987      * is inserted, so only relative paths should be persisted.
1988      *
1989      * @return the absolute paths to application-specific directories. Some
1990      *         individual paths may be {@code null} if that shared storage is
1991      *         not currently available.
1992      * @see Environment#getExternalStorageState(File)
1993      * @see Environment#isExternalStorageEmulated(File)
1994      * @see Environment#isExternalStorageRemovable(File)
1995      * @deprecated These directories still exist and are scanned, but developers
1996      *             are encouraged to migrate to inserting content into a
1997      *             {@link MediaStore} collection directly, as any app can
1998      *             contribute new media to {@link MediaStore} with no
1999      *             permissions required, starting in
2000      *             {@link android.os.Build.VERSION_CODES#Q}.
2001      */
2002     @Deprecated
getExternalMediaDirs()2003     public abstract File[] getExternalMediaDirs();
2004 
2005     /**
2006      * Returns an array of strings naming the private files associated with
2007      * this Context's application package.
2008      *
2009      * @return Array of strings naming the private files.
2010      *
2011      * @see #openFileInput
2012      * @see #openFileOutput
2013      * @see #deleteFile
2014      */
fileList()2015     public abstract String[] fileList();
2016 
2017     /**
2018      * Retrieve, creating if needed, a new directory in which the application
2019      * can place its own custom data files.  You can use the returned File
2020      * object to create and access files in this directory.  Note that files
2021      * created through a File object will only be accessible by your own
2022      * application; you can only set the mode of the entire directory, not
2023      * of individual files.
2024      * <p>
2025      * The returned path may change over time if the calling app is moved to an
2026      * adopted storage device, so only relative paths should be persisted.
2027      * <p>
2028      * Apps require no extra permissions to read or write to the returned path,
2029      * since this path lives in their private storage.
2030      *
2031      * @param name Name of the directory to retrieve.  This is a directory
2032      * that is created as part of your application data.
2033      * @param mode Operating mode.
2034      *
2035      * @return A {@link File} object for the requested directory.  The directory
2036      * will have been created if it does not already exist.
2037      *
2038      * @see #openFileOutput(String, int)
2039      */
getDir(String name, @FileMode int mode)2040     public abstract File getDir(String name, @FileMode int mode);
2041 
2042     /**
2043      * Open a new private SQLiteDatabase associated with this Context's
2044      * application package. Create the database file if it doesn't exist.
2045      *
2046      * @param name The name (unique in the application package) of the database.
2047      * @param mode Operating mode.
2048      * @param factory An optional factory class that is called to instantiate a
2049      *            cursor when query is called.
2050      * @return The contents of a newly created database with the given name.
2051      * @throws android.database.sqlite.SQLiteException if the database file
2052      *             could not be opened.
2053      * @see #MODE_PRIVATE
2054      * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
2055      * @see #MODE_NO_LOCALIZED_COLLATORS
2056      * @see #deleteDatabase
2057      */
openOrCreateDatabase(String name, @DatabaseMode int mode, CursorFactory factory)2058     public abstract SQLiteDatabase openOrCreateDatabase(String name,
2059             @DatabaseMode int mode, CursorFactory factory);
2060 
2061     /**
2062      * Open a new private SQLiteDatabase associated with this Context's
2063      * application package. Creates the database file if it doesn't exist.
2064      * <p>
2065      * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
2066      * to be used to handle corruption when sqlite reports database corruption.
2067      * </p>
2068      *
2069      * @param name The name (unique in the application package) of the database.
2070      * @param mode Operating mode.
2071      * @param factory An optional factory class that is called to instantiate a
2072      *            cursor when query is called.
2073      * @param errorHandler the {@link DatabaseErrorHandler} to be used when
2074      *            sqlite reports database corruption. if null,
2075      *            {@link android.database.DefaultDatabaseErrorHandler} is
2076      *            assumed.
2077      * @return The contents of a newly created database with the given name.
2078      * @throws android.database.sqlite.SQLiteException if the database file
2079      *             could not be opened.
2080      * @see #MODE_PRIVATE
2081      * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
2082      * @see #MODE_NO_LOCALIZED_COLLATORS
2083      * @see #deleteDatabase
2084      */
openOrCreateDatabase(String name, @DatabaseMode int mode, CursorFactory factory, @Nullable DatabaseErrorHandler errorHandler)2085     public abstract SQLiteDatabase openOrCreateDatabase(String name,
2086             @DatabaseMode int mode, CursorFactory factory,
2087             @Nullable DatabaseErrorHandler errorHandler);
2088 
2089     /**
2090      * Move an existing database file from the given source storage context to
2091      * this context. This is typically used to migrate data between storage
2092      * locations after an upgrade, such as migrating to device protected
2093      * storage.
2094      * <p>
2095      * The database must be closed before being moved.
2096      *
2097      * @param sourceContext The source context which contains the existing
2098      *            database to move.
2099      * @param name The name of the database file.
2100      * @return {@code true} if the move was successful or if the database didn't
2101      *         exist in the source context, otherwise {@code false}.
2102      * @see #createDeviceProtectedStorageContext()
2103      */
moveDatabaseFrom(Context sourceContext, String name)2104     public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
2105 
2106     /**
2107      * Delete an existing private SQLiteDatabase associated with this Context's
2108      * application package.
2109      *
2110      * @param name The name (unique in the application package) of the
2111      *             database.
2112      *
2113      * @return {@code true} if the database was successfully deleted; else {@code false}.
2114      *
2115      * @see #openOrCreateDatabase
2116      */
deleteDatabase(String name)2117     public abstract boolean deleteDatabase(String name);
2118 
2119     /**
2120      * Returns the absolute path on the filesystem where a database created with
2121      * {@link #openOrCreateDatabase} is stored.
2122      * <p>
2123      * The returned path may change over time if the calling app is moved to an
2124      * adopted storage device, so only relative paths should be persisted.
2125      *
2126      * @param name The name of the database for which you would like to get
2127      *          its path.
2128      *
2129      * @return An absolute path to the given database.
2130      *
2131      * @see #openOrCreateDatabase
2132      */
getDatabasePath(String name)2133     public abstract File getDatabasePath(String name);
2134 
2135     /**
2136      * Returns an array of strings naming the private databases associated with
2137      * this Context's application package.
2138      *
2139      * @return Array of strings naming the private databases.
2140      *
2141      * @see #openOrCreateDatabase
2142      * @see #deleteDatabase
2143      */
databaseList()2144     public abstract String[] databaseList();
2145 
2146     /**
2147      * @deprecated Use {@link android.app.WallpaperManager#getDrawable
2148      * WallpaperManager.get()} instead.
2149      */
2150     @Deprecated
getWallpaper()2151     public abstract Drawable getWallpaper();
2152 
2153     /**
2154      * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
2155      * WallpaperManager.peek()} instead.
2156      */
2157     @Deprecated
peekWallpaper()2158     public abstract Drawable peekWallpaper();
2159 
2160     /**
2161      * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
2162      * WallpaperManager.getDesiredMinimumWidth()} instead.
2163      */
2164     @Deprecated
getWallpaperDesiredMinimumWidth()2165     public abstract int getWallpaperDesiredMinimumWidth();
2166 
2167     /**
2168      * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
2169      * WallpaperManager.getDesiredMinimumHeight()} instead.
2170      */
2171     @Deprecated
getWallpaperDesiredMinimumHeight()2172     public abstract int getWallpaperDesiredMinimumHeight();
2173 
2174     /**
2175      * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
2176      * WallpaperManager.set()} instead.
2177      * <p>This method requires the caller to hold the permission
2178      * {@link android.Manifest.permission#SET_WALLPAPER}.
2179      */
2180     @Deprecated
setWallpaper(Bitmap bitmap)2181     public abstract void setWallpaper(Bitmap bitmap) throws IOException;
2182 
2183     /**
2184      * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
2185      * WallpaperManager.set()} instead.
2186      * <p>This method requires the caller to hold the permission
2187      * {@link android.Manifest.permission#SET_WALLPAPER}.
2188      */
2189     @Deprecated
setWallpaper(InputStream data)2190     public abstract void setWallpaper(InputStream data) throws IOException;
2191 
2192     /**
2193      * @deprecated Use {@link android.app.WallpaperManager#clear
2194      * WallpaperManager.clear()} instead.
2195      * <p>This method requires the caller to hold the permission
2196      * {@link android.Manifest.permission#SET_WALLPAPER}.
2197      */
2198     @Deprecated
clearWallpaper()2199     public abstract void clearWallpaper() throws IOException;
2200 
2201     /**
2202      * Same as {@link #startActivity(Intent, Bundle)} with no options
2203      * specified.
2204      *
2205      * @param intent The description of the activity to start.
2206      *
2207      * @throws ActivityNotFoundException &nbsp;
2208      *`
2209      * @see #startActivity(Intent, Bundle)
2210      * @see PackageManager#resolveActivity
2211      */
startActivity(@equiresPermission Intent intent)2212     public abstract void startActivity(@RequiresPermission Intent intent);
2213 
2214     /**
2215      * Version of {@link #startActivity(Intent)} that allows you to specify the
2216      * user the activity will be started for.  This is not available to applications
2217      * that are not pre-installed on the system image.
2218      * @param intent The description of the activity to start.
2219      * @param user The UserHandle of the user to start this activity for.
2220      * @throws ActivityNotFoundException &nbsp;
2221      * @hide
2222      */
2223     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
2224     @SystemApi
startActivityAsUser(@equiresPermission @onNull Intent intent, @NonNull UserHandle user)2225     public void startActivityAsUser(@RequiresPermission @NonNull Intent intent,
2226             @NonNull UserHandle user) {
2227         throw new RuntimeException("Not implemented. Must override in a subclass.");
2228     }
2229 
2230     /**
2231      * Launch a new activity.  You will not receive any information about when
2232      * the activity exits.
2233      *
2234      * <p>Note that if this method is being called from outside of an
2235      * {@link android.app.Activity} Context, then the Intent must include
2236      * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag.  This is because,
2237      * without being started from an existing Activity, there is no existing
2238      * task in which to place the new activity and thus it needs to be placed
2239      * in its own separate task.
2240      *
2241      * <p>This method throws {@link ActivityNotFoundException}
2242      * if there was no Activity found to run the given Intent.
2243      *
2244      * @param intent The description of the activity to start.
2245      * @param options Additional options for how the Activity should be started.
2246      * May be null if there are no options.  See {@link android.app.ActivityOptions}
2247      * for how to build the Bundle supplied here; there are no supported definitions
2248      * for building it manually.
2249      *
2250      * @throws ActivityNotFoundException &nbsp;
2251      *
2252      * @see #startActivity(Intent)
2253      * @see PackageManager#resolveActivity
2254      */
startActivity(@equiresPermission Intent intent, @Nullable Bundle options)2255     public abstract void startActivity(@RequiresPermission Intent intent,
2256             @Nullable Bundle options);
2257 
2258     /**
2259      * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
2260      * user the activity will be started for.  This is not available to applications
2261      * that are not pre-installed on the system image.
2262      * @param intent The description of the activity to start.
2263      * @param options Additional options for how the Activity should be started.
2264      * May be null if there are no options.  See {@link android.app.ActivityOptions}
2265      * for how to build the Bundle supplied here; there are no supported definitions
2266      * for building it manually.
2267      * @param userId The UserHandle of the user to start this activity for.
2268      * @throws ActivityNotFoundException &nbsp;
2269      * @hide
2270      */
2271     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
2272     @SystemApi
startActivityAsUser(@equiresPermission @onNull Intent intent, @Nullable Bundle options, @NonNull UserHandle userId)2273     public void startActivityAsUser(@RequiresPermission @NonNull Intent intent,
2274             @Nullable Bundle options, @NonNull UserHandle userId) {
2275         throw new RuntimeException("Not implemented. Must override in a subclass.");
2276     }
2277 
2278     /**
2279      * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
2280      * is only supported for Views and Fragments.
2281      * @param who The identifier for the calling element that will receive the result.
2282      * @param intent The intent to start.
2283      * @param requestCode The code that will be returned with onActivityResult() identifying this
2284      *          request.
2285      * @param options Additional options for how the Activity should be started.
2286      *          May be null if there are no options.  See {@link android.app.ActivityOptions}
2287      *          for how to build the Bundle supplied here; there are no supported definitions
2288      *          for building it manually.
2289      * @hide
2290      */
2291     @UnsupportedAppUsage
startActivityForResult( @onNull String who, Intent intent, int requestCode, @Nullable Bundle options)2292     public void startActivityForResult(
2293             @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
2294         throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
2295                 + "Check canStartActivityForResult() before calling.");
2296     }
2297 
2298     /**
2299      * Identifies whether this Context instance will be able to process calls to
2300      * {@link #startActivityForResult(String, Intent, int, Bundle)}.
2301      * @hide
2302      */
2303     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
canStartActivityForResult()2304     public boolean canStartActivityForResult() {
2305         return false;
2306     }
2307 
2308     /**
2309      * Same as {@link #startActivities(Intent[], Bundle)} with no options
2310      * specified.
2311      *
2312      * @param intents An array of Intents to be started.
2313      *
2314      * @throws ActivityNotFoundException &nbsp;
2315      *
2316      * @see #startActivities(Intent[], Bundle)
2317      * @see PackageManager#resolveActivity
2318      */
startActivities(@equiresPermission Intent[] intents)2319     public abstract void startActivities(@RequiresPermission Intent[] intents);
2320 
2321     /**
2322      * Launch multiple new activities.  This is generally the same as calling
2323      * {@link #startActivity(Intent)} for the first Intent in the array,
2324      * that activity during its creation calling {@link #startActivity(Intent)}
2325      * for the second entry, etc.  Note that unlike that approach, generally
2326      * none of the activities except the last in the array will be created
2327      * at this point, but rather will be created when the user first visits
2328      * them (due to pressing back from the activity on top).
2329      *
2330      * <p>This method throws {@link ActivityNotFoundException}
2331      * if there was no Activity found for <em>any</em> given Intent.  In this
2332      * case the state of the activity stack is undefined (some Intents in the
2333      * list may be on it, some not), so you probably want to avoid such situations.
2334      *
2335      * @param intents An array of Intents to be started.
2336      * @param options Additional options for how the Activity should be started.
2337      * See {@link android.content.Context#startActivity(Intent, Bundle)}
2338      * Context.startActivity(Intent, Bundle)} for more details.
2339      *
2340      * @throws ActivityNotFoundException &nbsp;
2341      *
2342      * @see #startActivities(Intent[])
2343      * @see PackageManager#resolveActivity
2344      */
startActivities(@equiresPermission Intent[] intents, Bundle options)2345     public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
2346 
2347     /**
2348      * @hide
2349      * Launch multiple new activities.  This is generally the same as calling
2350      * {@link #startActivity(Intent)} for the first Intent in the array,
2351      * that activity during its creation calling {@link #startActivity(Intent)}
2352      * for the second entry, etc.  Note that unlike that approach, generally
2353      * none of the activities except the last in the array will be created
2354      * at this point, but rather will be created when the user first visits
2355      * them (due to pressing back from the activity on top).
2356      *
2357      * <p>This method throws {@link ActivityNotFoundException}
2358      * if there was no Activity found for <em>any</em> given Intent.  In this
2359      * case the state of the activity stack is undefined (some Intents in the
2360      * list may be on it, some not), so you probably want to avoid such situations.
2361      *
2362      * @param intents An array of Intents to be started.
2363      * @param options Additional options for how the Activity should be started.
2364      * @param userHandle The user for whom to launch the activities
2365      * See {@link android.content.Context#startActivity(Intent, Bundle)}
2366      * Context.startActivity(Intent, Bundle)} for more details.
2367      *
2368      * @return The corresponding flag {@link ActivityManager#START_CANCELED},
2369      *         {@link ActivityManager#START_SUCCESS} etc. indicating whether the launch was
2370      *         successful.
2371      *
2372      * @throws ActivityNotFoundException &nbsp;
2373      *
2374      * @see #startActivities(Intent[])
2375      * @see PackageManager#resolveActivity
2376      */
2377     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle)2378     public int startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
2379         throw new RuntimeException("Not implemented. Must override in a subclass.");
2380     }
2381 
2382     /**
2383      * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
2384      * with no options specified.
2385      *
2386      * @param intent The IntentSender to launch.
2387      * @param fillInIntent If non-null, this will be provided as the
2388      * intent parameter to {@link IntentSender#sendIntent}.
2389      * @param flagsMask Intent flags in the original IntentSender that you
2390      * would like to change.
2391      * @param flagsValues Desired values for any bits set in
2392      * <var>flagsMask</var>
2393      * @param extraFlags Always set to 0.
2394      *
2395      * @see #startActivity(Intent)
2396      * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
2397      */
startIntentSender(IntentSender intent, @Nullable Intent fillInIntent, @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues, int extraFlags)2398     public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
2399             @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
2400             int extraFlags) throws IntentSender.SendIntentException;
2401 
2402     /**
2403      * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
2404      * to start.  If the IntentSender is for an activity, that activity will be started
2405      * as if you had called the regular {@link #startActivity(Intent)}
2406      * here; otherwise, its associated action will be executed (such as
2407      * sending a broadcast) as if you had called
2408      * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
2409      *
2410      * @param intent The IntentSender to launch.
2411      * @param fillInIntent If non-null, this will be provided as the
2412      * intent parameter to {@link IntentSender#sendIntent}.
2413      * @param flagsMask Intent flags in the original IntentSender that you
2414      * would like to change.
2415      * @param flagsValues Desired values for any bits set in
2416      * <var>flagsMask</var>
2417      * @param extraFlags Always set to 0.
2418      * @param options Additional options for how the Activity should be started.
2419      * See {@link android.content.Context#startActivity(Intent, Bundle)}
2420      * Context.startActivity(Intent, Bundle)} for more details.  If options
2421      * have also been supplied by the IntentSender, options given here will
2422      * override any that conflict with those given by the IntentSender.
2423      *
2424      * @see #startActivity(Intent, Bundle)
2425      * @see #startIntentSender(IntentSender, Intent, int, int, int)
2426      */
startIntentSender(IntentSender intent, @Nullable Intent fillInIntent, @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues, int extraFlags, @Nullable Bundle options)2427     public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
2428             @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
2429             int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
2430 
2431     /**
2432      * Broadcast the given intent to all interested BroadcastReceivers.  This
2433      * call is asynchronous; it returns immediately, and you will continue
2434      * executing while the receivers are run.  No results are propagated from
2435      * receivers and receivers can not abort the broadcast. If you want
2436      * to allow receivers to propagate results or abort the broadcast, you must
2437      * send an ordered broadcast using
2438      * {@link #sendOrderedBroadcast(Intent, String)}.
2439      *
2440      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2441      *
2442      * @param intent The Intent to broadcast; all receivers matching this
2443      *               Intent will receive the broadcast.
2444      *
2445      * @see android.content.BroadcastReceiver
2446      * @see #registerReceiver
2447      * @see #sendBroadcast(Intent, String)
2448      * @see #sendOrderedBroadcast(Intent, String)
2449      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2450      */
sendBroadcast(@equiresPermission Intent intent)2451     public abstract void sendBroadcast(@RequiresPermission Intent intent);
2452 
2453     /**
2454      * Broadcast the given intent to all interested BroadcastReceivers, allowing
2455      * an optional required permission to be enforced.  This
2456      * call is asynchronous; it returns immediately, and you will continue
2457      * executing while the receivers are run.  No results are propagated from
2458      * receivers and receivers can not abort the broadcast. If you want
2459      * to allow receivers to propagate results or abort the broadcast, you must
2460      * send an ordered broadcast using
2461      * {@link #sendOrderedBroadcast(Intent, String)}.
2462      *
2463      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2464      *
2465      * @param intent The Intent to broadcast; all receivers matching this
2466      *               Intent will receive the broadcast.
2467      * @param receiverPermission (optional) String naming a permission that
2468      *               a receiver must hold in order to receive your broadcast.
2469      *               If null, no permission is required.
2470      *
2471      * @see android.content.BroadcastReceiver
2472      * @see #registerReceiver
2473      * @see #sendBroadcast(Intent)
2474      * @see #sendOrderedBroadcast(Intent, String)
2475      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2476      */
sendBroadcast(@equiresPermission Intent intent, @Nullable String receiverPermission)2477     public abstract void sendBroadcast(@RequiresPermission Intent intent,
2478             @Nullable String receiverPermission);
2479 
2480 
2481     /**
2482      * Broadcast the given intent to all interested BroadcastReceivers, allowing
2483      * an array of required permissions to be enforced.  This call is asynchronous; it returns
2484      * immediately, and you will continue executing while the receivers are run.  No results are
2485      * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2486      * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2487      * using {@link #sendOrderedBroadcast(Intent, String)}.
2488      *
2489      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2490      *
2491      * @param intent The Intent to broadcast; all receivers matching this
2492      *               Intent will receive the broadcast.
2493      * @param receiverPermissions Array of names of permissions that a receiver must hold
2494      *                            in order to receive your broadcast.
2495      *                            If empty, no permissions are required.
2496      *
2497      * @see android.content.BroadcastReceiver
2498      * @see #registerReceiver
2499      * @see #sendBroadcast(Intent)
2500      * @see #sendOrderedBroadcast(Intent, String)
2501      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2502      * @hide
2503      */
sendBroadcastMultiplePermissions(@onNull Intent intent, @NonNull String[] receiverPermissions)2504     public void sendBroadcastMultiplePermissions(@NonNull Intent intent,
2505             @NonNull String[] receiverPermissions) {
2506         throw new RuntimeException("Not implemented. Must override in a subclass.");
2507     }
2508 
2509     /**
2510      * Like {@link #sendBroadcastMultiplePermissions(Intent, String[])}, but also allows
2511      * specification of a list of excluded permissions. This allows sending a broadcast to an
2512      * app that has the permissions in `receiverPermissions` but not `excludedPermissions`.
2513      * @hide
2514      */
sendBroadcastMultiplePermissions(@onNull Intent intent, @NonNull String[] receiverPermissions, @Nullable String[] excludedPermissions)2515     public void sendBroadcastMultiplePermissions(@NonNull Intent intent,
2516             @NonNull String[] receiverPermissions, @Nullable String[] excludedPermissions) {
2517         sendBroadcastMultiplePermissions(intent, receiverPermissions, excludedPermissions, null);
2518     }
2519 
2520     /**
2521      * Like {@link #sendBroadcastMultiplePermissions(Intent, String[], String[])}, but also allows
2522      * specification of a list of excluded packages.
2523      *
2524      * @hide
2525      */
sendBroadcastMultiplePermissions(@onNull Intent intent, @NonNull String[] receiverPermissions, @Nullable String[] excludedPermissions, @Nullable String[] excludedPackages)2526     public void sendBroadcastMultiplePermissions(@NonNull Intent intent,
2527             @NonNull String[] receiverPermissions, @Nullable String[] excludedPermissions,
2528             @Nullable String[] excludedPackages) {
2529         sendBroadcastMultiplePermissions(intent, receiverPermissions, excludedPermissions,
2530                 excludedPackages, null);
2531     }
2532 
2533     /**
2534      * Like {@link #sendBroadcastMultiplePermissions(Intent, String[], String[], String[])}, but
2535      * also allows specification of options generated from {@link android.app.BroadcastOptions}.
2536      *
2537      * @hide
2538      */
sendBroadcastMultiplePermissions(@onNull Intent intent, @NonNull String[] receiverPermissions, @Nullable String[] excludedPermissions, @Nullable String[] excludedPackages, @Nullable BroadcastOptions options)2539     public void sendBroadcastMultiplePermissions(@NonNull Intent intent,
2540             @NonNull String[] receiverPermissions, @Nullable String[] excludedPermissions,
2541             @Nullable String[] excludedPackages, @Nullable BroadcastOptions options) {
2542         throw new RuntimeException("Not implemented. Must override in a subclass.");
2543     }
2544 
2545     /**
2546      * Version of {@link #sendBroadcastMultiplePermissions(Intent, String[])} that allows you to
2547      * specify the {@link android.app.BroadcastOptions}.
2548      *
2549      * @param intent The Intent to broadcast; all receivers matching this
2550      *               Intent will receive the broadcast.
2551      * @param receiverPermissions Array of names of permissions that a receiver must hold
2552      *                            in order to receive your broadcast.
2553      *                            If empty, no permissions are required.
2554      * @param options Additional sending options, generated from a
2555      *                {@link android.app.BroadcastOptions}.
2556      * @see #sendBroadcastMultiplePermissions(Intent, String[])
2557      * @see android.app.BroadcastOptions
2558      * @hide
2559      */
sendBroadcastMultiplePermissions(@onNull Intent intent, @NonNull String[] receiverPermissions, @Nullable Bundle options)2560     public void sendBroadcastMultiplePermissions(@NonNull Intent intent,
2561             @NonNull String[] receiverPermissions, @Nullable Bundle options) {
2562         throw new RuntimeException("Not implemented. Must override in a subclass.");
2563     }
2564 
2565     /**
2566      * Version of {@link #sendBroadcastMultiplePermissions(Intent, String[])} that allows you to
2567      * specify the {@link android.app.BroadcastOptions}.
2568      *
2569      * @param intent The Intent to broadcast; all receivers matching this
2570      *               Intent will receive the broadcast.
2571      * @param receiverPermissions Array of names of permissions that a receiver must hold
2572      *                            in order to receive your broadcast.
2573      *                            If empty, no permissions are required.
2574      * @param options Additional sending options, generated from a
2575      *                {@link android.app.BroadcastOptions}.
2576      * @see #sendBroadcastMultiplePermissions(Intent, String[])
2577      * @see android.app.BroadcastOptions
2578      * @hide
2579      */
2580     @SystemApi
sendBroadcastMultiplePermissions(@onNull Intent intent, @NonNull String[] receiverPermissions, @Nullable BroadcastOptions options)2581     public void sendBroadcastMultiplePermissions(@NonNull Intent intent,
2582             @NonNull String[] receiverPermissions, @Nullable BroadcastOptions options) {
2583         sendBroadcastMultiplePermissions(intent, receiverPermissions,
2584                 (options == null ? null : options.toBundle()));
2585     }
2586 
2587     /**
2588      * Broadcast the given intent to all interested BroadcastReceivers, allowing
2589      * an array of required permissions to be enforced.  This call is asynchronous; it returns
2590      * immediately, and you will continue executing while the receivers are run.  No results are
2591      * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2592      * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2593      * using {@link #sendOrderedBroadcast(Intent, String)}.
2594      *
2595      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2596      *
2597      * @param intent The Intent to broadcast; all receivers matching this
2598      *               Intent will receive the broadcast.
2599      * @param receiverPermissions Array of names of permissions that a receiver must hold
2600      *                            in order to receive your broadcast.
2601      *                            If empty, no permissions are required.
2602      *
2603      * @see android.content.BroadcastReceiver
2604      * @see #registerReceiver
2605      * @see #sendBroadcast(Intent)
2606      * @see #sendOrderedBroadcast(Intent, String)
2607      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2608      */
sendBroadcastWithMultiplePermissions(@onNull Intent intent, @NonNull String[] receiverPermissions)2609     public void sendBroadcastWithMultiplePermissions(@NonNull Intent intent,
2610             @NonNull String[] receiverPermissions) {
2611         sendBroadcastMultiplePermissions(intent, receiverPermissions);
2612     }
2613 
2614     /**
2615      * Broadcast the given intent to all interested BroadcastReceivers, allowing
2616      * an array of required permissions to be enforced.  This call is asynchronous; it returns
2617      * immediately, and you will continue executing while the receivers are run.  No results are
2618      * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2619      * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2620      * using {@link #sendOrderedBroadcast(Intent, String)}.
2621      *
2622      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2623      *
2624      * @param intent The Intent to broadcast; all receivers matching this
2625      *               Intent will receive the broadcast.
2626      * @param user The user to send the broadcast to.
2627      * @param receiverPermissions Array of names of permissions that a receiver must hold
2628      *                            in order to receive your broadcast.
2629      *                            If null or empty, no permissions are required.
2630      *
2631      * @see android.content.BroadcastReceiver
2632      * @see #registerReceiver
2633      * @see #sendBroadcast(Intent)
2634      * @see #sendOrderedBroadcast(Intent, String)
2635      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2636      * @hide
2637      */
2638     @SuppressWarnings("HiddenAbstractMethod")
sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user, String[] receiverPermissions)2639     public abstract void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
2640             String[] receiverPermissions);
2641 
2642     /**
2643      * Broadcast the given intent to all interested BroadcastReceivers, allowing
2644      * an optional required permission to be enforced.  This
2645      * call is asynchronous; it returns immediately, and you will continue
2646      * executing while the receivers are run.  No results are propagated from
2647      * receivers and receivers can not abort the broadcast. If you want
2648      * to allow receivers to propagate results or abort the broadcast, you must
2649      * send an ordered broadcast using
2650      * {@link #sendOrderedBroadcast(Intent, String)}.
2651      *
2652      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2653      *
2654      * @param intent The Intent to broadcast; all receivers matching this
2655      *               Intent will receive the broadcast.
2656      * @param receiverPermission (optional) String naming a permission that
2657      *               a receiver must hold in order to receive your broadcast.
2658      *               If null, no permission is required.
2659      * @param options (optional) Additional sending options, generated from a
2660      * {@link android.app.BroadcastOptions}.
2661      *
2662      * @see android.content.BroadcastReceiver
2663      * @see #registerReceiver
2664      * @see #sendBroadcast(Intent)
2665      * @see #sendOrderedBroadcast(Intent, String)
2666      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2667      */
sendBroadcast(@onNull Intent intent, @Nullable String receiverPermission, @Nullable Bundle options)2668     public void sendBroadcast(@NonNull Intent intent,
2669             @Nullable String receiverPermission,
2670             @Nullable Bundle options) {
2671         throw new RuntimeException("Not implemented. Must override in a subclass.");
2672     }
2673 
2674     /**
2675      * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
2676      * of an associated app op as per {@link android.app.AppOpsManager}.
2677      * @hide
2678      */
2679     @SuppressWarnings("HiddenAbstractMethod")
2680     @UnsupportedAppUsage
sendBroadcast(Intent intent, String receiverPermission, int appOp)2681     public abstract void sendBroadcast(Intent intent,
2682             String receiverPermission, int appOp);
2683 
2684     /**
2685      * Broadcast the given intent to all interested BroadcastReceivers, delivering
2686      * them one at a time to allow more preferred receivers to consume the
2687      * broadcast before it is delivered to less preferred receivers.  This
2688      * call is asynchronous; it returns immediately, and you will continue
2689      * executing while the receivers are run.
2690      *
2691      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2692      *
2693      * @param intent The Intent to broadcast; all receivers matching this
2694      *               Intent will receive the broadcast.
2695      * @param receiverPermission (optional) String naming a permissions that
2696      *               a receiver must hold in order to receive your broadcast.
2697      *               If null, no permission is required.
2698      *
2699      * @see android.content.BroadcastReceiver
2700      * @see #registerReceiver
2701      * @see #sendBroadcast(Intent)
2702      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2703      */
sendOrderedBroadcast(@equiresPermission Intent intent, @Nullable String receiverPermission)2704     public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
2705             @Nullable String receiverPermission);
2706 
2707     /**
2708      * Broadcast the given intent to all interested BroadcastReceivers, delivering
2709      * them one at a time to allow more preferred receivers to consume the
2710      * broadcast before it is delivered to less preferred receivers.  This
2711      * call is asynchronous; it returns immediately, and you will continue
2712      * executing while the receivers are run.
2713      *
2714      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2715      *
2716      * @param intent             The Intent to broadcast; all receivers matching this
2717      *                           Intent will receive the broadcast.
2718      * @param receiverPermission (optional) String naming a permissions that
2719      *                           a receiver must hold in order to receive your broadcast.
2720      *                           If null, no permission is required.
2721      * @param options            (optional) Additional sending options, generated from a
2722      *                           {@link android.app.BroadcastOptions}.
2723      * @see android.content.BroadcastReceiver
2724      * @see #registerReceiver
2725      * @see #sendBroadcast(Intent)
2726      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2727      */
sendOrderedBroadcast(@onNull Intent intent, @Nullable String receiverPermission, @Nullable Bundle options)2728     public void sendOrderedBroadcast(@NonNull Intent intent, @Nullable String receiverPermission,
2729             @Nullable Bundle options) {
2730         throw new RuntimeException("Not implemented. Must override in a subclass.");
2731     }
2732 
2733     /**
2734      * Version of {@link #sendBroadcast(Intent)} that allows you to
2735      * receive data back from the broadcast.  This is accomplished by
2736      * supplying your own BroadcastReceiver when calling, which will be
2737      * treated as a final receiver at the end of the broadcast -- its
2738      * {@link BroadcastReceiver#onReceive} method will be called with
2739      * the result values collected from the other receivers.  The broadcast will
2740      * be serialized in the same way as calling
2741      * {@link #sendOrderedBroadcast(Intent, String)}.
2742      *
2743      * <p>Like {@link #sendBroadcast(Intent)}, this method is
2744      * asynchronous; it will return before
2745      * resultReceiver.onReceive() is called.
2746      *
2747      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2748      *
2749      * @param intent The Intent to broadcast; all receivers matching this
2750      *               Intent will receive the broadcast.
2751      * @param receiverPermission String naming a permissions that
2752      *               a receiver must hold in order to receive your broadcast.
2753      *               If null, no permission is required.
2754      * @param resultReceiver Your own BroadcastReceiver to treat as the final
2755      *                       receiver of the broadcast.
2756      * @param scheduler A custom Handler with which to schedule the
2757      *                  resultReceiver callback; if null it will be
2758      *                  scheduled in the Context's main thread.
2759      * @param initialCode An initial value for the result code.  Often
2760      *                    Activity.RESULT_OK.
2761      * @param initialData An initial value for the result data.  Often
2762      *                    null.
2763      * @param initialExtras An initial value for the result extras.  Often
2764      *                      null.
2765      *
2766      * @see #sendBroadcast(Intent)
2767      * @see #sendBroadcast(Intent, String)
2768      * @see #sendOrderedBroadcast(Intent, String)
2769      * @see android.content.BroadcastReceiver
2770      * @see #registerReceiver
2771      * @see android.app.Activity#RESULT_OK
2772      */
sendOrderedBroadcast(@equiresPermission @onNull Intent intent, @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)2773     public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
2774             @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
2775             @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2776             @Nullable Bundle initialExtras);
2777 
2778     /**
2779      * Version of {@link #sendBroadcast(Intent)} that allows you to
2780      * receive data back from the broadcast.  This is accomplished by
2781      * supplying your own BroadcastReceiver when calling, which will be
2782      * treated as a final receiver at the end of the broadcast -- its
2783      * {@link BroadcastReceiver#onReceive} method will be called with
2784      * the result values collected from the other receivers.  The broadcast will
2785      * be serialized in the same way as calling
2786      * {@link #sendOrderedBroadcast(Intent, String)}.
2787      *
2788      * <p>Like {@link #sendBroadcast(Intent)}, this method is
2789      * asynchronous; it will return before
2790      * resultReceiver.onReceive() is called.
2791      *
2792      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2793      *
2794      *
2795      * @param intent The Intent to broadcast; all receivers matching this
2796      *               Intent will receive the broadcast.
2797      * @param receiverPermission String naming a permissions that
2798      *               a receiver must hold in order to receive your broadcast.
2799      *               If null, no permission is required.
2800      * @param options (optional) Additional sending options, generated from a
2801      * {@link android.app.BroadcastOptions}.
2802      * @param resultReceiver Your own BroadcastReceiver to treat as the final
2803      *                       receiver of the broadcast.
2804      * @param scheduler A custom Handler with which to schedule the
2805      *                  resultReceiver callback; if null it will be
2806      *                  scheduled in the Context's main thread.
2807      * @param initialCode An initial value for the result code.  Often
2808      *                    Activity.RESULT_OK.
2809      * @param initialData An initial value for the result data.  Often
2810      *                    null.
2811      * @param initialExtras An initial value for the result extras.  Often
2812      *                      null.
2813      * @see #sendBroadcast(Intent)
2814      * @see #sendBroadcast(Intent, String)
2815      * @see #sendOrderedBroadcast(Intent, String)
2816      * @see android.content.BroadcastReceiver
2817      * @see #registerReceiver
2818      * @see android.app.Activity#RESULT_OK
2819      */
sendOrderedBroadcast(@onNull Intent intent, @Nullable String receiverPermission, @Nullable Bundle options, @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)2820     public void sendOrderedBroadcast(@NonNull Intent intent,
2821             @Nullable String receiverPermission, @Nullable Bundle options,
2822             @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2823             int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras) {
2824         throw new RuntimeException("Not implemented. Must override in a subclass.");
2825     }
2826 
2827     /**
2828      * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2829      * int, String, android.os.Bundle)}, but also allows specification
2830      * of an associated app op as per {@link android.app.AppOpsManager}.
2831      * @hide
2832      */
2833     @SuppressWarnings("HiddenAbstractMethod")
2834     @UnsupportedAppUsage
sendOrderedBroadcast(Intent intent, String receiverPermission, int appOp, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)2835     public abstract void sendOrderedBroadcast(Intent intent,
2836             String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2837             Handler scheduler, int initialCode, String initialData,
2838             Bundle initialExtras);
2839 
2840     /**
2841      * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2842      * user the broadcast will be sent to.  This is not available to applications
2843      * that are not pre-installed on the system image.
2844      * @param intent The intent to broadcast
2845      * @param user UserHandle to send the intent to.
2846      * @see #sendBroadcast(Intent)
2847      */
2848     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
sendBroadcastAsUser(@equiresPermission Intent intent, UserHandle user)2849     public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2850             UserHandle user);
2851 
2852     /**
2853      * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2854      * user the broadcast will be sent to.  This is not available to applications
2855      * that are not pre-installed on the system image.
2856      *
2857      * @param intent The Intent to broadcast; all receivers matching this
2858      *               Intent will receive the broadcast.
2859      * @param user UserHandle to send the intent to.
2860      * @param receiverPermission (optional) String naming a permission that
2861      *               a receiver must hold in order to receive your broadcast.
2862      *               If null, no permission is required.
2863      *
2864      * @see #sendBroadcast(Intent, String)
2865      */
2866     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
sendBroadcastAsUser(@equiresPermission Intent intent, UserHandle user, @Nullable String receiverPermission)2867     public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2868             UserHandle user, @Nullable String receiverPermission);
2869 
2870     /**
2871      * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2872      * user the broadcast will be sent to.  This is not available to applications
2873      * that are not pre-installed on the system image.
2874      *
2875      * @param intent The Intent to broadcast; all receivers matching this
2876      *               Intent will receive the broadcast.
2877      * @param user UserHandle to send the intent to.
2878      * @param receiverPermission (optional) String naming a permission that
2879      *               a receiver must hold in order to receive your broadcast.
2880      *               If null, no permission is required.
2881      * @param options (optional) Additional sending options, generated from a
2882      * {@link android.app.BroadcastOptions}.
2883      *
2884      * @see #sendBroadcast(Intent, String, Bundle)
2885      * @hide
2886      */
2887     @SuppressWarnings("HiddenAbstractMethod")
2888     @SystemApi
2889     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
sendBroadcastAsUser(@equiresPermission Intent intent, UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options)2890     public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2891             UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
2892 
2893     /**
2894      * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2895      * user the broadcast will be sent to.  This is not available to applications
2896      * that are not pre-installed on the system image.
2897      *
2898      * @param intent The Intent to broadcast; all receivers matching this
2899      *               Intent will receive the broadcast.
2900      * @param user UserHandle to send the intent to.
2901      * @param receiverPermission (optional) String naming a permission that
2902      *               a receiver must hold in order to receive your broadcast.
2903      *               If null, no permission is required.
2904      * @param appOp The app op associated with the broadcast.
2905      *
2906      * @see #sendBroadcast(Intent, String)
2907      *
2908      * @hide
2909      */
2910     @SuppressWarnings("HiddenAbstractMethod")
2911     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
2912     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
sendBroadcastAsUser(@equiresPermission Intent intent, UserHandle user, @Nullable String receiverPermission, int appOp)2913     public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2914             UserHandle user, @Nullable String receiverPermission, int appOp);
2915 
2916     /**
2917      * Version of
2918      * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2919      * that allows you to specify the
2920      * user the broadcast will be sent to.  This is not available to applications
2921      * that are not pre-installed on the system image.
2922      *
2923      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2924      *
2925      * @param intent The Intent to broadcast; all receivers matching this
2926      *               Intent will receive the broadcast.
2927      * @param user UserHandle to send the intent to.
2928      * @param receiverPermission String naming a permissions that
2929      *               a receiver must hold in order to receive your broadcast.
2930      *               If null, no permission is required.
2931      * @param resultReceiver Your own BroadcastReceiver to treat as the final
2932      *                       receiver of the broadcast.
2933      * @param scheduler A custom Handler with which to schedule the
2934      *                  resultReceiver callback; if null it will be
2935      *                  scheduled in the Context's main thread.
2936      * @param initialCode An initial value for the result code.  Often
2937      *                    Activity.RESULT_OK.
2938      * @param initialData An initial value for the result data.  Often
2939      *                    null.
2940      * @param initialExtras An initial value for the result extras.  Often
2941      *                      null.
2942      *
2943      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2944      */
2945     @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)2946     public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2947             UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
2948             @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2949             @Nullable  Bundle initialExtras);
2950 
2951     /**
2952      * Similar to above but takes an appOp as well, to enforce restrictions.
2953      * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2954      *       BroadcastReceiver, Handler, int, String, Bundle)
2955      * @hide
2956      */
2957     @SuppressWarnings("HiddenAbstractMethod")
2958     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
2959     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
sendOrderedBroadcastAsUser(Intent intent, UserHandle user, @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)2960     public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2961             @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2962             @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2963             @Nullable  Bundle initialExtras);
2964 
2965     /**
2966      * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2967      * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2968      *       BroadcastReceiver, Handler, int, String, Bundle)
2969      * @hide
2970      */
2971     @SuppressWarnings("HiddenAbstractMethod")
2972     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
2973     @UnsupportedAppUsage
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)2974     public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2975             @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2976             BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2977             @Nullable String initialData, @Nullable  Bundle initialExtras);
2978 
2979     /**
2980      * Similar to above but takes array of names of permissions that a receiver must hold in order
2981      * to receive your broadcast. If empty, no permissions are required.
2982      *
2983      * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2984      *       BroadcastReceiver, Handler, int, String, Bundle)
2985      * @hide
2986      */
2987     @SuppressWarnings("HiddenAbstractMethod")
2988     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
sendOrderedBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user, String[] receiverPermissions, int appOp, Bundle options, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)2989     public void sendOrderedBroadcastAsUserMultiplePermissions(Intent intent,
2990             UserHandle user, String[] receiverPermissions, int appOp, Bundle options,
2991             BroadcastReceiver resultReceiver, Handler scheduler, int initialCode,
2992             String initialData, Bundle initialExtras) {
2993         throw new RuntimeException("Not implemented. Must override in a subclass.");
2994     }
2995 
2996     /**
2997      * Version of
2998      * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
2999      * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers
3000      * the broadcast will be sent to.
3001      *
3002      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
3003      *
3004      * @param intent The Intent to broadcast; all receivers matching this
3005      *               Intent will receive the broadcast.
3006      * @param receiverPermission String naming a permissions that
3007      *               a receiver must hold in order to receive your broadcast.
3008      *               If null, no permission is required.
3009      * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is
3010      *                      required. If both receiverAppOp and receiverPermission are non-null,
3011      *                      a receiver must have both of them to
3012      *                      receive the broadcast
3013      * @param resultReceiver Your own BroadcastReceiver to treat as the final
3014      *                       receiver of the broadcast.
3015      * @param scheduler A custom Handler with which to schedule the
3016      *                  resultReceiver callback; if null it will be
3017      *                  scheduled in the Context's main thread.
3018      * @param initialCode An initial value for the result code.  Often
3019      *                    Activity.RESULT_OK.
3020      * @param initialData An initial value for the result data.  Often
3021      *                    null.
3022      * @param initialExtras An initial value for the result extras.  Often
3023      *                      null.
3024      *
3025      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
3026      */
sendOrderedBroadcast(@onNull Intent intent, @Nullable String receiverPermission, @Nullable String receiverAppOp, @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)3027     public void sendOrderedBroadcast(@NonNull Intent intent, @Nullable String receiverPermission,
3028             @Nullable String receiverAppOp, @Nullable BroadcastReceiver resultReceiver,
3029             @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
3030             @Nullable Bundle initialExtras) {
3031         throw new RuntimeException("Not implemented. Must override in a subclass.");
3032     }
3033 
3034     /**
3035      * Version of
3036      * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
3037      * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers
3038      * the broadcast will be sent to as well as supply an optional sending options
3039      *
3040      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
3041      *
3042      * @param intent The Intent to broadcast; all receivers matching this
3043      *               Intent will receive the broadcast.
3044      * @param receiverPermission String naming a permissions that
3045      *               a receiver must hold in order to receive your broadcast.
3046      *               If null, no permission is required.
3047      * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is
3048      *                      required. If both receiverAppOp and receiverPermission are non-null,
3049      *                      a receiver must have both of them to
3050      *                      receive the broadcast
3051      * @param options (optional) Additional sending options, generated from a
3052      * {@link android.app.BroadcastOptions}.
3053      * @param resultReceiver Your own BroadcastReceiver to treat as the final
3054      *                       receiver of the broadcast.
3055      * @param scheduler A custom Handler with which to schedule the
3056      *                  resultReceiver callback; if null it will be
3057      *                  scheduled in the Context's main thread.
3058      * @param initialCode An initial value for the result code.  Often
3059      *                    Activity.RESULT_OK.
3060      * @param initialData An initial value for the result data.  Often
3061      *                    null.
3062      * @param initialExtras An initial value for the result extras.  Often
3063      *                      null.
3064      *
3065      * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
3066      * @see android.app.BroadcastOptions
3067      * @hide
3068      */
sendOrderedBroadcast(@equiresPermission @onNull Intent intent, int initialCode, @Nullable String receiverPermission, @Nullable String receiverAppOp, @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, @Nullable String initialData, @Nullable Bundle initialExtras, @Nullable Bundle options)3069     public void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent, int initialCode,
3070             @Nullable String receiverPermission, @Nullable String receiverAppOp,
3071             @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
3072             @Nullable String initialData, @Nullable Bundle initialExtras,
3073             @Nullable Bundle options) {
3074         throw new RuntimeException("Not implemented. Must override in a subclass.");
3075     }
3076 
3077     /**
3078      * Like {@link #sendOrderedBroadcast(Intent, String, String, BroadcastReceiver, Handler, int,
3079      * String, Bundle)}, but also allows specification of a list of multiple permissions.
3080      * @hide
3081      */
3082     @FlaggedApi(Flags.FLAG_ORDERED_BROADCAST_MULTIPLE_PERMISSIONS)
3083     @SystemApi
sendOrderedBroadcastMultiplePermissions( @onNull Intent intent, @NonNull String[] receiverPermissions, @Nullable String receiverAppOp, @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras, @Nullable Bundle options)3084     public void sendOrderedBroadcastMultiplePermissions(
3085             @NonNull Intent intent, @NonNull String[] receiverPermissions,
3086             @Nullable String receiverAppOp, @Nullable BroadcastReceiver resultReceiver,
3087             @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
3088             @Nullable Bundle initialExtras, @Nullable Bundle options) {
3089         throw new RuntimeException("Not implemented. Must override in a subclass.");
3090     }
3091 
3092     /**
3093      * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
3094      * Intent you are sending stays around after the broadcast is complete,
3095      * so that others can quickly retrieve that data through the return
3096      * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}.  In
3097      * all other ways, this behaves the same as
3098      * {@link #sendBroadcast(Intent)}.
3099      *
3100      * @deprecated Sticky broadcasts should not be used.  They provide no security (anyone
3101      * can access them), no protection (anyone can modify them), and many other problems.
3102      * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
3103      * has changed, with another mechanism for apps to retrieve the current value whenever
3104      * desired.
3105      *
3106      * @param intent The Intent to broadcast; all receivers matching this
3107      * Intent will receive the broadcast, and the Intent will be held to
3108      * be re-broadcast to future receivers.
3109      *
3110      * @see #sendBroadcast(Intent)
3111      * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
3112      */
3113     @Deprecated
3114     @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
sendStickyBroadcast(@equiresPermission Intent intent)3115     public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
3116 
3117     /**
3118      * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
3119      * Intent you are sending stays around after the broadcast is complete,
3120      * so that others can quickly retrieve that data through the return
3121      * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}.  In
3122      * all other ways, this behaves the same as
3123      * {@link #sendBroadcast(Intent)}.
3124      *
3125      * @deprecated Sticky broadcasts should not be used.  They provide no security (anyone
3126      * can access them), no protection (anyone can modify them), and many other problems.
3127      * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
3128      * has changed, with another mechanism for apps to retrieve the current value whenever
3129      * desired.
3130      *
3131      * @param intent The Intent to broadcast; all receivers matching this
3132      * Intent will receive the broadcast, and the Intent will be held to
3133      * be re-broadcast to future receivers.
3134      * @param options (optional) Additional sending options, generated from a
3135      * {@link android.app.BroadcastOptions}.
3136      *
3137      * @see #sendBroadcast(Intent)
3138      * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
3139      */
3140     @Deprecated
3141     @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
sendStickyBroadcast(@equiresPermission @onNull Intent intent, @Nullable Bundle options)3142     public void sendStickyBroadcast(@RequiresPermission @NonNull Intent intent,
3143             @Nullable Bundle options) {
3144         throw new RuntimeException("Not implemented. Must override in a subclass.");
3145     }
3146 
3147     /**
3148      * <p>Version of {@link #sendStickyBroadcast} that allows you to
3149      * receive data back from the broadcast.  This is accomplished by
3150      * supplying your own BroadcastReceiver when calling, which will be
3151      * treated as a final receiver at the end of the broadcast -- its
3152      * {@link BroadcastReceiver#onReceive} method will be called with
3153      * the result values collected from the other receivers.  The broadcast will
3154      * be serialized in the same way as calling
3155      * {@link #sendOrderedBroadcast(Intent, String)}.
3156      *
3157      * <p>Like {@link #sendBroadcast(Intent)}, this method is
3158      * asynchronous; it will return before
3159      * resultReceiver.onReceive() is called.  Note that the sticky data
3160      * stored is only the data you initially supply to the broadcast, not
3161      * the result of any changes made by the receivers.
3162      *
3163      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
3164      *
3165      * @deprecated Sticky broadcasts should not be used.  They provide no security (anyone
3166      * can access them), no protection (anyone can modify them), and many other problems.
3167      * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
3168      * has changed, with another mechanism for apps to retrieve the current value whenever
3169      * desired.
3170      *
3171      * @param intent The Intent to broadcast; all receivers matching this
3172      *               Intent will receive the broadcast.
3173      * @param resultReceiver Your own BroadcastReceiver to treat as the final
3174      *                       receiver of the broadcast.
3175      * @param scheduler A custom Handler with which to schedule the
3176      *                  resultReceiver callback; if null it will be
3177      *                  scheduled in the Context's main thread.
3178      * @param initialCode An initial value for the result code.  Often
3179      *                    Activity.RESULT_OK.
3180      * @param initialData An initial value for the result data.  Often
3181      *                    null.
3182      * @param initialExtras An initial value for the result extras.  Often
3183      *                      null.
3184      *
3185      * @see #sendBroadcast(Intent)
3186      * @see #sendBroadcast(Intent, String)
3187      * @see #sendOrderedBroadcast(Intent, String)
3188      * @see #sendStickyBroadcast(Intent)
3189      * @see android.content.BroadcastReceiver
3190      * @see #registerReceiver
3191      * @see android.app.Activity#RESULT_OK
3192      */
3193     @Deprecated
3194     @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
sendStickyOrderedBroadcast(@equiresPermission Intent intent, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)3195     public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
3196             BroadcastReceiver resultReceiver,
3197             @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
3198             @Nullable Bundle initialExtras);
3199 
3200     /**
3201      * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
3202      * so that it is as if the sticky broadcast had never happened.
3203      *
3204      * @deprecated Sticky broadcasts should not be used.  They provide no security (anyone
3205      * can access them), no protection (anyone can modify them), and many other problems.
3206      * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
3207      * has changed, with another mechanism for apps to retrieve the current value whenever
3208      * desired.
3209      *
3210      * @param intent The Intent that was previously broadcast.
3211      *
3212      * @see #sendStickyBroadcast
3213      */
3214     @Deprecated
3215     @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
removeStickyBroadcast(@equiresPermission Intent intent)3216     public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
3217 
3218     /**
3219      * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
3220      * user the broadcast will be sent to.  This is not available to applications
3221      * that are not pre-installed on the system image.
3222      *
3223      * @deprecated Sticky broadcasts should not be used.  They provide no security (anyone
3224      * can access them), no protection (anyone can modify them), and many other problems.
3225      * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
3226      * has changed, with another mechanism for apps to retrieve the current value whenever
3227      * desired.
3228      *
3229      * @param intent The Intent to broadcast; all receivers matching this
3230      * Intent will receive the broadcast, and the Intent will be held to
3231      * be re-broadcast to future receivers.
3232      * @param user UserHandle to send the intent to.
3233      *
3234      * @see #sendBroadcast(Intent)
3235      */
3236     @Deprecated
3237     @RequiresPermission(allOf = {
3238             android.Manifest.permission.INTERACT_ACROSS_USERS,
3239             android.Manifest.permission.BROADCAST_STICKY
3240     })
sendStickyBroadcastAsUser(@equiresPermission Intent intent, UserHandle user)3241     public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
3242             UserHandle user);
3243 
3244     /**
3245      * @hide
3246      * This is just here for sending CONNECTIVITY_ACTION.
3247      */
3248     @SuppressWarnings("HiddenAbstractMethod")
3249     @Deprecated
3250     @RequiresPermission(allOf = {
3251             android.Manifest.permission.INTERACT_ACROSS_USERS,
3252             android.Manifest.permission.BROADCAST_STICKY
3253     })
sendStickyBroadcastAsUser(@equiresPermission Intent intent, UserHandle user, Bundle options)3254     public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
3255             UserHandle user, Bundle options);
3256 
3257     /**
3258      * <p>Version of
3259      * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
3260      * that allows you to specify the
3261      * user the broadcast will be sent to.  This is not available to applications
3262      * that are not pre-installed on the system image.
3263      *
3264      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
3265      *
3266      * @deprecated Sticky broadcasts should not be used.  They provide no security (anyone
3267      * can access them), no protection (anyone can modify them), and many other problems.
3268      * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
3269      * has changed, with another mechanism for apps to retrieve the current value whenever
3270      * desired.
3271      *
3272      * @param intent The Intent to broadcast; all receivers matching this
3273      *               Intent will receive the broadcast.
3274      * @param user UserHandle to send the intent to.
3275      * @param resultReceiver Your own BroadcastReceiver to treat as the final
3276      *                       receiver of the broadcast.
3277      * @param scheduler A custom Handler with which to schedule the
3278      *                  resultReceiver callback; if null it will be
3279      *                  scheduled in the Context's main thread.
3280      * @param initialCode An initial value for the result code.  Often
3281      *                    Activity.RESULT_OK.
3282      * @param initialData An initial value for the result data.  Often
3283      *                    null.
3284      * @param initialExtras An initial value for the result extras.  Often
3285      *                      null.
3286      *
3287      * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
3288      */
3289     @Deprecated
3290     @RequiresPermission(allOf = {
3291             android.Manifest.permission.INTERACT_ACROSS_USERS,
3292             android.Manifest.permission.BROADCAST_STICKY
3293     })
sendStickyOrderedBroadcastAsUser(@equiresPermission Intent intent, UserHandle user, BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)3294     public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
3295             UserHandle user, BroadcastReceiver resultReceiver,
3296             @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
3297             @Nullable Bundle initialExtras);
3298 
3299     /**
3300      * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
3301      * user the broadcast will be sent to.  This is not available to applications
3302      * that are not pre-installed on the system image.
3303      *
3304      * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
3305      * permission in order to use this API.  If you do not hold that
3306      * permission, {@link SecurityException} will be thrown.
3307      *
3308      * @deprecated Sticky broadcasts should not be used.  They provide no security (anyone
3309      * can access them), no protection (anyone can modify them), and many other problems.
3310      * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
3311      * has changed, with another mechanism for apps to retrieve the current value whenever
3312      * desired.
3313      *
3314      * @param intent The Intent that was previously broadcast.
3315      * @param user UserHandle to remove the sticky broadcast from.
3316      *
3317      * @see #sendStickyBroadcastAsUser
3318      */
3319     @Deprecated
3320     @RequiresPermission(allOf = {
3321             android.Manifest.permission.INTERACT_ACROSS_USERS,
3322             android.Manifest.permission.BROADCAST_STICKY
3323     })
removeStickyBroadcastAsUser(@equiresPermission Intent intent, UserHandle user)3324     public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
3325             UserHandle user);
3326 
3327     /**
3328      * Register a BroadcastReceiver to be run in the main activity thread.  The
3329      * <var>receiver</var> will be called with any broadcast Intent that
3330      * matches <var>filter</var>, in the main application thread.
3331      *
3332      * <p>The system may broadcast Intents that are "sticky" -- these stay
3333      * around after the broadcast has finished, to be sent to any later
3334      * registrations. If your IntentFilter matches one of these sticky
3335      * Intents, that Intent will be returned by this function
3336      * <strong>and</strong> sent to your <var>receiver</var> as if it had just
3337      * been broadcast.
3338      *
3339      * <p>There may be multiple sticky Intents that match <var>filter</var>,
3340      * in which case each of these will be sent to <var>receiver</var>.  In
3341      * this case, only one of these can be returned directly by the function;
3342      * which of these that is returned is arbitrarily decided by the system.
3343      *
3344      * <p>If you know the Intent you are registering for is sticky, you can
3345      * supply null for your <var>receiver</var>.  In this case, no receiver is
3346      * registered -- the function simply returns the sticky Intent that
3347      * matches <var>filter</var>.  In the case of multiple matches, the same
3348      * rules as described above apply.
3349      *
3350      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
3351      *
3352      * <p>As of {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, the system can <a
3353      * href="{@docRoot}develop/background-work/background-tasks/broadcasts#android-14">place
3354      * context-registered broadcasts in a queue while the app is in the <a
3355      * href="{@docRoot}guide/components/activities/process-lifecycle">cached state</a>.
3356      * When the app leaves the cached state, such as returning to the
3357      * foreground, the system delivers any queued broadcasts. Multiple instances
3358      * of certain broadcasts might be merged into one broadcast.
3359      *
3360      * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
3361      * registered with this method will correctly respect the
3362      * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
3363      * Prior to that, it would be ignored and delivered to all matching registered
3364      * receivers.  Be careful if using this for security.</p>
3365      *
3366      * <p>For apps targeting {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE},
3367      * either {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be
3368      * specified if the receiver is not being registered for <a
3369      * href="{@docRoot}guide/components/broadcasts#system-broadcasts">system broadcasts</a>
3370      * or a {@link SecurityException} will be thrown. See {@link
3371      * #registerReceiver(BroadcastReceiver, IntentFilter, int)} to register a receiver with
3372      * flags.
3373      *
3374      * <p class="note">Note: this method <em>cannot be called from a
3375      * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
3376      * that is declared in an application's manifest.  It is okay, however, to call
3377      * this method from another BroadcastReceiver that has itself been registered
3378      * at run time with {@link #registerReceiver}, since the lifetime of such a
3379      * registered BroadcastReceiver is tied to the object that registered it.</p>
3380      *
3381      * @param receiver The BroadcastReceiver to handle the broadcast.
3382      * @param filter Selects the Intent broadcasts to be received.
3383      *
3384      * @return The first sticky intent found that matches <var>filter</var>,
3385      *         or null if there are none.
3386      *
3387      * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
3388      * @see #sendBroadcast
3389      * @see #unregisterReceiver
3390      */
3391     @Nullable
registerReceiver(@ullable BroadcastReceiver receiver, IntentFilter filter)3392     public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
3393                                             IntentFilter filter);
3394 
3395     /**
3396      * Register to receive intent broadcasts, with the receiver optionally being
3397      * exposed to Instant Apps. See
3398      * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
3399      * information. By default Instant Apps cannot interact with receivers in other
3400      * applications, this allows you to expose a receiver that Instant Apps can
3401      * interact with.
3402      *
3403      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
3404      *
3405      * <p>As of {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, the system can <a
3406      * href="{@docRoot}develop/background-work/background-tasks/broadcasts#android-14">place
3407      * context-registered broadcasts in a queue while the app is in the <a
3408      * href="{@docRoot}guide/components/activities/process-lifecycle">cached state</a>.
3409      * When the app leaves the cached state, such as returning to the
3410      * foreground, the system delivers any queued broadcasts. Multiple instances
3411      * of certain broadcasts might be merged into one broadcast.
3412      *
3413      * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
3414      * registered with this method will correctly respect the
3415      * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
3416      * Prior to that, it would be ignored and delivered to all matching registered
3417      * receivers.  Be careful if using this for security.</p>
3418      *
3419      * @param receiver The BroadcastReceiver to handle the broadcast.
3420      * @param filter Selects the Intent broadcasts to be received.
3421      * @param flags Additional options for the receiver. For apps targeting {@link
3422      *      android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} either {@link #RECEIVER_EXPORTED} or
3423      *      {@link #RECEIVER_NOT_EXPORTED} must be specified if the receiver isn't being registered
3424      *      for <a href="{@docRoot}guide/components/broadcasts#system-broadcasts">system
3425      *      broadcasts</a> or a {@link SecurityException} will be thrown. If {@link
3426      *      #RECEIVER_EXPORTED} is specified, a receiver may additionally specify {@link
3427      *      #RECEIVER_VISIBLE_TO_INSTANT_APPS}. For a complete list of system broadcast actions,
3428      *      see the BROADCAST_ACTIONS.TXT file in the Android SDK. If both {@link
3429      *      #RECEIVER_EXPORTED} and {@link #RECEIVER_NOT_EXPORTED} are specified, an {@link
3430      *      IllegalArgumentException} will be thrown.
3431      *
3432      * @return The first sticky intent found that matches <var>filter</var>,
3433      *         or null if there are none.
3434      *
3435      * @see #registerReceiver(BroadcastReceiver, IntentFilter)
3436      * @see #sendBroadcast
3437      * @see #unregisterReceiver
3438      */
3439     @Nullable
registerReceiver(@ullable BroadcastReceiver receiver, IntentFilter filter, @RegisterReceiverFlags int flags)3440     public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
3441                                             IntentFilter filter,
3442                                             @RegisterReceiverFlags int flags);
3443 
3444     /**
3445      * Register to receive intent broadcasts, to run in the context of
3446      * <var>scheduler</var>.  See
3447      * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
3448      * information.  This allows you to enforce permissions on who can
3449      * broadcast intents to your receiver, or have the receiver run in
3450      * a different thread than the main application thread.
3451      *
3452      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
3453      *
3454      * <p>As of {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, the system can <a
3455      * href="{@docRoot}develop/background-work/background-tasks/broadcasts#android-14">place
3456      * context-registered broadcasts in a queue while the app is in the <a
3457      * href="{@docRoot}guide/components/activities/process-lifecycle">cached state</a>.
3458      * When the app leaves the cached state, such as returning to the
3459      * foreground, the system delivers any queued broadcasts. Multiple instances
3460      * of certain broadcasts might be merged into one broadcast.
3461      *
3462      * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
3463      * registered with this method will correctly respect the
3464      * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
3465      * Prior to that, it would be ignored and delivered to all matching registered
3466      * receivers.  Be careful if using this for security.</p>
3467      *
3468      * <p>For apps targeting {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE},
3469      * either {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be
3470      * specified if the receiver is not being registered for <a
3471      * href="{@docRoot}guide/components/broadcasts#system-broadcasts">system broadcasts</a>
3472      * or a {@link SecurityException} will be thrown. See {@link
3473      * #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler, int)} to register a
3474      * receiver with flags.
3475      *
3476      * @param receiver The BroadcastReceiver to handle the broadcast.
3477      * @param filter Selects the Intent broadcasts to be received.
3478      * @param broadcastPermission String naming a permissions that a
3479      *      broadcaster must hold in order to send an Intent to you.  If null,
3480      *      no permission is required.
3481      * @param scheduler Handler identifying the thread that will receive
3482      *      the Intent.  If null, the main thread of the process will be used.
3483      *
3484      * @return The first sticky intent found that matches <var>filter</var>,
3485      *         or null if there are none.
3486      *
3487      * @see #registerReceiver(BroadcastReceiver, IntentFilter)
3488      * @see #sendBroadcast
3489      * @see #unregisterReceiver
3490      */
3491     @Nullable
registerReceiver(BroadcastReceiver receiver, IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler)3492     public abstract Intent registerReceiver(BroadcastReceiver receiver,
3493             IntentFilter filter, @Nullable String broadcastPermission,
3494             @Nullable Handler scheduler);
3495 
3496     /**
3497      * Register to receive intent broadcasts, to run in the context of
3498      * <var>scheduler</var>. See
3499      * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
3500      * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
3501      * for more information.
3502      *
3503      * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
3504      *
3505      * <p>As of {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, the system can <a
3506      * href="{@docRoot}develop/background-work/background-tasks/broadcasts#android-14">place
3507      * context-registered broadcasts in a queue while the app is in the <a
3508      * href="{@docRoot}guide/components/activities/process-lifecycle">cached state</a>.
3509      * When the app leaves the cached state, such as returning to the
3510      * foreground, the system delivers any queued broadcasts. Multiple instances
3511      * of certain broadcasts might be merged into one broadcast.
3512      *
3513      * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
3514      * registered with this method will correctly respect the
3515      * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
3516      * Prior to that, it would be ignored and delivered to all matching registered
3517      * receivers.  Be careful if using this for security.</p>
3518      *
3519      * @param receiver The BroadcastReceiver to handle the broadcast.
3520      * @param filter Selects the Intent broadcasts to be received.
3521      * @param broadcastPermission String naming a permissions that a
3522      *      broadcaster must hold in order to send an Intent to you.  If null,
3523      *      no permission is required.
3524      * @param scheduler Handler identifying the thread that will receive
3525      *      the Intent.  If null, the main thread of the process will be used.
3526      * @param flags Additional options for the receiver. For apps targeting {@link
3527      *      android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} either {@link #RECEIVER_EXPORTED} or
3528      *      {@link #RECEIVER_NOT_EXPORTED} must be specified if the receiver isn't being registered
3529      *      for <a href="{@docRoot}guide/components/broadcasts#system-broadcasts">system
3530      *      broadcasts</a> or a {@link SecurityException} will be thrown. If {@link
3531      *      #RECEIVER_EXPORTED} is specified, a receiver may additionally specify {@link
3532      *      #RECEIVER_VISIBLE_TO_INSTANT_APPS}. For a complete list of system broadcast actions,
3533      *      see the BROADCAST_ACTIONS.TXT file in the Android SDK. If both {@link
3534      *      #RECEIVER_EXPORTED} and {@link #RECEIVER_NOT_EXPORTED} are specified, an {@link
3535      *      IllegalArgumentException} will be thrown.
3536      * @return The first sticky intent found that matches <var>filter</var>,
3537      *         or null if there are none.
3538      *
3539      * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
3540      * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
3541      * @see #sendBroadcast
3542      * @see #unregisterReceiver
3543      */
3544     @Nullable
registerReceiver(BroadcastReceiver receiver, IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler, @RegisterReceiverFlags int flags)3545     public abstract Intent registerReceiver(BroadcastReceiver receiver,
3546             IntentFilter filter, @Nullable String broadcastPermission,
3547             @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
3548 
3549     /**
3550      * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
3551      * but this receiver will receive broadcasts that are sent to all users. The receiver can
3552      * use {@link BroadcastReceiver#getSendingUser} to determine on which user the broadcast
3553      * was sent.
3554      *
3555      * @param receiver The BroadcastReceiver to handle the broadcast.
3556      * @param filter Selects the Intent broadcasts to be received.
3557      * @param broadcastPermission String naming a permissions that a
3558      *      broadcaster must hold in order to send an Intent to you. If {@code null},
3559      *      no permission is required.
3560      * @param scheduler Handler identifying the thread that will receive
3561      *      the Intent. If {@code null}, the main thread of the process will be used.
3562      *
3563      * @return The first sticky intent found that matches <var>filter</var>,
3564      *         or {@code null} if there are none.
3565      *
3566      * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
3567      * @see #sendBroadcast
3568      * @see #unregisterReceiver
3569      * @hide
3570      */
3571     @Nullable
3572     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
3573     @SystemApi
registerReceiverForAllUsers(@ullable BroadcastReceiver receiver, @NonNull IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler)3574     public Intent registerReceiverForAllUsers(@Nullable BroadcastReceiver receiver,
3575             @NonNull IntentFilter filter, @Nullable String broadcastPermission,
3576             @Nullable Handler scheduler) {
3577         throw new RuntimeException("Not implemented. Must override in a subclass.");
3578     }
3579 
3580     /**
3581      * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler, int)}
3582      * but this receiver will receive broadcasts that are sent to all users. The receiver can
3583      * use {@link BroadcastReceiver#getSendingUser} to determine on which user the broadcast
3584      * was sent.
3585      *
3586      * @param receiver The BroadcastReceiver to handle the broadcast.
3587      * @param filter Selects the Intent broadcasts to be received.
3588      * @param broadcastPermission String naming a permissions that a
3589      *      broadcaster must hold in order to send an Intent to you. If {@code null},
3590      *      no permission is required.
3591      * @param scheduler Handler identifying the thread that will receive
3592      *      the Intent. If {@code null}, the main thread of the process will be used.
3593      * @param flags Additional options for the receiver. For apps targeting {@link
3594      *      android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} either {@link #RECEIVER_EXPORTED} or
3595      *      {@link #RECEIVER_NOT_EXPORTED} must be specified if the receiver isn't being registered
3596      *      for <a href="{@docRoot}guide/components/broadcasts#system-broadcasts">system
3597      *      broadcasts</a> or a {@link SecurityException} will be thrown. If {@link
3598      *      #RECEIVER_EXPORTED} is specified, a receiver may additionally specify {@link
3599      *      #RECEIVER_VISIBLE_TO_INSTANT_APPS}. For a complete list of system broadcast actions,
3600      *      see the BROADCAST_ACTIONS.TXT file in the Android SDK. If both {@link
3601      *      #RECEIVER_EXPORTED} and {@link #RECEIVER_NOT_EXPORTED} are specified, an {@link
3602      *      IllegalArgumentException} will be thrown.
3603      *
3604      * @return The first sticky intent found that matches <var>filter</var>,
3605      *         or {@code null} if there are none.
3606      *
3607      * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler, int)
3608      * @see #sendBroadcast
3609      * @see #unregisterReceiver
3610      * @hide
3611      */
3612     @SuppressLint("IntentBuilderName")
3613     @Nullable
3614     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
3615     @SystemApi
registerReceiverForAllUsers(@ullable BroadcastReceiver receiver, @NonNull IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler, @RegisterReceiverFlags int flags)3616     public Intent registerReceiverForAllUsers(@Nullable BroadcastReceiver receiver,
3617             @NonNull IntentFilter filter, @Nullable String broadcastPermission,
3618             @Nullable Handler scheduler, @RegisterReceiverFlags int flags) {
3619         throw new RuntimeException("Not implemented. Must override in a subclass.");
3620     }
3621 
3622     /**
3623      * @hide
3624      * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
3625      * but for a specific user.  This receiver will receiver broadcasts that
3626      * are sent to the requested user.
3627      *
3628      * @param receiver The BroadcastReceiver to handle the broadcast.
3629      * @param user UserHandle to send the intent to.
3630      * @param filter Selects the Intent broadcasts to be received.
3631      * @param broadcastPermission String naming a permissions that a
3632      *      broadcaster must hold in order to send an Intent to you.  If null,
3633      *      no permission is required.
3634      * @param scheduler Handler identifying the thread that will receive
3635      *      the Intent.  If null, the main thread of the process will be used.
3636      *
3637      * @return The first sticky intent found that matches <var>filter</var>,
3638      *         or null if there are none.
3639      *
3640      * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
3641      * @see #sendBroadcast
3642      * @see #unregisterReceiver
3643      */
3644     @SuppressWarnings("HiddenAbstractMethod")
3645     @Nullable
3646     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
3647     @UnsupportedAppUsage
registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user, IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler)3648     public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
3649             UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
3650             @Nullable Handler scheduler);
3651 
3652     /**
3653      * @hide
3654      * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler, int)
3655      * but for a specific user.  This receiver will receiver broadcasts that
3656      * are sent to the requested user.
3657      *
3658      * @param receiver The BroadcastReceiver to handle the broadcast.
3659      * @param user UserHandle to send the intent to.
3660      * @param filter Selects the Intent broadcasts to be received.
3661      * @param broadcastPermission String naming a permissions that a
3662      *      broadcaster must hold in order to send an Intent to you.  If null,
3663      *      no permission is required.
3664      * @param scheduler Handler identifying the thread that will receive
3665      *      the Intent.  If null, the main thread of the process will be used.
3666      * @param flags Additional options for the receiver. For apps targeting {@link
3667      *      android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} either {@link #RECEIVER_EXPORTED} or
3668      *      {@link #RECEIVER_NOT_EXPORTED} must be specified if the receiver isn't being registered
3669      *      for <a href="{@docRoot}guide/components/broadcasts#system-broadcasts">system
3670      *      broadcasts</a> or a {@link SecurityException} will be thrown. If {@link
3671      *      #RECEIVER_EXPORTED} is specified, a receiver may additionally specify {@link
3672      *      #RECEIVER_VISIBLE_TO_INSTANT_APPS}. For a complete list of system broadcast actions,
3673      *      see the BROADCAST_ACTIONS.TXT file in the Android SDK. If both {@link
3674      *      #RECEIVER_EXPORTED} and {@link #RECEIVER_NOT_EXPORTED} are specified, an {@link
3675      *      IllegalArgumentException} will be thrown.
3676      *
3677      * @return The first sticky intent found that matches <var>filter</var>,
3678      *         or null if there are none.
3679      *
3680      * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler, int)
3681      * @see #sendBroadcast
3682      * @see #unregisterReceiver
3683      */
3684     @SuppressWarnings("HiddenAbstractMethod")
3685     @SuppressLint("IntentBuilderName")
3686     @Nullable
3687     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
3688     @UnsupportedAppUsage
registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user, IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler, @RegisterReceiverFlags int flags)3689     public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
3690             UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
3691             @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
3692 
3693     /**
3694      * Unregister a previously registered BroadcastReceiver.  <em>All</em>
3695      * filters that have been registered for this BroadcastReceiver will be
3696      * removed.
3697      *
3698      * @param receiver The BroadcastReceiver to unregister.
3699      *
3700      * @throws IllegalArgumentException if the {@code receiver} was not previously registered or
3701      *                                  already unregistered.
3702      * @see #registerReceiver
3703      */
unregisterReceiver(BroadcastReceiver receiver)3704     public abstract void unregisterReceiver(BroadcastReceiver receiver);
3705 
3706     /**
3707      * Returns the list of {@link IntentFilter} objects that have been registered for the given
3708      * {@link BroadcastReceiver}.
3709      *
3710      * @param receiver The {@link BroadcastReceiver} whose registered intent filters
3711      *                 should be retrieved.
3712      *
3713      * @return A list of registered intent filters, or an empty list if the given receiver is not
3714      *         registered.
3715      *
3716      * @throws NullPointerException if the {@code receiver} is {@code null}.
3717      *
3718      * @hide
3719      */
3720     @SuppressLint("UnflaggedApi") // TestApi
3721     @TestApi
3722     @NonNull
getRegisteredIntentFilters(@onNull BroadcastReceiver receiver)3723     public List<IntentFilter> getRegisteredIntentFilters(@NonNull BroadcastReceiver receiver) {
3724         throw new RuntimeException("Not implemented. Must override in a subclass.");
3725     }
3726 
3727     /**
3728      * Request that a given application service be started.  The Intent
3729      * should either contain the complete class name of a specific service
3730      * implementation to start, or a specific package name to target.  If the
3731      * Intent is less specified, it logs a warning about this.  In this case any of the
3732      * multiple matching services may be used.  If this service
3733      * is not already running, it will be instantiated and started (creating a
3734      * process for it if needed); if it is running then it remains running.
3735      *
3736      * <p>Every call to this method will result in a corresponding call to
3737      * the target service's {@link android.app.Service#onStartCommand} method,
3738      * with the <var>intent</var> given here.  This provides a convenient way
3739      * to submit jobs to a service without having to bind and call on to its
3740      * interface.
3741      *
3742      * <p>Using startService() overrides the default service lifetime that is
3743      * managed by {@link #bindService}: it requires the service to remain
3744      * running until {@link #stopService} is called, regardless of whether
3745      * any clients are connected to it.  Note that calls to startService()
3746      * do not nest: no matter how many times you call startService(),
3747      * a single call to {@link #stopService} will stop it.
3748      *
3749      * <p>The system attempts to keep running services around as much as
3750      * possible.  The only time they should be stopped is if the current
3751      * foreground application is using so many resources that the service needs
3752      * to be killed.  If any errors happen in the service's process, it will
3753      * automatically be restarted.
3754      *
3755      * <p>This function will throw {@link SecurityException} if you do not
3756      * have permission to start the given service.
3757      *
3758      * <div class="caution">
3759      * <p><strong>Note:</strong> Each call to startService()
3760      * results in significant work done by the system to manage service
3761      * lifecycle surrounding the processing of the intent, which can take
3762      * multiple milliseconds of CPU time. Due to this cost, startService()
3763      * should not be used for frequent intent delivery to a service, and only
3764      * for scheduling significant work. Use {@link #bindService bound services}
3765      * for high frequency calls.
3766      * </p>
3767      *
3768      * Beginning with SDK Version {@link android.os.Build.VERSION_CODES#O},
3769      * apps targeting SDK Version {@link android.os.Build.VERSION_CODES#O}
3770      * or higher are not allowed to start background services from the background.
3771      * See
3772      * <a href="/about/versions/oreo/background">
3773      * Background Execution Limits</a>
3774      * for more details.
3775      *
3776      * <p><strong>Note:</strong>
3777      * Beginning with SDK Version {@link android.os.Build.VERSION_CODES#S},
3778      * apps targeting SDK Version {@link android.os.Build.VERSION_CODES#S}
3779      * or higher are not allowed to start foreground services from the background.
3780      * See
3781      * <a href="/about/versions/12/behavior-changes-12">
3782      * Behavior changes: Apps targeting Android 12
3783      * </a>
3784      * for more details.
3785      * </div>
3786      *
3787      * @param service Identifies the service to be started.  The Intent must be
3788      *      fully explicit (supplying a component name).  Additional values
3789      *      may be included in the Intent extras to supply arguments along with
3790      *      this specific start call.
3791      *
3792      * @return If the service is being started or is already running, the
3793      * {@link ComponentName} of the actual service that was started is
3794      * returned; else if the service does not exist null is returned.
3795      *
3796      * @throws SecurityException If the caller does not have permission to access the service
3797      * or the service can not be found.
3798      * @throws IllegalStateException
3799      * Before Android {@link android.os.Build.VERSION_CODES#S},
3800      * if the application is in a state where the service
3801      * can not be started (such as not in the foreground in a state when services are allowed),
3802      * {@link IllegalStateException} was thrown.
3803      * @throws android.app.BackgroundServiceStartNotAllowedException
3804      * On Android {@link android.os.Build.VERSION_CODES#S} and later,
3805      * if the application is in a state where the service
3806      * can not be started (such as not in the foreground in a state when services are allowed),
3807      * {@link android.app.BackgroundServiceStartNotAllowedException} is thrown.
3808      * This exception extends {@link IllegalStateException}, so apps can
3809      * use {@code catch (IllegalStateException)} to catch both.
3810      *
3811      * @see #startForegroundService(Intent)
3812      * @see #stopService
3813      * @see #bindService
3814      */
3815     @Nullable
startService(Intent service)3816     public abstract ComponentName startService(Intent service);
3817 
3818     /**
3819      * Similar to {@link #startService(Intent)}, but with an implicit promise that the
3820      * Service will call {@link android.app.Service#startForeground(int, android.app.Notification)
3821      * startForeground(int, android.app.Notification)} once it begins running.  The service is given
3822      * an amount of time comparable to the ANR interval to do this, otherwise the system
3823      * will automatically crash the process, in which case an internal exception
3824      * {@code ForegroundServiceDidNotStartInTimeException} is logged on logcat on devices
3825      * running SDK Version {@link android.os.Build.VERSION_CODES#S} or later. On older Android
3826      * versions, an internal exception {@code RemoteServiceException} is logged instead, with
3827      * a corresponding message.
3828      *
3829      * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
3830      * at any time, regardless of whether the app hosting the service is in a foreground
3831      * state.
3832      *
3833      * <div class="caution">
3834      * <p><strong>Note:</strong>
3835      * Beginning with SDK Version {@link android.os.Build.VERSION_CODES#S},
3836      * apps targeting SDK Version {@link android.os.Build.VERSION_CODES#S}
3837      * or higher are not allowed to start foreground services from the background.
3838      * See
3839      * <a href="/about/versions/12/behavior-changes-12">
3840      * Behavior changes: Apps targeting Android 12
3841      * </a>
3842      * for more details.
3843      * </div>
3844      *
3845      * @param service Identifies the service to be started.  The Intent must be
3846      *      fully explicit (supplying a component name).  Additional values
3847      *      may be included in the Intent extras to supply arguments along with
3848      *      this specific start call.
3849      *
3850      * @return If the service is being started or is already running, the
3851      * {@link ComponentName} of the actual service that was started is
3852      * returned; else if the service does not exist null is returned.
3853      *
3854      * @throws SecurityException If the caller does not have permission to access the service
3855      * or the service can not be found.
3856      *
3857      * @throws android.app.ForegroundServiceStartNotAllowedException
3858      * If the caller app's targeting API is
3859      * {@link android.os.Build.VERSION_CODES#S} or later, and the foreground service is restricted
3860      * from start due to background restriction.
3861      *
3862      * @see #stopService
3863      * @see android.app.Service#startForeground(int, android.app.Notification)
3864      */
3865     @Nullable
startForegroundService(Intent service)3866     public abstract ComponentName startForegroundService(Intent service);
3867 
3868     /**
3869      * @hide like {@link #startForegroundService(Intent)} but for a specific user.
3870      */
3871     @SuppressWarnings("HiddenAbstractMethod")
3872     @Nullable
3873     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
startForegroundServiceAsUser(Intent service, UserHandle user)3874     public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
3875 
3876     /**
3877      * Request that a given application service be stopped.  If the service is
3878      * not running, nothing happens.  Otherwise it is stopped.  Note that calls
3879      * to startService() are not counted -- this stops the service no matter
3880      * how many times it was started.
3881      *
3882      * <p>If the service is running as a foreground service when it is
3883      * stopped, its associated notification will be removed.  To avoid this,
3884      * apps can use {@link android.app.Service#stopForeground(int)
3885      * stopForeground(STOP_FOREGROUND_DETACH)} to decouple the notification
3886      * from the service's lifecycle before stopping it.</p>
3887      *
3888      * <p>Note that if a stopped service still has {@link ServiceConnection}
3889      * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
3890      * not be destroyed until all of these bindings are removed.  See
3891      * the {@link android.app.Service} documentation for more details on a
3892      * service's lifecycle.
3893      *
3894      * <p>This function will throw {@link SecurityException} if you do not
3895      * have permission to stop the given service.
3896      *
3897      * @param service Description of the service to be stopped.  The Intent must be either
3898      *      fully explicit (supplying a component name) or specify a specific package
3899      *      name it is targeted to.
3900      *
3901      * @return If there is a service matching the given Intent that is already
3902      * running, then it is stopped and {@code true} is returned; else {@code false} is returned.
3903      *
3904      * @throws SecurityException If the caller does not have permission to access the service
3905      * or the service can not be found.
3906      * @throws IllegalStateException If the application is in a state where the service
3907      * can not be started (such as not in the foreground in a state when services are allowed).
3908      *
3909      * @see #startService
3910      */
stopService(Intent service)3911     public abstract boolean stopService(Intent service);
3912 
3913     /**
3914      * @hide like {@link #startService(Intent)} but for a specific user.
3915      */
3916     @SuppressWarnings("HiddenAbstractMethod")
3917     @Nullable
3918     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
3919     @UnsupportedAppUsage
startServiceAsUser(Intent service, UserHandle user)3920     public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
3921 
3922     /**
3923      * @hide like {@link #stopService(Intent)} but for a specific user.
3924      */
3925     @SuppressWarnings("HiddenAbstractMethod")
3926     @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
stopServiceAsUser(Intent service, UserHandle user)3927     public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
3928 
3929     /**
3930      * Connects to an application service, creating it if needed.  This defines
3931      * a dependency between your application and the service.  The given
3932      * <var>conn</var> will receive the service object when it is created and be
3933      * told if it dies and restarts.  The service will be considered required
3934      * by the system only for as long as the calling context exists.  For
3935      * example, if this Context is an Activity that is stopped, the service will
3936      * not be required to continue running until the Activity is resumed.
3937      *
3938      * <p>If the service does not support binding, it may return {@code null} from
3939      * its {@link android.app.Service#onBind(Intent) onBind()} method.  If it does, then
3940      * the ServiceConnection's
3941      * {@link ServiceConnection#onNullBinding(ComponentName) onNullBinding()} method
3942      * will be invoked instead of
3943      * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder) onServiceConnected()}.
3944      *
3945      * <p class="note"><b>Note:</b> This method <em>cannot</em> be called from a
3946      * {@link BroadcastReceiver} component.  A pattern you can use to
3947      * communicate from a BroadcastReceiver to a Service is to call
3948      * {@link #startService} with the arguments containing the command to be
3949      * sent, with the service calling its
3950      * {@link android.app.Service#stopSelf(int)} method when done executing
3951      * that command.  See the API demo App/Service/Service Start Arguments
3952      * Controller for an illustration of this.  It is okay, however, to use
3953      * this method from a BroadcastReceiver that has been registered with
3954      * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
3955      * is tied to another object (the one that registered it).</p>
3956      *
3957      * <p>This method only accepts a int type flag, to pass in a long type flag, call
3958      * {@link #bindService(Intent, ServiceConnection, BindServiceFlags)} instead.</p>
3959      *
3960      * @param service Identifies the service to connect to.  The Intent must
3961      *      specify an explicit component name.
3962      * @param conn Receives information as the service is started and stopped.
3963      *      This must be a valid ServiceConnection object; it must not be null.
3964      * @param flags Operation options for the binding. Can be:
3965      *      <ul>
3966      *          <li>0
3967      *          <li>{@link #BIND_AUTO_CREATE}
3968      *          <li>{@link #BIND_DEBUG_UNBIND}
3969      *          <li>{@link #BIND_NOT_FOREGROUND}
3970      *          <li>{@link #BIND_ABOVE_CLIENT}
3971      *          <li>{@link #BIND_ALLOW_OOM_MANAGEMENT}
3972      *          <li>{@link #BIND_WAIVE_PRIORITY}
3973      *          <li>{@link #BIND_IMPORTANT}
3974      *          <li>{@link #BIND_ADJUST_WITH_ACTIVITY}
3975      *          <li>{@link #BIND_NOT_PERCEPTIBLE}
3976      *          <li>{@link #BIND_INCLUDE_CAPABILITIES}
3977      *      </ul>
3978      *
3979      * @return {@code true} if the system is in the process of bringing up a
3980      *      service that your client has permission to bind to; {@code false}
3981      *      if the system couldn't find the service or if your client doesn't
3982      *      have permission to bind to it. Regardless of the return value, you
3983      *      should later call {@link #unbindService} to release the connection.
3984      *
3985      * @throws SecurityException If the caller does not have permission to
3986      *      access the service or the service cannot be found. Call
3987      *      {@link #unbindService} to release the connection when this exception
3988      *      is thrown.
3989      *
3990      * @see #unbindService
3991      * @see #startService
3992      */
bindService(@equiresPermission @onNull Intent service, @NonNull ServiceConnection conn, int flags)3993     public abstract boolean bindService(@RequiresPermission @NonNull Intent service,
3994             @NonNull ServiceConnection conn, int flags);
3995 
3996     /**
3997      * See {@link #bindService(Intent, ServiceConnection, int)}
3998      * Call {@link BindServiceFlags#of(long)} to obtain a BindServiceFlags object.
3999      */
bindService(@equiresPermission @onNull Intent service, @NonNull ServiceConnection conn, @NonNull BindServiceFlags flags)4000     public boolean bindService(@RequiresPermission @NonNull Intent service,
4001             @NonNull ServiceConnection conn, @NonNull BindServiceFlags flags) {
4002         throw new RuntimeException("Not implemented. Must override in a subclass.");
4003     }
4004 
4005     /**
4006      * Same as {@link #bindService(Intent, ServiceConnection, int)
4007      * bindService(Intent, ServiceConnection, int)} with executor to control ServiceConnection
4008      * callbacks.
4009      *
4010      * <p>This method only accepts a 32 bits flag, to pass in a 64 bits flag, call
4011      * {@link #bindService(Intent, BindServiceFlags, Executor, ServiceConnection)} instead.</p>
4012      *
4013      * @param executor Callbacks on ServiceConnection will be called on executor. Must use same
4014      *      instance for the same instance of ServiceConnection.
4015      *
4016      * @return The result of the binding as described in
4017      *      {@link #bindService(Intent, ServiceConnection, int)
4018      *      bindService(Intent, ServiceConnection, int)}.
4019      */
bindService(@equiresPermission @onNull Intent service, @BindServiceFlagsBits int flags, @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn)4020     public boolean bindService(@RequiresPermission @NonNull Intent service,
4021             @BindServiceFlagsBits int flags, @NonNull @CallbackExecutor Executor executor,
4022             @NonNull ServiceConnection conn) {
4023         throw new RuntimeException("Not implemented. Must override in a subclass.");
4024     }
4025 
4026     /**
4027      * See {@link #bindService(Intent, int, Executor, ServiceConnection)}
4028      * Call {@link BindServiceFlags#of(long)} to obtain a BindServiceFlags object.
4029      */
bindService(@equiresPermission @onNull Intent service, @NonNull BindServiceFlags flags, @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn)4030     public boolean bindService(@RequiresPermission @NonNull Intent service,
4031             @NonNull BindServiceFlags flags, @NonNull @CallbackExecutor Executor executor,
4032             @NonNull ServiceConnection conn) {
4033         throw new RuntimeException("Not implemented. Must override in a subclass.");
4034     }
4035 
4036     /**
4037      * Variation of {@link #bindService} that, in the specific case of isolated
4038      * services, allows the caller to generate multiple instances of a service
4039      * from a single component declaration.  In other words, you can use this to bind
4040      * to a service that has specified {@link android.R.attr#isolatedProcess} and, in
4041      * addition to the existing behavior of running in an isolated process, you can
4042      * also through the arguments here have the system bring up multiple concurrent
4043      * processes hosting their own instances of that service.  The <var>instanceName</var>
4044      * you provide here identifies the different instances, and you can use
4045      * {@link #updateServiceGroup(ServiceConnection, int, int)} to tell the system how it
4046      * should manage each of these instances.
4047      *
4048      * @param service Identifies the service to connect to.  The Intent must
4049      *      specify an explicit component name.
4050      * @param flags Operation options for the binding as per {@link #bindService}.
4051      * @param instanceName Unique identifier for the service instance.  Each unique
4052      *      name here will result in a different service instance being created.  Identifiers
4053      *      must only contain ASCII letters, digits, underscores, and periods.
4054      * @param executor Callbacks on ServiceConnection will be called on executor.
4055      *      Must use same instance for the same instance of ServiceConnection.
4056      * @param conn Receives information as the service is started and stopped.
4057      *      This must be a valid ServiceConnection object; it must not be null.
4058      *
4059      * @return Returns success of binding as per {@link #bindService}.
4060      *
4061      * @throws SecurityException If the caller does not have permission to access the service
4062      * @throws IllegalArgumentException If the instanceName is invalid.
4063      *
4064      * @see #bindService
4065      * @see #updateServiceGroup
4066      * @see android.R.attr#isolatedProcess
4067      */
bindIsolatedService(@equiresPermission @onNull Intent service, int flags, @NonNull String instanceName, @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn)4068     public boolean bindIsolatedService(@RequiresPermission @NonNull Intent service,
4069             int flags, @NonNull String instanceName,
4070             @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn) {
4071         throw new RuntimeException("Not implemented. Must override in a subclass.");
4072     }
4073 
4074     /**
4075      * See {@link #bindIsolatedService(Intent, int, String, Executor,ServiceConnection)}
4076      * Call {@link BindServiceFlags#of(long)} to obtain a BindServiceFlags object.
4077      */
bindIsolatedService(@equiresPermission @onNull Intent service, @NonNull BindServiceFlags flags, @NonNull String instanceName, @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn)4078     public boolean bindIsolatedService(@RequiresPermission @NonNull Intent service,
4079             @NonNull BindServiceFlags flags, @NonNull String instanceName,
4080             @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn) {
4081         throw new RuntimeException("Not implemented. Must override in a subclass.");
4082     }
4083 
4084     /**
4085      * Binds to a service in the given {@code user} in the same manner as {@link #bindService}.
4086      *
4087      * <p>Requires that one of the following conditions are met:
4088      * <ul>
4089      *  <li>caller has {@code android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}</li>
4090      *  <li>caller has {@code android.Manifest.permission.INTERACT_ACROSS_USERS} and is the same
4091      *      package as the {@code service} (determined by its component's package) and the Android
4092      *      version is at least {@link android.os.Build.VERSION_CODES#TIRAMISU}</li>
4093      *  <li>caller has {@code android.Manifest.permission.INTERACT_ACROSS_USERS} and is in same
4094      *      profile group as the given {@code user}</li>
4095      *  <li>caller has {@code android.Manifest.permission.INTERACT_ACROSS_PROFILES} and is in same
4096      *      profile group as the given {@code user} and is the same package as the {@code service}
4097      *      </li>
4098      * </ul>
4099      *
4100      * @param service Identifies the service to connect to.  The Intent must
4101      *      specify an explicit component name.
4102      * @param conn Receives information as the service is started and stopped.
4103      *      This must be a valid ServiceConnection object; it must not be null.
4104      * @param flags Operation options for the binding.  May be 0,
4105      *          {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
4106      *          {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
4107      *          {@link #BIND_ALLOW_OOM_MANAGEMENT}, {@link #BIND_WAIVE_PRIORITY}.
4108      *          {@link #BIND_IMPORTANT}, or
4109      *          {@link #BIND_ADJUST_WITH_ACTIVITY}.
4110      * @return {@code true} if the system is in the process of bringing up a
4111      *         service that your client has permission to bind to; {@code false}
4112      *         if the system couldn't find the service. You should call {@link #unbindService}
4113      *         to release the connection even if this method returned {@code false}.
4114      *
4115      * @throws SecurityException if the client does not have the required permission to bind.
4116      */
4117     @SuppressWarnings("unused")
4118     @RequiresPermission(anyOf = {
4119             android.Manifest.permission.INTERACT_ACROSS_USERS,
4120             android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
4121             android.Manifest.permission.INTERACT_ACROSS_PROFILES
4122             }, conditional = true)
bindServiceAsUser( @onNull @equiresPermission Intent service, @NonNull ServiceConnection conn, int flags, @NonNull UserHandle user)4123     public boolean bindServiceAsUser(
4124             @NonNull @RequiresPermission Intent service, @NonNull ServiceConnection conn, int flags,
4125             @NonNull UserHandle user) {
4126         throw new RuntimeException("Not implemented. Must override in a subclass.");
4127     }
4128 
4129     /**
4130      * See {@link #bindServiceAsUser(Intent, ServiceConnection, int, UserHandle)}
4131      * Call {@link BindServiceFlags#of(long)} to obtain a BindServiceFlags object.
4132      */
4133     @SuppressWarnings("unused")
4134     @RequiresPermission(anyOf = {
4135             android.Manifest.permission.INTERACT_ACROSS_USERS,
4136             android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
4137             android.Manifest.permission.INTERACT_ACROSS_PROFILES
4138     }, conditional = true)
bindServiceAsUser( @onNull @equiresPermission Intent service, @NonNull ServiceConnection conn, @NonNull BindServiceFlags flags, @NonNull UserHandle user)4139     public boolean bindServiceAsUser(
4140             @NonNull @RequiresPermission Intent service, @NonNull ServiceConnection conn,
4141             @NonNull BindServiceFlags flags, @NonNull UserHandle user) {
4142         throw new RuntimeException("Not implemented. Must override in a subclass.");
4143     }
4144 
4145     /**
4146      * Same as {@link #bindServiceAsUser(Intent, ServiceConnection, int, UserHandle)}, but with an
4147      * explicit non-null Handler to run the ServiceConnection callbacks on.
4148      * @hide
4149      */
4150     @RequiresPermission(anyOf = {
4151             android.Manifest.permission.INTERACT_ACROSS_USERS,
4152             android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
4153             android.Manifest.permission.INTERACT_ACROSS_PROFILES
4154             }, conditional = true)
4155     @UnsupportedAppUsage(trackingBug = 136728678)
bindServiceAsUser(Intent service, ServiceConnection conn, int flags, Handler handler, UserHandle user)4156     public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
4157             Handler handler, UserHandle user) {
4158         throw new RuntimeException("Not implemented. Must override in a subclass.");
4159     }
4160 
4161     /**
4162      * See {@link #bindServiceAsUser(Intent, ServiceConnection, int, Handler, UserHandle)}
4163      * Call {@link BindServiceFlags#of(long)} to obtain a BindServiceFlags object.
4164      * @hide
4165      */
4166     @RequiresPermission(anyOf = {
4167             android.Manifest.permission.INTERACT_ACROSS_USERS,
4168             android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
4169             android.Manifest.permission.INTERACT_ACROSS_PROFILES
4170     }, conditional = true)
4171     @UnsupportedAppUsage(trackingBug = 136728678)
bindServiceAsUser(@onNull Intent service, @NonNull ServiceConnection conn, @NonNull BindServiceFlags flags, @NonNull Handler handler, @NonNull UserHandle user)4172     public boolean bindServiceAsUser(@NonNull Intent service, @NonNull ServiceConnection conn,
4173             @NonNull BindServiceFlags flags, @NonNull Handler handler, @NonNull UserHandle user) {
4174         throw new RuntimeException("Not implemented. Must override in a subclass.");
4175     }
4176 
4177     /**
4178      * For a service previously bound with {@link #bindService} or a related method, change
4179      * how the system manages that service's process in relation to other processes.  This
4180      * doesn't modify the original bind flags that were passed in when binding, but adjusts
4181      * how the process will be managed in some cases based on those flags.  Currently only
4182      * works on isolated processes (will be ignored for non-isolated processes).
4183      *
4184      * <p>Note that this call does not take immediate effect, but will be applied the next
4185      * time the impacted process is adjusted for some other reason.  Typically you would
4186      * call this before then calling a new {@link #bindIsolatedService} on the service
4187      * of interest, with that binding causing the process to be shuffled accordingly.</p>
4188      *
4189      * @param conn The connection interface previously supplied to bindService().  This
4190      *             parameter must not be null.
4191      * @param group A group to put this connection's process in.  Upon calling here, this
4192      *              will override any previous group that was set for that process.  The group
4193      *              tells the system about processes that are logically grouped together, so
4194      *              should be managed as one unit of importance (such as when being considered
4195      *              a recently used app).  All processes in the same app with the same group
4196      *              are considered to be related.  Supplying 0 reverts to the default behavior
4197      *              of not grouping.
4198      * @param importance Additional importance of the processes within a group.  Upon calling
4199      *                   here, this will override any previous importance that was set for that
4200      *                   process.  The most important process is 0, and higher values are
4201      *                   successively less important.  You can view this as describing how
4202      *                   to order the processes in an array, with the processes at the end of
4203      *                   the array being the least important.  This value has no meaning besides
4204      *                   indicating how processes should be ordered in that array one after the
4205      *                   other.  This provides a way to fine-tune the system's process killing,
4206      *                   guiding it to kill processes at the end of the array first.
4207      *
4208      * @see #bindIsolatedService
4209      */
updateServiceGroup(@onNull ServiceConnection conn, int group, int importance)4210     public void updateServiceGroup(@NonNull ServiceConnection conn, int group,
4211             int importance) {
4212         throw new RuntimeException("Not implemented. Must override in a subclass.");
4213     }
4214 
4215     /**
4216      * Disconnect from an application service.  You will no longer receive
4217      * calls as the service is restarted, and the service is now allowed to
4218      * stop at any time.
4219      *
4220      * @param conn The connection interface previously supplied to
4221      *             bindService().  This parameter must not be null.
4222      *
4223      * @see #bindService
4224      */
unbindService(@onNull ServiceConnection conn)4225     public abstract void unbindService(@NonNull ServiceConnection conn);
4226 
4227     /**
4228      * Start executing an {@link android.app.Instrumentation} class.  The given
4229      * Instrumentation component will be run by killing its target application
4230      * (if currently running), starting the target process, instantiating the
4231      * instrumentation component, and then letting it drive the application.
4232      *
4233      * <p>This function is not synchronous -- it returns as soon as the
4234      * instrumentation has started and while it is running.
4235      *
4236      * <p>Instrumentation is normally only allowed to run against a package
4237      * that is either unsigned or signed with a signature that the
4238      * the instrumentation package is also signed with (ensuring the target
4239      * trusts the instrumentation).
4240      *
4241      * @param className Name of the Instrumentation component to be run.
4242      * @param profileFile Optional path to write profiling data as the
4243      * instrumentation runs, or null for no profiling.
4244      * @param arguments Additional optional arguments to pass to the
4245      * instrumentation, or null.
4246      *
4247      * @return {@code true} if the instrumentation was successfully started,
4248      * else {@code false} if it could not be found.
4249      */
startInstrumentation(@onNull ComponentName className, @Nullable String profileFile, @Nullable Bundle arguments)4250     public abstract boolean startInstrumentation(@NonNull ComponentName className,
4251             @Nullable String profileFile, @Nullable Bundle arguments);
4252 
4253     /** @hide */
4254     @StringDef(suffix = { "_SERVICE" }, value = {
4255             POWER_SERVICE,
4256             //@hide: POWER_STATS_SERVICE,
4257             WINDOW_SERVICE,
4258             LAYOUT_INFLATER_SERVICE,
4259             ACCOUNT_SERVICE,
4260             ACTIVITY_SERVICE,
4261             ALARM_SERVICE,
4262             NOTIFICATION_SERVICE,
4263             ACCESSIBILITY_SERVICE,
4264             CAPTIONING_SERVICE,
4265             KEYGUARD_SERVICE,
4266             LOCATION_SERVICE,
4267             HEALTHCONNECT_SERVICE,
4268             //@hide: COUNTRY_DETECTOR,
4269             SEARCH_SERVICE,
4270             SENSOR_SERVICE,
4271             SENSOR_PRIVACY_SERVICE,
4272             STORAGE_SERVICE,
4273             STORAGE_STATS_SERVICE,
4274             WALLPAPER_SERVICE,
4275             VIBRATOR_MANAGER_SERVICE,
4276             VIBRATOR_SERVICE,
4277             //@hide: STATUS_BAR_SERVICE,
4278             THREAD_NETWORK_SERVICE,
4279             CONNECTIVITY_SERVICE,
4280             TETHERING_SERVICE,
4281             PAC_PROXY_SERVICE,
4282             VCN_MANAGEMENT_SERVICE,
4283             //@hide: IP_MEMORY_STORE_SERVICE,
4284             IPSEC_SERVICE,
4285             VPN_MANAGEMENT_SERVICE,
4286             TEST_NETWORK_SERVICE,
4287             //@hide: UPDATE_LOCK_SERVICE,
4288             //@hide: NETWORKMANAGEMENT_SERVICE,
4289             NETWORK_STATS_SERVICE,
4290             //@hide: NETWORK_POLICY_SERVICE,
4291             WIFI_SERVICE,
4292             WIFI_AWARE_SERVICE,
4293             WIFI_P2P_SERVICE,
4294             WIFI_SCANNING_SERVICE,
4295             //@hide: LOWPAN_SERVICE,
4296             //@hide: WIFI_RTT_SERVICE,
4297             //@hide: ETHERNET_SERVICE,
4298             WIFI_RTT_RANGING_SERVICE,
4299             WIFI_USD_SERVICE,
4300             NSD_SERVICE,
4301             AUDIO_SERVICE,
4302             AUDIO_DEVICE_VOLUME_SERVICE,
4303             AUTH_SERVICE,
4304             FINGERPRINT_SERVICE,
4305             //@hide: FACE_SERVICE,
4306             BIOMETRIC_SERVICE,
4307             AUTHENTICATION_POLICY_SERVICE,
4308             MEDIA_ROUTER_SERVICE,
4309             TELEPHONY_SERVICE,
4310             TELEPHONY_SUBSCRIPTION_SERVICE,
4311             CARRIER_CONFIG_SERVICE,
4312             EUICC_SERVICE,
4313             //@hide: MMS_SERVICE,
4314             TELECOM_SERVICE,
4315             CLIPBOARD_SERVICE,
4316             INPUT_METHOD_SERVICE,
4317             TEXT_SERVICES_MANAGER_SERVICE,
4318             TEXT_CLASSIFICATION_SERVICE,
4319             APPWIDGET_SERVICE,
4320             //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
4321             //@hide: BACKUP_SERVICE,
4322             REBOOT_READINESS_SERVICE,
4323             ROLLBACK_SERVICE,
4324             DROPBOX_SERVICE,
4325             //@hide: DEVICE_IDLE_CONTROLLER,
4326             //@hide: POWER_WHITELIST_MANAGER,
4327             DEVICE_POLICY_SERVICE,
4328             UI_MODE_SERVICE,
4329             DOWNLOAD_SERVICE,
4330             NFC_SERVICE,
4331             BLUETOOTH_SERVICE,
4332             //@hide: SIP_SERVICE,
4333             USB_SERVICE,
4334             LAUNCHER_APPS_SERVICE,
4335             //@hide: SERIAL_SERVICE,
4336             //@hide: HDMI_CONTROL_SERVICE,
4337             INPUT_SERVICE,
4338             DISPLAY_SERVICE,
4339             //@hide COLOR_DISPLAY_SERVICE,
4340             USER_SERVICE,
4341             RESTRICTIONS_SERVICE,
4342             APP_OPS_SERVICE,
4343             ROLE_SERVICE,
4344             //@hide ROLE_CONTROLLER_SERVICE,
4345             CAMERA_SERVICE,
4346             //@hide: PLATFORM_COMPAT_SERVICE,
4347             //@hide: PLATFORM_COMPAT_NATIVE_SERVICE,
4348             PRINT_SERVICE,
4349             CONSUMER_IR_SERVICE,
4350             //@hide: TRUST_SERVICE,
4351             TV_INTERACTIVE_APP_SERVICE,
4352             TV_INPUT_SERVICE,
4353             //@hide: TV_TUNER_RESOURCE_MGR_SERVICE,
4354             //@hide: NETWORK_SCORE_SERVICE,
4355             USAGE_STATS_SERVICE,
4356             MEDIA_SESSION_SERVICE,
4357             MEDIA_COMMUNICATION_SERVICE,
4358             BATTERY_SERVICE,
4359             JOB_SCHEDULER_SERVICE,
4360             PERSISTENT_DATA_BLOCK_SERVICE,
4361             //@hide: OEM_LOCK_SERVICE,
4362             MEDIA_PROJECTION_SERVICE,
4363             MIDI_SERVICE,
4364             RADIO_SERVICE,
4365             HARDWARE_PROPERTIES_SERVICE,
4366             //@hide: SOUND_TRIGGER_SERVICE,
4367             SHORTCUT_SERVICE,
4368             //@hide: CONTEXTHUB_SERVICE,
4369             SYSTEM_HEALTH_SERVICE,
4370             //@hide: INCIDENT_SERVICE,
4371             //@hide: INCIDENT_COMPANION_SERVICE,
4372             //@hide: STATS_COMPANION_SERVICE,
4373             COMPANION_DEVICE_SERVICE,
4374             VIRTUAL_DEVICE_SERVICE,
4375             CROSS_PROFILE_APPS_SERVICE,
4376             //@hide: SYSTEM_UPDATE_SERVICE,
4377             //@hide: TIME_DETECTOR_SERVICE,
4378             //@hide: TIME_ZONE_DETECTOR_SERVICE,
4379             PERMISSION_SERVICE,
4380             LIGHTS_SERVICE,
4381             LOCALE_SERVICE,
4382             //@hide: PEOPLE_SERVICE,
4383             //@hide: DEVICE_STATE_SERVICE,
4384             //@hide: SPEECH_RECOGNITION_SERVICE,
4385             UWB_SERVICE,
4386             MEDIA_METRICS_SERVICE,
4387             //@hide: ATTESTATION_VERIFICATION_SERVICE,
4388             //@hide: SAFETY_CENTER_SERVICE,
4389             DISPLAY_HASH_SERVICE,
4390             CREDENTIAL_SERVICE,
4391             DEVICE_LOCK_SERVICE,
4392             VIRTUALIZATION_SERVICE,
4393             GRAMMATICAL_INFLECTION_SERVICE,
4394             SECURITY_STATE_SERVICE,
4395            //@hide: ECM_ENHANCED_CONFIRMATION_SERVICE,
4396             CONTACT_KEYS_SERVICE,
4397             RANGING_SERVICE,
4398             MEDIA_QUALITY_SERVICE,
4399             ADVANCED_PROTECTION_SERVICE,
4400 
4401     })
4402     @Retention(RetentionPolicy.SOURCE)
4403     public @interface ServiceName {}
4404 
4405     /**
4406      * Return the handle to a system-level service by name. The class of the
4407      * returned object varies by the requested name. Currently available names
4408      * are:
4409      *
4410      * <dl>
4411      *  <dt> {@link #WINDOW_SERVICE} ("window")
4412      *  <dd> The top-level window manager in which you can place custom
4413      *  windows.  The returned object is a {@link android.view.WindowManager}. Must only be obtained
4414      *  from a visual context such as Activity or a Context created with
4415      *  {@link #createWindowContext(int, Bundle)}, which are adjusted to the configuration and
4416      *  visual bounds of an area on screen.
4417      *  <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
4418      *  <dd> A {@link android.view.LayoutInflater} for inflating layout resources
4419      *  in this context. Must only be obtained from a visual context such as Activity or a Context
4420      *  created with {@link #createWindowContext(int, Bundle)}, which are adjusted to the
4421      *  configuration and visual bounds of an area on screen.
4422      *  <dt> {@link #ACTIVITY_SERVICE} ("activity")
4423      *  <dd> A {@link android.app.ActivityManager} for interacting with the
4424      *  global activity state of the system.
4425      *  <dt> {@link #WALLPAPER_SERVICE} ("wallpaper")
4426      *  <dd> A {@link android.service.wallpaper.WallpaperService} for accessing wallpapers in this
4427      *  context. Must only be obtained from a visual context such as Activity or a Context created
4428      *  with {@link #createWindowContext(int, Bundle)}, which are adjusted to the configuration and
4429      *  visual bounds of an area on screen.
4430      *  <dt> {@link #POWER_SERVICE} ("power")
4431      *  <dd> A {@link android.os.PowerManager} for controlling power
4432      *  management.
4433      *  <dt> {@link #ALARM_SERVICE} ("alarm")
4434      *  <dd> A {@link android.app.AlarmManager} for receiving intents at the
4435      *  time of your choosing.
4436      *  <dt> {@link #NOTIFICATION_SERVICE} ("notification")
4437      *  <dd> A {@link android.app.NotificationManager} for informing the user
4438      *   of background events.
4439      *  <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
4440      *  <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
4441      *  <dt> {@link #LOCATION_SERVICE} ("location")
4442      *  <dd> A {@link android.location.LocationManager} for controlling location
4443      *   (e.g., GPS) updates.
4444      *  <dt> {@link #SEARCH_SERVICE} ("search")
4445      *  <dd> A {@link android.app.SearchManager} for handling search.
4446      *  <dt> {@link #VIBRATOR_MANAGER_SERVICE} ("vibrator_manager")
4447      *  <dd> A {@link android.os.VibratorManager} for accessing the device vibrators, interacting
4448      *  with individual ones and playing synchronized effects on multiple vibrators.
4449      *  <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
4450      *  <dd> A {@link android.os.Vibrator} for interacting with the vibrator hardware.
4451      *  <dt> {@link #CONNECTIVITY_SERVICE} ("connectivity")
4452      *  <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
4453      *  handling management of network connections.
4454      *  <dt> {@link #IPSEC_SERVICE} ("ipsec")
4455      *  <dd> A {@link android.net.IpSecManager IpSecManager} for managing IPSec on
4456      *  sockets and networks.
4457      *  <dt> {@link #WIFI_SERVICE} ("wifi")
4458      *  <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
4459      *  connectivity.  On releases before Android 7, it should only be obtained from an application
4460      *  context, and not from any other derived context to avoid memory leaks within the calling
4461      *  process.
4462      *  <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
4463      *  <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
4464      * Wi-Fi Aware discovery and connectivity.
4465      *  <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
4466      *  <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
4467      * Wi-Fi Direct connectivity.
4468      * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
4469      * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
4470      * for management of input methods.
4471      * <dt> {@link #UI_MODE_SERVICE} ("uimode")
4472      * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
4473      * <dt> {@link #DOWNLOAD_SERVICE} ("download")
4474      * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
4475      * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
4476      * <dd> A {@link android.os.BatteryManager} for managing battery state
4477      * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
4478      * <dd>  A {@link android.app.job.JobScheduler} for managing scheduled tasks
4479      * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
4480      * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
4481      * usage statistics.
4482      * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
4483      * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
4484      * <dt> {@link #DOMAIN_VERIFICATION_SERVICE} ("domain_verification")
4485      * <dd> A {@link android.content.pm.verify.domain.DomainVerificationManager} for accessing
4486      * web domain approval state.
4487      * <dt> {@link #DISPLAY_HASH_SERVICE} ("display_hash")
4488      * <dd> A {@link android.view.displayhash.DisplayHashManager} for management of display hashes.
4489      * <dt> {@link #AUTHENTICATION_POLICY_SERVICE} ("authentication_policy")
4490      * <dd> A {@link android.security.authenticationpolicy.AuthenticationPolicyManager}
4491      * for managing authentication related policies on the device.
4492      * </dl>
4493      *
4494      * <p>Note:  System services obtained via this API may be closely associated with
4495      * the Context in which they are obtained from.  In general, do not share the
4496      * service objects between various different contexts (Activities, Applications,
4497      * Services, Providers, etc.)
4498      *
4499      * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
4500      * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
4501      * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
4502      * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
4503      * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
4504      * return <code>null</code>.  Generally, if you are running as an instant app you should always
4505      * check whether the result of this method is {@code null}.
4506      *
4507      * <p>Note: When implementing this method, keep in mind that new services can be added on newer
4508      * Android releases, so if you're looking for just the explicit names mentioned above, make sure
4509      * to return {@code null} when you don't recognize the name &mdash; if you throw a
4510      * {@link RuntimeException} exception instead, your app might break on new Android releases.
4511      *
4512      * @param name The name of the desired service.
4513      *
4514      * @return The service or {@code null} if the name does not exist.
4515      *
4516      * @see #WINDOW_SERVICE
4517      * @see android.view.WindowManager
4518      * @see #LAYOUT_INFLATER_SERVICE
4519      * @see android.view.LayoutInflater
4520      * @see #ACTIVITY_SERVICE
4521      * @see android.app.ActivityManager
4522      * @see #POWER_SERVICE
4523      * @see android.os.PowerManager
4524      * @see #ALARM_SERVICE
4525      * @see android.app.AlarmManager
4526      * @see #NOTIFICATION_SERVICE
4527      * @see android.app.NotificationManager
4528      * @see #KEYGUARD_SERVICE
4529      * @see android.app.KeyguardManager
4530      * @see #LOCATION_SERVICE
4531      * @see android.location.LocationManager
4532      * @see #SEARCH_SERVICE
4533      * @see android.app.SearchManager
4534      * @see #SENSOR_SERVICE
4535      * @see android.hardware.SensorManager
4536      * @see #STORAGE_SERVICE
4537      * @see android.os.storage.StorageManager
4538      * @see #VIBRATOR_MANAGER_SERVICE
4539      * @see android.os.VibratorManager
4540      * @see #VIBRATOR_SERVICE
4541      * @see android.os.Vibrator
4542      * @see #CONNECTIVITY_SERVICE
4543      * @see android.net.ConnectivityManager
4544      * @see #WIFI_SERVICE
4545      * @see android.net.wifi.WifiManager
4546      * @see #AUDIO_SERVICE
4547      * @see android.media.AudioManager
4548      * @see #MEDIA_ROUTER_SERVICE
4549      * @see android.media.MediaRouter
4550      * @see #TELEPHONY_SERVICE
4551      * @see android.telephony.TelephonyManager
4552      * @see #TELEPHONY_SUBSCRIPTION_SERVICE
4553      * @see android.telephony.SubscriptionManager
4554      * @see #CARRIER_CONFIG_SERVICE
4555      * @see android.telephony.CarrierConfigManager
4556      * @see #EUICC_SERVICE
4557      * @see android.telephony.euicc.EuiccManager
4558      * @see #INPUT_METHOD_SERVICE
4559      * @see android.view.inputmethod.InputMethodManager
4560      * @see #UI_MODE_SERVICE
4561      * @see android.app.UiModeManager
4562      * @see #DOWNLOAD_SERVICE
4563      * @see android.app.DownloadManager
4564      * @see #BATTERY_SERVICE
4565      * @see android.os.BatteryManager
4566      * @see #JOB_SCHEDULER_SERVICE
4567      * @see android.app.job.JobScheduler
4568      * @see #NETWORK_STATS_SERVICE
4569      * @see android.app.usage.NetworkStatsManager
4570      * @see android.os.HardwarePropertiesManager
4571      * @see #HARDWARE_PROPERTIES_SERVICE
4572      * @see #DOMAIN_VERIFICATION_SERVICE
4573      * @see android.content.pm.verify.domain.DomainVerificationManager
4574      * @see #DISPLAY_HASH_SERVICE
4575      * @see android.view.displayhash.DisplayHashManager
4576      * @see #AUTHENTICATION_POLICY_SERVICE
4577      * @see android.security.authenticationpolicy.AuthenticationPolicyManager
4578      */
getSystemService(@erviceName @onNull String name)4579     public abstract Object getSystemService(@ServiceName @NonNull String name);
4580 
4581     /**
4582      * Return the handle to a system-level service by class.
4583      * <p>
4584      * Currently available classes are:
4585      * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
4586      * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
4587      * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
4588      * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
4589      * {@link android.app.SearchManager}, {@link android.os.Vibrator},
4590      * {@link android.net.ConnectivityManager},
4591      * {@link android.net.wifi.WifiManager},
4592      * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
4593      * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
4594      * {@link android.view.inputmethod.InputMethodManager},
4595      * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
4596      * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
4597      * {@link android.app.usage.NetworkStatsManager},
4598      * {@link android.content.pm.verify.domain.DomainVerificationManager},
4599      * {@link android.view.displayhash.DisplayHashManager}
4600      * {@link android.security.authenticationpolicy.AuthenticationPolicyManager}.
4601      * </p>
4602      *
4603      * <p>
4604      * Note: System services obtained via this API may be closely associated with
4605      * the Context in which they are obtained from.  In general, do not share the
4606      * service objects between various different contexts (Activities, Applications,
4607      * Services, Providers, etc.)
4608      * </p>
4609      *
4610      * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
4611      * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
4612      * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
4613      * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
4614      * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
4615      * return {@code null}. Generally, if you are running as an instant app you should always
4616      * check whether the result of this method is {@code null}.
4617      * </p>
4618      *
4619      * @param serviceClass The class of the desired service.
4620      * @return The service or {@code null} if the class is not a supported system service. Note:
4621      * <b>never</b> throw a {@link RuntimeException} if the name is not supported.
4622      */
4623     @SuppressWarnings("unchecked")
4624     @RavenwoodKeep
getSystemService(@onNull Class<T> serviceClass)4625     public final <T> T getSystemService(@NonNull Class<T> serviceClass) {
4626         // Because subclasses may override getSystemService(String) we cannot
4627         // perform a lookup by class alone.  We must first map the class to its
4628         // service name then invoke the string-based method.
4629         String serviceName = getSystemServiceName(serviceClass);
4630         return serviceName != null ? (T)getSystemService(serviceName) : null;
4631     }
4632 
4633     /**
4634      * Gets the name of the system-level service that is represented by the specified class.
4635      *
4636      * @param serviceClass The class of the desired service.
4637      * @return The service name or null if the class is not a supported system service.
4638      */
getSystemServiceName(@onNull Class<?> serviceClass)4639     public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
4640 
4641     /**
4642      * Use with {@link #getSystemService(String)} to retrieve a
4643      * {@link android.os.PowerManager} for controlling power management,
4644      * including "wake locks," which let you keep the device on while
4645      * you're running long tasks.
4646      */
4647     public static final String POWER_SERVICE = "power";
4648 
4649     /**
4650      * Use with {@link #getSystemService(String)} to retrieve a
4651      * {@link android.os.PowerStatsService} for accessing power stats
4652      * service.
4653      *
4654      * @see #getSystemService(String)
4655      * @hide
4656      */
4657     public static final String POWER_STATS_SERVICE = "powerstats";
4658 
4659     /**
4660      * Use with {@link #getSystemService(String)} to retrieve a
4661      * {@link android.os.RecoverySystem} for accessing the recovery system
4662      * service.
4663      *
4664      * @see #getSystemService(String)
4665      * @hide
4666      */
4667     public static final String RECOVERY_SERVICE = "recovery";
4668 
4669     /**
4670      * Use with {@link #getSystemService(String)} to retrieve a
4671      * {@link android.os.SystemUpdateManager} for accessing the system update
4672      * manager service.
4673      *
4674      * @see #getSystemService(String)
4675      * @hide
4676      */
4677     @SystemApi
4678     public static final String SYSTEM_UPDATE_SERVICE = "system_update";
4679 
4680     /**
4681      * Use with {@link #getSystemService(String)} to retrieve a
4682      * {@link android.view.WindowManager} for accessing the system's window
4683      * manager.
4684      *
4685      * @see #getSystemService(String)
4686      * @see android.view.WindowManager
4687      */
4688     @UiContext
4689     public static final String WINDOW_SERVICE = "window";
4690 
4691     /**
4692      * Use with {@link #getSystemService(String)} to retrieve a
4693      * {@link android.view.LayoutInflater} for inflating layout resources in this
4694      * context.
4695      *
4696      * @see #getSystemService(String)
4697      * @see android.view.LayoutInflater
4698      */
4699     @UiContext
4700     public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
4701 
4702     /**
4703      * Use with {@link #getSystemService(String)} to retrieve a
4704      * {@link android.accounts.AccountManager} for receiving intents at a
4705      * time of your choosing.
4706      *
4707      * @see #getSystemService(String)
4708      * @see android.accounts.AccountManager
4709      */
4710     public static final String ACCOUNT_SERVICE = "account";
4711 
4712     /**
4713      * Use with {@link #getSystemService(String)} to retrieve a
4714      * {@link android.app.ActivityManager} for interacting with the global
4715      * system state.
4716      *
4717      * @see #getSystemService(String)
4718      * @see android.app.ActivityManager
4719      */
4720     public static final String ACTIVITY_SERVICE = "activity";
4721 
4722     /**
4723      * Use with {@link #getSystemService(String)} to retrieve a
4724      * {@link android.app.ActivityTaskManager} for interacting with the global system state.
4725      *
4726      * @see #getSystemService(String)
4727      * @see android.app.ActivityTaskManager
4728      * @hide
4729      */
4730     public static final String ACTIVITY_TASK_SERVICE = "activity_task";
4731 
4732     /**
4733      * Use with {@link #getSystemService(String)} to retrieve a
4734      * {@link android.app.UriGrantsManager} for interacting with the global system state.
4735      *
4736      * @see #getSystemService(String)
4737      * @see android.app.UriGrantsManager
4738      * @hide
4739      */
4740     public static final String URI_GRANTS_SERVICE = "uri_grants";
4741 
4742     /**
4743      * Use with {@link #getSystemService(String)} to retrieve a
4744      * {@link android.app.AlarmManager} for receiving intents at a
4745      * time of your choosing.
4746      *
4747      * @see #getSystemService(String)
4748      * @see android.app.AlarmManager
4749      */
4750     public static final String ALARM_SERVICE = "alarm";
4751 
4752     /**
4753      * Use with {@link #getSystemService(String)} to retrieve a
4754      * {@link android.app.NotificationManager} for informing the user of
4755      * background events.
4756      *
4757      * @see #getSystemService(String)
4758      * @see android.app.NotificationManager
4759      */
4760     public static final String NOTIFICATION_SERVICE = "notification";
4761 
4762     /**
4763      * Use with {@link #getSystemService(String)} to retrieve a
4764      * {@link android.view.accessibility.AccessibilityManager} for giving the user
4765      * feedback for UI events through the registered event listeners.
4766      *
4767      * @see #getSystemService(String)
4768      * @see android.view.accessibility.AccessibilityManager
4769      */
4770     public static final String ACCESSIBILITY_SERVICE = "accessibility";
4771 
4772     /**
4773      * Use with {@link #getSystemService(String)} to retrieve a
4774      * {@link android.view.accessibility.CaptioningManager} for obtaining
4775      * captioning properties and listening for changes in captioning
4776      * preferences.
4777      *
4778      * @see #getSystemService(String)
4779      * @see android.view.accessibility.CaptioningManager
4780      */
4781     public static final String CAPTIONING_SERVICE = "captioning";
4782 
4783     /**
4784      * Use with {@link #getSystemService(String)} to retrieve a
4785      * {@link android.app.KeyguardManager} for controlling keyguard.
4786      *
4787      * @see #getSystemService(String)
4788      * @see android.app.KeyguardManager
4789      */
4790     public static final String KEYGUARD_SERVICE = "keyguard";
4791 
4792     /**
4793      * Use with {@link #getSystemService(String)} to retrieve a {@link
4794      * android.location.LocationManager} for controlling location
4795      * updates.
4796      *
4797      * @see #getSystemService(String)
4798      * @see android.location.LocationManager
4799      */
4800     public static final String LOCATION_SERVICE = "location";
4801 
4802     /**
4803      * Use with {@link #getSystemService(String)} to retrieve a
4804      * {@link android.location.CountryDetector} for detecting the country that
4805      * the user is in.
4806      *
4807      * @hide
4808      */
4809     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
4810     public static final String COUNTRY_DETECTOR = "country_detector";
4811 
4812     /**
4813      * Use with {@link #getSystemService(String)} to retrieve a {@link
4814      * android.app.SearchManager} for handling searches.
4815      *
4816      * <p>
4817      * {@link Configuration#UI_MODE_TYPE_WATCH} does not support
4818      * {@link android.app.SearchManager}.
4819      *
4820      * @see #getSystemService
4821      * @see android.app.SearchManager
4822      */
4823     public static final String SEARCH_SERVICE = "search";
4824 
4825     /**
4826      * Use with {@link #getSystemService(String)} to retrieve a {@link
4827      * android.hardware.SensorManager} for accessing sensors.
4828      *
4829      * @see #getSystemService(String)
4830      * @see android.hardware.SensorManager
4831      */
4832     public static final String SENSOR_SERVICE = "sensor";
4833 
4834     /**
4835      * Use with {@link #getSystemService(String)} to retrieve a {@link
4836      * android.hardware.SensorPrivacyManager} for accessing sensor privacy
4837      * functions.
4838      *
4839      * @see #getSystemService(String)
4840      * @see android.hardware.SensorPrivacyManager
4841      *
4842      * @hide
4843      */
4844     public static final String SENSOR_PRIVACY_SERVICE = "sensor_privacy";
4845 
4846     /**
4847      * Use with {@link #getSystemService(String)} to retrieve a {@link
4848      * android.security.keystore.KeyStoreManager} for accessing
4849      * <a href="/privacy-and-security/keystore">Android Keystore</a>
4850      * functions.
4851      *
4852      * @see #getSystemService(String)
4853      * @see android.security.keystore.KeyStoreManager
4854      */
4855     @FlaggedApi(android.security.Flags.FLAG_KEYSTORE_GRANT_API)
4856     public static final String KEYSTORE_SERVICE = "keystore";
4857 
4858     /**
4859      * Use with {@link #getSystemService(String)} to retrieve a {@link
4860      * android.os.storage.StorageManager} for accessing system storage
4861      * functions.
4862      *
4863      * @see #getSystemService(String)
4864      * @see android.os.storage.StorageManager
4865      */
4866     public static final String STORAGE_SERVICE = "storage";
4867 
4868     /**
4869      * Use with {@link #getSystemService(String)} to retrieve a {@link
4870      * android.app.usage.StorageStatsManager} for accessing system storage
4871      * statistics.
4872      *
4873      * @see #getSystemService(String)
4874      * @see android.app.usage.StorageStatsManager
4875      */
4876     public static final String STORAGE_STATS_SERVICE = "storagestats";
4877 
4878     /**
4879      * Use with {@link #getSystemService(String)} to retrieve a
4880      * com.android.server.WallpaperService for accessing wallpapers.
4881      *
4882      * @see #getSystemService(String)
4883      */
4884     @UiContext
4885     public static final String WALLPAPER_SERVICE = "wallpaper";
4886 
4887     /**
4888      * Use with {@link #getSystemService(String)} to retrieve a {@link android.os.VibratorManager}
4889      * for accessing the device vibrators, interacting with individual ones and playing synchronized
4890      * effects on multiple vibrators.
4891      *
4892      * @see #getSystemService(String)
4893      * @see android.os.VibratorManager
4894      */
4895     @SuppressLint("ServiceName")
4896     public static final String VIBRATOR_MANAGER_SERVICE = "vibrator_manager";
4897 
4898     /**
4899      * Use with {@link #getSystemService(String)} to retrieve a {@link android.os.Vibrator} for
4900      * interacting with the vibration hardware.
4901      *
4902      * @deprecated Use {@link android.os.VibratorManager} to retrieve the default system vibrator.
4903      * @see #getSystemService(String)
4904      * @see android.os.Vibrator
4905      */
4906     @Deprecated
4907     public static final String VIBRATOR_SERVICE = "vibrator";
4908 
4909     /**
4910      * Use with {@link #getSystemService(String)} to retrieve a {@link
4911      * android.app.StatusBarManager} for interacting with the status bar and quick settings.
4912      *
4913      * @see #getSystemService(String)
4914      * @see android.app.StatusBarManager
4915      *
4916      */
4917     @SuppressLint("ServiceName")
4918     public static final String STATUS_BAR_SERVICE = "statusbar";
4919 
4920     /**
4921      * Use with {@link #getSystemService(String)} to retrieve a {@link
4922      * android.net.ConnectivityManager} for handling management of
4923      * network connections.
4924      *
4925      * @see #getSystemService(String)
4926      * @see android.net.ConnectivityManager
4927      */
4928     public static final String CONNECTIVITY_SERVICE = "connectivity";
4929 
4930     /**
4931      * Use with {@link #getSystemService(String)} to retrieve a {@link
4932      * android.net.PacProxyManager} for handling management of
4933      * pac proxy information.
4934      *
4935      * @see #getSystemService(String)
4936      * @see android.net.PacProxyManager
4937      * @hide
4938      */
4939     @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
4940     public static final String PAC_PROXY_SERVICE = "pac_proxy";
4941 
4942     /**
4943      * Use with {@link #getSystemService(String)} to retrieve a {@link android.net.vcn.VcnManager}
4944      * for managing Virtual Carrier Networks
4945      *
4946      * @see #getSystemService(String)
4947      * @see android.net.vcn.VcnManager
4948      * @hide
4949      */
4950     @FlaggedApi(android.os.Flags.FLAG_MAINLINE_VCN_PLATFORM_API)
4951     @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
4952     public static final String VCN_MANAGEMENT_SERVICE = "vcn_management";
4953 
4954     /**
4955      * Use with {@link #getSystemService(String)} to retrieve a
4956      * {@link android.net.INetd} for communicating with the network stack
4957      * @hide
4958      * @see #getSystemService(String)
4959      * @hide
4960      */
4961     @SystemApi
4962     public static final String NETD_SERVICE = "netd";
4963 
4964     /**
4965      * Use with {@link android.os.ServiceManager.getService()} to retrieve a
4966      * {@link INetworkStackConnector} IBinder for communicating with the network stack
4967      * @hide
4968      * @see NetworkStackClient
4969      */
4970     public static final String NETWORK_STACK_SERVICE = "network_stack";
4971 
4972     /**
4973      * Use with {@link #getSystemService(String)} to retrieve a {@link android.net.TetheringManager}
4974      * for managing tethering functions.
4975      *
4976      * @see android.net.TetheringManager
4977      */
4978     @SuppressLint("UnflaggedApi")
4979     public static final String TETHERING_SERVICE = "tethering";
4980 
4981     /**
4982      * Use with {@link #getSystemService(String)} to retrieve a
4983      * {@link android.net.thread.ThreadNetworkManager}.
4984      *
4985      * <p>On devices without {@link PackageManager#FEATURE_THREAD_NETWORK} system feature
4986      * the {@link #getSystemService(String)} will return {@code null}.
4987      *
4988      * @see #getSystemService(String)
4989      * @see android.net.thread.ThreadNetworkManager
4990      * @hide
4991      */
4992     @FlaggedApi(com.android.net.thread.platform.flags.Flags.FLAG_THREAD_ENABLED_PLATFORM)
4993     @SystemApi
4994     public static final String THREAD_NETWORK_SERVICE = "thread_network";
4995 
4996     /**
4997      * Use with {@link #getSystemService(String)} to retrieve a
4998      * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
4999      * IPSec.
5000      *
5001      * @see #getSystemService(String)
5002      */
5003     public static final String IPSEC_SERVICE = "ipsec";
5004 
5005     /**
5006      * Use with {@link #getSystemService(String)} to retrieve a {@link android.net.VpnManager} to
5007      * manage profiles for the platform built-in VPN.
5008      *
5009      * @see #getSystemService(String)
5010      */
5011     public static final String VPN_MANAGEMENT_SERVICE = "vpn_management";
5012 
5013     /**
5014      * Use with {@link #getSystemService(String)} to retrieve a {@link
5015      * android.net.ConnectivityDiagnosticsManager} for performing network connectivity diagnostics
5016      * as well as receiving network connectivity information from the system.
5017      *
5018      * @see #getSystemService(String)
5019      * @see android.net.ConnectivityDiagnosticsManager
5020      */
5021     public static final String CONNECTIVITY_DIAGNOSTICS_SERVICE = "connectivity_diagnostics";
5022 
5023     /**
5024      * Use with {@link #getSystemService(String)} to retrieve a {@link
5025      * android.net.TestNetworkManager} for building TUNs and limited-use Networks
5026      *
5027      * @see #getSystemService(String)
5028      * @hide
5029      */
5030     @TestApi @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
5031     public static final String TEST_NETWORK_SERVICE = "test_network";
5032 
5033     /**
5034      * Use with {@link #getSystemService(String)} to retrieve a {@link
5035      * android.os.IUpdateLock} for managing runtime sequences that
5036      * must not be interrupted by headless OTA application or similar.
5037      *
5038      * @hide
5039      * @see #getSystemService(String)
5040      * @see android.os.UpdateLock
5041      */
5042     public static final String UPDATE_LOCK_SERVICE = "updatelock";
5043 
5044     /**
5045      * Constant for the internal network management service, not really a Context service.
5046      * @hide
5047      */
5048     public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
5049 
5050     /**
5051      * Use with {@link #getSystemService(String)} to retrieve a
5052      * {@link com.android.server.slice.SliceManagerService} for managing slices.
5053      * @hide
5054      * @see #getSystemService(String)
5055      */
5056     public static final String SLICE_SERVICE = "slice";
5057 
5058     /**
5059      * Use with {@link #getSystemService(String)} to retrieve a {@link
5060      * android.app.usage.NetworkStatsManager} for querying network usage stats.
5061      *
5062      * @see #getSystemService(String)
5063      * @see android.app.usage.NetworkStatsManager
5064      */
5065     public static final String NETWORK_STATS_SERVICE = "netstats";
5066     /** {@hide} */
5067     public static final String NETWORK_POLICY_SERVICE = "netpolicy";
5068     /** {@hide} */
5069     public static final String NETWORK_WATCHLIST_SERVICE = "network_watchlist";
5070 
5071     /**
5072      * Use with {@link #getSystemService(String)} to retrieve a {@link
5073      * android.net.wifi.WifiManager} for handling management of
5074      * Wi-Fi access.
5075      *
5076      * @see #getSystemService(String)
5077      * @see android.net.wifi.WifiManager
5078      */
5079     public static final String WIFI_SERVICE = "wifi";
5080 
5081     /**
5082      * Use with {@link #getSystemService(String)} to retrieve a
5083      * {@link android.net.wifi.wificond.WifiNl80211Manager} for handling management of the
5084      * Wi-Fi nl802.11 daemon (wificond).
5085      *
5086      * @see #getSystemService(String)
5087      * @see android.net.wifi.wificond.WifiNl80211Manager
5088      * @hide
5089      */
5090     @SystemApi
5091     @SuppressLint("ServiceName")
5092     public static final String WIFI_NL80211_SERVICE = "wifinl80211";
5093 
5094     /**
5095      * Use with {@link #getSystemService(String)} to retrieve a {@link
5096      * android.net.wifi.p2p.WifiP2pManager} for handling management of
5097      * Wi-Fi peer-to-peer connections.
5098      *
5099      * @see #getSystemService(String)
5100      * @see android.net.wifi.p2p.WifiP2pManager
5101      */
5102     public static final String WIFI_P2P_SERVICE = "wifip2p";
5103 
5104     /**
5105      * Use with {@link #getSystemService(String)} to retrieve a
5106      * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
5107      * Wi-Fi Aware.
5108      *
5109      * @see #getSystemService(String)
5110      * @see android.net.wifi.aware.WifiAwareManager
5111      */
5112     public static final String WIFI_AWARE_SERVICE = "wifiaware";
5113 
5114     /**
5115      * Use with {@link #getSystemService(String)} to retrieve a {@link
5116      * android.net.wifi.WifiScanner} for scanning the wifi universe
5117      *
5118      * @see #getSystemService(String)
5119      * @see android.net.wifi.WifiScanner
5120      * @hide
5121      */
5122     @SystemApi
5123     public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
5124 
5125     /**
5126      * Use with {@link #getSystemService(String)} to retrieve a {@link
5127      * android.net.wifi.RttManager} for ranging devices with wifi
5128      *
5129      * @see #getSystemService(String)
5130      * @see android.net.wifi.RttManager
5131      * @hide
5132      */
5133     @SystemApi
5134     @Deprecated
5135     public static final String WIFI_RTT_SERVICE = "rttmanager";
5136 
5137     /**
5138      * Use with {@link #getSystemService(String)} to retrieve a {@link
5139      * android.net.wifi.rtt.WifiRttManager} for ranging devices with wifi.
5140      *
5141      * @see #getSystemService(String)
5142      * @see android.net.wifi.rtt.WifiRttManager
5143      */
5144     public static final String WIFI_RTT_RANGING_SERVICE = "wifirtt";
5145 
5146 
5147     /**
5148      * Use with {@link #getSystemService(String)} to retrieve a {@link
5149      * android.net.wifi.usd.UsdManager} for Unsynchronized Service Discovery (USD) operation.
5150      *
5151      * @see #getSystemService(String)
5152      * @see android.net.wifi.usd.UsdManager
5153      * @hide
5154      */
5155     @FlaggedApi(android.net.wifi.flags.Flags.FLAG_USD)
5156     @SystemApi
5157     public static final String WIFI_USD_SERVICE = "wifi_usd";
5158 
5159     /**
5160      * Use with {@link #getSystemService(String)} to retrieve a {@link
5161      * android.net.lowpan.LowpanManager} for handling management of
5162      * LoWPAN access.
5163      *
5164      * @see #getSystemService(String)
5165      * @see android.net.lowpan.LowpanManager
5166      *
5167      * @hide
5168      */
5169     public static final String LOWPAN_SERVICE = "lowpan";
5170 
5171     /**
5172      * Use with {@link #getSystemService(String)} to retrieve a {@link android.net.EthernetManager}
5173      * for handling management of Ethernet access.
5174      *
5175      * @see #getSystemService(String)
5176      * @see android.net.EthernetManager
5177      *
5178      * @hide
5179      */
5180     @SystemApi
5181     public static final String ETHERNET_SERVICE = "ethernet";
5182 
5183     /**
5184      * Use with {@link #getSystemService(String)} to retrieve a {@link
5185      * android.net.nsd.NsdManager} for handling management of network service
5186      * discovery
5187      *
5188      * @see #getSystemService(String)
5189      * @see android.net.nsd.NsdManager
5190      */
5191     public static final String NSD_SERVICE = "servicediscovery";
5192 
5193     /**
5194      * Use with {@link #getSystemService(String)} to retrieve a
5195      * {@link android.media.AudioManager} for handling management of volume,
5196      * ringer modes and audio routing.
5197      *
5198      * @see #getSystemService(String)
5199      * @see android.media.AudioManager
5200      */
5201     public static final String AUDIO_SERVICE = "audio";
5202 
5203     /**
5204      * @hide
5205      * Use with {@link #getSystemService(String)} to retrieve a
5206      * {@link android.media.AudioDeviceVolumeManager} for handling management of audio device
5207      * (e.g. speaker, USB headset) volume.
5208      *
5209      * @see #getSystemService(String)
5210      * @see android.media.AudioDeviceVolumeManager
5211      */
5212     @SystemApi
5213     public static final String AUDIO_DEVICE_VOLUME_SERVICE = "audio_device_volume";
5214 
5215     /**
5216      * Use with {@link #getSystemService(String)} to retrieve a {@link
5217      * android.media.MediaTranscodingManager} for transcoding media.
5218      *
5219      * @hide
5220      * @see #getSystemService(String)
5221      * @see android.media.MediaTranscodingManager
5222      */
5223     @SystemApi
5224     public static final String MEDIA_TRANSCODING_SERVICE = "media_transcoding";
5225 
5226     /**
5227      * AuthService orchestrates biometric and PIN/pattern/password authentication.
5228      *
5229      * BiometricService was split into two services, AuthService and BiometricService, where
5230      * AuthService is the high level service that orchestrates all types of authentication, and
5231      * BiometricService is a lower layer responsible only for biometric authentication.
5232      *
5233      * Ideally we should have renamed BiometricManager to AuthManager, because it logically
5234      * corresponds to AuthService. However, because BiometricManager is a public API, we kept
5235      * the old name but changed the internal implementation to use AuthService.
5236      *
5237      * As of now, the AUTH_SERVICE constant is only used to identify the service in
5238      * SystemServiceRegistry and SELinux. To obtain the manager for AUTH_SERVICE, one should use
5239      * BIOMETRIC_SERVICE with {@link #getSystemService(String)} to retrieve a
5240      * {@link android.hardware.biometrics.BiometricManager}
5241      *
5242      * Map of the two services and their managers:
5243      * [Service]            [Manager]
5244      * AuthService          BiometricManager
5245      * BiometricService     N/A
5246      *
5247      * @hide
5248      */
5249     public static final String AUTH_SERVICE = "auth";
5250 
5251     /**
5252      * Use with {@link #getSystemService(String)} to retrieve an {@link
5253      * android.security.authenticationpolicy.AuthenticationPolicyManager}.
5254      * @see #getSystemService
5255      * @see android.security.authenticationpolicy.AuthenticationPolicyManager
5256      *
5257      * @hide
5258      */
5259     @SystemApi
5260     @FlaggedApi(FLAG_SECURE_LOCKDOWN)
5261     public static final String AUTHENTICATION_POLICY_SERVICE = "authentication_policy";
5262 
5263     /**
5264      * Use with {@link #getSystemService(String)} to retrieve a
5265      * {@link android.hardware.fingerprint.FingerprintManager} for handling management
5266      * of fingerprints.
5267      *
5268      * @see #getSystemService(String)
5269      * @see android.hardware.fingerprint.FingerprintManager
5270      */
5271     public static final String FINGERPRINT_SERVICE = "fingerprint";
5272 
5273     /**
5274      * Use with {@link #getSystemService(String)} to retrieve a
5275      * {@link android.hardware.face.FaceManager} for handling management
5276      * of face authentication.
5277      *
5278      * @hide
5279      * @see #getSystemService
5280      * @see android.hardware.face.FaceManager
5281      */
5282     public static final String FACE_SERVICE = "face";
5283 
5284     /**
5285      * Use with {@link #getSystemService(String)} to retrieve a
5286      * {@link android.hardware.iris.IrisManager} for handling management
5287      * of iris authentication.
5288      *
5289      * @hide
5290      * @see #getSystemService
5291      * @see android.hardware.iris.IrisManager
5292      */
5293     public static final String IRIS_SERVICE = "iris";
5294 
5295     /**
5296      * Use with {@link #getSystemService(String)} to retrieve a
5297      * {@link android.hardware.biometrics.BiometricManager} for handling
5298      * biometric and PIN/pattern/password authentication.
5299      *
5300      * @see #getSystemService
5301      * @see android.hardware.biometrics.BiometricManager
5302      */
5303     public static final String BIOMETRIC_SERVICE = "biometric";
5304 
5305     /**
5306      * Use with {@link #getSystemService(String)} to retrieve a
5307      * {@link android.media.MediaCommunicationManager}
5308      * for managing {@link android.media.MediaSession2}.
5309      *
5310      * @see #getSystemService(String)
5311      * @see android.media.MediaCommunicationManager
5312      */
5313     public static final String MEDIA_COMMUNICATION_SERVICE = "media_communication";
5314 
5315     /**
5316      * Use with {@link #getSystemService} to retrieve a
5317      * {@link android.media.MediaRouter} for controlling and managing
5318      * routing of media.
5319      *
5320      * @see #getSystemService(String)
5321      * @see android.media.MediaRouter
5322      */
5323     public static final String MEDIA_ROUTER_SERVICE = "media_router";
5324 
5325     /**
5326      * Use with {@link #getSystemService(String)} to retrieve a
5327      * {@link android.media.session.MediaSessionManager} for managing media Sessions.
5328      *
5329      * @see #getSystemService(String)
5330      * @see android.media.session.MediaSessionManager
5331      */
5332     public static final String MEDIA_SESSION_SERVICE = "media_session";
5333 
5334     /**
5335      * Use with {@link #getSystemService(String)} to retrieve a
5336      * {@link android.telephony.TelephonyManager} for handling management the
5337      * telephony features of the device.
5338      *
5339      * @see #getSystemService(String)
5340      * @see android.telephony.TelephonyManager
5341      */
5342     public static final String TELEPHONY_SERVICE = "phone";
5343 
5344     /**
5345      * Use with {@link #getSystemService(String)} to retrieve a
5346      * {@link android.telephony.SubscriptionManager} for handling management the
5347      * telephony subscriptions of the device.
5348      *
5349      * @see #getSystemService(String)
5350      * @see android.telephony.SubscriptionManager
5351      */
5352     public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
5353 
5354     /**
5355      * Use with {@link #getSystemService(String)} to retrieve a
5356      * {@link android.telecom.TelecomManager} to manage telecom-related features
5357      * of the device.
5358      *
5359      * @see #getSystemService(String)
5360      * @see android.telecom.TelecomManager
5361      */
5362     public static final String TELECOM_SERVICE = "telecom";
5363 
5364     /**
5365      * Use with {@link #getSystemService(String)} to retrieve a
5366      * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
5367      *
5368      * @see #getSystemService(String)
5369      * @see android.telephony.CarrierConfigManager
5370      */
5371     public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
5372 
5373     /**
5374      * Use with {@link #getSystemService(String)} to retrieve a
5375      * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
5376      *
5377      * @see #getSystemService(String)
5378      * @see android.telephony.euicc.EuiccManager
5379      */
5380     public static final String EUICC_SERVICE = "euicc";
5381 
5382     /**
5383      * Use with {@link #getSystemService(String)} to retrieve a
5384      * {@link android.telephony.euicc.EuiccCardManager} to access the device eUICC (embedded SIM).
5385      *
5386      * @see #getSystemService(String)
5387      * @see android.telephony.euicc.EuiccCardManager
5388      * @hide
5389      */
5390     @SystemApi
5391     public static final String EUICC_CARD_SERVICE = "euicc_card";
5392 
5393     /**
5394      * Use with {@link #getSystemService(String)} to retrieve a
5395      * {@link android.telephony.MmsManager} to send/receive MMS messages.
5396      *
5397      * @see #getSystemService(String)
5398      * @see android.telephony.MmsManager
5399      * @hide
5400      */
5401     public static final String MMS_SERVICE = "mms";
5402 
5403     /**
5404      * Use with {@link #getSystemService(String)} to retrieve a
5405      * {@link android.content.ClipboardManager} for accessing and modifying
5406      * the contents of the global clipboard.
5407      *
5408      * @see #getSystemService(String)
5409      * @see android.content.ClipboardManager
5410      */
5411     public static final String CLIPBOARD_SERVICE = "clipboard";
5412 
5413     /**
5414      * Use with {@link #getSystemService(String)} to retrieve a
5415      * {@link TextClassificationManager} for text classification services.
5416      *
5417      * @see #getSystemService(String)
5418      * @see TextClassificationManager
5419      */
5420     public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
5421 
5422     /**
5423      * Use with {@link #getSystemService(String)} to retrieve a
5424      * {@link android.view.selectiontoolbar.SelectionToolbarManager} for selection toolbar service.
5425      *
5426      * @see #getSystemService(String)
5427      * @hide
5428      */
5429     public static final String SELECTION_TOOLBAR_SERVICE = "selection_toolbar";
5430 
5431     /**
5432      * Use with {@link #getSystemService(String)} to retrieve a
5433      * {@link android.graphics.fonts.FontManager} for font services.
5434      *
5435      * @see #getSystemService(String)
5436      * @see android.graphics.fonts.FontManager
5437      * @hide
5438      */
5439     @SystemApi
5440     @TestApi
5441     public static final String FONT_SERVICE = "font";
5442 
5443     /**
5444      * Use with {@link #getSystemService(String)} to retrieve a
5445      * {@link com.android.server.attention.AttentionManagerService} for attention services.
5446      *
5447      * @see #getSystemService(String)
5448      * @see android.server.attention.AttentionManagerService
5449      * @hide
5450      */
5451     @TestApi
5452     public static final String ATTENTION_SERVICE = "attention";
5453 
5454     /**
5455      * Official published name of the (internal) rotation resolver service.
5456      *
5457      * // TODO(b/178151184): change it back to rotation resolver before S release.
5458      *
5459      * @see #getSystemService(String)
5460      * @hide
5461      */
5462     public static final String ROTATION_RESOLVER_SERVICE = "resolver";
5463 
5464     /**
5465      * Use with {@link #getSystemService(String)} to retrieve a
5466      * {@link android.view.inputmethod.InputMethodManager} for accessing input
5467      * methods.
5468      *
5469      * @see #getSystemService(String)
5470      */
5471     public static final String INPUT_METHOD_SERVICE = "input_method";
5472 
5473     /**
5474      * Use with {@link #getSystemService(String)} to retrieve a
5475      * {@link android.view.textservice.TextServicesManager} for accessing
5476      * text services.
5477      *
5478      * @see #getSystemService(String)
5479      */
5480     public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
5481 
5482     /**
5483      * Use with {@link #getSystemService(String)} to retrieve a
5484      * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
5485      *
5486      * @see #getSystemService(String)
5487      */
5488     public static final String APPWIDGET_SERVICE = "appwidget";
5489 
5490     /**
5491      * Official published name of the (internal) voice interaction manager service.
5492      *
5493      * @hide
5494      * @see #getSystemService(String)
5495      */
5496     public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
5497 
5498     /**
5499      * Official published name of the (internal) autofill service.
5500      *
5501      * @hide
5502      * @see #getSystemService(String)
5503      */
5504     public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
5505 
5506     /**
5507      * Official published name of the (internal) text to speech manager service.
5508      *
5509      * @hide
5510      * @see #getSystemService(String)
5511      */
5512     public static final String TEXT_TO_SPEECH_MANAGER_SERVICE = "texttospeech";
5513 
5514     /**
5515      * Official published name of the content capture service.
5516      *
5517      * @hide
5518      * @see #getSystemService(String)
5519      */
5520     @TestApi
5521     @SuppressLint("ServiceName")  // TODO: This should be renamed to CONTENT_CAPTURE_SERVICE
5522     public static final String CONTENT_CAPTURE_MANAGER_SERVICE = "content_capture";
5523 
5524     /**
5525      * Official published name of the translation service.
5526      *
5527      * @hide
5528      * @see #getSystemService(String)
5529      */
5530     @SystemApi
5531     @SuppressLint("ServiceName")
5532     public static final String TRANSLATION_MANAGER_SERVICE = "translation";
5533 
5534     /**
5535      * Official published name of the translation service which supports ui translation function.
5536      *
5537      * @hide
5538      * @see #getSystemService(String)
5539      */
5540     @SystemApi
5541     public static final String UI_TRANSLATION_SERVICE = "ui_translation";
5542 
5543     /**
5544      * Used for getting content selections and classifications for task snapshots.
5545      *
5546      * @hide
5547      * @see #getSystemService(String)
5548      */
5549     @SystemApi
5550     public static final String CONTENT_SUGGESTIONS_SERVICE = "content_suggestions";
5551 
5552     /**
5553      * Official published name of the app prediction service.
5554      *
5555      * <p><b>NOTE: </b> this service is optional; callers of
5556      * {@code Context.getSystemServiceName(APP_PREDICTION_SERVICE)} should check for {@code null}.
5557      *
5558      * @hide
5559      * @see #getSystemService(String)
5560      */
5561     @SystemApi
5562     public static final String APP_PREDICTION_SERVICE = "app_prediction";
5563 
5564     /**
5565      * Used for reading system-wide, overridable flags.
5566      *
5567      * @hide
5568      */
5569     public static final String FEATURE_FLAGS_SERVICE = "feature_flags";
5570 
5571     /**
5572      * Official published name of the search ui service.
5573      *
5574      * <p><b>NOTE: </b> this service is optional; callers of
5575      * {@code Context.getSystemServiceName(SEARCH_UI_SERVICE)} should check for {@code null}.
5576      *
5577      * @hide
5578      * @see #getSystemService(String)
5579      */
5580     @SystemApi
5581     public static final String SEARCH_UI_SERVICE = "search_ui";
5582 
5583     /**
5584      * Used for getting the smartspace service.
5585      *
5586      * <p><b>NOTE: </b> this service is optional; callers of
5587      * {@code Context.getSystemServiceName(SMARTSPACE_SERVICE)} should check for {@code null}.
5588      *
5589      * @hide
5590      * @see #getSystemService(String)
5591      */
5592     @SystemApi
5593     public static final String SMARTSPACE_SERVICE = "smartspace";
5594 
5595     /**
5596      * Used for getting the contextual search service.
5597      *
5598      * <p><b>NOTE: </b> this service is optional; callers of
5599      * {@code Context.getSystemServiceName(CONTEXTUAL_SEARCH_SERVICE)} must check for {@code null}.
5600      *
5601      * @hide
5602      * @see #getSystemService(String)
5603      */
5604     @SystemApi
5605     public static final String CONTEXTUAL_SEARCH_SERVICE = "contextual_search";
5606 
5607     /**
5608      * Used for getting the cloudsearch service.
5609      *
5610      * <p><b>NOTE: </b> this service is optional; callers of
5611      * {@code Context.getSystemServiceName(CLOUDSEARCH_SERVICE)} should check for {@code null}.
5612      *
5613      * @hide
5614      * @see #getSystemService(String)
5615      */
5616     @SystemApi
5617     public static final String CLOUDSEARCH_SERVICE = "cloudsearch";
5618 
5619     /**
5620      * Use with {@link #getSystemService(String)} to access the
5621      * {@link com.android.server.voiceinteraction.SoundTriggerService}.
5622      *
5623      * @hide
5624      * @see #getSystemService(String)
5625      */
5626     public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
5627 
5628     /**
5629      * Use with {@link #getSystemService(String)} to access the
5630      * {@link com.android.server.soundtrigger_middleware.SoundTriggerMiddlewareService}.
5631      *
5632      * @hide
5633      * @see #getSystemService(String)
5634      */
5635     public static final String SOUND_TRIGGER_MIDDLEWARE_SERVICE = "soundtrigger_middleware";
5636 
5637     /**
5638      * Used for getting the wallpaper effects generation service.
5639      *
5640      * <p><b>NOTE: </b> this service is optional; callers of
5641      * {@code Context.getSystemServiceName(WALLPAPER_EFFECTS_GENERATION_SERVICE)} should check for
5642      * {@code null}.
5643      *
5644      * @hide
5645      * @see #getSystemService(String)
5646      */
5647     @SystemApi
5648     public static final String WALLPAPER_EFFECTS_GENERATION_SERVICE =
5649             "wallpaper_effects_generation";
5650 
5651     /**
5652      * Used to access {@link MusicRecognitionManagerService}.
5653      *
5654      * @hide
5655      * @see #getSystemService(String)
5656      */
5657     @SystemApi
5658     public static final String MUSIC_RECOGNITION_SERVICE = "music_recognition";
5659 
5660     /**
5661      * Official published name of the (internal) permission service.
5662      *
5663      * @see #getSystemService(String)
5664      * @hide
5665      */
5666     @SystemApi
5667     public static final String PERMISSION_SERVICE = "permission";
5668 
5669     /**
5670      * Official published name of the legacy (internal) permission service.
5671      *
5672      * @see #getSystemService(String)
5673      * @hide
5674      */
5675     //@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
5676     public static final String LEGACY_PERMISSION_SERVICE = "legacy_permission";
5677 
5678     /**
5679      * Official published name of the (internal) permission controller service.
5680      *
5681      * @see #getSystemService(String)
5682      * @hide
5683      */
5684     @SystemApi
5685     public static final String PERMISSION_CONTROLLER_SERVICE = "permission_controller";
5686 
5687     /**
5688      * Official published name of the (internal) permission checker service.
5689      *
5690      * @see #getSystemService(String)
5691      * @hide
5692      */
5693     public static final String PERMISSION_CHECKER_SERVICE = "permission_checker";
5694 
5695     /**
5696      * Official published name of the (internal) permission enforcer service.
5697      *
5698      * @see #getSystemService(String)
5699      * @hide
5700      */
5701     public static final String PERMISSION_ENFORCER_SERVICE = "permission_enforcer";
5702 
5703     /**
5704      * Use with {@link #getSystemService(String) to retrieve an
5705      * {@link android.apphibernation.AppHibernationManager}} for
5706      * communicating with the hibernation service.
5707      * @hide
5708      *
5709      * @see #getSystemService(String)
5710      */
5711     @SystemApi
5712     public static final String APP_HIBERNATION_SERVICE = "app_hibernation";
5713 
5714     /**
5715      * Use with {@link #getSystemService(String)} to retrieve an
5716      * {@link android.app.backup.IBackupManager IBackupManager} for communicating
5717      * with the backup mechanism.
5718      * @hide
5719      *
5720      * @see #getSystemService(String)
5721      */
5722     @SystemApi
5723     public static final String BACKUP_SERVICE = "backup";
5724 
5725     /**
5726      * Use with {@link #getSystemService(String)} to retrieve an
5727      * {@link android.content.rollback.RollbackManager} for communicating
5728      * with the rollback manager
5729      *
5730      * @see #getSystemService(String)
5731      * @hide
5732      */
5733     @SystemApi
5734     public static final String ROLLBACK_SERVICE = "rollback";
5735 
5736     /**
5737      * Use with {@link #getSystemService(String)} to retrieve an
5738      * {@link android.scheduling.RebootReadinessManager} for communicating
5739      * with the reboot readiness detector.
5740      *
5741      * @see #getSystemService(String)
5742      * @hide
5743      */
5744     @SystemApi
5745     public static final String REBOOT_READINESS_SERVICE = "reboot_readiness";
5746 
5747     /**
5748      * Use with {@link #getSystemService(String)} to retrieve a
5749      * {@link android.os.DropBoxManager} instance for recording
5750      * diagnostic logs.
5751      * @see #getSystemService(String)
5752      */
5753     public static final String DROPBOX_SERVICE = "dropbox";
5754 
5755     /**
5756      * System service name for BackgroundInstallControlService. This service supervises the MBAs
5757      * on device and provides the related metadata of the MBAs.
5758      *
5759      * @hide
5760      */
5761     @SuppressLint("ServiceName")
5762     public static final String BACKGROUND_INSTALL_CONTROL_SERVICE = "background_install_control";
5763 
5764     /**
5765      * System service name for BinaryTransparencyService. This is used to retrieve measurements
5766      * pertaining to various pre-installed and system binaries on device for the purposes of
5767      * providing transparency to the user.
5768      *
5769      * @hide
5770      */
5771     @SuppressLint("ServiceName")
5772     public static final String BINARY_TRANSPARENCY_SERVICE = "transparency";
5773 
5774     /**
5775      * System service name for IntrusionDetectionService.
5776      * The service manages the intrusion detection info on device.
5777      * @hide
5778      */
5779     @FlaggedApi(android.security.Flags.FLAG_AFL_API)
5780     public static final String INTRUSION_DETECTION_SERVICE = "intrusion_detection";
5781 
5782     /**
5783      * System service name for the DeviceIdleManager.
5784      * @see #getSystemService(String)
5785      * @hide
5786      */
5787     @TestApi
5788     @SuppressLint("ServiceName")  // TODO: This should be renamed to DEVICE_IDLE_SERVICE
5789     public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
5790 
5791     /**
5792      * System service name for the PowerWhitelistManager.
5793      *
5794      * @see #getSystemService(String)
5795      * @hide
5796      */
5797     @TestApi
5798     @Deprecated
5799     @SuppressLint("ServiceName")
5800     public static final String POWER_WHITELIST_MANAGER = "power_whitelist";
5801 
5802     /**
5803      * System service name for the PowerExemptionManager.
5804      *
5805      * @see #getSystemService(String)
5806      * @hide
5807      */
5808     @TestApi
5809     public static final String POWER_EXEMPTION_SERVICE = "power_exemption";
5810 
5811     /**
5812      * Use with {@link #getSystemService(String)} to retrieve a
5813      * {@link android.app.admin.DevicePolicyManager} for working with global
5814      * device policy management.
5815      *
5816      * @see #getSystemService(String)
5817      */
5818     public static final String DEVICE_POLICY_SERVICE = "device_policy";
5819 
5820     /**
5821      * Use with {@link #getSystemService(String)} to retrieve a
5822      * {@link android.app.UiModeManager} for controlling UI modes.
5823      *
5824      * @see #getSystemService(String)
5825      */
5826     public static final String UI_MODE_SERVICE = "uimode";
5827 
5828     /**
5829      * Use with {@link #getSystemService(String)} to retrieve a
5830      * {@link android.app.DownloadManager} for requesting HTTP downloads.
5831      *
5832      * @see #getSystemService(String)
5833      */
5834     public static final String DOWNLOAD_SERVICE = "download";
5835 
5836     /**
5837      * Use with {@link #getSystemService(String)} to retrieve a
5838      * {@link android.os.BatteryManager} for managing battery state.
5839      *
5840      * @see #getSystemService(String)
5841      */
5842     public static final String BATTERY_SERVICE = "batterymanager";
5843 
5844     /**
5845      * Use with {@link #getSystemService(String)} to retrieve a
5846      * {@link android.nfc.NfcManager} for using NFC.
5847      *
5848      * @see #getSystemService(String)
5849      */
5850     public static final String NFC_SERVICE = "nfc";
5851 
5852     /**
5853      * Use with {@link #getSystemService(String)} to retrieve a
5854      * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
5855      *
5856      * @see #getSystemService(String)
5857      */
5858     public static final String BLUETOOTH_SERVICE = "bluetooth";
5859 
5860     /**
5861      * Use with {@link #getSystemService(String)} to retrieve a
5862      * {@link android.net.sip.SipManager} for accessing the SIP related service.
5863      *
5864      * @see #getSystemService(String)
5865      */
5866     /** @hide */
5867     public static final String SIP_SERVICE = "sip";
5868 
5869     /**
5870      * Use with {@link #getSystemService(String)} to retrieve a {@link
5871      * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
5872      * and for controlling this device's behavior as a USB device.
5873      *
5874      * @see #getSystemService(String)
5875      * @see android.hardware.usb.UsbManager
5876      */
5877     public static final String USB_SERVICE = "usb";
5878 
5879     /**
5880      * Use with {@link #getSystemService(String)} to retrieve a {@link
5881      * Use with {@link #getSystemService} to retrieve a {@link
5882      * android.debug.AdbManager} for access to ADB debug functions.
5883      *
5884      * @see #getSystemService(String)
5885      * @see android.debug.AdbManager
5886      *
5887      * @hide
5888      */
5889     public static final String ADB_SERVICE = "adb";
5890 
5891     /**
5892      * Use with {@link #getSystemService(String)} to retrieve a {@link
5893      * android.hardware.SerialManager} for access to serial ports.
5894      *
5895      * @see #getSystemService(String)
5896      * @see android.hardware.SerialManager
5897      *
5898      * @hide
5899      */
5900     public static final String SERIAL_SERVICE = "serial";
5901 
5902     /**
5903      * Use with {@link #getSystemService(String)} to retrieve a
5904      * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
5905      * HDMI-CEC protocol.
5906      *
5907      * @see #getSystemService(String)
5908      * @see android.hardware.hdmi.HdmiControlManager
5909      * @hide
5910      */
5911     @SystemApi
5912     public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
5913 
5914     /**
5915      * Use with {@link #getSystemService(String)} to retrieve a
5916      * {@link android.hardware.input.InputManager} for interacting with input devices.
5917      *
5918      * @see #getSystemService(String)
5919      * @see android.hardware.input.InputManager
5920      */
5921     public static final String INPUT_SERVICE = "input";
5922 
5923     /**
5924      * Use with {@link #getSystemService(String)} to retrieve a
5925      * {@link android.hardware.display.DisplayManager} for interacting with display devices.
5926      *
5927      * @see #getSystemService(String)
5928      * @see android.hardware.display.DisplayManager
5929      */
5930     public static final String DISPLAY_SERVICE = "display";
5931 
5932     /**
5933      * Use with {@link #getSystemService(String)} to retrieve a
5934      * {@link android.hardware.display.ColorDisplayManager} for controlling color transforms.
5935      *
5936      * @see #getSystemService(String)
5937      * @see android.hardware.display.ColorDisplayManager
5938      * @hide
5939      */
5940     public static final String COLOR_DISPLAY_SERVICE = "color_display";
5941 
5942     /**
5943      * Use with {@link #getSystemService(String)} to retrieve a
5944      * {@link android.os.UserManager} for managing users on devices that support multiple users.
5945      *
5946      * @see #getSystemService(String)
5947      * @see android.os.UserManager
5948      */
5949     public static final String USER_SERVICE = "user";
5950 
5951     /**
5952      * Use with {@link #getSystemService(String)} to retrieve a
5953      * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
5954      * profiles of a user.
5955      *
5956      * @see #getSystemService(String)
5957      * @see android.content.pm.LauncherApps
5958      */
5959     public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
5960 
5961     /**
5962      * Use with {@link #getSystemService(String)} to retrieve a
5963      * {@link android.content.RestrictionsManager} for retrieving application restrictions
5964      * and requesting permissions for restricted operations.
5965      * @see #getSystemService(String)
5966      * @see android.content.RestrictionsManager
5967      */
5968     public static final String RESTRICTIONS_SERVICE = "restrictions";
5969 
5970     /**
5971      * Use with {@link #getSystemService(String)} to retrieve a
5972      * {@link android.app.AppOpsManager} for tracking application operations
5973      * on the device.
5974      *
5975      * @see #getSystemService(String)
5976      * @see android.app.AppOpsManager
5977      */
5978     public static final String APP_OPS_SERVICE = "appops";
5979 
5980     /**
5981      * Use with {@link #getSystemService(String)} to retrieve a {@link android.app.role.RoleManager}
5982      * for managing roles.
5983      *
5984      * @see #getSystemService(String)
5985      * @see android.app.role.RoleManager
5986      */
5987     public static final String ROLE_SERVICE = "role";
5988 
5989     /**
5990      * Use with {@link #getSystemService(String)} to retrieve a
5991      * {@link android.hardware.camera2.CameraManager} for interacting with
5992      * camera devices.
5993      *
5994      * @see #getSystemService(String)
5995      * @see android.hardware.camera2.CameraManager
5996      */
5997     public static final String CAMERA_SERVICE = "camera";
5998 
5999     /**
6000      * {@link android.print.PrintManager} for printing and managing
6001      * printers and print tasks.
6002      *
6003      * @see #getSystemService(String)
6004      * @see android.print.PrintManager
6005      */
6006     public static final String PRINT_SERVICE = "print";
6007 
6008     /**
6009      * Use with {@link #getSystemService(String)} to retrieve a
6010      * {@link android.companion.CompanionDeviceManager} for managing companion devices
6011      *
6012      * @see #getSystemService(String)
6013      * @see android.companion.CompanionDeviceManager
6014      */
6015     public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
6016 
6017     /**
6018      * Use with {@link #getSystemService(String)} to retrieve a
6019      * {@link android.companion.virtual.VirtualDeviceManager} for managing virtual devices.
6020      *
6021      * On devices without {@link PackageManager#FEATURE_COMPANION_DEVICE_SETUP}
6022      * system feature the {@link #getSystemService(String)} will return {@code null}.
6023      *
6024      * @see #getSystemService(String)
6025      * @see android.companion.virtual.VirtualDeviceManager
6026      */
6027     @SuppressLint("ServiceName")
6028     public static final String VIRTUAL_DEVICE_SERVICE = "virtualdevice";
6029 
6030     /**
6031      * Use with {@link #getSystemService(String)} to retrieve a
6032      * {@link android.hardware.ConsumerIrManager} for transmitting infrared
6033      * signals from the device.
6034      *
6035      * @see #getSystemService(String)
6036      * @see android.hardware.ConsumerIrManager
6037      */
6038     public static final String CONSUMER_IR_SERVICE = "consumer_ir";
6039 
6040     /**
6041      * {@link android.app.trust.TrustManager} for managing trust agents.
6042      * @see #getSystemService(String)
6043      * @see android.app.trust.TrustManager
6044      * @hide
6045      */
6046     public static final String TRUST_SERVICE = "trust";
6047 
6048     /**
6049      * Use with {@link #getSystemService(String)} to retrieve a
6050      * {@link android.media.tv.interactive.TvInteractiveAppManager} for interacting with TV
6051      * interactive applications on the device.
6052      *
6053      * @see #getSystemService(String)
6054      * @see android.media.tv.interactive.TvInteractiveAppManager
6055      */
6056     public static final String TV_INTERACTIVE_APP_SERVICE = "tv_interactive_app";
6057 
6058     /**
6059      * Use with {@link #getSystemService(String)} to retrieve a
6060      * {@link android.media.tv.TvInputManager} for interacting with TV inputs
6061      * on the device.
6062      *
6063      * @see #getSystemService(String)
6064      * @see android.media.tv.TvInputManager
6065      */
6066     public static final String TV_INPUT_SERVICE = "tv_input";
6067 
6068     /**
6069      * Use with {@link #getSystemService(String)} to retrieve a
6070      * {@link android.media.tv.ad.TvAdManager} for interacting with TV client-side advertisement
6071      * services on the device.
6072      *
6073      * @see #getSystemService(String)
6074      * @see android.media.tv.ad.TvAdManager
6075      */
6076     @FlaggedApi(android.media.tv.flags.Flags.FLAG_ENABLE_AD_SERVICE_FW)
6077     public static final String TV_AD_SERVICE = "tv_ad";
6078 
6079     /**
6080      * Use with {@link #getSystemService(String)} to retrieve a
6081      * {@link android.media.tv.TunerResourceManager} for interacting with TV
6082      * tuner resources on the device.
6083      *
6084      * @see #getSystemService(String)
6085      * @see android.media.tv.TunerResourceManager
6086      * @hide
6087      */
6088     public static final String TV_TUNER_RESOURCE_MGR_SERVICE = "tv_tuner_resource_mgr";
6089 
6090     /**
6091      * {@link android.net.NetworkScoreManager} for managing network scoring.
6092      * @see #getSystemService(String)
6093      * @see android.net.NetworkScoreManager
6094      * @deprecated see
6095      * <a href="{@docRoot}guide/topics/connectivity/wifi-suggest">Wi-Fi Suggestion API</a>
6096      * for alternative API to propose WiFi networks.
6097      * @hide
6098      */
6099     @SystemApi
6100     @Deprecated
6101     public static final String NETWORK_SCORE_SERVICE = "network_score";
6102 
6103     /**
6104      * Use with {@link #getSystemService(String)} to retrieve a {@link
6105      * android.app.usage.UsageStatsManager} for querying device usage stats.
6106      *
6107      * @see #getSystemService(String)
6108      * @see android.app.usage.UsageStatsManager
6109      */
6110     public static final String USAGE_STATS_SERVICE = "usagestats";
6111 
6112     /**
6113      * Use with {@link #getSystemService(String)} to retrieve a {@link
6114      * android.app.job.JobScheduler} instance for managing occasional
6115      * background tasks.
6116      * @see #getSystemService(String)
6117      * @see android.app.job.JobScheduler
6118      */
6119     public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
6120 
6121     /**
6122      * Use with {@link #getSystemService(String)} to retrieve a {@link
6123      * android.service.persistentdata.PersistentDataBlockManager} instance
6124      * for interacting with a storage device that lives across factory resets.
6125      *
6126      * @see #getSystemService(String)
6127      * @see android.service.persistentdata.PersistentDataBlockManager
6128      */
6129     @FlaggedApi(android.security.Flags.FLAG_FRP_ENFORCEMENT)
6130     public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
6131 
6132     /**
6133      * Use with {@link #getSystemService(String)} to retrieve a {@link
6134      * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
6135      *
6136      * @see #getSystemService(String)
6137      * @see android.service.oemlock.OemLockManager
6138      * @hide
6139      */
6140     @SystemApi
6141     public static final String OEM_LOCK_SERVICE = "oem_lock";
6142 
6143     /**
6144      * Use with {@link #getSystemService(String)} to retrieve a {@link
6145      * android.media.projection.MediaProjectionManager} instance for managing
6146      * media projection sessions.
6147      * @see #getSystemService(String)
6148      * @see android.media.projection.MediaProjectionManager
6149      */
6150     public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
6151 
6152     /**
6153      * Use with {@link #getSystemService(String)} to retrieve a
6154      * {@link android.media.midi.MidiManager} for accessing the MIDI service.
6155      *
6156      * @see #getSystemService(String)
6157      */
6158     public static final String MIDI_SERVICE = "midi";
6159 
6160 
6161     /**
6162      * Use with {@link #getSystemService(String)} to retrieve a
6163      * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
6164      *
6165      * @see #getSystemService(String)
6166      * @hide
6167      */
6168     public static final String RADIO_SERVICE = "broadcastradio";
6169 
6170     /**
6171      * Use with {@link #getSystemService(String)} to retrieve a
6172      * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
6173      *
6174      * @see #getSystemService(String)
6175      */
6176     public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
6177 
6178     /**
6179      * Use with {@link #getSystemService(String)} to retrieve a
6180      * {@link android.os.ThermalService} for accessing the thermal service.
6181      *
6182      * @see #getSystemService(String)
6183      * @hide
6184      */
6185     public static final String THERMAL_SERVICE = "thermalservice";
6186 
6187     /**
6188      * Use with {@link #getSystemService(String)} to retrieve a
6189      * {@link android.os.PerformanceHintManager} for accessing the performance hinting service.
6190      *
6191      * @see #getSystemService(String)
6192      */
6193     public static final String PERFORMANCE_HINT_SERVICE = "performance_hint";
6194 
6195     /**
6196      * Use with {@link #getSystemService(String)} to retrieve a
6197      * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
6198      *
6199      * @see #getSystemService(String)
6200      * @see android.content.pm.ShortcutManager
6201      */
6202     public static final String SHORTCUT_SERVICE = "shortcut";
6203 
6204     /**
6205      * Use with {@link #getSystemService(String)} to retrieve a {@link
6206      * android.hardware.location.ContextHubManager} for accessing context hubs.
6207      *
6208      * @see #getSystemService(String)
6209      * @see android.hardware.location.ContextHubManager
6210      *
6211      * @hide
6212      */
6213     @SystemApi
6214     public static final String CONTEXTHUB_SERVICE = "contexthub";
6215 
6216     /**
6217      * Use with {@link #getSystemService(String)} to retrieve a
6218      * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
6219      * memory, etc) metrics.
6220      *
6221      * @see #getSystemService(String)
6222      */
6223     public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
6224 
6225     /**
6226      * Gatekeeper Service.
6227      * @hide
6228      */
6229     public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
6230 
6231     /**
6232      * Service defining the policy for access to device identifiers.
6233      * @hide
6234      */
6235     public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
6236 
6237     /**
6238      * Service to report a system health "incident"
6239      * @hide
6240      */
6241     public static final String INCIDENT_SERVICE = "incident";
6242 
6243     /**
6244      * Service to assist incidentd and dumpstated in reporting status to the user
6245      * and in confirming authorization to take an incident report or bugreport
6246      * @hide
6247      */
6248     public static final String INCIDENT_COMPANION_SERVICE = "incidentcompanion";
6249 
6250     /**
6251      * Service to assist {@link android.app.StatsManager} that lives in system server.
6252      * @hide
6253      */
6254     public static final String STATS_MANAGER_SERVICE = "statsmanager";
6255 
6256     /**
6257      * Service to assist statsd in obtaining general stats.
6258      * @hide
6259      */
6260     public static final String STATS_COMPANION_SERVICE = "statscompanion";
6261 
6262     /**
6263      * Service to assist statsd in logging atoms from bootstrap atoms.
6264      * @hide
6265      */
6266     public static final String STATS_BOOTSTRAP_ATOM_SERVICE = "statsbootstrap";
6267 
6268     /**
6269      * Use with {@link #getSystemService(String)} to retrieve an {@link android.app.StatsManager}.
6270      * @hide
6271      */
6272     @SystemApi
6273     public static final String STATS_MANAGER = "stats";
6274 
6275     /**
6276      * Use with {@link android.os.ServiceManager.getService()} to retrieve a
6277      * {@link IPlatformCompat} IBinder for communicating with the platform compat service.
6278      * @hide
6279      */
6280     public static final String PLATFORM_COMPAT_SERVICE = "platform_compat";
6281 
6282     /**
6283      * Use with {@link android.os.ServiceManager.getService()} to retrieve a
6284      * {@link IPlatformCompatNative} IBinder for native code communicating with the platform compat
6285      * service.
6286      * @hide
6287      */
6288     public static final String PLATFORM_COMPAT_NATIVE_SERVICE = "platform_compat_native";
6289 
6290     /**
6291      * Service to capture a bugreport.
6292      * @see #getSystemService(String)
6293      * @see android.os.BugreportManager
6294      */
6295     public static final String BUGREPORT_SERVICE = "bugreport";
6296 
6297     /**
6298      * Use with {@link #getSystemService(String)} to retrieve a {@link
6299      * android.content.om.OverlayManager} for managing overlay packages.
6300      *
6301      * @see #getSystemService(String)
6302      * @see android.content.om.OverlayManager
6303      */
6304     public static final String OVERLAY_SERVICE = "overlay";
6305 
6306     /**
6307      * Use with {@link #getSystemService(String)} to manage resources.
6308      *
6309      * @see #getSystemService(String)
6310      * @see com.android.server.resources.ResourcesManagerService
6311      * @hide
6312      */
6313     public static final String RESOURCES_SERVICE = "resources";
6314 
6315     /**
6316      * Use with {@link #getSystemService(String)} to retrieve a
6317      * {android.os.IIdmap2} for managing idmap files (used by overlay
6318      * packages).
6319      *
6320      * @see #getSystemService(String)
6321      * @hide
6322      */
6323     public static final String IDMAP_SERVICE = "idmap";
6324 
6325     /**
6326      * Use with {@link #getSystemService(String)} to retrieve a
6327      * {@link VrManager} for accessing the VR service.
6328      *
6329      * @see #getSystemService(String)
6330      * @hide
6331      */
6332     @SystemApi
6333     public static final String VR_SERVICE = "vrmanager";
6334 
6335     /**
6336      * Use with {@link #getSystemService(String)} to retrieve a
6337      * {@link android.content.pm.CrossProfileApps} for cross profile operations.
6338      *
6339      * @see #getSystemService(String)
6340      */
6341     public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
6342 
6343     /**
6344      * Use with {@link #getSystemService} to retrieve a
6345      * {@link android.se.omapi.ISecureElementService}
6346      * for accessing the SecureElementService.
6347      *
6348      * @hide
6349      */
6350     @SystemApi
6351     public static final String SECURE_ELEMENT_SERVICE = "secure_element";
6352 
6353     /**
6354      * Use with {@link #getSystemService(String)} to retrieve a
6355      * {@link android.app.timedetector.TimeDetector}.
6356      * @hide
6357      *
6358      * @see #getSystemService(String)
6359      */
6360     public static final String TIME_DETECTOR_SERVICE = "time_detector";
6361 
6362     /**
6363      * Use with {@link #getSystemService(String)} to retrieve a
6364      * {@link android.app.timezonedetector.TimeZoneDetector}.
6365      * @hide
6366      *
6367      * @see #getSystemService(String)
6368      */
6369     public static final String TIME_ZONE_DETECTOR_SERVICE = "time_zone_detector";
6370 
6371     /**
6372      * Use with {@link #getSystemService(String)} to retrieve a {@link TimeManager}.
6373      * @hide
6374      *
6375      * @see #getSystemService(String)
6376      */
6377     @SystemApi
6378     @SuppressLint("ServiceName")
6379     public static final String TIME_MANAGER_SERVICE = "time_manager";
6380 
6381     /**
6382      * Binder service name for {@link AppBindingService}.
6383      * @hide
6384      */
6385     public static final String APP_BINDING_SERVICE = "app_binding";
6386 
6387     /**
6388      * Use with {@link #getSystemService(String)} to retrieve an
6389      * {@link android.telephony.ims.ImsManager}.
6390      */
6391     public static final String TELEPHONY_IMS_SERVICE = "telephony_ims";
6392 
6393     /**
6394      * Use with {@link #getSystemService(String)} to retrieve an
6395      * {@link android.os.SystemConfigManager}.
6396      * @hide
6397      */
6398     @SystemApi
6399     public static final String SYSTEM_CONFIG_SERVICE = "system_config";
6400 
6401     /**
6402      * Use with {@link #getSystemService(String)} to retrieve an
6403      * {@link android.telephony.ims.RcsMessageManager}.
6404      * @hide
6405      */
6406     public static final String TELEPHONY_RCS_MESSAGE_SERVICE = "ircsmessage";
6407 
6408      /**
6409      * Use with {@link #getSystemService(String)} to retrieve an
6410      * {@link android.os.image.DynamicSystemManager}.
6411      * @hide
6412      */
6413     public static final String DYNAMIC_SYSTEM_SERVICE = "dynamic_system";
6414 
6415     /**
6416      * Use with {@link #getSystemService(String)} to retrieve a {@link
6417      * android.app.blob.BlobStoreManager} for contributing and accessing data blobs
6418      * from the blob store maintained by the system.
6419      *
6420      * @see #getSystemService(String)
6421      * @see android.app.blob.BlobStoreManager
6422      */
6423     public static final String BLOB_STORE_SERVICE = "blob_store";
6424 
6425     /**
6426      * Use with {@link #getSystemService(String)} to retrieve an
6427      * {@link TelephonyRegistryManager}.
6428      * @hide
6429      */
6430     public static final String TELEPHONY_REGISTRY_SERVICE = "telephony_registry";
6431 
6432     /**
6433      * Use with {@link #getSystemService(String)} to retrieve an
6434      * {@link android.os.BatteryStatsManager}.
6435      * @hide
6436      */
6437     @SystemApi
6438     @SuppressLint("ServiceName")
6439     public static final String BATTERY_STATS_SERVICE = "batterystats";
6440 
6441     /**
6442      * Use with {@link #getSystemService(String)} to retrieve an
6443      * {@link android.app.appsearch.AppSearchManager} for
6444      * indexing and querying app data managed by the system.
6445      *
6446      * @see #getSystemService(String)
6447      */
6448     public static final String APP_SEARCH_SERVICE = "app_search";
6449 
6450     /**
6451      * Use with {@link #getSystemService(String)} to retrieve an
6452      * {@link AppFunctionManager} for
6453      * executing app functions.
6454      *
6455      * @see #getSystemService(String)
6456      */
6457     @FlaggedApi(FLAG_ENABLE_APP_FUNCTION_MANAGER)
6458     public static final String APP_FUNCTION_SERVICE = "app_function";
6459 
6460     /**
6461      * Use with {@link #getSystemService(String)} to retrieve an
6462      * {@link android.content.integrity.AppIntegrityManager}.
6463      * @hide
6464      */
6465     @SystemApi
6466     public static final String APP_INTEGRITY_SERVICE = "app_integrity";
6467 
6468     /**
6469      * Use with {@link #getSystemService(String)} to retrieve an
6470      * {@link android.content.pm.DataLoaderManager}.
6471      * @hide
6472      */
6473     public static final String DATA_LOADER_MANAGER_SERVICE = "dataloader_manager";
6474 
6475     /**
6476      * Use with {@link #getSystemService(String)} to retrieve an
6477      * {@link android.os.incremental.IncrementalManager}.
6478      * @hide
6479      */
6480     public static final String INCREMENTAL_SERVICE = "incremental";
6481 
6482     /**
6483      * Use with {@link #getSystemService(String)} to retrieve an
6484      * {@link android.security.attestationverification.AttestationVerificationManager}.
6485      * @see #getSystemService(String)
6486      * @see android.security.attestationverification.AttestationVerificationManager
6487      * @hide
6488      */
6489     public static final String ATTESTATION_VERIFICATION_SERVICE = "attestation_verification";
6490 
6491     /**
6492      * Use with {@link #getSystemService(String)} to retrieve an
6493      * {@link android.security.advancedprotection.AdvancedProtectionManager}
6494      * @see #getSystemService(String)
6495      * @see android.security.advancedprotection.AdvancedProtectionManager
6496      */
6497     @FlaggedApi(android.security.Flags.FLAG_AAPM_API)
6498     public static final String ADVANCED_PROTECTION_SERVICE = "advanced_protection";
6499 
6500     /**
6501      * Use with {@link #getSystemService(String)} to retrieve an
6502      * {@link android.security.FileIntegrityManager}.
6503      * @see #getSystemService(String)
6504      * @see android.security.FileIntegrityManager
6505      */
6506     public static final String FILE_INTEGRITY_SERVICE = "file_integrity";
6507 
6508     /**
6509      * Binder service for remote key provisioning.
6510      *
6511      * @see android.frameworks.rkp.IRemoteProvisioning
6512      * @hide
6513      */
6514     public static final String REMOTE_PROVISIONING_SERVICE = "remote_provisioning";
6515 
6516     /**
6517      * Use with {@link #getSystemService(String)} to retrieve a
6518      * {@link android.hardware.lights.LightsManager} for controlling device lights.
6519      *
6520      * @see #getSystemService(String)
6521      * @hide
6522      */
6523     public static final String LIGHTS_SERVICE = "lights";
6524 
6525     /**
6526      * Use with {@link #getSystemService(String)} to retrieve a
6527      * {@link android.uwb.UwbManager}.
6528      *
6529      * @see #getSystemService(String)
6530      * @hide
6531      */
6532     @SystemApi
6533     public static final String UWB_SERVICE = "uwb";
6534 
6535     /**
6536      * Use with {@link #getSystemService(String)} to retrieve a
6537      * {@link android.ranging.RangingManager}.
6538      *
6539      * @see #getSystemService(String)
6540      * @hide
6541      */
6542     @FlaggedApi(com.android.ranging.flags.Flags.FLAG_RANGING_STACK_ENABLED)
6543     @SystemApi
6544     public static final String RANGING_SERVICE = "ranging";
6545 
6546     /**
6547      * Use with {@link #getSystemService(String)} to retrieve a
6548      * {@link android.app.DreamManager} for controlling Dream states.
6549      *
6550      * @see #getSystemService(String)
6551 
6552      * @hide
6553      */
6554     @TestApi
6555     public static final String DREAM_SERVICE = "dream";
6556 
6557     /**
6558      * Use with {@link #getSystemService(String)} to retrieve a
6559      * {@link android.telephony.SmsManager} for accessing Sms functionality.
6560      *
6561      * @see #getSystemService(String)
6562 
6563      * @hide
6564      */
6565     public static final String SMS_SERVICE = "sms";
6566 
6567     /**
6568      * Use with {@link #getSystemService(String)} to access a {@link PeopleManager} to interact
6569      * with your published conversations.
6570      *
6571      * @see #getSystemService(String)
6572      */
6573     public static final String PEOPLE_SERVICE = "people";
6574 
6575     /**
6576      * Use with {@link #getSystemService(String)} to access device state service.
6577      *
6578      * @see #getSystemService(String)
6579      * @hide
6580      */
6581     public static final String DEVICE_STATE_SERVICE = "device_state";
6582 
6583     /**
6584      * Use with {@link #getSystemService(String)} to retrieve a
6585      * {@link android.media.metrics.MediaMetricsManager} for interacting with media metrics
6586      * on the device.
6587      *
6588      * @see #getSystemService(String)
6589      * @see android.media.metrics.MediaMetricsManager
6590      */
6591     public static final String MEDIA_METRICS_SERVICE = "media_metrics";
6592 
6593     /**
6594      * Use with {@link #getSystemService(String)} to access system speech recognition service.
6595      *
6596      * @see #getSystemService(String)
6597      * @hide
6598     */
6599     public static final String SPEECH_RECOGNITION_SERVICE = "speech_recognition";
6600 
6601     /**
6602      * Use with {@link #getSystemService(String)} to retrieve a
6603      * {@link GameManager}.
6604      *
6605      * @see #getSystemService(String)
6606      */
6607     public static final String GAME_SERVICE = "game";
6608 
6609     /**
6610      * Use with {@link #getSystemService(String)} to access
6611      * {@link android.content.pm.verify.domain.DomainVerificationManager} to retrieve approval and
6612      * user state for declared web domains.
6613      *
6614      * @see #getSystemService(String)
6615      * @see android.content.pm.verify.domain.DomainVerificationManager
6616      */
6617     public static final String DOMAIN_VERIFICATION_SERVICE = "domain_verification";
6618 
6619     /**
6620      * Use with {@link #getSystemService(String)} to access
6621      * {@link android.view.displayhash.DisplayHashManager} to handle display hashes.
6622      *
6623      * @see #getSystemService(String)
6624      */
6625     public static final String DISPLAY_HASH_SERVICE = "display_hash";
6626 
6627     /**
6628      * Use with {@link #getSystemService(String)} to retrieve a
6629      * {@link android.app.LocaleManager}.
6630      *
6631      * @see #getSystemService(String)
6632      */
6633     public static final String LOCALE_SERVICE = "locale";
6634 
6635     /**
6636      * Use with {@link #getSystemService(String)} to retrieve a {@link
6637      * android.safetycenter.SafetyCenterManager} instance for interacting with the safety center.
6638      *
6639      * @see #getSystemService(String)
6640      * @see android.safetycenter.SafetyCenterManager
6641      * @hide
6642      */
6643     @SystemApi
6644     public static final String SAFETY_CENTER_SERVICE = "safety_center";
6645 
6646     /**
6647      * Use with {@link #getSystemService(String)} to retrieve a
6648      * {@link android.nearby.NearbyManager} to discover nearby devices.
6649      *
6650      * @see #getSystemService(String)
6651      * @see android.nearby.NearbyManager
6652      * @hide
6653      */
6654     @SystemApi
6655     public static final String NEARBY_SERVICE = "nearby";
6656 
6657     /**
6658      * Use with {@link #getSystemService(String)} to retrieve a
6659      * {@link android.remoteauth.RemoteAuthManager} to discover,
6660      * register and authenticate via remote authenticator  devices.
6661      *
6662      * @see #getSystemService(String)
6663      * @see android.remoteauth.RemoteAuthManager
6664      * @hide
6665      */
6666     public static final String REMOTE_AUTH_SERVICE = "remote_auth";
6667 
6668     /**
6669      * Use with {@link #getSystemService(String)} to retrieve a
6670      * {@link android.app.ambientcontext.AmbientContextManager}.
6671      *
6672      * @see #getSystemService(String)
6673      * @see AmbientContextManager
6674      * @hide
6675      */
6676     @SystemApi
6677     public static final String AMBIENT_CONTEXT_SERVICE = "ambient_context";
6678 
6679     /**
6680      * Use with {@link #getSystemService(String)} to retrieve a
6681      * {@link android.app.wearable.WearableSensingManager}.
6682      *
6683      * @see #getSystemService(String)
6684      * @see WearableSensingManager
6685      * @hide
6686      */
6687     @SystemApi
6688     public static final String WEARABLE_SENSING_SERVICE = "wearable_sensing";
6689 
6690 
6691     /**
6692      * Use with {@link #getSystemService(String)} to retrieve a
6693      * {@link android.app.ondeviceintelligence.OnDeviceIntelligenceManager}.
6694      *
6695      * @see #getSystemService(String)
6696      * @see OnDeviceIntelligenceManager
6697      * @hide
6698      */
6699     @SystemApi
6700     @FlaggedApi(android.app.ondeviceintelligence.flags.Flags.FLAG_ENABLE_ON_DEVICE_INTELLIGENCE)
6701     public static final String ON_DEVICE_INTELLIGENCE_SERVICE = "on_device_intelligence";
6702 
6703     /**
6704      * Use with {@link #getSystemService(String)} to retrieve a
6705      * {@link android.health.connect.HealthConnectManager}.
6706      *
6707      * @see #getSystemService(String)
6708      * @see android.health.connect.HealthConnectManager
6709      */
6710     public static final String HEALTHCONNECT_SERVICE = "healthconnect";
6711 
6712     /**
6713      * Use with {@link #getSystemService(String)} to retrieve a
6714      * {@link android.credentials.CredentialManager} to authenticate a user to your app.
6715      *
6716      * @see #getSystemService(String)
6717      * @see CredentialManager
6718      */
6719     public static final String CREDENTIAL_SERVICE = "credential";
6720 
6721     /**
6722      * Use with {@link #getSystemService(String)} to retrieve a
6723      * {@link android.devicelock.DeviceLockManager}.
6724      *
6725      * @see #getSystemService(String)
6726      */
6727     public static final String DEVICE_LOCK_SERVICE = "device_lock";
6728 
6729     /**
6730      * Use with {@link #getSystemService(String)} to retrieve a
6731      * {@link android.system.virtualmachine.VirtualMachineManager}.
6732      *
6733      * <p>On devices without {@link PackageManager#FEATURE_VIRTUALIZATION_FRAMEWORK} system feature
6734      * the {@link #getSystemService(String)} will return {@code null}.
6735      *
6736      * @see #getSystemService(String)
6737      * @see android.system.virtualmachine.VirtualMachineManager
6738      * @hide
6739      */
6740     @SystemApi
6741     public static final String VIRTUALIZATION_SERVICE = "virtualization";
6742 
6743     /**
6744      * Use with {@link #getSystemService(String)} to retrieve a
6745      * {@link GrammaticalInflectionManager}.
6746      *
6747      * @see #getSystemService(String)
6748      */
6749     public static final String GRAMMATICAL_INFLECTION_SERVICE = "grammatical_inflection";
6750 
6751     /**
6752      * Use with {@link #getSystemService(String)} to retrieve a
6753      * {@link android.telephony.satellite.SatelliteManager} for accessing satellite functionality.
6754      *
6755      * @see #getSystemService(String)
6756      * @see android.telephony.satellite.SatelliteManager
6757      */
6758     @FlaggedApi(com.android.internal.telephony.flags.Flags.FLAG_SATELLITE_STATE_CHANGE_LISTENER)
6759     public static final String SATELLITE_SERVICE = "satellite";
6760 
6761     /**
6762      * Use with {@link #getSystemService(String)} to retrieve a
6763      * {@link android.net.wifi.sharedconnectivity.app.SharedConnectivityManager} for accessing
6764      * shared connectivity services.
6765      *
6766      * @see #getSystemService(String)
6767      * @see android.net.wifi.sharedconnectivity.app.SharedConnectivityManager
6768      * @hide
6769      */
6770     @SystemApi
6771     public static final String SHARED_CONNECTIVITY_SERVICE = "shared_connectivity";
6772 
6773     /**
6774      * Use with {@link #getSystemService(String)} to retrieve a
6775      * {@link android.os.SecurityStateManager} for accessing the security state manager service.
6776      *
6777      * @see #getSystemService(String)
6778      * @see android.os.SecurityStateManager
6779      */
6780     @FlaggedApi(Flags.FLAG_SECURITY_STATE_SERVICE)
6781     public static final String SECURITY_STATE_SERVICE = "security_state";
6782 
6783     /**
6784      * Use with {@link #getSystemService(String)} to retrieve an
6785      * {@link android.app.ecm.EnhancedConfirmationManager}.
6786      *
6787      * @see #getSystemService(String)
6788      * @see android.app.ecm.EnhancedConfirmationManager
6789      * @hide
6790      */
6791     @FlaggedApi(android.permission.flags.Flags.FLAG_ENHANCED_CONFIRMATION_MODE_APIS_ENABLED)
6792     @SystemApi
6793     public static final String ECM_ENHANCED_CONFIRMATION_SERVICE = "ecm_enhanced_confirmation";
6794 
6795     /**
6796      * Service to protect sensitive content during screen share.
6797      * @hide
6798      */
6799     public static final String SENSITIVE_CONTENT_PROTECTION_SERVICE =
6800             "sensitive_content_protection_service";
6801 
6802     /**
6803      * Use with {@link #getSystemService(String)} to retrieve a
6804      * {@link E2eeContactKeysManager} to managing contact keys.
6805      *
6806      * @see #getSystemService(String)
6807      * @see E2eeContactKeysManager
6808      */
6809     @FlaggedApi(android.provider.Flags.FLAG_USER_KEYS)
6810     public static final String CONTACT_KEYS_SERVICE = "contact_keys";
6811 
6812     /**
6813      * Use with {@link #getSystemService(String)} to retrieve an
6814      * {@link android.os.ProfilingManager}.
6815      *
6816      * @see #getSystemService(String)
6817      */
6818     @FlaggedApi(android.os.Flags.FLAG_TELEMETRY_APIS_FRAMEWORK_INITIALIZATION)
6819     public static final String PROFILING_SERVICE = "profiling";
6820 
6821     /**
6822      * Use with {@link #getSystemService(String)} to retrieve a {@link
6823      * android.webkit.WebViewUpdateManager} for accessing the WebView update service.
6824      *
6825      * <p>This can only be used on devices with {@link PackageManager#FEATURE_WEBVIEW}.
6826      *
6827      * @see #getSystemService(String)
6828      * @see android.webkit.WebViewUpdateManager
6829      * @hide
6830      */
6831     @FlaggedApi(android.webkit.Flags.FLAG_UPDATE_SERVICE_IPC_WRAPPER)
6832     @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
6833     @SuppressLint("ServiceName")
6834     @RequiresFeature(PackageManager.FEATURE_WEBVIEW)
6835     public static final String WEBVIEW_UPDATE_SERVICE = "webviewupdate";
6836 
6837     /**
6838      * Use with {@link #getSystemService(String)} to retrieve a
6839      * {@link android.provider.BlockedNumbersManager} for accessing the blocked number service.
6840      *
6841      * @see #getSystemService(String)
6842      * @see android.provider.BlockedNumbersManager
6843      * @hide
6844      */
6845     @FlaggedApi(
6846             com.android.server.telecom.flags.Flags.FLAG_TELECOM_MAINLINE_BLOCKED_NUMBERS_MANAGER)
6847     @SystemApi
6848     public static final String BLOCKED_NUMBERS_SERVICE = "blocked_numbers";
6849 
6850     /**
6851      * Use with {@link #getSystemService(String)} to retrieve the
6852      * {@link ProtoLogConfigurationService} for registering ProtoLog clients.
6853      *
6854      * @see #getSystemService(String)
6855      * @see ProtoLogConfigurationService
6856      * @hide
6857      */
6858     public static final String PROTOLOG_CONFIGURATION_SERVICE = "protolog_configuration";
6859 
6860     /**
6861      * Use with {@link #getSystemService(String)} to retrieve a
6862      * {@link android.app.supervision.SupervisionManager}.
6863      *
6864      * @see #getSystemService(String)
6865      * @see android.app.supervision.SupervisionManager
6866      * @hide
6867      */
6868     @SystemApi
6869     @FlaggedApi(android.app.supervision.flags.Flags.FLAG_SUPERVISION_MANAGER_APIS)
6870     public static final String SUPERVISION_SERVICE = "supervision";
6871 
6872     /**
6873      * Use with {@link #getSystemService(String)} to retrieve a
6874      * {@link android.media.quality.MediaQuality} for standardize picture and audio
6875      * API parameters.
6876      *
6877      * @see #getSystemService(String)
6878      * @see android.media.quality.MediaQuality
6879      */
6880     @FlaggedApi(android.media.tv.flags.Flags.FLAG_MEDIA_QUALITY_FW)
6881     public static final String MEDIA_QUALITY_SERVICE = "media_quality";
6882 
6883     /**
6884      * Service to perform operations needed for dynamic instrumentation.
6885      * @hide
6886      */
6887     public static final String DYNAMIC_INSTRUMENTATION_SERVICE = "dynamic_instrumentation";
6888 
6889     /**
6890      * Determine whether the given permission is allowed for a particular
6891      * process and user ID running in the system.
6892      *
6893      * @param permission The name of the permission being checked.
6894      * @param pid The process ID being checked against.  Must be > 0.
6895      * @param uid The UID being checked against.  A uid of 0 is the root
6896      * user, which will pass every permission check.
6897      *
6898      * @return {@link PackageManager#PERMISSION_GRANTED} if the given
6899      * pid/uid is allowed that permission, or
6900      * {@link PackageManager#PERMISSION_DENIED} if it is not.
6901      *
6902      * @see PackageManager#checkPermission(String, String)
6903      * @see #checkCallingPermission
6904      */
6905     @CheckResult(suggest="#enforcePermission(String,int,int,String)")
6906     @PackageManager.PermissionResult
6907     @PermissionMethod
checkPermission( @onNull @ermissionName String permission, int pid, int uid)6908     public abstract int checkPermission(
6909             @NonNull @PermissionName String permission, int pid, int uid);
6910 
6911     /** @hide */
6912     @SuppressWarnings("HiddenAbstractMethod")
6913     @PackageManager.PermissionResult
6914     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
checkPermission(@onNull String permission, int pid, int uid, IBinder callerToken)6915     public abstract int checkPermission(@NonNull String permission, int pid, int uid,
6916             IBinder callerToken);
6917 
6918     /**
6919      * Determine whether the calling process of an IPC you are handling has been
6920      * granted a particular permission.  This is basically the same as calling
6921      * {@link #checkPermission(String, int, int)} with the pid and uid returned
6922      * by {@link android.os.Binder#getCallingPid} and
6923      * {@link android.os.Binder#getCallingUid}.  One important difference
6924      * is that if you are not currently processing an IPC, this function
6925      * will always fail.  This is done to protect against accidentally
6926      * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
6927      * to avoid this protection.
6928      *
6929      * @param permission The name of the permission being checked.
6930      *
6931      * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
6932      * pid/uid is allowed that permission, or
6933      * {@link PackageManager#PERMISSION_DENIED} if it is not.
6934      *
6935      * @see PackageManager#checkPermission(String, String)
6936      * @see #checkPermission
6937      * @see #checkCallingOrSelfPermission
6938      */
6939     @CheckResult(suggest="#enforceCallingPermission(String,String)")
6940     @PackageManager.PermissionResult
6941     @PermissionMethod
checkCallingPermission(@onNull @ermissionName String permission)6942     public abstract int checkCallingPermission(@NonNull @PermissionName String permission);
6943 
6944     /**
6945      * Determine whether the calling process of an IPC <em>or you</em> have been
6946      * granted a particular permission.  This is the same as
6947      * {@link #checkCallingPermission}, except it grants your own permissions
6948      * if you are not currently processing an IPC.  Use with care!
6949      *
6950      * @param permission The name of the permission being checked.
6951      *
6952      * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
6953      * pid/uid is allowed that permission, or
6954      * {@link PackageManager#PERMISSION_DENIED} if it is not.
6955      *
6956      * @see PackageManager#checkPermission(String, String)
6957      * @see #checkPermission
6958      * @see #checkCallingPermission
6959      */
6960     @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
6961     @PackageManager.PermissionResult
6962     @PermissionMethod(orSelf = true)
checkCallingOrSelfPermission(@onNull @ermissionName String permission)6963     public abstract int checkCallingOrSelfPermission(@NonNull @PermissionName String permission);
6964 
6965     /**
6966      * Determine whether <em>you</em> have been granted a particular permission.
6967      *
6968      * @param permission The name of the permission being checked.
6969      *
6970      * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
6971      * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
6972      *
6973      * @see PackageManager#checkPermission(String, String)
6974      * @see #checkCallingPermission(String)
6975      */
6976     @PackageManager.PermissionResult
checkSelfPermission(@onNull String permission)6977     public abstract int checkSelfPermission(@NonNull String permission);
6978 
6979     /**
6980      * If the given permission is not allowed for a particular process
6981      * and user ID running in the system, throw a {@link SecurityException}.
6982      *
6983      * @param permission The name of the permission being checked.
6984      * @param pid The process ID being checked against.  Must be &gt; 0.
6985      * @param uid The UID being checked against.  A uid of 0 is the root
6986      * user, which will pass every permission check.
6987      * @param message A message to include in the exception if it is thrown.
6988      *
6989      * @see #checkPermission(String, int, int)
6990      */
6991     @PermissionMethod
enforcePermission( @onNull @ermissionName String permission, int pid, int uid, @Nullable String message)6992     public abstract void enforcePermission(
6993             @NonNull @PermissionName String permission, int pid, int uid, @Nullable String message);
6994 
6995     /**
6996      * If the calling process of an IPC you are handling has not been
6997      * granted a particular permission, throw a {@link
6998      * SecurityException}.  This is basically the same as calling
6999      * {@link #enforcePermission(String, int, int, String)} with the
7000      * pid and uid returned by {@link android.os.Binder#getCallingPid}
7001      * and {@link android.os.Binder#getCallingUid}.  One important
7002      * difference is that if you are not currently processing an IPC,
7003      * this function will always throw the SecurityException.  This is
7004      * done to protect against accidentally leaking permissions; you
7005      * can use {@link #enforceCallingOrSelfPermission} to avoid this
7006      * protection.
7007      *
7008      * @param permission The name of the permission being checked.
7009      * @param message A message to include in the exception if it is thrown.
7010      *
7011      * @see #checkCallingPermission(String)
7012      */
7013     @PermissionMethod
enforceCallingPermission( @onNull @ermissionName String permission, @Nullable String message)7014     public abstract void enforceCallingPermission(
7015             @NonNull @PermissionName String permission, @Nullable String message);
7016 
7017     /**
7018      * If neither you nor the calling process of an IPC you are
7019      * handling has been granted a particular permission, throw a
7020      * {@link SecurityException}.  This is the same as {@link
7021      * #enforceCallingPermission}, except it grants your own
7022      * permissions if you are not currently processing an IPC.  Use
7023      * with care!
7024      *
7025      * @param permission The name of the permission being checked.
7026      * @param message A message to include in the exception if it is thrown.
7027      *
7028      * @see #checkCallingOrSelfPermission(String)
7029      */
7030     @PermissionMethod(orSelf = true)
enforceCallingOrSelfPermission( @onNull @ermissionName String permission, @Nullable String message)7031     public abstract void enforceCallingOrSelfPermission(
7032             @NonNull @PermissionName String permission, @Nullable String message);
7033 
7034     /**
7035      * Returns the permission request state for a given runtime permission. This method provides a
7036      * streamlined mechanism for applications to determine whether a permission can be
7037      * requested (i.e. whether the user will be prompted with a permission dialog).
7038      *
7039      * <p>Traditionally, determining if a permission has been permanently denied (unrequestable)
7040      * required applications to initiate a permission request and subsequently analyze the result
7041      * of {@link android.app.Activity#shouldShowRequestPermissionRationale} in conjunction with the
7042      * grant result within the {@link android.app.Activity#onRequestPermissionsResult} callback.
7043      *
7044      * @param permission The name of the permission.
7045      *
7046      * @return The current request state of the specified permission, represented by one of the
7047      * following constants: {@link PermissionRequestState#PERMISSION_REQUEST_STATE_GRANTED},
7048      * {@link PermissionRequestState#PERMISSION_REQUEST_STATE_REQUESTABLE}, or
7049      * {@link PermissionRequestState#PERMISSION_REQUEST_STATE_UNREQUESTABLE}.
7050      *
7051      * @hide
7052      */
7053     @CheckResult
7054     @PermissionRequestState
getPermissionRequestState(@onNull String permission)7055     public int getPermissionRequestState(@NonNull String permission) {
7056         throw new RuntimeException("Not implemented. Must override in a subclass.");
7057     }
7058 
7059     /**
7060      * Grant permission to access a specific Uri to another package, regardless
7061      * of whether that package has general permission to access the Uri's
7062      * content provider.  This can be used to grant specific, temporary
7063      * permissions, typically in response to user interaction (such as the
7064      * user opening an attachment that you would like someone else to
7065      * display).
7066      *
7067      * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
7068      * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
7069      * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
7070      * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
7071      * start an activity instead of this function directly.  If you use this
7072      * function directly, you should be sure to call
7073      * {@link #revokeUriPermission} when the target should no longer be allowed
7074      * to access it.
7075      *
7076      * <p>To succeed, the content provider owning the Uri must have set the
7077      * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
7078      * grantUriPermissions} attribute in its manifest or included the
7079      * {@link android.R.styleable#AndroidManifestGrantUriPermission
7080      * &lt;grant-uri-permissions&gt;} tag.
7081      *
7082      * @param toPackage The package you would like to allow to access the Uri.
7083      * @param uri The Uri you would like to grant access to.
7084      * @param modeFlags The desired access modes.
7085      *
7086      * @see #revokeUriPermission
7087      */
grantUriPermission(String toPackage, Uri uri, @Intent.GrantUriMode int modeFlags)7088     public abstract void grantUriPermission(String toPackage, Uri uri,
7089             @Intent.GrantUriMode int modeFlags);
7090 
7091     /**
7092      * Remove all permissions to access a particular content provider Uri
7093      * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
7094      * The given Uri will match all previously granted Uris that are the same or a
7095      * sub-path of the given Uri.  That is, revoking "content://foo/target" will
7096      * revoke both "content://foo/target" and "content://foo/target/sub", but not
7097      * "content://foo".  It will not remove any prefix grants that exist at a
7098      * higher level.
7099      *
7100      * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
7101      * regular permission access to a Uri, but had received access to it through
7102      * a specific Uri permission grant, you could not revoke that grant with this
7103      * function and a {@link SecurityException} would be thrown.  As of
7104      * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
7105      * exception, but will remove whatever permission grants to the Uri had been given to the app
7106      * (or none).</p>
7107      *
7108      * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
7109      * grants matching the given Uri, for any package they had been granted to, through any
7110      * mechanism this had happened (such as indirectly through the clipboard, activity launch,
7111      * service start, etc).  That means this can be potentially dangerous to use, as it can
7112      * revoke grants that another app could be strongly expecting to stick around.</p>
7113      *
7114      * @param uri The Uri you would like to revoke access to.
7115      * @param modeFlags The access modes to revoke.
7116      *
7117      * @see #grantUriPermission
7118      */
revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags)7119     public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
7120 
7121     /**
7122      * Remove permissions to access a particular content provider Uri
7123      * that were previously added with {@link #grantUriPermission} for a specific target
7124      * package.  The given Uri will match all previously granted Uris that are the same or a
7125      * sub-path of the given Uri.  That is, revoking "content://foo/target" will
7126      * revoke both "content://foo/target" and "content://foo/target/sub", but not
7127      * "content://foo".  It will not remove any prefix grants that exist at a
7128      * higher level.
7129      *
7130      * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
7131      * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
7132      * and only for the package specified.  Any matching grants that have happened through
7133      * other mechanisms (clipboard, activity launching, service starting, etc) will not be
7134      * removed.</p>
7135      *
7136      * @param toPackage The package you had previously granted access to.
7137      * @param uri The Uri you would like to revoke access to.
7138      * @param modeFlags The access modes to revoke.
7139      *
7140      * @see #grantUriPermission
7141      */
revokeUriPermission(String toPackage, Uri uri, @Intent.AccessUriMode int modeFlags)7142     public abstract void revokeUriPermission(String toPackage, Uri uri,
7143             @Intent.AccessUriMode int modeFlags);
7144 
7145     /**
7146      * Determine whether a particular process and uid has been granted
7147      * permission to access a specific URI.  This only checks for permissions
7148      * that have been explicitly granted -- if the given process/uid has
7149      * more general access to the URI's content provider then this check will
7150      * always fail.
7151      *
7152      * @param uri The uri that is being checked.
7153      * @param pid The process ID being checked against.  Must be &gt; 0.
7154      * @param uid The UID being checked against.  A uid of 0 is the root
7155      * user, which will pass every permission check.
7156      * @param modeFlags The access modes to check.
7157      *
7158      * @return {@link PackageManager#PERMISSION_GRANTED} if the given
7159      * pid/uid is allowed to access that uri, or
7160      * {@link PackageManager#PERMISSION_DENIED} if it is not.
7161      *
7162      * @see #checkCallingUriPermission
7163      */
7164     @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
7165     @PackageManager.PermissionResult
checkUriPermission(Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags)7166     public abstract int checkUriPermission(Uri uri, int pid, int uid,
7167             @Intent.AccessUriMode int modeFlags);
7168 
7169     /**
7170      * Determine whether a particular process and uid has been granted
7171      * permission to access a specific content URI.
7172      *
7173      * <p>Unlike {@link #checkUriPermission(Uri, int, int, int)}, this method
7174      * checks for general access to the URI's content provider, as well as
7175      * explicitly granted permissions.</p>
7176      *
7177      * <p>Note, this check will throw an {@link IllegalArgumentException}
7178      * for non-content URIs.</p>
7179      *
7180      * @param uri The content uri that is being checked.
7181      * @param pid (Optional) The process ID being checked against. If the
7182      * pid is unknown, pass -1.
7183      * @param uid The UID being checked against.  A uid of 0 is the root
7184      * user, which will pass every permission check.
7185      * @param modeFlags The access modes to check.
7186      *
7187      * @return {@link PackageManager#PERMISSION_GRANTED} if the given
7188      * pid/uid is allowed to access that uri, or
7189      * {@link PackageManager#PERMISSION_DENIED} if it is not.
7190      *
7191      * @see #checkUriPermission(Uri, int, int, int)
7192      */
7193     @FlaggedApi(android.security.Flags.FLAG_CONTENT_URI_PERMISSION_APIS)
7194     @PackageManager.PermissionResult
checkContentUriPermissionFull(@onNull Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags)7195     public int checkContentUriPermissionFull(@NonNull Uri uri, int pid, int uid,
7196             @Intent.AccessUriMode int modeFlags) {
7197         throw new RuntimeException("Not implemented. Must override in a subclass.");
7198     }
7199 
7200     /**
7201      * Determine whether a particular process and uid has been granted
7202      * permission to access a list of URIs.  This only checks for permissions
7203      * that have been explicitly granted -- if the given process/uid has
7204      * more general access to the URI's content provider then this check will
7205      * always fail.
7206      *
7207      * <strong>Note:</strong> On SDK Version {@link android.os.Build.VERSION_CODES#S},
7208      * calling this method from a secondary-user's context will incorrectly return
7209      * {@link PackageManager#PERMISSION_DENIED} for all {code uris}.
7210      *
7211      * @param uris The list of URIs that is being checked.
7212      * @param pid The process ID being checked against.  Must be &gt; 0.
7213      * @param uid The UID being checked against.  A uid of 0 is the root
7214      * user, which will pass every permission check.
7215      * @param modeFlags The access modes to check for the list of uris
7216      *
7217      * @return Array of permission grants corresponding to each entry in the list of uris.
7218      * {@link PackageManager#PERMISSION_GRANTED} if the given pid/uid is allowed to access that uri,
7219      * or {@link PackageManager#PERMISSION_DENIED} if it is not.
7220      *
7221      * @see #checkCallingUriPermission
7222      */
7223     @NonNull
7224     @PackageManager.PermissionResult
checkUriPermissions(@onNull List<Uri> uris, int pid, int uid, @Intent.AccessUriMode int modeFlags)7225     public int[] checkUriPermissions(@NonNull List<Uri> uris, int pid, int uid,
7226             @Intent.AccessUriMode int modeFlags) {
7227         throw new RuntimeException("Not implemented. Must override in a subclass.");
7228     }
7229 
7230     /** @hide */
7231     @SuppressWarnings("HiddenAbstractMethod")
7232     @PackageManager.PermissionResult
checkUriPermission(Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, IBinder callerToken)7233     public abstract int checkUriPermission(Uri uri, int pid, int uid,
7234             @Intent.AccessUriMode int modeFlags, IBinder callerToken);
7235 
7236     /**
7237      * Determine whether the calling process and uid has been
7238      * granted permission to access a specific URI.  This is basically
7239      * the same as calling {@link #checkUriPermission(Uri, int, int,
7240      * int)} with the pid and uid returned by {@link
7241      * android.os.Binder#getCallingPid} and {@link
7242      * android.os.Binder#getCallingUid}.  One important difference is
7243      * that if you are not currently processing an IPC, this function
7244      * will always fail.
7245      *
7246      * @param uri The uri that is being checked.
7247      * @param modeFlags The access modes to check.
7248      *
7249      * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
7250      * is allowed to access that uri, or
7251      * {@link PackageManager#PERMISSION_DENIED} if it is not.
7252      *
7253      * @see #checkUriPermission(Uri, int, int, int)
7254      */
7255     @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
7256     @PackageManager.PermissionResult
checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags)7257     public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
7258 
7259     /**
7260      * Determine whether the calling process and uid has been
7261      * granted permission to access a list of URIs.  This is basically
7262      * the same as calling {@link #checkUriPermissions(List, int, int, int)}
7263      * with the pid and uid returned by {@link
7264      * android.os.Binder#getCallingPid} and {@link
7265      * android.os.Binder#getCallingUid}.  One important difference is
7266      * that if you are not currently processing an IPC, this function
7267      * will always fail.
7268      *
7269      * @param uris The list of URIs that is being checked.
7270      * @param modeFlags The access modes to check.
7271      *
7272      * @return Array of permission grants corresponding to each entry in the list of uris.
7273      * {@link PackageManager#PERMISSION_GRANTED} if the given pid/uid is allowed to access that uri,
7274      * or {@link PackageManager#PERMISSION_DENIED} if it is not.
7275      *
7276      * @see #checkUriPermission(Uri, int, int, int)
7277      */
7278     @NonNull
7279     @PackageManager.PermissionResult
checkCallingUriPermissions(@onNull List<Uri> uris, @Intent.AccessUriMode int modeFlags)7280     public int[] checkCallingUriPermissions(@NonNull List<Uri> uris,
7281             @Intent.AccessUriMode int modeFlags) {
7282         throw new RuntimeException("Not implemented. Must override in a subclass.");
7283     }
7284 
7285     /**
7286      * Determine whether the calling process of an IPC <em>or you</em> has been granted
7287      * permission to access a specific URI.  This is the same as
7288      * {@link #checkCallingUriPermission}, except it grants your own permissions
7289      * if you are not currently processing an IPC.  Use with care!
7290      *
7291      * @param uri The uri that is being checked.
7292      * @param modeFlags The access modes to check.
7293      *
7294      * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
7295      * is allowed to access that uri, or
7296      * {@link PackageManager#PERMISSION_DENIED} if it is not.
7297      *
7298      * @see #checkCallingUriPermission
7299      */
7300     @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
7301     @PackageManager.PermissionResult
checkCallingOrSelfUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags)7302     public abstract int checkCallingOrSelfUriPermission(Uri uri,
7303             @Intent.AccessUriMode int modeFlags);
7304 
7305     /**
7306      * Determine whether the calling process of an IPC <em>or you</em> has been granted
7307      * permission to access a list of URIs.  This is the same as
7308      * {@link #checkCallingUriPermission}, except it grants your own permissions
7309      * if you are not currently processing an IPC.  Use with care!
7310      *
7311      * @param uris The list of URIs that is being checked.
7312      * @param modeFlags The access modes to check.
7313      *
7314      * @return Array of permission grants corresponding to each entry in the list of uris.
7315      * {@link PackageManager#PERMISSION_GRANTED} if the given pid/uid is allowed to access that uri,
7316      * or {@link PackageManager#PERMISSION_DENIED} if it is not.
7317      *
7318      * @see #checkCallingUriPermission
7319      */
7320     @NonNull
7321     @PackageManager.PermissionResult
checkCallingOrSelfUriPermissions(@onNull List<Uri> uris, @Intent.AccessUriMode int modeFlags)7322     public int[] checkCallingOrSelfUriPermissions(@NonNull List<Uri> uris,
7323             @Intent.AccessUriMode int modeFlags) {
7324         throw new RuntimeException("Not implemented. Must override in a subclass.");
7325     }
7326 
7327     /**
7328      * Check both a Uri and normal permission.  This allows you to perform
7329      * both {@link #checkPermission} and {@link #checkUriPermission} in one
7330      * call.
7331      *
7332      * @param uri The Uri whose permission is to be checked, or null to not
7333      * do this check.
7334      * @param readPermission The permission that provides overall read access,
7335      * or null to not do this check.
7336      * @param writePermission The permission that provides overall write
7337      * access, or null to not do this check.
7338      * @param pid The process ID being checked against.  Must be &gt; 0.
7339      * @param uid The UID being checked against.  A uid of 0 is the root
7340      * user, which will pass every permission check.
7341      * @param modeFlags The access modes to check.
7342      *
7343      * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
7344      * is allowed to access that uri or holds one of the given permissions, or
7345      * {@link PackageManager#PERMISSION_DENIED} if it is not.
7346      */
7347     @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
7348     @PackageManager.PermissionResult
checkUriPermission(@ullable Uri uri, @Nullable String readPermission, @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags)7349     public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
7350             @Nullable String writePermission, int pid, int uid,
7351             @Intent.AccessUriMode int modeFlags);
7352 
7353     /**
7354      * If a particular process and uid has not been granted
7355      * permission to access a specific URI, throw {@link
7356      * SecurityException}.  This only checks for permissions that have
7357      * been explicitly granted -- if the given process/uid has more
7358      * general access to the URI's content provider then this check
7359      * will always fail.
7360      *
7361      * @param uri The uri that is being checked.
7362      * @param pid The process ID being checked against.  Must be &gt; 0.
7363      * @param uid The UID being checked against.  A uid of 0 is the root
7364      * user, which will pass every permission check.
7365      * @param modeFlags The access modes to enforce.
7366      * @param message A message to include in the exception if it is thrown.
7367      *
7368      * @see #checkUriPermission(Uri, int, int, int)
7369      */
enforceUriPermission( Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message)7370     public abstract void enforceUriPermission(
7371             Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
7372 
7373     /**
7374      * If the calling process and uid has not been granted
7375      * permission to access a specific URI, throw {@link
7376      * SecurityException}.  This is basically the same as calling
7377      * {@link #enforceUriPermission(Uri, int, int, int, String)} with
7378      * the pid and uid returned by {@link
7379      * android.os.Binder#getCallingPid} and {@link
7380      * android.os.Binder#getCallingUid}.  One important difference is
7381      * that if you are not currently processing an IPC, this function
7382      * will always throw a SecurityException.
7383      *
7384      * @param uri The uri that is being checked.
7385      * @param modeFlags The access modes to enforce.
7386      * @param message A message to include in the exception if it is thrown.
7387      *
7388      * @see #checkCallingUriPermission(Uri, int)
7389      */
enforceCallingUriPermission( Uri uri, @Intent.AccessUriMode int modeFlags, String message)7390     public abstract void enforceCallingUriPermission(
7391             Uri uri, @Intent.AccessUriMode int modeFlags, String message);
7392 
7393     /**
7394      * If the calling process of an IPC <em>or you</em> has not been
7395      * granted permission to access a specific URI, throw {@link
7396      * SecurityException}.  This is the same as {@link
7397      * #enforceCallingUriPermission}, except it grants your own
7398      * permissions if you are not currently processing an IPC.  Use
7399      * with care!
7400      *
7401      * @param uri The uri that is being checked.
7402      * @param modeFlags The access modes to enforce.
7403      * @param message A message to include in the exception if it is thrown.
7404      *
7405      * @see #checkCallingOrSelfUriPermission(Uri, int)
7406      */
enforceCallingOrSelfUriPermission( Uri uri, @Intent.AccessUriMode int modeFlags, String message)7407     public abstract void enforceCallingOrSelfUriPermission(
7408             Uri uri, @Intent.AccessUriMode int modeFlags, String message);
7409 
7410     /**
7411      * Enforce both a Uri and normal permission.  This allows you to perform
7412      * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
7413      * call.
7414      *
7415      * @param uri The Uri whose permission is to be checked, or null to not
7416      * do this check.
7417      * @param readPermission The permission that provides overall read access,
7418      * or null to not do this check.
7419      * @param writePermission The permission that provides overall write
7420      * access, or null to not do this check.
7421      * @param pid The process ID being checked against.  Must be &gt; 0.
7422      * @param uid The UID being checked against.  A uid of 0 is the root
7423      * user, which will pass every permission check.
7424      * @param modeFlags The access modes to enforce.
7425      * @param message A message to include in the exception if it is thrown.
7426      *
7427      * @see #checkUriPermission(Uri, String, String, int, int, int)
7428      */
enforceUriPermission( @ullable Uri uri, @Nullable String readPermission, @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags, @Nullable String message)7429     public abstract void enforceUriPermission(
7430             @Nullable Uri uri, @Nullable String readPermission,
7431             @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
7432             @Nullable String message);
7433 
7434 
7435     /**
7436      * Triggers the asynchronous revocation of a runtime permission. If the permission is not
7437      * currently granted, nothing happens (even if later granted by the user).
7438      *
7439      * @param permName The name of the permission to be revoked.
7440      * @see #revokeSelfPermissionsOnKill(Collection)
7441      * @throws IllegalArgumentException if the permission is not a runtime permission
7442      */
revokeSelfPermissionOnKill(@onNull String permName)7443     public void revokeSelfPermissionOnKill(@NonNull String permName) {
7444         revokeSelfPermissionsOnKill(Collections.singletonList(permName));
7445     }
7446 
7447     /**
7448      * Triggers the revocation of one or more permissions for the calling package. A package is only
7449      * able to revoke runtime permissions. If a permission is not currently granted, it is ignored
7450      * and will not get revoked (even if later granted by the user). Ultimately, you should never
7451      * make assumptions about a permission status as users may grant or revoke them at any time.
7452      * <p>
7453      * Background permissions which have no corresponding foreground permission still granted once
7454      * the revocation is effective will also be revoked.
7455      * <p>
7456      * The revocation happens asynchronously and kills all processes running in the calling UID. It
7457      * will be triggered once it is safe to do so. In particular, it will not be triggered as long
7458      * as the package remains in the foreground, or has any active manifest components (e.g. when
7459      * another app is accessing a content provider in the package).
7460      * <p>
7461      * If you want to revoke the permissions right away, you could call {@code System.exit()} in
7462      * {@code Handler.postDelayed} with a delay to allow completion of async IPC, But
7463      * {@code System.exit()} could affect other apps that are accessing your app at the moment.
7464      * For example, apps accessing a content provider in your app will all crash.
7465      * <p>
7466      * Note that the settings UI shows a permission group as granted as long as at least one
7467      * permission in the group is granted. If you want the user to observe the revocation in the
7468      * settings, you should revoke every permission in the target group. To learn the current list
7469      * of permissions in a group, you may use
7470      * {@link PackageManager#getGroupOfPlatformPermission(String, Executor, Consumer)} and
7471      * {@link PackageManager#getPlatformPermissionsForGroup(String, Executor, Consumer)}. This list
7472      * of permissions may evolve over time, so it is recommended to check whether it contains any
7473      * permission you wish to retain before trying to revoke an entire group.
7474      *
7475      * @param permissions Collection of permissions to be revoked.
7476      * @see PackageManager#getGroupOfPlatformPermission(String, Executor, Consumer)
7477      * @see PackageManager#getPlatformPermissionsForGroup(String, Executor, Consumer)
7478      * @throws IllegalArgumentException if any of the permissions is not a runtime permission
7479      */
revokeSelfPermissionsOnKill(@onNull Collection<String> permissions)7480     public void revokeSelfPermissionsOnKill(@NonNull Collection<String> permissions) {
7481         throw new AbstractMethodError("Must be overridden in implementing class");
7482     }
7483 
7484     /** @hide */
7485     @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
7486             CONTEXT_INCLUDE_CODE,
7487             CONTEXT_IGNORE_SECURITY,
7488             CONTEXT_RESTRICTED,
7489             CONTEXT_DEVICE_PROTECTED_STORAGE,
7490             CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
7491             CONTEXT_REGISTER_PACKAGE,
7492     })
7493     @Retention(RetentionPolicy.SOURCE)
7494     public @interface CreatePackageOptions {}
7495 
7496     /**
7497      * Flag for use with {@link #createPackageContext}: include the application
7498      * code with the context.  This means loading code into the caller's
7499      * process, so that {@link #getClassLoader()} can be used to instantiate
7500      * the application's classes.  Setting this flags imposes security
7501      * restrictions on what application context you can access; if the
7502      * requested application can not be safely loaded into your process,
7503      * java.lang.SecurityException will be thrown.  If this flag is not set,
7504      * there will be no restrictions on the packages that can be loaded,
7505      * but {@link #getClassLoader} will always return the default system
7506      * class loader.
7507      */
7508     public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
7509 
7510     /**
7511      * Flag for use with {@link #createPackageContext}: ignore any security
7512      * restrictions on the Context being requested, allowing it to always
7513      * be loaded.  For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
7514      * to be loaded into a process even when it isn't safe to do so.  Use
7515      * with extreme care!
7516      */
7517     public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
7518 
7519     /**
7520      * Flag for use with {@link #createPackageContext}: a restricted context may
7521      * disable specific features. For instance, a View associated with a restricted
7522      * context would ignore particular XML attributes.
7523      */
7524     public static final int CONTEXT_RESTRICTED = 0x00000004;
7525 
7526     /**
7527      * Flag for use with {@link #createPackageContext}: point all file APIs at
7528      * device-protected storage.
7529      *
7530      * @hide
7531      */
7532     public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
7533 
7534     /**
7535      * Flag for use with {@link #createPackageContext}: point all file APIs at
7536      * credential-protected storage.
7537      *
7538      * @hide
7539      */
7540     public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
7541 
7542     /**
7543      * @hide Used to indicate we should tell the activity manager about the process
7544      * loading this code.
7545      */
7546     public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
7547 
7548     /**
7549      * Return a new Context object for the given application name.  This
7550      * Context is the same as what the named application gets when it is
7551      * launched, containing the same resources and class loader.  Each call to
7552      * this method returns a new instance of a Context object; Context objects
7553      * are not shared, however they share common state (Resources, ClassLoader,
7554      * etc) so the Context instance itself is fairly lightweight.
7555      *
7556      * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
7557      * application with the given package name.
7558      *
7559      * <p>Throws {@link java.lang.SecurityException} if the Context requested
7560      * can not be loaded into the caller's process for security reasons (see
7561      * {@link #CONTEXT_INCLUDE_CODE} for more information}.
7562      *
7563      * @param packageName Name of the application's package.
7564      * @param flags Option flags.
7565      *
7566      * @return A {@link Context} for the application.
7567      *
7568      * @throws SecurityException &nbsp;
7569      * @throws PackageManager.NameNotFoundException if there is no application with
7570      * the given package name.
7571      */
createPackageContext(String packageName, @CreatePackageOptions int flags)7572     public abstract Context createPackageContext(String packageName,
7573             @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
7574 
7575     /**
7576      * Similar to {@link #createPackageContext(String, int)}, but with a
7577      * different {@link UserHandle}. For example, {@link #getContentResolver()}
7578      * will open any {@link Uri} as the given user.
7579      *
7580      * @hide
7581      */
7582     @SystemApi
7583     @NonNull
createPackageContextAsUser( @onNull String packageName, @CreatePackageOptions int flags, @NonNull UserHandle user)7584     public Context createPackageContextAsUser(
7585             @NonNull String packageName, @CreatePackageOptions int flags, @NonNull UserHandle user)
7586             throws PackageManager.NameNotFoundException {
7587         if (Build.IS_ENG) {
7588             throw new IllegalStateException("createPackageContextAsUser not overridden!");
7589         }
7590         return this;
7591     }
7592 
7593     /**
7594      * Similar to {@link #createPackageContext(String, int)}, but for the own package with a
7595      * different {@link UserHandle}. For example, {@link #getContentResolver()}
7596      * will open any {@link Uri} as the given user.
7597      *
7598      * @hide
7599      */
7600     @SystemApi
7601     @NonNull
createContextAsUser(@onNull UserHandle user, @CreatePackageOptions int flags)7602     public Context createContextAsUser(@NonNull UserHandle user, @CreatePackageOptions int flags) {
7603         if (Build.IS_ENG) {
7604             throw new IllegalStateException("createContextAsUser not overridden!");
7605         }
7606         return this;
7607     }
7608 
7609     /**
7610      * Creates a context given an {@link android.content.pm.ApplicationInfo}.
7611      *
7612      * @hide
7613      */
7614     @SuppressWarnings("HiddenAbstractMethod")
7615     @UnsupportedAppUsage
createApplicationContext(ApplicationInfo application, @CreatePackageOptions int flags)7616     public abstract Context createApplicationContext(ApplicationInfo application,
7617             @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
7618 
7619     /**
7620      * Creates a context given an {@link android.content.pm.ApplicationInfo}.
7621      *
7622      * Context created is for an sdk library that is being loaded in sdk sandbox.
7623      *
7624      * @param sdkInfo information regarding the sdk library being loaded.
7625      *
7626      * @throws PackageManager.NameNotFoundException if there is no application with
7627      * the given package name.
7628      * @throws SecurityException if caller is not a SdkSandbox process.
7629      *
7630      * @hide
7631      */
7632     @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
7633     @NonNull
createContextForSdkInSandbox(@onNull ApplicationInfo sdkInfo, @CreatePackageOptions int flags)7634     public Context createContextForSdkInSandbox(@NonNull ApplicationInfo sdkInfo,
7635             @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException {
7636         throw new RuntimeException("Not implemented. Must override in a subclass.");
7637     }
7638 
7639     /**
7640      * Return a new Context object for the given split name. The new Context has a ClassLoader and
7641      * Resources object that can access the split's and all of its dependencies' code/resources.
7642      * Each call to this method returns a new instance of a Context object;
7643      * Context objects are not shared, however common state (ClassLoader, other Resources for
7644      * the same split) may be so the Context itself can be fairly lightweight.
7645      *
7646      * @param splitName The name of the split to include, as declared in the split's
7647      *                  <code>AndroidManifest.xml</code>.
7648      * @return A {@link Context} with the given split's code and/or resources loaded.
7649      */
createContextForSplit(String splitName)7650     public abstract Context createContextForSplit(String splitName)
7651             throws PackageManager.NameNotFoundException;
7652 
7653     /**
7654      * Get the user associated with this context.
7655      *
7656      * @return the user associated with this context
7657      *
7658      * @hide
7659      */
7660     @NonNull
7661     @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
7662     @TestApi
getUser()7663     public UserHandle getUser() {
7664         return android.os.Process.myUserHandle();
7665     }
7666 
7667     /**
7668      * Get the user associated with this context
7669      * @hide
7670      */
7671     @UnsupportedAppUsage
7672     @TestApi
getUserId()7673     public @UserIdInt int getUserId() {
7674         return android.os.UserHandle.myUserId();
7675     }
7676 
7677     /**
7678      * Return a new Context object for the current Context but whose resources
7679      * are adjusted to match the given Configuration.  Each call to this method
7680      * returns a new instance of a Context object; Context objects are not
7681      * shared, however common state (ClassLoader, other Resources for the
7682      * same configuration) may be so the Context itself can be fairly lightweight.
7683      *
7684      * @param overrideConfiguration A {@link Configuration} specifying what
7685      * values to modify in the base Configuration of the original Context's
7686      * resources.  If the base configuration changes (such as due to an
7687      * orientation change), the resources of this context will also change except
7688      * for those that have been explicitly overridden with a value here.
7689      *
7690      * @return A {@link Context} with the given configuration override.
7691      */
createConfigurationContext( @onNull Configuration overrideConfiguration)7692     public abstract Context createConfigurationContext(
7693             @NonNull Configuration overrideConfiguration);
7694 
7695     /**
7696      * Returns a new {@code Context} object from the current context but with resources
7697      * adjusted to match the metrics of {@code display}. Each call to this method
7698      * returns a new instance of a context object. Context objects are not shared; however,
7699      * common state (such as the {@link ClassLoader} and other resources for the same
7700      * configuration) can be shared, so the {@code Context} itself is lightweight.
7701      *
7702      * <p><b>Note:</b>
7703      * This {@code Context} is <b>not</b> expected to be updated with new configuration if the
7704      * underlying display configuration changes and the cached {@code Resources} it returns
7705      * could be stale. It is suggested to use
7706      * {@link android.hardware.display.DisplayManager.DisplayListener} to listen for
7707      * changes and re-create an instance if necessary. </p>
7708      * <p>
7709      * This {@code Context} is <b>not</b> a UI context, do not use it to access UI components
7710      * or obtain a {@link WindowManager} instance.
7711      * </p><p>
7712      * To obtain an instance of {@link WindowManager} configured to show windows on the given
7713      * display, call {@link #createWindowContext(int, Bundle)} on the returned display context,
7714      * then call {@link #getSystemService(String)} or {@link #getSystemService(Class)} on the
7715      * returned window context.
7716      * </p>
7717      * @param display The display to which the current context's resources are adjusted.
7718      *
7719      * @return A context for the display.
7720      */
7721     @DisplayContext
createDisplayContext(@onNull Display display)7722     public abstract Context createDisplayContext(@NonNull Display display);
7723 
7724     /**
7725      * Returns a new {@code Context} object from the current context but with device association
7726      * given by the {@code deviceId}. Each call to this method returns a new instance of a context
7727      * object. Context objects are not shared; however, common state (such as the
7728      * {@link ClassLoader} and other resources for the same configuration) can be shared, so the
7729      * {@code Context} itself is lightweight.
7730      * <p>
7731      * Applications that run on virtual devices may use this method to access the default device
7732      * capabilities and functionality (by passing
7733      * {@link Context#DEVICE_ID_DEFAULT}. Similarly,
7734      * applications running on the default device may access the functionality of virtual devices.
7735      * </p>
7736      * <p>
7737      * Note that the newly created instance will be associated with the same display as the parent
7738      * Context, regardless of the device ID passed here.
7739      * </p>
7740      * @param deviceId The ID of the device to associate with this context.
7741      * @return A context associated with the given device ID.
7742      *
7743      * @see #getDeviceId()
7744      * @see VirtualDeviceManager#getVirtualDevices()
7745      * @throws IllegalArgumentException if the given device ID is not a valid ID of the default
7746      * device or a virtual device.
7747      */
createDeviceContext(int deviceId)7748     public @NonNull Context createDeviceContext(int deviceId) {
7749         throw new RuntimeException("Not implemented. Must override in a subclass.");
7750     }
7751 
7752     /**
7753      * Creates a Context for a non-activity window.
7754      *
7755      * <p>
7756      * A window context is a context that can be used to add non-activity windows, such as
7757      * {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY}. A window context
7758      * must be created from a context that has an associated {@link Display}, such as
7759      * {@link android.app.Activity Activity} or a context created with
7760      * {@link #createDisplayContext(Display)}.
7761      *
7762      * <p>
7763      * The window context is created with the appropriate {@link Configuration} for the area of the
7764      * display that the windows created with it can occupy; it must be used when
7765      * {@link android.view.LayoutInflater inflating} views, such that they can be inflated with
7766      * proper {@link Resources}.
7767      *
7768      * Below is a sample code to <b>add an application overlay window on the primary display:</b>
7769      * <pre class="prettyprint">
7770      * ...
7771      * final DisplayManager dm = anyContext.getSystemService(DisplayManager.class);
7772      * final Display primaryDisplay = dm.getDisplay(DEFAULT_DISPLAY);
7773      * final Context windowContext = anyContext.createDisplayContext(primaryDisplay)
7774      *         .createWindowContext(TYPE_APPLICATION_OVERLAY, null);
7775      * final View overlayView = Inflater.from(windowContext).inflate(someLayoutXml, null);
7776      *
7777      * // WindowManager.LayoutParams initialization
7778      * ...
7779      * // The types used in addView and createWindowContext must match.
7780      * mParams.type = TYPE_APPLICATION_OVERLAY;
7781      * ...
7782      *
7783      * windowContext.getSystemService(WindowManager.class).addView(overlayView, mParams);
7784      * </pre>
7785      *
7786      * <p>
7787      * This context's configuration and resources are adjusted to an area of the display where
7788      * the windows with provided type will be added. <b>Note that all windows associated with the
7789      * same context will have an affinity and can only be moved together between different displays
7790      * or areas on a display.</b> If there is a need to add different window types, or
7791      * non-associated windows, separate Contexts should be used.
7792      * </p>
7793      * <p>
7794      * Creating a window context is an expensive operation. Misuse of this API may lead to a huge
7795      * performance drop. The best practice is to use the same window context when possible.
7796      * An approach is to create one window context with specific window type and display and
7797      * use it everywhere it's needed.
7798      * </p>
7799      * <p>
7800      * After {@link Build.VERSION_CODES#S}, window context provides the capability to receive
7801      * configuration changes for existing token by overriding the
7802      * {@link android.view.WindowManager.LayoutParams#token token} of the
7803      * {@link android.view.WindowManager.LayoutParams} passed in
7804      * {@link WindowManager#addView(View, LayoutParams)}. This is useful when an application needs
7805      * to attach its window to an existing activity for window token sharing use-case.
7806      * </p>
7807      * <p>
7808      * Note that the window context in {@link Build.VERSION_CODES#R} didn't have this
7809      * capability. This is a no-op for the window context in {@link Build.VERSION_CODES#R}.
7810      * </p>
7811      * Below is sample code to <b>attach an existing token to a window context:</b>
7812      * <pre class="prettyprint">
7813      * final DisplayManager dm = anyContext.getSystemService(DisplayManager.class);
7814      * final Display primaryDisplay = dm.getDisplay(DEFAULT_DISPLAY);
7815      * final Context windowContext = anyContext.createWindowContext(primaryDisplay,
7816      *         TYPE_APPLICATION, null);
7817      *
7818      * // Get an existing token.
7819      * final IBinder existingToken = activity.getWindow().getAttributes().token;
7820      *
7821      * // The types used in addView() and createWindowContext() must match.
7822      * final WindowManager.LayoutParams params = new WindowManager.LayoutParams(TYPE_APPLICATION);
7823      * params.token = existingToken;
7824      *
7825      * // After WindowManager#addView(), the server side will extract the provided token from
7826      * // LayoutParams#token (existingToken in the sample code), and switch to propagate
7827      * // configuration changes from the node associated with the provided token.
7828      * windowContext.getSystemService(WindowManager.class).addView(overlayView, mParams);
7829      * </pre>
7830      * <p>
7831      * After {@link Build.VERSION_CODES#S}, window context provides the capability to listen to its
7832      * {@link Configuration} changes by calling
7833      * {@link #registerComponentCallbacks(ComponentCallbacks)}, while other kinds of {@link Context}
7834      * will register the {@link ComponentCallbacks} to {@link #getApplicationContext() its
7835      * Application context}. Note that window context only propagate
7836      * {@link ComponentCallbacks#onConfigurationChanged(Configuration)} callback.
7837      * {@link ComponentCallbacks#onLowMemory()} or other callbacks in {@link ComponentCallbacks2}
7838      * won't be invoked.
7839      * </p>
7840      * <p>
7841      * Note that using {@link android.app.Application} or {@link android.app.Service} context for
7842      * UI-related queries may result in layout or continuity issues on devices with variable screen
7843      * sizes (e.g. foldables) or in multi-window modes, since these non-UI contexts may not reflect
7844      * the {@link Configuration} changes for the visual container.
7845      * </p>
7846      * @param type Window type in {@link WindowManager.LayoutParams}
7847      * @param options A bundle used to pass window-related options
7848      * @return A {@link Context} that can be used to create
7849      *         non-{@link android.app.Activity activity} windows.
7850      *
7851      * @see #getSystemService(String)
7852      * @see #getSystemService(Class)
7853      * @see #WINDOW_SERVICE
7854      * @see #LAYOUT_INFLATER_SERVICE
7855      * @see #WALLPAPER_SERVICE
7856      * @throws UnsupportedOperationException if this {@link Context} does not attach to a display,
7857      * such as {@link android.app.Application Application} or {@link android.app.Service Service}.
7858      */
7859     @UiContext
7860     @NonNull
createWindowContext(@indowType int type, @Nullable Bundle options)7861     public Context createWindowContext(@WindowType int type, @Nullable Bundle options)  {
7862         throw new RuntimeException("Not implemented. Must override in a subclass.");
7863     }
7864 
7865     /**
7866      * Creates a {@code Context} for a non-{@link android.app.Activity activity} window on the given
7867      * {@link Display}.
7868      *
7869      * <p>
7870      * Similar to {@link #createWindowContext(int, Bundle)}, but the {@code display} is passed in,
7871      * instead of implicitly using the {@link #getDisplay() original Context's Display}.
7872      * </p>
7873      *
7874      * @param display The {@link Display} to associate with
7875      * @param type Window type in {@link WindowManager.LayoutParams}
7876      * @param options A bundle used to pass window-related options.
7877      * @return A {@link Context} that can be used to create
7878      *         non-{@link android.app.Activity activity} windows.
7879      * @throws IllegalArgumentException if the {@link Display} is {@code null}.
7880      *
7881      * @see #getSystemService(String)
7882      * @see #getSystemService(Class)
7883      * @see #WINDOW_SERVICE
7884      * @see #LAYOUT_INFLATER_SERVICE
7885      * @see #WALLPAPER_SERVICE
7886      */
7887     @UiContext
7888     @NonNull
createWindowContext(@onNull Display display, @WindowType int type, @SuppressLint("NullableCollection") @Nullable Bundle options)7889     public Context createWindowContext(@NonNull Display display, @WindowType int type,
7890             @SuppressLint("NullableCollection")
7891             @Nullable Bundle options) {
7892         throw new RuntimeException("Not implemented. Must override in a subclass.");
7893     }
7894 
7895     /**
7896      * Creates a context with specific properties and behaviors.
7897      *
7898      * @param contextParams Parameters for how the new context should behave.
7899      * @return A context with the specified behaviors.
7900      *
7901      * @see ContextParams
7902      */
7903     @NonNull
createContext(@onNull ContextParams contextParams)7904     public Context createContext(@NonNull ContextParams contextParams) {
7905         throw new RuntimeException("Not implemented. Must override in a subclass.");
7906     }
7907 
7908     /**
7909      * Return a new Context object for the current Context but attribute to a different tag.
7910      * In complex apps attribution tagging can be used to distinguish between separate logical
7911      * parts.
7912      *
7913      * @param attributionTag The tag or {@code null} to create a context for the default.
7914      *
7915      * @return A {@link Context} that is tagged for the new attribution
7916      *
7917      * @see #getAttributionTag()
7918      */
createAttributionContext(@ullable String attributionTag)7919     public @NonNull Context createAttributionContext(@Nullable String attributionTag) {
7920         throw new RuntimeException("Not implemented. Must override in a subclass.");
7921     }
7922 
7923     // TODO moltmann: remove
7924     /**
7925      * @removed
7926      */
7927     @Deprecated
createFeatureContext(@ullable String attributionTag)7928     public @NonNull Context createFeatureContext(@Nullable String attributionTag) {
7929         return createContext(new ContextParams.Builder(getParams())
7930                 .setAttributionTag(attributionTag)
7931                 .build());
7932     }
7933 
7934     /**
7935      * Return a new Context object for the current Context but whose storage
7936      * APIs are backed by device-protected storage.
7937      * <p>
7938      * On devices with direct boot, data stored in this location is encrypted
7939      * with a key tied to the physical device, and it can be accessed
7940      * immediately after the device has booted successfully, both
7941      * <em>before and after</em> the user has authenticated with their
7942      * credentials (such as a lock pattern or PIN).
7943      * <p>
7944      * Because device-protected data is available without user authentication,
7945      * you should carefully limit the data you store using this Context. For
7946      * example, storing sensitive authentication tokens or passwords in the
7947      * device-protected area is strongly discouraged.
7948      * <p>
7949      * If the underlying device does not have the ability to store
7950      * device-protected and credential-protected data using different keys, then
7951      * both storage areas will become available at the same time. They remain as
7952      * two distinct storage locations on disk, and only the window of
7953      * availability changes.
7954      * <p>
7955      * Each call to this method returns a new instance of a Context object;
7956      * Context objects are not shared, however common state (ClassLoader, other
7957      * Resources for the same configuration) may be so the Context itself can be
7958      * fairly lightweight.
7959      *
7960      * @see #isDeviceProtectedStorage()
7961      */
createDeviceProtectedStorageContext()7962     public abstract Context createDeviceProtectedStorageContext();
7963 
7964     /**
7965      * Return a new Context object for the current Context but whose storage
7966      * APIs are backed by credential-protected storage. This is the default
7967      * storage area for apps unless
7968      * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
7969      * <p>
7970      * On devices with direct boot, data stored in this location is encrypted
7971      * with a key tied to user credentials, which can be accessed
7972      * <em>only after</em> the user has entered their credentials (such as a
7973      * lock pattern or PIN).
7974      * <p>
7975      * If the underlying device does not have the ability to store
7976      * device-protected and credential-protected data using different keys, then
7977      * both storage areas will become available at the same time. They remain as
7978      * two distinct storage locations on disk, and only the window of
7979      * availability changes.
7980      * <p>
7981      * Each call to this method returns a new instance of a Context object;
7982      * Context objects are not shared, however common state (ClassLoader, other
7983      * Resources for the same configuration) may be so the Context itself can be
7984      * fairly lightweight.
7985      *
7986      * @see #isCredentialProtectedStorage()
7987      * @hide
7988      */
7989     @SuppressWarnings("HiddenAbstractMethod")
7990     @SystemApi
createCredentialProtectedStorageContext()7991     public abstract Context createCredentialProtectedStorageContext();
7992 
7993     /**
7994      * Creates a UI context with a {@code token}. The users of this API should handle this context's
7995      * configuration changes.
7996      *
7997      * @param token The token to associate with the {@link Resources}
7998      * @param display The display to associate with the token context
7999      *
8000      * @hide
8001      */
8002     @UiContext
8003     @NonNull
createTokenContext(@onNull IBinder token, @NonNull Display display)8004     public Context createTokenContext(@NonNull IBinder token, @NonNull Display display) {
8005         throw new RuntimeException("Not implemented. Must override in a subclass.");
8006     }
8007 
8008     /**
8009      * Gets the display adjustments holder for this context.  This information
8010      * is provided on a per-application or activity basis and is used to simulate lower density
8011      * display metrics for legacy applications and restricted screen sizes.
8012      *
8013      * @param displayId The display id for which to get compatibility info.
8014      * @return The compatibility info holder, or null if not required by the application.
8015      * @hide
8016      */
8017     @SuppressWarnings("HiddenAbstractMethod")
getDisplayAdjustments(int displayId)8018     public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
8019 
8020     /**
8021      * Get the display this context is associated with. Applications should use this method with
8022      * {@link android.app.Activity} or a context associated with a {@link Display} via
8023      * {@link #createDisplayContext(Display)} to get a display object associated with a Context, or
8024      * {@link android.hardware.display.DisplayManager#getDisplay} to get a display object by id.
8025      * @return Returns the {@link Display} object this context is associated with.
8026      * @throws UnsupportedOperationException if the method is called on an instance that is not
8027      *         associated with any display.
8028      */
8029     @NonNull
getDisplay()8030     public Display getDisplay() {
8031         throw new RuntimeException("Not implemented. Must override in a subclass.");
8032     }
8033 
8034     /**
8035      * A version of {@link #getDisplay()} that does not perform a Context misuse check to be used by
8036      * legacy APIs.
8037      * TODO(b/149790106): Fix usages and remove.
8038      * @hide
8039      */
8040     @Nullable
getDisplayNoVerify()8041     public Display getDisplayNoVerify() {
8042         throw new RuntimeException("Not implemented. Must override in a subclass.");
8043     }
8044 
8045     /**
8046      * Gets the ID of the display this context is associated with.
8047      *
8048      * @return display ID associated with this {@link Context}.
8049      * @see #getDisplay()
8050      * @hide
8051      */
8052     @SuppressWarnings("HiddenAbstractMethod")
8053     @TestApi
getDisplayId()8054     public abstract int getDisplayId();
8055 
8056     /**
8057      * @return Returns the id of the Display object associated with this Context or
8058      * {@link Display#INVALID_DISPLAY} if no Display has been associated.
8059      * @see #getDisplay()
8060      * @see #getDisplayId()
8061      *
8062      * @hide
8063      */
getAssociatedDisplayId()8064     public int getAssociatedDisplayId() {
8065         throw new RuntimeException("Not implemented. Must override in a subclass.");
8066     }
8067 
8068     /**
8069      * Updates the display association of this Context with the display with the given ID.
8070      *
8071      * @hide
8072      */
8073     @SuppressWarnings("HiddenAbstractMethod")
8074     @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
8075     @TestApi
updateDisplay(int displayId)8076     public abstract void updateDisplay(int displayId);
8077 
8078     /**
8079      * Updates the device ID association of this Context. Since a Context created with
8080      * {@link #createDeviceContext} cannot change its device association, this method must
8081      * not be called for instances created with {@link #createDeviceContext}.
8082      *<p>
8083      * Note that updating the deviceId of the Context will not update its associated display.
8084      *</p>
8085      * @param deviceId The new device ID to assign to this Context.
8086      * @throws UnsupportedOperationException if the method is called on an instance that was
8087      *         created with {@link Context#createDeviceContext(int)}
8088      * @throws IllegalArgumentException if the given device ID is not a valid ID of the default
8089      *         device or a virtual device.
8090      *
8091      * @see #createDeviceContext(int)
8092      * @hide
8093      */
8094     @TestApi
updateDeviceId(int deviceId)8095     public void updateDeviceId(int deviceId) {
8096         throw new RuntimeException("Not implemented. Must override in a subclass.");
8097     }
8098 
8099     /**
8100      * Gets the device ID this context is associated with. Applications can use this method to
8101      * determine whether they are running on a virtual device and identify that device.
8102      *
8103      * The device ID of the host device is
8104      * {@link Context#DEVICE_ID_DEFAULT}
8105      *
8106      * <p>
8107      * If the underlying device ID is changed by the system, for example, when an
8108      * {@link Activity} is moved to a different virtual device, applications can register to listen
8109      * to changes by calling
8110      * {@link Context#registerDeviceIdChangeListener(Executor, IntConsumer)}.
8111      * </p>
8112      *
8113      * <p>
8114      * This method will only return a reliable value for this instance if it was created with
8115      * {@link Context#createDeviceContext(int)}, or if this instance is a UI or Display Context.
8116      * Contexts created with {@link Context#createDeviceContext(int)} will have an explicit
8117      * device association, which will never change, even if the underlying device is closed or is
8118      * removed. UI Contexts and Display Contexts are
8119      * already associated with a display, so if the device association is not explicitly
8120      * given, {@link Context#getDeviceId()} will return the ID of the device associated with
8121      * the associated display. The system can assign an arbitrary device id value for Contexts not
8122      * logically associated with a device.
8123      * </p>
8124      *
8125      * @return the ID of the device this context is associated with.
8126      * @see #createDeviceContext(int)
8127      * @see #registerDeviceIdChangeListener(Executor, IntConsumer)
8128      * @see #isUiContext()
8129      */
getDeviceId()8130     public int getDeviceId() {
8131         throw new RuntimeException("Not implemented. Must override in a subclass.");
8132     }
8133 
8134     /**
8135      * Adds a new device ID changed listener to the {@code Context}, which will be called when
8136      * the device association is changed by the system.
8137      * <p>
8138      * The callback can be called when an app is moved to a different device and the {@code Context}
8139      * is not explicitly associated with a specific device.
8140      * </p>
8141      * <p> When an application receives a device id update callback, this Context is guaranteed to
8142      * also have an updated display ID(if any) and {@link Configuration}.
8143      * <p/>
8144      * @param executor The Executor on whose thread to execute the callbacks of the {@code listener}
8145      *                 object.
8146      * @param listener The listener {@code IntConsumer} to call which will receive the updated
8147      *                 device ID.
8148      *
8149      * @see Context#getDeviceId()
8150      * @see Context#createDeviceContext(int)
8151      */
registerDeviceIdChangeListener(@onNull @allbackExecutor Executor executor, @NonNull IntConsumer listener)8152     public void registerDeviceIdChangeListener(@NonNull @CallbackExecutor Executor executor,
8153             @NonNull IntConsumer listener) {
8154         throw new RuntimeException("Not implemented. Must override in a subclass.");
8155     }
8156 
8157     /**
8158      * Removes a device ID changed listener from the Context. It's a no-op if
8159      * the listener is not already registered.
8160      *
8161      * @param listener The {@code Consumer} to remove.
8162      *
8163      * @see #getDeviceId()
8164      * @see #registerDeviceIdChangeListener(Executor, IntConsumer)
8165      */
unregisterDeviceIdChangeListener(@onNull IntConsumer listener)8166     public void unregisterDeviceIdChangeListener(@NonNull IntConsumer listener) {
8167         throw new RuntimeException("Not implemented. Must override in a subclass.");
8168     }
8169 
8170     /**
8171      * Indicates whether this Context is restricted.
8172      *
8173      * @return {@code true} if this Context is restricted, {@code false} otherwise.
8174      *
8175      * @see #CONTEXT_RESTRICTED
8176      */
isRestricted()8177     public boolean isRestricted() {
8178         return false;
8179     }
8180 
8181     /**
8182      * Indicates if the storage APIs of this Context are backed by
8183      * device-protected storage.
8184      *
8185      * @see #createDeviceProtectedStorageContext()
8186      */
isDeviceProtectedStorage()8187     public abstract boolean isDeviceProtectedStorage();
8188 
8189     /**
8190      * Indicates if the storage APIs of this Context are backed by
8191      * credential-protected storage.
8192      *
8193      * @see #createCredentialProtectedStorageContext()
8194      * @hide
8195      */
8196     @SuppressWarnings("HiddenAbstractMethod")
8197     @SystemApi
isCredentialProtectedStorage()8198     public abstract boolean isCredentialProtectedStorage();
8199 
8200     /**
8201      * Returns true if the context can load unsafe resources, e.g. fonts.
8202      * @hide
8203      */
8204     @SuppressWarnings("HiddenAbstractMethod")
canLoadUnsafeResources()8205     public abstract boolean canLoadUnsafeResources();
8206 
8207     /**
8208      * Returns token if the {@link Context} is a {@link android.app.Activity}. Returns
8209      * {@code null} otherwise.
8210      *
8211      * @hide
8212      */
8213     @Nullable
getActivityToken()8214     public IBinder getActivityToken() {
8215         throw new RuntimeException("Not implemented. Must override in a subclass.");
8216     }
8217 
8218     /**
8219      * Returns the {@link IBinder} representing the associated
8220      * {@link com.android.server.wm.WindowToken} if the {@link Context} is a
8221      * {@link android.app.WindowContext}. Returns {@code null} otherwise.
8222      *
8223      * @hide
8224      */
8225     @Nullable
getWindowContextToken()8226     public IBinder getWindowContextToken() {
8227         throw new RuntimeException("Not implemented. Must override in a subclass.");
8228     }
8229 
8230     /**
8231      * Returns the proper token of a {@link Context}.
8232      *
8233      * If the {@link Context} is an {@link android.app.Activity}, returns
8234      * {@link #getActivityToken()}. If the {@lijnk Context} is a {@link android.app.WindowContext},
8235      * returns {@link #getWindowContextToken()}. Returns {@code null}, otherwise.
8236      *
8237      * @hide
8238      */
8239     @Nullable
getToken(@onNull Context context)8240     public static IBinder getToken(@NonNull Context context) {
8241         return context.getActivityToken() != null ? context.getActivityToken()
8242                 : context.getWindowContextToken();
8243     }
8244 
8245     /**
8246      * @hide
8247      */
8248     @Nullable
getServiceDispatcher(ServiceConnection conn, Handler handler, long flags)8249     public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
8250             long flags) {
8251         throw new RuntimeException("Not implemented. Must override in a subclass.");
8252     }
8253 
8254     /**
8255      * @hide
8256      */
getIApplicationThread()8257     public IApplicationThread getIApplicationThread() {
8258         throw new RuntimeException("Not implemented. Must override in a subclass.");
8259     }
8260 
8261     /**
8262      * Used by a mainline module to uniquely identify a specific app process.
8263      * @hide
8264      */
8265     @NonNull
8266     @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
getProcessToken()8267     public IBinder getProcessToken() {
8268         throw new RuntimeException("Not implemented. Must override in a subclass.");
8269     }
8270 
8271     /**
8272      * @hide
8273      */
getMainThreadHandler()8274     public Handler getMainThreadHandler() {
8275         throw new RuntimeException("Not implemented. Must override in a subclass.");
8276     }
8277 
8278     /**
8279      * @hide
8280      */
getAutofillClient()8281     public AutofillClient getAutofillClient() {
8282         return null;
8283     }
8284 
8285     /**
8286      * @hide
8287      */
setAutofillClient(@uppressWarnings"unused") AutofillClient client)8288     public void setAutofillClient(@SuppressWarnings("unused") AutofillClient client) {
8289     }
8290 
8291     /**
8292      * @hide
8293      */
8294     @Nullable
getContentCaptureClient()8295     public ContentCaptureClient getContentCaptureClient() {
8296         return null;
8297     }
8298 
8299     /**
8300      * @hide
8301      */
isAutofillCompatibilityEnabled()8302     public final boolean isAutofillCompatibilityEnabled() {
8303         final AutofillOptions options = getAutofillOptions();
8304         return options != null && options.compatModeEnabled;
8305     }
8306 
8307     /**
8308      * @hide
8309      */
8310     @Nullable
getAutofillOptions()8311     public AutofillOptions getAutofillOptions() {
8312         return null;
8313     }
8314 
8315     /**
8316      * @hide
8317      */
8318     @TestApi
setAutofillOptions(@uppressWarnings"unused") @ullable AutofillOptions options)8319     public void setAutofillOptions(@SuppressWarnings("unused") @Nullable AutofillOptions options) {
8320     }
8321 
8322     /**
8323      * Gets the Content Capture options for this context, or {@code null} if it's not allowlisted.
8324      *
8325      * @hide
8326      */
8327     @Nullable
getContentCaptureOptions()8328     public ContentCaptureOptions getContentCaptureOptions() {
8329         return null;
8330     }
8331 
8332     /**
8333      * @hide
8334      */
8335     @TestApi
setContentCaptureOptions( @uppressWarnings"unused") @ullable ContentCaptureOptions options)8336     public void setContentCaptureOptions(
8337             @SuppressWarnings("unused") @Nullable ContentCaptureOptions options) {
8338     }
8339 
8340     /**
8341      * Throws an exception if the Context is using system resources,
8342      * which are non-runtime-overlay-themable and may show inconsistent UI.
8343      * @hide
8344      */
assertRuntimeOverlayThemable()8345     public void assertRuntimeOverlayThemable() {
8346         // Resources.getSystem() is a singleton and the only Resources not managed by
8347         // ResourcesManager; therefore Resources.getSystem() is not themable.
8348         if (getResources() == Resources.getSystem()) {
8349             throw new IllegalArgumentException("Non-UI context used to display UI; "
8350                     + "get a UI context from ActivityThread#getSystemUiContext()");
8351         }
8352     }
8353 
8354     /**
8355      * Returns {@code true} if the context is a UI context which can access UI components such as
8356      * {@link WindowManager}, {@link android.view.LayoutInflater LayoutInflater} or
8357      * {@link android.app.WallpaperManager WallpaperManager}. Accessing UI components from non-UI
8358      * contexts throws {@link android.os.strictmode.Violation} if
8359      * {@link android.os.StrictMode.VmPolicy.Builder#detectIncorrectContextUse()} is enabled.
8360      * <p>
8361      * Examples of UI contexts are
8362      * an {@link android.app.Activity Activity}, a context created from
8363      * {@link #createWindowContext(int, Bundle)} or
8364      * {@link android.inputmethodservice.InputMethodService InputMethodService}
8365      * </p>
8366      * <p>
8367      * Note that even if it is allowed programmatically, it is not suggested to override this
8368      * method to bypass {@link android.os.strictmode.IncorrectContextUseViolation} verification.
8369      * </p>
8370      *
8371      * @see #getDisplay()
8372      * @see #getSystemService(String)
8373      * @see android.os.StrictMode.VmPolicy.Builder#detectIncorrectContextUse()
8374      */
isUiContext()8375     public boolean isUiContext() {
8376         throw new RuntimeException("Not implemented. Must override in a subclass.");
8377     }
8378 
8379     /**
8380      * Called when a {@link Context} is going to be released.
8381      * This method can be overridden to perform the final cleanups, such as release
8382      * {@link BroadcastReceiver} registrations.
8383      *
8384      * @see WindowContext#destroy()
8385      *
8386      * @hide
8387      */
destroy()8388     public void destroy() { }
8389 
8390     /**
8391      * Indicates this {@link Context} has the proper {@link Configuration} to obtain
8392      * {@link android.view.LayoutInflater}, {@link android.view.ViewConfiguration} and
8393      * {@link android.view.GestureDetector}. Generally, all UI contexts, such as
8394      * {@link android.app.Activity} or {@link android.app.WindowContext}, are initialized with base
8395      * configuration.
8396      * <p>
8397      * Note that the context created via {@link Context#createConfigurationContext(Configuration)}
8398      * is also regarded as a context that is based on a configuration because the
8399      * configuration is explicitly provided via the API.
8400      * </p>
8401      *
8402      * @see #isUiContext()
8403      * @see #createConfigurationContext(Configuration)
8404      *
8405      * @hide
8406      */
isConfigurationContext()8407     public boolean isConfigurationContext() {
8408         throw new RuntimeException("Not implemented. Must override in a subclass.");
8409     }
8410 
8411     /**
8412      * Closes temporary system dialogs. Some examples of temporary system dialogs are the
8413      * notification window-shade and the recent tasks dialog.
8414      *
8415      * @hide
8416      */
8417     @RequiresPermission(android.Manifest.permission.BROADCAST_CLOSE_SYSTEM_DIALOGS)
closeSystemDialogs()8418     public void closeSystemDialogs() {
8419         throw new RuntimeException("Not implemented. Must override in a subclass.");
8420     }
8421 }
8422