Skip to content

Commit

Permalink
Merge pull request #358 from DoctorMcKay/fix/bluetooth-permission-for…
Browse files Browse the repository at this point in the history
…-discovery

android: fix(terminal): request bluetooth permission for discoverReaders
  • Loading branch information
rdlabo authored Aug 11, 2024
2 parents f3b75b8 + 4d99339 commit 4b63ca4
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ private void locationPermsCallback(PluginCall call) throws TerminalException {
@PermissionCallback
private void bluetoothOldPermsCallback(PluginCall call) throws TerminalException {
if (getPermissionState("bluetooth_old") == PermissionState.GRANTED) {
this.connectReader(call);
if (Objects.equals(call.getMethodName(), "discoverReaders")) {
this.discoverReaders(call);
} else {
this.connectReader(call);
}
} else {
requestPermissionForAlias("bluetooth_old", call, "bluetoothOldPermsCallback");
}
Expand All @@ -68,7 +72,11 @@ private void bluetoothOldPermsCallback(PluginCall call) throws TerminalException
@PermissionCallback
private void bluetoothPermsCallback(PluginCall call) throws TerminalException {
if (getPermissionState("bluetooth") == PermissionState.GRANTED) {
this.connectReader(call);
if (Objects.equals(call.getMethodName(), "discoverReaders")) {
this.discoverReaders(call);
} else {
this.connectReader(call);
}
} else {
requestPermissionForAlias("bluetooth", call, "bluetoothPermsCallback");
}
Expand All @@ -85,7 +93,22 @@ private void _initialize(PluginCall call) throws TerminalException {

@PluginMethod
public void discoverReaders(PluginCall call) {
this.implementation.onDiscoverReaders(call);
if (
Objects.equals(call.getString("type"), TerminalConnectTypes.Bluetooth.getWebEventName()) ||
Objects.equals(call.getString("type"), TerminalConnectTypes.Simulated.getWebEventName())
) {
Log.d("Capacitor:permission bluetooth_old", getPermissionState("bluetooth_old").toString());
Log.d("Capacitor:permission bluetooth", getPermissionState("bluetooth").toString());
if (Build.VERSION.SDK_INT <= 30 && getPermissionState("bluetooth_old") != PermissionState.GRANTED) {
requestPermissionForAlias("bluetooth_old", call, "bluetoothOldPermsCallback");
} else if (Build.VERSION.SDK_INT > 30 && getPermissionState("bluetooth") != PermissionState.GRANTED) {
requestPermissionForAlias("bluetooth", call, "bluetoothPermsCallback");
} else {
this.implementation.onDiscoverReaders(call);
}
} else {
this.implementation.onDiscoverReaders(call);
}
}

@PluginMethod
Expand Down

0 comments on commit 4b63ca4

Please sign in to comment.