Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: repair several causes of crash after activty or dialog is destroyed #1297

Merged
merged 6 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading