Skip to content

Commit

Permalink
fix: refactor WalletActivity permission launcher to avoid InvalidStat…
Browse files Browse the repository at this point in the history
…eException (#1239)
  • Loading branch information
HashEngineering authored Dec 15, 2023
1 parent 2c2839a commit 929ecab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 3 additions & 0 deletions wallet/src/de/schildbach/wallet/ui/main/WalletActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.core.app.ActivityCompat;
import androidx.lifecycle.ViewModelProvider;

Expand Down Expand Up @@ -76,6 +78,7 @@ public static Intent createIntent(Context context) {
private BaseAlertDialogBuilder baseAlertDialogBuilder;
private MainViewModel viewModel;

ActivityResultLauncher<String> requestPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), result -> WalletActivityExt.INSTANCE.requestDisableBatteryOptimisation(WalletActivity.this));

@Override
protected void onCreate(final Bundle savedInstanceState) {
Expand Down
7 changes: 1 addition & 6 deletions wallet/src/de/schildbach/wallet/ui/main/WalletActivityExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,6 @@ object WalletActivityExt {
}
}

private val WalletActivity.requestPermissionLauncher: ActivityResultLauncher<String>
get() = registerForActivityResult(ActivityResultContracts.RequestPermission()) {
requestDisableBatteryOptimisation()
}

/**
* Android 13 - Show system dialog to get notification permission from user, if not granted
* ask again with each app upgrade if not granted. This logic is handled by
Expand Down Expand Up @@ -238,7 +233,7 @@ object WalletActivityExt {
configuration.showNotificationsExplainer = false
}

private fun WalletActivity.requestDisableBatteryOptimisation() {
fun WalletActivity.requestDisableBatteryOptimisation() {
val powerManager: PowerManager = getSystemService(PowerManager::class.java)
if (ContextCompat.checkSelfPermission(
walletApplication,
Expand Down

0 comments on commit 929ecab

Please sign in to comment.