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: specify crowdnode worker foreground service type #1303

Merged
merged 6 commits into from
Oct 4, 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
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
)
)
}
Comment on lines +70 to +85
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the foreground service fix.

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,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the ShortcutPane fix

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 { }
}
Comment on lines +141 to +143
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this problem started happening now and not previously on the dashpay branch.

observeBlockchainState_replaying_notSynced started to fail.


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
Loading