From 758b042680d74f69d704cf6dc0c010bacec4058f Mon Sep 17 00:00:00 2001 From: m2049r Date: Sun, 3 Nov 2024 16:19:35 +0100 Subject: [PATCH] fix some crashing if bluetooth pemissions are not given (#965) * show error instead of crashing * ignore if fragement is no longer * bump version --- app/build.gradle | 4 ++-- app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java | 2 +- .../java/com/m2049r/xmrwallet/SidekickConnectFragment.java | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3eb159bc..38e8fac1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { compileSdk 35 minSdkVersion 21 targetSdkVersion 35 - versionCode 4102 - versionName "4.1.2 'Exolix'" + versionCode 4103 + versionName "4.1.3 'Exolix'" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java index e0151d22..85511810 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java +++ b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java @@ -1411,7 +1411,7 @@ public class LoginActivity extends BaseActivity Timber.d("onDeviceConnected: %s", connectedDeviceName); try { SidekickConnectFragment f = (SidekickConnectFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_container); - assert f != null; + if (f == null) return; f.allowClick(); } catch (ClassCastException ex) { // ignore it diff --git a/app/src/main/java/com/m2049r/xmrwallet/SidekickConnectFragment.java b/app/src/main/java/com/m2049r/xmrwallet/SidekickConnectFragment.java index c27d4d60..4310195a 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/SidekickConnectFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/SidekickConnectFragment.java @@ -27,6 +27,7 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -116,8 +117,10 @@ public class SidekickConnectFragment extends Fragment private void populateList() { List items = new ArrayList<>(); - if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) - throw new IllegalStateException("Bluetooth permission not granted"); + if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) { + Toast.makeText(requireContext(), "Bluetooth permission not granted", Toast.LENGTH_LONG).show(); + return; + } for (BluetoothDevice device : bluetoothAdapter.getBondedDevices()) { final int deviceCLass = device.getBluetoothClass().getDeviceClass(); switch (deviceCLass) {