mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
ble: BluetoothDevice.getAlias replaced getAliasName in Android 11
This commit is contained in:
committed by
José Rebelo
parent
9814ee74ac
commit
a83026b180
@@ -426,6 +426,10 @@ public class GBApplication extends Application {
|
||||
return VERSION.SDK_INT >= Build.VERSION_CODES.Q;
|
||||
}
|
||||
|
||||
public static boolean isRedVelvetCakeOrLater() {
|
||||
return VERSION.SDK_INT >= Build.VERSION_CODES.R;
|
||||
}
|
||||
|
||||
public static boolean isRunningTwelveOrLater() {
|
||||
return VERSION.SDK_INT >= 31; // Build.VERSION_CODES.S, but our target SDK is lower
|
||||
}
|
||||
|
||||
@@ -35,9 +35,7 @@ import java.util.UUID;
|
||||
import androidx.annotation.NonNull;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
|
||||
/**
|
||||
* A device candidate is a Bluetooth device that is not yet managed by
|
||||
@@ -176,13 +174,22 @@ public class GBDeviceCandidate implements Parcelable, Cloneable {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final Method method = device.getClass().getMethod("getAliasName");
|
||||
deviceName = (String) method.invoke(device);
|
||||
} catch (final NoSuchMethodException ignore) {
|
||||
// ignored
|
||||
} catch (final IllegalAccessException | InvocationTargetException ignore) {
|
||||
LOG.warn("Could not get device alias for {}", device.getAddress());
|
||||
if (GBApplication.isRedVelvetCakeOrLater()) {
|
||||
try {
|
||||
deviceName = device.getAlias();
|
||||
} catch (final SecurityException e) {
|
||||
// Should never happen
|
||||
LOG.error("SecurityException on device.getAlias", e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
final Method method = device.getClass().getMethod("getAliasName");
|
||||
deviceName = (String) method.invoke(device);
|
||||
} catch (final NoSuchMethodException ignore) {
|
||||
// ignored
|
||||
} catch (final IllegalAccessException | InvocationTargetException ignore) {
|
||||
LOG.warn("Could not get device alias for {}", device.getAddress());
|
||||
}
|
||||
}
|
||||
if (deviceName == null || deviceName.isEmpty()) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user