Skip to content

Commit

Permalink
Merge pull request #8 from resideo/feature/ble-upgrade
Browse files Browse the repository at this point in the history
feat: Add removeBondForDevice api
  • Loading branch information
minhtuannguyen-r authored Jul 27, 2023
2 parents a148979 + 46e465c commit 6fec824
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ void removeBondForDevice(
OnSuccessCallback<Device> onSuccessCallback,
OnErrorCallback onErrorCallback);

void getBondStateForDevice(
String deviceIdentifier,
String transactionId,
OnSuccessCallback<Integer> onSuccessCallback,
OnErrorCallback onErrorCallback);

void createBondForDevice(
String deviceIdentifier,
String transactionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,21 @@ public void removeBondForDevice(String deviceIdentifier,
}

@Override
public void getBondStateForDevice(String deviceIdentifier,
String transactionId,
OnSuccessCallback<Integer> onSuccessCallback,
OnErrorCallback onErrorCallback) {
final Device device;
try {
device = getDeviceById(deviceIdentifier);
final int state = device.getBluetoothDevice().getBondState();
onSuccessCallback.onSuccess(state);
} catch (BleError error) {
onErrorCallback.onError(error);
return;
}
}

public void createBondForDevice(String deviceIdentifier,
final String transactionId,
final OnSuccessCallback<Boolean> onSuccessCallback,
Expand All @@ -580,11 +595,9 @@ public void createBondForDevice(String deviceIdentifier,
onErrorCallback.onError(error);
return;
}

safeCreateBondForDevice(device, transactionId, onSuccessCallback, onErrorCallback);
}


@Override
public List<Service> getServicesForDevice(String deviceIdentifier) throws BleError {
final Device device = getDeviceById(deviceIdentifier);
Expand Down Expand Up @@ -1346,6 +1359,18 @@ private Device getDeviceById(@NonNull final String deviceId) throws BleError {
return device;
}

@NonNull
private Device getKnownDeviceById(@NonNull final String deviceId) throws BleError {
Device device = connectedDevices.get(deviceId);
if (device == null) {
device = discoveredDevices.get(deviceId);
}
if (device == null) {
throw BleErrorUtils.deviceNotConnected(deviceId);
}
return device;
}

@NonNull
private Device getDiscoveredDeviceById(@NonNull final String deviceId) throws BleError {
Device device = discoveredDevices.get(deviceId);
Expand Down Expand Up @@ -1562,13 +1587,13 @@ private void safeRemoveBondForDevice(final Device device,
final OnErrorCallback onErrorCallback) {
try {
Method m = device.getBluetoothDevice().getClass().getMethod("removeBond", (Class[]) null);
Object status = m.invoke(device.getBluetoothDevice(), (Object[]) null);
m.invoke(device.getBluetoothDevice(), (Object[]) null);
onSuccessCallback.onSuccess(null);
} catch (Exception error) {
onErrorCallback.onError(new BleError(BleErrorCode.UnknownError, "Remove bond failed: " + error.getMessage(), 0));
}
}

Boolean bondingStarted = false;
private void safeCreateBondForDevice(final Device device,
final String transactionId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.polidea.multiplatformbleadapter.utils.mapper;

import android.bluetooth.BluetoothDevice;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

Expand Down

0 comments on commit 6fec824

Please sign in to comment.