Ensure that the battery optimization banner is not displayed after an internal clear cache.
This commit is contained in:
parent
c61b118f42
commit
d8095faa43
8 changed files with 47 additions and 1 deletions
|
|
@ -59,6 +59,7 @@ class DefaultClearCacheUseCase @Inject constructor(
|
||||||
seenInvitesStore.clear()
|
seenInvitesStore.clear()
|
||||||
// Ensure any error will be displayed again
|
// Ensure any error will be displayed again
|
||||||
pushService.setIgnoreRegistrationError(matrixClient.sessionId, false)
|
pushService.setIgnoreRegistrationError(matrixClient.sessionId, false)
|
||||||
|
pushService.resetBatteryOptimizationState()
|
||||||
// Ensure the app is restarted
|
// Ensure the app is restarted
|
||||||
defaultCacheService.onClearedCache(matrixClient.sessionId)
|
defaultCacheService.onClearedCache(matrixClient.sessionId)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,10 @@ class DefaultClearCacheUseCaseTest {
|
||||||
resetLambda = resetFtueLambda,
|
resetLambda = resetFtueLambda,
|
||||||
)
|
)
|
||||||
val setIgnoreRegistrationErrorLambda = lambdaRecorder<SessionId, Boolean, Unit> { _, _ -> }
|
val setIgnoreRegistrationErrorLambda = lambdaRecorder<SessionId, Boolean, Unit> { _, _ -> }
|
||||||
|
val resetBatteryOptimizationStateResult = lambdaRecorder<Unit> { }
|
||||||
val pushService = FakePushService(
|
val pushService = FakePushService(
|
||||||
setIgnoreRegistrationErrorLambda = setIgnoreRegistrationErrorLambda
|
setIgnoreRegistrationErrorLambda = setIgnoreRegistrationErrorLambda,
|
||||||
|
resetBatteryOptimizationStateResult = resetBatteryOptimizationStateResult,
|
||||||
)
|
)
|
||||||
val seenInvitesStore = InMemorySeenInvitesStore(setOf(A_ROOM_ID))
|
val seenInvitesStore = InMemorySeenInvitesStore(setOf(A_ROOM_ID))
|
||||||
assertThat(seenInvitesStore.seenRoomIds().first()).isNotEmpty()
|
assertThat(seenInvitesStore.seenRoomIds().first()).isNotEmpty()
|
||||||
|
|
@ -68,6 +70,7 @@ class DefaultClearCacheUseCaseTest {
|
||||||
resetFtueLambda.assertions().isCalledOnce()
|
resetFtueLambda.assertions().isCalledOnce()
|
||||||
setIgnoreRegistrationErrorLambda.assertions().isCalledOnce()
|
setIgnoreRegistrationErrorLambda.assertions().isCalledOnce()
|
||||||
.with(value(matrixClient.sessionId), value(false))
|
.with(value(matrixClient.sessionId), value(false))
|
||||||
|
resetBatteryOptimizationStateResult.assertions().isCalledOnce()
|
||||||
assertThat(awaitItem()).isEqualTo(matrixClient.sessionId)
|
assertThat(awaitItem()).isEqualTo(matrixClient.sessionId)
|
||||||
assertThat(seenInvitesStore.seenRoomIds().first()).isEmpty()
|
assertThat(seenInvitesStore.seenRoomIds().first()).isEmpty()
|
||||||
assertThat(activeRoomsHolder.getActiveRoom(A_SESSION_ID)).isNull()
|
assertThat(activeRoomsHolder.getActiveRoom(A_SESSION_ID)).isNull()
|
||||||
|
|
|
||||||
|
|
@ -67,4 +67,9 @@ interface PushService {
|
||||||
* Reset the push history, including the push counter.
|
* Reset the push history, including the push counter.
|
||||||
*/
|
*/
|
||||||
suspend fun resetPushHistory()
|
suspend fun resetPushHistory()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the battery optimization state.
|
||||||
|
*/
|
||||||
|
suspend fun resetBatteryOptimizationState()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
import io.element.android.libraries.push.api.GetCurrentPushProvider
|
import io.element.android.libraries.push.api.GetCurrentPushProvider
|
||||||
import io.element.android.libraries.push.api.PushService
|
import io.element.android.libraries.push.api.PushService
|
||||||
import io.element.android.libraries.push.api.history.PushHistoryItem
|
import io.element.android.libraries.push.api.history.PushHistoryItem
|
||||||
|
import io.element.android.libraries.push.impl.push.MutableBatteryOptimizationStore
|
||||||
import io.element.android.libraries.push.impl.store.PushDataStore
|
import io.element.android.libraries.push.impl.store.PushDataStore
|
||||||
import io.element.android.libraries.push.impl.test.TestPush
|
import io.element.android.libraries.push.impl.test.TestPush
|
||||||
import io.element.android.libraries.pushproviders.api.Distributor
|
import io.element.android.libraries.pushproviders.api.Distributor
|
||||||
|
|
@ -37,6 +38,7 @@ class DefaultPushService @Inject constructor(
|
||||||
private val sessionObserver: SessionObserver,
|
private val sessionObserver: SessionObserver,
|
||||||
private val pushClientSecretStore: PushClientSecretStore,
|
private val pushClientSecretStore: PushClientSecretStore,
|
||||||
private val pushDataStore: PushDataStore,
|
private val pushDataStore: PushDataStore,
|
||||||
|
private val mutableBatteryOptimizationStore: MutableBatteryOptimizationStore,
|
||||||
) : PushService, SessionListener {
|
) : PushService, SessionListener {
|
||||||
init {
|
init {
|
||||||
observeSessions()
|
observeSessions()
|
||||||
|
|
@ -138,4 +140,8 @@ class DefaultPushService @Inject constructor(
|
||||||
override suspend fun resetPushHistory() {
|
override suspend fun resetPushHistory() {
|
||||||
pushDataStore.reset()
|
pushDataStore.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun resetBatteryOptimizationState() {
|
||||||
|
mutableBatteryOptimizationStore.reset()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import javax.inject.Inject
|
||||||
interface MutableBatteryOptimizationStore {
|
interface MutableBatteryOptimizationStore {
|
||||||
suspend fun showBatteryOptimizationBanner()
|
suspend fun showBatteryOptimizationBanner()
|
||||||
suspend fun onOptimizationBannerDismissed()
|
suspend fun onOptimizationBannerDismissed()
|
||||||
|
suspend fun reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ContributesBinding(AppScope::class)
|
@ContributesBinding(AppScope::class)
|
||||||
|
|
@ -28,4 +29,8 @@ class DefaultMutableBatteryOptimizationStore @Inject constructor(
|
||||||
override suspend fun onOptimizationBannerDismissed() {
|
override suspend fun onOptimizationBannerDismissed() {
|
||||||
defaultPushDataStore.setBatteryOptimizationBannerState(DefaultPushDataStore.BATTERY_OPTIMIZATION_BANNER_STATE_DISMISSED)
|
defaultPushDataStore.setBatteryOptimizationBannerState(DefaultPushDataStore.BATTERY_OPTIMIZATION_BANNER_STATE_DISMISSED)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun reset() {
|
||||||
|
defaultPushDataStore.setBatteryOptimizationBannerState(DefaultPushDataStore.BATTERY_OPTIMIZATION_BANNER_STATE_INIT)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ import io.element.android.libraries.matrix.test.AN_EXCEPTION
|
||||||
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
||||||
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||||
import io.element.android.libraries.push.api.GetCurrentPushProvider
|
import io.element.android.libraries.push.api.GetCurrentPushProvider
|
||||||
|
import io.element.android.libraries.push.impl.push.FakeMutableBatteryOptimizationStore
|
||||||
|
import io.element.android.libraries.push.impl.push.MutableBatteryOptimizationStore
|
||||||
import io.element.android.libraries.push.impl.store.InMemoryPushDataStore
|
import io.element.android.libraries.push.impl.store.InMemoryPushDataStore
|
||||||
import io.element.android.libraries.push.impl.store.PushDataStore
|
import io.element.android.libraries.push.impl.store.PushDataStore
|
||||||
import io.element.android.libraries.push.impl.test.FakeTestPush
|
import io.element.android.libraries.push.impl.test.FakeTestPush
|
||||||
|
|
@ -283,6 +285,18 @@ class DefaultPushServiceTest {
|
||||||
assertThat(userPushStore.getPushProviderName()).isEqualTo(aPushProvider.name)
|
assertThat(userPushStore.getPushProviderName()).isEqualTo(aPushProvider.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `resetBatteryOptimizationState invokes the store method`() = runTest {
|
||||||
|
val resetResult = lambdaRecorder<Unit> { }
|
||||||
|
val defaultPushService = createDefaultPushService(
|
||||||
|
mutableBatteryOptimizationStore = FakeMutableBatteryOptimizationStore(
|
||||||
|
resetResult = resetResult,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
defaultPushService.resetBatteryOptimizationState()
|
||||||
|
resetResult.assertions().isCalledOnce()
|
||||||
|
}
|
||||||
|
|
||||||
private fun createDefaultPushService(
|
private fun createDefaultPushService(
|
||||||
testPush: TestPush = FakeTestPush(),
|
testPush: TestPush = FakeTestPush(),
|
||||||
userPushStoreFactory: UserPushStoreFactory = FakeUserPushStoreFactory(),
|
userPushStoreFactory: UserPushStoreFactory = FakeUserPushStoreFactory(),
|
||||||
|
|
@ -291,6 +305,7 @@ class DefaultPushServiceTest {
|
||||||
sessionObserver: SessionObserver = NoOpSessionObserver(),
|
sessionObserver: SessionObserver = NoOpSessionObserver(),
|
||||||
pushClientSecretStore: PushClientSecretStore = InMemoryPushClientSecretStore(),
|
pushClientSecretStore: PushClientSecretStore = InMemoryPushClientSecretStore(),
|
||||||
pushDataStore: PushDataStore = InMemoryPushDataStore(),
|
pushDataStore: PushDataStore = InMemoryPushDataStore(),
|
||||||
|
mutableBatteryOptimizationStore: MutableBatteryOptimizationStore = FakeMutableBatteryOptimizationStore(),
|
||||||
): DefaultPushService {
|
): DefaultPushService {
|
||||||
return DefaultPushService(
|
return DefaultPushService(
|
||||||
testPush = testPush,
|
testPush = testPush,
|
||||||
|
|
@ -300,6 +315,7 @@ class DefaultPushServiceTest {
|
||||||
sessionObserver = sessionObserver,
|
sessionObserver = sessionObserver,
|
||||||
pushClientSecretStore = pushClientSecretStore,
|
pushClientSecretStore = pushClientSecretStore,
|
||||||
pushDataStore = pushDataStore,
|
pushDataStore = pushDataStore,
|
||||||
|
mutableBatteryOptimizationStore = mutableBatteryOptimizationStore,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import io.element.android.tests.testutils.lambda.lambdaError
|
||||||
class FakeMutableBatteryOptimizationStore(
|
class FakeMutableBatteryOptimizationStore(
|
||||||
private val showBatteryOptimizationBannerResult: () -> Unit = { lambdaError() },
|
private val showBatteryOptimizationBannerResult: () -> Unit = { lambdaError() },
|
||||||
private val onOptimizationBannerDismissedResult: () -> Unit = { lambdaError() },
|
private val onOptimizationBannerDismissedResult: () -> Unit = { lambdaError() },
|
||||||
|
private val resetResult: () -> Unit = { lambdaError() },
|
||||||
) : MutableBatteryOptimizationStore {
|
) : MutableBatteryOptimizationStore {
|
||||||
override suspend fun showBatteryOptimizationBanner() {
|
override suspend fun showBatteryOptimizationBanner() {
|
||||||
showBatteryOptimizationBannerResult()
|
showBatteryOptimizationBannerResult()
|
||||||
|
|
@ -20,4 +21,8 @@ class FakeMutableBatteryOptimizationStore(
|
||||||
override suspend fun onOptimizationBannerDismissed() {
|
override suspend fun onOptimizationBannerDismissed() {
|
||||||
onOptimizationBannerDismissedResult()
|
onOptimizationBannerDismissedResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun reset() {
|
||||||
|
resetResult()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ class FakePushService(
|
||||||
private val selectPushProviderLambda: suspend (SessionId, PushProvider) -> Unit = { _, _ -> lambdaError() },
|
private val selectPushProviderLambda: suspend (SessionId, PushProvider) -> Unit = { _, _ -> lambdaError() },
|
||||||
private val setIgnoreRegistrationErrorLambda: (SessionId, Boolean) -> Unit = { _, _ -> lambdaError() },
|
private val setIgnoreRegistrationErrorLambda: (SessionId, Boolean) -> Unit = { _, _ -> lambdaError() },
|
||||||
private val resetPushHistoryResult: () -> Unit = { lambdaError() },
|
private val resetPushHistoryResult: () -> Unit = { lambdaError() },
|
||||||
|
private val resetBatteryOptimizationStateResult: () -> Unit = { lambdaError() },
|
||||||
) : PushService {
|
) : PushService {
|
||||||
override suspend fun getCurrentPushProvider(): PushProvider? {
|
override suspend fun getCurrentPushProvider(): PushProvider? {
|
||||||
return registeredPushProvider ?: currentPushProvider()
|
return registeredPushProvider ?: currentPushProvider()
|
||||||
|
|
@ -92,4 +93,8 @@ class FakePushService(
|
||||||
override suspend fun resetPushHistory() = simulateLongTask {
|
override suspend fun resetPushHistory() = simulateLongTask {
|
||||||
resetPushHistoryResult()
|
resetPushHistoryResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun resetBatteryOptimizationState() {
|
||||||
|
resetBatteryOptimizationStateResult()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue