Api26

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).

Since Android 8.0, LE 2M and LE Coded PHY are supported by the API, but not necessarily by the device. Also, some devices may not support scanning for Bluetooth LE devices advertising on LE Coded PHY as Primary PHY despite supporting LE Coded PHY.

Parameters

deviceName

The device name, by default set to "Mock".

isBluetoothSupported

Whether Bluetooth is supported on the device.

isBluetoothEnabled

Whether Bluetooth is enabled on the device.

isMultipleAdvertisementSupported

Whether multi advertisement is supported by the chipset.

isLeExtendedAdvertisingSupported

Whether LE Extended Advertising feature is supported.

isLePeriodicAdvertisingSupported

Whether LE Periodic Advertising feature is supported.

leMaximumAdvertisingDataLength

The maximum LE advertising data length in bytes, if LE Extended Advertising feature is supported.

isLe2MPhySupported

Whether LE 2M PHY is supported on the device.

isLeCodedPhySupported

Whether LE Coded PHY is supported on the device.

isScanningOnLeCodedPhySupported

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

isLocationPermissionGranted

Whether the fine location permission is initially granted.

isLocationEnabled

Whether location service is enabled on the device.

advertiser

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

scanner

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.

issueOnlyOneActiveScan

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.

issueIncorrectL2capTxMtu

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.

Constructors

Link copied to clipboard
constructor(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)

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.