Added in API level 1
Deprecated in API level 24

IsolatedContext

open class IsolatedContext : ContextWrapper
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.test.IsolatedContext

A mock context which prevents its users from talking to the rest of the device while stubbing enough methods to satify code that tries to talk to other packages.

Summary

Inherited constants
Public constructors
IsolatedContext(resolver: ContentResolver!, targetContext: Context!)

Public methods
open Boolean
bindIsolatedService(service: Intent, flags: Int, instanceName: String, executor: Executor, conn: ServiceConnection)

open Boolean
bindService(service: Intent, conn: ServiceConnection, flags: Int)

open Boolean
bindService(service: Intent, flags: Int, executor: Executor, conn: ServiceConnection)

open Int
checkUriPermission(uri: Uri?, readPermission: String?, writePermission: String?, pid: Int, uid: Int, modeFlags: Int)

open Int
checkUriPermission(uri: Uri!, pid: Int, uid: Int, modeFlags: Int)

open MutableList<Intent!>!

Returns the list of intents that were broadcast since the last call to this method.

open AttributionSource

open ContentResolver!

open File!

open Any!

open Intent?

open Unit

open Unit
sendOrderedBroadcast(intent: Intent!, receiverPermission: String?)

open Unit

Inherited functions

Public constructors

IsolatedContext

Added in API level 1
IsolatedContext(
    resolver: ContentResolver!,
    targetContext: Context!)

Public methods

bindIsolatedService

Added in API level 29
Deprecated in API level 24
open fun bindIsolatedService(
    service: Intent,
    flags: Int,
    instanceName: String,
    executor: Executor,
    conn: ServiceConnection
): Boolean

Deprecated: Deprecated in Java.

Parameters
service Intent: Identifies the service to connect to. The Intent must specify an explicit component name. This value cannot be null.
flags Int: Operation options for the binding as per #bindService.
instanceName String: Unique identifier for the service instance. Each unique name here will result in a different service instance being created. Identifiers must only contain ASCII letters, digits, underscores, and periods. This value cannot be null.
executor Executor: Callbacks on ServiceConnection will be called on executor. Must use same instance for the same instance of ServiceConnection. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
conn ServiceConnection: Receives information as the service is started and stopped. This must be a valid ServiceConnection object; it must not be null.
Return
Boolean Returns success of binding as per #bindService.
Exceptions
java.lang.SecurityException If the caller does not have permission to access the service
java.lang.IllegalArgumentException If the instanceName is invalid.

bindService

Added in API level 1
open fun bindService(
    service: Intent,
    conn: ServiceConnection,
    flags: Int
): Boolean

Deprecated: Deprecated in Java.

Parameters
service Intent: Identifies the service to connect to. The Intent must specify an explicit component name. This value cannot be null.
conn ServiceConnection: Receives information as the service is started and stopped. This must be a valid ServiceConnection object; it must not be null.
flags Int: Operation options for the binding. Can be:
Return
Boolean true if the system is in the process of bringing up a service that your client has permission to bind to; false if the system couldn't find the service or if your client doesn't have permission to bind to it. Regardless of the return value, you should later call unbindService to release the connection.
Exceptions
java.lang.SecurityException If the caller does not have permission to access the service or the service cannot be found. Call unbindService to release the connection when this exception is thrown.

bindService

Added in API level 29
Deprecated in API level 24
open fun bindService(
    service: Intent,
    flags: Int,
    executor: Executor,
    conn: ServiceConnection
): Boolean

Deprecated: Deprecated in Java.

Parameters
executor Executor: Callbacks on ServiceConnection will be called on executor. Must use same instance for the same instance of ServiceConnection. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
service Intent: This value cannot be null.
flags Int: Value is either 0 or a combination of android.content.Context#BIND_AUTO_CREATE, android.content.Context#BIND_DEBUG_UNBIND, android.content.Context#BIND_NOT_FOREGROUND, android.content.Context#BIND_ABOVE_CLIENT, android.content.Context#BIND_ALLOW_OOM_MANAGEMENT, android.content.Context#BIND_WAIVE_PRIORITY, android.content.Context#BIND_IMPORTANT, android.content.Context#BIND_ADJUST_WITH_ACTIVITY, android.content.Context#BIND_NOT_PERCEPTIBLE, android.content.Context#BIND_ALLOW_ACTIVITY_STARTS, android.content.Context#BIND_INCLUDE_CAPABILITIES, android.content.Context#BIND_SHARED_ISOLATED_PROCESS, android.content.Context.BIND_PACKAGE_ISOLATED_PROCESS, and android.content.Context#BIND_EXTERNAL_SERVICE
conn ServiceConnection: This value cannot be null.
Return
Boolean The result of the binding as described in bindService(Intent, ServiceConnection, int).

checkUriPermission

Added in API level 1
open fun checkUriPermission(
    uri: Uri?,
    readPermission: String?,
    writePermission: String?,
    pid: Int,
    uid: Int,
    modeFlags: Int
): Int

Deprecated: Deprecated in Java.

Parameters
uri Uri?: This value may be null.
readPermission String?: This value may be null.
writePermission String?: This value may be null.
pid Int: The process ID being checked against. Must be > 0.
uid Int: The UID being checked against. A uid of 0 is the root user, which will pass every permission check.
modeFlags Int: The access modes to check. Value is either 0 or a combination of android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION, and android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Return
Int PackageManager#PERMISSION_GRANTED if the caller is allowed to access that uri or holds one of the given permissions, or PackageManager#PERMISSION_DENIED if it is not. Value is android.content.pm.PackageManager#PERMISSION_GRANTED, or android.content.pm.PackageManager#PERMISSION_DENIED

checkUriPermission

Added in API level 1
open fun checkUriPermission(
    uri: Uri!,
    pid: Int,
    uid: Int,
    modeFlags: Int
): Int

Deprecated: Deprecated in Java.

Parameters
uri Uri!: The uri that is being checked.
pid Int: The process ID being checked against. Must be > 0.
uid Int: The UID being checked against. A uid of 0 is the root user, which will pass every permission check.
modeFlags Int: The access modes to check. Value is either 0 or a combination of android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION, and android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Return
Int PackageManager#PERMISSION_GRANTED if the given pid/uid is allowed to access that uri, or PackageManager#PERMISSION_DENIED if it is not. Value is android.content.pm.PackageManager#PERMISSION_GRANTED, or android.content.pm.PackageManager#PERMISSION_DENIED

getAndClearBroadcastIntents

Added in API level 1
open fun getAndClearBroadcastIntents(): MutableList<Intent!>!

Deprecated: Deprecated in Java.

Returns the list of intents that were broadcast since the last call to this method.

getAttributionSource

Added in API level 31
Deprecated in API level 24
open fun getAttributionSource(): AttributionSource

Deprecated: Deprecated in Java.

Return
AttributionSource This value cannot be null.

getContentResolver

Added in API level 1
open fun getContentResolver(): ContentResolver!

Deprecated: Deprecated in Java.

getFilesDir

Added in API level 1
open fun getFilesDir(): File!

Deprecated: Deprecated in Java.

Return
File! The path of the directory holding application files.

getSystemService

Added in API level 1
open fun getSystemService(name: String): Any!

Deprecated: Deprecated in Java.

Parameters
name String: The name of the desired service. Value is android.content.Context#POWER_SERVICE, android.content.Context#WINDOW_SERVICE, android.content.Context#LAYOUT_INFLATER_SERVICE, android.content.Context#ACCOUNT_SERVICE, android.content.Context#ACTIVITY_SERVICE, android.content.Context#ALARM_SERVICE, android.content.Context#NOTIFICATION_SERVICE, android.content.Context#ACCESSIBILITY_SERVICE, android.content.Context#CAPTIONING_SERVICE, android.content.Context#KEYGUARD_SERVICE, android.content.Context#LOCATION_SERVICE, android.content.Context#HEALTHCONNECT_SERVICE, android.content.Context#SEARCH_SERVICE, android.content.Context#SENSOR_SERVICE, android.content.Context.SENSOR_PRIVACY_SERVICE, android.content.Context#STORAGE_SERVICE, android.content.Context#STORAGE_STATS_SERVICE, android.content.Context#WALLPAPER_SERVICE, android.content.Context#VIBRATOR_MANAGER_SERVICE, android.content.Context#VIBRATOR_SERVICE, android.content.Context.THREAD_NETWORK_SERVICE, android.content.Context#CONNECTIVITY_SERVICE, android.content.Context.PAC_PROXY_SERVICE, android.content.Context.VCN_MANAGEMENT_SERVICE, android.content.Context#IPSEC_SERVICE, android.content.Context#VPN_MANAGEMENT_SERVICE, android.content.Context.TEST_NETWORK_SERVICE, android.content.Context#NETWORK_STATS_SERVICE, android.content.Context#WIFI_SERVICE, android.content.Context#WIFI_AWARE_SERVICE, android.content.Context#WIFI_P2P_SERVICE, android.content.Context.WIFI_SCANNING_SERVICE, android.content.Context#WIFI_RTT_RANGING_SERVICE, android.content.Context#NSD_SERVICE, android.content.Context#AUDIO_SERVICE, android.content.Context.AUDIO_DEVICE_VOLUME_SERVICE, android.content.Context.AUTH_SERVICE, android.content.Context#FINGERPRINT_SERVICE, android.content.Context#BIOMETRIC_SERVICE, android.content.Context#MEDIA_ROUTER_SERVICE, android.content.Context#TELEPHONY_SERVICE, android.content.Context#TELEPHONY_SUBSCRIPTION_SERVICE, android.content.Context#CARRIER_CONFIG_SERVICE, android.content.Context#EUICC_SERVICE, android.content.Context#TELECOM_SERVICE, android.content.Context#CLIPBOARD_SERVICE, android.content.Context#INPUT_METHOD_SERVICE, android.content.Context#TEXT_SERVICES_MANAGER_SERVICE, android.content.Context#TEXT_CLASSIFICATION_SERVICE, android.content.Context#APPWIDGET_SERVICE, android.content.Context.REBOOT_READINESS_SERVICE, android.content.Context.ROLLBACK_SERVICE, android.content.Context#DROPBOX_SERVICE, android.content.Context#DEVICE_POLICY_SERVICE, android.content.Context#UI_MODE_SERVICE, android.content.Context#DOWNLOAD_SERVICE, android.content.Context#NFC_SERVICE, android.content.Context#BLUETOOTH_SERVICE, android.content.Context#USB_SERVICE, android.content.Context#LAUNCHER_APPS_SERVICE, android.content.Context#INPUT_SERVICE, android.content.Context#DISPLAY_SERVICE, android.content.Context#USER_SERVICE, android.content.Context#RESTRICTIONS_SERVICE, android.content.Context#APP_OPS_SERVICE, android.content.Context#ROLE_SERVICE, android.content.Context#CAMERA_SERVICE, android.content.Context#PRINT_SERVICE, android.content.Context#CONSUMER_IR_SERVICE, android.content.Context#TV_INTERACTIVE_APP_SERVICE, android.content.Context#TV_INPUT_SERVICE, android.content.Context#USAGE_STATS_SERVICE, android.content.Context#MEDIA_SESSION_SERVICE, android.content.Context#MEDIA_COMMUNICATION_SERVICE, android.content.Context#BATTERY_SERVICE, android.content.Context#JOB_SCHEDULER_SERVICE, android.content.Context#MEDIA_PROJECTION_SERVICE, android.content.Context#MIDI_SERVICE, android.content.Context.RADIO_SERVICE, android.content.Context#HARDWARE_PROPERTIES_SERVICE, android.content.Context#SHORTCUT_SERVICE, android.content.Context#SYSTEM_HEALTH_SERVICE, android.content.Context#COMPANION_DEVICE_SERVICE, android.content.Context#VIRTUAL_DEVICE_SERVICE, android.content.Context#CROSS_PROFILE_APPS_SERVICE, android.content.Context.PERMISSION_SERVICE, android.content.Context.LIGHTS_SERVICE, android.content.Context#LOCALE_SERVICE, android.content.Context.UWB_SERVICE, android.content.Context#MEDIA_METRICS_SERVICE, android.content.Context#DISPLAY_HASH_SERVICE, android.content.Context#CREDENTIAL_SERVICE, android.content.Context#DEVICE_LOCK_SERVICE, android.content.Context.VIRTUALIZATION_SERVICE, android.content.Context#GRAMMATICAL_INFLECTION_SERVICE, or android.content.Context.SECURITY_STATE_SERVICE This value cannot be null.
Return
Any! The service or null if the name does not exist.

registerReceiver

Added in API level 1
open fun registerReceiver(
    receiver: BroadcastReceiver?,
    filter: IntentFilter!
): Intent?

Deprecated: Deprecated in Java.

Parameters
receiver BroadcastReceiver?: This value may be null.
filter IntentFilter!: Selects the Intent broadcasts to be received.
Return
Intent? The first sticky intent found that matches filter, or null if there are none.

sendBroadcast

Added in API level 1
open fun sendBroadcast(intent: Intent!): Unit

Deprecated: Deprecated in Java.

Parameters
intent Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast.

sendOrderedBroadcast

Added in API level 1
open fun sendOrderedBroadcast(
    intent: Intent!,
    receiverPermission: String?
): Unit

Deprecated: Deprecated in Java.

Parameters
intent Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast.
receiverPermission String?: This value may be null.

unregisterReceiver

Added in API level 1
open fun unregisterReceiver(receiver: BroadcastReceiver!): Unit

Deprecated: Deprecated in Java.

Parameters
receiver BroadcastReceiver!: The BroadcastReceiver to unregister.
Exceptions
java.lang.IllegalArgumentException if the receiver was not previously registered or already unregistered.