public class KontaktDeviceConnection extends java.lang.Object implements IKontaktDeviceConnection
All operation with device should be as quick as possible. You should not open connection and wait long time before taking any action. After doing job connection should be closed immediately
Modifier and Type | Class and Description |
---|---|
static class |
KontaktDeviceConnection.State
State enum describes all possible state that BeaconConnection may be in.
|
IKontaktDeviceConnection.ConnectionListener
Modifier and Type | Field and Description |
---|---|
static int |
ERROR_AUTHENTICATION
Error code informing that unexpected error has occured while attempting
beacon authentication.
|
static int |
ERROR_BATCH_WRITE_INSTANCE_ID
Error code informing that Batch write operation failed during InstanceId write
|
static int |
ERROR_BATCH_WRITE_INTERVAL
Error code informing that Batch write operation failed during Interval write.
|
static int |
ERROR_BATCH_WRITE_MAJOR
Error code informing that Batch write operation failed during Major write.
|
static int |
ERROR_BATCH_WRITE_MINOR
Error code informing that Batch write operation failed during Minor write.
|
static int |
ERROR_BATCH_WRITE_NAME
Error code informing that Batch write operation failed during Name write
|
static int |
ERROR_BATCH_WRITE_NAMESPACE
Error code informing that Batch write operation failed during Namespace write
|
static int |
ERROR_BATCH_WRITE_PASSWORD
Error code informing that Batch write failed during Password write
|
static int |
ERROR_BATCH_WRITE_PROFILE
Error code informing that Batch write operation failed during Profile write
|
static int |
ERROR_BATCH_WRITE_PROXIMITY_UUID
Error code informing that Batch write operation failed during Proximity UUID write.
|
static int |
ERROR_BATCH_WRITE_TX_POWER
Error code informing that Batch write operation failed during Transmission Power write.
|
static int |
ERROR_BATCH_WRITE_URL
Error code informing that Batch write operation failed during Url write
|
static int |
ERROR_OVERWRITE_REQUEST
Error code informing that error has occured during characteristic
overwrite process.
|
static int |
ERROR_SERVICES_DISCOVERY
Error code informing that Beacon services discovery has failed.
|
static int |
FAILURE_UNKNOWN_BEACON
Failure code informing that BLE device was not recognised as kontakt.io
Beacon.
|
static int |
FAILURE_WRONG_PASSWORD
Failure code informing that beacon was not authenticated because of
wrong password.
|
Modifier | Constructor and Description |
---|---|
|
KontaktDeviceConnection(Context context,
RemoteBluetoothDevice bluetoothDevice,
IKontaktDeviceConnection.ConnectionListener connectionListener) |
protected |
KontaktDeviceConnection(Context context,
RemoteBluetoothDevice bluetoothDevice,
IKontaktDeviceConnection.ConnectionListener connectionListener,
KontaktDeviceServiceStore serviceStore) |
Modifier and Type | Method and Description |
---|---|
void |
acceptProfile(IPreset profile,
WriteBatchListener<IPreset> writeBatchListener)
Accepts predefined profile (
Preset ) and changes parameters for Beacon. |
void |
applyConfig(IConfig config,
WriteBatchListener<IConfig> writeBatchListener)
Applies pending configuration (
Config ) for Beacon. |
void |
applySecureConfig(java.lang.String secureConfig,
WriteListener writeListener)
Method for writing secure config.
|
void |
close() |
boolean |
connect() |
void |
enableDfuMode(java.lang.String masterPassword,
WriteListener writeListener)
Enables dfu mode.
|
void |
enableNonConnectableMode(java.lang.String masterPassword,
WriteListener writeListener)
Changes Beacon mode to non-connectable.
|
void |
executeSecureCommand(java.lang.String secureCommand,
WriteListener writeListener) |
RemoteBluetoothDevice |
getDevice() |
static int |
getGattError(int errorCode)
Method for getting gatt erorr status code from received errorCode
|
boolean |
isAuthenticated() |
boolean |
isClosed() |
boolean |
isConnected() |
static boolean |
isGattError(int errorCode)
Metohd for checking is error code indicating GATT error
|
protected void |
overwrite(BluetoothGattCharacteristic characteristic,
byte[] newValue,
WriteListener listener) |
void |
overwriteAdvertisingInterval(long millis,
WriteListener writeListener)
Changes Beacon advertising interval.
|
void |
overwriteInstanceId(java.lang.String instanceId,
WriteListener writeListener)
Overwrite instance id.
|
void |
overwriteMajor(int value,
WriteListener writeListener)
Changes Beacon major value.
|
void |
overwriteMinor(int value,
WriteListener writeListener)
Writes minor value.
|
void |
overwriteModelName(java.lang.String newModelName,
WriteListener writeListener)
Changes Beacon model name.
|
void |
overwriteNamespaceId(java.lang.String namespaceId,
WriteListener writeListener)
Overwrites namespace id.
|
void |
overwritePassword(java.lang.String newPassword,
WriteListener writeListener)
Changes beacon password.
|
void |
overwritePowerLevel(int powerLevel,
WriteListener writeListener)
Changes Beacon power level.
|
void |
overwriteProximityUUID(java.util.UUID proximity,
WriteListener writeListener)
Changes Beacon Proximity UUID value.
|
protected void |
overwriteSecure(BluetoothGattCharacteristic characteristic,
byte[] newValue,
WriteListener listener,
boolean readResponse) |
void |
overwriteUrl(java.lang.String newUrl,
WriteListener writeListener)
Overwrites url.
|
void |
resetDevice(WriteListener writeListener)
Resets device so that connection is established once again.
|
void |
restoreDefaultSettings(java.lang.String masterPassword,
WriteListener writeListener)
Restores default Beacon settings.
|
void |
switchToDeviceProfile(DeviceProfile deviceProfile,
WriteListener writeListener)
Switch to device profile.
|
public static final int ERROR_SERVICES_DISCOVERY
public static final int ERROR_OVERWRITE_REQUEST
public static final int ERROR_AUTHENTICATION
public static final int FAILURE_UNKNOWN_BEACON
public static final int FAILURE_WRONG_PASSWORD
public static final int ERROR_BATCH_WRITE_PROXIMITY_UUID
public static final int ERROR_BATCH_WRITE_TX_POWER
public static final int ERROR_BATCH_WRITE_MAJOR
public static final int ERROR_BATCH_WRITE_MINOR
public static final int ERROR_BATCH_WRITE_INTERVAL
public static final int ERROR_BATCH_WRITE_PROFILE
public static final int ERROR_BATCH_WRITE_NAMESPACE
public static final int ERROR_BATCH_WRITE_INSTANCE_ID
public static final int ERROR_BATCH_WRITE_URL
public static final int ERROR_BATCH_WRITE_NAME
public static final int ERROR_BATCH_WRITE_PASSWORD
public KontaktDeviceConnection(Context context, RemoteBluetoothDevice bluetoothDevice, IKontaktDeviceConnection.ConnectionListener connectionListener)
protected KontaktDeviceConnection(Context context, RemoteBluetoothDevice bluetoothDevice, IKontaktDeviceConnection.ConnectionListener connectionListener, KontaktDeviceServiceStore serviceStore)
public static boolean isGattError(int errorCode)
errorCode
- received from IKontaktDeviceConnection.ConnectionListener.onErrorOccured(int)
public static int getGattError(int errorCode)
throws IllegalAccessException
if errorCode is not gatt error code
errorCode
- public RemoteBluetoothDevice getDevice()
getDevice
in interface IKontaktDeviceConnection
public boolean connect()
connect
in interface IKontaktDeviceConnection
public boolean isConnected()
isConnected
in interface IKontaktDeviceConnection
public boolean isAuthenticated()
isAuthenticated
in interface IKontaktDeviceConnection
public void close()
close
in interface IKontaktDeviceConnection
public boolean isClosed()
isClosed
in interface IKontaktDeviceConnection
public void applyConfig(IConfig config, WriteBatchListener<IConfig> writeBatchListener)
Config
) for Beacon.
It is possible to encounter problems during batch (the Config in this case)
write operation which result in launching error handle callback method.
Once the write batch operation failes, the Write Batch Processor
will attempt performing rollback write batch operation aiming at
restoring original Beacon configuration.
The rollback operation however may not succeed as well leaving Beacon device
changed partially.
Therefore it is strongly advisable to write batches in relatively close distance
to Beacon device. Thus, the risk of leaving Beacon in unspecified state may
be avoided.
The method is synchronized.
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
applyConfig
in interface IKontaktDeviceConnection
config
- the configwriteBatchListener
- the write batch listenerpublic void acceptProfile(IPreset profile, WriteBatchListener<IPreset> writeBatchListener)
Preset
) and changes parameters for Beacon.
It is possible to encounter problems during batch (the Preset in this case) write operation which result
in launching error handle callback method. Once the write batch operation failes,
the Write Batch Processor will attempt performing rollback write batch
operation aiming at restoring original Beacon configuration.
The rollback operation however may not succeed as well leaving Beacon device
changed partially.
Therefore it is strongly advisable to write batches in relatively close distance
to Beacon device. Thus, the risk of leaving Beacon in unspecified state may
be avoided.
The method is synchronized.
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
acceptProfile
in interface IKontaktDeviceConnection
profile
- the profilewriteBatchListener
- the write batch listenerpublic void overwriteMinor(int value, WriteListener writeListener)
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
overwriteMinor
in interface IKontaktDeviceConnection
value
- the valuewriteListener
- the write listenerpublic void enableNonConnectableMode(java.lang.String masterPassword, WriteListener writeListener)
DeviceCredentials
)
The method is synchronized.
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
enableNonConnectableMode
in interface IKontaktDeviceConnection
masterPassword
- the beacon master passwordwriteListener
- the write listenerpublic void overwriteMajor(int value, WriteListener writeListener)
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
overwriteMajor
in interface IKontaktDeviceConnection
value
- new valuewriteListener
- the write listenerpublic void overwriteProximityUUID(java.util.UUID proximity, WriteListener writeListener)
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
overwriteProximityUUID
in interface IKontaktDeviceConnection
proximity
- the proximity UUIDwriteListener
- the write listenerpublic void overwritePassword(java.lang.String newPassword, WriteListener writeListener)
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
overwritePassword
in interface IKontaktDeviceConnection
newPassword
- the new passwordwriteListener
- the write listenerpublic void overwriteModelName(java.lang.String newModelName, WriteListener writeListener)
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
overwriteModelName
in interface IKontaktDeviceConnection
newModelName
- the new model namewriteListener
- the write listenerpublic void overwriteAdvertisingInterval(long millis, WriteListener writeListener)
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
overwriteAdvertisingInterval
in interface IKontaktDeviceConnection
millis
- the interval milliswriteListener
- the write listenerpublic void overwritePowerLevel(int powerLevel, WriteListener writeListener)
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
overwritePowerLevel
in interface IKontaktDeviceConnection
powerLevel
- the power levelwriteListener
- the write listenerpublic void switchToDeviceProfile(DeviceProfile deviceProfile, WriteListener writeListener)
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
switchToDeviceProfile
in interface IKontaktDeviceConnection
deviceProfile
- the device profilewriteListener
- the write listenerpublic void resetDevice(WriteListener writeListener)
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
resetDevice
in interface IKontaktDeviceConnection
writeListener
- the write listenerpublic void enableDfuMode(java.lang.String masterPassword, WriteListener writeListener)
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
enableDfuMode
in interface IKontaktDeviceConnection
masterPassword
- the master passwordwriteListener
- the write listenerpublic void overwriteUrl(java.lang.String newUrl, WriteListener writeListener)
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
overwriteUrl
in interface IKontaktDeviceConnection
newUrl
- the new urlwriteListener
- the write listenerpublic void overwriteNamespaceId(java.lang.String namespaceId, WriteListener writeListener)
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
overwriteNamespaceId
in interface IKontaktDeviceConnection
namespaceId
- the namespace idwriteListener
- the write listenerpublic void overwriteInstanceId(java.lang.String instanceId, WriteListener writeListener)
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
overwriteInstanceId
in interface IKontaktDeviceConnection
instanceId
- the instance idwriteListener
- the write listenerpublic void restoreDefaultSettings(java.lang.String masterPassword, WriteListener writeListener)
Throws IllegalOperationException
if provided RemoteBluetoothDevice
is in version 4.0 or higher
restoreDefaultSettings
in interface IKontaktDeviceConnection
masterPassword
- the master passwordwriteListener
- the write listenerpublic void applySecureConfig(java.lang.String secureConfig, WriteListener writeListener)
Throws IllegalOperationException
if provided device is below 4.0 firmware version
applySecureConfig
in interface IKontaktDeviceConnection
secureConfig
- writeListener
- public void executeSecureCommand(java.lang.String secureCommand, WriteListener writeListener)
executeSecureCommand
in interface IKontaktDeviceConnection
protected void overwrite(BluetoothGattCharacteristic characteristic, byte[] newValue, WriteListener listener)
protected void overwriteSecure(BluetoothGattCharacteristic characteristic, byte[] newValue, WriteListener listener, boolean readResponse)