Skip to content

Commit

Permalink
simplified accessibility update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
aj-rosado committed Feb 26, 2025
1 parent 889ec6f commit 8303422
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class BitwardenAccessibilityService : AccessibilityService() {
override fun onInterrupt() = Unit

override fun onUnbind(intent: Intent?): Boolean {
accessibilityEnabledManager.updateAccessibilityEnabledStateFlow(isEnabled = false)
accessibilityEnabledManager.refreshAccessibilityEnabledFromSettings()
return super.onUnbind(intent)
}

override fun onServiceConnected() {
super.onServiceConnected()
accessibilityEnabledManager.updateAccessibilityEnabledStateFlow(isEnabled = true)
accessibilityEnabledManager.refreshAccessibilityEnabledFromSettings()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.data.platform.repository.model.UriMatchType
import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect
import com.x8bit.bitwarden.ui.platform.base.util.LivecycleEventEffect
import com.x8bit.bitwarden.ui.platform.base.util.standardHorizontalMargin
import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenTopAppBar
import com.x8bit.bitwarden.ui.platform.components.badge.NotificationBadge
Expand Down Expand Up @@ -71,15 +69,6 @@ fun AutoFillScreen(
val context = LocalContext.current
val resources = context.resources
var shouldShowAutofillFallbackDialog by rememberSaveable { mutableStateOf(false) }
LivecycleEventEffect { _, event ->
when (event) {
Lifecycle.Event.ON_RESUME -> {
viewModel.trySendAction(AutoFillAction.LifecycleResume)
}

else -> Unit
}
}
EventsEffect(viewModel = viewModel) { event ->
when (event) {
AutoFillEvent.NavigateBack -> onNavigateBack.invoke()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ class AutoFillViewModel @Inject constructor(
AutoFillAction.AutofillActionCardCtaClick -> handleAutofillActionCardCtaClick()
AutoFillAction.DismissShowAutofillActionCard -> handleDismissShowAutofillActionCard()
is AutoFillAction.ChromeAutofillSelected -> handleChromeAutofillSelected(action)
AutoFillAction.LifecycleResume -> handleOnResumed()
}

private fun handleOnResumed() {
settingsRepository.refreshAccessibilityEnabled()
}

private fun handleInternalAction(action: AutoFillAction.Internal) {
Expand Down Expand Up @@ -335,11 +330,6 @@ sealed class AutoFillEvent {
*/
sealed class AutoFillAction {

/**
* Indicates the UI has been entered a resumed lifecycle state.
*/
data object LifecycleResume : AutoFillAction()

/**
* User clicked ask to add login button.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ class AccessibilityEnabledManagerTest {
Assertions.assertTrue(result)
}

@Test
fun `updateAccessibilityEnabledStateFlow updates the state flow`() = runTest {
accessibilityEnabledManager.updateAccessibilityEnabledStateFlow(true)

accessibilityEnabledManager.isAccessibilityEnabledStateFlow.value
val result = accessibilityEnabledManager.isAccessibilityEnabledStateFlow.value

Assertions.assertTrue(result)
}

private fun mockkSettingsSecureGetString(value: String?) {
every {
Settings.Secure.getString(any(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,7 @@ class AutoFillScreenTest : BaseComposeTest() {
.filterToOne(hasAnyAncestor(isDialog()))
.performClick()

// LifecycleResume should be sent
verify(exactly = 1) { viewModel.trySendAction(any()) }
verify(exactly = 0) { viewModel.trySendAction(any()) }
composeTestRule.assertNoDialogExists()
}

Expand Down Expand Up @@ -587,23 +586,18 @@ class AutoFillScreenTest : BaseComposeTest() {
intentManager.startChromeAutofillSettingsActivity(ChromeReleaseChannel.STABLE)
}
}

@Test
fun `LifecycleResumed action is sent when the screen is resumed`() {
verify { viewModel.trySendAction(AutoFillAction.LifecycleResume) }
}
}

private val DEFAULT_STATE: AutoFillState = AutoFillState(
isAskToAddLoginEnabled = false,
isAccessibilityAutofillEnabled = false,
isAutoFillServicesEnabled = false,
isCopyTotpAutomaticallyEnabled = false,
isUseInlineAutoFillEnabled = false,
showInlineAutofillOption = true,
showPasskeyManagementRow = true,
defaultUriMatchType = UriMatchType.DOMAIN,
showAutofillActionCard = false,
activeUserId = "activeUserId",
chromeAutofillSettingsOptions = persistentListOf(),
)
private val DEFAULT_STATE: AutoFillState = AutoFillState(
isAskToAddLoginEnabled = false,
isAccessibilityAutofillEnabled = false,
isAutoFillServicesEnabled = false,
isCopyTotpAutomaticallyEnabled = false,
isUseInlineAutoFillEnabled = false,
showInlineAutofillOption = true,
showPasskeyManagementRow = true,
defaultUriMatchType = UriMatchType.DOMAIN,
showAutofillActionCard = false,
activeUserId = "activeUserId",
chromeAutofillSettingsOptions = persistentListOf(),
)

0 comments on commit 8303422

Please sign in to comment.