PM-12297: Add accessibility service alert for autofill tile (#3931)

This commit is contained in:
David Perez 2024-09-18 10:08:04 -05:00 committed by GitHub
parent 1c2ccd5305
commit 2721f7293c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,14 +1,18 @@
package com.x8bit.bitwarden.data.tiles
import android.annotation.SuppressLint
import android.app.AlertDialog
import android.app.Dialog
import android.app.PendingIntent
import android.content.Intent
import android.os.Build
import android.service.quicksettings.TileService
import androidx.annotation.Keep
import com.x8bit.bitwarden.AccessibilityActivity
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.data.autofill.accessibility.manager.AccessibilityAutofillManager
import com.x8bit.bitwarden.data.autofill.accessibility.model.AccessibilityAction
import com.x8bit.bitwarden.data.autofill.accessibility.util.isAccessibilityServiceEnabled
import com.x8bit.bitwarden.data.platform.annotation.OmitFromCoverage
import com.x8bit.bitwarden.data.platform.util.isBuildVersionBelow
import dagger.hilt.android.AndroidEntryPoint
@ -34,6 +38,10 @@ class BitwardenAutofillTileService : TileService() {
@SuppressLint("StartActivityAndCollapseDeprecated")
private fun launchAutofill() {
if (!applicationContext.isAccessibilityServiceEnabled) {
showDialog(getAccessibilityServiceRequiredDialog())
return
}
accessibilityAutofillManager.accessibilityAction = AccessibilityAction.AttemptParseUri
val intent = Intent(applicationContext, AccessibilityActivity::class.java)
if (isBuildVersionBelow(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)) {
@ -50,4 +58,11 @@ class BitwardenAutofillTileService : TileService() {
)
}
}
private fun getAccessibilityServiceRequiredDialog(): Dialog =
AlertDialog.Builder(this)
.setMessage(R.string.autofill_tile_accessibility_required)
.setCancelable(true)
.setPositiveButton(R.string.ok) { dialog, _ -> dialog.cancel() }
.create()
}