From 5861c0ee6a01222582167021fbad76f0d9a3032b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 14 Mar 2022 22:22:12 +0100 Subject: [PATCH] Insight: fix pairing --- .../layout/danars_pairing_progress_dialog.xml | 2 +- insight/src/main/AndroidManifest.xml | 2 ++ .../activities/InsightPairingActivity.java | 26 +++++++++++++++---- .../res/layout/activity_insight_alert.xml | 4 +-- .../res/layout/activity_insight_pairing.xml | 6 ++--- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/danars/src/main/res/layout/danars_pairing_progress_dialog.xml b/danars/src/main/res/layout/danars_pairing_progress_dialog.xml index 9d586e536c..d8816e1fda 100644 --- a/danars/src/main/res/layout/danars_pairing_progress_dialog.xml +++ b/danars/src/main/res/layout/danars_pairing_progress_dialog.xml @@ -61,7 +61,7 @@ android:minHeight="3dp" /> + + = Build.VERSION_CODES.S) { + if (ContextCompat.checkSelfPermission(context, "android.permission.BLUETOOTH_CONNECT") != PackageManager.PERMISSION_GRANTED || + ContextCompat.checkSelfPermission(context, "android.permission.BLUETOOTH_SCAN") != PackageManager.PERMISSION_GRANTED + ) { + ActivityCompat.requestPermissions(this, new String[]{"android.permission.BLUETOOTH_SCAN", "android.permission.BLUETOOTH_CONNECT"}, PERMISSION_REQUEST_BLUETOOTH); + finish(); + return; + } + } bindService(new Intent(this, InsightConnectionService.class), serviceConnection, BIND_AUTO_CREATE); -} + } @Override protected void onDestroy() { @@ -110,8 +125,8 @@ public class InsightPairingActivity extends NoSplashAppCompatActivity implements service.withdrawConnectionRequest(InsightPairingActivity.this); service.unregisterStateCallback(InsightPairingActivity.this); service.unregisterExceptionCallback(InsightPairingActivity.this); + unbindService(serviceConnection); } - unbindService(serviceConnection); super.onDestroy(); } @@ -172,7 +187,7 @@ public class InsightPairingActivity extends NoSplashAppCompatActivity implements private void startBLScan() { if (!scanning) { - BluetoothAdapter bluetoothAdapter = ((BluetoothManager)context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter(); + BluetoothAdapter bluetoothAdapter = ((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter(); if (bluetoothAdapter != null) { if (!bluetoothAdapter.isEnabled()) bluetoothAdapter.enable(); IntentFilter intentFilter = new IntentFilter(); @@ -188,13 +203,14 @@ public class InsightPairingActivity extends NoSplashAppCompatActivity implements private void stopBLScan() { if (scanning) { unregisterReceiver(broadcastReceiver); - BluetoothAdapter bluetoothAdapter = ((BluetoothManager)context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter(); + BluetoothAdapter bluetoothAdapter = ((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter(); if (bluetoothAdapter != null) { bluetoothAdapter.cancelDiscovery(); } scanning = false; } } + @Override public void onClick(View v) { if (v == exit) finish(); @@ -216,7 +232,7 @@ public class InsightPairingActivity extends NoSplashAppCompatActivity implements public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) - ((BluetoothManager)context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter().startDiscovery(); + ((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter().startDiscovery(); else if (action.equals(BluetoothDevice.ACTION_FOUND)) { BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); deviceAdapter.addDevice(bluetoothDevice); diff --git a/insight/src/main/res/layout/activity_insight_alert.xml b/insight/src/main/res/layout/activity_insight_alert.xml index c94b18a336..aa7ef66665 100644 --- a/insight/src/main/res/layout/activity_insight_alert.xml +++ b/insight/src/main/res/layout/activity_insight_alert.xml @@ -51,7 +51,7 @@