Skip to content

Commit c17fff3

Browse files
committed
gives a nameless scale a fake device name
1 parent 81d61cb commit c17fff3

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothFactory.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.health.openscale.core.bluetooth;
1818

1919
import android.content.Context;
20+
import android.util.SparseArray;
2021

2122
import java.util.Locale;
2223

@@ -118,7 +119,7 @@ public static BluetoothCommunication createDeviceDriver(Context context, String
118119
if (deviceName.equals("ADV") || deviceName.equals("Chipsea-BLE")) {
119120
return new BluetoothOKOK(context);
120121
}
121-
if (deviceName.isEmpty()) {
122+
if (deviceName.equals("NoName OkOk")) {
122123
return new BluetoothOKOK2(context);
123124
}
124125
if (deviceName.equals("BF105") || deviceName.equals("BF720")) {
@@ -150,4 +151,11 @@ public static BluetoothCommunication createDeviceDriver(Context context, String
150151
}
151152
return null;
152153
}
154+
155+
public static String convertNoNameToDeviceName(SparseArray<byte[]> manufacturerSpecificData) {
156+
String deviceName = null;
157+
deviceName = BluetoothOKOK2.convertNoNameToDeviceName(manufacturerSpecificData);
158+
159+
return deviceName;
160+
}
153161
}

android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOKOK2.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package com.health.openscale.core.bluetooth;
1717

18+
import static com.health.openscale.core.utils.Converters.WeightUnit.LB;
19+
import static com.health.openscale.core.utils.Converters.WeightUnit.ST;
20+
1821
import android.bluetooth.le.ScanFilter;
1922
import android.bluetooth.le.ScanResult;
2023
import android.content.Context;
@@ -35,9 +38,6 @@
3538

3639
import timber.log.Timber;
3740

38-
import static com.health.openscale.core.utils.Converters.WeightUnit.LB;
39-
import static com.health.openscale.core.utils.Converters.WeightUnit.ST;
40-
4141
public class BluetoothOKOK2 extends BluetoothCommunication {
4242
private static final int IDX_WEIGHT_MSB = 0;
4343
private static final int IDX_WEIGHT_LSB = 1;
@@ -66,6 +66,21 @@ public BluetoothOKOK2(Context context) {
6666
central = new BluetoothCentralManager(context, btCallback, new Handler(Looper.getMainLooper()));
6767
}
6868

69+
static String convertNoNameToDeviceName(SparseArray<byte[]> manufacturerSpecificData) {
70+
int vendorIndex = -1;
71+
for (int i = 0; i < manufacturerSpecificData.size(); i++) {
72+
int vendorId = manufacturerSpecificData.keyAt(i);
73+
if ((vendorId & 0xff) == 0xc0) { // 0x00c0-->0xffc0
74+
vendorIndex = vendorId;
75+
}
76+
}
77+
if (vendorIndex == -1) {
78+
return null;
79+
}
80+
81+
return "NoName OkOk";
82+
}
83+
6984
private final BluetoothCentralManagerCallback btCallback = new BluetoothCentralManagerCallback() {
7085
@Override
7186
public void onDiscoveredPeripheral(@NotNull BluetoothPeripheral peripheral, @NotNull ScanResult scanResult) {

android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,12 @@ private void onDeviceFound(final ScanResult bleScanResult) {
325325
BluetoothDeviceView deviceView = new BluetoothDeviceView(context);
326326
deviceView.setDeviceName(formatDeviceName(bleScanResult.getDevice()));
327327

328-
String name = device.getName() != null ? device.getName() : "";
329-
BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(context, name);
328+
String deviceName = device.getName();
329+
if (deviceName == null) {
330+
deviceName = BluetoothFactory.convertNoNameToDeviceName(bleScanResult.getScanRecord().getManufacturerSpecificData());
331+
}
332+
333+
BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(context, deviceName);
330334
if (btDevice != null) {
331335
Timber.d("Found supported device %s (driver: %s)",
332336
formatDeviceName(device), btDevice.driverName());

0 commit comments

Comments
 (0)