blob: 0daa8e2517846fdc42de95a04f7fe1a0aa6daf1c [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
Tor Norbyed9273d62013-05-30 15:59:53 -070019import android.annotation.IntDef;
20import android.annotation.NonNull;
21import android.annotation.Nullable;
22import android.annotation.StringDef;
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090023import android.annotation.SystemApi;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070024import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.PackageManager;
26import android.content.res.AssetManager;
Dianne Hackborn756220b2012-08-14 16:45:30 -070027import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.content.res.Resources;
29import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070030import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.database.sqlite.SQLiteDatabase;
32import android.database.sqlite.SQLiteDatabase.CursorFactory;
33import android.graphics.Bitmap;
34import android.graphics.drawable.Drawable;
Adam Powellac695c62010-07-20 18:19:27 -070035import android.media.MediaScannerConnection.OnScanCompletedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.net.Uri;
37import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070038import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.os.Handler;
Dianne Hackbornff170242014-11-19 10:59:01 -080040import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070042import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070043import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070044import android.os.UserManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070045import android.provider.MediaStore;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.util.AttributeSet;
Craig Mautner48d0d182013-06-11 07:53:06 -070047import android.view.DisplayAdjustments;
Jeff Browna492c3a2012-08-23 19:48:44 -070048import android.view.Display;
Jon Miranda836c0a82014-08-11 12:32:26 -070049import android.view.ViewDebug;
Jeff Browna492c3a2012-08-23 19:48:44 -070050import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
52import java.io.File;
53import java.io.FileInputStream;
54import java.io.FileNotFoundException;
55import java.io.FileOutputStream;
56import java.io.IOException;
57import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070058import java.lang.annotation.Retention;
59import java.lang.annotation.RetentionPolicy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060
61/**
62 * Interface to global information about an application environment. This is
63 * an abstract class whose implementation is provided by
64 * the Android system. It
65 * allows access to application-specific resources and classes, as well as
66 * up-calls for application-level operations such as launching activities,
67 * broadcasting and receiving intents, etc.
68 */
69public abstract class Context {
70 /**
71 * File creation mode: the default mode, where the created file can only
72 * be accessed by the calling application (or all applications sharing the
73 * same user ID).
74 * @see #MODE_WORLD_READABLE
75 * @see #MODE_WORLD_WRITEABLE
76 */
77 public static final int MODE_PRIVATE = 0x0000;
78 /**
Nick Kralevich15069212013-01-09 15:54:56 -080079 * @deprecated Creating world-readable files is very dangerous, and likely
80 * to cause security holes in applications. It is strongly discouraged;
81 * instead, applications should use more formal mechanism for interactions
82 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
83 * {@link android.app.Service}. There are no guarantees that this
84 * access mode will remain on a file, such as when it goes through a
85 * backup and restore.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 * File creation mode: allow all other applications to have read access
87 * to the created file.
88 * @see #MODE_PRIVATE
89 * @see #MODE_WORLD_WRITEABLE
90 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -070091 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 public static final int MODE_WORLD_READABLE = 0x0001;
93 /**
Nick Kralevich15069212013-01-09 15:54:56 -080094 * @deprecated Creating world-writable files is very dangerous, and likely
95 * to cause security holes in applications. It is strongly discouraged;
96 * instead, applications should use more formal mechanism for interactions
97 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
98 * {@link android.app.Service}. There are no guarantees that this
99 * access mode will remain on a file, such as when it goes through a
100 * backup and restore.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 * File creation mode: allow all other applications to have write access
102 * to the created file.
103 * @see #MODE_PRIVATE
104 * @see #MODE_WORLD_READABLE
105 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700106 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 public static final int MODE_WORLD_WRITEABLE = 0x0002;
108 /**
109 * File creation mode: for use with {@link #openFileOutput}, if the file
110 * already exists then write data to the end of the existing file
111 * instead of erasing it.
112 * @see #openFileOutput
113 */
114 public static final int MODE_APPEND = 0x8000;
115
116 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800117 * SharedPreference loading flag: when set, the file on disk will
118 * be checked for modification even if the shared preferences
119 * instance is already loaded in this process. This behavior is
120 * sometimes desired in cases where the application has multiple
121 * processes, all writing to the same SharedPreferences file.
122 * Generally there are better forms of communication between
123 * processes, though.
124 *
125 * <p>This was the legacy (but undocumented) behavior in and
126 * before Gingerbread (Android 2.3) and this flag is implied when
127 * targetting such releases. For applications targetting SDK
128 * versions <em>greater than</em> Android 2.3, this flag must be
129 * explicitly set if desired.
130 *
131 * @see #getSharedPreferences
132 */
133 public static final int MODE_MULTI_PROCESS = 0x0004;
134
135 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700136 * Database open flag: when set, the database is opened with write-ahead
137 * logging enabled by default.
138 *
139 * @see #openOrCreateDatabase(String, int, CursorFactory)
140 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
141 * @see SQLiteDatabase#enableWriteAheadLogging
142 */
143 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
144
Tor Norbyed9273d62013-05-30 15:59:53 -0700145 /** @hide */
146 @IntDef(flag = true,
147 value = {
148 BIND_AUTO_CREATE,
149 BIND_AUTO_CREATE,
150 BIND_DEBUG_UNBIND,
151 BIND_NOT_FOREGROUND,
152 BIND_ABOVE_CLIENT,
153 BIND_ALLOW_OOM_MANAGEMENT,
154 BIND_WAIVE_PRIORITY
155 })
156 @Retention(RetentionPolicy.SOURCE)
157 public @interface BindServiceFlags {}
158
Jeff Brown47847f32012-03-22 19:13:11 -0700159 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 * Flag for {@link #bindService}: automatically create the service as long
161 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700162 * its {@link android.app.Service#onStartCommand}
163 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 * explicit call to {@link #startService}. Even without that, though,
165 * this still provides you with access to the service object while the
166 * service is created.
167 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700168 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
169 * not supplying this flag would also impact how important the system
170 * consider's the target service's process to be. When set, the only way
171 * for it to be raised was by binding from a service in which case it will
172 * only be important when that activity is in the foreground. Now to
173 * achieve this behavior you must explicitly supply the new flag
174 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
175 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
176 * the flags {@link #BIND_WAIVE_PRIORITY} and
177 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
178 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 */
180 public static final int BIND_AUTO_CREATE = 0x0001;
181
182 /**
183 * Flag for {@link #bindService}: include debugging help for mismatched
184 * calls to unbind. When this flag is set, the callstack of the following
185 * {@link #unbindService} call is retained, to be printed if a later
186 * incorrect unbind call is made. Note that doing this requires retaining
187 * information about the binding that was made for the lifetime of the app,
188 * resulting in a leak -- this should only be used for debugging.
189 */
190 public static final int BIND_DEBUG_UNBIND = 0x0002;
191
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800192 /**
193 * Flag for {@link #bindService}: don't allow this binding to raise
194 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700195 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800196 * as the client (so that its process will not be killable in any
197 * situation where the client is not killable), but for CPU scheduling
198 * purposes it may be left in the background. This only has an impact
199 * in the situation where the binding client is a foreground process
200 * and the target service is in a background process.
201 */
202 public static final int BIND_NOT_FOREGROUND = 0x0004;
203
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700204 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700205 * Flag for {@link #bindService}: indicates that the client application
206 * binding to this service considers the service to be more important than
207 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700208 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700209 * this is not guaranteed to be the case.
210 */
211 public static final int BIND_ABOVE_CLIENT = 0x0008;
212
213 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700214 * Flag for {@link #bindService}: allow the process hosting the bound
215 * service to go through its normal memory management. It will be
216 * treated more like a running service, allowing the system to
217 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700218 * whim it may have, and being more aggressive about making it a candidate
219 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700220 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700221 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
222
223 /**
224 * Flag for {@link #bindService}: don't impact the scheduling or
225 * memory management priority of the target service's hosting process.
226 * Allows the service's process to be managed on the background LRU list
227 * just like a regular application process in the background.
228 */
229 public static final int BIND_WAIVE_PRIORITY = 0x0020;
230
231 /**
232 * Flag for {@link #bindService}: this service is very important to
233 * the client, so should be brought to the foreground process level
234 * when the client is. Normally a process can only be raised to the
235 * visibility level by a client, even if that client is in the foreground.
236 */
237 public static final int BIND_IMPORTANT = 0x0040;
238
239 /**
240 * Flag for {@link #bindService}: If binding from an activity, allow the
241 * target service's process importance to be raised based on whether the
242 * activity is visible to the user, regardless whether another flag is
243 * used to reduce the amount that the client process's overall importance
244 * is used to impact it.
245 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700246 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
247
248 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700249 * @hide Flag for {@link #bindService}: Treat the binding as hosting
250 * an activity, an unbinding as the activity going in the background.
251 * That is, when unbinding, the process when empty will go on the activity
252 * LRU list instead of the regular one, keeping it around more aggressively
253 * than it otherwise would be. This is intended for use with IMEs to try
254 * to keep IME processes around for faster keyboard switching.
255 */
256 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
257
258 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700259 * @hide An idea that is not yet implemented.
260 * Flag for {@link #bindService}: If binding from an activity, consider
261 * this service to be visible like the binding activity is. That is,
262 * it will be treated as something more important to keep around than
263 * invisible background activities. This will impact the number of
264 * recent activities the user can switch between without having them
265 * restart. There is no guarantee this will be respected, as the system
266 * tries to balance such requests from one app vs. the importantance of
267 * keeping other apps around.
268 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700269 public static final int BIND_VISIBLE = 0x10000000;
270
271 /**
272 * @hide
273 * Flag for {@link #bindService}: Consider this binding to be causing the target
274 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
275 * away.
276 */
277 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700278
279 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700280 * Flag for {@link #bindService}: Don't consider the bound service to be
281 * visible, even if the caller is visible.
282 * @hide
283 */
284 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 /** Return an AssetManager instance for your application's package. */
287 public abstract AssetManager getAssets();
288
289 /** Return a Resources instance for your application's package. */
290 public abstract Resources getResources();
291
292 /** Return PackageManager instance to find global package information. */
293 public abstract PackageManager getPackageManager();
294
295 /** Return a ContentResolver instance for your application's package. */
296 public abstract ContentResolver getContentResolver();
297
298 /**
299 * Return the Looper for the main thread of the current process. This is
300 * the thread used to dispatch calls to application components (activities,
301 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700302 * <p>
303 * By definition, this method returns the same result as would be obtained
304 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
305 * </p>
306 *
307 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 */
309 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 /**
312 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800313 * current process. This generally should only be used if you need a
314 * Context whose lifecycle is separate from the current context, that is
315 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700316 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800317 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800318 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800319 * <ul>
320 * <li> <p>If used from an Activity context, the receiver is being registered
321 * within that activity. This means that you are expected to unregister
322 * before the activity is done being destroyed; in fact if you do not do
323 * so, the framework will clean up your leaked registration as it removes
324 * the activity and log an error. Thus, if you use the Activity context
325 * to register a receiver that is static (global to the process, not
326 * associated with an Activity instance) then that registration will be
327 * removed on you at whatever point the activity you used is destroyed.
328 * <li> <p>If used from the Context returned here, the receiver is being
329 * registered with the global state associated with your application. Thus
330 * it will never be unregistered for you. This is necessary if the receiver
331 * is associated with static data, not a particular component. However
332 * using the ApplicationContext elsewhere can easily lead to serious leaks
333 * if you forget to unregister, unbind, etc.
334 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 */
336 public abstract Context getApplicationContext();
337
338 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700339 * Add a new {@link ComponentCallbacks} to the base application of the
340 * Context, which will be called at the same times as the ComponentCallbacks
341 * methods of activities and other components are called. Note that you
342 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
343 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700344 *
345 * @param callback The interface to call. This can be either a
346 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700347 */
348 public void registerComponentCallbacks(ComponentCallbacks callback) {
349 getApplicationContext().registerComponentCallbacks(callback);
350 }
351
352 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400353 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700354 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
355 */
356 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
357 getApplicationContext().unregisterComponentCallbacks(callback);
358 }
359
360 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 * Return a localized, styled CharSequence from the application's package's
362 * default string table.
363 *
364 * @param resId Resource id for the CharSequence text
365 */
366 public final CharSequence getText(int resId) {
367 return getResources().getText(resId);
368 }
369
370 /**
371 * Return a localized string from the application's package's
372 * default string table.
373 *
374 * @param resId Resource id for the string
375 */
376 public final String getString(int resId) {
377 return getResources().getString(resId);
378 }
379
380 /**
381 * Return a localized formatted string from the application's package's
382 * default string table, substituting the format arguments as defined in
383 * {@link java.util.Formatter} and {@link java.lang.String#format}.
384 *
385 * @param resId Resource id for the format string
386 * @param formatArgs The format arguments that will be used for substitution.
387 */
388
389 public final String getString(int resId, Object... formatArgs) {
390 return getResources().getString(resId, formatArgs);
391 }
392
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800393 /**
394 * Return a drawable object associated with a particular resource ID and
395 * styled for the current theme.
396 *
397 * @param id The desired resource identifier, as generated by the aapt
398 * tool. This integer encodes the package, type, and resource
399 * entry. The value 0 is an invalid identifier.
400 * @return Drawable An object that can be used to draw this resource.
401 */
402 public final Drawable getDrawable(int id) {
403 return getResources().getDrawable(id, getTheme());
404 }
405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 /**
407 * Set the base theme for this context. Note that this should be called
408 * before any views are instantiated in the Context (for example before
409 * calling {@link android.app.Activity#setContentView} or
410 * {@link android.view.LayoutInflater#inflate}).
411 *
412 * @param resid The style resource describing the theme.
413 */
414 public abstract void setTheme(int resid);
415
Dianne Hackborn247fe742011-01-08 17:25:57 -0800416 /** @hide Needed for some internal implementation... not public because
417 * you can't assume this actually means anything. */
418 public int getThemeResId() {
419 return 0;
420 }
421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 /**
423 * Return the Theme object associated with this Context.
424 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700425 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 public abstract Resources.Theme getTheme();
427
428 /**
429 * Retrieve styled attribute information in this Context's theme. See
430 * {@link Resources.Theme#obtainStyledAttributes(int[])}
431 * for more information.
432 *
433 * @see Resources.Theme#obtainStyledAttributes(int[])
434 */
435 public final TypedArray obtainStyledAttributes(
436 int[] attrs) {
437 return getTheme().obtainStyledAttributes(attrs);
438 }
439
440 /**
441 * Retrieve styled attribute information in this Context's theme. See
442 * {@link Resources.Theme#obtainStyledAttributes(int, int[])}
443 * for more information.
444 *
445 * @see Resources.Theme#obtainStyledAttributes(int, int[])
446 */
447 public final TypedArray obtainStyledAttributes(
448 int resid, int[] attrs) throws Resources.NotFoundException {
449 return getTheme().obtainStyledAttributes(resid, attrs);
450 }
451
452 /**
453 * Retrieve styled attribute information in this Context's theme. See
454 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
455 * for more information.
456 *
457 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
458 */
459 public final TypedArray obtainStyledAttributes(
460 AttributeSet set, int[] attrs) {
461 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
462 }
463
464 /**
465 * Retrieve styled attribute information in this Context's theme. See
466 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
467 * for more information.
468 *
469 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
470 */
471 public final TypedArray obtainStyledAttributes(
472 AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) {
473 return getTheme().obtainStyledAttributes(
474 set, attrs, defStyleAttr, defStyleRes);
475 }
476
477 /**
478 * Return a class loader you can use to retrieve classes in this package.
479 */
480 public abstract ClassLoader getClassLoader();
481
482 /** Return the name of this application's package. */
483 public abstract String getPackageName();
484
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800485 /** @hide Return the name of the base context this context is derived from. */
486 public abstract String getBasePackageName();
487
Dianne Hackborn95d78532013-09-11 09:51:14 -0700488 /** @hide Return the package name that should be used for app ops calls from
489 * this context. This is the same as {@link #getBasePackageName()} except in
490 * cases where system components are loaded into other app processes, in which
491 * case this will be the name of the primary package in that process (so that app
492 * ops uid verification will work with the name). */
493 public abstract String getOpPackageName();
494
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700495 /** Return the full application info for this context's package. */
496 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 /**
Kenny Root32148392010-01-21 15:40:47 -0800499 * Return the full path to this context's primary Android package.
500 * The Android package is a ZIP file which contains the application's
501 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 *
503 * <p>Note: this is not generally useful for applications, since they should
504 * not be directly accessing the file system.
505 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 * @return String Path to the resources.
507 */
508 public abstract String getPackageResourcePath();
509
510 /**
Kenny Root32148392010-01-21 15:40:47 -0800511 * Return the full path to this context's primary Android package.
512 * The Android package is a ZIP file which contains application's
513 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 *
515 * <p>Note: this is not generally useful for applications, since they should
516 * not be directly accessing the file system.
517 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 * @return String Path to the code and assets.
519 */
520 public abstract String getPackageCodePath();
521
522 /**
Joe Onorato23ecae32009-06-10 17:07:15 -0700523 * {@hide}
524 * Return the full path to the shared prefs file for the given prefs group name.
525 *
526 * <p>Note: this is not generally useful for applications, since they should
527 * not be directly accessing the file system.
528 */
529 public abstract File getSharedPrefsFile(String name);
530
531 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 * Retrieve and hold the contents of the preferences file 'name', returning
533 * a SharedPreferences through which you can retrieve and modify its
534 * values. Only one instance of the SharedPreferences object is returned
535 * to any callers for the same name, meaning they will see each other's
536 * edits as soon as they are made.
537 *
538 * @param name Desired preferences file. If a preferences file by this name
539 * does not exist, it will be created when you retrieve an
540 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
541 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
542 * default operation, {@link #MODE_WORLD_READABLE}
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800543 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. The bit
544 * {@link #MODE_MULTI_PROCESS} can also be used if multiple processes
545 * are mutating the same SharedPreferences file. {@link #MODE_MULTI_PROCESS}
Tor Norbyed9273d62013-05-30 15:59:53 -0700546 * is always on in apps targeting Gingerbread (Android 2.3) and below, and
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800547 * off by default in later versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400549 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 * to retrieve and modify the preference values.
551 *
552 * @see #MODE_PRIVATE
553 * @see #MODE_WORLD_READABLE
554 * @see #MODE_WORLD_WRITEABLE
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800555 * @see #MODE_MULTI_PROCESS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 */
557 public abstract SharedPreferences getSharedPreferences(String name,
558 int mode);
559
560 /**
561 * Open a private file associated with this Context's application package
562 * for reading.
563 *
564 * @param name The name of the file to open; can not contain path
565 * separators.
566 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400567 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 *
569 * @see #openFileOutput
570 * @see #fileList
571 * @see #deleteFile
572 * @see java.io.FileInputStream#FileInputStream(String)
573 */
574 public abstract FileInputStream openFileInput(String name)
575 throws FileNotFoundException;
576
577 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800578 * Open a private file associated with this Context's application package
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 * for writing. Creates the file if it doesn't already exist.
580 *
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700581 * <p>No permissions are required to invoke this method, since it uses internal
582 * storage.
583 *
Nick Kralevich15069212013-01-09 15:54:56 -0800584 * @param name The name of the file to open; can not contain path
585 * separators.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Nick Kralevich15069212013-01-09 15:54:56 -0800587 * default operation, {@link #MODE_APPEND} to append to an existing file,
588 * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control
589 * permissions.
590 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400591 * @return The resulting {@link FileOutputStream}.
Nick Kralevich15069212013-01-09 15:54:56 -0800592 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 * @see #MODE_APPEND
594 * @see #MODE_PRIVATE
595 * @see #MODE_WORLD_READABLE
596 * @see #MODE_WORLD_WRITEABLE
597 * @see #openFileInput
598 * @see #fileList
599 * @see #deleteFile
600 * @see java.io.FileOutputStream#FileOutputStream(String)
601 */
602 public abstract FileOutputStream openFileOutput(String name, int mode)
603 throws FileNotFoundException;
604
605 /**
606 * Delete the given private file associated with this Context's
607 * application package.
608 *
609 * @param name The name of the file to delete; can not contain path
610 * separators.
611 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400612 * @return {@code true} if the file was successfully deleted; else
613 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 *
615 * @see #openFileInput
616 * @see #openFileOutput
617 * @see #fileList
618 * @see java.io.File#delete()
619 */
620 public abstract boolean deleteFile(String name);
621
622 /**
623 * Returns the absolute path on the filesystem where a file created with
624 * {@link #openFileOutput} is stored.
625 *
626 * @param name The name of the file for which you would like to get
627 * its path.
628 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400629 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 *
631 * @see #openFileOutput
632 * @see #getFilesDir
633 * @see #getDir
634 */
635 public abstract File getFileStreamPath(String name);
636
637 /**
638 * Returns the absolute path to the directory on the filesystem where
639 * files created with {@link #openFileOutput} are stored.
640 *
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700641 * <p>No permissions are required to read or write to the returned path, since this
642 * path is internal storage.
643 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400644 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 *
646 * @see #openFileOutput
647 * @see #getFileStreamPath
648 * @see #getDir
649 */
650 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 /**
Christopher Tatea7835b62014-07-11 17:25:57 -0700653 * Returns the absolute path to the directory on the filesystem similar to
654 * {@link #getFilesDir()}. The difference is that files placed under this
655 * directory will be excluded from automatic backup to remote storage. See
656 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
657 * of the automatic backup mechanism in Android.
658 *
659 * <p>No permissions are required to read or write to the returned path, since this
660 * path is internal storage.
661 *
662 * @return The path of the directory holding application files that will not be
663 * automatically backed up to remote storage.
664 *
665 * @see #openFileOutput
666 * @see #getFileStreamPath
667 * @see #getDir
668 * @see android.app.backup.BackupAgent
669 */
670 public abstract File getNoBackupFilesDir();
671
672 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700673 * Returns the absolute path to the directory on the primary external filesystem
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800674 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700675 * Environment.getExternalStorageDirectory()}) where the application can
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700676 * place persistent files it owns. These files are internal to the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800677 * applications, and not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700678 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800679 * <p>This is like {@link #getFilesDir()} in that these
680 * files will be deleted when the application is uninstalled, however there
681 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700682 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800683 * <ul>
684 * <li>External files are not always available: they will disappear if the
685 * user mounts the external storage on a computer or removes it. See the
686 * APIs on {@link android.os.Environment} for information in the storage state.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700687 * <li>There is no security enforced with these files. For example, any application
688 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
689 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800690 * </ul>
Scott Main4b5da682010-10-21 11:49:12 -0700691 *
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700692 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
693 * are required to read or write to the returned path; it's always
694 * accessible to the calling app. This only applies to paths generated for
695 * package name of the calling application. To access paths belonging
696 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
697 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
698 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700699 * <p>On devices with multiple users (as described by {@link UserManager}),
700 * each user has their own isolated external storage. Applications only
701 * have access to the external storage for the user they're running as.</p>
702 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800703 * <p>Here is an example of typical code to manipulate a file in
704 * an application's private storage:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700705 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800706 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
707 * private_file}
708 *
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700709 * <p>If you supply a non-null <var>type</var> to this function, the returned
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800710 * file will be a path to a sub-directory of the given type. Though these files
711 * are not automatically scanned by the media scanner, you can explicitly
712 * add them to the media database with
713 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
Ray Chenb7c8c762010-03-30 17:21:39 -0700714 * OnScanCompletedListener) MediaScannerConnection.scanFile}.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800715 * Note that this is not the same as
716 * {@link android.os.Environment#getExternalStoragePublicDirectory
717 * Environment.getExternalStoragePublicDirectory()}, which provides
718 * directories of media shared by all applications. The
719 * directories returned here are
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700720 * owned by the application, and their contents will be removed when the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800721 * application is uninstalled. Unlike
722 * {@link android.os.Environment#getExternalStoragePublicDirectory
723 * Environment.getExternalStoragePublicDirectory()}, the directory
724 * returned here will be automatically created for you.
Scott Main4b5da682010-10-21 11:49:12 -0700725 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800726 * <p>Here is an example of typical code to manipulate a picture in
727 * an application's private storage and add it to the media database:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700728 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800729 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
730 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -0700731 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800732 * @param type The type of files directory to return. May be null for
733 * the root of the files directory or one of
734 * the following Environment constants for a subdirectory:
735 * {@link android.os.Environment#DIRECTORY_MUSIC},
736 * {@link android.os.Environment#DIRECTORY_PODCASTS},
737 * {@link android.os.Environment#DIRECTORY_RINGTONES},
738 * {@link android.os.Environment#DIRECTORY_ALARMS},
739 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
740 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
741 * {@link android.os.Environment#DIRECTORY_MOVIES}.
Scott Main4b5da682010-10-21 11:49:12 -0700742 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400743 * @return The path of the directory holding application files
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800744 * on external storage. Returns null if external storage is not currently
745 * mounted so it could not ensure the path exists; you will need to call
746 * this method again when it is available.
747 *
748 * @see #getFilesDir
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700749 * @see android.os.Environment#getExternalStoragePublicDirectory
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800750 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700751 @Nullable
752 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -0700753
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800754 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700755 * Returns absolute paths to application-specific directories on all
756 * external storage devices where the application can place persistent files
757 * it owns. These files are internal to the application, and not typically
758 * visible to the user as media.
759 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700760 * This is like {@link #getFilesDir()} in that these files will be deleted when
761 * the application is uninstalled, however there are some important differences:
762 * <ul>
763 * <li>External files are not always available: they will disappear if the
764 * user mounts the external storage on a computer or removes it.
765 * <li>There is no security enforced with these files.
766 * </ul>
767 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700768 * External storage devices returned here are considered a permanent part of
769 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700770 * slots, such as SD cards in a battery compartment. The returned paths do
771 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700772 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700773 * An application may store data on any or all of the returned devices. For
774 * example, an app may choose to store large files on the device with the
775 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700776 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700777 * No permissions are required to read or write to the returned paths; they
778 * are always accessible to the calling app. Write access outside of these
779 * paths on secondary external storage devices is not available.
780 * <p>
781 * The first path returned is the same as {@link #getExternalFilesDir(String)}.
782 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey8c165792012-10-22 14:08:29 -0700783 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700784 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800785 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700786 */
787 public abstract File[] getExternalFilesDirs(String type);
788
789 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700790 * Return the primary external storage directory where this application's OBB
791 * files (if there are any) can be found. Note if the application does not have
792 * any OBB files, this directory may not exist.
793 * <p>
794 * This is like {@link #getFilesDir()} in that these files will be deleted when
795 * the application is uninstalled, however there are some important differences:
796 * <ul>
797 * <li>External files are not always available: they will disappear if the
798 * user mounts the external storage on a computer or removes it.
799 * <li>There is no security enforced with these files. For example, any application
800 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
801 * these files.
802 * </ul>
803 * <p>
804 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
805 * are required to read or write to the returned path; it's always
806 * accessible to the calling app. This only applies to paths generated for
807 * package name of the calling application. To access paths belonging
808 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
809 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700810 * <p>
811 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -0700812 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700813 * should ensure that multiple instances running under different users don't
814 * interfere with each other.
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800815 */
816 public abstract File getObbDir();
817
818 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700819 * Returns absolute paths to application-specific directories on all
820 * external storage devices where the application's OBB files (if there are
821 * any) can be found. Note if the application does not have any OBB files,
822 * these directories may not exist.
823 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700824 * This is like {@link #getFilesDir()} in that these files will be deleted when
825 * the application is uninstalled, however there are some important differences:
826 * <ul>
827 * <li>External files are not always available: they will disappear if the
828 * user mounts the external storage on a computer or removes it.
829 * <li>There is no security enforced with these files.
830 * </ul>
831 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700832 * External storage devices returned here are considered a permanent part of
833 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700834 * slots, such as SD cards in a battery compartment. The returned paths do
835 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700836 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700837 * An application may store data on any or all of the returned devices. For
838 * example, an app may choose to store large files on the device with the
839 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700840 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700841 * No permissions are required to read or write to the returned paths; they
842 * are always accessible to the calling app. Write access outside of these
843 * paths on secondary external storage devices is not available.
844 * <p>
845 * The first path returned is the same as {@link #getObbDir()}.
846 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700847 *
848 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800849 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700850 */
851 public abstract File[] getObbDirs();
852
853 /**
Scott Main4b5da682010-10-21 11:49:12 -0700854 * Returns the absolute path to the application specific cache directory
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 * on the filesystem. These files will be ones that get deleted first when the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800856 * device runs low on storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 * There is no guarantee when these files will be deleted.
Scott Main4b5da682010-10-21 11:49:12 -0700858 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800859 * <strong>Note: you should not <em>rely</em> on the system deleting these
860 * files for you; you should always have a reasonable maximum, such as 1 MB,
861 * for the amount of space you consume with cache files, and prune those
862 * files when exceeding that space.</strong>
Scott Main4b5da682010-10-21 11:49:12 -0700863 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400864 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 *
866 * @see #openFileOutput
867 * @see #getFileStreamPath
868 * @see #getDir
869 */
870 public abstract File getCacheDir();
871
872 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -0700873 * Returns the absolute path to the application specific cache directory on
874 * the filesystem designed for storing cached code. The system will delete
875 * any files stored in this location both when your specific application is
876 * upgraded, and when the entire platform is upgraded.
877 * <p>
878 * This location is optimal for storing compiled or optimized code generated
879 * by your application at runtime.
880 * <p>
881 * Apps require no extra permissions to read or write to the returned path,
882 * since this path lives in their private storage.
883 *
884 * @return The path of the directory holding application code cache files.
885 */
886 public abstract File getCodeCacheDir();
887
888 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700889 * Returns the absolute path to the directory on the primary external filesystem
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800890 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
891 * Environment.getExternalStorageDirectory()} where the application can
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700892 * place cache files it owns. These files are internal to the application, and
893 * not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700894 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800895 * <p>This is like {@link #getCacheDir()} in that these
896 * files will be deleted when the application is uninstalled, however there
897 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700898 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800899 * <ul>
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700900 * <li>The platform does not always monitor the space available in external
901 * storage, and thus may not automatically delete these files. Currently
902 * the only time files here will be deleted by the platform is when running
903 * on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
904 * {@link android.os.Environment#isExternalStorageEmulated()
905 * Environment.isExternalStorageEmulated()} returns true. Note that you should
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800906 * be managing the maximum space you will use for these anyway, just like
907 * with {@link #getCacheDir()}.
908 * <li>External files are not always available: they will disappear if the
909 * user mounts the external storage on a computer or removes it. See the
910 * APIs on {@link android.os.Environment} for information in the storage state.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700911 * <li>There is no security enforced with these files. For example, any application
912 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
913 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800914 * </ul>
915 *
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700916 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
917 * are required to read or write to the returned path; it's always
918 * accessible to the calling app. This only applies to paths generated for
919 * package name of the calling application. To access paths belonging
920 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
921 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
922 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700923 * <p>On devices with multiple users (as described by {@link UserManager}),
924 * each user has their own isolated external storage. Applications only
925 * have access to the external storage for the user they're running as.</p>
Jeff Sharkey8c165792012-10-22 14:08:29 -0700926 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400927 * @return The path of the directory holding application cache files
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800928 * on external storage. Returns null if external storage is not currently
929 * mounted so it could not ensure the path exists; you will need to call
930 * this method again when it is available.
931 *
932 * @see #getCacheDir
933 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700934 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800935 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -0700936
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800937 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700938 * Returns absolute paths to application-specific directories on all
939 * external storage devices where the application can place cache files it
940 * owns. These files are internal to the application, and not typically
941 * visible to the user as media.
942 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700943 * This is like {@link #getCacheDir()} in that these files will be deleted when
944 * the application is uninstalled, however there are some important differences:
945 * <ul>
946 * <li>External files are not always available: they will disappear if the
947 * user mounts the external storage on a computer or removes it.
948 * <li>There is no security enforced with these files.
949 * </ul>
950 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700951 * External storage devices returned here are considered a permanent part of
952 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700953 * slots, such as SD cards in a battery compartment. The returned paths do
954 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700955 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700956 * An application may store data on any or all of the returned devices. For
957 * example, an app may choose to store large files on the device with the
958 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700959 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700960 * No permissions are required to read or write to the returned paths; they
961 * are always accessible to the calling app. Write access outside of these
962 * paths on secondary external storage devices is not available.
963 * <p>
964 * The first path returned is the same as {@link #getExternalCacheDir()}.
965 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700966 *
967 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800968 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700969 */
970 public abstract File[] getExternalCacheDirs();
971
972 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -0700973 * Returns absolute paths to application-specific directories on all
974 * external storage devices where the application can place media files.
975 * These files are scanned and made available to other apps through
976 * {@link MediaStore}.
977 * <p>
978 * This is like {@link #getExternalFilesDirs} in that these files will be
979 * deleted when the application is uninstalled, however there are some
980 * important differences:
981 * <ul>
982 * <li>External files are not always available: they will disappear if the
983 * user mounts the external storage on a computer or removes it.
984 * <li>There is no security enforced with these files.
985 * </ul>
986 * <p>
987 * External storage devices returned here are considered a permanent part of
988 * the device, including both emulated external storage and physical media
989 * slots, such as SD cards in a battery compartment. The returned paths do
990 * not include transient devices, such as USB flash drives.
991 * <p>
992 * An application may store data on any or all of the returned devices. For
993 * example, an app may choose to store large files on the device with the
994 * most available space, as measured by {@link StatFs}.
995 * <p>
996 * No permissions are required to read or write to the returned paths; they
997 * are always accessible to the calling app. Write access outside of these
998 * paths on secondary external storage devices is not available.
999 * <p>
1000 * Returned paths may be {@code null} if a storage device is unavailable.
1001 *
1002 * @see Environment#getExternalStorageState(File)
1003 */
1004 public abstract File[] getExternalMediaDirs();
1005
1006 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 * Returns an array of strings naming the private files associated with
1008 * this Context's application package.
1009 *
1010 * @return Array of strings naming the private files.
1011 *
1012 * @see #openFileInput
1013 * @see #openFileOutput
1014 * @see #deleteFile
1015 */
1016 public abstract String[] fileList();
1017
1018 /**
1019 * Retrieve, creating if needed, a new directory in which the application
1020 * can place its own custom data files. You can use the returned File
1021 * object to create and access files in this directory. Note that files
1022 * created through a File object will only be accessible by your own
1023 * application; you can only set the mode of the entire directory, not
1024 * of individual files.
1025 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001026 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001027 * that is created as part of your application data.
Nick Kralevich92091fa2012-12-12 16:24:31 -08001028 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Nick Kralevich15069212013-01-09 15:54:56 -08001029 * default operation, {@link #MODE_WORLD_READABLE} and
1030 * {@link #MODE_WORLD_WRITEABLE} to control permissions.
1031 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001032 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001033 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 *
1035 * @see #openFileOutput(String, int)
1036 */
1037 public abstract File getDir(String name, int mode);
1038
1039 /**
1040 * Open a new private SQLiteDatabase associated with this Context's
1041 * application package. Create the database file if it doesn't exist.
1042 *
1043 * @param name The name (unique in the application package) of the database.
1044 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1045 * default operation, {@link #MODE_WORLD_READABLE}
1046 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -07001047 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 * @param factory An optional factory class that is called to instantiate a
1049 * cursor when query is called.
Nick Kralevich15069212013-01-09 15:54:56 -08001050 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 * @return The contents of a newly created database with the given name.
1052 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
Nick Kralevich15069212013-01-09 15:54:56 -08001053 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 * @see #MODE_PRIVATE
1055 * @see #MODE_WORLD_READABLE
1056 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -07001057 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 * @see #deleteDatabase
1059 */
1060 public abstract SQLiteDatabase openOrCreateDatabase(String name,
1061 int mode, CursorFactory factory);
1062
1063 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001064 * Open a new private SQLiteDatabase associated with this Context's
1065 * application package. Creates the database file if it doesn't exist.
1066 *
1067 * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be
1068 * used to handle corruption when sqlite reports database corruption.</p>
1069 *
1070 * @param name The name (unique in the application package) of the database.
1071 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1072 * default operation, {@link #MODE_WORLD_READABLE}
1073 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -07001074 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
Vasu Nori74f170f2010-06-01 18:06:18 -07001075 * @param factory An optional factory class that is called to instantiate a
1076 * cursor when query is called.
1077 * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database
Nick Kralevich15069212013-01-09 15:54:56 -08001078 * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001079 * @return The contents of a newly created database with the given name.
1080 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
Nick Kralevich15069212013-01-09 15:54:56 -08001081 *
Vasu Nori74f170f2010-06-01 18:06:18 -07001082 * @see #MODE_PRIVATE
1083 * @see #MODE_WORLD_READABLE
1084 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -07001085 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Vasu Nori74f170f2010-06-01 18:06:18 -07001086 * @see #deleteDatabase
1087 */
1088 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Tor Norbyed9273d62013-05-30 15:59:53 -07001089 int mode, CursorFactory factory,
1090 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001091
1092 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 * Delete an existing private SQLiteDatabase associated with this Context's
1094 * application package.
1095 *
1096 * @param name The name (unique in the application package) of the
1097 * database.
1098 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001099 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 *
1101 * @see #openOrCreateDatabase
1102 */
1103 public abstract boolean deleteDatabase(String name);
1104
1105 /**
1106 * Returns the absolute path on the filesystem where a database created with
1107 * {@link #openOrCreateDatabase} is stored.
1108 *
1109 * @param name The name of the database for which you would like to get
1110 * its path.
1111 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001112 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 *
1114 * @see #openOrCreateDatabase
1115 */
1116 public abstract File getDatabasePath(String name);
1117
1118 /**
1119 * Returns an array of strings naming the private databases associated with
1120 * this Context's application package.
1121 *
1122 * @return Array of strings naming the private databases.
1123 *
1124 * @see #openOrCreateDatabase
1125 * @see #deleteDatabase
1126 */
1127 public abstract String[] databaseList();
1128
1129 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001130 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001131 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001133 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 public abstract Drawable getWallpaper();
1135
1136 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001137 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001138 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001140 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 public abstract Drawable peekWallpaper();
1142
1143 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001144 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1145 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001147 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 public abstract int getWallpaperDesiredMinimumWidth();
1149
1150 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001151 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1152 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001153 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001154 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 public abstract int getWallpaperDesiredMinimumHeight();
1156
1157 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001158 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001159 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001160 * <p>This method requires the caller to hold the permission
1161 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001162 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001163 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1165
1166 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001167 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001168 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001169 * <p>This method requires the caller to hold the permission
1170 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001172 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 public abstract void setWallpaper(InputStream data) throws IOException;
1174
1175 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001176 * @deprecated Use {@link android.app.WallpaperManager#clear
1177 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001178 * <p>This method requires the caller to hold the permission
1179 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001181 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 public abstract void clearWallpaper() throws IOException;
1183
1184 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001185 * Same as {@link #startActivity(Intent, Bundle)} with no options
1186 * specified.
1187 *
1188 * @param intent The description of the activity to start.
1189 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001190 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001191 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001192 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001193 * @see PackageManager#resolveActivity
1194 */
1195 public abstract void startActivity(Intent intent);
1196
1197 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001198 * Version of {@link #startActivity(Intent)} that allows you to specify the
1199 * user the activity will be started for. This is not available to applications
1200 * that are not pre-installed on the system image. Using it requires holding
1201 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani82644082012-08-03 13:09:11 -07001202 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001203 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001204 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001205 * @hide
1206 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001207 public void startActivityAsUser(Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001208 throw new RuntimeException("Not implemented. Must override in a subclass.");
1209 }
1210
1211 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 * Launch a new activity. You will not receive any information about when
1213 * the activity exits.
1214 *
1215 * <p>Note that if this method is being called from outside of an
1216 * {@link android.app.Activity} Context, then the Intent must include
1217 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1218 * without being started from an existing Activity, there is no existing
1219 * task in which to place the new activity and thus it needs to be placed
1220 * in its own separate task.
1221 *
1222 * <p>This method throws {@link ActivityNotFoundException}
1223 * if there was no Activity found to run the given Intent.
1224 *
1225 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001226 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001227 * May be null if there are no options. See {@link android.app.ActivityOptions}
1228 * for how to build the Bundle supplied here; there are no supported definitions
1229 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001231 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 *
Scott Main60dd5202012-06-23 00:01:22 -07001233 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 * @see PackageManager#resolveActivity
1235 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001236 public abstract void startActivity(Intent intent, @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001237
1238 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001239 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1240 * user the activity will be started for. This is not available to applications
1241 * that are not pre-installed on the system image. Using it requires holding
1242 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001243 * @param intent The description of the activity to start.
1244 * @param options Additional options for how the Activity should be started.
1245 * May be null if there are no options. See {@link android.app.ActivityOptions}
1246 * for how to build the Bundle supplied here; there are no supported definitions
1247 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001248 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001249 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001250 * @hide
1251 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001252 public void startActivityAsUser(Intent intent, @Nullable Bundle options, UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001253 throw new RuntimeException("Not implemented. Must override in a subclass.");
1254 }
1255
1256 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001257 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1258 * specified.
1259 *
1260 * @param intents An array of Intents to be started.
1261 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001262 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001263 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001264 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001265 * @see PackageManager#resolveActivity
1266 */
1267 public abstract void startActivities(Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268
1269 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001270 * Launch multiple new activities. This is generally the same as calling
1271 * {@link #startActivity(Intent)} for the first Intent in the array,
1272 * that activity during its creation calling {@link #startActivity(Intent)}
1273 * for the second entry, etc. Note that unlike that approach, generally
1274 * none of the activities except the last in the array will be created
1275 * at this point, but rather will be created when the user first visits
1276 * them (due to pressing back from the activity on top).
1277 *
1278 * <p>This method throws {@link ActivityNotFoundException}
1279 * if there was no Activity found for <em>any</em> given Intent. In this
1280 * case the state of the activity stack is undefined (some Intents in the
1281 * list may be on it, some not), so you probably want to avoid such situations.
1282 *
1283 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001284 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001285 * See {@link android.content.Context#startActivity(Intent, Bundle)
1286 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001287 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001288 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001289 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001290 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001291 * @see PackageManager#resolveActivity
1292 */
Dianne Hackborna4972e92012-03-14 10:38:05 -07001293 public abstract void startActivities(Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001294
1295 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001296 * @hide
1297 * Launch multiple new activities. This is generally the same as calling
1298 * {@link #startActivity(Intent)} for the first Intent in the array,
1299 * that activity during its creation calling {@link #startActivity(Intent)}
1300 * for the second entry, etc. Note that unlike that approach, generally
1301 * none of the activities except the last in the array will be created
1302 * at this point, but rather will be created when the user first visits
1303 * them (due to pressing back from the activity on top).
1304 *
1305 * <p>This method throws {@link ActivityNotFoundException}
1306 * if there was no Activity found for <em>any</em> given Intent. In this
1307 * case the state of the activity stack is undefined (some Intents in the
1308 * list may be on it, some not), so you probably want to avoid such situations.
1309 *
1310 * @param intents An array of Intents to be started.
1311 * @param options Additional options for how the Activity should be started.
1312 * @param userHandle The user for whom to launch the activities
1313 * See {@link android.content.Context#startActivity(Intent, Bundle)
1314 * Context.startActivity(Intent, Bundle)} for more details.
1315 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001316 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001317 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001318 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001319 * @see PackageManager#resolveActivity
1320 */
1321 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1322 throw new RuntimeException("Not implemented. Must override in a subclass.");
1323 }
1324
1325 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001326 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1327 * with no options specified.
1328 *
1329 * @param intent The IntentSender to launch.
1330 * @param fillInIntent If non-null, this will be provided as the
1331 * intent parameter to {@link IntentSender#sendIntent}.
1332 * @param flagsMask Intent flags in the original IntentSender that you
1333 * would like to change.
1334 * @param flagsValues Desired values for any bits set in
1335 * <var>flagsMask</var>
1336 * @param extraFlags Always set to 0.
1337 *
1338 * @see #startActivity(Intent)
1339 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1340 */
1341 public abstract void startIntentSender(IntentSender intent,
1342 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1343 throws IntentSender.SendIntentException;
1344
1345 /**
1346 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001347 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001348 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001349 * here; otherwise, its associated action will be executed (such as
1350 * sending a broadcast) as if you had called
1351 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001352 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001353 * @param intent The IntentSender to launch.
1354 * @param fillInIntent If non-null, this will be provided as the
1355 * intent parameter to {@link IntentSender#sendIntent}.
1356 * @param flagsMask Intent flags in the original IntentSender that you
1357 * would like to change.
1358 * @param flagsValues Desired values for any bits set in
1359 * <var>flagsMask</var>
1360 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001361 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001362 * See {@link android.content.Context#startActivity(Intent, Bundle)
1363 * Context.startActivity(Intent, Bundle)} for more details. If options
1364 * have also been supplied by the IntentSender, options given here will
1365 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001366 *
1367 * @see #startActivity(Intent, Bundle)
1368 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001369 */
1370 public abstract void startIntentSender(IntentSender intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001371 @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
Dianne Hackborna4972e92012-03-14 10:38:05 -07001372 Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001373
1374 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 * Broadcast the given intent to all interested BroadcastReceivers. This
1376 * call is asynchronous; it returns immediately, and you will continue
1377 * executing while the receivers are run. No results are propagated from
1378 * receivers and receivers can not abort the broadcast. If you want
1379 * to allow receivers to propagate results or abort the broadcast, you must
1380 * send an ordered broadcast using
1381 * {@link #sendOrderedBroadcast(Intent, String)}.
1382 *
1383 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1384 *
1385 * @param intent The Intent to broadcast; all receivers matching this
1386 * Intent will receive the broadcast.
1387 *
1388 * @see android.content.BroadcastReceiver
1389 * @see #registerReceiver
1390 * @see #sendBroadcast(Intent, String)
1391 * @see #sendOrderedBroadcast(Intent, String)
1392 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1393 */
1394 public abstract void sendBroadcast(Intent intent);
1395
1396 /**
1397 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1398 * an optional required permission to be enforced. This
1399 * call is asynchronous; it returns immediately, and you will continue
1400 * executing while the receivers are run. No results are propagated from
1401 * receivers and receivers can not abort the broadcast. If you want
1402 * to allow receivers to propagate results or abort the broadcast, you must
1403 * send an ordered broadcast using
1404 * {@link #sendOrderedBroadcast(Intent, String)}.
1405 *
1406 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1407 *
1408 * @param intent The Intent to broadcast; all receivers matching this
1409 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001410 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001411 * a receiver must hold in order to receive your broadcast.
1412 * If null, no permission is required.
1413 *
1414 * @see android.content.BroadcastReceiver
1415 * @see #registerReceiver
1416 * @see #sendBroadcast(Intent)
1417 * @see #sendOrderedBroadcast(Intent, String)
1418 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1419 */
1420 public abstract void sendBroadcast(Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001421 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422
1423 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001424 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001425 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001426 * @hide
1427 */
1428 public abstract void sendBroadcast(Intent intent,
1429 String receiverPermission, int appOp);
1430
1431 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1433 * them one at a time to allow more preferred receivers to consume the
1434 * broadcast before it is delivered to less preferred receivers. This
1435 * call is asynchronous; it returns immediately, and you will continue
1436 * executing while the receivers are run.
1437 *
1438 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1439 *
1440 * @param intent The Intent to broadcast; all receivers matching this
1441 * Intent will receive the broadcast.
1442 * @param receiverPermission (optional) String naming a permissions that
1443 * a receiver must hold in order to receive your broadcast.
1444 * If null, no permission is required.
1445 *
1446 * @see android.content.BroadcastReceiver
1447 * @see #registerReceiver
1448 * @see #sendBroadcast(Intent)
1449 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1450 */
1451 public abstract void sendOrderedBroadcast(Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001452 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453
1454 /**
1455 * Version of {@link #sendBroadcast(Intent)} that allows you to
1456 * receive data back from the broadcast. This is accomplished by
1457 * supplying your own BroadcastReceiver when calling, which will be
1458 * treated as a final receiver at the end of the broadcast -- its
1459 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001460 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 * be serialized in the same way as calling
1462 * {@link #sendOrderedBroadcast(Intent, String)}.
1463 *
1464 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1465 * asynchronous; it will return before
1466 * resultReceiver.onReceive() is called.
1467 *
1468 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1469 *
1470 * @param intent The Intent to broadcast; all receivers matching this
1471 * Intent will receive the broadcast.
1472 * @param receiverPermission String naming a permissions that
1473 * a receiver must hold in order to receive your broadcast.
1474 * If null, no permission is required.
1475 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1476 * receiver of the broadcast.
1477 * @param scheduler A custom Handler with which to schedule the
1478 * resultReceiver callback; if null it will be
1479 * scheduled in the Context's main thread.
1480 * @param initialCode An initial value for the result code. Often
1481 * Activity.RESULT_OK.
1482 * @param initialData An initial value for the result data. Often
1483 * null.
1484 * @param initialExtras An initial value for the result extras. Often
1485 * null.
1486 *
1487 * @see #sendBroadcast(Intent)
1488 * @see #sendBroadcast(Intent, String)
1489 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 * @see android.content.BroadcastReceiver
1491 * @see #registerReceiver
1492 * @see android.app.Activity#RESULT_OK
1493 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001494 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
1495 @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1496 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1497 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498
1499 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001500 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1501 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001502 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001503 * @hide
1504 */
1505 public abstract void sendOrderedBroadcast(Intent intent,
1506 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1507 Handler scheduler, int initialCode, String initialData,
1508 Bundle initialExtras);
1509
1510 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001511 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
1512 * user the broadcast will be sent to. This is not available to applications
1513 * that are not pre-installed on the system image. Using it requires holding
1514 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001515 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001516 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001517 * @see #sendBroadcast(Intent)
1518 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001519 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001520
1521 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001522 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
1523 * user the broadcast will be sent to. This is not available to applications
1524 * that are not pre-installed on the system image. Using it requires holding
1525 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001526 *
1527 * @param intent The Intent to broadcast; all receivers matching this
1528 * Intent will receive the broadcast.
1529 * @param user UserHandle to send the intent to.
1530 * @param receiverPermission (optional) String naming a permission that
1531 * a receiver must hold in order to receive your broadcast.
1532 * If null, no permission is required.
1533 *
1534 * @see #sendBroadcast(Intent, String)
1535 */
1536 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user,
Tor Norbyed9273d62013-05-30 15:59:53 -07001537 @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001538
1539 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001540 * Version of
1541 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
1542 * that allows you to specify the
1543 * user the broadcast will be sent to. This is not available to applications
1544 * that are not pre-installed on the system image. Using it requires holding
1545 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001546 *
1547 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1548 *
1549 * @param intent The Intent to broadcast; all receivers matching this
1550 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001551 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001552 * @param receiverPermission String naming a permissions that
1553 * a receiver must hold in order to receive your broadcast.
1554 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001555 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1556 * receiver of the broadcast.
1557 * @param scheduler A custom Handler with which to schedule the
1558 * resultReceiver callback; if null it will be
1559 * scheduled in the Context's main thread.
1560 * @param initialCode An initial value for the result code. Often
1561 * Activity.RESULT_OK.
1562 * @param initialData An initial value for the result data. Often
1563 * null.
1564 * @param initialExtras An initial value for the result extras. Often
1565 * null.
1566 *
1567 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1568 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001569 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Tor Norbyed9273d62013-05-30 15:59:53 -07001570 @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1571 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1572 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001573
1574 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07001575 * Similar to above but takes an appOp as well, to enforce restrictions.
1576 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
1577 * BroadcastReceiver, Handler, int, String, Bundle)
1578 * @hide
1579 */
1580 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
1581 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1582 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1583 @Nullable Bundle initialExtras);
1584
1585 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001586 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 * Intent you are sending stays around after the broadcast is complete,
1588 * so that others can quickly retrieve that data through the return
1589 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
1590 * all other ways, this behaves the same as
1591 * {@link #sendBroadcast(Intent)}.
1592 *
1593 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1594 * permission in order to use this API. If you do not hold that
1595 * permission, {@link SecurityException} will be thrown.
1596 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001597 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1598 * can access them), no protection (anyone can modify them), and many other problems.
1599 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1600 * has changed, with another mechanism for apps to retrieve the current value whenever
1601 * desired.
1602 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 * @param intent The Intent to broadcast; all receivers matching this
1604 * Intent will receive the broadcast, and the Intent will be held to
1605 * be re-broadcast to future receivers.
1606 *
1607 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001608 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001610 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 public abstract void sendStickyBroadcast(Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07001612
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001613 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001614 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001615 * receive data back from the broadcast. This is accomplished by
1616 * supplying your own BroadcastReceiver when calling, which will be
1617 * treated as a final receiver at the end of the broadcast -- its
1618 * {@link BroadcastReceiver#onReceive} method will be called with
1619 * the result values collected from the other receivers. The broadcast will
1620 * be serialized in the same way as calling
1621 * {@link #sendOrderedBroadcast(Intent, String)}.
1622 *
1623 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1624 * asynchronous; it will return before
1625 * resultReceiver.onReceive() is called. Note that the sticky data
1626 * stored is only the data you initially supply to the broadcast, not
1627 * the result of any changes made by the receivers.
1628 *
1629 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1630 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001631 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1632 * can access them), no protection (anyone can modify them), and many other problems.
1633 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1634 * has changed, with another mechanism for apps to retrieve the current value whenever
1635 * desired.
1636 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001637 * @param intent The Intent to broadcast; all receivers matching this
1638 * Intent will receive the broadcast.
1639 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1640 * receiver of the broadcast.
1641 * @param scheduler A custom Handler with which to schedule the
1642 * resultReceiver callback; if null it will be
1643 * scheduled in the Context's main thread.
1644 * @param initialCode An initial value for the result code. Often
1645 * Activity.RESULT_OK.
1646 * @param initialData An initial value for the result data. Often
1647 * null.
1648 * @param initialExtras An initial value for the result extras. Often
1649 * null.
1650 *
1651 * @see #sendBroadcast(Intent)
1652 * @see #sendBroadcast(Intent, String)
1653 * @see #sendOrderedBroadcast(Intent, String)
1654 * @see #sendStickyBroadcast(Intent)
1655 * @see android.content.BroadcastReceiver
1656 * @see #registerReceiver
1657 * @see android.app.Activity#RESULT_OK
1658 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001659 @Deprecated
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001660 public abstract void sendStickyOrderedBroadcast(Intent intent,
1661 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001662 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1663 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001665 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001666 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001667 * so that it is as if the sticky broadcast had never happened.
1668 *
1669 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1670 * permission in order to use this API. If you do not hold that
1671 * permission, {@link SecurityException} will be thrown.
1672 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001673 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1674 * can access them), no protection (anyone can modify them), and many other problems.
1675 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1676 * has changed, with another mechanism for apps to retrieve the current value whenever
1677 * desired.
1678 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679 * @param intent The Intent that was previously broadcast.
1680 *
1681 * @see #sendStickyBroadcast
1682 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001683 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001684 public abstract void removeStickyBroadcast(Intent intent);
1685
1686 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001687 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07001688 * user the broadcast will be sent to. This is not available to applications
1689 * that are not pre-installed on the system image. Using it requires holding
1690 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001691 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001692 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1693 * can access them), no protection (anyone can modify them), and many other problems.
1694 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1695 * has changed, with another mechanism for apps to retrieve the current value whenever
1696 * desired.
1697 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001698 * @param intent The Intent to broadcast; all receivers matching this
1699 * Intent will receive the broadcast, and the Intent will be held to
1700 * be re-broadcast to future receivers.
1701 * @param user UserHandle to send the intent to.
1702 *
1703 * @see #sendBroadcast(Intent)
1704 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001705 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001706 public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user);
1707
1708 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001709 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07001710 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
1711 * that allows you to specify the
1712 * user the broadcast will be sent to. This is not available to applications
1713 * that are not pre-installed on the system image. Using it requires holding
1714 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001715 *
1716 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1717 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001718 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1719 * can access them), no protection (anyone can modify them), and many other problems.
1720 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1721 * has changed, with another mechanism for apps to retrieve the current value whenever
1722 * desired.
1723 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001724 * @param intent The Intent to broadcast; all receivers matching this
1725 * Intent will receive the broadcast.
1726 * @param user UserHandle to send the intent to.
1727 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1728 * receiver of the broadcast.
1729 * @param scheduler A custom Handler with which to schedule the
1730 * resultReceiver callback; if null it will be
1731 * scheduled in the Context's main thread.
1732 * @param initialCode An initial value for the result code. Often
1733 * Activity.RESULT_OK.
1734 * @param initialData An initial value for the result data. Often
1735 * null.
1736 * @param initialExtras An initial value for the result extras. Often
1737 * null.
1738 *
1739 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1740 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001741 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001742 public abstract void sendStickyOrderedBroadcastAsUser(Intent intent,
1743 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001744 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1745 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001746
1747 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001748 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07001749 * user the broadcast will be sent to. This is not available to applications
1750 * that are not pre-installed on the system image. Using it requires holding
1751 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001752 *
1753 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1754 * permission in order to use this API. If you do not hold that
1755 * permission, {@link SecurityException} will be thrown.
1756 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001757 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1758 * can access them), no protection (anyone can modify them), and many other problems.
1759 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1760 * has changed, with another mechanism for apps to retrieve the current value whenever
1761 * desired.
1762 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001763 * @param intent The Intent that was previously broadcast.
1764 * @param user UserHandle to remove the sticky broadcast from.
1765 *
1766 * @see #sendStickyBroadcastAsUser
1767 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001768 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001769 public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user);
1770
1771 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07001772 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001773 * <var>receiver</var> will be called with any broadcast Intent that
1774 * matches <var>filter</var>, in the main application thread.
1775 *
1776 * <p>The system may broadcast Intents that are "sticky" -- these stay
1777 * around after the broadcast as finished, to be sent to any later
1778 * registrations. If your IntentFilter matches one of these sticky
1779 * Intents, that Intent will be returned by this function
1780 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
1781 * been broadcast.
1782 *
1783 * <p>There may be multiple sticky Intents that match <var>filter</var>,
1784 * in which case each of these will be sent to <var>receiver</var>. In
1785 * this case, only one of these can be returned directly by the function;
1786 * which of these that is returned is arbitrarily decided by the system.
1787 *
1788 * <p>If you know the Intent your are registering for is sticky, you can
1789 * supply null for your <var>receiver</var>. In this case, no receiver is
1790 * registered -- the function simply returns the sticky Intent that
1791 * matches <var>filter</var>. In the case of multiple matches, the same
1792 * rules as described above apply.
1793 *
1794 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1795 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001796 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1797 * registered with this method will correctly respect the
1798 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1799 * Prior to that, it would be ignored and delivered to all matching registered
1800 * receivers. Be careful if using this for security.</p>
1801 *
Chris Tatea34df8a22009-04-02 23:15:58 -07001802 * <p class="note">Note: this method <em>cannot be called from a
1803 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
1804 * that is declared in an application's manifest. It is okay, however, to call
1805 * this method from another BroadcastReceiver that has itself been registered
1806 * at run time with {@link #registerReceiver}, since the lifetime of such a
1807 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 *
1809 * @param receiver The BroadcastReceiver to handle the broadcast.
1810 * @param filter Selects the Intent broadcasts to be received.
1811 *
1812 * @return The first sticky intent found that matches <var>filter</var>,
1813 * or null if there are none.
1814 *
1815 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1816 * @see #sendBroadcast
1817 * @see #unregisterReceiver
1818 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001819 @Nullable
1820 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001821 IntentFilter filter);
1822
1823 /**
1824 * Register to receive intent broadcasts, to run in the context of
1825 * <var>scheduler</var>. See
1826 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
1827 * information. This allows you to enforce permissions on who can
1828 * broadcast intents to your receiver, or have the receiver run in
1829 * a different thread than the main application thread.
1830 *
1831 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1832 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001833 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1834 * registered with this method will correctly respect the
1835 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1836 * Prior to that, it would be ignored and delivered to all matching registered
1837 * receivers. Be careful if using this for security.</p>
1838 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 * @param receiver The BroadcastReceiver to handle the broadcast.
1840 * @param filter Selects the Intent broadcasts to be received.
1841 * @param broadcastPermission String naming a permissions that a
1842 * broadcaster must hold in order to send an Intent to you. If null,
1843 * no permission is required.
1844 * @param scheduler Handler identifying the thread that will receive
1845 * the Intent. If null, the main thread of the process will be used.
1846 *
1847 * @return The first sticky intent found that matches <var>filter</var>,
1848 * or null if there are none.
1849 *
1850 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1851 * @see #sendBroadcast
1852 * @see #unregisterReceiver
1853 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001854 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001855 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001856 IntentFilter filter, @Nullable String broadcastPermission,
1857 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07001858
1859 /**
1860 * @hide
1861 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1862 * but for a specific user. This receiver will receiver broadcasts that
1863 * are sent to the requested user. It
1864 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
1865 * permission.
1866 *
1867 * @param receiver The BroadcastReceiver to handle the broadcast.
1868 * @param user UserHandle to send the intent to.
1869 * @param filter Selects the Intent broadcasts to be received.
1870 * @param broadcastPermission String naming a permissions that a
1871 * broadcaster must hold in order to send an Intent to you. If null,
1872 * no permission is required.
1873 * @param scheduler Handler identifying the thread that will receive
1874 * the Intent. If null, the main thread of the process will be used.
1875 *
1876 * @return The first sticky intent found that matches <var>filter</var>,
1877 * or null if there are none.
1878 *
1879 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler
1880 * @see #sendBroadcast
1881 * @see #unregisterReceiver
1882 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001883 @Nullable
Dianne Hackborn20e80982012-08-31 19:00:44 -07001884 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001885 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
1886 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887
1888 /**
1889 * Unregister a previously registered BroadcastReceiver. <em>All</em>
1890 * filters that have been registered for this BroadcastReceiver will be
1891 * removed.
1892 *
1893 * @param receiver The BroadcastReceiver to unregister.
1894 *
1895 * @see #registerReceiver
1896 */
1897 public abstract void unregisterReceiver(BroadcastReceiver receiver);
1898
1899 /**
1900 * Request that a given application service be started. The Intent
Dianne Hackborn221ea892013-08-04 16:50:16 -07001901 * should contain either contain the complete class name of a specific service
1902 * implementation to start or a specific package name to target. If the
Dianne Hackborn6bc37892013-10-03 11:05:14 -07001903 * Intent is less specified, it log a warning about this and which of the
1904 * multiple matching services it finds and uses will be undefined. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001905 * is not already running, it will be instantiated and started (creating a
1906 * process for it if needed); if it is running then it remains running.
1907 *
1908 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07001909 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 * with the <var>intent</var> given here. This provides a convenient way
1911 * to submit jobs to a service without having to bind and call on to its
1912 * interface.
1913 *
1914 * <p>Using startService() overrides the default service lifetime that is
1915 * managed by {@link #bindService}: it requires the service to remain
1916 * running until {@link #stopService} is called, regardless of whether
1917 * any clients are connected to it. Note that calls to startService()
1918 * are not nesting: no matter how many times you call startService(),
1919 * a single call to {@link #stopService} will stop it.
1920 *
1921 * <p>The system attempts to keep running services around as much as
1922 * possible. The only time they should be stopped is if the current
1923 * foreground application is using so many resources that the service needs
1924 * to be killed. If any errors happen in the service's process, it will
1925 * automatically be restarted.
1926 *
1927 * <p>This function will throw {@link SecurityException} if you do not
1928 * have permission to start the given service.
1929 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07001930 * @param service Identifies the service to be started. The Intent must be either
1931 * fully explicit (supplying a component name) or specify a specific package
1932 * name it is targetted to. Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001933 * may be included in the Intent extras to supply arguments along with
1934 * this specific start call.
1935 *
1936 * @return If the service is being started or is already running, the
1937 * {@link ComponentName} of the actual service that was started is
1938 * returned; else if the service does not exist null is returned.
1939 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001940 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001941 *
1942 * @see #stopService
1943 * @see #bindService
1944 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001945 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946 public abstract ComponentName startService(Intent service);
1947
1948 /**
1949 * Request that a given application service be stopped. If the service is
1950 * not running, nothing happens. Otherwise it is stopped. Note that calls
1951 * to startService() are not counted -- this stops the service no matter
1952 * how many times it was started.
1953 *
1954 * <p>Note that if a stopped service still has {@link ServiceConnection}
1955 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
1956 * not be destroyed until all of these bindings are removed. See
1957 * the {@link android.app.Service} documentation for more details on a
1958 * service's lifecycle.
1959 *
1960 * <p>This function will throw {@link SecurityException} if you do not
1961 * have permission to stop the given service.
1962 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07001963 * @param service Description of the service to be stopped. The Intent must be either
1964 * fully explicit (supplying a component name) or specify a specific package
1965 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001966 *
1967 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04001968 * running, then it is stopped and {@code true} is returned; else {@code false} is returned.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001969 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001970 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001971 *
1972 * @see #startService
1973 */
1974 public abstract boolean stopService(Intent service);
1975
1976 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001977 * @hide like {@link #startService(Intent)} but for a specific user.
1978 */
1979 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
1980
1981 /**
1982 * @hide like {@link #stopService(Intent)} but for a specific user.
1983 */
1984 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08001985
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001986 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001987 * Connect to an application service, creating it if needed. This defines
1988 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001989 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001990 * told if it dies and restarts. The service will be considered required
1991 * by the system only for as long as the calling context exists. For
1992 * example, if this Context is an Activity that is stopped, the service will
1993 * not be required to continue running until the Activity is resumed.
1994 *
1995 * <p>This function will throw {@link SecurityException} if you do not
1996 * have permission to bind to the given service.
1997 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001998 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001999 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002000 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 * {@link #startService} with the arguments containing the command to be
2002 * sent, with the service calling its
2003 * {@link android.app.Service#stopSelf(int)} method when done executing
2004 * that command. See the API demo App/Service/Service Start Arguments
2005 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002006 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002007 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2008 * is tied to another object (the one that registered it).</p>
2009 *
2010 * @param service Identifies the service to connect to. The Intent may
2011 * specify either an explicit component name, or a logical
2012 * description (action, category, etc) to match an
2013 * {@link IntentFilter} published by a service.
2014 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002015 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002016 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002017 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2018 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2019 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2020 * {@link #BIND_WAIVE_PRIORITY}.
John Spurlock6098c5d2013-06-17 10:32:46 -04002021 * @return If you have successfully bound to the service, {@code true} is returned;
2022 * {@code false} is returned if the connection is not made so you will not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002023 * receive the service object.
2024 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002025 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002026 *
2027 * @see #unbindService
2028 * @see #startService
2029 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002030 * @see #BIND_DEBUG_UNBIND
2031 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002032 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002033 public abstract boolean bindService(Intent service, @NonNull ServiceConnection conn,
2034 @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002035
2036 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002037 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002038 * argument for use by system server and other multi-user aware code.
2039 * @hide
2040 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07002041 @SystemApi
Amith Yamasani27b89e62013-01-16 12:30:11 -08002042 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002043 throw new RuntimeException("Not implemented. Must override in a subclass.");
2044 }
2045
2046 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002047 * Disconnect from an application service. You will no longer receive
2048 * calls as the service is restarted, and the service is now allowed to
2049 * stop at any time.
2050 *
2051 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002052 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002053 *
2054 * @see #bindService
2055 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002056 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002057
2058 /**
2059 * Start executing an {@link android.app.Instrumentation} class. The given
2060 * Instrumentation component will be run by killing its target application
2061 * (if currently running), starting the target process, instantiating the
2062 * instrumentation component, and then letting it drive the application.
2063 *
2064 * <p>This function is not synchronous -- it returns as soon as the
2065 * instrumentation has started and while it is running.
2066 *
2067 * <p>Instrumentation is normally only allowed to run against a package
2068 * that is either unsigned or signed with a signature that the
2069 * the instrumentation package is also signed with (ensuring the target
2070 * trusts the instrumentation).
2071 *
2072 * @param className Name of the Instrumentation component to be run.
2073 * @param profileFile Optional path to write profiling data as the
2074 * instrumentation runs, or null for no profiling.
2075 * @param arguments Additional optional arguments to pass to the
2076 * instrumentation, or null.
2077 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002078 * @return {@code true} if the instrumentation was successfully started,
2079 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002080 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002081 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2082 @Nullable String profileFile, @Nullable Bundle arguments);
2083
2084 /** @hide */
2085 @StringDef({
2086 POWER_SERVICE,
2087 WINDOW_SERVICE,
2088 LAYOUT_INFLATER_SERVICE,
2089 ACCOUNT_SERVICE,
2090 ACTIVITY_SERVICE,
2091 ALARM_SERVICE,
2092 NOTIFICATION_SERVICE,
2093 ACCESSIBILITY_SERVICE,
2094 CAPTIONING_SERVICE,
2095 KEYGUARD_SERVICE,
2096 LOCATION_SERVICE,
2097 //@hide: COUNTRY_DETECTOR,
2098 SEARCH_SERVICE,
2099 SENSOR_SERVICE,
2100 STORAGE_SERVICE,
2101 WALLPAPER_SERVICE,
2102 VIBRATOR_SERVICE,
2103 //@hide: STATUS_BAR_SERVICE,
2104 CONNECTIVITY_SERVICE,
2105 //@hide: UPDATE_LOCK_SERVICE,
2106 //@hide: NETWORKMANAGEMENT_SERVICE,
2107 //@hide: NETWORK_STATS_SERVICE,
2108 //@hide: NETWORK_POLICY_SERVICE,
2109 WIFI_SERVICE,
Yuhao Zhenga4864472014-04-10 11:45:42 -07002110 WIFI_PASSPOINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002111 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002112 WIFI_SCANNING_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07002113 //@hide: ETHERNET_SERVICE,
Vinit Deshpande7686c062014-06-30 15:25:01 -07002114 WIFI_RTT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002115 NSD_SERVICE,
2116 AUDIO_SERVICE,
2117 MEDIA_ROUTER_SERVICE,
2118 TELEPHONY_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002119 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002120 CLIPBOARD_SERVICE,
2121 INPUT_METHOD_SERVICE,
2122 TEXT_SERVICES_MANAGER_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07002123 APPWIDGET_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002124 //@hide: BACKUP_SERVICE,
2125 DROPBOX_SERVICE,
2126 DEVICE_POLICY_SERVICE,
2127 UI_MODE_SERVICE,
2128 DOWNLOAD_SERVICE,
2129 NFC_SERVICE,
2130 BLUETOOTH_SERVICE,
2131 //@hide: SIP_SERVICE,
2132 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08002133 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002134 //@hide: SERIAL_SERVICE,
2135 INPUT_SERVICE,
2136 DISPLAY_SERVICE,
2137 //@hide: SCHEDULING_POLICY_SERVICE,
2138 USER_SERVICE,
2139 //@hide: APP_OPS_SERVICE
2140 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002141 PRINT_SERVICE,
2142 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08002143 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07002144 JOB_SCHEDULER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002145 })
2146 @Retention(RetentionPolicy.SOURCE)
2147 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002148
2149 /**
2150 * Return the handle to a system-level service by name. The class of the
2151 * returned object varies by the requested name. Currently available names
2152 * are:
Scott Main4b5da682010-10-21 11:49:12 -07002153 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002154 * <dl>
2155 * <dt> {@link #WINDOW_SERVICE} ("window")
2156 * <dd> The top-level window manager in which you can place custom
2157 * windows. The returned object is a {@link android.view.WindowManager}.
2158 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
2159 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
2160 * in this context.
2161 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
2162 * <dd> A {@link android.app.ActivityManager} for interacting with the
2163 * global activity state of the system.
2164 * <dt> {@link #POWER_SERVICE} ("power")
2165 * <dd> A {@link android.os.PowerManager} for controlling power
2166 * management.
2167 * <dt> {@link #ALARM_SERVICE} ("alarm")
2168 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
2169 * time of your choosing.
2170 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
2171 * <dd> A {@link android.app.NotificationManager} for informing the user
2172 * of background events.
2173 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
2174 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
2175 * <dt> {@link #LOCATION_SERVICE} ("location")
2176 * <dd> A {@link android.location.LocationManager} for controlling location
2177 * (e.g., GPS) updates.
2178 * <dt> {@link #SEARCH_SERVICE} ("search")
2179 * <dd> A {@link android.app.SearchManager} for handling search.
2180 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
2181 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
2182 * hardware.
2183 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
2184 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
2185 * handling management of network connections.
2186 * <dt> {@link #WIFI_SERVICE} ("wifi")
2187 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
2188 * Wi-Fi connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002189 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
2190 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
2191 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
2193 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
2194 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08002195 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
2196 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07002197 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07002198 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08002199 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07002200 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07002201 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
2202 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002203 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07002204 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 * <p>Note: System services obtained via this API may be closely associated with
2206 * the Context in which they are obtained from. In general, do not share the
2207 * service objects between various different contexts (Activities, Applications,
2208 * Services, Providers, etc.)
2209 *
2210 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07002211 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002212 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07002213 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 * @see #WINDOW_SERVICE
2215 * @see android.view.WindowManager
2216 * @see #LAYOUT_INFLATER_SERVICE
2217 * @see android.view.LayoutInflater
2218 * @see #ACTIVITY_SERVICE
2219 * @see android.app.ActivityManager
2220 * @see #POWER_SERVICE
2221 * @see android.os.PowerManager
2222 * @see #ALARM_SERVICE
2223 * @see android.app.AlarmManager
2224 * @see #NOTIFICATION_SERVICE
2225 * @see android.app.NotificationManager
2226 * @see #KEYGUARD_SERVICE
2227 * @see android.app.KeyguardManager
2228 * @see #LOCATION_SERVICE
2229 * @see android.location.LocationManager
2230 * @see #SEARCH_SERVICE
2231 * @see android.app.SearchManager
2232 * @see #SENSOR_SERVICE
2233 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08002234 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08002235 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002236 * @see #VIBRATOR_SERVICE
2237 * @see android.os.Vibrator
2238 * @see #CONNECTIVITY_SERVICE
2239 * @see android.net.ConnectivityManager
2240 * @see #WIFI_SERVICE
2241 * @see android.net.wifi.WifiManager
2242 * @see #AUDIO_SERVICE
2243 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002244 * @see #MEDIA_ROUTER_SERVICE
2245 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 * @see #TELEPHONY_SERVICE
2247 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08002248 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
2249 * @see android.telephony.SubscriptionManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002250 * @see #INPUT_METHOD_SERVICE
2251 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08002252 * @see #UI_MODE_SERVICE
2253 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07002254 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07002255 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08002256 * @see #BATTERY_SERVICE
2257 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07002258 * @see #JOB_SCHEDULER_SERVICE
2259 * @see android.app.job.JobScheduler
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002260 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002261 public abstract Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262
2263 /**
2264 * Use with {@link #getSystemService} to retrieve a
2265 * {@link android.os.PowerManager} for controlling power management,
2266 * including "wake locks," which let you keep the device on while
2267 * you're running long tasks.
2268 */
2269 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07002270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 /**
2272 * Use with {@link #getSystemService} to retrieve a
2273 * {@link android.view.WindowManager} for accessing the system's window
2274 * manager.
2275 *
2276 * @see #getSystemService
2277 * @see android.view.WindowManager
2278 */
2279 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07002280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 /**
2282 * Use with {@link #getSystemService} to retrieve a
2283 * {@link android.view.LayoutInflater} for inflating layout resources in this
2284 * context.
2285 *
2286 * @see #getSystemService
2287 * @see android.view.LayoutInflater
2288 */
2289 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07002290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002291 /**
2292 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07002293 * {@link android.accounts.AccountManager} for receiving intents at a
2294 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07002295 *
2296 * @see #getSystemService
2297 * @see android.accounts.AccountManager
2298 */
2299 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07002300
Fred Quintana60307342009-03-24 22:48:12 -07002301 /**
2302 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 * {@link android.app.ActivityManager} for interacting with the global
2304 * system state.
2305 *
2306 * @see #getSystemService
2307 * @see android.app.ActivityManager
2308 */
2309 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07002310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311 /**
2312 * Use with {@link #getSystemService} to retrieve a
2313 * {@link android.app.AlarmManager} for receiving intents at a
2314 * time of your choosing.
2315 *
2316 * @see #getSystemService
2317 * @see android.app.AlarmManager
2318 */
2319 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07002320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 /**
2322 * Use with {@link #getSystemService} to retrieve a
2323 * {@link android.app.NotificationManager} for informing the user of
2324 * background events.
2325 *
2326 * @see #getSystemService
2327 * @see android.app.NotificationManager
2328 */
2329 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07002330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002331 /**
2332 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07002333 * {@link android.view.accessibility.AccessibilityManager} for giving the user
2334 * feedback for UI events through the registered event listeners.
2335 *
2336 * @see #getSystemService
2337 * @see android.view.accessibility.AccessibilityManager
2338 */
2339 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07002340
svetoslavganov75986cf2009-05-14 22:28:01 -07002341 /**
2342 * Use with {@link #getSystemService} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07002343 * {@link android.view.accessibility.CaptioningManager} for obtaining
2344 * captioning properties and listening for changes in captioning
2345 * preferences.
2346 *
2347 * @see #getSystemService
2348 * @see android.view.accessibility.CaptioningManager
2349 */
2350 public static final String CAPTIONING_SERVICE = "captioning";
2351
2352 /**
2353 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002354 * {@link android.app.NotificationManager} for controlling keyguard.
2355 *
2356 * @see #getSystemService
2357 * @see android.app.KeyguardManager
2358 */
2359 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07002360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002361 /**
2362 * Use with {@link #getSystemService} to retrieve a {@link
2363 * android.location.LocationManager} for controlling location
2364 * updates.
2365 *
2366 * @see #getSystemService
2367 * @see android.location.LocationManager
2368 */
2369 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08002370
2371 /**
2372 * Use with {@link #getSystemService} to retrieve a
2373 * {@link android.location.CountryDetector} for detecting the country that
2374 * the user is in.
2375 *
2376 * @hide
2377 */
2378 public static final String COUNTRY_DETECTOR = "country_detector";
2379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002380 /**
2381 * Use with {@link #getSystemService} to retrieve a {@link
2382 * android.app.SearchManager} for handling searches.
2383 *
2384 * @see #getSystemService
2385 * @see android.app.SearchManager
2386 */
2387 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07002388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002389 /**
2390 * Use with {@link #getSystemService} to retrieve a {@link
2391 * android.hardware.SensorManager} for accessing sensors.
2392 *
2393 * @see #getSystemService
2394 * @see android.hardware.SensorManager
2395 */
2396 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07002397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 /**
San Mehatc9d81752010-02-01 10:23:27 -08002399 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07002400 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08002401 * functions.
2402 *
2403 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08002404 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08002405 */
2406 public static final String STORAGE_SERVICE = "storage";
2407
2408 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002409 * Use with {@link #getSystemService} to retrieve a
2410 * com.android.server.WallpaperService for accessing wallpapers.
2411 *
2412 * @see #getSystemService
2413 */
2414 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07002415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002416 /**
2417 * Use with {@link #getSystemService} to retrieve a {@link
2418 * android.os.Vibrator} for interacting with the vibration hardware.
2419 *
2420 * @see #getSystemService
2421 * @see android.os.Vibrator
2422 */
2423 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07002424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002425 /**
2426 * Use with {@link #getSystemService} to retrieve a {@link
2427 * android.app.StatusBarManager} for interacting with the status bar.
2428 *
2429 * @see #getSystemService
2430 * @see android.app.StatusBarManager
2431 * @hide
2432 */
2433 public static final String STATUS_BAR_SERVICE = "statusbar";
2434
2435 /**
2436 * Use with {@link #getSystemService} to retrieve a {@link
2437 * android.net.ConnectivityManager} for handling management of
2438 * network connections.
2439 *
2440 * @see #getSystemService
2441 * @see android.net.ConnectivityManager
2442 */
2443 public static final String CONNECTIVITY_SERVICE = "connectivity";
2444
2445 /**
2446 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08002447 * android.os.IUpdateLock} for managing runtime sequences that
2448 * must not be interrupted by headless OTA application or similar.
2449 *
2450 * @hide
2451 * @see #getSystemService
2452 * @see android.os.UpdateLock
2453 */
2454 public static final String UPDATE_LOCK_SERVICE = "updatelock";
2455
2456 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07002457 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07002458 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08002459 */
2460 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
2461
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07002462 /** {@hide} */
Jeff Sharkey75279902011-05-24 18:39:45 -07002463 public static final String NETWORK_STATS_SERVICE = "netstats";
2464 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07002465 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
2466
San Mehatd1df8ac2010-01-26 06:17:26 -08002467 /**
2468 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 * android.net.wifi.WifiManager} for handling management of
2470 * Wi-Fi access.
2471 *
2472 * @see #getSystemService
2473 * @see android.net.wifi.WifiManager
2474 */
2475 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07002476
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002477 /**
repo sync55bc5f32011-06-24 14:23:07 -07002478 * Use with {@link #getSystemService} to retrieve a {@link
Roger Chang7fee7232014-05-15 14:46:49 -07002479 * android.net.wifi.passpoint.WifiPasspointManager} for handling management of
Yuhao Zhenga4864472014-04-10 11:45:42 -07002480 * Wi-Fi passpoint access.
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002481 *
2482 * @see #getSystemService
Roger Chang7fee7232014-05-15 14:46:49 -07002483 * @see android.net.wifi.passpoint.WifiPasspointManager
Yuhao Zheng0cb59f22014-05-27 10:35:02 -07002484 * @hide
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002485 */
Yuhao Zhenga4864472014-04-10 11:45:42 -07002486 public static final String WIFI_PASSPOINT_SERVICE = "wifipasspoint";
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002487
2488 /**
2489 * Use with {@link #getSystemService} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07002490 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07002491 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07002492 *
2493 * @see #getSystemService
2494 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07002495 */
2496 public static final String WIFI_P2P_SERVICE = "wifip2p";
2497
2498 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002499 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002500 * android.net.wifi.WifiScanner} for scanning the wifi universe
2501 *
2502 * @see #getSystemService
2503 * @see android.net.wifi.WifiScanner
2504 * @hide
2505 */
Wei Wang35d552f2014-07-08 21:37:01 -07002506 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002507 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
2508
2509 /**
2510 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07002511 * android.net.wifi.RttManager} for ranging devices with wifi
2512 *
2513 * @see #getSystemService
2514 * @see android.net.wifi.RttManager
2515 * @hide
2516 */
2517 @SystemApi
2518 public static final String WIFI_RTT_SERVICE = "rttmanager";
2519
2520 /**
2521 * Use with {@link #getSystemService} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002522 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07002523 * Ethernet access.
2524 *
2525 * @see #getSystemService
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002526 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07002527 *
2528 * @hide
2529 */
2530 public static final String ETHERNET_SERVICE = "ethernet";
2531
2532 /**
2533 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002534 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002535 * discovery
2536 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002537 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002538 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002539 */
2540 public static final String NSD_SERVICE = "servicediscovery";
2541
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002542 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543 * Use with {@link #getSystemService} to retrieve a
2544 * {@link android.media.AudioManager} for handling management of volume,
2545 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07002546 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 * @see #getSystemService
2548 * @see android.media.AudioManager
2549 */
2550 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07002551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 /**
2553 * Use with {@link #getSystemService} to retrieve a
Jim Miller08fa40c2014-04-29 18:18:47 -07002554 * {@link android.service.fingerprint.FingerprintManager} for handling management
2555 * of fingerprints.
2556 *
2557 * @see #getSystemService
2558 * @see android.app.FingerprintManager
Jim Miller777f5b22014-08-25 15:03:50 -07002559 * @hide
Jim Miller08fa40c2014-04-29 18:18:47 -07002560 */
2561 public static final String FINGERPRINT_SERVICE = "fingerprint";
2562
2563 /**
2564 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002565 * {@link android.media.MediaRouter} for controlling and managing
2566 * routing of media.
2567 *
2568 * @see #getSystemService
2569 * @see android.media.MediaRouter
2570 */
2571 public static final String MEDIA_ROUTER_SERVICE = "media_router";
2572
2573 /**
2574 * Use with {@link #getSystemService} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07002575 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08002576 *
2577 * @see #getSystemService
RoboErik42ea7ee2014-05-16 16:27:35 -07002578 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08002579 */
2580 public static final String MEDIA_SESSION_SERVICE = "media_session";
2581
2582 /**
2583 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002584 * {@link android.telephony.TelephonyManager} for handling management the
2585 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07002586 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 * @see #getSystemService
2588 * @see android.telephony.TelephonyManager
2589 */
2590 public static final String TELEPHONY_SERVICE = "phone";
2591
2592 /**
2593 * Use with {@link #getSystemService} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08002594 * {@link android.telephony.SubscriptionManager} for handling management the
2595 * telephony subscriptions of the device.
2596 *
2597 * @see #getSystemService
2598 * @see android.telephony.SubscriptionManager
2599 */
2600 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
2601
2602 /**
2603 * Use with {@link #getSystemService} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002604 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07002605 * of the device.
2606 *
2607 * @see #getSystemService
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002608 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07002609 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002610 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07002611
2612 /**
2613 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 * {@link android.text.ClipboardManager} for accessing and modifying
2615 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07002616 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 * @see #getSystemService
2618 * @see android.text.ClipboardManager
2619 */
2620 public static final String CLIPBOARD_SERVICE = "clipboard";
2621
2622 /**
Scott Main4b5da682010-10-21 11:49:12 -07002623 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002624 * {@link android.view.inputmethod.InputMethodManager} for accessing input
2625 * methods.
2626 *
2627 * @see #getSystemService
2628 */
2629 public static final String INPUT_METHOD_SERVICE = "input_method";
2630
2631 /**
2632 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09002633 * {@link android.view.textservice.TextServicesManager} for accessing
2634 * text services.
2635 *
2636 * @see #getSystemService
2637 */
2638 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
2639
2640 /**
2641 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08002642 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002643 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002644 * @see #getSystemService
2645 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002646 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07002647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07002649 * Official published name of the (internal) voice interaction manager service.
2650 *
2651 * @hide
2652 * @see #getSystemService
2653 */
2654 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
2655
2656 /**
Christopher Tate487529a2009-04-29 14:03:25 -07002657 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08002658 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07002659 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07002660 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07002661 *
Christopher Tate487529a2009-04-29 14:03:25 -07002662 * @see #getSystemService
2663 */
Christopher Tated5cf7222014-07-29 16:53:09 -07002664 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07002665 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07002666
2667 /**
2668 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08002669 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07002670 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07002671 * @see #getSystemService
2672 */
2673 public static final String DROPBOX_SERVICE = "dropbox";
2674
Christopher Tate487529a2009-04-29 14:03:25 -07002675 /**
Scott Main4b5da682010-10-21 11:49:12 -07002676 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002677 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08002678 * device policy management.
2679 *
2680 * @see #getSystemService
2681 */
2682 public static final String DEVICE_POLICY_SERVICE = "device_policy";
2683
2684 /**
Tobias Haamel53332882010-02-18 16:15:43 -08002685 * Use with {@link #getSystemService} to retrieve a
2686 * {@link android.app.UiModeManager} for controlling UI modes.
2687 *
2688 * @see #getSystemService
2689 */
2690 public static final String UI_MODE_SERVICE = "uimode";
2691
2692 /**
Steve Howarda2709362010-07-02 17:12:48 -07002693 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07002694 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07002695 *
2696 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07002697 */
2698 public static final String DOWNLOAD_SERVICE = "download";
2699
2700 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08002701 * Use with {@link #getSystemService} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08002702 * {@link android.os.BatteryManager} for managing battery state.
2703 *
2704 * @see #getSystemService
2705 */
2706 public static final String BATTERY_SERVICE = "batterymanager";
2707
2708 /**
2709 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08002710 * {@link android.nfc.NfcManager} for using NFC.
2711 *
2712 * @see #getSystemService
2713 */
2714 public static final String NFC_SERVICE = "nfc";
2715
2716 /**
2717 * Use with {@link #getSystemService} to retrieve a
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002718 * {@link android.bluetooth.BluetoothAdapter} for using Bluetooth.
2719 *
2720 * @see #getSystemService
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002721 */
2722 public static final String BLUETOOTH_SERVICE = "bluetooth";
2723
2724 /**
2725 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08002726 * {@link android.net.sip.SipManager} for accessing the SIP related service.
2727 *
2728 * @see #getSystemService
2729 */
2730 /** @hide */
2731 public static final String SIP_SERVICE = "sip";
2732
2733 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002734 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08002735 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002736 * and for controlling this device's behavior as a USB device.
2737 *
2738 * @see #getSystemService
John Spurlock6098c5d2013-06-17 10:32:46 -04002739 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002740 */
2741 public static final String USB_SERVICE = "usb";
2742
2743 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002744 * Use with {@link #getSystemService} to retrieve a {@link
2745 * android.hardware.SerialManager} for access to serial ports.
2746 *
2747 * @see #getSystemService
Dianne Hackborn35f72be2013-09-16 10:57:39 -07002748 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002749 *
2750 * @hide
2751 */
2752 public static final String SERIAL_SERVICE = "serial";
2753
2754 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002755 * Use with {@link #getSystemService} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09002756 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
2757 * HDMI-CEC protocol.
2758 *
2759 * @see #getSystemService
2760 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09002761 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09002762 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09002763 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09002764 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09002765
2766 /**
2767 * Use with {@link #getSystemService} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002768 * {@link android.hardware.input.InputManager} for interacting with input devices.
2769 *
2770 * @see #getSystemService
2771 * @see android.hardware.input.InputManager
2772 */
2773 public static final String INPUT_SERVICE = "input";
2774
2775 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07002776 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07002777 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
2778 *
2779 * @see #getSystemService
2780 * @see android.hardware.display.DisplayManager
2781 */
2782 public static final String DISPLAY_SERVICE = "display";
2783
2784 /**
2785 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07002786 * {@link android.os.UserManager} for managing users on devices that support multiple users.
2787 *
2788 * @see #getSystemService
2789 * @see android.os.UserManager
2790 */
2791 public static final String USER_SERVICE = "user";
2792
2793 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002794 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08002795 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
2796 * profiles of a user.
2797 *
2798 * @see #getSystemService
2799 * @see android.content.pm.LauncherApps
2800 */
2801 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
2802
2803 /**
2804 * Use with {@link #getSystemService} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07002805 * {@link android.content.RestrictionsManager} for retrieving application restrictions
2806 * and requesting permissions for restricted operations.
2807 * @see #getSystemService
2808 * @see android.content.RestrictionsManager
2809 */
2810 public static final String RESTRICTIONS_SERVICE = "restrictions";
2811
2812 /**
2813 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002814 * {@link android.app.AppOpsManager} for tracking application operations
2815 * on the device.
2816 *
2817 * @see #getSystemService
2818 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002819 */
2820 public static final String APP_OPS_SERVICE = "appops";
2821
2822 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002823 * Use with {@link #getSystemService} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07002824 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002825 * camera devices.
2826 *
2827 * @see #getSystemService
Dianne Hackborn221ea892013-08-04 16:50:16 -07002828 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002829 */
2830 public static final String CAMERA_SERVICE = "camera";
2831
2832 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07002833 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07002834 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07002835 *
2836 * @see #getSystemService
2837 * @see android.print.PrintManager
2838 */
2839 public static final String PRINT_SERVICE = "print";
2840
2841 /**
Erik Gilling51e95df2013-06-26 11:06:51 -07002842 * Use with {@link #getSystemService} to retrieve a
2843 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
2844 * signals from the device.
2845 *
2846 * @see #getSystemService
2847 * @see android.hardware.ConsumerIrManager
2848 */
2849 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
2850
2851 /**
Adrian Roos82142c22014-03-27 14:56:59 +01002852 * {@link android.app.trust.TrustManager} for managing trust agents.
2853 * @see #getSystemService
2854 * @see android.app.trust.TrustManager
2855 * @hide
2856 */
2857 public static final String TRUST_SERVICE = "trust";
2858
2859 /**
Jae Seo39570912014-02-20 18:23:25 -08002860 * Use with {@link #getSystemService} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07002861 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
2862 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08002863 *
2864 * @see #getSystemService
Jae Seod5cc4a22014-05-30 16:57:43 -07002865 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08002866 */
2867 public static final String TV_INPUT_SERVICE = "tv_input";
2868
2869 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07002870 * {@link android.net.NetworkScoreManager} for managing network scoring.
2871 * @see #getSystemService
2872 * @see android.net.NetworkScoreManager
2873 * @hide
2874 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07002875 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07002876 public static final String NETWORK_SCORE_SERVICE = "network_score";
2877
2878 /**
Dianne Hackborne22b3b12014-05-07 18:06:44 -07002879 * Use with {@link #getSystemService} to retrieve a {@link
Dianne Hackbornff170242014-11-19 10:59:01 -08002880 * android.app.usage.UsageStatsManager} for interacting with the status bar.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07002881 *
2882 * @see #getSystemService
Dianne Hackbornff170242014-11-19 10:59:01 -08002883 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07002884 * @hide
2885 */
2886 public static final String USAGE_STATS_SERVICE = "usagestats";
2887
2888 /**
Christopher Tatefa380e92014-05-19 13:46:29 -07002889 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07002890 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07002891 * background tasks.
2892 * @see #getSystemService
Christopher Tate7060b042014-06-09 19:50:00 -07002893 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07002894 */
Christopher Tate7060b042014-06-09 19:50:00 -07002895 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07002896
2897 /**
Andres Morales68d4acd2014-07-01 19:40:41 -07002898 * Use with {@link #getSystemService} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07002899 * android.service.persistentdata.PersistentDataBlockManager} instance
2900 * for interacting with a storage device that lives across factory resets.
2901 *
Andres Morales68d4acd2014-07-01 19:40:41 -07002902 * @see #getSystemService
2903 * @see android.service.persistentdata.PersistentDataBlockManager
2904 * @hide
2905 */
Andres Morales33df9372014-09-26 17:08:59 -07002906 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07002907 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
2908
2909 /**
Michael Wrightc39d47a2014-07-08 18:07:36 -07002910 * Use with {@link #getSystemService} to retrieve a {@link
2911 * android.media.projection.MediaProjectionManager} instance for managing
2912 * media projection sessions.
2913 * @see #getSystemService
2914 * @see android.media.projection.ProjectionManager
2915 */
2916 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
2917
2918 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002919 * Determine whether the given permission is allowed for a particular
2920 * process and user ID running in the system.
2921 *
2922 * @param permission The name of the permission being checked.
2923 * @param pid The process ID being checked against. Must be > 0.
2924 * @param uid The user ID being checked against. A uid of 0 is the root
2925 * user, which will pass every permission check.
2926 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002927 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 * pid/uid is allowed that permission, or
2929 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2930 *
2931 * @see PackageManager#checkPermission(String, String)
2932 * @see #checkCallingPermission
2933 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002934 @PackageManager.PermissionResult
2935 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002936
Dianne Hackbornff170242014-11-19 10:59:01 -08002937 /** @hide */
2938 @PackageManager.PermissionResult
2939 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
2940 IBinder callerToken);
2941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 /**
2943 * Determine whether the calling process of an IPC you are handling has been
2944 * granted a particular permission. This is basically the same as calling
2945 * {@link #checkPermission(String, int, int)} with the pid and uid returned
2946 * by {@link android.os.Binder#getCallingPid} and
2947 * {@link android.os.Binder#getCallingUid}. One important difference
2948 * is that if you are not currently processing an IPC, this function
2949 * will always fail. This is done to protect against accidentally
2950 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
2951 * to avoid this protection.
2952 *
2953 * @param permission The name of the permission being checked.
2954 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002955 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 * pid/uid is allowed that permission, or
2957 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2958 *
2959 * @see PackageManager#checkPermission(String, String)
2960 * @see #checkPermission
2961 * @see #checkCallingOrSelfPermission
2962 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002963 @PackageManager.PermissionResult
2964 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965
2966 /**
2967 * Determine whether the calling process of an IPC <em>or you</em> have been
2968 * granted a particular permission. This is the same as
2969 * {@link #checkCallingPermission}, except it grants your own permissions
2970 * if you are not currently processing an IPC. Use with care!
2971 *
2972 * @param permission The name of the permission being checked.
2973 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002974 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 * pid/uid is allowed that permission, or
2976 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2977 *
2978 * @see PackageManager#checkPermission(String, String)
2979 * @see #checkPermission
2980 * @see #checkCallingPermission
2981 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002982 @PackageManager.PermissionResult
2983 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984
2985 /**
2986 * If the given permission is not allowed for a particular process
2987 * and user ID running in the system, throw a {@link SecurityException}.
2988 *
2989 * @param permission The name of the permission being checked.
2990 * @param pid The process ID being checked against. Must be &gt; 0.
2991 * @param uid The user ID being checked against. A uid of 0 is the root
2992 * user, which will pass every permission check.
2993 * @param message A message to include in the exception if it is thrown.
2994 *
2995 * @see #checkPermission(String, int, int)
2996 */
2997 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07002998 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999
3000 /**
3001 * If the calling process of an IPC you are handling has not been
3002 * granted a particular permission, throw a {@link
3003 * SecurityException}. This is basically the same as calling
3004 * {@link #enforcePermission(String, int, int, String)} with the
3005 * pid and uid returned by {@link android.os.Binder#getCallingPid}
3006 * and {@link android.os.Binder#getCallingUid}. One important
3007 * difference is that if you are not currently processing an IPC,
3008 * this function will always throw the SecurityException. This is
3009 * done to protect against accidentally leaking permissions; you
3010 * can use {@link #enforceCallingOrSelfPermission} to avoid this
3011 * protection.
3012 *
3013 * @param permission The name of the permission being checked.
3014 * @param message A message to include in the exception if it is thrown.
3015 *
3016 * @see #checkCallingPermission(String)
3017 */
3018 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003019 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003020
3021 /**
3022 * If neither you nor the calling process of an IPC you are
3023 * handling has been granted a particular permission, throw a
3024 * {@link SecurityException}. This is the same as {@link
3025 * #enforceCallingPermission}, except it grants your own
3026 * permissions if you are not currently processing an IPC. Use
3027 * with care!
3028 *
3029 * @param permission The name of the permission being checked.
3030 * @param message A message to include in the exception if it is thrown.
3031 *
3032 * @see #checkCallingOrSelfPermission(String)
3033 */
3034 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003035 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003036
3037 /**
3038 * Grant permission to access a specific Uri to another package, regardless
3039 * of whether that package has general permission to access the Uri's
3040 * content provider. This can be used to grant specific, temporary
3041 * permissions, typically in response to user interaction (such as the
3042 * user opening an attachment that you would like someone else to
3043 * display).
3044 *
3045 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3046 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3047 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3048 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
3049 * start an activity instead of this function directly. If you use this
3050 * function directly, you should be sure to call
3051 * {@link #revokeUriPermission} when the target should no longer be allowed
3052 * to access it.
3053 *
3054 * <p>To succeed, the content provider owning the Uri must have set the
3055 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
3056 * grantUriPermissions} attribute in its manifest or included the
3057 * {@link android.R.styleable#AndroidManifestGrantUriPermission
3058 * &lt;grant-uri-permissions&gt;} tag.
3059 *
3060 * @param toPackage The package you would like to allow to access the Uri.
3061 * @param uri The Uri you would like to grant access to.
3062 * @param modeFlags The desired access modes. Any combination of
3063 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003064 * Intent.FLAG_GRANT_READ_URI_PERMISSION},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003065 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003066 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION},
3067 * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION
3068 * Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION}, or
3069 * {@link Intent#FLAG_GRANT_PREFIX_URI_PERMISSION
3070 * Intent.FLAG_GRANT_PREFIX_URI_PERMISSION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003071 *
3072 * @see #revokeUriPermission
3073 */
3074 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07003075 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003076
3077 /**
3078 * Remove all permissions to access a particular content provider Uri
3079 * that were previously added with {@link #grantUriPermission}. The given
3080 * Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07003081 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07003083 * "content://foo". It will not remove any prefix grants that exist at a
3084 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003085 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003086 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07003087 * regular permission access to a Uri, but had received access to it through
3088 * a specific Uri permission grant, you could not revoke that grant with this
3089 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003090 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security exception,
Dianne Hackborn192679a2014-09-10 14:28:48 -07003091 * but will remove whatever permission grants to the Uri had been given to the app
3092 * (or none).</p>
3093 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003094 * @param uri The Uri you would like to revoke access to.
3095 * @param modeFlags The desired access modes. Any combination of
3096 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3097 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3098 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3099 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3100 *
3101 * @see #grantUriPermission
3102 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07003103 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003104
3105 /**
3106 * Determine whether a particular process and user ID has been granted
3107 * permission to access a specific URI. This only checks for permissions
3108 * that have been explicitly granted -- if the given process/uid has
3109 * more general access to the URI's content provider then this check will
3110 * always fail.
3111 *
3112 * @param uri The uri that is being checked.
3113 * @param pid The process ID being checked against. Must be &gt; 0.
3114 * @param uid The user ID being checked against. A uid of 0 is the root
3115 * user, which will pass every permission check.
3116 * @param modeFlags The type of access to grant. May be one or both of
3117 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3118 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3119 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003120 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003121 * pid/uid is allowed to access that uri, or
3122 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3123 *
3124 * @see #checkCallingUriPermission
3125 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003126 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003127 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003128
Dianne Hackbornff170242014-11-19 10:59:01 -08003129 /** @hide */
3130 public abstract int checkUriPermission(Uri uri, int pid, int uid,
3131 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
3132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003133 /**
3134 * Determine whether the calling process and user ID has been
3135 * granted permission to access a specific URI. This is basically
3136 * the same as calling {@link #checkUriPermission(Uri, int, int,
3137 * int)} with the pid and uid returned by {@link
3138 * android.os.Binder#getCallingPid} and {@link
3139 * android.os.Binder#getCallingUid}. One important difference is
3140 * that if you are not currently processing an IPC, this function
3141 * will always fail.
3142 *
3143 * @param uri The uri that is being checked.
3144 * @param modeFlags The type of access to grant. May be one or both of
3145 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3146 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3147 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003148 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003149 * is allowed to access that uri, or
3150 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3151 *
3152 * @see #checkUriPermission(Uri, int, int, int)
3153 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07003154 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003155
3156 /**
3157 * Determine whether the calling process of an IPC <em>or you</em> has been granted
3158 * permission to access a specific URI. This is the same as
3159 * {@link #checkCallingUriPermission}, except it grants your own permissions
3160 * if you are not currently processing an IPC. Use with care!
3161 *
3162 * @param uri The uri that is being checked.
3163 * @param modeFlags The type of access to grant. May be one or both of
3164 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3165 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3166 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003167 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003168 * is allowed to access that uri, or
3169 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3170 *
3171 * @see #checkCallingUriPermission
3172 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003173 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003174 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003175
3176 /**
3177 * Check both a Uri and normal permission. This allows you to perform
3178 * both {@link #checkPermission} and {@link #checkUriPermission} in one
3179 * call.
3180 *
3181 * @param uri The Uri whose permission is to be checked, or null to not
3182 * do this check.
3183 * @param readPermission The permission that provides overall read access,
3184 * or null to not do this check.
3185 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003186 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 * @param pid The process ID being checked against. Must be &gt; 0.
3188 * @param uid The user ID being checked against. A uid of 0 is the root
3189 * user, which will pass every permission check.
3190 * @param modeFlags The type of access to grant. May be one or both of
3191 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3192 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3193 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003194 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003195 * is allowed to access that uri or holds one of the given permissions, or
3196 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3197 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003198 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
3199 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003200 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003201
3202 /**
3203 * If a particular process and user ID has not been granted
3204 * permission to access a specific URI, throw {@link
3205 * SecurityException}. This only checks for permissions that have
3206 * been explicitly granted -- if the given process/uid has more
3207 * general access to the URI's content provider then this check
3208 * will always fail.
3209 *
3210 * @param uri The uri that is being checked.
3211 * @param pid The process ID being checked against. Must be &gt; 0.
3212 * @param uid The user ID being checked against. A uid of 0 is the root
3213 * user, which will pass every permission check.
3214 * @param modeFlags The type of access to grant. May be one or both of
3215 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3216 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3217 * @param message A message to include in the exception if it is thrown.
3218 *
3219 * @see #checkUriPermission(Uri, int, int, int)
3220 */
3221 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003222 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223
3224 /**
3225 * If the calling process and user ID has not been granted
3226 * permission to access a specific URI, throw {@link
3227 * SecurityException}. This is basically the same as calling
3228 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
3229 * the pid and uid returned by {@link
3230 * android.os.Binder#getCallingPid} and {@link
3231 * android.os.Binder#getCallingUid}. One important difference is
3232 * that if you are not currently processing an IPC, this function
3233 * will always throw a SecurityException.
3234 *
3235 * @param uri The uri that is being checked.
3236 * @param modeFlags The type of access to grant. May be one or both of
3237 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3238 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3239 * @param message A message to include in the exception if it is thrown.
3240 *
3241 * @see #checkCallingUriPermission(Uri, int)
3242 */
3243 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003244 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245
3246 /**
3247 * If the calling process of an IPC <em>or you</em> has not been
3248 * granted permission to access a specific URI, throw {@link
3249 * SecurityException}. This is the same as {@link
3250 * #enforceCallingUriPermission}, except it grants your own
3251 * permissions if you are not currently processing an IPC. Use
3252 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07003253 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003254 * @param uri The uri that is being checked.
3255 * @param modeFlags The type of access to grant. May be one or both of
3256 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3257 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3258 * @param message A message to include in the exception if it is thrown.
3259 *
3260 * @see #checkCallingOrSelfUriPermission(Uri, int)
3261 */
3262 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003263 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264
3265 /**
3266 * Enforce both a Uri and normal permission. This allows you to perform
3267 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
3268 * call.
Scott Main4b5da682010-10-21 11:49:12 -07003269 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003270 * @param uri The Uri whose permission is to be checked, or null to not
3271 * do this check.
3272 * @param readPermission The permission that provides overall read access,
3273 * or null to not do this check.
3274 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003275 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276 * @param pid The process ID being checked against. Must be &gt; 0.
3277 * @param uid The user ID being checked against. A uid of 0 is the root
3278 * user, which will pass every permission check.
3279 * @param modeFlags The type of access to grant. May be one or both of
3280 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3281 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3282 * @param message A message to include in the exception if it is thrown.
3283 *
3284 * @see #checkUriPermission(Uri, String, String, int, int, int)
3285 */
3286 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003287 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003288 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07003289 @Nullable String message);
3290
3291 /** @hide */
3292 @IntDef(flag = true,
3293 value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED})
3294 @Retention(RetentionPolicy.SOURCE)
3295 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296
3297 /**
3298 * Flag for use with {@link #createPackageContext}: include the application
3299 * code with the context. This means loading code into the caller's
3300 * process, so that {@link #getClassLoader()} can be used to instantiate
3301 * the application's classes. Setting this flags imposes security
3302 * restrictions on what application context you can access; if the
3303 * requested application can not be safely loaded into your process,
3304 * java.lang.SecurityException will be thrown. If this flag is not set,
3305 * there will be no restrictions on the packages that can be loaded,
3306 * but {@link #getClassLoader} will always return the default system
3307 * class loader.
3308 */
3309 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
3310
3311 /**
3312 * Flag for use with {@link #createPackageContext}: ignore any security
3313 * restrictions on the Context being requested, allowing it to always
3314 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
3315 * to be loaded into a process even when it isn't safe to do so. Use
3316 * with extreme care!
3317 */
3318 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07003319
Romain Guy870e09f2009-07-06 16:35:25 -07003320 /**
3321 * Flag for use with {@link #createPackageContext}: a restricted context may
3322 * disable specific features. For instance, a View associated with a restricted
3323 * context would ignore particular XML attributes.
3324 */
3325 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326
3327 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003328 * @hide Used to indicate we should tell the activity manager about the process
3329 * loading this code.
3330 */
3331 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
3332
3333 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 * Return a new Context object for the given application name. This
3335 * Context is the same as what the named application gets when it is
3336 * launched, containing the same resources and class loader. Each call to
3337 * this method returns a new instance of a Context object; Context objects
3338 * are not shared, however they share common state (Resources, ClassLoader,
3339 * etc) so the Context instance itself is fairly lightweight.
3340 *
3341 * <p>Throws {@link PackageManager.NameNotFoundException} if there is no
3342 * application with the given package name.
3343 *
3344 * <p>Throws {@link java.lang.SecurityException} if the Context requested
3345 * can not be loaded into the caller's process for security reasons (see
3346 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
3347 *
3348 * @param packageName Name of the application's package.
3349 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
3350 * or {@link #CONTEXT_IGNORE_SECURITY}.
3351 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003352 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003354 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003355 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04003356 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003357 */
3358 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07003359 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07003360
3361 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07003362 * Similar to {@link #createPackageContext(String, int)}, but with a
3363 * different {@link UserHandle}. For example, {@link #getContentResolver()}
3364 * will open any {@link Uri} as the given user.
3365 *
3366 * @hide
3367 */
3368 public abstract Context createPackageContextAsUser(
3369 String packageName, int flags, UserHandle user)
3370 throws PackageManager.NameNotFoundException;
3371
3372 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07003373 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
3374 *
3375 * @hide
3376 */
3377 public abstract Context createApplicationContext(ApplicationInfo application,
3378 int flags) throws PackageManager.NameNotFoundException;
3379
3380 /**
Jim Millera75a8832013-02-07 16:53:32 -08003381 * Get the userId associated with this context
3382 * @return user id
3383 *
3384 * @hide
3385 */
3386 public abstract int getUserId();
3387
3388 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07003389 * Return a new Context object for the current Context but whose resources
3390 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07003391 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07003392 * shared, however common state (ClassLoader, other Resources for the
3393 * same configuration) may be so the Context itself can be fairly lightweight.
3394 *
3395 * @param overrideConfiguration A {@link Configuration} specifying what
3396 * values to modify in the base Configuration of the original Context's
3397 * resources. If the base configuration changes (such as due to an
3398 * orientation change), the resources of this context will also change except
3399 * for those that have been explicitly overridden with a value here.
3400 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003401 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07003402 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003403 public abstract Context createConfigurationContext(
3404 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07003405
3406 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07003407 * Return a new Context object for the current Context but whose resources
3408 * are adjusted to match the metrics of the given Display. Each call to this method
3409 * returns a new instance of a Context object; Context objects are not
3410 * shared, however common state (ClassLoader, other Resources for the
3411 * same configuration) may be so the Context itself can be fairly lightweight.
3412 *
3413 * The returned display Context provides a {@link WindowManager}
3414 * (see {@link #getSystemService(String)}) that is configured to show windows
3415 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
3416 * method can be used to retrieve the Display from the returned Context.
3417 *
3418 * @param display A {@link Display} object specifying the display
3419 * for whose metrics the Context's resources should be tailored and upon which
3420 * new windows should be shown.
3421 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003422 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07003423 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003424 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07003425
3426 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07003427 * Gets the display adjustments holder for this context. This information
3428 * is provided on a per-application or activity basis and is used to simulate lower density
3429 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07003430 *
Jeff Browna492c3a2012-08-23 19:48:44 -07003431 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07003432 * @return The compatibility info holder, or null if not required by the application.
3433 * @hide
3434 */
Craig Mautner48d0d182013-06-11 07:53:06 -07003435 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07003436
3437 /**
Romain Guy870e09f2009-07-06 16:35:25 -07003438 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07003439 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003440 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07003441 *
Romain Guy870e09f2009-07-06 16:35:25 -07003442 * @see #CONTEXT_RESTRICTED
3443 */
3444 public boolean isRestricted() {
3445 return false;
3446 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003447}