Skip to content

Commit

Permalink
fix: specify crowdnode worker foreground service type, etc (#1303)
Browse files Browse the repository at this point in the history
* fix: specify foreground service type on Android 10 and higher

* fix: show send button

* tests: fix MainViewModelTest
  • Loading branch information
HashEngineering authored Oct 4, 2024
1 parent b6af80a commit b0ceaff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.dash.wallet.integrations.crowdnode.api

import android.content.Context
import android.content.pm.ServiceInfo
import android.os.Build
import androidx.hilt.work.HiltWorker
import androidx.work.CoroutineWorker
import androidx.work.ForegroundInfo
Expand Down Expand Up @@ -65,7 +67,22 @@ class CrowdNodeWorker @AssistedInject constructor(
intent = crowdNodeApi.notificationIntent
)
log.info("calling setForeground")
setForeground(ForegroundInfo(operation.hashCode(), notification))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
setForeground(
ForegroundInfo(
operation.hashCode(),
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
)
)
} else {
setForeground(
ForegroundInfo(
operation.hashCode(),
notification
)
)
}
crowdNodeApi.signUp(address)
}
}
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/de/schildbach/wallet/ui/widget/ShortcutsPane.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class ShortcutsPane(context: Context, attrs: AttributeSet) : FlexboxLayout(conte
secureNowButton,
explore,
receiveButton,
payToContactButton,
if (Constants.SUPPORTS_PLATFORM) payToContactButton else payToAddressButton,
buySellButton,
scanToPayButton
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import de.schildbach.wallet.database.dao.InvitationsDao
import de.schildbach.wallet.ui.dashpay.utils.DashPayConfig
import de.schildbach.wallet.transactions.TxFilterType
import androidx.datastore.preferences.core.Preferences
import de.schildbach.wallet.database.dao.UserAlertDao
import de.schildbach.wallet.database.entity.BlockchainIdentityBaseData
import de.schildbach.wallet.database.entity.BlockchainIdentityConfig
import de.schildbach.wallet.database.entity.BlockchainIdentityData
Expand All @@ -45,6 +46,7 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.*
import org.bitcoinj.core.Coin
import org.bitcoinj.core.PeerGroup
import org.bitcoinj.core.Transaction
import org.bitcoinj.params.TestNet3Params
import org.bitcoinj.utils.MonetaryFormat
Expand All @@ -55,6 +57,7 @@ import org.dash.wallet.common.data.entity.BlockchainState
import org.dash.wallet.common.data.entity.ExchangeRate
import org.dash.wallet.common.services.BlockchainStateProvider
import org.dash.wallet.common.services.ExchangeRatesProvider
import org.dash.wallet.common.services.RateRetrievalState
import org.dash.wallet.common.services.TransactionMetadataProvider
import org.dash.wallet.common.services.analytics.AnalyticsService
import org.junit.Before
Expand Down Expand Up @@ -135,6 +138,10 @@ class MainViewModelTest {
every { observe(WalletUIConfig.SELECTED_CURRENCY) } returns MutableStateFlow("USD")
}

private val userAgentDaoMock = mockk<UserAlertDao> {
every { observe(any()) } returns flow { }
}

private val platformRepo = mockk<PlatformRepo>()

@get:Rule
Expand All @@ -149,6 +156,7 @@ class MainViewModelTest {
every { configMock.registerOnSharedPreferenceChangeListener(any()) } just runs

every { blockchainStateMock.observeState() } returns flow { BlockchainState() }
every { blockchainStateMock.observeSyncStage() } returns MutableStateFlow(PeerGroup.SyncStage.BLOCKS)
every { exchangeRatesMock.observeExchangeRate(any()) } returns flow { ExchangeRate("USD", "100") }
every { walletDataMock.observeBalance() } returns flow { Coin.COIN }
every { walletDataMock.observeMostRecentTransaction() } returns flow {
Expand All @@ -169,7 +177,7 @@ class MainViewModelTest {
0
)
}

every { exchangeRatesMock.observeStaleRates(any()) } returns flow { RateRetrievalState(false, false, false) }
mockkStatic(WalletApplication::class)
every { WalletApplication.getInstance() } returns walletApp

Expand All @@ -195,12 +203,13 @@ class MainViewModelTest {
@Test
fun observeBlockchainState_replaying_notSynced() {
every { blockchainStateMock.observeState() } returns MutableStateFlow(BlockchainState(replaying = true))

val viewModel = spyk(
MainViewModel(
analyticsService, configMock, uiConfigMock,
exchangeRatesMock, walletDataMock, walletApp, platformRepo,
mockk(), mockk(), blockchainIdentityConfigMock, savedStateMock, transactionMetadataMock,
blockchainStateMock, mockk(), mockk(), mockk(), mockk(), mockk(), mockDashPayConfig, mockk(), mockk()
blockchainStateMock, mockk(), mockk(), mockk(), userAgentDaoMock, mockk(), mockDashPayConfig, mockk(), mockk()
)
)

Expand Down

0 comments on commit b0ceaff

Please sign in to comment.