MockAndroidEnvironment

A mock environment that can be used to test the behavior of the Central Manager.

Inheritors

Types

Link copied to clipboard
class Api21(deviceName: String = DEFAULT_NAME, isBluetoothSupported: Boolean = true, isBluetoothEnabled: Boolean = true, isMultipleAdvertisementSupported: Boolean = true, advertiser: MockAdvertiser = DEFAULT_MOCK_ADVERTISER, scanner: MockScanner = DEFAULT_MOCK_SCANNER, issueOnlyOneActiveScan: Boolean = false) : MockAndroidEnvironment

A mock environment for Android 5.0 (Lollipop).

Link copied to clipboard
class Api23(deviceName: String = DEFAULT_NAME, isBluetoothSupported: Boolean = true, isBluetoothEnabled: Boolean = true, isMultipleAdvertisementSupported: Boolean = true, isLocationPermissionGranted: Boolean = true, isLocationEnabled: Boolean = true, advertiser: MockAdvertiser = DEFAULT_MOCK_ADVERTISER, scanner: MockScanner = DEFAULT_MOCK_SCANNER, issueOnlyOneActiveScan: Boolean = false, issueIncorrectL2capTxMtu: Boolean = false) : MockAndroidEnvironment

A mock environment for Android 6.0 (Marshmallow).

Link copied to clipboard
class Api26(deviceName: String = DEFAULT_NAME, isBluetoothSupported: Boolean = true, isBluetoothEnabled: Boolean = true, isMultipleAdvertisementSupported: Boolean = true, isLeExtendedAdvertisingSupported: Boolean = true, isLePeriodicAdvertisingSupported: Boolean = isLeExtendedAdvertisingSupported, leMaximumAdvertisingDataLength: @Range(from = 31, to = 1650) Int = if (isLeExtendedAdvertisingSupported) 1650 else 31, isLe2MPhySupported: Boolean = true, isLeCodedPhySupported: Boolean = true, isScanningOnLeCodedPhySupported: Boolean = isLeCodedPhySupported, isLocationPermissionGranted: Boolean = true, isLocationEnabled: Boolean = true, advertiser: MockAdvertiser = DEFAULT_MOCK_ADVERTISER, scanner: MockScanner = DEFAULT_MOCK_SCANNER, issueOnlyOneActiveScan: Boolean = false, issueIncorrectL2capTxMtu: Boolean = false) : MockAndroidEnvironment

A mock environment for Android 8.0 (Oreo).

Link copied to clipboard
class Api31(deviceName: String = DEFAULT_NAME, isBluetoothSupported: Boolean = true, isBluetoothEnabled: Boolean = true, isMultipleAdvertisementSupported: Boolean = true, isLeExtendedAdvertisingSupported: Boolean = true, isLePeriodicAdvertisingSupported: Boolean = isLeExtendedAdvertisingSupported, leMaximumAdvertisingDataLength: @Range(from = 31, to = 1650) Int = if (isLeExtendedAdvertisingSupported) 1650 else 31, isLe2MPhySupported: Boolean = true, isLeCodedPhySupported: Boolean = true, isScanningOnLeCodedPhySupported: Boolean = isLeCodedPhySupported, isBluetoothScanPermissionGranted: Boolean = true, isBluetoothConnectPermissionGranted: Boolean = true, isBluetoothAdvertisePermissionGranted: Boolean = true, isNeverForLocationFlagSet: Boolean = true, isLocationPermissionGranted: Boolean = true, isLocationEnabled: Boolean = true, advertiser: MockAdvertiser = DEFAULT_MOCK_ADVERTISER, scanner: MockScanner = DEFAULT_MOCK_SCANNER, issueOnlyOneActiveScan: Boolean = false, issueIncorrectL2capTxMtu: Boolean = false) : MockAndroidEnvironment

A mock environment for Android 12 (S).

Link copied to clipboard
class Nexus4(deviceName: String = "Nexus 4", isBluetoothEnabled: Boolean = true, advertiser: MockAdvertiser = DEFAULT_MOCK_ADVERTISER, scanner: MockScanner = DEFAULT_MOCK_SCANNER) : MockAndroidEnvironment

A mock environment for the Nexus 4.

Link copied to clipboard
class SamsungA8(deviceName: String = "Samsung A8", isBluetoothEnabled: Boolean = true, isBluetoothScanPermissionGranted: Boolean = true, isBluetoothConnectPermissionGranted: Boolean = true, isBluetoothAdvertisePermissionGranted: Boolean = true, isNeverForLocationFlagSet: Boolean = true, isLocationPermissionGranted: Boolean = true, isLocationEnabled: Boolean = true, advertiser: MockAdvertiser = DEFAULT_MOCK_ADVERTISER, scanner: MockScanner = DEFAULT_MOCK_SCANNER) : MockAndroidEnvironment

A mock environment for the Samsung A8 with Android 14.

Properties

Link copied to clipboard

A callback that will be called when the app requests to advertise. The callback should return the TX power level used for mock advertising.

Link copied to clipboard
open override val androidSdkVersion: Int
Link copied to clipboard
open override val bluetoothState: StateFlow<Manager.State>
Link copied to clipboard
open override var deviceName: String
Link copied to clipboard
Link copied to clipboard

Whether the BLUETOOTH_ADVERTISE permission is granted. The permission can be set to true to emulate it being granted in runtime.

Link copied to clipboard

Whether the BLUETOOTH_CONNECT permission is granted. The permission can be set to true to emulate it being granted in runtime.

Link copied to clipboard
open override val isBluetoothEnabled: Boolean
Link copied to clipboard

Whether the BLUETOOTH_SCAN permission is granted. The permission can be set to true to emulate it being granted in runtime.

Link copied to clipboard
open override val isBluetoothSupported: Boolean
Link copied to clipboard
open override val isLe2MPhySupported: Boolean
Link copied to clipboard
open override val isLeCodedPhySupported: Boolean
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Whether the fine location permission is granted. The permission can be set to true to emulate it being granted in runtime.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Whether the device can scan for Bluetooth LE devices advertising on LE Coded PHY as Primary PHY.

Link copied to clipboard

Some Android devices claim they can only transmit 27-byte long packets on L2CAP in the LLCP Data Length Update procedure, while later trying to send 251 bytes. This causes the peripheral to terminate the connection. This flag simulates this issue. It was encountered e.g. on Samsung A8 and Samsung A8 Tab.

Link copied to clipboard

Some early Android devices were sending only one Scan Request message for a single device per scan. Non-connectable devices were reported continuously, but connectable devices were reported only once. The client had to stop and start scanning again to receive further advertisements. This flag simulates this issue. It was encountered e.g. on Nexus 4.

Link copied to clipboard
open override val leMaximumAdvertisingDataLength: @Range(from = 31, to = 1650) Int
Link copied to clipboard
open override val locationState: StateFlow<Boolean>
Link copied to clipboard
Link copied to clipboard

A callback that will be called when the mock central manager requests to scan for devices. It returns whether the scan was successful, secretly failed, or returned an error.

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
open override fun enableBluetooth()
Link copied to clipboard

Simulates turning on/off location service on the mock device.

Link copied to clipboard

Simulates turning off Bluetooth adapter on the mock device.

Link copied to clipboard

Simulates turning on Bluetooth adapter on the mock device.