more permission checks

This commit is contained in:
m2049r 2024-11-05 08:42:14 +01:00
parent 758b042680
commit c9132d7d97
No known key found for this signature in database
GPG Key ID: 4386E69AF260078D
1 changed files with 10 additions and 7 deletions

View File

@ -76,12 +76,13 @@ public class SidekickConnectFragment extends Fragment
@Override @Override
public void onPause() { public void onPause() {
Timber.d("onPause()"); Timber.d("onPause()");
if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
throw new IllegalStateException("Bluetooth permission not granted"); Toast.makeText(requireContext(), "Bluetooth permission not granted", Toast.LENGTH_LONG).show();
} else {
if (bluetoothAdapter.isDiscovering()) { if (bluetoothAdapter.isDiscovering()) {
bluetoothAdapter.cancelDiscovery(); bluetoothAdapter.cancelDiscovery();
} }
// the the activity we are connected? why? it can ask the bluetoothservice... }
super.onPause(); super.onPause();
} }
@ -161,8 +162,10 @@ public class SidekickConnectFragment extends Fragment
// Make sure we're not doing discovery anymore // Make sure we're not doing discovery anymore
if (bluetoothAdapter != null) { if (bluetoothAdapter != null) {
if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
throw new IllegalStateException("Bluetooth permission not granted"); Toast.makeText(requireContext(), "Bluetooth permission not granted", Toast.LENGTH_LONG).show();
return;
}
bluetoothAdapter.cancelDiscovery(); bluetoothAdapter.cancelDiscovery();
} }
} }