Skip to content

Commit

Permalink
fix: repair several causes of crash after activty or dialog is destro…
Browse files Browse the repository at this point in the history
…yed (#1297)

* fix: add logging when BlockchainServiceImpl is started without a wallet

* fix: use flow for transaction metadata instead of LiveData

* fix: add check for isFinishing or isDestroyed when dismissing transaction details

* fix: add check for view when setting state in CheckPinDialog

* fix: remove unused executor in BlockchainServiceImpl
  • Loading branch information
HashEngineering authored Aug 14, 2024
1 parent 0ba26f2 commit a54539d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
7 changes: 5 additions & 2 deletions wallet/src/de/schildbach/wallet/WalletApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -729,15 +729,18 @@ public void startBlockchainService(final boolean cancelCoinsReceived) {
List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = activityManager != null ? activityManager.getRunningAppProcesses() : null;
if (runningAppProcesses != null) {
int importance = runningAppProcesses.get(0).importance;
if (importance <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND)

if (importance <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
if (wallet == null) {
log.warn("wallet does not exist, but starting blockchain service");
}
if (cancelCoinsReceived) {
Intent blockchainServiceCancelCoinsReceivedIntent = new Intent(BlockchainService.ACTION_CANCEL_COINS_RECEIVED, null,
this, BlockchainServiceImpl.class);
startService(blockchainServiceCancelCoinsReceivedIntent);
} else {
startService(blockchainServiceIntent);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ public class BlockchainServiceImpl extends LifecycleService implements Blockchai

public static final String START_AS_FOREGROUND_EXTRA = "start_as_foreground";

private Executor executor = Executors.newSingleThreadExecutor();
private int syncPercentage = 0; // 0 to 100%

// Risk Analyser for Transactions that is PeerGroup Aware
Expand Down
4 changes: 4 additions & 0 deletions wallet/src/de/schildbach/wallet/ui/CheckPinDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ open class CheckPinDialog(
}

protected fun setState(newState: State) {
if (view == null) {
log.warn("Attempted to set state when the view is not available.")
return
}
when (newState) {
State.ENTER_PIN -> {
if (viewModel.pinLength != PinPreviewView.DEFAULT_PIN_LENGTH) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class TransactionResultViewModel @Inject constructor(
private val analytics: AnalyticsService,
val walletApplication: WalletApplication
) : ViewModel() {

val dashFormat: MonetaryFormat = configuration.format.noCode()

val wallet: Wallet?
Expand All @@ -56,7 +55,7 @@ class TransactionResultViewModel @Inject constructor(

private val _transactionMetadata: MutableStateFlow<TransactionMetadata?> = MutableStateFlow(null)
val transactionMetadata
get() = _transactionMetadata.filterNotNull().asLiveData()
get() = _transactionMetadata.filterNotNull()

val transactionIcon = _transactionMetadata
.filterNotNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.dash.wallet.common.services.analytics.AnalyticsConstants
import org.dash.wallet.common.ui.dialogs.AdaptiveDialog
import org.dash.wallet.common.ui.dialogs.OffsetDialogFragment
import org.dash.wallet.common.ui.viewBinding
import org.dash.wallet.common.util.observe
import org.slf4j.LoggerFactory
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ import org.bitcoinj.core.Sha256Hash
import org.bitcoinj.core.Transaction
import org.dash.wallet.common.services.analytics.AnalyticsConstants
import org.dash.wallet.common.ui.dialogs.AdaptiveDialog
import org.dash.wallet.common.util.observe
import org.slf4j.LoggerFactory

/**
* @author Samuel Barbosa
*/
@AndroidEntryPoint
class TransactionResultActivity : LockScreenActivity() {

private val log = LoggerFactory.getLogger(javaClass.simpleName)

companion object {
Expand Down Expand Up @@ -161,6 +161,11 @@ class TransactionResultActivity : LockScreenActivity() {
}

private fun onTransactionDetailsDismiss() {
if (isFinishing || isDestroyed) {
log.warn("Activity is finishing or destroyed. Skipping dismiss actions.")
return
}

when {
intent.action == Intent.ACTION_VIEW || intent.action == SendCoinsActivity.ACTION_SEND_FROM_WALLET_URI -> {
finish()
Expand Down

0 comments on commit a54539d

Please sign in to comment.